| 310 | |
| 311 | |
| 312 | ILuint ILAPIENTRY ilGetDXTCData(void *Buffer, ILuint BufferSize, ILenum DXTCFormat) |
| 313 | { |
| 314 | ILubyte *CurData = NULL; |
| 315 | ILuint retVal; |
| 316 | ILint BlockNum; |
| 317 | |
| 318 | if (Buffer == NULL) { // Return the number that will be written with a subsequent call. |
| 319 | BlockNum = ((iCurImage->Width + 3)/4) * ((iCurImage->Height + 3)/4) |
| 320 | * iCurImage->Depth; |
| 321 | |
| 322 | switch (DXTCFormat) |
| 323 | { |
| 324 | case IL_DXT1: |
| 325 | case IL_DXT1A: |
| 326 | case IL_ATI1N: |
| 327 | return BlockNum * 8; |
| 328 | case IL_DXT3: |
| 329 | case IL_DXT5: |
| 330 | case IL_3DC: |
| 331 | case IL_RXGB: |
| 332 | return BlockNum * 16; |
| 333 | default: |
| 334 | ilSetError(IL_FORMAT_NOT_SUPPORTED); |
| 335 | return 0; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (DXTCFormat == iCurImage->DxtcFormat && iCurImage->DxtcSize && iCurImage->DxtcData) { |
| 340 | memcpy(Buffer, iCurImage->DxtcData, IL_MIN(BufferSize, iCurImage->DxtcSize)); |
| 341 | return IL_MIN(BufferSize, iCurImage->DxtcSize); |
| 342 | } |
| 343 | |
| 344 | if (iCurImage->Origin != IL_ORIGIN_UPPER_LEFT) { |
| 345 | CurData = iCurImage->Data; |
| 346 | iCurImage->Data = iGetFlipped(iCurImage); |
| 347 | if (iCurImage->Data == NULL) { |
| 348 | iCurImage->Data = CurData; |
| 349 | return 0; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | //@TODO: Is this the best way to do this? |
| 354 | iSetOutputLump(Buffer, BufferSize); |
| 355 | retVal = Compress(iCurImage, DXTCFormat); |
| 356 | |
| 357 | if (iCurImage->Origin != IL_ORIGIN_UPPER_LEFT) { |
| 358 | ifree(iCurImage->Data); |
| 359 | iCurImage->Data = CurData; |
| 360 | } |
| 361 | |
| 362 | return retVal; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | // Added the next two functions based on Charles Bloom's rant at |
nothing calls this directly
no test coverage detected