00001
00031 #ifndef LL_LLIMAGEDXT_H
00032 #define LL_LLIMAGEDXT_H
00033
00034 #include "llimage.h"
00035
00036
00037
00038 class LLImageDXT : public LLImageFormatted
00039 {
00040 public:
00041 enum EFileFormat
00042 {
00043 FORMAT_UNKNOWN = 0,
00044 FORMAT_I8 = 1,
00045 FORMAT_A8,
00046 FORMAT_RGB8,
00047 FORMAT_RGBA8,
00048 FORMAT_DXT1,
00049 FORMAT_DXT2,
00050 FORMAT_DXT3,
00051 FORMAT_DXT4,
00052 FORMAT_DXT5,
00053 FORMAT_DXR1,
00054 FORMAT_DXR2,
00055 FORMAT_DXR3,
00056 FORMAT_DXR4,
00057 FORMAT_DXR5,
00058 FORMAT_NOFILE = 0xff,
00059 };
00060
00061 struct dxtfile_header_old_t
00062 {
00063 S32 format;
00064 S32 maxlevel;
00065 S32 maxwidth;
00066 S32 maxheight;
00067 };
00068
00069 struct dxtfile_header_t
00070 {
00071 S32 fourcc;
00072
00073 S32 header_size;
00074 S32 flags;
00075 S32 maxheight;
00076 S32 maxwidth;
00077 S32 image_size;
00078 S32 depth;
00079 S32 num_mips;
00080 S32 reserved[11];
00081 struct pixel_format
00082 {
00083 S32 struct_size;
00084 S32 flags;
00085 S32 fourcc;
00086 S32 bit_count;
00087 S32 r_mask;
00088 S32 g_mask;
00089 S32 b_mask;
00090 S32 a_mask;
00091 } pixel_fmt;
00092 S32 caps[4];
00093 S32 reserved2;
00094 };
00095
00096 protected:
00097 ~LLImageDXT();
00098
00099 private:
00100 BOOL encodeDXT(const LLImageRaw* raw_image, F32 decode_time, bool explicit_mips);
00101
00102 public:
00103 LLImageDXT();
00104
00105 BOOL updateData();
00106
00107 BOOL decode(LLImageRaw* raw_image, F32 decode_time);
00108 BOOL encode(const LLImageRaw* raw_image, F32 encode_time);
00109
00110 S32 calcHeaderSize();
00111 S32 calcDataSize(S32 discard_level = 0);
00112
00113 BOOL getMipData(LLPointer<LLImageRaw>& raw, S32 discard=-1);
00114
00115 void setFormat();
00116 S32 getMipOffset(S32 discard);
00117
00118 EFileFormat getFileFormat() { return mFileFormat; }
00119 bool isCompressed() { return (mFileFormat >= FORMAT_DXT1 && mFileFormat <= FORMAT_DXR5); }
00120
00121 bool convertToDXR();
00122
00123 static void checkMinWidthHeight(EFileFormat format, S32& width, S32& height);
00124 static S32 formatBits(EFileFormat format);
00125 static S32 formatBytes(EFileFormat format, S32 width, S32 height);
00126 static S32 formatOffset(EFileFormat format, S32 width, S32 height, S32 max_width, S32 max_height);
00127 static S32 formatComponents(EFileFormat format);
00128
00129 static EFileFormat getFormat(S32 fourcc);
00130 static S32 getFourCC(EFileFormat format);
00131
00132 static void calcDiscardWidthHeight(S32 discard_level, EFileFormat format, S32& width, S32& height);
00133 static S32 calcNumMips(S32 width, S32 height);
00134
00135 private:
00136 static void extractMip(const U8 *indata, U8* mipdata, int width, int height,
00137 int mip_width, int mip_height, EFileFormat format);
00138
00139 private:
00140 EFileFormat mFileFormat;
00141 S32 mHeaderSize;
00142 };
00143
00144 #endif