After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 518910 - Perspective transformation does no inverse transformation
Perspective transformation does no inverse transformation
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: libgimp
2.4.x
Other All
: Normal normal
: 2.4
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2008-02-26 19:54 UTC by J.M.B
Modified: 2008-10-30 20:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test-script for forward and backward perspective transformation (2.92 KB, text/plain)
2008-02-26 20:30 UTC, J.M.B
  Details
(untested) patch to fix the problem (858 bytes, patch)
2008-02-27 08:23 UTC, Sven Neumann
committed Details | Review

Description J.M.B 2008-02-26 19:54:42 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)
Comment 1 J.M.B 2008-02-26 20:30:05 UTC
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.
Comment 2 weskaggs 2008-02-26 23:49:01 UTC
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.
Comment 3 Sven Neumann 2008-02-27 08:18:09 UTC
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.
Comment 4 Sven Neumann 2008-02-27 08:23:22 UTC
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.
Comment 5 Michael Natterer 2008-02-27 11:05:55 UTC
Most definitely correct. Please commit.
Comment 6 Sven Neumann 2008-02-27 15:26:16 UTC
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.