-
Notifications
You must be signed in to change notification settings - Fork 275
Introduce gdLayerDiff() and gdEffectDiff #920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1299,6 +1299,9 @@ BGD_DECLARE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color) | |
| case gdEffectMultiply : | ||
| im->tpixels[y][x] = gdLayerMultiply(im->tpixels[y][x], color); | ||
| break; | ||
| case gdEffectDiff : | ||
| im->tpixels[y][x] = gdLayerDiff(im->tpixels[y][x], color); | ||
| break; | ||
| } | ||
| } else { | ||
| im->pixels[y][x] = color; | ||
|
|
@@ -4070,6 +4073,7 @@ BGD_DECLARE(int) gdImageCompare (gdImagePtr im1, gdImagePtr im2) | |
| * - <gdImageAlphaBlending> | ||
| * - <gdLayerOverlay> | ||
| * - <gdLayerMultiply> | ||
| * - <gdLayerDiff> | ||
| */ | ||
| BGD_DECLARE(int) gdAlphaBlend (int dst, int src) | ||
| { | ||
|
|
@@ -4131,6 +4135,7 @@ static int gdAlphaOverlayColor (int src, int dst, int max ); | |
| * - <gdImageAlphaBlending> | ||
| * - <gdAlphaBlend> | ||
| * - <gdLayerMultiply> | ||
| * - <gdLayerDiff> | ||
| */ | ||
| BGD_DECLARE(int) gdLayerOverlay (int dst, int src) | ||
| { | ||
|
|
@@ -4170,6 +4175,7 @@ static int gdAlphaOverlayColor (int src, int dst, int max ) | |
| * - <gdImageAlphaBlending> | ||
| * - <gdAlphaBlend> | ||
| * - <gdLayerOverlay> | ||
| * - <gdLayerDiff> | ||
| */ | ||
| BGD_DECLARE(int) gdLayerMultiply (int dst, int src) | ||
| { | ||
|
|
@@ -4193,6 +4199,45 @@ BGD_DECLARE(int) gdLayerMultiply (int dst, int src) | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Function: gdLayerDiff | ||
| * | ||
| * Difference of two colors; commutative operation. | ||
| * | ||
| * Parameters: | ||
| * dst - The first color. | ||
| * src - The second color. | ||
| * | ||
| * See also: | ||
| * - <gdImageAlphaBlending> | ||
| * - <gdAlphaBlend> | ||
| * - <gdLayerMultiply> | ||
| * - <gdLayerOverlay> | ||
| */ | ||
| BGD_DECLARE(int) gdLayerDiff (int dst, int src) | ||
| { | ||
| int r1,b1,g1,a1,r2,b2,g2,a2; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces after commas please |
||
| int diff_a,diff_r,diff_g,diff_b; | ||
|
|
||
| a1 = gdTrueColorGetAlpha(dst); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm on the fence whether all these variables are needed vs a single statement. |
||
| a2 = gdTrueColorGetAlpha(src); | ||
| diff_a = abs(a1 - a2); | ||
|
|
||
| r1 = gdTrueColorGetRed(dst); | ||
| r2 = gdTrueColorGetRed(src); | ||
| diff_r = abs(r1 - r2); | ||
|
|
||
| g1 = gdTrueColorGetGreen(dst); | ||
| g2 = gdTrueColorGetGreen(src); | ||
| diff_g = abs(g1 - g2); | ||
|
|
||
| b1 = gdTrueColorGetBlue(dst); | ||
| b2 = gdTrueColorGetBlue(src); | ||
| diff_b = abs(b1 - b2); | ||
|
|
||
| return gdTrueColorAlpha(diff_r, diff_g, diff_b, diff_a); | ||
| } | ||
|
|
||
| /** | ||
| * Function: gdImageAlphaBlending | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ LIST(APPEND TESTS_FILES | |
| bug00186 | ||
| gdeffectoverlay | ||
| gdeffectmultiply | ||
| gdeffectdiff | ||
| ) | ||
|
|
||
| IF(PNG_FOUND) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include "gd.h" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a proper file header: license, copyright, and text explaining the test goals. |
||
| #include "gdtest.h" | ||
|
|
||
| int main() | ||
| { | ||
| gdImagePtr im; | ||
| int x, y, c; | ||
| int r=0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces around binary operators like |
||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only one blank line |
||
| im = gdImageCreateTrueColor(256, 256); | ||
| gdImageAlphaBlending( im, gdEffectReplace ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no space after |
||
| for (x=0; x<256; x++) { | ||
| for (y=0; y<256; y++) { | ||
| c = (y/2 << 24) + (x << 16) + (x << 8) + x; | ||
| gdImageSetPixel(im, x, y, c ); | ||
| } | ||
| } | ||
| gdImageAlphaBlending( im, gdEffectDiff ); | ||
| gdImageFilledRectangle(im, 0, 0, 255, 255, 0xff7f00); | ||
|
|
||
| if (gdTrueColorGetGreen(gdImageGetPixel(im, 0, 128)) != 0x7f) { | ||
| r = 1; | ||
| } | ||
| if (gdTrueColorGetGreen(gdImageGetPixel(im, 128, 128)) != 0x01) { | ||
| r = 1; | ||
| } | ||
| if (gdTrueColorGetGreen(gdImageGetPixel(im, 255, 128)) != 0x80) { | ||
| r = 1; | ||
| } | ||
| gdImageDestroy(im); | ||
| return r; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it note that it's absolute ?