diff --git a/ChangeLog b/ChangeLog index 9115c8b9ff..044aa4ce31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Jul 24 19:36:33 BST 1998 Adam D. Moss + + * app/appenv.h app/brightness_contrast.c app/color_balance.c + app/curves.c app/gdisplay.h app/gdisplay_ops.c + app/hue_saturation.c app/paint_core.c app/paint_funcs.c + app/undo.c: Attempt to speed-up and/or sanitize + MAX/MIN/CLAMP macro usage throughout gimp-core. + Fri Jul 24 12:01:31 CDT 1998 Larry Ewing * app/gdisplay.c (gdisplay_update_cursor): Fixed a string diff --git a/app/appenv.h b/app/appenv.h index 364e420f08..3197d68d14 100644 --- a/app/appenv.h +++ b/app/appenv.h @@ -18,16 +18,24 @@ #ifndef __APPENV_H__ #define __APPENV_H__ +#include "glib.h" #include "gdk/gdkx.h" #include "gtk/gtk.h" #include "gimpsetF.h" #define DISPLAY ((Display *) GDK_DISPLAY()) -/* important macros */ -#define BOUNDS(a,x,y) ((a < x) ? x : ((a > y) ? y : a)) -#define MINIMUM(x,y) ((x < y) ? x : y) -#define MAXIMUM(x,y) ((x > y) ? x : y) +/* important macros - we reuse the ones from glib */ +#define BOUNDS(a,x,y) CLAMP(a,x,y) +#define MINIMUM(x,y) MIN(x,y) +#define MAXIMUM(x,y) MAX(x,y) + +/* limit a (0->511) int to 255 */ +#define MAX255(a) (a | ((a & 256) - ((a & 256) >> 8))) + +/* clamp a int32-range int between 0 and 255 inclusive */ +#define CLAMP0255(a) ((a&256)? (~(a>>31)) : a) + typedef enum { MESSAGE_BOX, diff --git a/app/base/color-balance.c b/app/base/color-balance.c index 2b6c839252..178ec52906 100644 --- a/app/base/color-balance.c +++ b/app/base/color-balance.c @@ -154,25 +154,25 @@ color_balance (PixelRegion *srcPR, b = b_n = s[BLUE_PIX]; r_n += cbd->cyan_red[SHADOWS] * cyan_red_transfer[SHADOWS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[MIDTONES] * cyan_red_transfer[MIDTONES][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[HIGHLIGHTS] * cyan_red_transfer[HIGHLIGHTS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); g_n += cbd->magenta_green[SHADOWS] * magenta_green_transfer[SHADOWS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[MIDTONES] * magenta_green_transfer[MIDTONES][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[HIGHLIGHTS] * magenta_green_transfer[HIGHLIGHTS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); b_n += cbd->yellow_blue[SHADOWS] * yellow_blue_transfer[SHADOWS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[MIDTONES] * yellow_blue_transfer[MIDTONES][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[HIGHLIGHTS] * yellow_blue_transfer[HIGHLIGHTS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); if (cbd->preserve_luminosity) { diff --git a/app/base/curves.c b/app/base/curves.c index fe057c648f..15512ec6f6 100644 --- a/app/base/curves.c +++ b/app/base/curves.c @@ -757,8 +757,8 @@ curves_plot_curve (CurvesDialog *cd, dy += dy2; dy2 += dy3; - newx = BOUNDS ((ROUND (x)), 0, 255); - newy = BOUNDS ((ROUND (y)), 0, 255); + newx = CLAMP0255 (ROUND (x)); + newy = CLAMP0255 (ROUND (y)); /* if this point is different than the last one...then draw it */ if ((lastx != newx) || (lasty != newy)) @@ -914,7 +914,7 @@ curves_smooth_callback (GtkWidget *w, /* pick representative points from the curve and make them control points */ for (i = 0; i <= 8; i++) { - index = BOUNDS ((i * 32), 0, 255); + index = CLAMP0255 (i * 32); cd->points[cd->channel][i * 2][0] = index; cd->points[cd->channel][i * 2][1] = cd->curve[cd->channel][index]; } diff --git a/app/base/hue-saturation.c b/app/base/hue-saturation.c index e09bcbb2c0..9b37b8b4b0 100644 --- a/app/base/hue-saturation.c +++ b/app/base/hue-saturation.c @@ -163,7 +163,7 @@ hue_saturation_calculate_transfers (HueSaturationDialog *hsd) value = (hsd->saturation[0] + hsd->saturation[hue + 1]) * 255.0 / 100.0; value = BOUNDS (value, -255, 255); #if 0 - saturation_transfer[hue][i] = (unsigned char) (BOUNDS ((i * (255 + value)) / 255, 0, 255)); + saturation_transfer[hue][i] = (unsigned char) (CLAMP0255 ((i * (255 + value)) / 255)); #else if (value < 0) saturation_transfer[hue][i] = (unsigned char) ((i * (255 + value)) / 255); diff --git a/app/brightness_contrast.c b/app/brightness_contrast.c index 66bc9d5f84..3e0de2157f 100644 --- a/app/brightness_contrast.c +++ b/app/brightness_contrast.c @@ -133,7 +133,7 @@ brightness_contrast (PixelRegion *srcPR, value = (i > 127) ? (255 - i) : i; value = (int) (127.0 * pow ((double) (value ? value : 1) / 127.0, (double) (127 + bcd->contrast) / 127.0)); - value = BOUNDS (value, 0, 255); + value = CLAMP0255 (value); contrast[i] = (i > 127) ? (255 - value) : value; } else @@ -142,7 +142,7 @@ brightness_contrast (PixelRegion *srcPR, value = (i > 127) ? (255 - i) : i; power = (bcd->contrast == 127) ? 127 : 127.0 / (127 - bcd->contrast); value = (int) (127.0 * pow ((double) value / 127.0, power)); - value = BOUNDS (value, 0, 255); + value = CLAMP0255 (value); contrast[i] = (i > 127) ? (255 - value) : value; } diff --git a/app/color_balance.c b/app/color_balance.c index 2b6c839252..178ec52906 100644 --- a/app/color_balance.c +++ b/app/color_balance.c @@ -154,25 +154,25 @@ color_balance (PixelRegion *srcPR, b = b_n = s[BLUE_PIX]; r_n += cbd->cyan_red[SHADOWS] * cyan_red_transfer[SHADOWS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[MIDTONES] * cyan_red_transfer[MIDTONES][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[HIGHLIGHTS] * cyan_red_transfer[HIGHLIGHTS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); g_n += cbd->magenta_green[SHADOWS] * magenta_green_transfer[SHADOWS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[MIDTONES] * magenta_green_transfer[MIDTONES][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[HIGHLIGHTS] * magenta_green_transfer[HIGHLIGHTS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); b_n += cbd->yellow_blue[SHADOWS] * yellow_blue_transfer[SHADOWS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[MIDTONES] * yellow_blue_transfer[MIDTONES][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[HIGHLIGHTS] * yellow_blue_transfer[HIGHLIGHTS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); if (cbd->preserve_luminosity) { diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index b7deea7280..facc59be9b 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -513,6 +513,7 @@ undo_push_image_mod (GImage *gimage, int sparse) { long size; + int dwidth, dheight; Undo * new; ImageUndo *image_undo; TileManager *tiles; @@ -524,10 +525,13 @@ undo_push_image_mod (GImage *gimage, if (! tiles_ptr) return FALSE; - x1 = BOUNDS (x1, 0, drawable_width (drawable)); - y1 = BOUNDS (y1, 0, drawable_height (drawable)); - x2 = BOUNDS (x2, 0, drawable_width (drawable)); - y2 = BOUNDS (y2, 0, drawable_height (drawable)); + dwidth = drawable_width (drawable); + dheight = drawable_height (drawable); + + x1 = BOUNDS (x1, 0, dwidth); + y1 = BOUNDS (y1, 0, dheight); + x2 = BOUNDS (x2, 0, dwidth); + y2 = BOUNDS (y2, 0, dheight); tiles = (TileManager *) tiles_ptr; size = tiles->levels[0].width * tiles->levels[0].height * diff --git a/app/core/gimpprojection.h b/app/core/gimpprojection.h index 723a91a386..cd9467d48a 100644 --- a/app/core/gimpprojection.h +++ b/app/core/gimpprojection.h @@ -35,7 +35,7 @@ #define UNSCALE(g,x) ((x * SCALESRC(g)) / SCALEDEST(g)) #define LOWPASS(x) ((x>0) ? x : 0) -#define HIGHPASS(x,y) ((x>y) ? y : x) +/* #define HIGHPASS(x,y) ((x>y) ? y : x) */ /* unused - == MIN */ typedef enum diff --git a/app/curves.c b/app/curves.c index fe057c648f..15512ec6f6 100644 --- a/app/curves.c +++ b/app/curves.c @@ -757,8 +757,8 @@ curves_plot_curve (CurvesDialog *cd, dy += dy2; dy2 += dy3; - newx = BOUNDS ((ROUND (x)), 0, 255); - newy = BOUNDS ((ROUND (y)), 0, 255); + newx = CLAMP0255 (ROUND (x)); + newy = CLAMP0255 (ROUND (y)); /* if this point is different than the last one...then draw it */ if ((lastx != newx) || (lasty != newy)) @@ -914,7 +914,7 @@ curves_smooth_callback (GtkWidget *w, /* pick representative points from the curve and make them control points */ for (i = 0; i <= 8; i++) { - index = BOUNDS ((i * 32), 0, 255); + index = CLAMP0255 (i * 32); cd->points[cd->channel][i * 2][0] = index; cd->points[cd->channel][i * 2][1] = cd->curve[cd->channel][index]; } diff --git a/app/display/gimpdisplay-ops.c b/app/display/gimpdisplay-ops.c index 116141142b..efa65b26e2 100644 --- a/app/display/gimpdisplay-ops.c +++ b/app/display/gimpdisplay-ops.c @@ -154,8 +154,8 @@ gdisplay_shrink_wrap (GDisplay *gdisp) shell_width = width + border_x; shell_height = height + border_y; - x = HIGHPASS (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); - y = HIGHPASS (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); + x = MINIMUM (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); + y = MINIMUM (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); if (x != shell_x || y != shell_y) gdk_window_move (gdisp->shell->window, x, y); @@ -183,8 +183,8 @@ gdisplay_shrink_wrap (GDisplay *gdisp) shell_width = width + border_x; shell_height = height + border_y; - x = HIGHPASS (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); - y = HIGHPASS (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); + x = MINIMUM (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); + y = MINIMUM (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); if (x != shell_x || y != shell_y) gdk_window_move (gdisp->shell->window, x, y); @@ -219,8 +219,8 @@ gdisplay_resize_image (GDisplay *gdisp) /* Calculate the width and height of the new canvas */ sx = SCALE (gdisp, gdisp->gimage->width); sy = SCALE (gdisp, gdisp->gimage->height); - width = HIGHPASS (sx, gdisp->disp_width); - height = HIGHPASS (sy, gdisp->disp_height); + width = MINIMUM (sx, gdisp->disp_width); + height = MINIMUM (sy, gdisp->disp_height); /* if the new dimensions of the ximage are different than the old...resize */ if (width != gdisp->disp_width || height != gdisp->disp_height) diff --git a/app/display/gimpdisplay.h b/app/display/gimpdisplay.h index 723a91a386..cd9467d48a 100644 --- a/app/display/gimpdisplay.h +++ b/app/display/gimpdisplay.h @@ -35,7 +35,7 @@ #define UNSCALE(g,x) ((x * SCALESRC(g)) / SCALEDEST(g)) #define LOWPASS(x) ((x>0) ? x : 0) -#define HIGHPASS(x,y) ((x>y) ? y : x) +/* #define HIGHPASS(x,y) ((x>y) ? y : x) */ /* unused - == MIN */ typedef enum diff --git a/app/gdisplay.h b/app/gdisplay.h index 723a91a386..cd9467d48a 100644 --- a/app/gdisplay.h +++ b/app/gdisplay.h @@ -35,7 +35,7 @@ #define UNSCALE(g,x) ((x * SCALESRC(g)) / SCALEDEST(g)) #define LOWPASS(x) ((x>0) ? x : 0) -#define HIGHPASS(x,y) ((x>y) ? y : x) +/* #define HIGHPASS(x,y) ((x>y) ? y : x) */ /* unused - == MIN */ typedef enum diff --git a/app/gdisplay_ops.c b/app/gdisplay_ops.c index 116141142b..efa65b26e2 100644 --- a/app/gdisplay_ops.c +++ b/app/gdisplay_ops.c @@ -154,8 +154,8 @@ gdisplay_shrink_wrap (GDisplay *gdisp) shell_width = width + border_x; shell_height = height + border_y; - x = HIGHPASS (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); - y = HIGHPASS (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); + x = MINIMUM (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); + y = MINIMUM (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); if (x != shell_x || y != shell_y) gdk_window_move (gdisp->shell->window, x, y); @@ -183,8 +183,8 @@ gdisplay_shrink_wrap (GDisplay *gdisp) shell_width = width + border_x; shell_height = height + border_y; - x = HIGHPASS (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); - y = HIGHPASS (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); + x = MINIMUM (shell_x, BOUNDS (s_width - shell_width, border_x, s_width)); + y = MINIMUM (shell_y, BOUNDS (s_height - shell_height, border_y, s_height)); if (x != shell_x || y != shell_y) gdk_window_move (gdisp->shell->window, x, y); @@ -219,8 +219,8 @@ gdisplay_resize_image (GDisplay *gdisp) /* Calculate the width and height of the new canvas */ sx = SCALE (gdisp, gdisp->gimage->width); sy = SCALE (gdisp, gdisp->gimage->height); - width = HIGHPASS (sx, gdisp->disp_width); - height = HIGHPASS (sy, gdisp->disp_height); + width = MINIMUM (sx, gdisp->disp_width); + height = MINIMUM (sy, gdisp->disp_height); /* if the new dimensions of the ximage are different than the old...resize */ if (width != gdisp->disp_width || height != gdisp->disp_height) diff --git a/app/hue_saturation.c b/app/hue_saturation.c index e09bcbb2c0..9b37b8b4b0 100644 --- a/app/hue_saturation.c +++ b/app/hue_saturation.c @@ -163,7 +163,7 @@ hue_saturation_calculate_transfers (HueSaturationDialog *hsd) value = (hsd->saturation[0] + hsd->saturation[hue + 1]) * 255.0 / 100.0; value = BOUNDS (value, -255, 255); #if 0 - saturation_transfer[hue][i] = (unsigned char) (BOUNDS ((i * (255 + value)) / 255, 0, 255)); + saturation_transfer[hue][i] = (unsigned char) (CLAMP0255 ((i * (255 + value)) / 255)); #else if (value < 0) saturation_transfer[hue][i] = (unsigned char) ((i * (255 + value)) / 255); diff --git a/app/paint-funcs/paint-funcs.c b/app/paint-funcs/paint-funcs.c index 716529182e..623fddb06f 100644 --- a/app/paint-funcs/paint-funcs.c +++ b/app/paint-funcs/paint-funcs.c @@ -725,7 +725,7 @@ divide_pixels (unsigned char *src1, { for (b = 0; b < alpha; b++) { result = ((src1[b] * 256) / (1+src2[b])); - dest[b] = (result > 255) ? 255 : result; + dest[b] = MINIMUM(result, 255); } if (ha1 && ha2) @@ -827,7 +827,9 @@ add_pixels (unsigned char *src1, for (b = 0; b < alpha; b++) { sum = src1[b] + src2[b]; - dest[b] = (sum > 255) ? 255 : sum; + dest[b] = MAX255 (sum); + /* dest[b] = sum | ((sum&256) - ((sum&256) >> 8)); */ + /* dest[b] = (sum > 255) ? 255 : sum; */ /* older, little slower */ } if (ha1 && ha2) diff --git a/app/paint_core.c b/app/paint_core.c index f38908d4dd..cf23777e63 100644 --- a/app/paint_core.c +++ b/app/paint_core.c @@ -603,6 +603,7 @@ paint_core_get_paint_area (paint_core, drawable) int x, y; int x1, y1, x2, y2; int bytes; + int dwidth, dheight; bytes = drawable_has_alpha (drawable) ? drawable_bytes (drawable) : drawable_bytes (drawable) + 1; @@ -611,12 +612,15 @@ paint_core_get_paint_area (paint_core, drawable) x = (int) paint_core->curx - (paint_core->brush->mask->width >> 1); y = (int) paint_core->cury - (paint_core->brush->mask->height >> 1); - x1 = BOUNDS (x - 1, 0, drawable_width (drawable)); - y1 = BOUNDS (y - 1, 0, drawable_height (drawable)); + dwidth = drawable_width (drawable); + dheight = drawable_height (drawable); + + x1 = BOUNDS (x - 1, 0, dwidth); + y1 = BOUNDS (y - 1, 0, dheight); x2 = BOUNDS (x + paint_core->brush->mask->width + 1, - 0, drawable_width (drawable)); + 0, dwidth); y2 = BOUNDS (y + paint_core->brush->mask->height + 1, - 0, drawable_height (drawable)); + 0, dheight); /* configure the canvas buffer */ if ((x2 - x1) && (y2 - y1)) @@ -640,18 +644,24 @@ paint_core_get_orig_image (paint_core, drawable, x1, y1, x2, y2) int h; int refd; int pixelwidth; + int dwidth, dheight; unsigned char * s, * d; void * pr; orig_buf = temp_buf_resize (orig_buf, drawable_bytes (drawable), x1, y1, (x2 - x1), (y2 - y1)); - x1 = BOUNDS (x1, 0, drawable_width (drawable)); - y1 = BOUNDS (y1, 0, drawable_height (drawable)); - x2 = BOUNDS (x2, 0, drawable_width (drawable)); - y2 = BOUNDS (y2, 0, drawable_height (drawable)); + + dwidth = drawable_width (drawable); + dheight = drawable_height (drawable); + + x1 = BOUNDS (x1, 0, dwidth); + y1 = BOUNDS (y1, 0, dheight); + x2 = BOUNDS (x2, 0, dwidth); + y2 = BOUNDS (y2, 0, dheight); /* configure the pixel regions */ - pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE); + pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, + (x2 - x1), (y2 - y1), FALSE); destPR.bytes = orig_buf->bytes; destPR.x = 0; destPR.y = 0; destPR.w = (x2 - x1); destPR.h = (y2 - y1); @@ -659,14 +669,18 @@ paint_core_get_orig_image (paint_core, drawable, x1, y1, x2, y2) destPR.data = temp_buf_data (orig_buf) + (y1 - orig_buf->y) * destPR.rowstride + (x1 - orig_buf->x) * destPR.bytes; - for (pr = pixel_regions_register (2, &srcPR, &destPR); pr != NULL; pr = pixel_regions_process (pr)) + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr != NULL; + pr = pixel_regions_process (pr)) { /* If the undo tile corresponding to this location is valid, use it */ - undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, 0, FALSE, FALSE); + undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, + 0, FALSE, FALSE); if (undo_tile->valid == TRUE) { refd = 1; - undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, 0, TRUE, FALSE); + undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, + 0, TRUE, FALSE); s = undo_tile->data + srcPR.rowstride * (srcPR.y % TILE_HEIGHT) + srcPR.bytes * (srcPR.x % TILE_WIDTH); } @@ -810,7 +824,7 @@ paint_core_subsample_mask (mask, x, y) while (s--) { new_val = *d + ((*m * *k++) >> 8); - *d++ = (new_val > 255) ? 255 : new_val; + *d++ = MINIMUM (new_val, 255); } } m++; diff --git a/app/paint_funcs.c b/app/paint_funcs.c index 716529182e..623fddb06f 100644 --- a/app/paint_funcs.c +++ b/app/paint_funcs.c @@ -725,7 +725,7 @@ divide_pixels (unsigned char *src1, { for (b = 0; b < alpha; b++) { result = ((src1[b] * 256) / (1+src2[b])); - dest[b] = (result > 255) ? 255 : result; + dest[b] = MINIMUM(result, 255); } if (ha1 && ha2) @@ -827,7 +827,9 @@ add_pixels (unsigned char *src1, for (b = 0; b < alpha; b++) { sum = src1[b] + src2[b]; - dest[b] = (sum > 255) ? 255 : sum; + dest[b] = MAX255 (sum); + /* dest[b] = sum | ((sum&256) - ((sum&256) >> 8)); */ + /* dest[b] = (sum > 255) ? 255 : sum; */ /* older, little slower */ } if (ha1 && ha2) diff --git a/app/tools/brightness_contrast.c b/app/tools/brightness_contrast.c index 66bc9d5f84..3e0de2157f 100644 --- a/app/tools/brightness_contrast.c +++ b/app/tools/brightness_contrast.c @@ -133,7 +133,7 @@ brightness_contrast (PixelRegion *srcPR, value = (i > 127) ? (255 - i) : i; value = (int) (127.0 * pow ((double) (value ? value : 1) / 127.0, (double) (127 + bcd->contrast) / 127.0)); - value = BOUNDS (value, 0, 255); + value = CLAMP0255 (value); contrast[i] = (i > 127) ? (255 - value) : value; } else @@ -142,7 +142,7 @@ brightness_contrast (PixelRegion *srcPR, value = (i > 127) ? (255 - i) : i; power = (bcd->contrast == 127) ? 127 : 127.0 / (127 - bcd->contrast); value = (int) (127.0 * pow ((double) value / 127.0, power)); - value = BOUNDS (value, 0, 255); + value = CLAMP0255 (value); contrast[i] = (i > 127) ? (255 - value) : value; } diff --git a/app/tools/color_balance.c b/app/tools/color_balance.c index 2b6c839252..178ec52906 100644 --- a/app/tools/color_balance.c +++ b/app/tools/color_balance.c @@ -154,25 +154,25 @@ color_balance (PixelRegion *srcPR, b = b_n = s[BLUE_PIX]; r_n += cbd->cyan_red[SHADOWS] * cyan_red_transfer[SHADOWS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[MIDTONES] * cyan_red_transfer[MIDTONES][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[HIGHLIGHTS] * cyan_red_transfer[HIGHLIGHTS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); g_n += cbd->magenta_green[SHADOWS] * magenta_green_transfer[SHADOWS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[MIDTONES] * magenta_green_transfer[MIDTONES][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[HIGHLIGHTS] * magenta_green_transfer[HIGHLIGHTS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); b_n += cbd->yellow_blue[SHADOWS] * yellow_blue_transfer[SHADOWS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[MIDTONES] * yellow_blue_transfer[MIDTONES][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[HIGHLIGHTS] * yellow_blue_transfer[HIGHLIGHTS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); if (cbd->preserve_luminosity) { diff --git a/app/tools/curves.c b/app/tools/curves.c index fe057c648f..15512ec6f6 100644 --- a/app/tools/curves.c +++ b/app/tools/curves.c @@ -757,8 +757,8 @@ curves_plot_curve (CurvesDialog *cd, dy += dy2; dy2 += dy3; - newx = BOUNDS ((ROUND (x)), 0, 255); - newy = BOUNDS ((ROUND (y)), 0, 255); + newx = CLAMP0255 (ROUND (x)); + newy = CLAMP0255 (ROUND (y)); /* if this point is different than the last one...then draw it */ if ((lastx != newx) || (lasty != newy)) @@ -914,7 +914,7 @@ curves_smooth_callback (GtkWidget *w, /* pick representative points from the curve and make them control points */ for (i = 0; i <= 8; i++) { - index = BOUNDS ((i * 32), 0, 255); + index = CLAMP0255 (i * 32); cd->points[cd->channel][i * 2][0] = index; cd->points[cd->channel][i * 2][1] = cd->curve[cd->channel][index]; } diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c index 66bc9d5f84..3e0de2157f 100644 --- a/app/tools/gimpbrightnesscontrasttool.c +++ b/app/tools/gimpbrightnesscontrasttool.c @@ -133,7 +133,7 @@ brightness_contrast (PixelRegion *srcPR, value = (i > 127) ? (255 - i) : i; value = (int) (127.0 * pow ((double) (value ? value : 1) / 127.0, (double) (127 + bcd->contrast) / 127.0)); - value = BOUNDS (value, 0, 255); + value = CLAMP0255 (value); contrast[i] = (i > 127) ? (255 - value) : value; } else @@ -142,7 +142,7 @@ brightness_contrast (PixelRegion *srcPR, value = (i > 127) ? (255 - i) : i; power = (bcd->contrast == 127) ? 127 : 127.0 / (127 - bcd->contrast); value = (int) (127.0 * pow ((double) value / 127.0, power)); - value = BOUNDS (value, 0, 255); + value = CLAMP0255 (value); contrast[i] = (i > 127) ? (255 - value) : value; } diff --git a/app/tools/gimpcolorbalancetool.c b/app/tools/gimpcolorbalancetool.c index 2b6c839252..178ec52906 100644 --- a/app/tools/gimpcolorbalancetool.c +++ b/app/tools/gimpcolorbalancetool.c @@ -154,25 +154,25 @@ color_balance (PixelRegion *srcPR, b = b_n = s[BLUE_PIX]; r_n += cbd->cyan_red[SHADOWS] * cyan_red_transfer[SHADOWS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[MIDTONES] * cyan_red_transfer[MIDTONES][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); r_n += cbd->cyan_red[HIGHLIGHTS] * cyan_red_transfer[HIGHLIGHTS][r_n]; - r_n = BOUNDS (r_n, 0, 255); + r_n = CLAMP0255 (r_n); g_n += cbd->magenta_green[SHADOWS] * magenta_green_transfer[SHADOWS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[MIDTONES] * magenta_green_transfer[MIDTONES][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); g_n += cbd->magenta_green[HIGHLIGHTS] * magenta_green_transfer[HIGHLIGHTS][g_n]; - g_n = BOUNDS (g_n, 0, 255); + g_n = CLAMP0255 (g_n); b_n += cbd->yellow_blue[SHADOWS] * yellow_blue_transfer[SHADOWS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[MIDTONES] * yellow_blue_transfer[MIDTONES][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); b_n += cbd->yellow_blue[HIGHLIGHTS] * yellow_blue_transfer[HIGHLIGHTS][b_n]; - b_n = BOUNDS (b_n, 0, 255); + b_n = CLAMP0255 (b_n); if (cbd->preserve_luminosity) { diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c index fe057c648f..15512ec6f6 100644 --- a/app/tools/gimpcurvestool.c +++ b/app/tools/gimpcurvestool.c @@ -757,8 +757,8 @@ curves_plot_curve (CurvesDialog *cd, dy += dy2; dy2 += dy3; - newx = BOUNDS ((ROUND (x)), 0, 255); - newy = BOUNDS ((ROUND (y)), 0, 255); + newx = CLAMP0255 (ROUND (x)); + newy = CLAMP0255 (ROUND (y)); /* if this point is different than the last one...then draw it */ if ((lastx != newx) || (lasty != newy)) @@ -914,7 +914,7 @@ curves_smooth_callback (GtkWidget *w, /* pick representative points from the curve and make them control points */ for (i = 0; i <= 8; i++) { - index = BOUNDS ((i * 32), 0, 255); + index = CLAMP0255 (i * 32); cd->points[cd->channel][i * 2][0] = index; cd->points[cd->channel][i * 2][1] = cd->curve[cd->channel][index]; } diff --git a/app/tools/gimphuesaturationtool.c b/app/tools/gimphuesaturationtool.c index e09bcbb2c0..9b37b8b4b0 100644 --- a/app/tools/gimphuesaturationtool.c +++ b/app/tools/gimphuesaturationtool.c @@ -163,7 +163,7 @@ hue_saturation_calculate_transfers (HueSaturationDialog *hsd) value = (hsd->saturation[0] + hsd->saturation[hue + 1]) * 255.0 / 100.0; value = BOUNDS (value, -255, 255); #if 0 - saturation_transfer[hue][i] = (unsigned char) (BOUNDS ((i * (255 + value)) / 255, 0, 255)); + saturation_transfer[hue][i] = (unsigned char) (CLAMP0255 ((i * (255 + value)) / 255)); #else if (value < 0) saturation_transfer[hue][i] = (unsigned char) ((i * (255 + value)) / 255); diff --git a/app/tools/hue_saturation.c b/app/tools/hue_saturation.c index e09bcbb2c0..9b37b8b4b0 100644 --- a/app/tools/hue_saturation.c +++ b/app/tools/hue_saturation.c @@ -163,7 +163,7 @@ hue_saturation_calculate_transfers (HueSaturationDialog *hsd) value = (hsd->saturation[0] + hsd->saturation[hue + 1]) * 255.0 / 100.0; value = BOUNDS (value, -255, 255); #if 0 - saturation_transfer[hue][i] = (unsigned char) (BOUNDS ((i * (255 + value)) / 255, 0, 255)); + saturation_transfer[hue][i] = (unsigned char) (CLAMP0255 ((i * (255 + value)) / 255)); #else if (value < 0) saturation_transfer[hue][i] = (unsigned char) ((i * (255 + value)) / 255); diff --git a/app/tools/paint_core.c b/app/tools/paint_core.c index f38908d4dd..cf23777e63 100644 --- a/app/tools/paint_core.c +++ b/app/tools/paint_core.c @@ -603,6 +603,7 @@ paint_core_get_paint_area (paint_core, drawable) int x, y; int x1, y1, x2, y2; int bytes; + int dwidth, dheight; bytes = drawable_has_alpha (drawable) ? drawable_bytes (drawable) : drawable_bytes (drawable) + 1; @@ -611,12 +612,15 @@ paint_core_get_paint_area (paint_core, drawable) x = (int) paint_core->curx - (paint_core->brush->mask->width >> 1); y = (int) paint_core->cury - (paint_core->brush->mask->height >> 1); - x1 = BOUNDS (x - 1, 0, drawable_width (drawable)); - y1 = BOUNDS (y - 1, 0, drawable_height (drawable)); + dwidth = drawable_width (drawable); + dheight = drawable_height (drawable); + + x1 = BOUNDS (x - 1, 0, dwidth); + y1 = BOUNDS (y - 1, 0, dheight); x2 = BOUNDS (x + paint_core->brush->mask->width + 1, - 0, drawable_width (drawable)); + 0, dwidth); y2 = BOUNDS (y + paint_core->brush->mask->height + 1, - 0, drawable_height (drawable)); + 0, dheight); /* configure the canvas buffer */ if ((x2 - x1) && (y2 - y1)) @@ -640,18 +644,24 @@ paint_core_get_orig_image (paint_core, drawable, x1, y1, x2, y2) int h; int refd; int pixelwidth; + int dwidth, dheight; unsigned char * s, * d; void * pr; orig_buf = temp_buf_resize (orig_buf, drawable_bytes (drawable), x1, y1, (x2 - x1), (y2 - y1)); - x1 = BOUNDS (x1, 0, drawable_width (drawable)); - y1 = BOUNDS (y1, 0, drawable_height (drawable)); - x2 = BOUNDS (x2, 0, drawable_width (drawable)); - y2 = BOUNDS (y2, 0, drawable_height (drawable)); + + dwidth = drawable_width (drawable); + dheight = drawable_height (drawable); + + x1 = BOUNDS (x1, 0, dwidth); + y1 = BOUNDS (y1, 0, dheight); + x2 = BOUNDS (x2, 0, dwidth); + y2 = BOUNDS (y2, 0, dheight); /* configure the pixel regions */ - pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE); + pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, + (x2 - x1), (y2 - y1), FALSE); destPR.bytes = orig_buf->bytes; destPR.x = 0; destPR.y = 0; destPR.w = (x2 - x1); destPR.h = (y2 - y1); @@ -659,14 +669,18 @@ paint_core_get_orig_image (paint_core, drawable, x1, y1, x2, y2) destPR.data = temp_buf_data (orig_buf) + (y1 - orig_buf->y) * destPR.rowstride + (x1 - orig_buf->x) * destPR.bytes; - for (pr = pixel_regions_register (2, &srcPR, &destPR); pr != NULL; pr = pixel_regions_process (pr)) + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr != NULL; + pr = pixel_regions_process (pr)) { /* If the undo tile corresponding to this location is valid, use it */ - undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, 0, FALSE, FALSE); + undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, + 0, FALSE, FALSE); if (undo_tile->valid == TRUE) { refd = 1; - undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, 0, TRUE, FALSE); + undo_tile = tile_manager_get_tile (undo_tiles, srcPR.x, srcPR.y, + 0, TRUE, FALSE); s = undo_tile->data + srcPR.rowstride * (srcPR.y % TILE_HEIGHT) + srcPR.bytes * (srcPR.x % TILE_WIDTH); } @@ -810,7 +824,7 @@ paint_core_subsample_mask (mask, x, y) while (s--) { new_val = *d + ((*m * *k++) >> 8); - *d++ = (new_val > 255) ? 255 : new_val; + *d++ = MINIMUM (new_val, 255); } } m++; diff --git a/app/undo.c b/app/undo.c index b7deea7280..facc59be9b 100644 --- a/app/undo.c +++ b/app/undo.c @@ -513,6 +513,7 @@ undo_push_image_mod (GImage *gimage, int sparse) { long size; + int dwidth, dheight; Undo * new; ImageUndo *image_undo; TileManager *tiles; @@ -524,10 +525,13 @@ undo_push_image_mod (GImage *gimage, if (! tiles_ptr) return FALSE; - x1 = BOUNDS (x1, 0, drawable_width (drawable)); - y1 = BOUNDS (y1, 0, drawable_height (drawable)); - x2 = BOUNDS (x2, 0, drawable_width (drawable)); - y2 = BOUNDS (y2, 0, drawable_height (drawable)); + dwidth = drawable_width (drawable); + dheight = drawable_height (drawable); + + x1 = BOUNDS (x1, 0, dwidth); + y1 = BOUNDS (y1, 0, dheight); + x2 = BOUNDS (x2, 0, dwidth); + y2 = BOUNDS (y2, 0, dheight); tiles = (TileManager *) tiles_ptr; size = tiles->levels[0].width * tiles->levels[0].height *