From 9a3f33f6f0a457c41900af487ca9254bf02d571e Mon Sep 17 00:00:00 2001 From: Austin Donnelly Date: Wed, 29 Nov 2000 16:19:43 +0000 Subject: [PATCH] Applied patch from David Hodson to fix Bug#33399: 2000-11-29 Austin Donnelly * app/curves.c: Applied patch from David Hodson to fix Bug#33399: GIMP crashes when applying curve to Grayscaled image when preview is off. Previously the curves tool attempted a reset when changing image, but didn't correctly do this. Now it has the (more useful) behaviour of doing a partial reset, where the curve remains the same across multiple invocations, allowing you to apply the same tweak to multiple images. The internal state relevant to image type/depth is correctly reset, stopping the segfault behaviour seen before. Still no fix for Bug#33403: Curves/Levels Tool does not work on GRAYA-Images. --- ChangeLog | 16 +++++++++ app/base/curves.c | 68 ++++++++++++++++++++------------------ app/curves.c | 68 ++++++++++++++++++++------------------ app/tools/curves.c | 68 ++++++++++++++++++++------------------ app/tools/gimpcurvestool.c | 68 ++++++++++++++++++++------------------ 5 files changed, 160 insertions(+), 128 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88c8523d6e..d8a7073b9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2000-11-29 Austin Donnelly + + * app/curves.c: Applied patch from David Hodson + to fix Bug#33399: GIMP crashes when + applying curve to Grayscaled image when preview is off. + Previously the curves tool attempted a reset when changing + image, but didn't correctly do this. Now it has the + (more useful) behaviour of doing a partial reset, where the + curve remains the same across multiple invocations, allowing + you to apply the same tweak to multiple images. The internal + state relevant to image type/depth is correctly reset, + stopping the segfault behaviour seen before. + + Still no fix for Bug#33403: Curves/Levels Tool does not work + on GRAYA-Images. + 2000-11-27 Sven Neumann * libgimp/gimpwidgets.c (gimp_int_adjustment_update): use rint(). diff --git a/app/base/curves.c b/app/base/curves.c index e275fdcfa2..c4399bb0cd 100644 --- a/app/base/curves.c +++ b/app/base/curves.c @@ -113,6 +113,7 @@ static void curves_channel_callback (GtkWidget *, gpointer); static void curves_smooth_callback (GtkWidget *, gpointer); static void curves_free_callback (GtkWidget *, gpointer); +static void curves_channel_reset (int); static void curves_reset_callback (GtkWidget *, gpointer); static void curves_ok_callback (GtkWidget *, gpointer); static void curves_cancel_callback (GtkWidget *, gpointer); @@ -442,29 +443,19 @@ curves_initialize (GDisplay *gdisp) /* The curves dialog */ if (!curves_dialog) - curves_dialog = curves_dialog_new (); - else - if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) - gtk_widget_show (curves_dialog->shell); - - /* Initialize the values */ - curves_dialog->channel = HISTOGRAM_VALUE; - for (i = 0; i < 5; i++) - for (j = 0; j < 256; j++) - curves_dialog->curve[i][j] = j; - - curves_dialog->grab_point = -1; - for (i = 0; i < 5; i++) { - for (j = 0; j < 17; j++) - { - curves_dialog->points[i][j][0] = -1; - curves_dialog->points[i][j][1] = -1; - } - curves_dialog->points[i][0][0] = 0; - curves_dialog->points[i][0][1] = 0; - curves_dialog->points[i][16][0] = 255; - curves_dialog->points[i][16][1] = 255; + curves_dialog = curves_dialog_new (); + + /* Initialize the values */ + curves_dialog->channel = HISTOGRAM_VALUE; + for (i = 0; i < 5; i++) + for (j = 0; j < 256; j++) + curves_dialog->curve[i][j] = j; + + for (i = 0; i < 5; i++) + { + curves_channel_reset (i); + } } curves_dialog->drawable = gimage_active_drawable (gdisp->gimage); @@ -489,6 +480,9 @@ curves_initialize (GDisplay *gdisp) gtk_option_menu_set_history (GTK_OPTION_MENU (curves_dialog->channel_menu), curves_dialog->channel); + gimp_lut_setup (curves_dialog->lut, (GimpLutFunc) curves_lut_func, + (void *) curves_dialog, gimp_drawable_bytes (curves_dialog->drawable)); + if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) gtk_widget_show (curves_dialog->shell); @@ -1182,6 +1176,25 @@ curves_free_callback (GtkWidget *widget, } } +static void +curves_channel_reset (int i) +{ + int j; + + curves_dialog->grab_point = -1; + + for (j = 0; j < 17; j++) + { + curves_dialog->points[i][j][0] = -1; + curves_dialog->points[i][j][1] = -1; + } + curves_dialog->points[i][0][0] = 0; + curves_dialog->points[i][0][1] = 0; + curves_dialog->points[i][16][0] = 255; + curves_dialog->points[i][16][1] = 255; +} + + static void curves_reset_callback (GtkWidget *widget, gpointer data) @@ -1195,16 +1208,7 @@ curves_reset_callback (GtkWidget *widget, for (i = 0; i < 256; i++) cd->curve[cd->channel][i] = i; - cd->grab_point = -1; - for (i = 0; i < 17; i++) - { - cd->points[cd->channel][i][0] = -1; - cd->points[cd->channel][i][1] = -1; - } - cd->points[cd->channel][0][0] = 0; - cd->points[cd->channel][0][1] = 0; - cd->points[cd->channel][16][0] = 255; - cd->points[cd->channel][16][1] = 255; + curves_channel_reset (cd->channel); curves_calculate_curve (cd); curves_update (cd, GRAPH | XRANGE_TOP | DRAW); diff --git a/app/curves.c b/app/curves.c index e275fdcfa2..c4399bb0cd 100644 --- a/app/curves.c +++ b/app/curves.c @@ -113,6 +113,7 @@ static void curves_channel_callback (GtkWidget *, gpointer); static void curves_smooth_callback (GtkWidget *, gpointer); static void curves_free_callback (GtkWidget *, gpointer); +static void curves_channel_reset (int); static void curves_reset_callback (GtkWidget *, gpointer); static void curves_ok_callback (GtkWidget *, gpointer); static void curves_cancel_callback (GtkWidget *, gpointer); @@ -442,29 +443,19 @@ curves_initialize (GDisplay *gdisp) /* The curves dialog */ if (!curves_dialog) - curves_dialog = curves_dialog_new (); - else - if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) - gtk_widget_show (curves_dialog->shell); - - /* Initialize the values */ - curves_dialog->channel = HISTOGRAM_VALUE; - for (i = 0; i < 5; i++) - for (j = 0; j < 256; j++) - curves_dialog->curve[i][j] = j; - - curves_dialog->grab_point = -1; - for (i = 0; i < 5; i++) { - for (j = 0; j < 17; j++) - { - curves_dialog->points[i][j][0] = -1; - curves_dialog->points[i][j][1] = -1; - } - curves_dialog->points[i][0][0] = 0; - curves_dialog->points[i][0][1] = 0; - curves_dialog->points[i][16][0] = 255; - curves_dialog->points[i][16][1] = 255; + curves_dialog = curves_dialog_new (); + + /* Initialize the values */ + curves_dialog->channel = HISTOGRAM_VALUE; + for (i = 0; i < 5; i++) + for (j = 0; j < 256; j++) + curves_dialog->curve[i][j] = j; + + for (i = 0; i < 5; i++) + { + curves_channel_reset (i); + } } curves_dialog->drawable = gimage_active_drawable (gdisp->gimage); @@ -489,6 +480,9 @@ curves_initialize (GDisplay *gdisp) gtk_option_menu_set_history (GTK_OPTION_MENU (curves_dialog->channel_menu), curves_dialog->channel); + gimp_lut_setup (curves_dialog->lut, (GimpLutFunc) curves_lut_func, + (void *) curves_dialog, gimp_drawable_bytes (curves_dialog->drawable)); + if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) gtk_widget_show (curves_dialog->shell); @@ -1182,6 +1176,25 @@ curves_free_callback (GtkWidget *widget, } } +static void +curves_channel_reset (int i) +{ + int j; + + curves_dialog->grab_point = -1; + + for (j = 0; j < 17; j++) + { + curves_dialog->points[i][j][0] = -1; + curves_dialog->points[i][j][1] = -1; + } + curves_dialog->points[i][0][0] = 0; + curves_dialog->points[i][0][1] = 0; + curves_dialog->points[i][16][0] = 255; + curves_dialog->points[i][16][1] = 255; +} + + static void curves_reset_callback (GtkWidget *widget, gpointer data) @@ -1195,16 +1208,7 @@ curves_reset_callback (GtkWidget *widget, for (i = 0; i < 256; i++) cd->curve[cd->channel][i] = i; - cd->grab_point = -1; - for (i = 0; i < 17; i++) - { - cd->points[cd->channel][i][0] = -1; - cd->points[cd->channel][i][1] = -1; - } - cd->points[cd->channel][0][0] = 0; - cd->points[cd->channel][0][1] = 0; - cd->points[cd->channel][16][0] = 255; - cd->points[cd->channel][16][1] = 255; + curves_channel_reset (cd->channel); curves_calculate_curve (cd); curves_update (cd, GRAPH | XRANGE_TOP | DRAW); diff --git a/app/tools/curves.c b/app/tools/curves.c index e275fdcfa2..c4399bb0cd 100644 --- a/app/tools/curves.c +++ b/app/tools/curves.c @@ -113,6 +113,7 @@ static void curves_channel_callback (GtkWidget *, gpointer); static void curves_smooth_callback (GtkWidget *, gpointer); static void curves_free_callback (GtkWidget *, gpointer); +static void curves_channel_reset (int); static void curves_reset_callback (GtkWidget *, gpointer); static void curves_ok_callback (GtkWidget *, gpointer); static void curves_cancel_callback (GtkWidget *, gpointer); @@ -442,29 +443,19 @@ curves_initialize (GDisplay *gdisp) /* The curves dialog */ if (!curves_dialog) - curves_dialog = curves_dialog_new (); - else - if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) - gtk_widget_show (curves_dialog->shell); - - /* Initialize the values */ - curves_dialog->channel = HISTOGRAM_VALUE; - for (i = 0; i < 5; i++) - for (j = 0; j < 256; j++) - curves_dialog->curve[i][j] = j; - - curves_dialog->grab_point = -1; - for (i = 0; i < 5; i++) { - for (j = 0; j < 17; j++) - { - curves_dialog->points[i][j][0] = -1; - curves_dialog->points[i][j][1] = -1; - } - curves_dialog->points[i][0][0] = 0; - curves_dialog->points[i][0][1] = 0; - curves_dialog->points[i][16][0] = 255; - curves_dialog->points[i][16][1] = 255; + curves_dialog = curves_dialog_new (); + + /* Initialize the values */ + curves_dialog->channel = HISTOGRAM_VALUE; + for (i = 0; i < 5; i++) + for (j = 0; j < 256; j++) + curves_dialog->curve[i][j] = j; + + for (i = 0; i < 5; i++) + { + curves_channel_reset (i); + } } curves_dialog->drawable = gimage_active_drawable (gdisp->gimage); @@ -489,6 +480,9 @@ curves_initialize (GDisplay *gdisp) gtk_option_menu_set_history (GTK_OPTION_MENU (curves_dialog->channel_menu), curves_dialog->channel); + gimp_lut_setup (curves_dialog->lut, (GimpLutFunc) curves_lut_func, + (void *) curves_dialog, gimp_drawable_bytes (curves_dialog->drawable)); + if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) gtk_widget_show (curves_dialog->shell); @@ -1182,6 +1176,25 @@ curves_free_callback (GtkWidget *widget, } } +static void +curves_channel_reset (int i) +{ + int j; + + curves_dialog->grab_point = -1; + + for (j = 0; j < 17; j++) + { + curves_dialog->points[i][j][0] = -1; + curves_dialog->points[i][j][1] = -1; + } + curves_dialog->points[i][0][0] = 0; + curves_dialog->points[i][0][1] = 0; + curves_dialog->points[i][16][0] = 255; + curves_dialog->points[i][16][1] = 255; +} + + static void curves_reset_callback (GtkWidget *widget, gpointer data) @@ -1195,16 +1208,7 @@ curves_reset_callback (GtkWidget *widget, for (i = 0; i < 256; i++) cd->curve[cd->channel][i] = i; - cd->grab_point = -1; - for (i = 0; i < 17; i++) - { - cd->points[cd->channel][i][0] = -1; - cd->points[cd->channel][i][1] = -1; - } - cd->points[cd->channel][0][0] = 0; - cd->points[cd->channel][0][1] = 0; - cd->points[cd->channel][16][0] = 255; - cd->points[cd->channel][16][1] = 255; + curves_channel_reset (cd->channel); curves_calculate_curve (cd); curves_update (cd, GRAPH | XRANGE_TOP | DRAW); diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c index e275fdcfa2..c4399bb0cd 100644 --- a/app/tools/gimpcurvestool.c +++ b/app/tools/gimpcurvestool.c @@ -113,6 +113,7 @@ static void curves_channel_callback (GtkWidget *, gpointer); static void curves_smooth_callback (GtkWidget *, gpointer); static void curves_free_callback (GtkWidget *, gpointer); +static void curves_channel_reset (int); static void curves_reset_callback (GtkWidget *, gpointer); static void curves_ok_callback (GtkWidget *, gpointer); static void curves_cancel_callback (GtkWidget *, gpointer); @@ -442,29 +443,19 @@ curves_initialize (GDisplay *gdisp) /* The curves dialog */ if (!curves_dialog) - curves_dialog = curves_dialog_new (); - else - if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) - gtk_widget_show (curves_dialog->shell); - - /* Initialize the values */ - curves_dialog->channel = HISTOGRAM_VALUE; - for (i = 0; i < 5; i++) - for (j = 0; j < 256; j++) - curves_dialog->curve[i][j] = j; - - curves_dialog->grab_point = -1; - for (i = 0; i < 5; i++) { - for (j = 0; j < 17; j++) - { - curves_dialog->points[i][j][0] = -1; - curves_dialog->points[i][j][1] = -1; - } - curves_dialog->points[i][0][0] = 0; - curves_dialog->points[i][0][1] = 0; - curves_dialog->points[i][16][0] = 255; - curves_dialog->points[i][16][1] = 255; + curves_dialog = curves_dialog_new (); + + /* Initialize the values */ + curves_dialog->channel = HISTOGRAM_VALUE; + for (i = 0; i < 5; i++) + for (j = 0; j < 256; j++) + curves_dialog->curve[i][j] = j; + + for (i = 0; i < 5; i++) + { + curves_channel_reset (i); + } } curves_dialog->drawable = gimage_active_drawable (gdisp->gimage); @@ -489,6 +480,9 @@ curves_initialize (GDisplay *gdisp) gtk_option_menu_set_history (GTK_OPTION_MENU (curves_dialog->channel_menu), curves_dialog->channel); + gimp_lut_setup (curves_dialog->lut, (GimpLutFunc) curves_lut_func, + (void *) curves_dialog, gimp_drawable_bytes (curves_dialog->drawable)); + if (!GTK_WIDGET_VISIBLE (curves_dialog->shell)) gtk_widget_show (curves_dialog->shell); @@ -1182,6 +1176,25 @@ curves_free_callback (GtkWidget *widget, } } +static void +curves_channel_reset (int i) +{ + int j; + + curves_dialog->grab_point = -1; + + for (j = 0; j < 17; j++) + { + curves_dialog->points[i][j][0] = -1; + curves_dialog->points[i][j][1] = -1; + } + curves_dialog->points[i][0][0] = 0; + curves_dialog->points[i][0][1] = 0; + curves_dialog->points[i][16][0] = 255; + curves_dialog->points[i][16][1] = 255; +} + + static void curves_reset_callback (GtkWidget *widget, gpointer data) @@ -1195,16 +1208,7 @@ curves_reset_callback (GtkWidget *widget, for (i = 0; i < 256; i++) cd->curve[cd->channel][i] = i; - cd->grab_point = -1; - for (i = 0; i < 17; i++) - { - cd->points[cd->channel][i][0] = -1; - cd->points[cd->channel][i][1] = -1; - } - cd->points[cd->channel][0][0] = 0; - cd->points[cd->channel][0][1] = 0; - cd->points[cd->channel][16][0] = 255; - cd->points[cd->channel][16][1] = 255; + curves_channel_reset (cd->channel); curves_calculate_curve (cd); curves_update (cd, GRAPH | XRANGE_TOP | DRAW);