MCPcopy Create free account
hub / github.com/DentonW/DevIL / CompressTo565

Function CompressTo565

DevIL/src-IL/src/il_dds-save.cpp:382–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380
381
382ILushort *CompressTo565(ILimage *Image)
383{
384 ILimage *TempImage;
385 ILushort *Data;
386 ILuint i, j;
387
388 if ((Image->Type != IL_UNSIGNED_BYTE && Image->Type != IL_BYTE) || Image->Format == IL_COLOUR_INDEX) {
389 TempImage = iConvertImage(iCurImage, IL_BGRA, IL_UNSIGNED_BYTE); // @TODO: Needs to be BGRA.
390 if (TempImage == NULL)
391 return NULL;
392 }
393 else {
394 TempImage = Image;
395 }
396
397 Data = (ILushort*)ialloc(iCurImage->Width * iCurImage->Height * 2 * iCurImage->Depth);
398 if (Data == NULL) {
399 if (TempImage != Image)
400 ilCloseImage(TempImage);
401 return NULL;
402 }
403
404 //changed 20040623: Use TempImages format :)
405 switch (TempImage->Format)
406 {
407 case IL_RGB:
408 for (i = 0, j = 0; i < TempImage->SizeOfData; i += 3, j++) {
409 /*Data[j] = (TempImage->Data[i ] >> 3) << 11;
410 Data[j] |= (TempImage->Data[i+1] >> 2) << 5;
411 Data[j] |= TempImage->Data[i+2] >> 3;*/
412 Data[j] = As16Bit(TempImage->Data[i], TempImage->Data[i+1], TempImage->Data[i+2]);
413 }
414 break;
415
416 case IL_RGBA:
417 for (i = 0, j = 0; i < TempImage->SizeOfData; i += 4, j++) {
418 /*Data[j] = (TempImage->Data[i ] >> 3) << 11;
419 Data[j] |= (TempImage->Data[i+1] >> 2) << 5;
420 Data[j] |= TempImage->Data[i+2] >> 3;*/
421 Data[j] = As16Bit(TempImage->Data[i], TempImage->Data[i+1], TempImage->Data[i+2]);
422 }
423 break;
424
425 case IL_BGR:
426 for (i = 0, j = 0; i < TempImage->SizeOfData; i += 3, j++) {
427 /*Data[j] = (TempImage->Data[i+2] >> 3) << 11;
428 Data[j] |= (TempImage->Data[i+1] >> 2) << 5;
429 Data[j] |= TempImage->Data[i ] >> 3;*/
430 Data[j] = As16Bit(TempImage->Data[i+2], TempImage->Data[i+1], TempImage->Data[i]);
431 }
432 break;
433
434 case IL_BGRA:
435 for (i = 0, j = 0; i < TempImage->SizeOfData; i += 4, j++) {
436 /*Data[j] = (TempImage->Data[i+2] >> 3) << 11;
437 Data[j] |= (TempImage->Data[i+1] >> 2) << 5;
438 Data[j] |= TempImage->Data[i ] >> 3;*/
439 Data[j] = As16Bit(TempImage->Data[i+2], TempImage->Data[i+1], TempImage->Data[i]);

Callers 1

CompressFunction · 0.85

Calls 2

ilCloseImageFunction · 0.85
As16BitFunction · 0.85

Tested by

no test coverage detected