Bug 547967 – Improve app/paint-funcs/ maintainability

2008-10-13  Sven Neumann  <sven@gimp.org>

	Bug 547967 – Improve app/paint-funcs/ maintainability

	Applied patch from Luidnel Maignan that splits the legacy code 
for
	layer modes into new files.
	
	* app/paint-funcs/Makefile.am
	* app/paint-funcs/layer-modes.[ch]
	* app/paint-funcs/paint-funcs-utils.h: new files with code taken
	from ...

	* app/paint-funcs/paint-funcs-generic.h
	* app/paint-funcs/paint-funcs.c: ... these two files.


svn path=/trunk/; revision=27268
This commit is contained in:
Sven Neumann 2008-10-13 18:51:32 +00:00 committed by Sven Neumann
parent 8403da8b60
commit b387734c3d
7 changed files with 1261 additions and 1169 deletions

View File

@ -1,3 +1,18 @@
2008-10-13 Sven Neumann <sven@gimp.org>
Bug 547967 Improve app/paint-funcs/ maintainability
Applied patch from Luidnel Maignan that splits the legacy code for
layer modes into new files.
* app/paint-funcs/Makefile.am
* app/paint-funcs/layer-modes.[ch]
* app/paint-funcs/paint-funcs-utils.h: new files with code taken
from ...
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c: ... these two files.
2008-10-13 Michael Natterer <mitch@gimp.org>
* app/gegl/gimp-gegl-utils.c (gimp_layer_mode_to_gegl_operation):

View File

@ -19,10 +19,13 @@ INCLUDES = \
noinst_LIBRARIES = libapppaint-funcs.a
libapppaint_funcs_a_SOURCES = \
paint-funcs-types.h \
layer-modes.c \
layer-modes.h \
paint-funcs.c \
paint-funcs.h \
paint-funcs-generic.h \
paint-funcs-types.h \
paint-funcs-utils.h \
reduce-region.c \
reduce-region.h \
scale-region.c \

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C); 1995 Spencer Kimball and Peter Mattis
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option); any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __LAYER_MODES_H__
#define __LAYER_MODES_H__
/* FIXME: This function should not be called directly but
* through layer_dissolve_mode function
*/
void dissolve_pixels (const guchar *src,
const guchar *mask,
guchar *dest,
gint x,
gint y,
gint opacity,
gint length,
gint sb,
gint db,
gboolean has_alpha);
struct apply_layer_mode_struct
{
guint bytes1 : 3;
guint bytes2 : 3;
guchar *src1;
guchar *src2;
const guchar *mask;
guchar **dest;
gint x;
gint y;
guint opacity;
guint length;
CombinationMode combine;
};
void layer_modes_setup (void);
void layer_normal_mode (struct apply_layer_mode_struct *alms);
void layer_dissolve_mode (struct apply_layer_mode_struct *alms);
void layer_multiply_mode (struct apply_layer_mode_struct *alms);
void layer_divide_mode (struct apply_layer_mode_struct *alms);
void layer_screen_mode (struct apply_layer_mode_struct *alms);
void layer_overlay_mode (struct apply_layer_mode_struct *alms);
void layer_difference_mode (struct apply_layer_mode_struct *alms);
void layer_addition_mode (struct apply_layer_mode_struct *alms);
void layer_subtract_mode (struct apply_layer_mode_struct *alms);
void layer_darken_only_mode (struct apply_layer_mode_struct *alms);
void layer_lighten_only_mode (struct apply_layer_mode_struct *alms);
void layer_hue_mode (struct apply_layer_mode_struct *alms);
void layer_saturation_mode (struct apply_layer_mode_struct *alms);
void layer_value_mode (struct apply_layer_mode_struct *alms);
void layer_color_mode (struct apply_layer_mode_struct *alms);
void layer_behind_mode (struct apply_layer_mode_struct *alms);
void layer_replace_mode (struct apply_layer_mode_struct *alms);
void layer_erase_mode (struct apply_layer_mode_struct *alms);
void layer_anti_erase_mode (struct apply_layer_mode_struct *alms);
void layer_color_erase_mode (struct apply_layer_mode_struct *alms);
void layer_dodge_mode (struct apply_layer_mode_struct *alms);
void layer_burn_mode (struct apply_layer_mode_struct *alms);
void layer_hardlight_mode (struct apply_layer_mode_struct *alms);
void layer_softlight_mode (struct apply_layer_mode_struct *alms);
void layer_grain_extract_mode (struct apply_layer_mode_struct *alms);
void layer_grain_merge_mode (struct apply_layer_mode_struct *alms);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PAINT_FUNCS_UTILS_H__
#define __PAINT_FUNCS_UTILS_H__
#define INT_MULT(a,b,t) ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8))
/* This version of INT_MULT3 is very fast, but suffers from some
slight roundoff errors. It returns the correct result 99.987
percent of the time */
#define INT_MULT3(a,b,c,t) ((t) = (a) * (b) * (c) + 0x7F5B, \
((((t) >> 7) + (t)) >> 16))
/*
This version of INT_MULT3 always gives the correct result, but runs at
approximatly one third the speed. */
/* #define INT_MULT3(a,b,c,t) (((a) * (b) * (c) + 32512) / 65025.0)
*/
#define INT_BLEND(a,b,alpha,tmp) (INT_MULT((a) - (b), alpha, tmp) + (b))
/* A drawable has an alphachannel if contains either 4 or 2 bytes data
* aka GRAYA and RGBA and thus the macro below works. This will have
* to change if we support bigger formats. We'll do it so for now because
* masking is always cheaper than passing parameters over the stack. */
/* FIXME: Move to a global place */
#define HAS_ALPHA(bytes) (~bytes & 1)
#endif /* __PAINT_FUNCS_UTILS_H__ */

