brought the array used for optimization back in sync with the

2001-01-24  Sven Neumann  <sven@gimp.org>

	* app/paint_funcs.c: brought the array used for optimization back in
	sync with the LayerModeEffects enum. This was causing really strange
	rendering errors. Started to clean up the file up and removed the
	unused layer_mode names.

	* app/tile.[ch]
	* plug-ins/common/colortoalpha.c: small cleanups

	* po/POTFILES.in: removed app/paint_funcs.c
This commit is contained in:
Sven Neumann 2001-01-24 15:36:55 +00:00 committed by Sven Neumann
parent 5439fe5b01
commit 911893e0f9
9 changed files with 1010 additions and 901 deletions

View File

@ -1,3 +1,15 @@
2001-01-24 Sven Neumann <sven@gimp.org>
* app/paint_funcs.c: brought the array used for optimization back in
sync with the LayerModeEffects enum. This was causing really strange
rendering errors. Started to clean up the file up and removed the
unused layer_mode names.
* app/tile.[ch]
* plug-ins/common/colortoalpha.c: small cleanups
* po/POTFILES.in: removed app/paint_funcs.c
2001-01-24 Sven Neumann <sven@gimp.org> 2001-01-24 Sven Neumann <sven@gimp.org>
* app/tools/airbrush.c * app/tools/airbrush.c

View File

