Commit 9efe077c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

also return the color's alpha byte if it has alpha, not only the converted

2004-01-18  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage.[ch] (gimp_image_get_color): also return the
	color's alpha byte if it has alpha, not only the converted RGB
	values.  Return OPAQUE_OPACITY for drawables without alpha.
	Fixes bug #131706.

	* app/core/gimpdrawable.c (gimp_drawable_get_color_at)
	* app/core/gimpimage-contiguous-region.c
	(gimp_image_contiguous_region_by_color)
	* app/core/gimpimage-projection.c (gimp_image_projection_get_color_at)
	* app/core/gimpimagemap.c (gimp_image_map_get_color_at)
	* app/paint/gimpclone.c (gimp_clone_line_image): removed separate
	handling of the alpha byte from all users of gimp_image_get_color().
parent b2c661e3
2004-01-18 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage.[ch] (gimp_image_get_color): also return the
color's alpha byte if it has alpha, not only the converted RGB
values. Return OPAQUE_OPACITY for drawables without alpha.
Fixes bug #131706.
* app/core/gimpdrawable.c (gimp_drawable_get_color_at)
* app/core/gimpimage-contiguous-region.c
(gimp_image_contiguous_region_by_color)
* app/core/gimpimage-projection.c (gimp_image_projection_get_color_at)
* app/core/gimpimagemap.c (gimp_image_map_get_color_at)
* app/paint/gimpclone.c (gimp_clone_line_image): removed separate
handling of the alpha byte from all users of gimp_image_get_color().
2004-01-18 Michael Natterer <mitch@gimp.org>
 
