GNOME Bugzilla – Bug 518910
Perspective transformation does no inverse transformation
Last modified: 2008-10-30 20:10:17 UTC
gimp-drawable-transform-perspective asks for the parameter 'transform-direction' specified by: Direction of transformation { TRANSFORM-FORWARD (0), TRANSFORM-BACKWARD (1) } Nevertheless, if invoked by a script, the result is the same for '0' as well as '1', in fact the result of an forward/normal perspective transformation. btw: this problem doesn't occur with the perspective-transformation-tool from the gimp toolbox (up to now I thought that this invokes the same procedure, but it obviosly doesn't) i'll attach a small script to illustrate the bug (seems to me, that you can't attach directly to the report)
Created attachment 106023 [details] test-script for forward and backward perspective transformation a small script written to illustrate the bug. It should apply the same perspective transformation forward and backward on images in a directory, but due to the bug mentioned above each two resulting images are the same.
It's pretty easy to see that the code in the pdb is broken. The full code for this function is: gimp_matrix3_identity (&matrix); gimp_transform_matrix_perspective (&matrix, x, y, width, height, x0, y0, x1, y1, x2, y2, x3, y3); The transform_direction value isn't used at all here. If I understand correctly how this is supposed to work, then it should be sufficient to add if (transform_direction == GIMP_TRANSFORM_BACKWARD) gimp_matrix3_invert (&matrix); after the code that is shown above. (This is in drawable_transform.pdb.) We may also want to add a note to the documentation warning that inverse transforms are dangerous, because it is easy for them to map internal points to infinity if the parameters are chosen carelessly. Also, the documentation explains that the "supersample" parameter is ignored, but it doesn't explain that the "interpolation", "recursion_level", and "clip_result" parameters are also ignored, as they obviously are in the code above. It looks like maybe this was added to the pdb with the intention of fixing it later, but the fix never happened.
I am sorry, but your analysis of the problem is incorrect. The "transform_direction", "interpolation", "recursion_level", and "clip_result" parameters are not ignored at all. Please have a look at the generated code in app/pdb/drawable_transform_cmds.c.
Created attachment 106052 [details] [review] (untested) patch to fix the problem It appears that the problem is in gimp_drawable_transform_affine() which does not pass the direction variable down to gimp_drawable_transform_tiles_affine(). I haven't found time yet to test this patch and to check if it might introduce other problems.
Most definitely correct. Please commit.
Committed in both branches. Closing as FIXED. 2008-02-27 Sven Neumann <sven@gimp.org> * app/core/gimpdrawable-transform.c (gimp_drawable_transform_affine): pass the direction parameter down to gimp_drawable_transform_tiles_affine() instead of hardcoding it to GIMP_TRANSFORM_FORWARD. Fixes bug #518910.