diff --git a/ChangeLog b/ChangeLog index 29a7dac08d..ad7091f996 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,43 @@ +2005-08-03 Sven Neumann + + * libgimpcolor/gimprgb.[ch]: deprecated RGB intensity functions + and definitions. These coefficients do not accurately compute + luminance for contemporary monitors. Instead the coefficients from + the sRGB spec should be used which have now been added. + + * libgimpcolor/gimpcolor.def: updated. + + * libgimp/gimpdrawable.c + * libgimp/gimppixelfetcher.c + * app/base/colorize.c + * app/base/levels.c + * app/base/temp-buf.c + * app/core/gimpdrawable-blend.c + * app/core/gimpdrawable-convert.c + * app/core/gimpdrawable-desaturate.c + * app/core/gimpimage-convert.c + * app/core/gimpimage.c + * app/gui/splash.c + * app/widgets/gimpgradienteditor.c + * modules/colorsel_triangle.c + * plug-ins/common/aa.c + * plug-ins/common/bumpmap.c + * plug-ins/common/colorify.c + * plug-ins/common/despeckle.c + * plug-ins/common/displace.c + * plug-ins/common/engrave.c + * plug-ins/common/gradmap.c + * plug-ins/common/grid.c + * plug-ins/common/mng.c + * plug-ins/common/newsprint.c + * plug-ins/common/png.c + * plug-ins/common/whirlpinch.c + * plug-ins/gflare/gflare.c + * plug-ins/gfli/gfli.c + * plug-ins/maze/handy.c + * plug-ins/pagecurl/pagecurl.c: use gimp_rgb_luminance() and + friends instead of the deprecated intensity functions. + 2005-08-03 Michael Natterer * libgimp/gimpprocbrowserdialog.[ch]: removed all parameters from diff --git a/app/base/colorize.c b/app/base/colorize.c index 68bc5dbe03..79f5a5af70 100644 --- a/app/base/colorize.c +++ b/app/base/colorize.c @@ -42,9 +42,9 @@ colorize_init (Colorize *colorize) for (i = 0; i < 256; i ++) { - colorize->lum_red_lookup[i] = i * GIMP_RGB_INTENSITY_RED; - colorize->lum_green_lookup[i] = i * GIMP_RGB_INTENSITY_GREEN; - colorize->lum_blue_lookup[i] = i * GIMP_RGB_INTENSITY_BLUE; + colorize->lum_red_lookup[i] = i * GIMP_RGB_LUMINANCE_RED; + colorize->lum_green_lookup[i] = i * GIMP_RGB_LUMINANCE_GREEN; + colorize->lum_blue_lookup[i] = i * GIMP_RGB_LUMINANCE_BLUE; } } diff --git a/app/base/levels.c b/app/base/levels.c index 6ebc99fd17..db4d7d63e2 100644 --- a/app/base/levels.c +++ b/app/base/levels.c @@ -194,7 +194,7 @@ levels_adjust_by_colors (Levels *levels, guchar lightness; /* Calculate lightness value */ - lightness = GIMP_RGB_INTENSITY (gray[0], gray[1], gray[2]); + lightness = GIMP_RGB_LUMINANCE (gray[0], gray[1], gray[2]); input = levels_input_from_color (channel, gray); diff --git a/app/base/temp-buf.c b/app/base/temp-buf.c index 78753ad18c..d03c207fa2 100644 --- a/app/base/temp-buf.c +++ b/app/base/temp-buf.c @@ -116,7 +116,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]) + 0.5; + pix = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5; *dest++ = (guchar) pix; src += 3; @@ -127,7 +127,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]) + 0.5; + pix = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5; *dest++ = (guchar) pix; *dest++ = src[3]; /* alpha channel */ diff --git a/app/core/gimpdrawable-blend.c b/app/core/gimpdrawable-blend.c index 1a4ac3e09b..756f60f9a2 100644 --- a/app/core/gimpdrawable-blend.c +++ b/app/core/gimpdrawable-blend.c @@ -820,7 +820,7 @@ gradient_put_pixel (gint x, else { /* Convert to grayscale */ - gdouble gray = gimp_rgb_intensity (color); + gdouble gray = gimp_rgb_luminance (color); if (ppd->dither_rand) { @@ -1078,7 +1078,7 @@ gradient_fill_single_region_gray (RenderBlendData *rbd, gradient_render_pixel (x, y, &color, rbd); - *dest++ = gimp_rgb_intensity_uchar (&color); + *dest++ = gimp_rgb_luminance_uchar (&color); *dest++ = ROUND (color.a * 255.0); } } @@ -1102,7 +1102,7 @@ gradient_fill_single_region_gray_dither (RenderBlendData *rbd, gradient_render_pixel (x, y, &color, rbd); - gray = gimp_rgb_intensity (&color); + gray = gimp_rgb_luminance (&color); *dest++ = gray * 255.0 + (gdouble) (i & 0xff) / 256.0; i >>= 8; *dest++ = color.a * 255.0 + (gdouble) (i & 0xff) / 256.0; diff --git a/app/core/gimpdrawable-convert.c b/app/core/gimpdrawable-convert.c index 3c570cd39f..dadd0da281 100644 --- a/app/core/gimpdrawable-convert.c +++ b/app/core/gimpdrawable-convert.c @@ -186,7 +186,7 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable, d = dest; for (col = 0; col < srcPR.w; col++) { - val = GIMP_RGB_INTENSITY (s[RED_PIX], + val = GIMP_RGB_LUMINANCE (s[RED_PIX], s[GREEN_PIX], s[BLUE_PIX]) + 0.5; *d++ = (guchar) val; @@ -217,7 +217,7 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable, for (col = 0; col < srcPR.w; col++) { offset = *s++ * 3; - val = GIMP_RGB_INTENSITY (cmap[offset+0], + val = GIMP_RGB_LUMINANCE (cmap[offset+0], cmap[offset+1], cmap[offset+2]) + 0.5; *d++ = (guchar) val; diff --git a/app/core/gimpdrawable-desaturate.c b/app/core/gimpdrawable-desaturate.c index 3c14b0d6de..4a826885fc 100644 --- a/app/core/gimpdrawable-desaturate.c +++ b/app/core/gimpdrawable-desaturate.c @@ -161,7 +161,7 @@ desaturate_region_luminosity (gpointer data, for (j = 0; j < srcPR->w; j++) { - gint luminosity = GIMP_RGB_INTENSITY (s[RED_PIX], + gint luminosity = GIMP_RGB_LUMINANCE (s[RED_PIX], s[GREEN_PIX], s[BLUE_PIX]) + 0.5; diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c index 1c1c88dd85..0592d657d7 100644 --- a/app/core/gimpimage-convert.c +++ b/app/core/gimpimage-convert.c @@ -760,8 +760,8 @@ color_quicksort (const void *c1, Color *color1 = (Color *)c1; Color *color2 = (Color *)c2; - double v1 = GIMP_RGB_INTENSITY (color1->red, color1->green, color1->blue); - double v2 = GIMP_RGB_INTENSITY (color2->red, color2->green, color2->blue); + double v1 = GIMP_RGB_LUMINANCE (color1->red, color1->green, color1->blue); + double v2 = GIMP_RGB_LUMINANCE (color2->red, color2->green, color2->blue); if (v1 < v2) return -1; diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index b909a09b79..8375c458db 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -2064,7 +2064,7 @@ gimp_image_transform_color (const GimpImage *dest_gimage, case GIMP_GRAY_IMAGE: case GIMP_GRAYA_IMAGE: /* NTSC conversion */ - *dest = GIMP_RGB_INTENSITY (src[RED_PIX], + *dest = GIMP_RGB_LUMINANCE (src[RED_PIX], src[GREEN_PIX], src[BLUE_PIX]) + 0.5; break; diff --git a/app/gui/splash.c b/app/gui/splash.c index 397f817167..cdfb863f83 100644 --- a/app/gui/splash.c +++ b/app/gui/splash.c @@ -370,7 +370,7 @@ splash_average_bottom (GtkWidget *widget, gint width, height; gint rowstride; gint channels; - gint intensity; + gint luminance; gint count; guint sum[3] = { 0, 0, 0 }; @@ -404,13 +404,13 @@ splash_average_bottom (GtkWidget *widget, pixels += rowstride; } - intensity = GIMP_RGB_INTENSITY (sum[0] / count, + luminance = GIMP_RGB_LUMINANCE (sum[0] / count, sum[1] / count, sum[2] / count); - intensity = CLAMP0255 (intensity > 127 ? intensity - 223 : intensity + 223); + luminance = CLAMP0255 (luminance > 127 ? luminance - 223 : luminance + 223); - color->red = color->green = color->blue = (intensity << 8 | intensity); + color->red = color->green = color->blue = (luminance << 8 | luminance); return gdk_colormap_alloc_color (gtk_widget_get_colormap (widget), color, FALSE, TRUE); diff --git a/app/widgets/gimpgradienteditor.c b/app/widgets/gimpgradienteditor.c index b6259a4e6c..63f1ac8eba 100644 --- a/app/widgets/gimpgradienteditor.c +++ b/app/widgets/gimpgradienteditor.c @@ -942,14 +942,12 @@ view_set_hint (GimpGradientEditor *editor, gimp_rgb_to_hsv (&rgb, &hsv); str1 = g_strdup_printf (_("Position: %0.6f"), xpos); - str2 = g_strdup_printf (_("RGB (%0.3f, %0.3f, %0.3f)"), rgb.r, rgb.g, rgb.b); - str3 = g_strdup_printf (_("HSV (%0.3f, %0.3f, %0.3f)"), hsv.h * 360.0, hsv.s, hsv.v); - str4 = g_strdup_printf (_("Intensity: %0.3f Opacity: %0.3f"), - GIMP_RGB_INTENSITY (rgb.r, rgb.g, rgb.b), rgb.a); + str4 = g_strdup_printf (_("Luminance: %0.3f Opacity: %0.3f"), + GIMP_RGB_LUMINANCE (rgb.r, rgb.g, rgb.b), rgb.a); gradient_editor_set_hint (editor, str1, str2, str3, str4); diff --git a/devel-docs/ChangeLog b/devel-docs/ChangeLog index 96f1e604a3..07351bd75c 100644 --- a/devel-docs/ChangeLog +++ b/devel-docs/ChangeLog @@ -1,3 +1,9 @@ +2005-08-03 Sven Neumann + + * libgimpcolor/libgimpcolor-sections.txt + * libgimpcolor/tmpl/gimprgb.sgml: added gimp_rgb_luminance() and + friends. + 2005-07-22 Sven Neumann * libgimpwidgets/libgimpwidgets-sections.txt diff --git a/devel-docs/libgimpcolor/libgimpcolor-sections.txt b/devel-docs/libgimpcolor/libgimpcolor-sections.txt index a6afc16789..39500a2e50 100644 --- a/devel-docs/libgimpcolor/libgimpcolor-sections.txt +++ b/devel-docs/libgimpcolor/libgimpcolor-sections.txt @@ -63,6 +63,8 @@ gimp_rgb_max gimp_rgb_min gimp_rgb_clamp gimp_rgb_gamma +gimp_rgb_luminance +gimp_rgb_luminance_uchar gimp_rgb_intensity gimp_rgb_intensity_uchar gimp_rgb_composite @@ -74,6 +76,10 @@ gimp_rgba_add gimp_rgba_subtract gimp_rgba_multiply gimp_rgba_distance +GIMP_RGB_LUMINANCE +GIMP_RGB_LUMINANCE_RED +GIMP_RGB_LUMINANCE_GREEN +GIMP_RGB_LUMINANCE_BLUE GIMP_RGB_INTENSITY GIMP_RGB_INTENSITY_RED GIMP_RGB_INTENSITY_GREEN diff --git a/devel-docs/libgimpcolor/tmpl/gimprgb.sgml b/devel-docs/libgimpcolor/tmpl/gimprgb.sgml index 3a3999c57b..2d93015eb2 100644 --- a/devel-docs/libgimpcolor/tmpl/gimprgb.sgml +++ b/devel-docs/libgimpcolor/tmpl/gimprgb.sgml @@ -193,6 +193,24 @@ Definitions and Functions relating to RGB colors. @gamma: + + + + + +@rgb: +@Returns: + + + + + + + +@rgb: +@Returns: + + @@ -305,6 +323,37 @@ Definitions and Functions relating to RGB colors. @Returns: + + + + + +@r: +@g: +@b: + + + + + + + + + + + + + + + + + + + + + + + This macro calculates the intensity of an RGB value based on diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c index 3f7de2ab9c..da74a063d0 100644 --- a/libgimp/gimpdrawable.c +++ b/libgimp/gimpdrawable.c @@ -248,12 +248,12 @@ gimp_drawable_get_color_uchar (gint32 drawable_ID, break; case GIMP_GRAY_IMAGE: - color_uchar[0] = gimp_rgb_intensity_uchar (color); + color_uchar[0] = gimp_rgb_luminance_uchar (color); color_uchar[1] = 255; break; case GIMP_GRAYA_IMAGE: - color_uchar[0] = gimp_rgb_intensity_uchar (color); + color_uchar[0] = gimp_rgb_luminance_uchar (color); gimp_rgba_get_uchar (color, NULL, NULL, NULL, &color_uchar[1]); break; diff --git a/libgimp/gimppixelfetcher.c b/libgimp/gimppixelfetcher.c index 621355e697..45a1579fcb 100644 --- a/libgimp/gimppixelfetcher.c +++ b/libgimp/gimppixelfetcher.c @@ -160,7 +160,7 @@ gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf, { case 2: pf->bg_color[1] = 255; case 1: - pf->bg_color[0] = gimp_rgb_intensity_uchar (color); + pf->bg_color[0] = gimp_rgb_luminance_uchar (color); break; case 4: pf->bg_color[3] = 255; diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def index 2b354c6930..c96571753e 100644 --- a/libgimpcolor/gimpcolor.def +++ b/libgimpcolor/gimpcolor.def @@ -36,6 +36,8 @@ EXPORTS gimp_rgb_intensity gimp_rgb_intensity_uchar gimp_rgb_list_names + gimp_rgb_luminance + gimp_rgb_luminance_uchar gimp_rgb_max gimp_rgb_min gimp_rgb_multiply diff --git a/libgimpcolor/gimprgb.c b/libgimpcolor/gimprgb.c index a62c39c01a..378ef6c841 100644 --- a/libgimpcolor/gimprgb.c +++ b/libgimpcolor/gimprgb.c @@ -25,6 +25,7 @@ #include "gimpcolortypes.h" +#undef GIMP_DISABLE_DEPRECATED /* for GIMP_RGB_INTENSITY() */ #include "gimprgb.h" @@ -228,6 +229,50 @@ gimp_rgb_gamma (GimpRGB *rgb, rgb->b = pow (rgb->b, ig); } +/** + * gimp_rgb_luminance: + * @rgb: + * + * Return value: the luminous intensity of the range from 0.0 to 1.0. + * + * Since: GIMP 2.4 + **/ +gdouble +gimp_rgb_luminance (const GimpRGB *rgb) +{ + gdouble luminance; + + g_return_val_if_fail (rgb != NULL, 0.0); + + luminance = GIMP_RGB_LUMINANCE (rgb->r, rgb->g, rgb->b); + + return CLAMP (luminance, 0.0, 1.0); +} + +/** + * gimp_rgb_luminance_uchar: + * @rgb: + * + * Return value: the luminous intensity in the range from 0 to 255. + * + * Since: GIMP 2.4 + **/ +guchar +gimp_rgb_luminance_uchar (const GimpRGB *rgb) +{ + g_return_val_if_fail (rgb != NULL, 0); + + return ROUND (gimp_rgb_luminance (rgb) * 255.0); +} + +/** + * gimp_rgb_intensity: + * @rgb: + * + * This function is deprecated! Use gimp_rgb_luminance() instead. + * + * Return value: the intensity in the range from 0.0 to 1.0. + **/ gdouble gimp_rgb_intensity (const GimpRGB *rgb) { @@ -240,6 +285,14 @@ gimp_rgb_intensity (const GimpRGB *rgb) return CLAMP (intensity, 0.0, 1.0); } +/** + * gimp_rgb_intensity_uchar: + * @rgb: + * + * This function is deprecated! Use gimp_rgb_luminance_uchar() instead. + * + * Return value: the intensity in the range from 0 to 255. + **/ guchar gimp_rgb_intensity_uchar (const GimpRGB *rgb) { diff --git a/libgimpcolor/gimprgb.h b/libgimpcolor/gimprgb.h index 3533241c87..c8f12f6866 100644 --- a/libgimpcolor/gimprgb.h +++ b/libgimpcolor/gimprgb.h @@ -99,8 +99,13 @@ void gimp_rgb_clamp (GimpRGB *rgb); void gimp_rgb_gamma (GimpRGB *rgb, gdouble gamma); -gdouble gimp_rgb_intensity (const GimpRGB *rgb); -guchar gimp_rgb_intensity_uchar (const GimpRGB *rgb); +gdouble gimp_rgb_luminance (const GimpRGB *rgb); +guchar gimp_rgb_luminance_uchar (const GimpRGB *rgb); + +#ifndef GIMP_DISABLE_DEPRECATED +gdouble gimp_rgb_intensity (const GimpRGB *rgb); +guchar gimp_rgb_intensity_uchar (const GimpRGB *rgb); +#endif void gimp_rgb_composite (GimpRGB *color1, const GimpRGB *color2, @@ -146,13 +151,44 @@ gdouble gimp_rgba_distance (const GimpRGB *rgba1, /* Map RGB to intensity */ -#define GIMP_RGB_INTENSITY_RED 0.30 -#define GIMP_RGB_INTENSITY_GREEN 0.59 -#define GIMP_RGB_INTENSITY_BLUE 0.11 +/* + * The weights to compute true CIE luminance from linear red, green + * and blue, as defined by the ITU-R Recommendation BT.709, "Basic + * Parameter Values for the HDTV Standard for the Studio and for + * International Programme Exchange" (1990). Also suggested in the + * sRGB colorspace specification by the W3C. + */ + +#define GIMP_RGB_LUMINANCE_RED (0.2126) +#define GIMP_RGB_LUMINANCE_GREEN (0.7152) +#define GIMP_RGB_LUMINANCE_BLUE (0.0722) + +#define GIMP_RGB_LUMINANCE(r,g,b) ((r) * GIMP_RGB_LUMINANCE_RED + \ + (g) * GIMP_RGB_LUMINANCE_GREEN + \ + (b) * GIMP_RGB_LUMINANCE_BLUE) + + +#ifndef GIMP_DISABLE_DEPRECATED + +/* + * The coefficients below properly computed luminance for monitors + * having phosphors that were contemporary at the introduction of NTSC + * television in 1953. They are still appropriate for computing video + * luma. However, these coefficients do not accurately compute + * luminance for contemporary monitors. The use of these definitions + * is deprecated. + */ + +#define GIMP_RGB_INTENSITY_RED (0.30) +#define GIMP_RGB_INTENSITY_GREEN (0.59) +#define GIMP_RGB_INTENSITY_BLUE (0.11) + #define GIMP_RGB_INTENSITY(r,g,b) ((r) * GIMP_RGB_INTENSITY_RED + \ (g) * GIMP_RGB_INTENSITY_GREEN + \ (b) * GIMP_RGB_INTENSITY_BLUE) +#endif + G_END_DECLS diff --git a/modules/colorsel_triangle.c b/modules/colorsel_triangle.c index be8b778442..3921030e16 100644 --- a/modules/colorsel_triangle.c +++ b/modules/colorsel_triangle.c @@ -325,7 +325,7 @@ colorsel_triangle_update_preview (ColorselTriangle *triangle) gimp_hsv_to_rgb4 (buf, atn / (2 * G_PI), 1, 1); - col = GIMP_RGB_INTENSITY (buf[0], buf[1], buf[2]) > 127 ? 0 : 255; + col = GIMP_RGB_LUMINANCE (buf[0], buf[1], buf[2]) > 127 ? 0 : 255; d = CLAMP (triangle->wheelradius / 16, 2, 4); diff --git a/plug-ins/common/aa.c b/plug-ins/common/aa.c index ca994dfebc..a69ce3b577 100644 --- a/plug-ins/common/aa.c +++ b/plug-ins/common/aa.c @@ -306,13 +306,13 @@ 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]) + 0.5); + GIMP_RGB_LUMINANCE (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]) + 0.5) + ((guchar) (GIMP_RGB_LUMINANCE (p[0], p[1], p[2]) + 0.5) * (p[3] + 1)) >> 8); break; diff --git a/plug-ins/common/bumpmap.c b/plug-ins/common/bumpmap.c index 7c6be1c003..eff34c7638 100644 --- a/plug-ins/common/bumpmap.c +++ b/plug-ins/common/bumpmap.c @@ -785,12 +785,12 @@ bumpmap_convert_row (guchar *row, { if (has_alpha) *p++ = lut[(gint) (bmvals.waterlevel + - (((gint) (GIMP_RGB_INTENSITY (row[0], + (((gint) (GIMP_RGB_LUMINANCE (row[0], row[1], row[2]) + 0.5) - bmvals.waterlevel) * row[3]) / 255.0)]; else - *p++ = lut[(gint) (GIMP_RGB_INTENSITY (row[0], + *p++ = lut[(gint) (GIMP_RGB_LUMINANCE (row[0], row[1], row[2]) + 0.5)]; diff --git a/plug-ins/common/colorify.c b/plug-ins/common/colorify.c index e8c7273a9f..da024e8eef 100644 --- a/plug-ins/common/colorify.c +++ b/plug-ins/common/colorify.c @@ -212,9 +212,9 @@ colorify (GimpDrawable *drawable, for (i = 0; i < 256; i ++) { - lum_red_lookup[i] = i * GIMP_RGB_INTENSITY_RED; - lum_green_lookup[i] = i * GIMP_RGB_INTENSITY_GREEN; - lum_blue_lookup[i] = i * GIMP_RGB_INTENSITY_BLUE; + lum_red_lookup[i] = i * GIMP_RGB_LUMINANCE_RED; + lum_green_lookup[i] = i * GIMP_RGB_LUMINANCE_GREEN; + lum_blue_lookup[i] = i * GIMP_RGB_LUMINANCE_BLUE; final_red_lookup[i] = i * cvals.color.r; final_green_lookup[i] = i * cvals.color.g; final_blue_lookup[i] = i * cvals.color.b; diff --git a/plug-ins/common/despeckle.c b/plug-ins/common/despeckle.c index 6676bfe897..ef84215d96 100644 --- a/plug-ins/common/despeckle.c +++ b/plug-ins/common/despeckle.c @@ -86,7 +86,7 @@ static void preview_update (GtkWidget *preview); static gint quick_median_select (guchar **p, guchar *i, gint n); -static inline guchar pixel_intensity (const guchar *p, +static inline guchar pixel_luminance (const guchar *p, gint bpp); static inline void pixel_copy (guchar *dest, const guchar *src, @@ -635,7 +635,7 @@ despeckle_median (guchar *src, for (u = xmin, off2 += xmin * bpp; u <= xmax; u++, off2 += bpp) { - guchar value = pixel_intensity (src + off2, bpp); + guchar value = pixel_luminance (src + off2, bpp); if (value < black_level) { @@ -705,7 +705,7 @@ despeckle_median (guchar *src, * Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5 * This code by Nicolas Devillard - 1998. Public domain. * - * Modified to swap pointers: swap is done by comparing intensity + * Modified to swap pointers: swap is done by comparing luminance * value for the pointer to RGB. */ static gint @@ -793,7 +793,7 @@ quick_median_select (guchar **p, } static inline guchar -pixel_intensity (const guchar *p, +pixel_luminance (const guchar *p, gint bpp) { switch (bpp) @@ -804,7 +804,7 @@ pixel_intensity (const guchar *p, case 3: case 4: - return GIMP_RGB_INTENSITY (p[0], p[1], p[2]); + return GIMP_RGB_LUMINANCE (p[0], p[1], p[2]); default: return 0; /* should not be reached */ diff --git a/plug-ins/common/displace.c b/plug-ins/common/displace.c index 0fe4b14b6d..ea2169ab69 100644 --- a/plug-ins/common/displace.c +++ b/plug-ins/common/displace.c @@ -31,7 +31,7 @@ * (http://ha1.seikyou.ne.jp/home/taka/gimp/displace/displace.html) * Added ability to use transparency as the identity transformation * (Full transparency is treated as if it was grey 0.5) - * and the possibility to use RGB/RGBA pictures where the intensity + * and the possibility to use RGB/RGBA pictures where the luminance * of the pixel is taken into account * * Joao S. O. Bueno, Dec. 2004: @@ -175,7 +175,7 @@ query (void) "Displace the contents of the specified drawable", "Displaces the contents of the specified drawable " "by the amounts specified by 'amount_x' and " - "'amount_y' multiplied by the intensity of " + "'amount_y' multiplied by the luminance of " "corresponding pixels in the 'displace_map' " "drawables. If mode is polar coordinates" "drawable is whirled and pinched according to map.", @@ -757,7 +757,7 @@ displace_map_give_value (guchar *pt, gdouble ret, val_alpha; if (bytes >= 3) - ret = GIMP_RGB_INTENSITY (pt[0], pt[1], pt[2]); + ret = GIMP_RGB_LUMINANCE (pt[0], pt[1], pt[2]); else ret = (gdouble) *pt; diff --git a/plug-ins/common/engrave.c b/plug-ins/common/engrave.c index 4125021e0c..f63c5c9fbc 100644 --- a/plug-ins/common/engrave.c +++ b/plug-ins/common/engrave.c @@ -362,7 +362,7 @@ engrave_large (GimpDrawable *drawable, if (bpp < 3) inten = average[0] / 254.0 * height; else - inten = GIMP_RGB_INTENSITY (average[0], + inten = GIMP_RGB_LUMINANCE (average[0], average[1], average[2]) / 254.0 * height; @@ -553,7 +553,7 @@ engrave_sub (gint height, if (bpp < 3) inten = average[0] / 254.0 * height; else - inten = GIMP_RGB_INTENSITY (average[0], + inten = GIMP_RGB_LUMINANCE (average[0], average[1], average[2]) / 254.0 * height; diff --git a/plug-ins/common/gradmap.c b/plug-ins/common/gradmap.c index 789f773085..42673cb349 100644 --- a/plug-ins/common/gradmap.c +++ b/plug-ins/common/gradmap.c @@ -27,14 +27,10 @@ #include "libgimp/stdplugins-intl.h" -#ifdef RCSID -static char rcsid[] = "$Id$"; -#endif - /* Some useful macros */ #define NSAMPLES 256 -#define LUMINOSITY(X) (GIMP_RGB_INTENSITY (X[0], X[1], X[2]) + 0.5) +#define LUMINOSITY(X) (GIMP_RGB_LUMINANCE (X[0], X[1], X[2]) + 0.5) typedef enum { @@ -331,7 +327,7 @@ get_samples_palette (GimpDrawable *drawable) gimp_rgb_get_uchar (&color_sample, b_samp, b_samp + 1, b_samp + 2); else - *b_samp = gimp_rgb_intensity_uchar (&color_sample); + *b_samp = gimp_rgb_luminance_uchar (&color_sample); if (has_alpha) b_samp[alpha] = 255; diff --git a/plug-ins/common/grid.c b/plug-ins/common/grid.c index 606f2722b5..d3a024b2ea 100644 --- a/plug-ins/common/grid.c +++ b/plug-ins/common/grid.c @@ -354,9 +354,9 @@ grid (gint32 image_ID, break; case GIMP_GRAY: - hcolor[0] = gimp_rgb_intensity_uchar (&grid_cfg.hcolor); - vcolor[0] = gimp_rgb_intensity_uchar (&grid_cfg.vcolor); - icolor[0] = gimp_rgb_intensity_uchar (&grid_cfg.icolor); + hcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.hcolor); + vcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.vcolor); + icolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.icolor); blend = TRUE; break; diff --git a/plug-ins/common/mng.c b/plug-ins/common/mng.c index 9ebc8e6e12..c92cfb50be 100644 --- a/plug-ins/common/mng.c +++ b/plug-ins/common/mng.c @@ -662,7 +662,9 @@ mng_save_image (const gchar *filename, gimp_context_get_background(&bgcolor); gimp_rgb_get_uchar(&bgcolor, &red, &green, &blue); - if ((ret = mng_putchunk_back(handle, red, green, blue, MNG_BACKGROUNDCOLOR_MANDATORY, 0, MNG_BACKGROUNDIMAGE_NOTILE)) != MNG_NOERROR) + if ((ret = mng_putchunk_back(handle, red, green, blue, + MNG_BACKGROUNDCOLOR_MANDATORY, + 0, MNG_BACKGROUNDIMAGE_NOTILE)) != MNG_NOERROR) { g_warning("Unable to mng_putchunk_back() in mng_save_image()"); mng_cleanup(&handle); @@ -671,7 +673,9 @@ mng_save_image (const gchar *filename, return 0; } - if ((ret = mng_putchunk_bkgd(handle, MNG_FALSE, 2, 0, gimp_rgb_intensity_uchar(&bgcolor), red, green, blue)) != MNG_NOERROR) + if ((ret = mng_putchunk_bkgd(handle, MNG_FALSE, 2, 0, + gimp_rgb_luminance_uchar(&bgcolor), + red, green, blue)) != MNG_NOERROR) { g_warning("Unable to mng_putchunk_bkgd() in mng_save_image()"); mng_cleanup(&handle); diff --git a/plug-ins/common/newsprint.c b/plug-ins/common/newsprint.c index 7da7f49a61..52853e823a 100644 --- a/plug-ins/common/newsprint.c +++ b/plug-ins/common/newsprint.c @@ -89,7 +89,7 @@ #define CS_GREY 0 #define CS_RGB 1 #define CS_CMYK 2 -#define CS_INTENSITY 3 +#define CS_LUMINANCE 3 #define NUM_CS 4 #define VALID_CS(x) ((x) >= 0 && (x) <= NUM_CS-1) @@ -190,7 +190,7 @@ typedef struct gint cell_width; /* screening section: */ - gint colourspace; /* 0: RGB, 1: CMYK, 2: Intensity */ + gint colourspace; /* 0: RGB, 1: CMYK, 2: Luminance */ gint k_pullout; /* percentage of black to pull out */ /* grey screen (only used if greyscale drawable) */ @@ -276,7 +276,7 @@ static const NewsprintValues factory_defaults = 10, /* cell width */ /* screen setup (default is the classic rosette pattern) */ - CS_RGB, /* use RGB, not CMYK or Intensity */ + CS_RGB, /* use RGB, not CMYK or Luminance */ 100, /* max pullout */ /* grey/black */ @@ -404,10 +404,10 @@ static const chan_tmpl cmyk_tmpl[] = { NULL, NULL, NULL, NULL, NULL } }; -static const chan_tmpl intensity_tmpl[] = +static const chan_tmpl luminance_tmpl[] = { { - N_("Intensity"), + N_("Luminance"), &pvals.gry_ang, &pvals.gry_spotfn, &factory_defaults.gry_ang, @@ -424,7 +424,7 @@ static const chan_tmpl *cspace_chan_tmpl[] = grey_tmpl, rgb_tmpl, cmyk_tmpl, - intensity_tmpl + luminance_tmpl }; #define NCHANS(x) ((sizeof(x) / sizeof(chan_tmpl)) - 1) @@ -437,7 +437,7 @@ static const gint cspace_nchans[] = NCHANS (grey_tmpl), NCHANS (rgb_tmpl), NCHANS (cmyk_tmpl), - NCHANS (intensity_tmpl) + NCHANS (luminance_tmpl) }; @@ -497,7 +497,7 @@ query (void) { GIMP_PDB_INT32, "cell_width", "screen cell width, in pixels" }, - { GIMP_PDB_INT32, "colorspace", "separate to 0:RGB, 1:CMYK, 2:Intensity" }, + { GIMP_PDB_INT32, "colorspace", "separate to 0:RGB, 1:CMYK, 2:Luminance" }, { GIMP_PDB_INT32, "k_pullout", "Percentage of black to pullout (CMYK only)" }, { GIMP_PDB_FLOAT, "gry_ang", "Grey/black screen angle (degrees)" }, @@ -1327,7 +1327,7 @@ newsprint_dialog (GimpDrawable *drawable) G_CALLBACK (gimp_preview_invalidate), preview); - /* RGB / CMYK / Intensity select */ + /* RGB / CMYK / Luminance select */ hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (st.vbox), hbox, FALSE, FALSE, 0); @@ -1376,7 +1376,7 @@ newsprint_dialog (GimpDrawable *drawable) group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle)); gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), - (pvals.colourspace == CS_INTENSITY)); + (pvals.colourspace == CS_LUMINANCE)); gtk_widget_show (toggle); g_object_set_data (G_OBJECT (toggle), "dialog", &st); @@ -1384,7 +1384,7 @@ newsprint_dialog (GimpDrawable *drawable) g_signal_connect (toggle, "toggled", G_CALLBACK (newsprint_cspace_update), - GINT_TO_POINTER (CS_INTENSITY)); + GINT_TO_POINTER (CS_LUMINANCE)); g_signal_connect_swapped (toggle, "toggled", G_CALLBACK (gimp_preview_invalidate), preview); @@ -1840,7 +1840,7 @@ do { \ } while(0) /* calculate the RGB / CMYK rotations and threshold matrices */ - if (colour_bpp == 1 || colourspace == CS_INTENSITY) + if (colour_bpp == 1 || colourspace == CS_LUMINANCE) { rot[0] = DEG2RAD (pvals.gry_ang); thresh[0] = spot2thresh (pvals.gry_spotfn, width); @@ -1951,9 +1951,9 @@ do { \ } break; - case CS_INTENSITY: + case CS_LUMINANCE: data[3] = data[0]; /* save orig for later */ - data[0] = GIMP_RGB_INTENSITY (data[0], + data[0] = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]) + 0.5; break; @@ -2012,7 +2012,7 @@ do { \ data[2] = 0xff - data[2]; break; - case CS_INTENSITY: + case CS_LUMINANCE: if (has_alpha) { dest[colour_bpp] = data[0]; diff --git a/plug-ins/common/png.c b/plug-ins/common/png.c index 85b58bc75c..73a5616a17 100644 --- a/plug-ins/common/png.c +++ b/plug-ins/common/png.c @@ -1283,7 +1283,7 @@ save_image (const gchar *filename, background.red = red; background.green = green; background.blue = blue; - background.gray = gimp_rgb_intensity_uchar (&color); + background.gray = gimp_rgb_luminance_uchar (&color); png_set_bKGD (pp, info, &background); } else diff --git a/plug-ins/common/whirlpinch.c b/plug-ins/common/whirlpinch.c index 9b0bec203c..417e9780ad 100644 --- a/plug-ins/common/whirlpinch.c +++ b/plug-ins/common/whirlpinch.c @@ -632,12 +632,12 @@ dialog_update_preview (GimpDrawable *drawable, switch (img_bpp) { case 1: - outside[0] = outside[1] = outside [2] = gimp_rgb_intensity_uchar (&background); + outside[0] = outside[1] = outside [2] = gimp_rgb_luminance_uchar (&background); outside[3] = 255; break; case 2: - outside[0] = outside[1] = outside [2] = gimp_rgb_intensity_uchar (&background); + outside[0] = outside[1] = outside [2] = gimp_rgb_luminance_uchar (&background); outside[3] = 0; break; diff --git a/plug-ins/gflare/gflare.c b/plug-ins/gflare/gflare.c index 7509126bdb..d81f013877 100644 --- a/plug-ins/gflare/gflare.c +++ b/plug-ins/gflare/gflare.c @@ -58,7 +58,7 @@ #define DEBUG_PRINT(X) #endif -#define LUMINOSITY(PIX) (GIMP_RGB_INTENSITY (PIX[0], PIX[1], PIX[2]) + 0.5) +#define LUMINOSITY(PIX) (GIMP_RGB_LUMINANCE (PIX[0], PIX[1], PIX[2]) + 0.5) #define OFFSETOF(t,f) ((int) ((char*) &((t*) 0)->f)) #define RESPONSE_RESCAN 1 @@ -1155,7 +1155,7 @@ plugin_put_pixel_func (gint ix, } else { - dest[0] = gimp_rgb_intensity_uchar (color); + dest[0] = gimp_rgb_luminance_uchar (color); } if (dinfo.has_alpha) diff --git a/plug-ins/gfli/gfli.c b/plug-ins/gfli/gfli.c index 1c455a85e3..389a2c6f34 100644 --- a/plug-ins/gfli/gfli.c +++ b/plug-ins/gfli/gfli.c @@ -638,7 +638,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) + 0.5; + bg = GIMP_RGB_LUMINANCE (red, green, blue) + 0.5; break; case GIMP_INDEXED: diff --git a/plug-ins/maze/handy.c b/plug-ins/maze/handy.c index a039d123d3..8b796484ff 100644 --- a/plug-ins/maze/handy.c +++ b/plug-ins/maze/handy.c @@ -34,10 +34,10 @@ however handling of indexed images is somewhat broken. Patches appreciated. */ -void -get_colors (GimpDrawable *drawable, - guint8 *fg, - guint8 *bg) +void +get_colors (GimpDrawable *drawable, + guint8 *fg, + guint8 *bg) { GimpRGB foreground; GimpRGB background; @@ -52,14 +52,14 @@ get_colors (GimpDrawable *drawable, { case GIMP_RGB_IMAGE: case GIMP_RGBA_IMAGE: - gimp_rgb_get_uchar (&foreground, &fg[0], &fg[1], &fg[2]); - gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]); + gimp_rgb_get_uchar (&foreground, &fg[0], &fg[1], &fg[2]); + gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]); break; case GIMP_GRAYA_IMAGE: case GIMP_GRAY_IMAGE: - fg[0] = gimp_rgb_intensity_uchar (&foreground); - bg[0] = gimp_rgb_intensity_uchar (&background); + fg[0] = gimp_rgb_luminance_uchar (&foreground); + bg[0] = gimp_rgb_luminance_uchar (&background); break; case GIMP_INDEXEDA_IMAGE: @@ -77,22 +77,22 @@ get_colors (GimpDrawable *drawable, /* Draws a solid color box in a GimpPixelRgn. */ /* Optimization assumptions: * (Or, "Why Maze is Faster Than Checkerboard.") - * + * * Assuming calling memcpy is faster than using loops. * Row buffers are nice... * - * Assume allocating memory for row buffers takes a significant amount + * Assume allocating memory for row buffers takes a significant amount * of time. Assume drawbox will be called many times. * Only allocate memory once. * * Do not assume the row buffer will always be the same size. Allow - * for reallocating to make it bigger if needed. However, I don't see + * for reallocating to make it bigger if needed. However, I don't see * reason to bother ever shrinking it again. * (Under further investigation, assuming the row buffer never grows * may be a safe assumption in this case.) * * Also assume that the program calling drawbox is short-lived, so - * memory leaks aren't of particular concern-- the memory allocated to + * memory leaks aren't of particular concern-- the memory allocated to * the row buffer is never set free. */ @@ -103,9 +103,9 @@ get_colors (GimpDrawable *drawable, * We could keep a row of each color on hand so we wouldn't have to * re-fill it every time... */ -void -drawbox( GimpPixelRgn *dest_rgn, - guint x, guint y, guint w, guint h, +void +drawbox( GimpPixelRgn *dest_rgn, + guint x, guint y, guint w, guint h, guint8 clr[4]) { const guint bpp = dest_rgn->bpp; @@ -114,34 +114,34 @@ drawbox( GimpPixelRgn *dest_rgn, /* x_max = dest_rgn->bpp * MIN(dest_rgn->w, (x + w)); */ /* rowsize = x_max - x_min */ const guint rowsize = bpp * MIN(dest_rgn->w, (x + w)) - x_min; - + /* The maximum [xy] value is that of the far end of the box, or * the edge of the region, whichever comes first. */ const guint y_max = dest_rgn->rowstride * MIN(dest_rgn->h, (y + h)); - + static guint8 *rowbuf; - static guint high_size = 0; - + static guint high_size = 0; + guint xx, yy; - + /* Does the row buffer need to be (re)allocated? */ - if (high_size == 0) + if (high_size == 0) { rowbuf = g_new (guint8, rowsize); - } - else if (rowsize > high_size) + } + else if (rowsize > high_size) { rowbuf = g_renew (guint8, rowbuf, rowsize); } - + high_size = MAX(high_size, rowsize); - + /* Fill the row buffer with the color. */ - for (xx = 0; xx < rowsize; xx += bpp) + for (xx = 0; xx < rowsize; xx += bpp) { memcpy (&rowbuf[xx], clr, bpp); } - + /* Fill in the box in the region with rows... */ for (yy = dest_rgn->rowstride * y; yy < y_max; yy += dest_rgn->rowstride) { diff --git a/plug-ins/pagecurl/pagecurl.c b/plug-ins/pagecurl/pagecurl.c index 66e3a0cf4c..ccbafcc778 100644 --- a/plug-ins/pagecurl/pagecurl.c +++ b/plug-ins/pagecurl/pagecurl.c @@ -760,10 +760,10 @@ do_curl_effect (gint32 drawable_id) /* Init shade_curl */ - fore_grayval = GIMP_RGB_INTENSITY (fore_color[0], + fore_grayval = GIMP_RGB_LUMINANCE (fore_color[0], fore_color[1], fore_color[2]) + 0.5; - back_grayval = GIMP_RGB_INTENSITY (back_color[0], + back_grayval = GIMP_RGB_LUMINANCE (back_color[0], back_color[1], back_color[2]) + 0.5; @@ -1069,7 +1069,7 @@ get_gradient_samples (gint32 drawable_id, for (j = 0; j < 3; j++) b_samp[j] = f_samp[j] * 255; else - b_samp[0] = GIMP_RGB_INTENSITY (f_samp[0], f_samp[1], f_samp[2]) * 255; + b_samp[0] = GIMP_RGB_LUMINANCE (f_samp[0], f_samp[1], f_samp[2]) * 255; if (has_alpha) b_samp[alpha] = f_samp[3] * 255; diff --git a/plug-ins/pygimp/ChangeLog b/plug-ins/pygimp/ChangeLog index 527b82a839..c9613e725e 100644 --- a/plug-ins/pygimp/ChangeLog +++ b/plug-ins/pygimp/ChangeLog @@ -1,3 +1,7 @@ +2005-08-03 Sven Neumann + + * pygimp-rgb.c: added wrapper for gimp_rgb_luminance(). + 2005-07-29 Sven Neumann * plug-ins/benchmark-foreground-extract.py: follow PDB API change. diff --git a/plug-ins/pygimp/pygimp-colors.c b/plug-ins/pygimp/pygimp-colors.c index ea1ae458fb..b8a7baeaf9 100644 --- a/plug-ins/pygimp/pygimp-colors.c +++ b/plug-ins/pygimp/pygimp-colors.c @@ -203,6 +203,12 @@ rgb_gamma(PyObject *self, PyObject *args, PyObject *kwargs) return Py_None; } +static PyObject * +rgb_luminance(PyObject *self) +{ + return PyFloat_FromDouble(gimp_rgb_luminance(pyg_boxed_get(self, GimpRGB))); +} + static PyObject * rgb_intensity(PyObject *self) { @@ -222,7 +228,7 @@ rgb_composite(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; if (mode < GIMP_RGB_COMPOSITE_NONE || mode > GIMP_RGB_COMPOSITE_BEHIND) { - PyErr_SetString(PyExc_TypeError, "composite type is not valid"); + PyErr_SetString(PyExc_TypeError, "composite type is not valid"); return NULL; } @@ -322,6 +328,7 @@ static PyMethodDef rgb_methods[] = { { "min", (PyCFunction)rgb_min, METH_NOARGS }, { "clamp", (PyCFunction)rgb_clamp, METH_NOARGS }, { "gamma", (PyCFunction)rgb_gamma, METH_VARARGS|METH_KEYWORDS }, + { "luminance", (PyCFunction)rgb_luminance, METH_NOARGS }, { "intensity", (PyCFunction)rgb_intensity, METH_NOARGS }, { "composite", (PyCFunction)rgb_composite, METH_VARARGS|METH_KEYWORDS }, { "parse_name", (PyCFunction)rgb_parse_name, METH_VARARGS|METH_KEYWORDS }, diff --git a/plug-ins/pygimp/pygimp-rgb.c b/plug-ins/pygimp/pygimp-rgb.c index ea1ae458fb..b8a7baeaf9 100644 --- a/plug-ins/pygimp/pygimp-rgb.c +++ b/plug-ins/pygimp/pygimp-rgb.c @@ -203,6 +203,12 @@ rgb_gamma(PyObject *self, PyObject *args, PyObject *kwargs) return Py_None; } +static PyObject * +rgb_luminance(PyObject *self) +{ + return PyFloat_FromDouble(gimp_rgb_luminance(pyg_boxed_get(self, GimpRGB))); +} + static PyObject * rgb_intensity(PyObject *self) { @@ -222,7 +228,7 @@ rgb_composite(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; if (mode < GIMP_RGB_COMPOSITE_NONE || mode > GIMP_RGB_COMPOSITE_BEHIND) { - PyErr_SetString(PyExc_TypeError, "composite type is not valid"); + PyErr_SetString(PyExc_TypeError, "composite type is not valid"); return NULL; } @@ -322,6 +328,7 @@ static PyMethodDef rgb_methods[] = { { "min", (PyCFunction)rgb_min, METH_NOARGS }, { "clamp", (PyCFunction)rgb_clamp, METH_NOARGS }, { "gamma", (PyCFunction)rgb_gamma, METH_VARARGS|METH_KEYWORDS }, + { "luminance", (PyCFunction)rgb_luminance, METH_NOARGS }, { "intensity", (PyCFunction)rgb_intensity, METH_NOARGS }, { "composite", (PyCFunction)rgb_composite, METH_VARARGS|METH_KEYWORDS }, { "parse_name", (PyCFunction)rgb_parse_name, METH_VARARGS|METH_KEYWORDS },