Hello everyone,
A few words about a new feature planned for the next release 3.1.0 of G’MIC (to be released this week if everything goes well). This is related to how the preview can be computed when defining a filter.
Before :
When defining a filter, it was possible to set the zoom-factor associated to the preview (more often è 0or
1`), like this:
#@gui My Filter : my_filter, my_filter_preview(1)
- If the zoom factor is
1
: The input image passed to the preview commandmy_filter_preview
is a thumbnail of the entire image. - If the zoom factor is
0
: The input image passed to the preview command is a 1:1 crop of the entire image.
In both cases, these images were not larger than $_preview_width
x $_preview_height
.
After:
A new preview mode is now possible, by defining your filter like this:
#@gui My Filter : my_filter, my_filter_preview(1)*
In this case, the image passed to the preview command is always the whole image. It’s the role of the preview command to actually render the part of the image that corresponds to what the user sees in the preview widget.
For that, you have access to several pre-defined variables:
-
$_preview_x0
,$_preview_y0
,$_preview_x1
,$_preview_y1
are the upper-left and bottom-right coordinates of the previewed image, expressed in the coordinate space of the full input image. -
$_preview_width
and$_preview_height
is the size of the previewed image. -
$_preview_area_width
and$_preview_area_height
is the size of the preview area (can be a bit larger than$_preview_width
and$_preview_height
.
So, with this new preview mode, a preview command must deal with these variables to return an image with the correct size, e.g.
my_filter_preview :
my_filter # Filter applied to the whole image, to get a pixel-perfect preview
z $_preview_x0,$_preview_y0,$_preview_x1,$_preview_y1 # Crop to correct location
r $_preview_width,$_preview_height,1,100% # Resize to correct preview size
Doing this ensures you’ll always get an accurate preview, because the filter is actually computed on the whole image (don’t do this for slow filters though), before being cropped/resized to the correct preview size.
I’ll probably add a few commands, like _preview_crop
and preview_resize
to make it even easier to use.