app: apply patch from Villa Sokk that implements GimpOperationDissolveMode
This commit is contained in:
@ -1033,7 +1033,6 @@ gimp_layer_sync_mode_node (GimpLayer *layer)
|
||||
|
||||
switch (layer->mode)
|
||||
{
|
||||
case GIMP_DISSOLVE_MODE:
|
||||
case GIMP_BEHIND_MODE:
|
||||
case GIMP_MULTIPLY_MODE:
|
||||
case GIMP_SCREEN_MODE:
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpoperationdissolvemode.c
|
||||
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
|
||||
* Copyright (C) 2012 Ville Sokk <ville.sokk@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -28,6 +28,9 @@
|
||||
#include "gimpoperationdissolvemode.h"
|
||||
|
||||
|
||||
#define RANDOM_TABLE_SIZE 4096
|
||||
|
||||
|
||||
static gboolean gimp_operation_dissolve_mode_process (GeglOperation *operation,
|
||||
void *in_buf,
|
||||
void *aux_buf,
|
||||
@ -40,12 +43,16 @@ static gboolean gimp_operation_dissolve_mode_process (GeglOperation *opera
|
||||
G_DEFINE_TYPE (GimpOperationDissolveMode, gimp_operation_dissolve_mode,
|
||||
GIMP_TYPE_OPERATION_POINT_LAYER_MODE)
|
||||
|
||||
static gint32 random_table[RANDOM_TABLE_SIZE];
|
||||
|
||||
|
||||
static void
|
||||
gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass)
|
||||
{
|
||||
GeglOperationClass *operation_class;
|
||||
GeglOperationPointComposerClass *point_class;
|
||||
GRand *gr;
|
||||
gint i;
|
||||
|
||||
operation_class = GEGL_OPERATION_CLASS (klass);
|
||||
point_class = GEGL_OPERATION_POINT_COMPOSER_CLASS (klass);
|
||||
@ -56,6 +63,18 @@ gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass)
|
||||
NULL);
|
||||
|
||||
point_class->process = gimp_operation_dissolve_mode_process;
|
||||
|
||||
#define RANDOM_SEED 314159265
|
||||
|
||||
/* generate a table of random seeds */
|
||||
gr = g_rand_new_with_seed (RANDOM_SEED);
|
||||
|
||||
for (i = 0; i < RANDOM_TABLE_SIZE; i++)
|
||||
{
|
||||
random_table[i] = g_rand_int (gr);
|
||||
}
|
||||
|
||||
g_rand_free (gr);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -72,20 +91,59 @@ gimp_operation_dissolve_mode_process (GeglOperation *operation,
|
||||
const GeglRectangle *roi,
|
||||
gint level)
|
||||
{
|
||||
gfloat *in = in_buf;
|
||||
gfloat *layer = aux_buf;
|
||||
gfloat *out = out_buf;
|
||||
gfloat *in = in_buf;
|
||||
gfloat *layer = aux_buf;
|
||||
gfloat *out = out_buf;
|
||||
gint x = roi->x;
|
||||
gint y = roi->y;
|
||||
gint width = roi->width;
|
||||
gint height = roi->height;
|
||||
gint row;
|
||||
|
||||
while (samples--)
|
||||
for (row = 0; row < height; row++)
|
||||
{
|
||||
out[RED] = in[RED];
|
||||
out[GREEN] = in[GREEN];
|
||||
out[BLUE] = in[BLUE];
|
||||
out[ALPHA] = in[ALPHA];
|
||||
GRand *gr;
|
||||
gint pixel;
|
||||
gint i;
|
||||
|
||||
in += 4;
|
||||
layer += 4;
|
||||
out += 4;
|
||||
gr = g_rand_new_with_seed (random_table[(y + row) % RANDOM_TABLE_SIZE]);
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
g_rand_int (gr);
|
||||
}
|
||||
|
||||
for (pixel = 0; pixel < width; pixel++)
|
||||
{
|
||||
gdouble rand_val;
|
||||
|
||||
/* dissolve if random value is >= opacity */
|
||||
rand_val = g_rand_double_range (gr, 0.0, 1.0);
|
||||
|
||||
if (layer[ALPHA] >= rand_val)
|
||||
{
|
||||
out[ALPHA] = 1.0;
|
||||
|
||||
for (i = RED; i < ALPHA; i++)
|
||||
{
|
||||
out[i] = layer[ALPHA] ? layer[i] / layer[ALPHA] : 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out[ALPHA] = in[ALPHA];
|
||||
|
||||
for (i = RED; i < ALPHA; i++)
|
||||
{
|
||||
out[i] = in[i];
|
||||
}
|
||||
}
|
||||
|
||||
in += 4;
|
||||
layer += 4;
|
||||
out += 4;
|
||||
}
|
||||
|
||||
g_rand_free (gr);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
Reference in New Issue
Block a user