1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 
5 #include "gd.h"
6 #include "gd_color.h"
7 
8 /**
9  * The threshold method works relatively well but it can be improved.
10  * Maybe L*a*b* and Delta-E will give better results (and a better
11  * granularity).
12  */
gdColorMatch(gdImagePtr im,int col1,int col2,float threshold)13 int gdColorMatch(gdImagePtr im, int col1, int col2, float threshold)
14 {
15 	const int dr = gdImageRed(im, col1) - gdImageRed(im, col2);
16 	const int dg = gdImageGreen(im, col1) - gdImageGreen(im, col2);
17 	const int db = gdImageBlue(im, col1) - gdImageBlue(im, col2);
18 	const int da = gdImageAlpha(im, col1) - gdImageAlpha(im, col2);
19 	const int dist = dr * dr + dg * dg + db * db + da * da;
20 
21 	return (100.0 * dist / 195075) < threshold;
22 }
23 
24 /*
25  * To be implemented when we have more image formats.
26  * Buffer like gray8 gray16 or rgb8 will require some tweak
27  * and can be done in this function (called from the autocrop
28  * function. (Pierre)
29  */
30 #if 0
31 static int colors_equal (const int col1, const in col2)
32 {
33 
34 }
35 #endif
36