diff --git a/src/blend.c b/src/blend.c index 38662f0..843ae05 100644 --- a/src/blend.c +++ b/src/blend.c @@ -65,6 +65,9 @@ * packed integers. The packed ordering of both the input and output images * is assumed to be ARGB. */ + +/************************************************************************ + * ********************************************************************** #define READ_RGB(p, r, g, b) \ (r) = (*(p) >> 16) & 0xff; \ (g) = (*(p) >> 8 ) & 0xff; \ @@ -87,255 +90,8 @@ #define WRITE_RGBA(p, r, g, b, a) \ *(p) = ((a) << 24) | ((r) << 16) | ((g) << 8) | (b); - -/* - * 1) Basic Saturation - 8 bit unsigned - * - * The add, subtract, and reshade operations generate new color values that may - * be out of range for an unsigned 8 bit quantity. Therefore, we will want to - * saturate the values into the range [0, 255]. Any value < 0 will become 0, - * and any value > 255 will become 255. Or simply: - * - * saturated = (value < 0) ? 0 : ((value > 255) ? 255 : value) - * - * Of course the above isn't the most efficient means of saturating. Sometimes - * due to the nature of a calculation, we know we only need to saturate from - * above (> 255) or just from below (< 0). Or simply: - * - * saturated = (value < 0) ? 0 : value - * saturated = (value > 255) ? 255 : value - * - * 2) Alternate Forms of Saturation - * - * The methods of saturation described above use testing/branching operations, - * which are not necessarily efficient on all platforms. There are other means - * of performing saturation using just simple arithmetic operations - * (+, -, >>, <<, ~). A discussion of these saturation techniques follows. - * - * A) Saturation in the range [0, 512), or "from above". - * - * Assuming we have an integral value in the range [0, 512), the following - * formula evaluates to either 0, or 255: - * - * (value & 255) - ((value & 256) >> 8) - * - * This is easy to show. Notice that if the value is in the range [0, 256) - * the 9th bit is 0, and we get (0 - 0), which is 0. And if the value is in - * the range [256, 512) the 9th bit is 1, and we get (256 - 1), which is 255. - * - * Now, using the above information and the fact that assigning an integer to - * an 8 bit unsigned value will truncate to the lower 8 bits of the integer, - * the following properly saturates: - * - * 8bit_value = value | (value & 256) - ((value & 256) >> 8) - * - * To prove this to yourself, just think about what the lower 8 bits look like - * in the ranges [0, 256) and [256, 512). In particular, notice that the value - * in the range [0, 256) are unchanged, and values in the range [256, 512) - * always give you 255. Just what we want! - * - * B) Saturation in the range (-256, 256), or "from below". - * - * Assuming we have an integral value in the range (-256, 256), the following - * formula evaluates to either 0, or -1: - * - * ~(value >> 8) - * - * Here's why. If the value is in the range [0, 256), then shifting right by - * 8 bits gives us all 0 bits, or 0. And thus inverting the bits gives all - * 1 bits, which is -1. If the value is in the range (-256, 0), then the 9th - * bit and higher bits are all 1. So, when we shift right by 8 bits (with - * signed extension), we get a value with all 1 bits. Which when inverted is - * all 0 bits, or 0. - * - * Now, using the above information the following properly saturates: - * - * 8bit_value = value & (~(value >> 8)) - * - * To prove this to yourself, noticed that values in the range (-256, 0) will - * always be AND'd with 0, and thus map to 0. Further, values in the range - * [0, 256) will always be AND'd with a value that is all 1 bits, and thus - * be unchanged. Just what we want! - * - * C) Saturation in the range (-256, 512), or "from above and below". - * - * The short of it is the following works: - * - * 8bit_value = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9)) - * - * We leave it to the reader to prove. Looks very similar to the techniques - * used above, eh? :) - */ - -/* Saturate values in the range [0, 512) */ -#define SATURATE_UPPER(nc, v) \ - tmp = (v); \ - nc = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))); - -/* Saturate values in the range (-256, 256) */ -#define SATURATE_LOWER(nc, v) \ - tmp = (v); \ - nc = tmp & (~(tmp >> 8)); - -/* Saturate values in the range (-256, 512) */ -#define SATURATE_BOTH(nc, v) \ - tmp = (v); \ - nc = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9)); - -/* - * 1) Operations - * - * There are 4 operations supported: - * - * Copy, Add, Subtract, and Reshade - * - * For each operation there are 3 different variations that can be made: - * - * a) Use "blend" or "copy" in the calculations? A "blend" uses the alpha - * value of the source pixel to lighten the source pixel values. Where - * as "copy" ignores the alpha value and uses the raw source pixel values. - * 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). - * c) Should the source pixels be passed through a color modifier before the - * calculations are performed? - * - * All together we have 4*2*2*2 = 32 combinations. - * - * 2) Copy operation - * - * The "copy" version of this operation copies the source image onto the - * destination image. - * - * The "blend" version of this operation blends the source image color 'c' with - * the destination image color 'cc' using 'a' (in the range [0, 1]) according - * to the following formula. Also notice that saturation is not needed for - * this calculation, the output is in the range [0, 255]: - * - * nc = c * alpha + (1 - alpha) * cc - * = c * alpha - cc * alpha + cc - * = (c - cc) * alpha + cc; - * - * A discussion of how we're calculating this value follows: - * - * We're using 'a', an integer, in the range [0, 255] for alpha (and for 'c' - * and 'cc', BTW). Therefore, we need to slightly modify the equation to take - * that into account. To get into the range [0, 255] we need to divide 'a' - * by 255: - * - * nc = ((c - cc) * a) / 255 + cc - * - * Notice that it is faster to divide by 256 (bit shifting), however without a - * fudge factor 'x' to balance things this isn't horribly accurate. So, let's - * solve for 'x'. The equality is: - * - * ((c - cc) * a) / 256 + cc + x = ((c - cc) * a) / 255 + cc - * - * The 'cc' terms cancel, and multiply both sides by 255*256 to remove the - * fractions: - * - * ((c - cc) * a) * 255 + 255 * 256 * x = ((c - cc) * a) * 256 - * - * Get the 'x' term alone: - * - * 255 * 256 * x = ((c - cc) * a) - * - * Divide both sides by 255 * 256 to solve for 'x': - * - * x = ((c - cc) * a) / (255 * 256) - * - * And putting 'x' back into the equation we get: - * - * nc = ((c - cc) * a) / 256 + cc + ((c - cc) * a) / (255 * 256) - * - * And if we let 'tmp' represent the value '(c - cc) * a', and do a little - * regrouping we get: - * - * nc = tmp / 256 + tmp / (255 * 256) + cc - * = (tmp + tmp / 255) / 256 + cc - * - * We'll be using integer arithmetic, and over the range of values tmp takes - * (in [-255*255, 255*255]) the term tmp/(255*256) is pretty much the same as - * tmp/(256*256). So we get: - * - * nc = (tmp + tmp / 256) / 256 + cc - * - * And because the division of the sum uses integer arithmetic, it always - * rounds up/down even if that isn't the "best" choice. If we add .5 to the - * sum, we can get standard rounding: Like so: - * - * nc = (tmp + tmp / 256 + 128) / 256 + cc - * - * 3) Add operation - * - * The "copy" version of this operation sums the source image pixel values - * with the destination image pixel values, saturating at 255 (from above). - * - * The "blend" version of this operation sums the source image pixel values, - * after taking into account alpha transparency (e.g. a percentage), with the - * destination image pixel values, saturating at 255 (from above). - * - * 4) Subtract operation - * - * This operation is the same as the Add operation, except the source values - * are subtracted from the destination values (instead of added). Further, - * the result must be saturated at 0 (from below). - * - * 5) Reshade operation - * - * This operation uses the source image color values to lighten/darken color - * values in the destination image using the following formula: - * - * nc = cc + ((c - middle_value) * 2 * alpha) - * - * Recall our pixel color and alpha values are in the range [0, 255]. So, the - * "blend" version of this operation can be calculated as: - * - * nc = cc + ((c - 127) * 2 * (a / 255)) - * - * And in an integer arithmetic friendly form is: - * - * nc = cc + (((c - 127) * a) >> 7) - * - * The "copy" version of this operation treats alpha as 1.0 (or a/255), and in - * integer arithmetic friendly form is: - * - * nc = cc + ((c - 127) << 1) - * - * 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). - */ - -#define BLEND_COLOR(a, nc, c, cc) \ - tmp = (c - cc) * a; \ - 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); - -#define ADD_COLOR(nc, c, cc) \ - tmp = cc + c; \ - SATURATE_UPPER(nc, tmp); - -#define SUB_COLOR_WITH_ALPHA(a, nc, c, cc) \ - tmp = cc - ((c * a) >> 8); \ - SATURATE_LOWER(nc, tmp); - -#define SUB_COLOR(nc, c, cc) \ - tmp = cc - c; \ - SATURATE_LOWER(nc, tmp); - -#define RESHADE_COLOR_WITH_ALPHA(a, nc, c, cc) \ - tmp = cc + (((c - 127) * a) >> 7); \ - SATURATE_BOTH(nc, tmp); - -#define RESHADE_COLOR(nc, c, cc) \ - tmp = cc + ((c - 127) << 1); \ - SATURATE_BOTH(nc, tmp); - - + * ********************************************************************** +*************************************************************************/ /* COPY OPS */ diff --git a/src/blend.h b/src/blend.h index 5a7d36d..faf1761 100644 --- a/src/blend.h +++ b/src/blend.h @@ -1,6 +1,316 @@ #ifndef __BLEND #define __BLEND 1 +/* FIXME: endian dependant */ +#define READ_RGB(p, r, g, b) \ + (r) = ((DATA8 *)p)[2]; \ + (g) = ((DATA8 *)p)[1]; \ + (b) = ((DATA8 *)p)[0]; + +#define READ_ALPHA(p, a) \ + (a) = ((DATA8 *)p)[3]; + +#define READ_RGBA(p, r, g, b, a) \ + (a) = ((DATA8 *)p)[3]; \ + (r) = ((DATA8 *)p)[2]; \ + (g) = ((DATA8 *)p)[1]; \ + (b) = ((DATA8 *)p)[0]; + +#define WRITE_RGB(p, r, g, b) \ + ((DATA8 *)p)[2] = r; \ + ((DATA8 *)p)[1] = g; \ + ((DATA8 *)p)[0] = b; + +#define WRITE_RGB_PRESERVE_ALPHA(p, r, g, b) \ + ((DATA8 *)p)[2] = r; \ + ((DATA8 *)p)[1] = g; \ + ((DATA8 *)p)[0] = b; + +#define WRITE_RGBA(p, r, g, b, a) \ + ((DATA8 *)p)[3] = a; \ + ((DATA8 *)p)[2] = r; \ + ((DATA8 *)p)[1] = g; \ + ((DATA8 *)p)[0] = b; + + +/* + * 1) Basic Saturation - 8 bit unsigned + * + * The add, subtract, and reshade operations generate new color values that may + * be out of range for an unsigned 8 bit quantity. Therefore, we will want to + * saturate the values into the range [0, 255]. Any value < 0 will become 0, + * and any value > 255 will become 255. Or simply: + * + * saturated = (value < 0) ? 0 : ((value > 255) ? 255 : value) + * + * Of course the above isn't the most efficient means of saturating. Sometimes + * due to the nature of a calculation, we know we only need to saturate from + * above (> 255) or just from below (< 0). Or simply: + * + * saturated = (value < 0) ? 0 : value + * saturated = (value > 255) ? 255 : value + * + * 2) Alternate Forms of Saturation + * + * The methods of saturation described above use testing/branching operations, + * which are not necessarily efficient on all platforms. There are other means + * of performing saturation using just simple arithmetic operations + * (+, -, >>, <<, ~). A discussion of these saturation techniques follows. + * + * A) Saturation in the range [0, 512), or "from above". + * + * Assuming we have an integral value in the range [0, 512), the following + * formula evaluates to either 0, or 255: + * + * (value & 255) - ((value & 256) >> 8) + * + * This is easy to show. Notice that if the value is in the range [0, 256) + * the 9th bit is 0, and we get (0 - 0), which is 0. And if the value is in + * the range [256, 512) the 9th bit is 1, and we get (256 - 1), which is 255. + * + * Now, using the above information and the fact that assigning an integer to + * an 8 bit unsigned value will truncate to the lower 8 bits of the integer, + * the following properly saturates: + * + * 8bit_value = value | (value & 256) - ((value & 256) >> 8) + * + * To prove this to yourself, just think about what the lower 8 bits look like + * in the ranges [0, 256) and [256, 512). In particular, notice that the value + * in the range [0, 256) are unchanged, and values in the range [256, 512) + * always give you 255. Just what we want! + * + * B) Saturation in the range (-256, 256), or "from below". + * + * Assuming we have an integral value in the range (-256, 256), the following + * formula evaluates to either 0, or -1: + * + * ~(value >> 8) + * + * Here's why. If the value is in the range [0, 256), then shifting right by + * 8 bits gives us all 0 bits, or 0. And thus inverting the bits gives all + * 1 bits, which is -1. If the value is in the range (-256, 0), then the 9th + * bit and higher bits are all 1. So, when we shift right by 8 bits (with + * signed extension), we get a value with all 1 bits. Which when inverted is + * all 0 bits, or 0. + * + * Now, using the above information the following properly saturates: + * + * 8bit_value = value & (~(value >> 8)) + * + * To prove this to yourself, noticed that values in the range (-256, 0) will + * always be AND'd with 0, and thus map to 0. Further, values in the range + * [0, 256) will always be AND'd with a value that is all 1 bits, and thus + * be unchanged. Just what we want! + * + * C) Saturation in the range (-256, 512), or "from above and below". + * + * The short of it is the following works: + * + * 8bit_value = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9)) + * + * We leave it to the reader to prove. Looks very similar to the techniques + * used above, eh? :) + */ + +/* Saturate values in the range [0, 512) */ +#define SATURATE_UPPER(nc, v) \ + tmp = (v); \ + nc = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))); + +/* Saturate values in the range (-256, 256) */ +#define SATURATE_LOWER(nc, v) \ + tmp = (v); \ + nc = tmp & (~(tmp >> 8)); + +/* Saturate values in the range (-256, 512) */ +#define SATURATE_BOTH(nc, v) \ + tmp = (v); \ + nc = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9)); + +/* + * 1) Operations + * + * There are 4 operations supported: + * + * Copy, Add, Subtract, and Reshade + * + * For each operation there are 3 different variations that can be made: + * + * a) Use "blend" or "copy" in the calculations? A "blend" uses the alpha + * value of the source pixel to lighten the source pixel values. Where + * as "copy" ignores the alpha value and uses the raw source pixel values. + * 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). + * c) Should the source pixels be passed through a color modifier before the + * calculations are performed? + * + * All together we have 4*2*2*2 = 32 combinations. + * + * 2) Copy operation + * + * The "copy" version of this operation copies the source image onto the + * destination image. + * + * The "blend" version of this operation blends the source image color 'c' with + * the destination image color 'cc' using 'a' (in the range [0, 1]) according + * to the following formula. Also notice that saturation is not needed for + * this calculation, the output is in the range [0, 255]: + * + * nc = c * alpha + (1 - alpha) * cc + * = c * alpha - cc * alpha + cc + * = (c - cc) * alpha + cc; + * + * A discussion of how we're calculating this value follows: + * + * We're using 'a', an integer, in the range [0, 255] for alpha (and for 'c' + * and 'cc', BTW). Therefore, we need to slightly modify the equation to take + * that into account. To get into the range [0, 255] we need to divide 'a' + * by 255: + * + * nc = ((c - cc) * a) / 255 + cc + * + * Notice that it is faster to divide by 256 (bit shifting), however without a + * fudge factor 'x' to balance things this isn't horribly accurate. So, let's + * solve for 'x'. The equality is: + * + * ((c - cc) * a) / 256 + cc + x = ((c - cc) * a) / 255 + cc + * + * The 'cc' terms cancel, and multiply both sides by 255*256 to remove the + * fractions: + * + * ((c - cc) * a) * 255 + 255 * 256 * x = ((c - cc) * a) * 256 + * + * Get the 'x' term alone: + * + * 255 * 256 * x = ((c - cc) * a) + * + * Divide both sides by 255 * 256 to solve for 'x': + * + * x = ((c - cc) * a) / (255 * 256) + * + * And putting 'x' back into the equation we get: + * + * nc = ((c - cc) * a) / 256 + cc + ((c - cc) * a) / (255 * 256) + * + * And if we let 'tmp' represent the value '(c - cc) * a', and do a little + * regrouping we get: + * + * nc = tmp / 256 + tmp / (255 * 256) + cc + * = (tmp + tmp / 255) / 256 + cc + * + * We'll be using integer arithmetic, and over the range of values tmp takes + * (in [-255*255, 255*255]) the term tmp/(255*256) is pretty much the same as + * tmp/(256*256). So we get: + * + * nc = (tmp + tmp / 256) / 256 + cc + * + * And because the division of the sum uses integer arithmetic, it always + * rounds up/down even if that isn't the "best" choice. If we add .5 to the + * sum, we can get standard rounding: Like so: + * + * nc = (tmp + tmp / 256 + 128) / 256 + cc + * + * 3) Add operation + * + * The "copy" version of this operation sums the source image pixel values + * with the destination image pixel values, saturating at 255 (from above). + * + * The "blend" version of this operation sums the source image pixel values, + * after taking into account alpha transparency (e.g. a percentage), with the + * destination image pixel values, saturating at 255 (from above). + * + * 4) Subtract operation + * + * This operation is the same as the Add operation, except the source values + * are subtracted from the destination values (instead of added). Further, + * the result must be saturated at 0 (from below). + * + * 5) Reshade operation + * + * This operation uses the source image color values to lighten/darken color + * values in the destination image using the following formula: + * + * nc = cc + ((c - middle_value) * 2 * alpha) + * + * Recall our pixel color and alpha values are in the range [0, 255]. So, the + * "blend" version of this operation can be calculated as: + * + * nc = cc + ((c - 127) * 2 * (a / 255)) + * + * And in an integer arithmetic friendly form is: + * + * nc = cc + (((c - 127) * a) >> 7) + * + * The "copy" version of this operation treats alpha as 1.0 (or a/255), and in + * integer arithmetic friendly form is: + * + * nc = cc + ((c - 127) << 1) + * + * 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). + */ + +#define BLEND_COLOR(a, nc, c, cc) \ +tmp = ((c) - (cc)) * (a); \ +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); + +#define ADD_COLOR(nc, c, cc) \ +tmp = (cc) + (c); \ +SATURATE_UPPER(nc, tmp); + +#define SUB_COLOR_WITH_ALPHA(a, nc, c, cc) \ +tmp = (cc) - (((c) * (a)) >> 8); \ +SATURATE_LOWER((nc), (tmp)); + +#define SUB_COLOR(nc, c, cc) \ +tmp = (cc) - (c); \ +SATURATE_LOWER(nc, tmp); + +#define RESHADE_COLOR_WITH_ALPHA(a, nc, c, cc) \ +tmp = (cc) + ((((c) - 127) * (a)) >> 7); \ +SATURATE_BOTH(nc, tmp); + +#define RESHADE_COLOR(nc, c, cc) \ +tmp = (cc) + (((c) - 127) << 1); \ +SATURATE_BOTH(nc, tmp); + +#define BLEND(r1, g1, b1, a1, dest) \ +READ_RGBA(dest, rr, gg, bb, aa); \ +BLEND_COLOR(a1, nr, r1, rr); \ +BLEND_COLOR(a1, ng, g1, gg); \ +BLEND_COLOR(a1, nb, b1, bb); \ +SATURATE_UPPER(na, (a1) + aa); \ +WRITE_RGBA(dest, nr, ng, nb, na); + +#define BLEND_ADD(r1, g1, b1, a1, dest) \ +READ_RGBA(dest, rr, gg, bb, aa); \ +ADD_COLOR_WITH_ALPHA(a1, nr, r1, rr); \ +ADD_COLOR_WITH_ALPHA(a1, ng, g1, gg); \ +ADD_COLOR_WITH_ALPHA(a1, nb, b1, bb); \ +SATURATE_UPPER(na, (a1) + aa); \ +WRITE_RGBA(dest, nr, ng, nb, na); + +#define BLEND_SUB(r1, g1, b1, a1, dest) \ +READ_RGBA(dest, rr, gg, bb, aa); \ +SUB_COLOR_WITH_ALPHA(a1, nr, r1, rr); \ +SUB_COLOR_WITH_ALPHA(a1, ng, g1, gg); \ +SUB_COLOR_WITH_ALPHA(a1, nb, b1, bb); \ +SATURATE_UPPER(na, (a1) + aa); \ +WRITE_RGBA(dest, nr, ng, nb, na); + +#define BLEND_RE(r1, g1, b1, a1, dest) \ +READ_RGBA(dest, rr, gg, bb, aa); \ +RESHADE_COLOR_WITH_ALPHA(a1, nr, r1, rr); \ +RESHADE_COLOR_WITH_ALPHA(a1, ng, g1, gg); \ +RESHADE_COLOR_WITH_ALPHA(a1, nb, b1, bb); \ +WRITE_RGBA(dest, nr, ng, nb, na); + enum _imlibop { OP_COPY, diff --git a/src/colormod.c b/src/colormod.c index dd468be..3f1e4dc 100644 --- a/src/colormod.c +++ b/src/colormod.c @@ -5,6 +5,7 @@ #include #include #include "image.h" +#include "blend.h" static DATABIG mod_count = 0; @@ -87,14 +88,9 @@ __imlib_DataCmodApply(DATA32 *data, int w, int h, int jump, { for (x = 0; x < w; x++) { - b = (*p ) & 0xff; - g = (*p >> 8 ) & 0xff; - r = (*p >> 16) & 0xff; - a = (*p >> 24) & 0xff; - + READ_RGBA(p, r, g, b, a); CMOD_APPLY_RGBA(cm, r, g, b, a); - - *p = (a << 24) | (r << 16) | (g << 8) | b; + WRITE_RGBA(p, r, g, b, a); p++; } p += jump; diff --git a/src/grad.c b/src/grad.c index 1b9794d..e10a37a 100644 --- a/src/grad.c +++ b/src/grad.c @@ -142,66 +142,6 @@ __imlib_MapRange(ImlibRange *rg, int len) return map; } -#define BLEND(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = ((r1) - rr) * (a1);\ -nr = rr + ((tmp + (tmp >> 8) + 0x80) >> 8);\ -tmp = ((g1) - gg) * (a1);\ -ng = gg + ((tmp + (tmp >> 8) + 0x80) >> 8);\ -tmp = ((b1) - bb) * (a1);\ -nb = bb + ((tmp + (tmp >> 8) + 0x80) >> 8);\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - -#define BLEND_ADD(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = rr + (((r1) * (a1)) >> 8);\ -nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -tmp = gg + (((g1) * (a1)) >> 8);\ -ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -tmp = bb + (((b1) * (a1)) >> 8);\ -nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - -#define BLEND_SUB(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = rr - (((r1) * (a1)) >> 8);\ -nr = tmp & (~(tmp >> 8));\ -tmp = gg - (((g1) * (a1)) >> 8);\ -ng = tmp & (~(tmp >> 8));\ -tmp = bb - (((b1) * (a1)) >> 8);\ -nb = tmp & (~(tmp >> 8));\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - -#define BLEND_RE(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = rr + ((((r1) - 127) * (a1)) >> 7);\ -nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9));\ -tmp = gg + ((((g1) - 127) * (a1)) >> 7);\ -ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9));\ -tmp = bb + ((((b1) - 127) * (a1)) >> 7);\ -nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9));\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - void __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, ImlibRange *rg, double angle, ImlibOp op) @@ -282,12 +222,8 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, i = 0; else if (i >= len) i = len - 1; - v = map[i]; - b = ((v) ) & 0xff; - g = ((v) >> 8 ) & 0xff; - r = ((v) >> 16) & 0xff; - a = ((v) >> 24) & 0xff; - BLEND(r, g, b, a, *p); + READ_RGBA(&(map[i]), r, g, b, a); + BLEND(r, g, b, a, p); p++; } p += jump; @@ -303,12 +239,8 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, i = 0; else if (i >= len) i = len - 1; - v = map[i]; - b = ((v) ) & 0xff; - g = ((v) >> 8 ) & 0xff; - r = ((v) >> 16) & 0xff; - a = ((v) >> 24) & 0xff; - BLEND_SUB(r, g, b, a, *p); + READ_RGBA(&(map[i]), r, g, b, a); + BLEND_SUB(r, g, b, a, p); p++; } p += jump; @@ -324,12 +256,8 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, i = 0; else if (i >= len) i = len - 1; - v = map[i]; - b = ((v) ) & 0xff; - g = ((v) >> 8 ) & 0xff; - r = ((v) >> 16) & 0xff; - a = ((v) >> 24) & 0xff; - BLEND_SUB(r, g, b, a, *p); + READ_RGBA(&(map[i]), r, g, b, a); + BLEND_SUB(r, g, b, a, p); p++; } p += jump; @@ -345,12 +273,8 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, i = 0; else if (i >= len) i = len - 1; - v = map[i]; - b = ((v) ) & 0xff; - g = ((v) >> 8 ) & 0xff; - r = ((v) >> 16) & 0xff; - a = ((v) >> 24) & 0xff; - BLEND_RE(r, g, b, a, *p); + READ_RGBA(&(map[i]), r, g, b, a); + BLEND_RE(r, g, b, a, p); p++; } p += jump; diff --git a/src/rgbadraw.c b/src/rgbadraw.c index 73dbf23..0e6f20d 100644 --- a/src/rgbadraw.c +++ b/src/rgbadraw.c @@ -425,67 +425,6 @@ __imlib_TileImageVert(ImlibImage *im) im->data = data; } -#define BLEND(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = ((r1) - rr) * (a1);\ -nr = rr + ((tmp + (tmp >> 8) + 0x80) >> 8);\ -tmp = ((g1) - gg) * (a1);\ -ng = gg + ((tmp + (tmp >> 8) + 0x80) >> 8);\ -tmp = ((b1) - bb) * (a1);\ -nb = bb + ((tmp + (tmp >> 8) + 0x80) >> 8);\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - -#define BLEND_ADD(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = rr + (((r1) * (a1)) >> 8);\ -nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -tmp = gg + (((g1) * (a1)) >> 8);\ -ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -tmp = bb + (((b1) * (a1)) >> 8);\ -nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - -#define BLEND_SUB(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = rr - (((r1) * (a1)) >> 8);\ -nr = tmp & (~(tmp >> 8));\ -tmp = gg - (((g1) * (a1)) >> 8);\ -ng = tmp & (~(tmp >> 8));\ -tmp = bb - (((b1) * (a1)) >> 8);\ -nb = tmp & (~(tmp >> 8));\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - -#define BLEND_RE(r1, g1, b1, a1, dest) \ -bb = ((dest) ) & 0xff;\ -gg = ((dest) >> 8 ) & 0xff;\ -rr = ((dest) >> 16) & 0xff;\ -aa = ((dest) >> 24) & 0xff;\ -tmp = rr + ((((r1) - 127) * (a1)) >> 7);\ -nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9));\ -tmp = gg + ((((g1) - 127) * (a1)) >> 7);\ -ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9));\ -tmp = bb + ((((b1) - 127) * (a1)) >> 7);\ -nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9));\ -tmp = (a1) + aa;\ -na = (tmp | ((tmp & 256) - ((tmp & 256) >> 9)));\ -(dest) = (na << 24) | (nr << 16) | (ng << 8) | nb; - - ImlibUpdate * __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, DATA8 r, DATA8 g, DATA8 b, DATA8 a, @@ -569,7 +508,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (y = y1; y <= y2; y++) { - BLEND(r, g, b, a, *p); + BLEND(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y1, 1, (y2 - y1 + 1)); @@ -579,7 +518,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y2) + x1]); for (y = y2; y <= y1; y++) { - BLEND(r, g, b, a, *p); + BLEND(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y2, 1, (y1 - y2 + 1)); @@ -593,7 +532,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (x = x1; x <= x2; x++) { - BLEND(r, g, b, a, *p); + BLEND(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x1, y1, (x2 - x1 + 1), 1); @@ -603,7 +542,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x2]); for (x = x2; x <= x1; x++) { - BLEND(r, g, b, a, *p); + BLEND(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x2, y1, (x1 - x2 + 1), 1); @@ -626,13 +565,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p ++; - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); } x += dx; } @@ -650,13 +589,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); } y += dy; } @@ -681,13 +620,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p--; - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); } x += dx; } @@ -705,13 +644,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND(r, g, b, aaa, *p); + BLEND(r, g, b, aaa, p); } y += dy; } @@ -729,7 +668,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (y = y1; y <= y2; y++) { - BLEND_ADD(r, g, b, a, *p); + BLEND_ADD(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y1, 1, (y2 - y1 + 1)); @@ -739,7 +678,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y2) + x1]); for (y = y2; y <= y1; y++) { - BLEND_ADD(r, g, b, a, *p); + BLEND_ADD(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y2, 1, (y1 - y2 + 1)); @@ -753,7 +692,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (x = x1; x <= x2; x++) { - BLEND_ADD(r, g, b, a, *p); + BLEND_ADD(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x1, y1, (x2 - x1 + 1), 1); @@ -763,7 +702,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x2]); for (x = x2; x <= x1; x++) { - BLEND_ADD(r, g, b, a, *p); + BLEND_ADD(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x2, y1, (x1 - x2 + 1), 1); @@ -786,13 +725,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p ++; - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); } x += dx; } @@ -810,13 +749,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); } y += dy; } @@ -841,13 +780,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p--; - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); } x += dx; } @@ -865,13 +804,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND_ADD(r, g, b, aaa, *p); + BLEND_ADD(r, g, b, aaa, p); } y += dy; } @@ -889,7 +828,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (y = y1; y <= y2; y++) { - BLEND_SUB(r, g, b, a, *p); + BLEND_SUB(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y1, 1, (y2 - y1 + 1)); @@ -899,7 +838,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y2) + x1]); for (y = y2; y <= y1; y++) { - BLEND_SUB(r, g, b, a, *p); + BLEND_SUB(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y2, 1, (y1 - y2 + 1)); @@ -913,7 +852,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (x = x1; x <= x2; x++) { - BLEND_SUB(r, g, b, a, *p); + BLEND_SUB(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x1, y1, (x2 - x1 + 1), 1); @@ -923,7 +862,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x2]); for (x = x2; x <= x1; x++) { - BLEND_SUB(r, g, b, a, *p); + BLEND_SUB(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x2, y1, (x1 - x2 + 1), 1); @@ -946,13 +885,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p ++; - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); } x += dx; } @@ -970,13 +909,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); } y += dy; } @@ -1001,13 +940,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p--; - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); } x += dx; } @@ -1025,13 +964,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND_SUB(r, g, b, aaa, *p); + BLEND_SUB(r, g, b, aaa, p); } y += dy; } @@ -1049,7 +988,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (y = y1; y <= y2; y++) { - BLEND_RE(r, g, b, a, *p); + BLEND_RE(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y1, 1, (y2 - y1 + 1)); @@ -1059,7 +998,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y2) + x1]); for (y = y2; y <= y1; y++) { - BLEND_RE(r, g, b, a, *p); + BLEND_RE(r, g, b, a, p); p += im->w; } return __imlib_AddUpdate(NULL, x1, y2, 1, (y1 - y2 + 1)); @@ -1073,7 +1012,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x1]); for (x = x1; x <= x2; x++) { - BLEND_RE(r, g, b, a, *p); + BLEND_RE(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x1, y1, (x2 - x1 + 1), 1); @@ -1083,7 +1022,7 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, p = &(im->data[(im->w * y1) + x2]); for (x = x2; x <= x1; x++) { - BLEND_RE(r, g, b, a, *p); + BLEND_RE(r, g, b, a, p); p++; } return __imlib_AddUpdate(NULL, x2, y1, (x1 - x2 + 1), 1); @@ -1106,13 +1045,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p ++; - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); } x += dx; } @@ -1130,13 +1069,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); } y += dy; } @@ -1161,13 +1100,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = (((x - (xx << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * y) + xx]); - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); if (xx < (im->w - 1)) { am = 256 - am; aaa = (a * am) >> 8; p--; - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); } x += dx; } @@ -1185,13 +1124,13 @@ __imlib_draw_line(ImlibImage *im, int x1, int y1, int x2, int y2, am = 256 - (((y - (yy << 16)) + 1) >> 8); aaa = (a * am) >> 8; p = &(im->data[(im->w * yy) + x]); - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); if (yy < (im->h - 1)) { am = 256 - am; aaa = (a * am) >> 8; p += im->w; - BLEND_RE(r, g, b, aaa, *p); + BLEND_RE(r, g, b, aaa, p); } y += dy; } @@ -1256,7 +1195,7 @@ __imlib_draw_filled_box(ImlibImage *im, int x, int y, int w, int h, p = im->data + ((y + yy) * im->w) + x; for (xx = 0; xx < w; xx++) { - BLEND(r, g, b, a, *p); + BLEND(r, g, b, a, p); p++; } } @@ -1267,7 +1206,7 @@ __imlib_draw_filled_box(ImlibImage *im, int x, int y, int w, int h, p = im->data + ((y + yy) * im->w) + x; for (xx = 0; xx < w; xx++) { - BLEND_ADD(r, g, b, a, *p); + BLEND_ADD(r, g, b, a, p); p++; } } @@ -1278,7 +1217,7 @@ __imlib_draw_filled_box(ImlibImage *im, int x, int y, int w, int h, p = im->data + ((y + yy) * im->w) + x; for (xx = 0; xx < w; xx++) { - BLEND_SUB(r, g, b, a, *p); + BLEND_SUB(r, g, b, a, p); p++; } } @@ -1289,7 +1228,7 @@ __imlib_draw_filled_box(ImlibImage *im, int x, int y, int w, int h, p = im->data + ((y + yy) * im->w) + x; for (xx = 0; xx < w; xx++) { - BLEND_RE(r, g, b, a, *p); + BLEND_RE(r, g, b, a, p); p++; } } @@ -1462,8 +1401,8 @@ __imlib_copy_alpha_data(ImlibImage *src, ImlibImage *dst, return; /* figure out what our source and destnation start pointers are */ - p1 = src->data + (y * src->h) + x; - p2 = dst->data + (ny * dst->h) + nx; + p1 = src->data + (y * src->w) + x; + p2 = dst->data + (ny * dst->w) + nx; /* the pointer jump between lines */ jump = (src->w - w); jump2 = (dst->w - w);