From 797665dee01c2b2a049cb682c641989fb7466080 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 4 Dec 2003 12:18:41 +0000 Subject: [PATCH] optimized to reallocate the projection TileManager only if it does not 2003-12-04 Michael Natterer * app/core/gimpimage-projection.c (gimp_image_projection_allocate): optimized to reallocate the projection TileManager only if it does not match the required width, height and depth. * app/core/gimpimage.c (gimp_image_size_changed): call gimp_image_projection_allocate(). * app/core/gimpimage-crop.c * app/core/gimpimage-resize.c * app/core/gimpimage-rotate.c * app/core/gimpimage-scale.c * app/core/gimpimage-undo-push.c: removed calls to gimp_image_projection_allocate(), since "size_changed" does it automatically now. --- ChangeLog | 17 +++++++++++ app/core/gimpimage-crop.c | 3 -- app/core/gimpimage-projection.c | 44 +++++++++++++++++++++-------- app/core/gimpimage-resize.c | 4 --- app/core/gimpimage-rotate.c | 4 --- app/core/gimpimage-scale.c | 4 --- app/core/gimpimage-undo-push.c | 2 -- app/core/gimpimage.c | 2 ++ app/core/gimpprojection-construct.c | 44 +++++++++++++++++++++-------- 9 files changed, 83 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index f0bc0815df..b14e36e11a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2003-12-04 Michael Natterer + + * app/core/gimpimage-projection.c (gimp_image_projection_allocate): + optimized to reallocate the projection TileManager only if it does + not match the required width, height and depth. + + * app/core/gimpimage.c (gimp_image_size_changed): call + gimp_image_projection_allocate(). + + * app/core/gimpimage-crop.c + * app/core/gimpimage-resize.c + * app/core/gimpimage-rotate.c + * app/core/gimpimage-scale.c + * app/core/gimpimage-undo-push.c: removed calls to + gimp_image_projection_allocate(), since "size_changed" does it + automatically now. + 2003-12-04 Michael Natterer * plug-ins/helpbrowser/dialog.c diff --git a/app/core/gimpimage-crop.c b/app/core/gimpimage-crop.c index fd0a7373c6..f6960518dd 100644 --- a/app/core/gimpimage-crop.c +++ b/app/core/gimpimage-crop.c @@ -249,9 +249,6 @@ gimp_image_crop (GimpImage *gimage, gimp_image_move_guide (gimage, guide, new_position, TRUE); } - /* Make sure the projection matches the gimage size */ - gimp_image_projection_allocate (gimage); - /* rigor the floating layer */ if (floating_layer) floating_sel_rigor (floating_layer, TRUE); diff --git a/app/core/gimpimage-projection.c b/app/core/gimpimage-projection.c index 7db8a174e7..6e0eccb3ca 100644 --- a/app/core/gimpimage-projection.c +++ b/app/core/gimpimage-projection.c @@ -94,8 +94,10 @@ static void project_channel (GimpImage *gimage, void gimp_image_projection_allocate (GimpImage *gimage) { - if (gimage->projection) - gimp_image_projection_free (gimage); + GimpImageType proj_type = 0; + gint proj_bytes = 0; + + g_return_if_fail (GIMP_IS_IMAGE (gimage)); /* Find the number of bytes required for the projection. * This includes the intensity channels and an alpha channel @@ -105,23 +107,41 @@ gimp_image_projection_allocate (GimpImage *gimage) { case GIMP_RGB: case GIMP_INDEXED: - gimage->proj_bytes = 4; - gimage->proj_type = GIMP_RGBA_IMAGE; + proj_bytes = 4; + proj_type = GIMP_RGBA_IMAGE; break; + case GIMP_GRAY: - gimage->proj_bytes = 2; - gimage->proj_type = GIMP_GRAYA_IMAGE; + proj_bytes = 2; + proj_type = GIMP_GRAYA_IMAGE; break; + default: g_assert_not_reached (); } - /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, - gimage->proj_bytes); - tile_manager_set_user_data (gimage->projection, (void *) gimage); - tile_manager_set_validate_proc (gimage->projection, - gimp_image_projection_validate_tile); + if (gimage->projection) + { + if (proj_type != gimage->proj_type || + proj_bytes != gimage->proj_bytes || + gimage->width != tile_manager_width (gimage->projection) || + gimage->height != tile_manager_height (gimage->projection)) + { + gimp_image_projection_free (gimage); + } + } + + if (! gimage->projection) + { + gimage->proj_type = proj_type; + gimage->proj_bytes = proj_bytes; + + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); + tile_manager_set_user_data (gimage->projection, gimage); + tile_manager_set_validate_proc (gimage->projection, + gimp_image_projection_validate_tile); + } } void diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index e135d30773..f88b5008d8 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -25,7 +25,6 @@ #include "gimp.h" #include "gimpimage.h" #include "gimpimage-guides.h" -#include "gimpimage-projection.h" #include "gimpimage-resize.h" #include "gimpimage-undo.h" #include "gimpimage-undo-push.h" @@ -157,9 +156,6 @@ gimp_image_resize (GimpImage *gimage, gimp_image_move_guide (gimage, guide, new_position, TRUE); } - /* Make sure the projection matches the gimage size */ - gimp_image_projection_allocate (gimage); - /* Rigor the floating selection */ if (floating_layer) floating_sel_rigor (floating_layer, TRUE); diff --git a/app/core/gimpimage-rotate.c b/app/core/gimpimage-rotate.c index 531bb0abc4..881e3a7f46 100644 --- a/app/core/gimpimage-rotate.c +++ b/app/core/gimpimage-rotate.c @@ -24,7 +24,6 @@ #include "gimp.h" #include "gimpimage.h" -#include "gimpimage-projection.h" #include "gimpimage-rotate.h" #include "gimpimage-guides.h" #include "gimpimage-undo.h" @@ -193,9 +192,6 @@ gimp_image_rotate (GimpImage *gimage, } } - /* Make sure the projection matches the gimage size */ - gimp_image_projection_allocate (gimage); - /* Rigor the floating selection */ if (floating_layer) floating_sel_rigor (floating_layer, TRUE); diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index db8fcf1284..3b1fc17dd2 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -25,7 +25,6 @@ #include "gimp.h" #include "gimpimage.h" #include "gimpimage-guides.h" -#include "gimpimage-projection.h" #include "gimpimage-scale.h" #include "gimpimage-undo.h" #include "gimpimage-undo-push.h" @@ -179,9 +178,6 @@ gimp_image_scale (GimpImage *gimage, } } - /* Make sure the projection matches the gimage size */ - gimp_image_projection_allocate (gimage); - /* Rigor the floating selection */ if (floating_layer) floating_sel_rigor (floating_layer, TRUE); diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index 0241d337ef..4fa8dc496b 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -45,7 +45,6 @@ #include "gimpimage-colormap.h" #include "gimpimage-grid.h" #include "gimpimage-guides.h" -#include "gimpimage-projection.h" #include "gimpimage-undo.h" #include "gimpimage.h" #include "gimpitemundo.h" @@ -444,7 +443,6 @@ undo_pop_image_size (GimpUndo *undo, undo->gimage->width = width; undo->gimage->height = height; - gimp_image_projection_allocate (undo->gimage); gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (undo->gimage))); if (undo->gimage->width != isu->width || diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index e65593134c..56e0b7e495 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -785,6 +785,8 @@ gimp_image_size_changed (GimpViewable *viewable) } gimp_viewable_size_changed (GIMP_VIEWABLE (gimp_image_get_mask (gimage))); + + gimp_image_projection_allocate (gimage); } static gchar * diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 7db8a174e7..6e0eccb3ca 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -94,8 +94,10 @@ static void project_channel (GimpImage *gimage, void gimp_image_projection_allocate (GimpImage *gimage) { - if (gimage->projection) - gimp_image_projection_free (gimage); + GimpImageType proj_type = 0; + gint proj_bytes = 0; + + g_return_if_fail (GIMP_IS_IMAGE (gimage)); /* Find the number of bytes required for the projection. * This includes the intensity channels and an alpha channel @@ -105,23 +107,41 @@ gimp_image_projection_allocate (GimpImage *gimage) { case GIMP_RGB: case GIMP_INDEXED: - gimage->proj_bytes = 4; - gimage->proj_type = GIMP_RGBA_IMAGE; + proj_bytes = 4; + proj_type = GIMP_RGBA_IMAGE; break; + case GIMP_GRAY: - gimage->proj_bytes = 2; - gimage->proj_type = GIMP_GRAYA_IMAGE; + proj_bytes = 2; + proj_type = GIMP_GRAYA_IMAGE; break; + default: g_assert_not_reached (); } - /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, - gimage->proj_bytes); - tile_manager_set_user_data (gimage->projection, (void *) gimage); - tile_manager_set_validate_proc (gimage->projection, - gimp_image_projection_validate_tile); + if (gimage->projection) + { + if (proj_type != gimage->proj_type || + proj_bytes != gimage->proj_bytes || + gimage->width != tile_manager_width (gimage->projection) || + gimage->height != tile_manager_height (gimage->projection)) + { + gimp_image_projection_free (gimage); + } + } + + if (! gimage->projection) + { + gimage->proj_type = proj_type; + gimage->proj_bytes = proj_bytes; + + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); + tile_manager_set_user_data (gimage->projection, gimage); + tile_manager_set_validate_proc (gimage->projection, + gimp_image_projection_validate_tile); + } } void