Converts an image from one format to another
| 273 | |
| 274 | // Converts an image from one format to another |
| 275 | ILAPI ILimage* ILAPIENTRY iConvertImage(ILimage *Image, ILenum DestFormat, ILenum DestType) |
| 276 | { |
| 277 | ILimage *NewImage, *CurImage; |
| 278 | ILuint i; |
| 279 | ILubyte *NewData; |
| 280 | |
| 281 | CurImage = Image; |
| 282 | if (Image == NULL) { |
| 283 | ilSetError(IL_ILLEGAL_OPERATION); |
| 284 | return IL_FALSE; |
| 285 | } |
| 286 | |
| 287 | // We don't support 16-bit color indices (or higher). |
| 288 | if (DestFormat == IL_COLOUR_INDEX && DestType >= IL_SHORT) { |
| 289 | ilSetError(IL_INVALID_CONVERSION); |
| 290 | return NULL; |
| 291 | } |
| 292 | |
| 293 | if (Image->Format == IL_COLOUR_INDEX) { |
| 294 | NewImage = iConvertPalette(Image, DestFormat); |
| 295 | |
| 296 | //added test 2003-09-01 |
| 297 | if (NewImage == NULL) |
| 298 | return NULL; |
| 299 | |
| 300 | if (DestType == NewImage->Type) |
| 301 | return NewImage; |
| 302 | |
| 303 | NewData = (ILubyte*)ilConvertBuffer(NewImage->SizeOfData, NewImage->Format, DestFormat, NewImage->Type, DestType, NULL, NewImage->Data); |
| 304 | if (NewData == NULL) { |
| 305 | ifree(NewImage); // ilCloseImage not needed. |
| 306 | return NULL; |
| 307 | } |
| 308 | ifree(NewImage->Data); |
| 309 | NewImage->Data = NewData; |
| 310 | |
| 311 | ilCopyImageAttr(NewImage, Image); |
| 312 | NewImage->Format = DestFormat; |
| 313 | NewImage->Type = DestType; |
| 314 | NewImage->Bpc = ilGetBpcType(DestType); |
| 315 | NewImage->Bpp = ilGetBppFormat(DestFormat); |
| 316 | NewImage->Bps = NewImage->Bpp * NewImage->Bpc * NewImage->Width; |
| 317 | NewImage->SizeOfPlane = NewImage->Bps * NewImage->Height; |
| 318 | NewImage->SizeOfData = NewImage->SizeOfPlane * NewImage->Depth; |
| 319 | } |
| 320 | else if (DestFormat == IL_COLOUR_INDEX && Image->Format != IL_LUMINANCE) { |
| 321 | if (iGetInt(IL_QUANTIZATION_MODE) == IL_NEU_QUANT) |
| 322 | return iNeuQuant(Image, iGetInt(IL_MAX_QUANT_INDICES)); |
| 323 | else // Assume IL_WU_QUANT otherwise. |
| 324 | return iQuantizeImage(Image, iGetInt(IL_MAX_QUANT_INDICES)); |
| 325 | } |
| 326 | else { |
| 327 | NewImage = (ILimage*)icalloc(1, sizeof(ILimage)); // Much better to have it all set to 0. |
| 328 | if (NewImage == NULL) { |
| 329 | return NULL; |
| 330 | } |
| 331 | |
| 332 | if (ilGetBppFormat(DestFormat) == 0) { |
nothing calls this directly
no test coverage detected