From 83ae8866097c5b687a706371ed69e4031c830e7c Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 17 Nov 2003 17:33:14 +0000 Subject: [PATCH] removed the addition of 0.001 that isn't correct for use with integers 2003-11-17 Sven Neumann * libgimpcolor/gimprgb.h (GIMP_RGB_INTENSITY): removed the addition of 0.001 that isn't correct for use with integers (should be 0.5 then) and just plain wrong for use with floats/doubles. * app/base/temp-buf.c * app/core/gimpdrawable.c * app/core/gimpimage-convert.c * app/core/gimpimage.c * plug-ins/common/aa.c * plug-ins/common/engrave.c * plug-ins/common/gradmap.c * plug-ins/common/newsprint.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/pagecurl/pagecurl.c: add 0.5 to the result of GIMP_RGB_INTENSITY() in all places that use it with integers. --- ChangeLog | 19 +++++++++++++++++++ app/base/temp-buf.c | 4 ++-- app/core/gimpdrawable.c | 2 +- app/core/gimpimage-convert.c | 4 ++-- app/core/gimpimage.c | 26 +++++++++++++++++--------- plug-ins/common/aa.c | 8 ++++---- plug-ins/common/engrave.c | 2 +- plug-ins/common/gradmap.c | 4 ++-- plug-ins/common/newsprint.c | 2 +- plug-ins/gflare/gflare.c | 2 +- plug-ins/gfli/gfli.c | 2 +- plug-ins/pagecurl/pagecurl.c | 4 ++-- 12 files changed, 53 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index e80928c4ef..cb682d3762 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2003-11-17 Sven Neumann + + * libgimpcolor/gimprgb.h (GIMP_RGB_INTENSITY): removed the + addition of 0.001 that isn't correct for use with integers (should + be 0.5 then) and just plain wrong for use with floats/doubles. + + * app/base/temp-buf.c + * app/core/gimpdrawable.c + * app/core/gimpimage-convert.c + * app/core/gimpimage.c + * plug-ins/common/aa.c + * plug-ins/common/engrave.c + * plug-ins/common/gradmap.c + * plug-ins/common/newsprint.c + * plug-ins/gflare/gflare.c + * plug-ins/gfli/gfli.c + * plug-ins/pagecurl/pagecurl.c: add 0.5 to the result of + GIMP_RGB_INTENSITY() in all places that use it with integers. + 2003-11-17 Michael Natterer * modules/colorsel_triangle.c (colorsel_triangle_update_previews): diff --git a/app/base/temp-buf.c b/app/base/temp-buf.c index 7625e7690f..9b3be04fe0 100644 --- a/app/base/temp-buf.c +++ b/app/base/temp-buf.c @@ -135,7 +135,7 @@ temp_buf_to_gray (TempBuf *src_buf, g_return_if_fail (src_buf->bytes == 3); while (num_pixels--) { - pix = GIMP_RGB_INTENSITY (src[0], src[1], src[2]); + pix = GIMP_RGB_INTENSITY (src[0], src[1], src[2]) + 0.5; *dest++ = (guchar) pix; src += 3; @@ -146,7 +146,7 @@ temp_buf_to_gray (TempBuf *src_buf, g_return_if_fail (src_buf->bytes == 4); while (num_pixels--) { - pix = GIMP_RGB_INTENSITY (src[0], src[1], src[2]); + pix = GIMP_RGB_INTENSITY (src[0], src[1], src[2]) + 0.5; *dest++ = (guchar) pix; *dest++ = src[3]; /* alpha channel */ diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c index a61455abfd..100fc15400 100644 --- a/app/core/gimpdrawable.c +++ b/app/core/gimpdrawable.c @@ -788,7 +788,7 @@ gimp_drawable_fill (GimpDrawable *drawable, case GIMP_GRAY: c[GRAY_PIX] = GIMP_RGB_INTENSITY (c[RED_PIX], c[GREEN_PIX], - c[BLUE_PIX]); + c[BLUE_PIX]) + 0.5; c[ALPHA_G_PIX] = c[ALPHA_PIX]; if (drawable_type != GIMP_GRAYA_IMAGE) diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c index c46bb7a26e..7de98c84d5 100644 --- a/app/core/gimpimage-convert.c +++ b/app/core/gimpimage-convert.c @@ -1197,7 +1197,7 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable, { val = GIMP_RGB_INTENSITY (s[RED_PIX], s[GREEN_PIX], - s[BLUE_PIX]); + s[BLUE_PIX]) + 0.5; *d++ = (guchar) val; s += 3; if (has_alpha) @@ -1219,7 +1219,7 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable, offset = *s++ * 3; val = GIMP_RGB_INTENSITY (cmap[offset+0], cmap[offset+1], - cmap[offset+2]); + cmap[offset+2]) + 0.5; *d++ = (guchar) val; if (has_alpha) *d++ = *s++; diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 654d370403..f01982f636 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -1605,7 +1605,8 @@ gimp_image_get_foreground (const GimpImage *gimage, g_return_if_fail (! drawable || GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (fg != NULL); - gimp_context_get_foreground (gimp_get_current_context (gimage->gimp), &color); + gimp_context_get_foreground (gimp_get_current_context (gimage->gimp), + &color); gimp_rgb_get_uchar (&color, &pfg[0], &pfg[1], &pfg[2]); @@ -1624,7 +1625,8 @@ gimp_image_get_background (const GimpImage *gimage, g_return_if_fail (! drawable || GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (bg != NULL); - gimp_context_get_background (gimp_get_current_context (gimage->gimp), &color); + gimp_context_get_background (gimp_get_current_context (gimage->gimp), + &color); gimp_rgb_get_uchar (&color, &pbg[0], &pbg[1], &pbg[2]); @@ -1641,21 +1643,24 @@ gimp_image_get_color (const GimpImage *src_gimage, switch (src_type) { - case GIMP_RGB_IMAGE: case GIMP_RGBA_IMAGE: + case GIMP_RGB_IMAGE: + case GIMP_RGBA_IMAGE: /* Straight copy */ *rgb++ = *src++; *rgb++ = *src++; *rgb = *src; break; - case GIMP_GRAY_IMAGE: case GIMP_GRAYA_IMAGE: + case GIMP_GRAY_IMAGE: + case GIMP_GRAYA_IMAGE: /* Gray to RG&B */ *rgb++ = *src; *rgb++ = *src; *rgb = *src; break; - case GIMP_INDEXED_IMAGE: case GIMP_INDEXEDA_IMAGE: + case GIMP_INDEXED_IMAGE: + case GIMP_INDEXEDA_IMAGE: /* Indexed palette lookup */ { gint index = *src * 3; @@ -1702,7 +1707,7 @@ gimp_image_transform_color (const GimpImage *dest_gimage, /* NTSC conversion */ *dest = GIMP_RGB_INTENSITY (src[RED_PIX], src[GREEN_PIX], - src[BLUE_PIX]); + src[BLUE_PIX]) + 0.5; break; case GIMP_INDEXED_IMAGE: @@ -1719,19 +1724,22 @@ gimp_image_transform_color (const GimpImage *dest_gimage, case GIMP_GRAY: switch (dest_type) { - case GIMP_RGB_IMAGE: case GIMP_RGBA_IMAGE: + case GIMP_RGB_IMAGE: + case GIMP_RGBA_IMAGE: /* Gray to RG&B */ *dest++ = *src; *dest++ = *src; *dest++ = *src; break; - case GIMP_GRAY_IMAGE: case GIMP_GRAYA_IMAGE: + case GIMP_GRAY_IMAGE: + case GIMP_GRAYA_IMAGE: /* Straight copy */ *dest = *src; break; - case GIMP_INDEXED_IMAGE: case GIMP_INDEXEDA_IMAGE: + case GIMP_INDEXED_IMAGE: + case GIMP_INDEXEDA_IMAGE: /* Least squares method */ *dest = gimp_image_color_hash_rgb_to_indexed (dest_gimage, src[GRAY_PIX], diff --git a/plug-ins/common/aa.c b/plug-ins/common/aa.c index fc58ca581f..1b09265c5e 100644 --- a/plug-ins/common/aa.c +++ b/plug-ins/common/aa.c @@ -298,15 +298,15 @@ gimp2aa (gint32 drawable_ID, case 3: /* RGB */ for (x = 0, p = buffer; x < width; x++, p += 3) - aa_putpixel (context, x, y, GIMP_RGB_INTENSITY (p[0], p[1], p[2])); + aa_putpixel (context, x, y, + GIMP_RGB_INTENSITY (p[0], p[1], p[2]) + 0.5); break; case 4: /* RGBA, blend over black */ for (x = 0, p = buffer; x < width; x++, p += 4) aa_putpixel (context, x, y, - ((guchar) GIMP_RGB_INTENSITY (p[0], - p[1], - p[2]) * (p[3] + 1)) >> 8); + ((guchar) (GIMP_RGB_INTENSITY (p[0], p[1], p[2]) + 0.5) + * (p[3] + 1)) >> 8); break; default: diff --git a/plug-ins/common/engrave.c b/plug-ins/common/engrave.c index c72628d846..b8ce3c6a14 100644 --- a/plug-ins/common/engrave.c +++ b/plug-ins/common/engrave.c @@ -325,7 +325,7 @@ engrave_large (GimpDrawable *drawable, average[b] = (guchar) (average[b] / count); if (bpp < 3) - inten = average[0]/254.0*height; + inten = average[0] / 254.0 * height; else inten = GIMP_RGB_INTENSITY (average[0], average[1], diff --git a/plug-ins/common/gradmap.c b/plug-ins/common/gradmap.c index c86ebf39b2..01d552b2b7 100644 --- a/plug-ins/common/gradmap.c +++ b/plug-ins/common/gradmap.c @@ -66,7 +66,7 @@ static char rcsid[] = "$Id$"; #define NSAMPLES 256 #define TILE_CACHE_SIZE 32 -#define LUMINOSITY(X) (GIMP_RGB_INTENSITY (X[0], X[1], X[2])) +#define LUMINOSITY(X) (GIMP_RGB_INTENSITY (X[0], X[1], X[2]) + 0.5) static GimpRunMode run_mode; @@ -178,7 +178,7 @@ typedef struct { gboolean has_alpha; } GradMapParam_t; -static void +static void gradmap_func (const guchar *src, guchar *dest, gint bpp, diff --git a/plug-ins/common/newsprint.c b/plug-ins/common/newsprint.c index 785f05782e..ad07476a2b 100644 --- a/plug-ins/common/newsprint.c +++ b/plug-ins/common/newsprint.c @@ -1918,7 +1918,7 @@ do { \ data[3] = data[0]; /* save orig for later */ data[0] = GIMP_RGB_INTENSITY (data[0], data[1], - data[2]); + data[2]) + 0.5; break; default: diff --git a/plug-ins/gflare/gflare.c b/plug-ins/gflare/gflare.c index 36a3b6e232..73081dffa3 100644 --- a/plug-ins/gflare/gflare.c +++ b/plug-ins/gflare/gflare.c @@ -70,7 +70,7 @@ static char rcsid[] = "$Id$"; #define DEBUG_PRINT(X) #endif -#define LUMINOSITY(PIX) (GIMP_RGB_INTENSITY (PIX[0], PIX[1], PIX[2])) +#define LUMINOSITY(PIX) (GIMP_RGB_INTENSITY (PIX[0], PIX[1], PIX[2]) + 0.5) #define OFFSETOF(t,f) ((int) ((char*) &((t*) 0)->f)) #define RESPONSE_RESCAN 1 diff --git a/plug-ins/gfli/gfli.c b/plug-ins/gfli/gfli.c index d0e400f29f..0915bc53e2 100644 --- a/plug-ins/gfli/gfli.c +++ b/plug-ins/gfli/gfli.c @@ -642,7 +642,7 @@ save_image (const gchar *filename, { cm[i*3+0] = cm[i*3+1] = cm[i*3+2] = i; } - bg = GIMP_RGB_INTENSITY (red, green, blue); + bg = GIMP_RGB_INTENSITY (red, green, blue) + 0.5; break; case GIMP_INDEXED: diff --git a/plug-ins/pagecurl/pagecurl.c b/plug-ins/pagecurl/pagecurl.c index fb660bb6e3..1f7259ed50 100644 --- a/plug-ins/pagecurl/pagecurl.c +++ b/plug-ins/pagecurl/pagecurl.c @@ -782,10 +782,10 @@ do_curl_effect (void) fore_grayval = GIMP_RGB_INTENSITY (fore_color[0], fore_color[1], - fore_color[2]); + fore_color[2]) + 0.5; back_grayval = GIMP_RGB_INTENSITY (back_color[0], back_color[1], - back_color[2]); + back_color[2]) + 0.5; /* Gradient Samples */ if (curl.do_curl_gradient)