Commit ddc01ea9 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

some cleanup, removed unused parameters and code.

2002-03-03  Sven Neumann  <sven@gimp.org>

	* app/core/gimpimage-contiguous-region.c: some cleanup, removed
	unused parameters and code.

	* app/widgets/gimptoolinfopreview.c: fixed stupid bug I introduced
	yesterday.
parent ce643d27
2002-03-03 Sven Neumann <sven@gimp.org>
* app/core/gimpimage-contiguous-region.c: some cleanup, removed
unused parameters and code.
* app/widgets/gimptoolinfopreview.c: fixed stupid bug I introduced
yesterday.
2002-03-03 Michael Natterer <mitch@gimp.org> 2002-03-03 Michael Natterer <mitch@gimp.org>
Use gdouble in a [0.0..1.0] range for opacity values in the whole Use gdouble in a [0.0..1.0] range for opacity values in the whole
......
...@@ -38,43 +38,42 @@ ...@@ -38,43 +38,42 @@
/* local function prototypes */ /* local function prototypes */
static gint is_pixel_sufficiently_different (guchar *col1, static gint pixel_difference (guchar *col1,
guchar *col2, guchar *col2,
gboolean antialias, gboolean antialias,
gint threshold, gint threshold,
gint bytes, gint bytes,
gboolean has_alpha, gboolean has_alpha,
gboolean select_transparent); gboolean select_transparent);
static void ref_tiles (TileManager *src, static void ref_tiles (TileManager *src,
TileManager *mask, TileManager *mask,
Tile **s_tile, Tile **s_tile,
Tile **m_tile, Tile **m_tile,
gint x, gint x,
gint y, gint y,
guchar **s, guchar **s,
guchar **m); guchar **m);
static gint find_contiguous_segment (guchar *col, static gint find_contiguous_segment (guchar *col,
PixelRegion *src, PixelRegion *src,
PixelRegion *mask, PixelRegion *mask,
gint width, gint width,
gint bytes, gint bytes,
gboolean has_alpha, gboolean has_alpha,
gboolean select_transparent, gboolean select_transparent,
gboolean antialias, gboolean antialias,
gint threshold, gint threshold,
gint initial, gint initial,
gint *start, gint *start,
gint *end); gint *end);
static void find_contiguous_region_helper (PixelRegion *mask, static void find_contiguous_region_helper (PixelRegion *mask,
PixelRegion *src, PixelRegion *src,
gboolean has_alpha, gboolean has_alpha,
gboolean select_transparent, gboolean select_transparent,
gboolean antialias, gboolean antialias,
gint threshold, gint threshold,
gboolean indexed, gint x,
gint x, gint y,
gint y, guchar *col);
guchar *col);
/* public functions */ /* public functions */
...@@ -93,7 +92,6 @@ gimp_image_contiguous_region_by_seed (GimpImage *gimage, ...@@ -93,7 +92,6 @@ gimp_image_contiguous_region_by_seed (GimpImage *gimage,
GimpChannel *mask; GimpChannel *mask;
guchar *start; guchar *start;
gboolean has_alpha; gboolean has_alpha;
gboolean indexed;
gint bytes; gint bytes;
Tile *tile; Tile *tile;
...@@ -118,13 +116,11 @@ gimp_image_contiguous_region_by_seed (GimpImage *gimage, ...@@ -118,13 +116,11 @@ gimp_image_contiguous_region_by_seed (GimpImage *gimage,
has_alpha = gimp_drawable_has_alpha (drawable); has_alpha = gimp_drawable_has_alpha (drawable);
} }
indexed = gimp_drawable_is_indexed (drawable);
bytes = gimp_drawable_bytes (drawable);
if (indexed) if (gimp_drawable_is_indexed (drawable))
{ bytes = has_alpha ? 4 : 3;
bytes = has_alpha ? 4 : 3; else
} bytes = gimp_drawable_bytes (drawable);
mask = gimp_channel_new_mask (gimage, srcPR.w, srcPR.h); mask = gimp_channel_new_mask (gimage, srcPR.w, srcPR.h);
pixel_region_init (&maskPR, gimp_drawable_data (GIMP_DRAWABLE (mask)), pixel_region_init (&maskPR, gimp_drawable_data (GIMP_DRAWABLE (mask)),
...@@ -156,7 +152,7 @@ gimp_image_contiguous_region_by_seed (GimpImage *gimage, ...@@ -156,7 +152,7 @@ gimp_image_contiguous_region_by_seed (GimpImage *gimage,
find_contiguous_region_helper (&maskPR, &srcPR, has_alpha, find_contiguous_region_helper (&maskPR, &srcPR, has_alpha,
select_transparent, antialias, threshold, select_transparent, antialias, threshold,
bytes, x, y, start); x, y, start);
tile_release (tile, FALSE); tile_release (tile, FALSE);
} }
...@@ -274,6 +270,7 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage, ...@@ -274,6 +270,7 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage,
{ {
idata = image_data; idata = image_data;
mdata = mask_data; mdata = mask_data;
for (j = 0; j < imagePR.w; j++) for (j = 0; j < imagePR.w; j++)
{ {
/* Get the rgb values for the color */ /* Get the rgb values for the color */
...@@ -284,13 +281,10 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage, ...@@ -284,13 +281,10 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage,
rgb[color_bytes - 1] = idata[alpha]; rgb[color_bytes - 1] = idata[alpha];
/* Find how closely the colors match */ /* Find how closely the colors match */
*mdata++ = is_pixel_sufficiently_different (col, *mdata++ = pixel_difference (col, rgb,
rgb, antialias, threshold,
antialias, color_bytes,
threshold, has_alpha, select_transparent);
color_bytes,
has_alpha,
select_transparent);
idata += bytes; idata += bytes;
} }
...@@ -307,40 +301,35 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage, ...@@ -307,40 +301,35 @@ gimp_image_contiguous_region_by_color (GimpImage *gimage,
/* private functions */ /* private functions */
static gint static gint
is_pixel_sufficiently_different (guchar *col1, pixel_difference (guchar *col1,
guchar *col2, guchar *col2,
gboolean antialias, gboolean antialias,
gint threshold, gint threshold,
gint bytes, gint bytes,
gboolean has_alpha, gboolean has_alpha,
gboolean select_transparent) gboolean select_transparent)
{ {
gint diff; gint max = 0;
gint max;
gint b;
gint alpha;
max = 0;
alpha = (has_alpha) ? bytes - 1 : bytes;
/* if there is an alpha channel, never select transparent regions */ /* if there is an alpha channel, never select transparent regions */
if (! select_transparent && has_alpha && col2[alpha] == 0) if (! select_transparent && has_alpha && col2[bytes - 1] == 0)
return 0; return 0;
if (select_transparent && has_alpha) if (select_transparent && has_alpha)
{ {
max = col1[alpha] - col2[alpha]; max = abs (col1[bytes - 1] - col2[bytes - 1]);
max = abs (max);
} }
else else
{ {
/* fuzzy_select had a "for (b = 0; b < _bytes_; b++)" loop. however gint diff;
* i'm quite sure "b < alpha" is correct for both tools --Mitch gint b;
*/
for (b = 0; b < alpha; b++) if (has_alpha)
bytes--;
for (b = 0; b < bytes; b++)
{ {
diff = col1[b] - col2[b]; diff = abs (col1[b] - col2[b]);
diff = abs (diff);
if (diff > max) if (diff > max)
max = diff; max = diff;
} }
...@@ -348,11 +337,9 @@ is_pixel_sufficiently_different (guchar *col1, ...@@ -348,11 +337,9 @@ is_pixel_sufficiently_different (guchar *col1,
if (antialias && threshold > 0) if (antialias && threshold > 0)
{ {
gfloat aa; gfloat aa = 1.5 - ((gfloat) max / threshold);
aa = 1.5 - ((gfloat) max / threshold);
if (aa <= 0) if (aa <= 0.0)
return 0; return 0;
else if (aa < 0.5) else if (aa < 0.5)
return (guchar) (aa * 512); return (guchar) (aa * 512);
...@@ -410,12 +397,12 @@ find_contiguous_segment (guchar *col, ...@@ -410,12 +397,12 @@ find_contiguous_segment (guchar *col,
Tile *s_tile = NULL; Tile *s_tile = NULL;
Tile *m_tile = NULL; Tile *m_tile = NULL;
ref_tiles (src->tiles, mask->tiles, &s_tile, &m_tile, src->x, src->y, &s, &m); ref_tiles (src->tiles, mask->tiles,
&s_tile, &m_tile, src->x, src->y, &s, &m);
/* check the starting pixel */ /* check the starting pixel */
if (! (diff = is_pixel_sufficiently_different (col, s, antialias, if (! (diff = pixel_difference (col, s, antialias, threshold,
threshold, bytes, has_alpha, bytes, has_alpha, select_transparent)))
select_transparent)))
{ {
tile_release (s_tile, FALSE); tile_release (s_tile, FALSE);
tile_release (m_tile, TRUE); tile_release (m_tile, TRUE);
...@@ -429,11 +416,12 @@ find_contiguous_segment (guchar *col, ...@@ -429,11 +416,12 @@ find_contiguous_segment (guchar *col,
while (*start >= 0 && diff) while (*start >= 0 && diff)
{ {
if (! ((*start + 1) % TILE_WIDTH)) if (! ((*start + 1) % TILE_WIDTH))
ref_tiles (src->tiles, mask->tiles, &s_tile, &m_tile, *start, src->y, &s, &m); ref_tiles (src->tiles, mask->tiles,
&s_tile, &m_tile, *start, src->y, &s, &m);
diff = pixel_difference (col, s, antialias, threshold,
bytes, has_alpha, select_transparent);
diff = is_pixel_sufficiently_different (col, s, antialias,
threshold, bytes, has_alpha,
select_transparent);
if ((*m-- = diff)) if ((*m-- = diff))
{ {
s -= bytes; s -= bytes;
...@@ -443,17 +431,20 @@ find_contiguous_segment (guchar *col, ...@@ -443,17 +431,20 @@ find_contiguous_segment (guchar *col,
diff = 1; diff = 1;
*end = initial + 1; *end = initial + 1;
if (*end % TILE_WIDTH && *end < width) if (*end % TILE_WIDTH && *end < width)
ref_tiles (src->tiles, mask->tiles, &s_tile, &m_tile, *end, src->y, &s, &m); ref_tiles (src->tiles, mask->tiles,
&s_tile, &m_tile, *end, src->y, &s, &m);
while (*end < width && diff) while (*end < width && diff)
{ {
if (! (*end % TILE_WIDTH)) if (! (*end % TILE_WIDTH))
ref_tiles (src->tiles, mask->tiles, &s_tile, &m_tile, *end, src->y, &s, &m); ref_tiles (src->tiles, mask->tiles,
&s_tile, &m_tile, *end, src->y, &s, &m);
diff = pixel_difference (col, s, antialias, threshold,
bytes, has_alpha, select_transparent);
diff = is_pixel_sufficiently_different (col, s, antialias,
threshold, bytes, has_alpha,
select_transparent);
if ((*m++ = diff)) if ((*m++ = diff))
{ {
s += bytes; s += bytes;
...@@ -474,14 +465,12 @@ find_contiguous_region_helper (PixelRegion *mask, ...@@ -474,14 +465,12 @@ find_contiguous_region_helper (PixelRegion *mask,
gboolean select_transparent, gboolean select_transparent,
gboolean antialias, gboolean antialias,
gint threshold, gint threshold,
gboolean indexed,
gint x, gint x,
gint y, gint y,
guchar *col) guchar *col)
{ {
gint start, end, i; gint start, end, i;
gint val; gint val;
gint bytes;
Tile *tile; Tile *tile;
...@@ -501,25 +490,19 @@ find_contiguous_region_helper (PixelRegion *mask, ...@@ -501,25 +490,19 @@ find_contiguous_region_helper (PixelRegion *mask,
src->x = x; src->x = x;
src->y = y; src->y = y;
bytes = src->bytes; if (! find_contiguous_segment (col, src, mask, src->w, src->bytes,
if(indexed) has_alpha, select_transparent,
{ antialias, threshold,
bytes = has_alpha ? 4 : 3;
}
if (! find_contiguous_segment (col, src, mask, src->w,
src->bytes, has_alpha,
select_transparent, antialias, threshold,
x, &start, &end)) x, &start, &end))
return; return;
for (i = start + 1; i < end; i++) for (i = start + 1; i < end; i++)
{ {
find_contiguous_region_helper (mask, src, has_alpha, select_transparent, find_contiguous_region_helper (mask, src, has_alpha, select_transparent,
antialias, threshold, indexed, antialias, threshold,
i, y - 1, col); i, y - 1, col);
find_contiguous_region_helper (mask, src, has_alpha, select_transparent, find_contiguous_region_helper (mask, src, has_alpha, select_transparent,
antialias, threshold, indexed, antialias, threshold,
i, y + 1, col); i, y + 1, col);
} }
} }
...@@ -114,7 +114,6 @@ gimp_tool_info_preview_render (GimpPreview *preview) ...@@ -114,7 +114,6 @@ gimp_tool_info_preview_render (GimpPreview *preview)
GtkWidget *widget; GtkWidget *widget;
GimpToolInfo *tool_info; GimpToolInfo *tool_info;
TempBuf *temp_buf; TempBuf *temp_buf;
TempBuf *render_buf;
gint width; gint width;
gint height; gint height;
gint tool_info_width; gint tool_info_width;
...@@ -130,11 +129,9 @@ gimp_tool_info_preview_render (GimpPreview *preview) ...@@ -130,11 +129,9 @@ gimp_tool_info_preview_render (GimpPreview *preview)
width = preview->width; width = preview->width;
height = preview->height; height = preview->height;
if (width == tool_info_width && if (width == tool_info_width && height == tool_info_height)
height == tool_info_height)
{ {
temp_buf = gimp_viewable_get_preview (preview->viewable, temp_buf = gimp_viewable_get_preview (preview->viewable, width, height);
width, height);
} }
else else
{ {
...@@ -146,20 +143,22 @@ gimp_tool_info_preview_render (GimpPreview *preview) ...@@ -146,20 +143,22 @@ gimp_tool_info_preview_render (GimpPreview *preview)
switch (temp_buf->bytes) switch (temp_buf->bytes)
{ {
case 3: case 3:
render_buf = temp_buf; gimp_preview_render_and_flush (preview, temp_buf, -1);
break; break;
case 4: case 4:
{ {
gint x, y; TempBuf *render_buf;
guchar *src; gint x, y;
guchar *dest; guchar *src;
guchar color[3]; guchar *dest;
guchar color[3] =
color[0] = widget->style->bg[widget->state].red >> 8; {
color[1] = widget->style->bg[widget->state].green >> 8; widget->style->bg[widget->state].red >> 8,
color[2] = widget->style->bg[widget->state].blue >> 8; widget->style->bg[widget->state].green >> 8,
widget->style->bg[widget->state].blue >> 8
};
render_buf = temp_buf_new (width, height, 3, 0, 0, color); render_buf = temp_buf_new (width, height, 3, 0, 0, color);
src = temp_buf_data (temp_buf); src = temp_buf_data (temp_buf);
...@@ -192,20 +191,17 @@ gimp_tool_info_preview_render (GimpPreview *preview) ...@@ -192,20 +191,17 @@ gimp_tool_info_preview_render (GimpPreview *preview)
dest += 3; dest += 3;
} }
} }
gimp_preview_render_and_flush (preview, render_buf, -1);
} }
break; break;
default: default:
render_buf = 0;
g_assert_not_reached (); g_assert_not_reached ();
break; break;
} }
gimp_preview_render_and_flush (preview, render_buf, -1); if (new_buf)
temp_buf_free (render_buf);
if (new_buf && temp_buf->bytes != 3)
temp_buf_free (temp_buf); temp_buf_free (temp_buf);
} }
......
Markdown is supported
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