app: cleaned dissolve and lighten only modes

This commit is contained in:
Ville Sokk 2012-04-18 21:35:38 +03:00 committed by Michael Natterer
parent 793bebe2d3
commit 0233c99c8b
2 changed files with 19 additions and 17 deletions

View File

@ -99,12 +99,12 @@ gimp_operation_dissolve_mode_process (GeglOperation *operation,
const GeglRectangle *result,
gint level)
{
gint x, y, i;
gint x, y;
gfloat *in = in_buf;
gfloat *out = out_buf;
gfloat *aux = aux_buf;
for (i = 0, y = result->y; y < result->y + result->height; y++)
for (y = result->y; y < result->y + result->height; y++)
{
GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]);
@ -112,7 +112,7 @@ gimp_operation_dissolve_mode_process (GeglOperation *operation,
for (x = 0; x < result->x; x++)
g_rand_int (gr);
for (x = result->x; x < result->x + result->width; x++, i++)
for (x = result->x; x < result->x + result->width; x++)
{
if (g_rand_int_range (gr, 0, 255) >= aux[3] * 255)
{

View File

@ -28,7 +28,7 @@
#include "gimpoperationlightenonlymode.h"
static void gimp_operation_lighten_only_mode_prepare (GeglOperation *operation);
static gboolean gimp_operation_lighten_only_mode_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
@ -41,14 +41,6 @@ static gboolean gimp_operation_lighten_only_mode_process (GeglOperation *o
G_DEFINE_TYPE (GimpOperationLightenOnlyMode, gimp_operation_lighten_only_mode,
GIMP_TYPE_OPERATION_POINT_LAYER_MODE)
static void prepare (GeglOperation *operation)
{
const Babl *format = babl_format ("R'G'B'A float");
gegl_operation_set_format (operation, "input", format);
gegl_operation_set_format (operation, "aux", format);
gegl_operation_set_format (operation, "output", format);
}
static void
gimp_operation_lighten_only_mode_class_init (GimpOperationLightenOnlyModeClass *klass)
@ -65,7 +57,7 @@ gimp_operation_lighten_only_mode_class_init (GimpOperationLightenOnlyModeClass *
NULL);
point_class->process = gimp_operation_lighten_only_mode_process;
operation_class->prepare = prepare;
operation_class->prepare = gimp_operation_lighten_only_mode_prepare;
}
static void
@ -73,6 +65,16 @@ gimp_operation_lighten_only_mode_init (GimpOperationLightenOnlyMode *self)
{
}
static void
gimp_operation_lighten_only_mode_prepare (GeglOperation *operation)
{
const Babl *format = babl_format ("R'G'B'A float");
gegl_operation_set_format (operation, "input", format);
gegl_operation_set_format (operation, "aux", format);
gegl_operation_set_format (operation, "output", format);
}
static gboolean
gimp_operation_lighten_only_mode_process (GeglOperation *operation,
void *in_buf,
@ -89,12 +91,10 @@ gimp_operation_lighten_only_mode_process (GeglOperation *operation,
while (samples--)
{
gint b;
gfloat comp_alpha = MIN (in[ALPHA] * layer[ALPHA], layer[ALPHA] * in[ALPHA]);
gfloat comp_alpha = in[ALPHA] * layer[ALPHA];
gfloat new_alpha = in[ALPHA] + (1 - in[ALPHA]) * comp_alpha;
gfloat ratio = comp_alpha / new_alpha;
out[ALPHA] = in[ALPHA];
for (b = RED; b < ALPHA; b++)
{
gfloat comp = MAX (layer[b], in[b]);
@ -102,6 +102,8 @@ gimp_operation_lighten_only_mode_process (GeglOperation *operation,
out[b] = comp * ratio + in[b] * (1 - ratio);
}
out[ALPHA] = in[ALPHA];
in += 4;
layer += 4;
out += 4;