From e3c27c9751046ebd28bf653b117f40e8f7f6865e Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 10 Nov 1998 22:50:34 +0000 Subject: [PATCH] Minimal speedup by avoiding to do a inverse->inverse matrix calculation. Use transform_core_do() for scaling too. This gives a consistent behaviour regarding the corrective transform and seems to be faster too... --Sven --- ChangeLog | 9 +++++++++ app/scale_tool.c | 33 ++------------------------------- app/tools/gimpscaletool.c | 33 ++------------------------------- app/tools/scale_tool.c | 33 ++------------------------------- app/tools/transform_core.c | 12 ++++++++---- app/transform_core.c | 12 ++++++++---- libgimp/gimpmatrix.c | 10 ++++++++++ libgimp/gimpmatrix.h | 1 + 8 files changed, 42 insertions(+), 101 deletions(-) diff --git a/ChangeLog b/ChangeLog index c370bfa8d2..b9414aeb0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Nov 10 23:44:07 MET 1998 Sven Neumann + + * libgimp/gimpmatrix.[ch] + * app/transform_core.c: minimal speedup + + * app/scale_tool.c: Use transform_core_do() for scaling too. + This gives a consistent behaviour regarding the corrective transform + and seems to be faster anyway... + Mon Nov 9 16:20:33 MET 1998 Sven Neumann * app/session.c: use gdk_window_get_root_origin to get the window diff --git a/app/scale_tool.c b/app/scale_tool.c index ca41474c27..c17cd02176 100644 --- a/app/scale_tool.c +++ b/app/scale_tool.c @@ -335,8 +335,7 @@ scale_tool_motion (tool, gdisp_ptr) if (*y1 <= *y2) *y1 = *y2 + 1; } - /* if both the control key & shift keys are down, keep the aspect ratio intac -t */ + /* if both the control key & shift keys are down, keep the aspect ratio intact */ if (transform_core->state & GDK_CONTROL_MASK && transform_core->state & GDK_SHIFT_MASK) { ratio = (double) (transform_core->x2 - transform_core->x1) / @@ -432,35 +431,7 @@ scale_tool_scale (gimage, drawable, trans_info, float_tiles, interpolation, matr int interpolation; GimpMatrix matrix; { - TileManager *new_tiles; - int x1, y1, x2, y2; - PixelRegion srcPR, destPR; - - x1 = trans_info[X1]; - y1 = trans_info[Y1]; - x2 = trans_info[X2]; - y2 = trans_info[Y2]; - - pixel_region_init (&srcPR, float_tiles, 0, 0, - float_tiles->width, - float_tiles->height, FALSE); - - /* Create the new tile manager */ - new_tiles = tile_manager_new ((x2 - x1), (y2 - y1), float_tiles->bpp); - pixel_region_init (&destPR, new_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE); - - - if (drawable_type (drawable) == INDEXED_GIMAGE || - drawable_type (drawable) == INDEXEDA_GIMAGE || - !interpolation) - scale_region_no_resample (&srcPR, &destPR); - else - scale_region (&srcPR, &destPR); - - new_tiles->x = x1; - new_tiles->y = y1; - - return (void *) new_tiles; + return transform_core_do (gimage, drawable, float_tiles, interpolation, matrix); } diff --git a/app/tools/gimpscaletool.c b/app/tools/gimpscaletool.c index ca41474c27..c17cd02176 100644 --- a/app/tools/gimpscaletool.c +++ b/app/tools/gimpscaletool.c @@ -335,8 +335,7 @@ scale_tool_motion (tool, gdisp_ptr) if (*y1 <= *y2) *y1 = *y2 + 1; } - /* if both the control key & shift keys are down, keep the aspect ratio intac -t */ + /* if both the control key & shift keys are down, keep the aspect ratio intact */ if (transform_core->state & GDK_CONTROL_MASK && transform_core->state & GDK_SHIFT_MASK) { ratio = (double) (transform_core->x2 - transform_core->x1) / @@ -432,35 +431,7 @@ scale_tool_scale (gimage, drawable, trans_info, float_tiles, interpolation, matr int interpolation; GimpMatrix matrix; { - TileManager *new_tiles; - int x1, y1, x2, y2; - PixelRegion srcPR, destPR; - - x1 = trans_info[X1]; - y1 = trans_info[Y1]; - x2 = trans_info[X2]; - y2 = trans_info[Y2]; - - pixel_region_init (&srcPR, float_tiles, 0, 0, - float_tiles->width, - float_tiles->height, FALSE); - - /* Create the new tile manager */ - new_tiles = tile_manager_new ((x2 - x1), (y2 - y1), float_tiles->bpp); - pixel_region_init (&destPR, new_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE); - - - if (drawable_type (drawable) == INDEXED_GIMAGE || - drawable_type (drawable) == INDEXEDA_GIMAGE || - !interpolation) - scale_region_no_resample (&srcPR, &destPR); - else - scale_region (&srcPR, &destPR); - - new_tiles->x = x1; - new_tiles->y = y1; - - return (void *) new_tiles; + return transform_core_do (gimage, drawable, float_tiles, interpolation, matrix); } diff --git a/app/tools/scale_tool.c b/app/tools/scale_tool.c index ca41474c27..c17cd02176 100644 --- a/app/tools/scale_tool.c +++ b/app/tools/scale_tool.c @@ -335,8 +335,7 @@ scale_tool_motion (tool, gdisp_ptr) if (*y1 <= *y2) *y1 = *y2 + 1; } - /* if both the control key & shift keys are down, keep the aspect ratio intac -t */ + /* if both the control key & shift keys are down, keep the aspect ratio intact */ if (transform_core->state & GDK_CONTROL_MASK && transform_core->state & GDK_SHIFT_MASK) { ratio = (double) (transform_core->x2 - transform_core->x1) / @@ -432,35 +431,7 @@ scale_tool_scale (gimage, drawable, trans_info, float_tiles, interpolation, matr int interpolation; GimpMatrix matrix; { - TileManager *new_tiles; - int x1, y1, x2, y2; - PixelRegion srcPR, destPR; - - x1 = trans_info[X1]; - y1 = trans_info[Y1]; - x2 = trans_info[X2]; - y2 = trans_info[Y2]; - - pixel_region_init (&srcPR, float_tiles, 0, 0, - float_tiles->width, - float_tiles->height, FALSE); - - /* Create the new tile manager */ - new_tiles = tile_manager_new ((x2 - x1), (y2 - y1), float_tiles->bpp); - pixel_region_init (&destPR, new_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE); - - - if (drawable_type (drawable) == INDEXED_GIMAGE || - drawable_type (drawable) == INDEXEDA_GIMAGE || - !interpolation) - scale_region_no_resample (&srcPR, &destPR); - else - scale_region (&srcPR, &destPR); - - new_tiles->x = x1; - new_tiles->y = y1; - - return (void *) new_tiles; + return transform_core_do (gimage, drawable, float_tiles, interpolation, matrix); } diff --git a/app/tools/transform_core.c b/app/tools/transform_core.c index d092a0d643..2c8358d3d9 100644 --- a/app/tools/transform_core.c +++ b/app/tools/transform_core.c @@ -35,7 +35,6 @@ #include "temp_buf.h" #include "tools.h" #include "undo.h" - #include "layer_pvt.h" #include "drawable_pvt.h" #include "tile_manager_pvt.h" @@ -996,12 +995,17 @@ transform_core_do (gimage, drawable, float_tiles, interpolation, matrix) if (transform_tool_direction () == TRANSFORM_CORRECTIVE) { + /* keep the original matrix here, so we dont need to recalculate + the inverse later */ + gimp_matrix_duplicate (matrix, m); gimp_matrix_invert (matrix, im); matrix = im; } - - /* Find the inverse of the transformation matrix */ - gimp_matrix_invert (matrix, m); + else + { + /* Find the inverse of the transformation matrix */ + gimp_matrix_invert (matrix, m); + } x1 = float_tiles->x; y1 = float_tiles->y; diff --git a/app/transform_core.c b/app/transform_core.c index d092a0d643..2c8358d3d9 100644 --- a/app/transform_core.c +++ b/app/transform_core.c @@ -35,7 +35,6 @@ #include "temp_buf.h" #include "tools.h" #include "undo.h" - #include "layer_pvt.h" #include "drawable_pvt.h" #include "tile_manager_pvt.h" @@ -996,12 +995,17 @@ transform_core_do (gimage, drawable, float_tiles, interpolation, matrix) if (transform_tool_direction () == TRANSFORM_CORRECTIVE) { + /* keep the original matrix here, so we dont need to recalculate + the inverse later */ + gimp_matrix_duplicate (matrix, m); gimp_matrix_invert (matrix, im); matrix = im; } - - /* Find the inverse of the transformation matrix */ - gimp_matrix_invert (matrix, m); + else + { + /* Find the inverse of the transformation matrix */ + gimp_matrix_invert (matrix, m); + } x1 = float_tiles->x; y1 = float_tiles->y; diff --git a/libgimp/gimpmatrix.c b/libgimp/gimpmatrix.c index ffa27c3672..78b8d48966 100644 --- a/libgimp/gimpmatrix.c +++ b/libgimp/gimpmatrix.c @@ -169,3 +169,13 @@ gimp_matrix_invert (GimpMatrix m, GimpMatrix m_inv) m_inv[1][2] = - ( m[0][0] * m[1][2] - m[0][2] * m[1][0] ) * det_1; m_inv[2][2] = ( m[0][0] * m[1][1] - m[0][1] * m[1][0] ) * det_1; } + +void +gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target) +{ + int i,j; + + for (i=0; i<3; i++) + for (j=0; j<3; j++) + target[i][j] = src[i][j]; +} diff --git a/libgimp/gimpmatrix.h b/libgimp/gimpmatrix.h index a1b6a72862..e9cf9964ed 100644 --- a/libgimp/gimpmatrix.h +++ b/libgimp/gimpmatrix.h @@ -37,6 +37,7 @@ void gimp_matrix_xshear (GimpMatrix, double); void gimp_matrix_yshear (GimpMatrix, double); double gimp_matrix_determinant (GimpMatrix); void gimp_matrix_invert (GimpMatrix m, GimpMatrix m_inv); +void gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target); #ifdef __cplusplus }