MCPcopy Create free account
hub / github.com/DentonW/DevIL / ILAPIENTRY ilCompressDXT

Function ILAPIENTRY ilCompressDXT

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

Compresses data to a DXT format using different methods. The data must be in unsigned byte RGBA or BGRA format. Only DXT1, DXT3 and DXT5 are supported.

Source from the content-addressed store, hash-verified

1246//! Compresses data to a DXT format using different methods.
1247// The data must be in unsigned byte RGBA or BGRA format. Only DXT1, DXT3 and DXT5 are supported.
1248ILAPI ILubyte* ILAPIENTRY ilCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILuint Depth, ILenum DXTCFormat, ILuint *DXTCSize)
1249{
1250 ILimage *TempImage, *CurImage = iCurImage;
1251 ILuint BuffSize;
1252 ILubyte *Buffer;
1253
1254 if ((DXTCFormat != IL_DXT1 && DXTCFormat != IL_DXT1A && DXTCFormat != IL_DXT3 && DXTCFormat != IL_DXT5)
1255 || Data == NULL || Width == 0 || Height == 0 || Depth == 0) {
1256 ilSetError(IL_INVALID_PARAM);
1257 return NULL;
1258 }
1259
1260 // We want to try nVidia compression first, because it is the fastest.
1261#ifdef IL_USE_DXTC_NVIDIA
1262 if (ilIsEnabled(IL_NVIDIA_COMPRESS) && Depth == 1) { // See if we need to use the nVidia Texture Tools library.
1263 // NVTT needs data as BGRA 32-bit.
1264 // Here's where all the compression and writing goes on.
1265 return ilNVidiaCompressDXT(Data, Width, Height, 1, DXTCFormat, DXTCSize);
1266 }
1267#endif//IL_USE_DXTC_NVIDIA
1268
1269 // libsquish generates better quality output than DevIL does, so we try it next.
1270#ifdef IL_USE_DXTC_SQUISH
1271 if (ilIsEnabled(IL_SQUISH_COMPRESS) && Depth == 1) { // See if we need to use the nVidia Texture Tools library.
1272 if (DXTCFormat == IL_DXT1 || DXTCFormat == IL_DXT1A || DXTCFormat == IL_DXT3 || DXTCFormat == IL_DXT5) {
1273 // libsquish needs data as RGBA 32-bit.
1274 // Get compressed data here.
1275 return ilSquishCompressDXT(Data, Width, Height, 1, DXTCFormat, DXTCSize);
1276 }
1277 }
1278#endif//IL_USE_DXTC_SQUISH
1279
1280 TempImage = (ILimage*)ialloc(sizeof(ILimage));
1281 memset(TempImage, 0, sizeof(ILimage));
1282 TempImage->Width = Width;
1283 TempImage->Height = Height;
1284 TempImage->Depth = Depth;
1285 TempImage->Bpp = 4; // RGBA or BGRA
1286 TempImage->Format = IL_BGRA;
1287 TempImage->Bpc = 1; // Unsigned bytes only
1288 TempImage->Type = IL_UNSIGNED_BYTE;
1289 TempImage->SizeOfPlane = TempImage->Bps * Height;
1290 TempImage->SizeOfData = TempImage->SizeOfPlane * Depth;
1291 TempImage->Origin = IL_ORIGIN_UPPER_LEFT;
1292 TempImage->Data = Data;
1293
1294 BuffSize = ilGetDXTCData(NULL, 0, DXTCFormat);
1295 if (BuffSize == 0)
1296 return NULL;
1297 Buffer = (ILubyte*)ialloc(BuffSize);
1298 if (Buffer == NULL)
1299 return NULL;
1300
1301 if (ilGetDXTCData(Buffer, BuffSize, DXTCFormat) != BuffSize) {
1302 ifree(Buffer);
1303 return NULL;
1304 }
1305 *DXTCSize = BuffSize;

Callers

nothing calls this directly

Calls 2

ilSetErrorFunction · 0.85
ilCloseImageFunction · 0.85

Tested by

no test coverage detected