Blame src/gd_color.c

Packit ed3af9
#ifdef HAVE_CONFIG_H
Packit ed3af9
#include "config.h"
Packit ed3af9
#endif
Packit ed3af9
Packit ed3af9
#include "gd.h"
Packit ed3af9
#include "gd_color.h"
Packit ed3af9
Packit ed3af9
/**
Packit ed3af9
 * The threshold method works relatively well but it can be improved.
Packit ed3af9
 * Maybe L*a*b* and Delta-E will give better results (and a better
Packit ed3af9
 * granularity).
Packit ed3af9
 */
Packit ed3af9
int gdColorMatch(gdImagePtr im, int col1, int col2, float threshold)
Packit ed3af9
{
Packit ed3af9
	const int dr = gdImageRed(im, col1) - gdImageRed(im, col2);
Packit ed3af9
	const int dg = gdImageGreen(im, col1) - gdImageGreen(im, col2);
Packit ed3af9
	const int db = gdImageBlue(im, col1) - gdImageBlue(im, col2);
Packit ed3af9
	const int da = gdImageAlpha(im, col1) - gdImageAlpha(im, col2);
Packit ed3af9
	const int dist = dr * dr + dg * dg + db * db + da * da;
Packit ed3af9
Packit ed3af9
	return (100.0 * dist / 195075) < threshold;
Packit ed3af9
}
Packit ed3af9
Packit ed3af9
/*
Packit ed3af9
 * To be implemented when we have more image formats.
Packit ed3af9
 * Buffer like gray8 gray16 or rgb8 will require some tweak
Packit ed3af9
 * and can be done in this function (called from the autocrop
Packit ed3af9
 * function. (Pierre)
Packit ed3af9
 */
Packit ed3af9
#if 0
Packit ed3af9
static int colors_equal (const int col1, const in col2)
Packit ed3af9
{
Packit ed3af9
Packit ed3af9
}
Packit ed3af9
#endif