Hacking:Porting filters to GEGL

From GIMP Developer Wiki
Revision as of 10:31, 3 July 2012 by BatO (Talk | contribs)

Jump to: navigation, search

How to port

This is the general process to write a new GEGL operation:

  1. Gather information.
    1. Read the plugin you want to port, understand the algorithm hidden in it.
    2. Read carefully the GEGL website. There is lot of information here.
    3. Read the Babl website and understand the difference between color models.
    4. You may want to find a similar existing operation and get inspiration from it.
  2. Choose a base class. This is the general structure of your operation, the number of input/output, what kind of optimization GEGL can do.
  3. Create a new file for your operation. No need to register it in some Makefile, the build system will build every C file present in the operations directory. The exact directory where you should put your file is explained in the GEGL website.
  4. Copy another operation with the same base class and clean it to have your operation skeleton. GEGL use a macro system called GEGL chant, that avoid you to write all the GObject boilerplate, and register easily parameters for your op. Look other operation to see how it works.
  5. Use the prepare function to indicate what color model your op will operate, for each input/output.
  6. Create your op's parameter using the chant system. You can have integer, floats, string, color, curve, enum ... There is some predefined enum in the GEGL core, for instance GeglSamplerType. You can register your own, like in the ripple op.
  7. Write your operation in the process function. Some tips here:
    1. GEGL store data in tile, so it impose some restriction, especially for transform op. You usually need to write your algorithm backward, ie iterate over the output, compute where the data come from, use a sampler to get it and affect the output.
    2. ROI mean region of interest, it's the area your are currently working on.
    3. Sometimes you need to know the size of the full input, not just the roi. You can have it using gegl_operation_source_get_bounding_box.
    4. Rather than carry a lot of parameter in you different functions, you can register a custom structure in the chant system, like the WarpPrivate structure in the warp op.
    5. When you fetch data outside of the input buffer (in it's abyss) you get for now zeroed memory. In the future, the abyss policy will allow you to chose what you want here, and in particular, you can choose to clamp to the border, loop in the buffer extent ... It will allow to write more clever algorithm. For instance, see the ripple op. In the future, setting the abyss policy to GEGL_ABYSS_LOOP will add the tileability to the op for free. If you need behavior like this, it's better to not rewrite your own algorithm and wait a little.
  8. Test your operation. You can use the gegl binary to run an xml file, or use the GEGL tool in GIMP.

Porting matrix

Processing, color grading and effects

GIMP filter GEGL operation OpenCL version Comment
Alien Map 0 0 -
Align Visible Layers 0 0 -
Antialias  ? 0 -
Apply Canvas 0 0 -
Apply Lens 0 0 -
Assign Color Profile 0 0 -
Autocrop Image 0 0 -
Autocrop Layer 0 0 -
Border Average 0 0 -
Bump Map 0 0 -
Cartoon 0 0 -
Channel Mixer 0 0 -
Checkerboard X 0 -
CML Explorer 0 0 -
Color to Alpha X 0 -
Colorcube Analysis 0 0 -
Color Enhance 0 0 -
Color Exchange 0 0 -
Compose 0 0 -
Convert to Color Profile 0 0 -
Convolution Matrix X 0 -
CSS stylesheet 0 0 -
Cubism X  ? -
Curve Bend 0 0 -
Decompose 0 0 -
Deinterlace X 0 -
Depth Merge 0 0 -
Despeckle 0 0 -
Destripe 0 0 -
Difference of Gaussians X 0 The port is missing Normalize and Invert options
Diffraction Patterns 0 0 -
Dilate 0  ? -
Displace  ? 0 -
Edge  ?  ? -
Emboss X 0 -
Engrave 0 0 -
Erode 0 0 -
Filmstrip 0 0 -
Filterpack 0 0 -
Flame 0 0 -
Fractal Explorer X  ? -
Fractal Trace X  ? -
From Webpage 0 0 Probably doesn't need porting
Gaussian blur X X Needs abyss policy
Gfig 0 0 Probably doesn't need porting
GIMPressionist 0 0 -
Glass Tile 0 0 -
Gradient Flare 0 0 -
Gradient Map  ? 0 -
Grey X X -
Grid X 0 Missing intersection option, is it needed?
Hot 0 0 -
HSV Noise 0 0 -
Hurl 0 0 -
IFS Fractal 0 0 -
Illusion 0 0 -
Image Map 0 0 Probably doesn't need porting
Invert X 0 -
iWarp 0 0 To be replaced with Warp Transform tool
Java map 0 0 Probably doesn't need porting
Jigsaw 0 0 -
Laplace X X -
Lens Distortion X 0 -
Lens Flare 0 0 -
Lighting Effects 0 0 -
Make Seamless 0 0 -
Maximum RGB - - Will be removed without replacement
Maze 0 0 -
Mosaic 0 0 -
Motion Blur X X The GEGL port is incomplete (no type and center selection)
Neon 0  ? -
Newsprint 0 0 -
NL Filter 0 0 -
Normalize 0 0 -
Noise Spread X 0 -
Oilify 0 0 -
Optimize (Difference) 0 0 -
Optimize (for GIF) 0 0 -
Pagecurl 0 0 -
Palette Map 0 0 -
Paper Tile 0 0 -
Photocopy X 0 -
Pick 0 0 -
Pixelize X X Needs abyss policy
Plasma X  ? -
Playback 0 0 Probably doesn't have to be ported?
Polar Coordinates X 0 -
Qbist 0  ? -
Recompose 0 0 -
Red Eye Removal X 0 -
Retinex 0 0 -
RGB Noise 0  ? -
Ripple X  ? Complete in abyss branch
Rotate Colors X 0 Check if the port is complete
Sample Colorize 0 0 -
Selective Gaussian Blur 0 0 -
Shift X 0 -
Sinus 0 0 -
Slur 0 0 -
Smooth Palette  ? 0 -
Sobel X X -
Softglow 0 0 -
Solid Noise 0 0 -
Sparkle 0 0 -
Sphere Designer 0 0 -
Spread X 0 -
Stretch Contrast 0 0 not sure we need that with gegl being the core of gimp
Stretch HSV 0 0 -
Supernova 0 0 -
Threshoild X X -
Tile 0 0 -
Unoptimize 0 0 -
Unsharp Mask X  ? -
Value Propagate 0 0 -
Van Gogh (LIC) 0 0 -
Video 0 0 -
Warp 0 0 -
Waves X  ? Missing reflective option that produce strange result, I suggest dropping that.
Whirl and Pinch X 0 Check if the port is complete
Wind 0 0 -
Zealous Crop  ? 0 -

File loaders/savers

GIMP filter GEGL version OpenCL version Comment
OpenRaster Save 0 0 -
OpenRaster Load 0 0 -
FITS loader 0 0 -
TIFF loader 0 0 -
TIFF saver 0 0 -
PSD loader 0 0 -
PSD saver 0 0 -

Port of new GEGL ops to OpenCL

GEGL operation OpenCL version Comment
bilateral filter X -
box blur X -
c2g X -
Color Temperature X -
mantiuk06 0 -
mono mixer X -
Noise Reduction X -
reinhard05 X -
snn-mean X -
Vignette X -