@ -167,13 +167,14 @@ tile_lock (Tile *tile)
} }
void void
tile_release (Tile *tile, int dirty) tile_release (Tile *tile,
gboolean dirty)
{ {
/* Decrement the global reference count. /* Decrement the global reference count.
*/ */
tile_ref_count--; tile_ref_count--;
TILE_MUTEX_LOCK(tile); TILE_MUTEX_LOCK (tile);
/* Decrement this tile's reference count. /* Decrement this tile's reference count.
*/ */

View File

@ -62,7 +62,7 @@ void tile_init (Tile *tile,
void tile_lock (Tile *tile); void tile_lock (Tile *tile);
void tile_release (Tile *tile, void tile_release (Tile *tile,
gint); gboolean dirty);
/* Allocate the data for the tile. /* Allocate the data for the tile.
*/ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -167,13 +167,14 @@ tile_lock (Tile *tile)
} }
void void
tile_release (Tile *tile, int dirty) tile_release (Tile *tile,
gboolean dirty)
{ {
/* Decrement the global reference count. /* Decrement the global reference count.
*/ */
tile_ref_count--; tile_ref_count--;
TILE_MUTEX_LOCK(tile); TILE_MUTEX_LOCK (tile);
/* Decrement this tile's reference count. /* Decrement this tile's reference count.
*/ */

View File

@ -62,7 +62,7 @@ void tile_init (Tile *tile,
void tile_lock (Tile *tile); void tile_lock (Tile *tile);
void tile_release (Tile *tile, void tile_release (Tile *tile,
gint); gboolean dirty);
/* Allocate the data for the tile. /* Allocate the data for the tile.
*/ */

View File

@ -61,17 +61,17 @@ static void run (gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals); GimpParam **return_vals);
static void colortoalpha (GimpRGB *src, static void colortoalpha (GimpRGB *src,
GimpRGB *color); const GimpRGB *color);
static void toalpha (GimpDrawable *drawable); static void toalpha (GimpDrawable *drawable);
static void toalpha_render_row (const guchar *src_row, static void toalpha_render_row (const guchar *src_row,
guchar *dest_row, guchar *dest_row,
gint row_width, gint row_width,
const gint bytes); const gint bytes);
/* UI stuff */ /* UI stuff */
static gboolean colortoalpha_dialog (GimpDrawable *drawable); static gboolean colortoalpha_dialog (GimpDrawable *drawable);
static void colortoalpha_ok_callback (GtkWidget *widget, static void colortoalpha_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static GimpRunModeType run_mode; static GimpRunModeType run_mode;
@ -211,8 +211,8 @@ run (gchar *name,
} }
static void static void
colortoalpha (GimpRGB *src, colortoalpha (GimpRGB *src,
GimpRGB *color) const GimpRGB *color)
{ {
GimpRGB alpha; GimpRGB alpha;
@ -273,23 +273,30 @@ colortoalpha (GimpRGB *src,
} }
/* /*
<clahey> so if a1 > c1, a2 > c2, and a3 > c2 and a1 - c1 > a2-c2, a3-c3, then a1 = b1 * alpha + c1 * (1-alpha) So, maximizing alpha without taking b1 above 1 gives a1 = alpha + c1(1-alpha) and therefore alpha = (a1-c1)/(1-c1). <clahey> so if a1 > c1, a2 > c2, and a3 > c2 and a1 - c1 > a2-c2, a3-c3,
<AmJur2d> eek! math! then a1 = b1 * alpha + c1 * (1-alpha)
> AmJur2d runs and hides behind a library carrel So, maximizing alpha without taking b1 above 1 gives
<sjburges> clahey: btw, the ordering of that a2, a3 in the white->alpha didn't matter a1 = alpha + c1(1-alpha) and therefore alpha = (a1-c1) / (1-c1).
<clahey> sjburges: You mean that it could be either a1, a2, a3 or a1, a3, a2? <sjburges> clahey: btw, the ordering of that a2, a3 in the white->alpha didn't
<sjburges> yeah matter
<sjburges> because neither one uses the other <clahey> sjburges: You mean that it could be either a1, a2, a3 or a1, a3, a2?
<clahey> sjburges: That's exactly as it should be. They are both just getting reduced to the same amount, limited by the the darkest color. <sjburges> yeah
<clahey> Then a2 = b2 * alpha + c2 * ( 1- alpha). Solving for b2 gives b2 = (a1-c2)/alpha + c2. <sjburges> because neither one uses the other
<sjburges> yeah <clahey> sjburges: That's exactly as it should be. They are both just getting
<jlb> xachbot, url holy wars reduced to the same amount, limited by the the darkest color.
<jlb> xachbot, url wars <clahey> Then a2 = b2 * alpha + c2 * ( 1- alpha). Solving for b2 gives
<clahey> That gives us are formula for if the background is darker than the foreground? Yep. b2 = (a1-c2)/alpha + c2.
<clahey> Next if a1 < c1, a2 < c2, a3 < c3, and c1-a1 > c2-a2, c3-a3, and by our desired result a1 = b1 * alpha + c1 * (1-alpha), we maximize alpha without taking b1 negative gives alpha = 1-a1/c1. <sjburges> yeah
<clahey> And then again, b2 = (a2-c2)/alpha + c2 by the same formula. (Actually, I think we can use that formula for all cases, though it may possibly introduce rounding error. <clahey> That gives us are formula for if the background is darker than the
<clahey> sjburges: I like the idea of using floats to avoid rounding error. Good call. foreground? Yep.
<clahey> It's cool to be able to replace all the black in an image with another color. It' <clahey> Next if a1 < c1, a2 < c2, a3 < c3, and c1-a1 > c2-a2, c3-a3, and by our
desired result a1 = b1 * alpha + c1 * (1-alpha), we maximize alpha
without taking b1 negative gives alpha = 1 - a1 / c1.
<clahey> And then again, b2 = (a2-c2) / alpha + c2 by the same formula.
(Actually, I think we can use that formula for all cases, though it
may possibly introduce rounding error.
<clahey> sjburges: I like the idea of using floats to avoid rounding error.
Good call.
*/ */
static void static void
@ -298,28 +305,23 @@ toalpha_render_row (const guchar *src_data,
gint col, /* row width in pixels */ gint col, /* row width in pixels */
const gint bytes) const gint bytes)
{ {
GimpRGB src; GimpRGB color;
while (col--) while (col--)
{ {
gimp_rgba_set (&src, gimp_rgba_set_uchar (&color,
(gdouble) src_data[col * bytes ] / 255.0, src_data[col * bytes ],
(gdouble) src_data[col * bytes + 1] / 255.0, src_data[col * bytes + 1],
(gdouble) src_data[col * bytes + 2] / 255.0, src_data[col * bytes + 2],
(gdouble) src_data[col * bytes + 3] / 255.0); src_data[col * bytes + 3]);
/* For brighter than the background the rule is to send the colortoalpha (&color, &pvals.color);
farthest above the background as the first address.
However, since v1 < COLOR_RED, for example, all of these
are negative so we have to invert the operator to reduce
the amount of typing to fix the problem. :) */
colortoalpha (&src, &pvals.color); gimp_rgba_get_uchar (&color,
&dest_data[col * bytes],
dest_data[col * bytes ] = src.r * 255.999; &dest_data[col * bytes + 1],
dest_data[col * bytes + 1] = src.g * 255.999; &dest_data[col * bytes + 2],
dest_data[col * bytes + 2] = src.b * 255.999; &dest_data[col * bytes + 3]);
dest_data[col * bytes + 3] = src.a * 255.999;
} }
} }
@ -364,10 +366,13 @@ toalpha (GimpDrawable *drawable)
*/ */
gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2); gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1); total_area = (x2 - x1) * (y2 - y1);
area_so_far = 0; area_so_far = 0;
progress_skip = 0; progress_skip = 0;
if (total_area < 1)
return;
/* Initialize the pixel regions. */ /* Initialize the pixel regions. */
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1), gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
FALSE, FALSE); FALSE, FALSE);
@ -384,8 +389,7 @@ toalpha (GimpDrawable *drawable)
{ {
area_so_far += srcPR.w * srcPR.h; area_so_far += srcPR.w * srcPR.h;
if (++progress_skip % 10 == 0) if (++progress_skip % 10 == 0)
gimp_progress_update ((gdouble) area_so_far / gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
(gdouble) total_area);
} }
} }

View File

@ -53,7 +53,6 @@ app/main.c
app/menus.c app/menus.c
app/module_db.c app/module_db.c
app/nav_window.c app/nav_window.c
app/paint_funcs.c
app/palette.c app/palette.c
app/palette_import.c app/palette_import.c
app/palette_select.c app/palette_select.c