php_error_docref(NULL, E_WARNING, "Number of colors has to be greater than zero and no more than %d", INT_MAX);
RETURN_FALSE;
}
- gdImageTrueColorToPalette(im, dither, (int)ncolors);
-
- RETURN_TRUE;
+ if (gdImageTrueColorToPalette(im, dither, (int)ncolors)) {
+ RETURN_TRUE;
+ } else {
+ php_error_docref(NULL, E_WARNING, "Couldn't convert to palette");
+ RETURN_FALSE;
+ }
}
/* }}} */
}
if (im_org->trueColor) {
- gdImageTrueColorToPalette(im_org, 1, 256);
+ if (!gdImageTrueColorToPalette(im_org, 1, 256)) {
+ php_error_docref(NULL, E_WARNING, "Unable to convert to palette");
+ return;
+ }
}
for (y = 0; y < dest_height; y++) {
gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag, int colorsWanted);
-void gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted);
+int gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted);
int gdImagePaletteToTrueColor(gdImagePtr src);
/* An attempt at getting the results of gdImageTrueColorToPalette
}
}
-static void gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colorsWanted, gdImagePtr *cimP);
+static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colorsWanted, gdImagePtr *cimP);
gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im, int dither, int colorsWanted)
{
gdImagePtr nim;
- gdImageTrueColorToPaletteBody(im, dither, colorsWanted, &nim);
- return nim;
+ if (TRUE == gdImageTrueColorToPaletteBody(im, dither, colorsWanted, &nim)) {
+ return nim;
+ }
+ return NULL;
}
-void gdImageTrueColorToPalette (gdImagePtr im, int dither, int colorsWanted)
+int gdImageTrueColorToPalette (gdImagePtr im, int dither, int colorsWanted)
{
- gdImageTrueColorToPaletteBody(im, dither, colorsWanted, 0);
+ return gdImageTrueColorToPaletteBody(im, dither, colorsWanted, 0);
}
/*
* Module initialization routine for 2-pass color quantization.
*/
-static void gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colorsWanted, gdImagePtr *cimP)
+static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colorsWanted, gdImagePtr *cimP)
{
my_cquantize_ptr cquantize = NULL;
- int i;
+ int i, conversionSucceeded=0;
/* Allocate the JPEG palette-storage */
size_t arraysize;
nim = gdImageCreate(oim->sx, oim->sy);
*cimP = nim;
if (!nim) {
- return;
+ return FALSE;
}
} else {
nim = oim;
gdImageCopy(nim, oim, 0, 0, 0, 0, oim->sx, oim->sy);
*cimP = nim;
}
- return;
+ return TRUE;
}
/* If we have a transparent color (the alphaless mode of transparency), we
}
/* Success! Get rid of the truecolor image data. */
+ conversionSucceeded = TRUE;
if (!cimP) {
oim->trueColor = 0;
/* Junk the truecolor pixels */
gdFree (oim->tpixels);
oim->tpixels = 0;
}
- goto success;
+ goto freeQuantizeData;
/* Tediously free stuff. */
outOfMemory:
+ conversionSucceeded = FALSE;
if (oim->trueColor)
{
if (!cimP) {
*cimP = 0;
}
}
-success:
+freeQuantizeData:
for (i = 0; i < HIST_C0_ELEMS; i++)
{
if (cquantize->histogram[i])
{
gdFree (cquantize);
}
+ return conversionSucceeded;
}