| 405 | |
| 406 | |
| 407 | ILimage *iQuantizeImage(ILimage *Image, ILuint NumCols) |
| 408 | { |
| 409 | Box cube[MAXCOLOR]; |
| 410 | ILubyte *tag = NULL; |
| 411 | ILubyte lut_r[MAXCOLOR], lut_g[MAXCOLOR], lut_b[MAXCOLOR]; |
| 412 | ILint next; |
| 413 | ILint weight; |
| 414 | ILuint k; |
| 415 | ILfloat vv[MAXCOLOR], temp; |
| 416 | //ILint color_num; |
| 417 | ILubyte *NewData = NULL, *Palette = NULL; |
| 418 | ILimage *TempImage = NULL, *NewImage = NULL; |
| 419 | ILubyte *Ir = NULL, *Ig = NULL, *Ib = NULL; |
| 420 | |
| 421 | ILint num_alloced_colors; // number of colors we allocated space for in palette, as NumCols but will not be less than 256 |
| 422 | |
| 423 | num_alloced_colors=NumCols; |
| 424 | if(num_alloced_colors<256) { num_alloced_colors=256; } |
| 425 | |
| 426 | |
| 427 | NewImage = iCurImage; |
| 428 | iCurImage = Image; |
| 429 | TempImage = iConvertImage(iCurImage, IL_RGB, IL_UNSIGNED_BYTE); |
| 430 | iCurImage = NewImage; |
| 431 | |
| 432 | |
| 433 | |
| 434 | if (TempImage == NULL) |
| 435 | return NULL; |
| 436 | |
| 437 | buffer = Image->Data; |
| 438 | WindW = Width = Image->Width; |
| 439 | WindH = Height = Image->Height; |
| 440 | WindD = Depth = Image->Depth; |
| 441 | Comp = Image->Bpp; |
| 442 | Qadd = NULL; |
| 443 | |
| 444 | //color_num = ImagePrecalculate(Image); |
| 445 | |
| 446 | NewData = (ILubyte*)ialloc(Image->Width * Image->Height * Image->Depth); |
| 447 | Palette = (ILubyte*)ialloc(3 * num_alloced_colors); |
| 448 | if (!NewData || !Palette) { |
| 449 | ifree(NewData); |
| 450 | ifree(Palette); |
| 451 | return NULL; |
| 452 | } |
| 453 | |
| 454 | Ir = (ILubyte*)ialloc(Width * Height * Depth); |
| 455 | Ig = (ILubyte*)ialloc(Width * Height * Depth); |
| 456 | Ib = (ILubyte*)ialloc(Width * Height * Depth); |
| 457 | if (!Ir || !Ig || !Ib) { |
| 458 | ifree(Ir); |
| 459 | ifree(Ig); |
| 460 | ifree(Ib); |
| 461 | ifree(NewData); |
| 462 | ifree(Palette); |
| 463 | return NULL; |
| 464 | } |
no test coverage detected