* app/paint/gimppaintcore.c (gimp_paint_core_get_paint_area): use
......@@ -1050,11 +1050,6 @@ gimp_drawable_get_color_at (GimpDrawable *drawable,
gimp_image_get_color (gimage, gimp_drawable_type (drawable), src, dest);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_drawable_type (drawable)))
dest[ALPHA_PIX] = src[gimp_drawable_bytes (drawable) - 1];
else
dest[ALPHA_PIX] = OPAQUE_OPACITY;
if (gimp_drawable_is_indexed (drawable))
dest[4] = src[0];
else
......
......@@ -295,10 +295,6 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage,
/* Get the rgb values for the color */
gimp_image_get_color (gimage, d_type, idata, rgb);
/* Plug the alpha channel in there */
if (has_alpha)
rgb[color_bytes - 1] = idata[alpha];
/* Find how closely the colors match */
*mdata++ = pixel_difference (col, rgb,
antialias, threshold,
......
......@@ -215,11 +215,6 @@ gimp_image_projection_get_color_at (GimpImage *gimage,
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
gimp_image_get_color (gimage, gimp_image_projection_type (gimage), src, dest);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_image_projection_type (gimage)))
dest[3] = src[gimp_image_projection_bytes (gimage) - 1];
else
dest[3] = OPAQUE_OPACITY;
dest[4] = 0;
tile_release (tile, FALSE);
......
......@@ -1647,40 +1647,53 @@ void
gimp_image_get_color (const GimpImage *src_gimage,
GimpImageType src_type,
const guchar *src,
guchar *rgb)
guchar *rgba)
{
gboolean has_alpha = FALSE;
g_return_if_fail (GIMP_IS_IMAGE (src_gimage));
switch (src_type)
{
case GIMP_RGB_IMAGE:
case GIMP_RGBA_IMAGE:
has_alpha = TRUE;
case GIMP_RGB_IMAGE:
/* Straight copy */
*rgb++ = *src++;
*rgb++ = *src++;
*rgb = *src;
*rgba++ = *src++;
*rgba++ = *src++;
*rgba++ = *src++;
break;
case GIMP_GRAY_IMAGE:
case GIMP_GRAYA_IMAGE:
has_alpha = TRUE;
case GIMP_GRAY_IMAGE:
/* Gray to RG&B */
*rgb++ = *src;
*rgb++ = *src;
*rgb = *src;
*rgba++ = *src;
*rgba++ = *src;
*rgba++ = *src++;
break;
case GIMP_INDEXED_IMAGE:
case GIMP_INDEXEDA_IMAGE:
has_alpha = TRUE;
case GIMP_INDEXED_IMAGE:
/* Indexed palette lookup */
{
gint index = *src * 3;
gint index = *src++ * 3;
*rgb++ = src_gimage->cmap[index++];
*rgb++ = src_gimage->cmap[index++];
*rgb = src_gimage->cmap[index++];
*rgba++ = src_gimage->cmap[index++];
*rgba++ = src_gimage->cmap[index++];
*rgba++ = src_gimage->cmap[index++];
}
break;
}
if (has_alpha)
*rgba = *src;
else
*rgba = OPAQUE_OPACITY;
}
void
......
......@@ -332,7 +332,7 @@ void gimp_image_get_background (const GimpImage *gimage,
void gimp_image_get_color (const GimpImage *src_gimage,
GimpImageType src_type,
const guchar *src,
guchar *rgb);
guchar *rgba);
void gimp_image_transform_color (const GimpImage *dest_gimage,
const GimpDrawable *dest_drawable,
guchar *dest,
......
......@@ -263,10 +263,10 @@ gimp_image_map_apply (GimpImageMap *image_map,
{
/* Reset to initial drawable conditions. */
/* Copy from the backup undo tiles to the drawable */
pixel_region_init (&image_map->srcPR, image_map->undo_tiles,
pixel_region_init (&image_map->srcPR, image_map->undo_tiles,
0, 0, width, height, FALSE);
pixel_region_init (&image_map->destPR,
gimp_drawable_data (image_map->drawable),
gimp_drawable_data (image_map->drawable),
offset_x, offset_y, width, height, TRUE);
copy_region (&image_map->srcPR, &image_map->destPR);
......@@ -374,13 +374,13 @@ gimp_image_map_clear (GimpImageMap *image_map)
height = tile_manager_height (image_map->undo_tiles),
/* Copy from the drawable to the tiles */
pixel_region_init (&srcPR, image_map->undo_tiles,
pixel_region_init (&srcPR, image_map->undo_tiles,
0, 0, width, height, FALSE);
pixel_region_init (&destPR, gimp_drawable_data (image_map->drawable),
offset_x, offset_y, width, height, TRUE);
/* if the user has changed the image depth get out quickly */
if (destPR.bytes != srcPR.bytes)
if (destPR.bytes != srcPR.bytes)
{
g_message ("image depth change, unable to restore original image");
......@@ -429,8 +429,8 @@ gimp_image_map_abort (GimpImageMap *image_map)
}
guchar *
gimp_image_map_get_color_at (GimpImageMap *image_map,
gint x,
gimp_image_map_get_color_at (GimpImageMap *image_map,
gint x,
gint y)
{
guchar src[5];
......@@ -438,7 +438,7 @@ gimp_image_map_get_color_at (GimpImageMap *image_map,
g_return_val_if_fail (GIMP_IS_IMAGE_MAP (image_map), NULL);
if (x >= 0 && x < gimp_item_width (GIMP_ITEM (image_map->drawable)) &&
if (x >= 0 && x < gimp_item_width (GIMP_ITEM (image_map->drawable)) &&
y >= 0 && y < gimp_item_height (GIMP_ITEM (image_map->drawable)))
{
/* Check if done damage to original image */
......@@ -446,7 +446,7 @@ gimp_image_map_get_color_at (GimpImageMap *image_map,
return gimp_drawable_get_color_at (image_map->drawable, x, y);
if (! image_map ||
(! gimp_item_get_image (GIMP_ITEM (image_map->drawable)) &&
(! gimp_item_get_image (GIMP_ITEM (image_map->drawable)) &&
gimp_drawable_is_indexed (image_map->drawable)) ||
x < 0 || y < 0 ||
x >= tile_manager_width (image_map->undo_tiles) ||
......@@ -456,18 +456,13 @@ gimp_image_map_get_color_at (GimpImageMap *image_map,
}
dest = g_new (guchar, 5);
read_pixel_data_1 (image_map->undo_tiles, x, y, src);
gimp_image_get_color (gimp_item_get_image (GIMP_ITEM (image_map->drawable)),
gimp_drawable_type (image_map->drawable),
src, dest);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_drawable_type (image_map->drawable)))
dest[3] = src[gimp_drawable_bytes (image_map->drawable) - 1];
else
dest[3] = 255;
if (gimp_drawable_is_indexed (image_map->drawable))
dest[4] = src[0];
else
......
......@@ -215,11 +215,6 @@ gimp_image_projection_get_color_at (GimpImage *gimage,
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
gimp_image_get_color (gimage, gimp_image_projection_type (gimage), src, dest);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_image_projection_type (gimage)))
dest[3] = src[gimp_image_projection_bytes (gimage) - 1];
else
dest[3] = OPAQUE_OPACITY;
dest[4] = 0;
tile_release (tile, FALSE);
......
......@@ -470,21 +470,17 @@ gimp_clone_line_image (GimpImage *dest,
gint dest_bytes,
gint width)
{
guchar rgb[3];
gint src_alpha, dest_alpha;
guchar rgba[MAX_CHANNELS];
gint alpha;
src_alpha = src_bytes - 1;
dest_alpha = dest_bytes - 1;
alpha = dest_bytes - 1;
while (width--)
{
gimp_image_get_color (src, gimp_drawable_type (s_drawable), s, rgb);
gimp_image_transform_color (dest, d_drawable, d, GIMP_RGB, rgb);
gimp_image_get_color (src, gimp_drawable_type (s_drawable), s, rgba);
gimp_image_transform_color (dest, d_drawable, d, GIMP_RGB, rgba);
if (has_alpha)
d[dest_alpha] = s[src_alpha];
else
d[dest_alpha] = OPAQUE_OPACITY;
d[alpha] = rgba[ALPHA_PIX];
s += src_bytes;
d += dest_bytes;
......
......@@ -470,21 +470,17 @@ gimp_clone_line_image (GimpImage *dest,
gint dest_bytes,
gint width)
{
guchar rgb[3];
gint src_alpha, dest_alpha;
guchar rgba[MAX_CHANNELS];
gint alpha;
src_alpha = src_bytes - 1;
dest_alpha = dest_bytes - 1;
alpha = dest_bytes - 1;
while (width--)
{
gimp_image_get_color (src, gimp_drawable_type (s_drawable), s, rgb);
gimp_image_transform_color (dest, d_drawable, d, GIMP_RGB, rgb);
gimp_image_get_color (src, gimp_drawable_type (s_drawable), s, rgba);
gimp_image_transform_color (dest, d_drawable, d, GIMP_RGB, rgba);
if (has_alpha)
d[dest_alpha] = s[src_alpha];
else
d[dest_alpha] = OPAQUE_OPACITY;
d[alpha] = rgba[ALPHA_PIX];
s += src_bytes;
d += dest_bytes;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment