[Bf-blender-npr] Gimp filtering from a compositing node?
Terry Hancock
lunatics.ml14 at anansispaceworks.com
Thu Feb 20 16:03:37 CET 2014
Hi NPR fans,
Since I first started tinkering in Blender's compositing node editor, one of
the things that keeps coming to my mind is "Gee, I wish I could just call Gimp
for this step."
So I was thinking about how to do that.
It IS possible, with some python code (I've only just realized that this is a
brand-new feature in 2.67!):
* You can write a Blender plug-in that creates a node for the node editor,
access node sockets, etc. (Python Nodes)
* Parameters allow you to input various kinds of data (including a text block,
I hope? Ah yes -- "string" is an option.)
* I presume you can write and read images to the /tmp drive, or some other
local storage? PNG format would probably be a winner for this.
* You can use Python's 'subprocess' to make operating system calls and run
other programs (I believe that using subprocess will make this somewhat
independent of operating system, though I'm not certain -- it works very
nicely in Linux, but I don't know if Windows would present obstacles)
* You can run Gimp from the command line in "batch" mode (no interface), via
command line switches
* You can pass a script to Gimp through the command line interface
* You can use the script to call any of the features available from Gimp
including plugins and scripts
* You can load an image from /tmp and write it back to another image in /tmp
So the idea is that you would have a node that would accept at minimum a
single "Image" input and output a single "image" output. This would take (at
minimum) a text block parameter. The text block would contain the interesting
part of a "Python-Fu" or "Script-Fu" script for Gimp which would do whatever
it is you were hoping to do in the filter. The node script would take the input
image from the socket, write it out to /tmp, call Gimp in batch mode, passing
it the script, with the correct path for the input image and an output image,
the output being written to /tmp. The node script would read the output image
back in from /tmp and present it to its output "Image" socket.
So what this would give you is access to any Gimp capabilities INSIDE of a
Blender compositing node system.
The only drawback I can see is that it would likely be rather slow -- but then
again, when I'm considering 10-minutes-per-render already, it might not be
prohibitively slow.
It seems so useful, it's hard for me to believe no one has done it yet (has
anyone done it? Because I've looked and can't find it).
This article gives, I think, enough info to write the Gimp gateway part of the
code:
http://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-
part-4
And this looks like the starting point for writing new nodes for Blender in
Python:
http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes
Although it looks like there's probably a lot more information required to
actually do it.
I figure this is worth doing, because Gimp is ALWAYS going to be ahead of
Blender on 2D compositing and filtering features. That's what Gimp is all
about. It will inevitably be slower than using Blender-native features, but I
can already see some really useful NPR applications for this. On my current
project, for example, it would be nice to use "Oilify", "GIMPressionist", or
"Van Gogh" artistic filters into my compositing chain to create a "painted"
background look.
Obviously, of course, once you had the basics down, you could write custom
nodes to automate the more popular filtering options (e.g. you could mimic the
Gimp interface for GIMPressionist, collect all the values, and pass them
through via the script -- eliminating the need for the Blender user to know
the Gimp scripting language).
I doubt I'll have time to tackle this any time soon, but damn it would be
useful.
Cheers,
Terry
--
Terry Hancock
Director/Producer - "Lunatics" Project - http://lunatics.tv
Anansi Spaceworks
More information about the Bf-blender-npr
mailing list