- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-IL/src/il_squish.cpp

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2009 by Denton Woods
    00005 // Last modified: 01/15/2009
    00006 //
    00007 // Filename: src-IL/src/il_squish.cpp
    00008 //
    00009 // Description: Implements access to the Squish library.
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 /*#include "il_dds.h"
    00016 #include "il_manip.h"
    00017 #include <limits.h>*/
    00018
    00019
    00020 #ifdef IL_USE_DXTC_SQUISH
    00021 #include <squish.h>
    00022
    00023 #if defined(_WIN32) && defined(IL_USE_PRAGMA_LIBS)
    00024         #if defined(_MSC_VER) || defined(__BORLANDC__)
    00025                 #ifndef _DEBUG
    00026                         #pragma comment(lib, "squish.lib")
    00027                 #else
    00028                         #pragma comment(lib, "squish-d.lib")
    00029                 #endif
    00030         #endif
    00031 #endif
    00032
    00033
    00035 //  The data must be in unsigned byte RGBA format.  The alpha channel will be ignored if DxtType is IL_DXT1.
    00036 //  DxtSize is used to return the size in bytes of the DXTC data returned.
    00037 ILAPI ILubyte* ILAPIENTRY ilSquishCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILuint Depth, ILenum DxtFormat, ILuint *DxtSize)
    00038 {
    00039         ILuint  Size;  //@TODO: Support larger than 32-bit data?
    00040         ILint   Flags;
    00041         ILubyte *DxtcData;
    00042
    00043         if (Data == NULL) {  // We cannot operate on a null pointer.
    00044                 ilSetError(IL_INVALID_PARAM);
    00045                 return NULL;
    00046         }
    00047
    00048         // The nVidia Texture Tools library does not support volume textures yet.
    00049         if (Depth != 1) {
    00050                 ilSetError(IL_INVALID_PARAM);
    00051                 return NULL;
    00052         }
    00053
    00054         switch (DxtFormat)
    00055         {
    00056                 case IL_DXT1:  // Should these two be
    00057                 case IL_DXT1A: //  any different?
    00058                         Flags = squish::kDxt1;
    00059                         break;
    00060                 case IL_DXT3:
    00061                         Flags = squish::kDxt3;
    00062                         break;
    00063                 case IL_DXT5:
    00064                         Flags = squish::kDxt5;
    00065                         break;
    00066                 default:  // Does not support DXT2 or DXT4.
    00067                         ilSetError(IL_INVALID_PARAM);
    00068                         break;
    00069         }
    00070
    00071         Size = squish::GetStorageRequirements(Width, Height, Flags);
    00072         DxtcData = (ILubyte*)ialloc(Size);
    00073         if (DxtcData == NULL)
    00074                 return NULL;
    00075
    00076         squish::CompressImage(Data, Width, Height, DxtcData, Flags);
    00077
    00078         *DxtSize = Size;
    00079         return DxtcData;
    00080 }
    00081
    00082 #endif//IL_NO_DXTC_SQUISH