mirror of https://github.com/GNOME/gimp.git
introduced an enum to clean up the code. Optimize another not so uncommon
2008-05-13 Sven Neumann <sven@gimp.org> * app/core/gimpcurve-map.[ch] (gimp_curve_map_pixels): introduced an enum to clean up the code. Optimize another not so uncommon case. svn path=/trunk/; revision=25650
This commit is contained in:
parent
aba934224e
commit
517cfe6750
|
@ -1,3 +1,8 @@
|
|||
2008-05-13 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/core/gimpcurve-map.[ch] (gimp_curve_map_pixels): introduced
|
||||
an enum to clean up the code. Optimize another not so uncommon case.
|
||||
|
||||
2008-05-13 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/core/gimpcurve-map.c (gimp_curve_map_pixels): create a
|
||||
|
|
|
@ -28,6 +28,17 @@
|
|||
#include "gimpcurve-map.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
CURVE_NONE = 0,
|
||||
CURVE_COLORS = 1 << 0,
|
||||
CURVE_RED = 1 << 1,
|
||||
CURVE_GREEN = 1 << 2,
|
||||
CURVE_BLUE = 1 << 3,
|
||||
CURVE_ALPHA = 1 << 4
|
||||
};
|
||||
|
||||
|
||||
gdouble
|
||||
gimp_curve_map_value (GimpCurve *curve,
|
||||
gdouble value)
|
||||
|
@ -66,7 +77,7 @@ gimp_curve_map_value (GimpCurve *curve,
|
|||
}
|
||||
|
||||
void
|
||||
gimp_curve_map_pixels (GimpCurve *curve_all,
|
||||
gimp_curve_map_pixels (GimpCurve *curve_colors,
|
||||
GimpCurve *curve_red,
|
||||
GimpCurve *curve_green,
|
||||
GimpCurve *curve_blue,
|
||||
|
@ -75,32 +86,32 @@ gimp_curve_map_pixels (GimpCurve *curve_all,
|
|||
gfloat *dest,
|
||||
glong samples)
|
||||
{
|
||||
guint mask = 0;
|
||||
guint mask = CURVE_NONE;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve_all));
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve_colors));
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve_red));
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve_green));
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve_blue));
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve_alpha));
|
||||
|
||||
mask |= (gimp_curve_is_identity (curve_all) ? 0 : 1) << 0;
|
||||
mask |= (gimp_curve_is_identity (curve_red) ? 0 : 1) << 1;
|
||||
mask |= (gimp_curve_is_identity (curve_green) ? 0 : 1) << 2;
|
||||
mask |= (gimp_curve_is_identity (curve_blue) ? 0 : 1) << 3;
|
||||
mask |= (gimp_curve_is_identity (curve_alpha) ? 0 : 1) << 4;
|
||||
if (! gimp_curve_is_identity (curve_colors)) mask |= CURVE_COLORS;
|
||||
if (! gimp_curve_is_identity (curve_red)) mask |= CURVE_RED;
|
||||
if (! gimp_curve_is_identity (curve_green)) mask |= CURVE_GREEN;
|
||||
if (! gimp_curve_is_identity (curve_blue)) mask |= CURVE_BLUE;
|
||||
if (! gimp_curve_is_identity (curve_alpha)) mask |= CURVE_ALPHA;
|
||||
|
||||
switch (mask)
|
||||
{
|
||||
case 0: /* all curves are identity, nothing to do */
|
||||
case CURVE_NONE:
|
||||
break;
|
||||
|
||||
case 1: /* only the overall curve needs to be applied */
|
||||
case CURVE_COLORS:
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = gimp_curve_map_value (curve_all, src[0]);
|
||||
dest[1] = gimp_curve_map_value (curve_all, src[1]);
|
||||
dest[2] = gimp_curve_map_value (curve_all, src[2]);
|
||||
/* don't apply the overall curve to the alpha channel */
|
||||
dest[0] = gimp_curve_map_value (curve_colors, src[0]);
|
||||
dest[1] = gimp_curve_map_value (curve_colors, src[1]);
|
||||
dest[2] = gimp_curve_map_value (curve_colors, src[2]);
|
||||
/* don't apply the colors curve to the alpha channel */
|
||||
dest[3] = src[3];
|
||||
|
||||
src += 4;
|
||||
|
@ -108,7 +119,7 @@ gimp_curve_map_pixels (GimpCurve *curve_all,
|
|||
}
|
||||
break;
|
||||
|
||||
case 2: /* only the red curve needs to be applied */
|
||||
case CURVE_RED:
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = gimp_curve_map_value (curve_red, src[0]);
|
||||
|
@ -121,7 +132,7 @@ gimp_curve_map_pixels (GimpCurve *curve_all,
|
|||
}
|
||||
break;
|
||||
|
||||
case 4: /* only the green curve needs to be applied */
|
||||
case CURVE_GREEN:
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = src[0];
|
||||
|
@ -134,7 +145,7 @@ gimp_curve_map_pixels (GimpCurve *curve_all,
|
|||
}
|
||||
break;
|
||||
|
||||
case 8: /* only the blue curve needs to be applied */
|
||||
case CURVE_BLUE:
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = src[0];
|
||||
|
@ -147,7 +158,7 @@ gimp_curve_map_pixels (GimpCurve *curve_all,
|
|||
}
|
||||
break;
|
||||
|
||||
case 16: /* only the alpha curve needs to be applied */
|
||||
case CURVE_ALPHA:
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = src[0];
|
||||
|
@ -160,19 +171,32 @@ gimp_curve_map_pixels (GimpCurve *curve_all,
|
|||
}
|
||||
break;
|
||||
|
||||
case (CURVE_RED | CURVE_GREEN | CURVE_BLUE):
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = gimp_curve_map_value (curve_red, src[0]);
|
||||
dest[1] = gimp_curve_map_value (curve_green, src[1]);
|
||||
dest[2] = gimp_curve_map_value (curve_blue, src[2]);
|
||||
dest[3] = src[3];
|
||||
|
||||
src += 4;
|
||||
dest += 4;
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* apply all curves */
|
||||
while (samples--)
|
||||
{
|
||||
dest[0] = gimp_curve_map_value (curve_all,
|
||||
dest[0] = gimp_curve_map_value (curve_colors,
|
||||
gimp_curve_map_value (curve_red,
|
||||
src[0]));
|
||||
dest[1] = gimp_curve_map_value (curve_all,
|
||||
dest[1] = gimp_curve_map_value (curve_colors,
|
||||
gimp_curve_map_value (curve_green,
|
||||
src[1]));
|
||||
dest[2] = gimp_curve_map_value (curve_all,
|
||||
dest[2] = gimp_curve_map_value (curve_colors,
|
||||
gimp_curve_map_value (curve_blue,
|
||||
src[2]));
|
||||
/* don't apply the overall curve to the alpha channel */
|
||||
/* don't apply the colors curve to the alpha channel */
|
||||
dest[3] = gimp_curve_map_value (curve_alpha, src[3]);
|
||||
|
||||
src += 4;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
gdouble gimp_curve_map_value (GimpCurve *curve,
|
||||
gdouble value);
|
||||
void gimp_curve_map_pixels (GimpCurve *curve_all,
|
||||
void gimp_curve_map_pixels (GimpCurve *curve_colors,
|
||||
GimpCurve *curve_red,
|
||||
GimpCurve *curve_green,
|
||||
GimpCurve *curve_blue,
|
||||
|
|
Loading…
Reference in New Issue