cvs: gd /libgd/src gd_crop.c

[email protected] ("Pierre-Alain Joye") Fri, 14 Mar 2008 21:42:26 -0000
Newsgroups php.gd.cvs
Message-ID <cvspajoye1205530946@cvsserver>
pajoye		Fri Mar 14 21:42:26 2008 UTC

  Modified files:              
    /gd/libgd/src	gd_crop.c 
  Log:
  - remove debug code
  
  
http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_crop.c?r1=1.3&r2=1.4&diff_format=u
Index: gd/libgd/src/gd_crop.c
diff -u gd/libgd/src/gd_crop.c:1.3 gd/libgd/src/gd_crop.c:1.4
--- gd/libgd/src/gd_crop.c:1.3	Sun Jan 13 21:11:35 2008
+++ gd/libgd/src/gd_crop.c	Fri Mar 14 21:42:26 2008
@@ -12,7 +12,7 @@
 #include <stdlib.h>
 
 static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color);
-static int gdColorMatch(gdImagePtr im, int col1, int col2, int threshold);
+static int gdColorMatch(gdImagePtr im, int col1, int col2, float threshold);
 
 BGD_DECLARE(gdImagePtr) gdImageCrop(gdImagePtr src, const gdRect *crop)
 {
@@ -112,7 +112,7 @@
 	return gdImageCrop(im, &crop);
 }
 
-BGD_DECLARE(gdImagePtr) gdImageThresholdCrop(gdImagePtr im, const unsigned int color, const int threshold)
+BGD_DECLARE(gdImagePtr) gdImageThresholdCrop(gdImagePtr im, const unsigned int color, const float threshold)
 {
 	const int width = gdImageSX(im);
 	const int height = gdImageSY(im);
@@ -127,7 +127,7 @@
 	crop.height = 0;
 
 	/* Pierre: crop everything sounds bad */
-	if (threshold >= 255) {
+	if (threshold > 1.0) {
 		return NULL;
 	}
 
@@ -229,42 +229,15 @@
 	}
 }
 
-static int gdColorMatch(gdImagePtr im, int col1, int col2, int threshold)
+static int gdColorMatch(gdImagePtr im, int col1, int col2, float threshold)
 {
-	int diff, max = 0;
+	const int dr = gdImageRed(im, col1) - gdImageRed(im, col2);
+	const int dg = gdImageGreen(im, col1) - gdImageGreen(im, col2);
+	const int db = gdImageBlue(im, col1) - gdImageBlue(im, col2);
+	const int da = gdImageAlpha(im, col1) - gdImageAlpha(im, col2);
+	const int dist = dr * dr + dg * dg + db * db + da * da;
 
-
-	/* alternative method would be to take the distance in the rgb cube
-	 * between the desired color and the current pixel:
-	 * (r2 - r1)^2 + (g2 -b1)^2 + (g1 -g2)^2
-	 *
-	 * but I did not see a difference in my results, that's why I kept
-	 * this faster implementation.
-	 */
-	diff = abs(gdImageRed(im, col2) - gdImageRed(im, col1));
-	if (diff > max) {
-		max = diff;
-	}
-
-	diff = abs(gdImageGreen(im, col2) - gdImageGreen(im, col1));
-	if (diff > max) {
-		max = diff;
-	}
-
-	diff = abs(gdImageBlue(im, col2) - gdImageBlue(im, col1));
-	if (diff > max) {
-		max = diff;
-	}
-/* do we need alpha here? We may detect full transparency and consider
- * them as background
- */
-/*
-	diff = abs(gdImageAlpha(im, col2) - gdImageAlpha(im, col1));
-	if (diff > max) {
-		max = diff;
-	}
-*/
-	return (max < threshold);
+	return (100.0 * dist / 195075) < threshold;
 }
 
 /*