From: Jose O G. <jos...@ju...> - 2004-03-13 12:39:31
|
Hello to all on this list. What follows is the first in a series of patches designed to address a few problems and inconsistencies in Imlib2. Feel free to do with this as you wish... but, understand that nothing here has been tested or checked in any real way. This first patch involves the files "blend.h" and "blend.c". In brief: All the static functions in blend.c have been re-written, and some of the "mmx" functions in the function table have been commented out and replaced with the corresponding C versions. Some macros in blend.c have been modified and some comments have been added regarding the handling of the destination alpha when blending. In somewhat more detail: The static functions in blend.c have been re-written in order to address the following: 1) Lack of consistency in the use of the "pow_lut" and incorrect determination of the color-blending alpha when blending to rgba with all the cmod functions. 2) The copy versions of the Add, Sub, Re functions with rgba source and destinations were adding source and destination alphas to obtain the new dest alpha value. This contradicts the semantics of this case (as described in blend.h). 3) In a few of the functions blending to/from rgb, the alpha component of the data was being read/written for various uses, which they should not do. This patch fixes all the above issues and gains considerable speed in most cases -- especially when blending to rgba. The implementations of the static functions has been written without the use of macros for the various "looping" statements, etc. in order to make it easier to see what's being done. If anyone would prefer a smaller file that uses more macros I can send a suitable version. In blend.h, the comment regarding the determination of the new destination alpha has been re-written to reflect the actual use, and a further comment added to give a bit more detail on this. Also, the macros ADD_COLOR_WITH_ALPHA and SUB_COLOR_WITH_ALPHA have been modified to give more accurate results, and the macro BLEND_DST_ALPHA modified to give a faster, accurate computation for the destination alpha. Other macros have had some minor changes. ---------------------------------------------------------- For blend.h ---------------------------------------------------------- Index: cvs/e17/libs/imlib2/src/blend.h =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/imlib2/src/blend.h,v retrieving revision 1.15 diff -u -r1.15 blend.h --- cvs/e17/libs/imlib2/src/blend.h 15 Feb 2004 01:58:23 -0000 1.15 +++ cvs/e17/libs/imlib2/src/blend.h 11 Mar 2004 05:08:11 -0000 @@ -188,7 +188,8 @@ * b) Include source alpha in the calculation for new destination alpha? * If source alpha is not used, then destination alpha is preserved. * If source alpha is used, a "copy" sets the new alpha to the source - * alpha, and a "blend" adds them together (with saturation). + * alpha, and a "blend" increases it by a factor given by the product + * of the source alpha with one minus the destination alpha. * c) Should the source pixels be passed through a color modifier before the * calculations are performed? * @@ -296,6 +297,19 @@ * * Notice the color values created by this operation are in the range * (-256, 512), and thus must be saturated at 0 and 255 (from above and below). + * + * For all the operations, when the "blend" version involves computing new + * destination alpha values via the use of some source alpha, we have that: + * + * nalpha = alpha + ((255 - alpha) * (a / 255)) + * + * We can use the previous argument for approximating division by 255, and + * calculate this by: + * + * tmp = (255 - alpha) * a; + * nalpha = alpha + ((tmp + (tmp >> 8) + 0x80) >> 8); + * + * This is again in the range [0, 255], so no saturation is needed. */ #define BLEND_COLOR(a, nc, c, cc) \ @@ -303,58 +317,57 @@ nc = (cc) + ((tmp + (tmp >> 8) + 0x80) >> 8); #define ADD_COLOR_WITH_ALPHA(a, nc, c, cc) \ -tmp = (cc) + (((c) * (a)) >> 8); \ -SATURATE_UPPER(nc, tmp); +tmp = (c) * (a); \ +tmp = (cc) + ((tmp + (tmp >> 8) + 0x80) >> 8); \ +nc = (tmp | (-(tmp >> 8))); #define ADD_COLOR(nc, c, cc) \ tmp = (cc) + (c); \ -SATURATE_UPPER(nc, tmp); +nc = (tmp | (-(tmp >> 8))); #define SUB_COLOR_WITH_ALPHA(a, nc, c, cc) \ -tmp = (cc) - (((c) * (a)) >> 8); \ -SATURATE_LOWER((nc), (tmp)); +tmp = (c) * (a); \ +tmp = (cc) - ((tmp + (tmp >> 8) + 0x80) >> 8); \ +nc = (tmp & (~(tmp >> 8))); #define SUB_COLOR(nc, c, cc) \ tmp = (cc) - (c); \ -SATURATE_LOWER(nc, tmp); +nc = (tmp & (~(tmp >> 8))); #define RESHADE_COLOR_WITH_ALPHA(a, nc, c, cc) \ tmp = (cc) + ((((c) - 127) * (a)) >> 7); \ -SATURATE_BOTH(nc, tmp); +nc = (tmp | (-(tmp >> 8))) & (~(tmp >> 9)); #define RESHADE_COLOR(nc, c, cc) \ tmp = (cc) + (((c) - 127) << 1); \ -SATURATE_BOTH(nc, tmp); +nc = (tmp | (-(tmp >> 8))) & (~(tmp >> 9)); extern int pow_lut_initialized; extern DATA8 pow_lut[256][256]; #define BLEND_DST_ALPHA(r1, g1, b1, a1, dest) \ -{ int _aa; \ +{ DATA8 _aa; \ _aa = pow_lut[a1][A_VAL(dest)]; \ +BLEND_COLOR(a1, A_VAL(dest), 255, A_VAL(dest)); \ BLEND_COLOR(_aa, R_VAL(dest), r1, R_VAL(dest)); \ BLEND_COLOR(_aa, G_VAL(dest), g1, G_VAL(dest)); \ BLEND_COLOR(_aa, B_VAL(dest), b1, B_VAL(dest)); \ -A_VAL(dest) = A_VAL(dest) + ((a1 * (255 - A_VAL(dest))) / 255); \ } #define BLEND(r1, g1, b1, a1, dest) \ BLEND_COLOR(a1, R_VAL(dest), r1, R_VAL(dest)); \ BLEND_COLOR(a1, G_VAL(dest), g1, G_VAL(dest)); \ -BLEND_COLOR(a1, B_VAL(dest), b1, B_VAL(dest)); \ -SATURATE_UPPER(A_VAL(dest), (a1) + A_VAL(dest)); +BLEND_COLOR(a1, B_VAL(dest), b1, B_VAL(dest)); #define BLEND_ADD(r1, g1, b1, a1, dest) \ ADD_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \ ADD_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \ -ADD_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest)); \ -SATURATE_UPPER(A_VAL(dest), (a1) + A_VAL(dest)); +ADD_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest)); #define BLEND_SUB(r1, g1, b1, a1, dest) \ SUB_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \ SUB_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \ -SUB_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest)); \ -SATURATE_UPPER(A_VAL(dest), (a1) + A_VAL(dest)); +SUB_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest)); #define BLEND_RE(r1, g1, b1, a1, dest) \ RESHADE_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \ ------------------------------------------------------------------------- ---------------------------- for blend.c ------------------------------------------------------------------------- --------------------------- Index: cvs/e17/libs/imlib2/src/blend.c =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/imlib2/src/blend.c,v retrieving revision 1.40 diff -u -r1.40 blend.c --- cvs/e17/libs/imlib2/src/blend.c 13 Jul 2003 01:09:17 -0000 1.40 +++ cvs/e17/libs/imlib2/src/blend.c 11 Mar 2004 05:08:39 -0000 @@ -5,62 +5,23 @@ #include "blend.h" #include "scale.h" -/* - * Thanks to Ryan Gustafson <rya...@ya...> fro the reduction in - * size of this file with lots of macros.. :) - * - * These operations are over a rectangular region in each of the images. The - * macros below provide common code for looping over the region. The pointers - * 'p1' and 'p2' point to the current pixel. - * - * There are several version of the LOOP_START macro so that -Wall compilations - * will no complain about unused variables. Use as appropriate. - */ - -/* Just enough variables to loop, no color variables at all. */ -#define LOOP_START \ - int x, y; \ - DATA32 *p1, *p2; \ - \ - p1 = src; \ - p2 = dst; \ - for (y = h; y > 0; y--) \ - { \ - for (x = w; x > 0; x--) \ - { - -/* Add tmp calculation variable. */ -#define LOOP_START_0 \ - DATA32 tmp; \ - LOOP_START - -/* Add variables to read pixel colors (no alpha) */ -#define LOOP_START_1 \ - DATA8 r, g, b, rr, gg, bb, nr, ng, nb; \ - LOOP_START_0 - -/* Add source alpha. */ -#define LOOP_START_2 \ - DATA8 a; \ - LOOP_START_1 - -/* Add destination and new alpha. */ -#define LOOP_START_3 \ - DATA8 aa, na; \ - LOOP_START_2 - -#define LOOP_END \ - } \ - p1 += srcw - w; \ - p2 += dstw - w; \ - } - -#define LOOP_END_WITH_INCREMENT \ - p1++; \ - p2++; \ - LOOP_END -/* COPY OPS */ +#define ADD_COPY(r, g, b, dest) \ + ADD_COLOR(R_VAL(dest), r, R_VAL(dest)); \ + ADD_COLOR(G_VAL(dest), g, G_VAL(dest)); \ + ADD_COLOR(B_VAL(dest), b, B_VAL(dest)); + +#define SUB_COPY(r, g, b, dest) \ + SUB_COLOR(R_VAL(dest), r, R_VAL(dest)); \ + SUB_COLOR(G_VAL(dest), g, G_VAL(dest)); \ + SUB_COLOR(B_VAL(dest), b, B_VAL(dest)); + +#define RE_COPY(r, g, b, dest) \ + RESHADE_COLOR(R_VAL(dest), r, R_VAL(dest)); \ + RESHADE_COLOR(G_VAL(dest), g, G_VAL(dest)); \ + RESHADE_COLOR(B_VAL(dest), b, B_VAL(dest)); + + int pow_lut_initialized = 0; DATA8 pow_lut[256][256]; @@ -89,583 +50,1349 @@ } } + +/* COPY OPS */ + +static void +__imlib_CopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) +{ + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + *dst = 0xff000000 | (*src & 0x00ffffff); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} + +static void +__imlib_CopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) +{ + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + *dst = (*dst & 0xff000000) | (*src & 0x00ffffff); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} + +static void +__imlib_CopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) +{ + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + *dst = *src; + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} + static void __imlib_BlendRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_VAL(p1); - BLEND_COLOR(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - BLEND_COLOR(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - BLEND_COLOR(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + *dst = (*dst & 0xff000000) | (*src & 0x00ffffff); + src++; dst++; continue; + } + BLEND(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_BlendRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 a = pow_lut[A_VAL(p1)][A_VAL(p2)]; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; - BLEND_COLOR(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - BLEND_COLOR(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - BLEND_COLOR(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + *dst = *src; + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(A_VAL(src), A_VAL(dst), 255, A_VAL(dst)); + BLEND(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} - A_VAL(p2) = A_VAL(p2) + ((A_VAL(p1) * (255 - A_VAL(p2))) / 255); -LOOP_END_WITH_INCREMENT} +/* ADD OPS */ static void -__imlib_CopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddCopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START * p2 = (*p2 & 0xff000000) | (*p1 & 0x00ffffff); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + + A_VAL(dst) = 0xff; + ADD_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_CopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddCopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START * p2 = 0xff000000 | (*p1 & 0x00ffffff); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + + ADD_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_CopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddCopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - /* FIXME: This could be a memcpy operation. */ - LOOP_START * p2 = *p1; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; -/* ADD OPS */ + A_VAL(dst) = A_VAL(src); + ADD_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_AddBlendRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_VAL(p1); - ADD_COLOR_WITH_ALPHA(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -LOOP_END_WITH_INCREMENT} + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + ADD_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; continue; + } + BLEND_ADD(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_AddBlendRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 a = pow_lut[A_VAL(p1)][A_VAL(p2)]; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; - ADD_COLOR_WITH_ALPHA(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; - A_VAL(p2) = A_VAL(p2) + ((A_VAL(p1) * (255 - A_VAL(p2))) / 255); + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + A_VAL(dst) = 0xff; + ADD_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(A_VAL(src), A_VAL(dst), 255, A_VAL(dst)); + BLEND_ADD(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} -LOOP_END_WITH_INCREMENT} +/* SUBTRACT OPS */ static void -__imlib_AddCopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, +__imlib_SubCopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_1 ADD_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - ADD_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - ADD_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + A_VAL(dst) = 0xff; + SUB_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_AddCopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_SubCopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 ADD_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - ADD_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - ADD_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_VAL(p1) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + SUB_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_AddCopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_SubCopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 ADD_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - ADD_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - ADD_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); - A_VAL(p2) = 0xff; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; -/* SUBTRACT OPS */ + A_VAL(dst) = A_VAL(src); + SUB_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_SubBlendRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 SATURATE_UPPER(a, A_VAL(p1) + (255 - A_VAL(p2))); - SUB_COLOR_WITH_ALPHA(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_VAL(p1) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + SUB_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; continue; + } + BLEND_SUB(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_SubBlendRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 a = pow_lut[A_VAL(p1)][A_VAL(p2)]; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; - SUB_COLOR_WITH_ALPHA(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; - A_VAL(p2) = A_VAL(p2) + ((A_VAL(p1) * (255 - A_VAL(p2))) / 255); + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + A_VAL(dst) = 0xff; + SUB_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(A_VAL(src), A_VAL(dst), 255, A_VAL(dst)); + BLEND_SUB(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} -LOOP_END_WITH_INCREMENT} +/* RESHADE OPS */ static void -__imlib_SubCopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_ReCopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_1 SUB_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - SUB_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - SUB_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + + A_VAL(dst) = 0xff; + RE_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_SubCopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_ReCopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SUB_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - SUB_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - SUB_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_VAL(p1) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + + while (h--) + { + while (w--) + { + DATA32 tmp; + + RE_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} -LOOP_END_WITH_INCREMENT} static void -__imlib_SubCopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, +__imlib_ReCopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SUB_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - SUB_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - SUB_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); - A_VAL(p2) = 0xff; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; -/* RESHADE OPS */ + A_VAL(dst) = A_VAL(src); + RE_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_ReBlendRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_VAL(p1); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; - RESHADE_COLOR_WITH_ALPHA(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -LOOP_END_WITH_INCREMENT} + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + RE_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; continue; + } + BLEND_RE(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_ReBlendRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 a = pow_lut[A_VAL(p1)][A_VAL(p2)]; - - RESHADE_COLOR_WITH_ALPHA(a, R_VAL(p2), R_VAL(p1), R_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, G_VAL(p2), G_VAL(p1), G_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, B_VAL(p2), B_VAL(p1), B_VAL(p2)); - - A_VAL(p2) = A_VAL(p2) + ((A_VAL(p1) * (255 - A_VAL(p2))) / 255); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -static void -__imlib_ReCopyRGBAToRGB(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) -{ - LOOP_START_1 RESHADE_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - RESHADE_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - RESHADE_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); + a = A_VAL(src); + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + A_VAL(dst) = 0xff; + RE_COPY(R_VAL(src), G_VAL(src), B_VAL(src), dst); + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(A_VAL(src), A_VAL(dst), 255, A_VAL(dst)); + BLEND_RE(R_VAL(src), G_VAL(src), B_VAL(src), a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} -LOOP_END_WITH_INCREMENT} +/* WITH COLOMOD */ +/* COPY OPS */ static void -__imlib_ReCopyRGBAToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_CopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 RESHADE_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - RESHADE_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - RESHADE_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_VAL(p1) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + A_VAL(dst) = am; + R_VAL(dst) = rmod[R_VAL(src)]; + G_VAL(dst) = gmod[G_VAL(src)]; + B_VAL(dst) = bmod[B_VAL(src)]; + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_ReCopyRGBToRGBA(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_CopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 RESHADE_COLOR(R_VAL(p2), R_VAL(p1), R_VAL(p2)); - RESHADE_COLOR(G_VAL(p2), G_VAL(p1), G_VAL(p2)); - RESHADE_COLOR(B_VAL(p2), B_VAL(p1), B_VAL(p2)); - A_VAL(p2) = 0xff; + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} - -/* WITH COLOMOD */ -/* COPY OPS */ + while (h--) + { + while (w--) + { + R_VAL(dst) = rmod[R_VAL(src)]; + G_VAL(dst) = gmod[G_VAL(src)]; + B_VAL(dst) = bmod[B_VAL(src)]; + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_BlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, +__imlib_CopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_CMOD(cm, A_VAL(p1)); - BLEND_COLOR(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - BLEND_COLOR(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - BLEND_COLOR(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + A_VAL(dst) = amod[A_VAL(src)]; + R_VAL(dst) = rmod[R_VAL(src)]; + G_VAL(dst) = gmod[G_VAL(src)]; + B_VAL(dst) = bmod[B_VAL(src)]; + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_BlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_BlendRGBToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 - SATURATE_UPPER(a, - A_CMOD(cm, - A_VAL(p1)) + - (((255 - A_VAL(p2)) * (A_CMOD(cm, A_VAL(p1)))) / 255)); - - BLEND_COLOR(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - BLEND_COLOR(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - BLEND_COLOR(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_CopyRGBToRGBCmod(src, srcw, dst, dstw, w, h, cm); + return; + } - A_VAL(p2) = A_VAL(p2) + ((A_CMOD(cm, A_VAL(p1)) * (255 - A_VAL(p2))) / 255); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + BLEND(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], am, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_BlendRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SATURATE_UPPER(a, A_CMOD(cm, 0xff) + (255 - A_VAL(p2))); - BLEND_COLOR(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - BLEND_COLOR(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - BLEND_COLOR(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, 0xff) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_CopyRGBToRGBACmod(src, srcw, dst, dstw, w, h, cm); + return; + } + + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -LOOP_END_WITH_INCREMENT} + a = pow_lut[am][A_VAL(dst)]; + BLEND_COLOR(am, A_VAL(dst), 255, A_VAL(dst)) + BLEND(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_BlendRGBToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_BlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 a = A_CMOD(cm, 0xff); - BLEND_COLOR(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - BLEND_COLOR(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - BLEND_COLOR(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = amod[A_VAL(src)]; + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + R_VAL(dst) = rmod[R_VAL(src)]; + G_VAL(dst) = gmod[G_VAL(src)]; + B_VAL(dst) = bmod[B_VAL(src)]; + src++; dst++; continue; + } + BLEND(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_CopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_BlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START R_VAL(p2) = R_CMOD(cm, R_VAL(p1)); - G_VAL(p2) = G_CMOD(cm, G_VAL(p1)); - B_VAL(p2) = B_CMOD(cm, B_VAL(p1)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -static void -__imlib_CopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) -{ - LOOP_START R_VAL(p2) = R_CMOD(cm, R_VAL(p1)); - G_VAL(p2) = G_CMOD(cm, G_VAL(p1)); - B_VAL(p2) = B_CMOD(cm, B_VAL(p1)); - A_VAL(p2) = A_CMOD(cm, 0xff); + a = amod[A_VAL(src)]; + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + A_VAL(dst) = 0xff; + R_VAL(dst) = rmod[R_VAL(src)]; + G_VAL(dst) = gmod[G_VAL(src)]; + B_VAL(dst) = bmod[B_VAL(src)]; + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(amod[A_VAL(src)], A_VAL(dst), 255, A_VAL(dst)); + BLEND(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} -LOOP_END_WITH_INCREMENT} +/* ADD OPS */ static void -__imlib_CopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddCopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START R_VAL(p2) = R_CMOD(cm, R_VAL(p1)); - G_VAL(p2) = G_CMOD(cm, G_VAL(p1)); - B_VAL(p2) = B_CMOD(cm, B_VAL(p1)); - A_VAL(p2) = A_CMOD(cm, A_VAL(p1)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; -/* ADD OPS */ + A_VAL(dst) = am; + ADD_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_AddBlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddCopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 SATURATE_UPPER(a, A_CMOD(cm, A_VAL(p1)) + (255 - A_VAL(p2))); - ADD_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + + ADD_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_AddBlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddCopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 - SATURATE_UPPER(a, - A_CMOD(cm, - A_VAL(p1)) + - (((255 - A_VAL(p2)) * (A_CMOD(cm, A_VAL(p1)))) / 255)); - - ADD_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; - A_VAL(p2) = A_VAL(p2) + ((A_CMOD(cm, A_VAL(p1)) * (255 - A_VAL(p2))) / 255); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + A_VAL(dst) = amod[A_VAL(src)]; + ADD_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_AddBlendRGBToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 a = A_CMOD(cm, 0xff); - ADD_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_AddCopyRGBToRGBCmod(src, srcw, dst, dstw, w, h, cm); + return; + } + + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + BLEND_ADD(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], am, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_AddBlendRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SATURATE_UPPER(a, A_CMOD(cm, 0xff) + (255 - A_VAL(p2))); - ADD_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, A_VAL(p1)) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_AddCopyRGBToRGBACmod(src, srcw, dst, dstw, w, h, cm); + return; + } -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = pow_lut[am][A_VAL(dst)]; + BLEND_COLOR(am, A_VAL(dst), 255, A_VAL(dst)); + BLEND_ADD(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_AddCopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddBlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_1 ADD_COLOR(R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR(G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR(B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -LOOP_END_WITH_INCREMENT} + a = amod[A_VAL(src)]; + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + ADD_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; continue; + } + BLEND_ADD(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_AddCopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_AddBlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 ADD_COLOR(R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR(G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR(B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, A_VAL(p1)) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; -LOOP_END_WITH_INCREMENT} + a = amod[A_VAL(src)]; + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + A_VAL(dst) = 0xff; + ADD_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(amod[A_VAL(src)], A_VAL(dst), 255, A_VAL(dst)); + BLEND_ADD(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} + +/* SUBTRACT OPS */ static void -__imlib_AddCopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, +__imlib_SubCopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 ADD_COLOR(R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - ADD_COLOR(G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - ADD_COLOR(B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, 0xff) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; -/* SUBTRACT OPS */ + A_VAL(dst) = am; + SUB_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_SubBlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_SubCopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_CMOD(cm, A_VAL(p1)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; - SUB_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + SUB_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_SubBlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_SubCopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 - SATURATE_UPPER(a, - A_CMOD(cm, - A_VAL(p1)) + - (((255 - A_VAL(p2)) * (A_CMOD(cm, A_VAL(p1)))) / 255)); - - SUB_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; - A_VAL(p2) = A_VAL(p2) + ((A_CMOD(cm, A_VAL(p1)) * (255 - A_VAL(p2))) / 255); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + A_VAL(dst) = amod[A_VAL(src)]; + SUB_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_SubBlendRGBToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_CMOD(cm, 0xff); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_SubCopyRGBToRGBCmod(src, srcw, dst, dstw, w, h, cm); + return; + } - SUB_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + BLEND_SUB(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], am, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_SubBlendRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SATURATE_UPPER(a, A_CMOD(cm, 0xff) + (255 - A_VAL(p2))); - SUB_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, 0xff) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_SubCopyRGBToRGBACmod(src, srcw, dst, dstw, w, h, cm); + return; + } -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = pow_lut[am][A_VAL(dst)]; + BLEND_COLOR(am, A_VAL(dst), 255, A_VAL(dst)); + BLEND_SUB(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_SubCopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_SubBlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_1 SUB_COLOR(R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR(G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR(B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = amod[A_VAL(src)]; + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + SUB_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; continue; + } + BLEND_SUB(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_SubCopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_SubBlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SUB_COLOR(R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR(G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR(B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, A_VAL(p1)) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; + DATA8 a; + + a = amod[A_VAL(src)]; + if (!a) + { src++; dst++; continue; } + if (a == 255) + { + A_VAL(dst) = 0xff; + SUB_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; continue; + } + a = pow_lut[a][A_VAL(dst)]; + BLEND_COLOR(amod[A_VAL(src)], A_VAL(dst), 255, A_VAL(dst)); + BLEND_SUB(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], a, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} + +/* RESHADE OPS */ static void -__imlib_SubCopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_ReCopyRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SUB_COLOR(R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - SUB_COLOR(G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - SUB_COLOR(B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p2), A_CMOD(cm, 0xff) + A_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; -LOOP_END_WITH_INCREMENT} + while (h--) + { + while (w--) + { + DATA32 tmp; -/* RESHADE OPS */ + A_VAL(dst) = am; + RE_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_ReBlendRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_ReCopyRGBAToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_CMOD(cm, A_VAL(p1)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; - RESHADE_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + RE_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void -__imlib_ReBlendRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, - int w, int h, ImlibColorModifier * cm) +__imlib_ReCopyRGBAToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, + int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 - SATURATE_UPPER(a, - A_CMOD(cm, - A_VAL(p1)) + - (((255 - A_VAL(p2)) * (A_CMOD(cm, A_VAL(p1)))) / 255)); - - RESHADE_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; - A_VAL(p2) = A_VAL(p2) + ((A_CMOD(cm, A_VAL(p1)) * (255 - A_VAL(p2))) / 255); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + A_VAL(dst) = amod[A_VAL(src)]; + RE_COPY(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_ReBlendRGBToRGBCmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_2 a = A_CMOD(cm, 0xff); + int src_step = (srcw - w), dst_step = (dstw - w), ww = w; + DATA8 *amod = cm->alpha_mapping, *rmod = cm->red_mapping, + *gmod = cm->green_mapping, *bmod = cm->blue_mapping; + DATA8 am = amod[255]; + + if (!am) return; + if (am == 255) + { + __imlib_ReCopyRGBToRGBCmod(src, srcw, dst, dstw, w, h, cm); + return; + } - RESHADE_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); + while (h--) + { + while (w--) + { + DATA32 tmp; -LOOP_END_WITH_INCREMENT} + BLEND_RE(rmod[R_VAL(src)], gmod[G_VAL(src)], bmod[B_VAL(src)], am, dst); + src++; dst++; + } + src += src_step; + dst += dst_step; + w = ww; + } +} static void __imlib_ReBlendRGBToRGBACmod(DATA32 * src, int srcw, DATA32 * dst, int dstw, int w, int h, ImlibColorModifier * cm) { - LOOP_START_3 SATURATE_UPPER(a, A_CMOD(cm, A_VAL(p1)) + (255 - A_VAL(p2))); - RESHADE_COLOR_WITH_ALPHA(a, R_VAL(p2), R_CMOD(cm, R_VAL(p1)), R_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, G_VAL(p2), G_CMOD(cm, G_VAL(p1)), G_VAL(p2)); - RESHADE_COLOR_WITH_ALPHA(a, B_VAL(p2), B_CMOD(cm, B_VAL(p1)), B_VAL(p2)); - SATURATE_UPPER(A_VAL(p... [truncated message content] |