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

Function iSaveRleSgi

DevIL/src-IL/src/il_sgi.cpp:697–758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

695/*----------------------------------------------------------------------------*/
696
697ILboolean iSaveRleSgi(ILubyte *Data, ILuint w, ILuint h, ILuint numChannels,
698 ILuint bps)
699{
700 //works only for sgi files with only 1 bpc
701
702 ILuint c, i, y, j;
703 ILubyte *ScanLine = NULL, *CompLine = NULL;
704 ILuint *StartTable = NULL, *LenTable = NULL;
705 ILuint TableOff, DataOff = 0;
706
707 ScanLine = (ILubyte*)ialloc(w);
708 CompLine = (ILubyte*)ialloc(w * 2 + 1); // Absolute worst case.
709 StartTable = (ILuint*)ialloc(h * numChannels * sizeof(ILuint));
710 LenTable = (ILuint*)icalloc(h * numChannels, sizeof(ILuint));
711 if (!ScanLine || !CompLine || !StartTable || !LenTable) {
712 ifree(ScanLine);
713 ifree(CompLine);
714 ifree(StartTable);
715 ifree(LenTable);
716 return IL_FALSE;
717 }
718
719 // These just contain dummy values at this point.
720 TableOff = itellw();
721 iwrite(StartTable, sizeof(ILuint), h * numChannels);
722 iwrite(LenTable, sizeof(ILuint), h * numChannels);
723
724 DataOff = itellw();
725 for (c = 0; c < numChannels; c++) {
726 for (y = 0; y < h; y++) {
727 i = y * bps + c;
728 for (j = 0; j < w; j++, i += numChannels) {
729 ScanLine[j] = Data[i];
730 }
731
732 ilRleCompressLine(ScanLine, w, 1, CompLine, LenTable + h * c + y, IL_SGICOMP);
733 iwrite(CompLine, 1, *(LenTable + h * c + y));
734 }
735 }
736
737 iseekw(TableOff, IL_SEEK_SET);
738
739 j = h * numChannels;
740 for (y = 0; y < j; y++) {
741 StartTable[y] = DataOff;
742 DataOff += LenTable[y];
743#ifdef __LITTLE_ENDIAN__
744 iSwapUInt(&StartTable[y]);
745 iSwapUInt(&LenTable[y]);
746#endif
747 }
748
749 iwrite(StartTable, sizeof(ILuint), h * numChannels);
750 iwrite(LenTable, sizeof(ILuint), h * numChannels);
751
752 ifree(ScanLine);
753 ifree(CompLine);
754 ifree(StartTable);

Callers 1

iSaveSgiInternalFunction · 0.85

Calls 2

ilRleCompressLineFunction · 0.85
iSwapUIntFunction · 0.85

Tested by

no test coverage detected