View File

@ -37,10 +37,11 @@
#include "composite/gimp-composite.h"
#include "paint-funcs.h"
#include "layer-modes.h"
#include "paint-funcs-utils.h"
#include "paint-funcs-generic.h"
#define RANDOM_SEED 314159265
#define EPSILON 0.0001
#define LOG_1_255 -5.541263545 /* log (1.0 / 255.0) */
@ -248,22 +249,7 @@ cubic (gdouble dx,
void
paint_funcs_setup (void)
{
GRand *gr;
gint i;
/* 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);
for (i = 0; i < 256; i++)
add_lut[i] = i;
for (i = 256; i <= 510; i++)
add_lut[i] = 255;
g_rand_free (gr);
layer_modes_setup ();
}
void
@ -668,40 +654,6 @@ combine_inten_and_inten_a_pixels (const guchar *src1,
}
}
/*orig #define alphify(src2_alpha,new_alpha) \
if (new_alpha == 0 || src2_alpha == 0) \
{ \
for (b = 0; b < alpha; b++) \
dest[b] = src1 [b]; \
} \
else if (src2_alpha == new_alpha){ \
for (b = 0; b < alpha; b++) \
dest [b] = affect [b] ? src2 [b] : src1 [b]; \
} else { \
ratio = (float) src2_alpha / new_alpha; \
compl_ratio = 1.0 - ratio; \
\
for (b = 0; b < alpha; b++) \
dest[b] = affect[b] ? \
(guchar) (src2[b] * ratio + src1[b] * compl_ratio + EPSILON) : src1[b]; \
}*/
/*shortened #define alphify(src2_alpha,new_alpha) \
if (src2_alpha != 0 && new_alpha != 0) \
{ \
if (src2_alpha == new_alpha){ \
for (b = 0; b < alpha; b++) \
dest [b] = affect [b] ? src2 [b] : src1 [b]; \
} else { \
ratio = (float) src2_alpha / new_alpha; \
compl_ratio = 1.0 - ratio; \
\
for (b = 0; b < alpha; b++) \
dest[b] = affect[b] ? \
(guchar) (src2[b] * ratio + src1[b] * compl_ratio + EPSILON) : src1[b];\
} \
}*/
#define alphify(src2_alpha,new_alpha) \
if (src2_alpha != 0 && new_alpha != 0) \
{ \
@ -720,26 +672,6 @@ combine_inten_and_inten_a_pixels (const guchar *src1,
} \
}
/*special #define alphify4(src2_alpha,new_alpha) \
if (src2_alpha != 0 && new_alpha != 0) \
{ \
if (src2_alpha == new_alpha){ \
dest [0] = affect [0] ? src2 [0] : src1 [0]; \
dest [1] = affect [1] ? src2 [1] : src1 [1]; \
dest [2] = affect [2] ? src2 [2] : src1 [2]; \
} else { \
ratio = (float) src2_alpha / new_alpha; \
compl_ratio = 1.0 - ratio; \
\
dest[0] = affect[0] ? \
(guchar) (src2[0] * ratio + src1[0] * compl_ratio + EPSILON) : src1[0]; \
dest[1] = affect[1] ? \
(guchar) (src2[1] * ratio + src1[1] * compl_ratio + EPSILON) : src1[1]; \
dest[2] = affect[2] ? \
(guchar) (src2[2] * ratio + src1[2] * compl_ratio + EPSILON) : src1[2]; \
} \
}*/
void
combine_inten_a_and_inten_pixels (const guchar *src1,
const guchar *src2,