Attempt to speed-up and/or sanitize MAX/MIN/CLAMP macro usage throughout

* 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.
This commit is contained in:
Adam D. Moss 1998-07-24 18:52:03 +00:00
parent d982011311
commit 814a4285c6
28 changed files with 171 additions and 115 deletions

View File

@ -1,3 +1,11 @@
Fri Jul 24 19:36:33 BST 1998 Adam D. Moss <adam@gimp.org>
* 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 <lewing@gimp.org>
* app/gdisplay.c (gdisplay_update_cursor): Fixed a string

View File

@ -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,

View File

@ -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)
{

View File

@ -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];
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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 *

View File

@ -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

View File

@ -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];
}

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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++;

View File

@ -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)

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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];
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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];
}

View File

@ -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);

View File

@ -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);

View File

@ -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++;

View File

@ -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 *