summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-src/src/gd_crop.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/gd/libgd-src/src/gd_crop.c')
-rw-r--r--Build/source/libs/gd/libgd-src/src/gd_crop.c51
1 files changed, 21 insertions, 30 deletions
diff --git a/Build/source/libs/gd/libgd-src/src/gd_crop.c b/Build/source/libs/gd/libgd-src/src/gd_crop.c
index 1a6a11f73ca..68f58c695cc 100644
--- a/Build/source/libs/gd/libgd-src/src/gd_crop.c
+++ b/Build/source/libs/gd/libgd-src/src/gd_crop.c
@@ -6,7 +6,7 @@
* Some functions to crop images, automatically (auto detection of the border
* color), using a given color (with or without tolerance) or using a given
* rectangle.
- *
+ *
* Example:
* (start code)
* im2 = gdImageAutoCrop(im, GD_CROP_SIDES);
@@ -48,6 +48,7 @@ static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color);
BGD_DECLARE(gdImagePtr) gdImageCrop(gdImagePtr src, const gdRect *crop)
{
gdImagePtr dst;
+ int alphaBlendingFlag;
if (gdImageTrueColor(src)) {
dst = gdImageCreateTrueColor(crop->width, crop->height);
@@ -55,7 +56,10 @@ BGD_DECLARE(gdImagePtr) gdImageCrop(gdImagePtr src, const gdRect *crop)
dst = gdImageCreate(crop->width, crop->height);
}
if (!dst) return NULL;
+ alphaBlendingFlag = dst->alphaBlendingFlag;
+ gdImageAlphaBlending(dst, gdEffectReplace);
gdImageCopy(dst, src, 0, 0, crop->x, crop->y, crop->width, crop->height);
+ gdImageAlphaBlending(dst, alphaBlendingFlag);
return dst;
}
@@ -126,30 +130,24 @@ BGD_DECLARE(gdImagePtr) gdImageCropAuto(gdImagePtr im, const unsigned int mode)
}
}
- /* Nothing to do > bye
- * Duplicate the image?
- */
- if (y == height - 1) {
+ /* Whole image would be cropped > bye */
+ if (match) {
return NULL;
}
- crop.y = y -1;
+ crop.y = y - 1;
+
match = 1;
for (y = height - 1; match && y >= 0; y--) {
for (x = 0; match && x < width; x++) {
match = (color == gdImageGetPixel(im, x,y));
}
}
-
- if (y == 0) {
- crop.height = height - crop.y + 1;
- } else {
- crop.height = y - crop.y + 2;
- }
+ crop.height = y - crop.y + 2;
match = 1;
for (x = 0; match && x < width; x++) {
- for (y = 0; match && y < crop.y + crop.height - 1; y++) {
+ for (y = 0; match && y < crop.y + crop.height; y++) {
match = (color == gdImageGetPixel(im, x,y));
}
}
@@ -157,7 +155,7 @@ BGD_DECLARE(gdImagePtr) gdImageCropAuto(gdImagePtr im, const unsigned int mode)
match = 1;
for (x = width - 1; match && x >= 0; x--) {
- for (y = 0; match && y < crop.y + crop.height - 1; y++) {
+ for (y = 0; match && y < crop.y + crop.height; y++) {
match = (color == gdImageGetPixel(im, x,y));
}
}
@@ -179,7 +177,7 @@ BGD_DECLARE(gdImagePtr) gdImageCropAuto(gdImagePtr im, const unsigned int mode)
* im - The image.
* color - The crop color.
* threshold - The crop threshold.
- *
+ *
* Returns:
* The newly created cropped image, or NULL on failure.
*
@@ -221,31 +219,24 @@ BGD_DECLARE(gdImagePtr) gdImageCropThreshold(gdImagePtr im, const unsigned int c
}
}
- /* Pierre
- * Nothing to do > bye
- * Duplicate the image?
- */
- if (y == height - 1) {
+ /* Whole image would be cropped > bye */
+ if (match) {
return NULL;
}
- crop.y = y -1;
+ crop.y = y - 1;
+
match = 1;
for (y = height - 1; match && y >= 0; y--) {
for (x = 0; match && x < width; x++) {
match = (gdColorMatch(im, color, gdImageGetPixel(im, x, y), threshold)) > 0;
}
}
-
- if (y == 0) {
- crop.height = height - crop.y + 1;
- } else {
- crop.height = y - crop.y + 2;
- }
+ crop.height = y - crop.y + 2;
match = 1;
for (x = 0; match && x < width; x++) {
- for (y = 0; match && y < crop.y + crop.height - 1; y++) {
+ for (y = 0; match && y < crop.y + crop.height; y++) {
match = (gdColorMatch(im, color, gdImageGetPixel(im, x,y), threshold)) > 0;
}
}
@@ -253,7 +244,7 @@ BGD_DECLARE(gdImagePtr) gdImageCropThreshold(gdImagePtr im, const unsigned int c
match = 1;
for (x = width - 1; match && x >= 0; x--) {
- for (y = 0; match && y < crop.y + crop.height - 1; y++) {
+ for (y = 0; match && y < crop.y + crop.height; y++) {
match = (gdColorMatch(im, color, gdImageGetPixel(im, x,y), threshold)) > 0;
}
}
@@ -290,7 +281,7 @@ static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color)
} else if (tl == tr || tl == bl || tl == br) {
*color = tl;
return 2;
- } else if (tr == bl) {
+ } else if (tr == bl || tr == br) {
*color = tr;
return 2;
} else if (br == bl) {