app: use gimp_image_transform_rgb() instead of transform_color()

instead of fiddling with gimp_rgb_get_uchar() manually.
This commit is contained in:
Michael Natterer 2012-03-16 00:02:27 +01:00
parent 54108d9413
commit dc8d6a3977
6 changed files with 64 additions and 87 deletions

View File

@ -19,9 +19,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <cairo.h>
#include <gegl.h> #include <gegl.h>
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h" #include "core-types.h"
@ -569,13 +571,10 @@ gimp_edit_fill_internal (GimpImage *image,
case GIMP_WHITE_FILL: case GIMP_WHITE_FILL:
{ {
guchar tmp_col[MAX_CHANNELS]; GimpRGB white;
tmp_col[RED] = 255; gimp_rgb_set (&white, 1.0, 1.0, 1.0);
tmp_col[GREEN] = 255; gimp_image_transform_rgb (image, drawable_type, &white, col);
tmp_col[BLUE] = 255;
gimp_image_transform_color (image, drawable_type, col,
GIMP_RGB, tmp_col);
} }
break; break;

View File

@ -152,15 +152,8 @@ gimp_drawable_bucket_fill_full (GimpDrawable *drawable,
if (fill_mode == GIMP_FG_BUCKET_FILL || if (fill_mode == GIMP_FG_BUCKET_FILL ||
fill_mode == GIMP_BG_BUCKET_FILL) fill_mode == GIMP_BG_BUCKET_FILL)
{ {
guchar tmp_col[MAX_CHANNELS]; gimp_image_transform_rgb (image, gimp_drawable_type (drawable),
color, col);
gimp_rgb_get_uchar (color,
&tmp_col[RED],
&tmp_col[GREEN],
&tmp_col[BLUE]);
gimp_image_transform_color (image, gimp_drawable_type (drawable), col,
GIMP_RGB, tmp_col);
col[gimp_drawable_bytes_with_alpha (drawable) - 1] = OPAQUE_OPACITY; col[gimp_drawable_bytes_with_alpha (drawable) - 1] = OPAQUE_OPACITY;
} }
else if (fill_mode == GIMP_PATTERN_BUCKET_FILL) else if (fill_mode == GIMP_PATTERN_BUCKET_FILL)

View File

@ -367,16 +367,10 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable,
{ {
case GIMP_FILL_STYLE_SOLID: case GIMP_FILL_STYLE_SOLID:
{ {
guchar tmp_col[MAX_CHANNELS] = { 0, };
guchar col[MAX_CHANNELS] = { 0, }; guchar col[MAX_CHANNELS] = { 0, };
gimp_rgb_get_uchar (&context->foreground, gimp_image_get_foreground (image, context,
&tmp_col[RED], gimp_drawable_type (drawable), col);
&tmp_col[GREEN],
&tmp_col[BLUE]);
gimp_image_transform_color (image, gimp_drawable_type (drawable), col,
GIMP_RGB, tmp_col);
col[bytes - 1] = OPAQUE_OPACITY; col[bytes - 1] = OPAQUE_OPACITY;
color_region_mask (&basePR, &maskPR, col); color_region_mask (&basePR, &maskPR, col);

View File

@ -2533,46 +2533,6 @@ gimp_image_inc_instance_count (GimpImage *image)
/* color transforms / utilities */ /* color transforms / utilities */
void
gimp_image_get_foreground (const GimpImage *image,
GimpContext *context,
GimpImageType dest_type,
guchar *fg)
{
GimpRGB color;
guchar pfg[3];
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (fg != NULL);
gimp_context_get_foreground (context, &color);
gimp_rgb_get_uchar (&color, &pfg[0], &pfg[1], &pfg[2]);
gimp_image_transform_color (image, dest_type, fg, GIMP_RGB, pfg);
}
void
gimp_image_get_background (const GimpImage *image,
GimpContext *context,
GimpImageType dest_type,
guchar *bg)
{
GimpRGB color;
guchar pbg[3];
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (bg != NULL);
gimp_context_get_background (context, &color);
gimp_rgb_get_uchar (&color, &pbg[0], &pbg[1], &pbg[2]);
gimp_image_transform_color (image, dest_type, bg, GIMP_RGB, pbg);
}
void void
gimp_image_get_color (const GimpImage *src_image, gimp_image_get_color (const GimpImage *src_image,
GimpImageType src_type, GimpImageType src_type,
@ -2627,6 +2587,40 @@ gimp_image_get_color (const GimpImage *src_image,
*rgba = OPAQUE_OPACITY; *rgba = OPAQUE_OPACITY;
} }
void
gimp_image_get_foreground (const GimpImage *image,
GimpContext *context,
GimpImageType dest_type,
guchar *fg)
{
GimpRGB color;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (fg != NULL);
gimp_context_get_foreground (context, &color);
gimp_image_transform_rgb (image, dest_type, &color, fg);
}
void
gimp_image_get_background (const GimpImage *image,
GimpContext *context,
GimpImageType dest_type,
guchar *bg)
{
GimpRGB color;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (bg != NULL);
gimp_context_get_background (context, &color);
gimp_image_transform_rgb (image, dest_type, &color, bg);
}
void void
gimp_image_transform_rgb (const GimpImage *dest_image, gimp_image_transform_rgb (const GimpImage *dest_image,
GimpImageType dest_type, GimpImageType dest_type,

View File

@ -323,6 +323,11 @@ void gimp_image_inc_instance_count (GimpImage *image);
/* color transforms / utilities */ /* color transforms / utilities */
void gimp_image_get_color (const GimpImage *src_image,
GimpImageType src_type,
const guchar *src,
guchar *rgba);
void gimp_image_get_foreground (const GimpImage *image, void gimp_image_get_foreground (const GimpImage *image,
GimpContext *context, GimpContext *context,
GimpImageType dest_type, GimpImageType dest_type,
@ -331,10 +336,6 @@ void gimp_image_get_background (const GimpImage *image,
GimpContext *context, GimpContext *context,
GimpImageType dest_type, GimpImageType dest_type,
guchar *bg); guchar *bg);
void gimp_image_get_color (const GimpImage *src_image,
GimpImageType src_type,
const guchar *src,
guchar *rgba);
void gimp_image_transform_rgb (const GimpImage *dest_image, void gimp_image_transform_rgb (const GimpImage *dest_image,
GimpImageType dest_type, GimpImageType dest_type,
const GimpRGB *rgb, const GimpRGB *rgb,

View File

@ -119,11 +119,14 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
GimpImage *image; GimpImage *image;
GimpRGB gradient_color; GimpRGB gradient_color;
TempBuf *area; TempBuf *area;
guchar col[MAX_CHANNELS];
GimpPaintApplicationMode paint_appl_mode; GimpPaintApplicationMode paint_appl_mode;
gdouble fade_point; gdouble fade_point;
gdouble grad_point; gdouble grad_point;
gdouble force; gdouble force;
guchar pixel[MAX_CHANNELS] = { OPAQUE_OPACITY,
OPAQUE_OPACITY,
OPAQUE_OPACITY,
OPAQUE_OPACITY };
image = gimp_item_get_image (GIMP_ITEM (drawable)); image = gimp_item_get_image (GIMP_ITEM (drawable));
@ -155,26 +158,17 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
paint_options, paint_options,
fade_point); fade_point);
/* optionally take the color from the current gradient */
if (gimp_paint_options_get_gradient_color (paint_options, image, if (gimp_paint_options_get_gradient_color (paint_options, image,
grad_point, grad_point,
paint_core->pixel_dist, paint_core->pixel_dist,
&gradient_color)) &gradient_color))
{ {
guchar pixel[MAX_CHANNELS] = { OPAQUE_OPACITY, /* optionally take the color from the current gradient */
OPAQUE_OPACITY,
OPAQUE_OPACITY,
OPAQUE_OPACITY };
opacity *= gradient_color.a; opacity *= gradient_color.a;
gimp_rgb_get_uchar (&gradient_color, gimp_image_transform_rgb (image, gimp_drawable_type (drawable),
&col[RED], &gradient_color, pixel);
&col[GREEN],
&col[BLUE]);
gimp_image_transform_color (image, gimp_drawable_type (drawable), pixel,
GIMP_RGB, col);
color_pixels (temp_buf_get_data (area), pixel, color_pixels (temp_buf_get_data (area), pixel,
area->width * area->height, area->width * area->height,
@ -182,9 +176,12 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
paint_appl_mode = GIMP_PAINT_INCREMENTAL; paint_appl_mode = GIMP_PAINT_INCREMENTAL;
} }
/* otherwise check if the brush has a pixmap and use that to color the area */
else if (brush_core->brush && brush_core->brush->pixmap) else if (brush_core->brush && brush_core->brush->pixmap)
{ {
/* otherwise check if the brush has a pixmap and use that to
* color the area
*/
gimp_brush_core_color_area_with_pixmap (brush_core, drawable, gimp_brush_core_color_area_with_pixmap (brush_core, drawable,
coords, coords,
area, area,
@ -192,15 +189,14 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
paint_appl_mode = GIMP_PAINT_INCREMENTAL; paint_appl_mode = GIMP_PAINT_INCREMENTAL;
} }
/* otherwise fill the area with the foreground color */
else else
{ {
/* otherwise fill the area with the foreground color */
gimp_image_get_foreground (image, context, gimp_drawable_type (drawable), gimp_image_get_foreground (image, context, gimp_drawable_type (drawable),
col); pixel);
col[area->bytes - 1] = OPAQUE_OPACITY; color_pixels (temp_buf_get_data (area), pixel,
color_pixels (temp_buf_get_data (area), col,
area->width * area->height, area->width * area->height,
area->bytes); area->bytes);
} }