llimagedxt.h

Go to the documentation of this file.
00001 
00031 #ifndef LL_LLIMAGEDXT_H
00032 #define LL_LLIMAGEDXT_H
00033 
00034 #include "llimage.h"
00035 
00036 // This class decodes and encodes LL DXT files (which may unclude uncompressed RGB or RGBA mipped data)
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                 // begin DDSURFACEDESC2 struct
00073                 S32 header_size; // size of the header
00074                 S32 flags; // flags - unused
00075                 S32 maxheight;
00076                 S32 maxwidth;
00077                 S32 image_size; // size of the compressed image
00078                 S32 depth;
00079                 S32 num_mips;
00080                 S32 reserved[11];
00081                 struct pixel_format
00082                 {
00083                         S32 struct_size; // size of this structure
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         /*virtual*/ ~LLImageDXT();
00098         
00099 public:
00100         LLImageDXT();
00101 
00102         /*virtual*/ BOOL updateData();
00103 
00104         /*virtual*/ BOOL decode(LLImageRaw* raw_image, F32 time=0.0);
00105                                 BOOL encode(const LLImageRaw* raw_image, F32 time, bool explicit_mips);
00106         /*virtual*/ BOOL encode(const LLImageRaw* raw_image, F32 time=0.0);
00107 
00108         /*virtual*/ S32 calcHeaderSize();
00109         /*virtual*/ S32 calcDataSize(S32 discard_level = 0);
00110 
00111         BOOL getMipData(LLPointer<LLImageRaw>& raw, S32 discard=-1);
00112         
00113         void setFormat();
00114         S32 getMipOffset(S32 discard);
00115         
00116         EFileFormat getFileFormat() { return mFileFormat; }
00117         bool isCompressed() { return (mFileFormat >= FORMAT_DXT1 && mFileFormat <= FORMAT_DXR5); }
00118 
00119         bool convertToDXR(); // convert from DXT to DXR
00120         
00121         static void checkMinWidthHeight(EFileFormat format, S32& width, S32& height);
00122         static S32 formatBits(EFileFormat format);
00123         static S32 formatBytes(EFileFormat format, S32 width, S32 height);
00124         static S32 formatOffset(EFileFormat format, S32 width, S32 height, S32 max_width, S32 max_height);
00125         static S32 formatComponents(EFileFormat format);
00126         
00127         static EFileFormat getFormat(S32 fourcc);
00128         static S32 getFourCC(EFileFormat format);
00129 
00130         static void calcDiscardWidthHeight(S32 discard_level, EFileFormat format, S32& width, S32& height);
00131         static S32 calcNumMips(S32 width, S32 height);
00132 
00133 private:
00134         static void extractMip(const U8 *indata, U8* mipdata, int width, int height,
00135                                                    int mip_width, int mip_height, EFileFormat format);
00136         
00137 private:
00138         EFileFormat mFileFormat;
00139         S32 mHeaderSize;
00140 };
00141 
00142 #endif

Generated on Thu Jul 1 06:08:43 2010 for Second Life Viewer by  doxygen 1.4.7