aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llimage/llimagedxt.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llimage/llimagedxt.h')
-rw-r--r--linden/indra/llimage/llimagedxt.h139
1 files changed, 139 insertions, 0 deletions
diff --git a/linden/indra/llimage/llimagedxt.h b/linden/indra/llimage/llimagedxt.h
new file mode 100644
index 0000000..c3c01c1
--- /dev/null
+++ b/linden/indra/llimage/llimagedxt.h
@@ -0,0 +1,139 @@
1/**
2 * @file llimagedxt.h
3 *
4 * Copyright (c) 2001-2007, Linden Research, Inc.
5 *
6 * The source code in this file ("Source Code") is provided by Linden Lab
7 * to you under the terms of the GNU General Public License, version 2.0
8 * ("GPL"), unless you have obtained a separate licensing agreement
9 * ("Other License"), formally executed by you and Linden Lab. Terms of
10 * the GPL can be found in doc/GPL-license.txt in this distribution, or
11 * online at http://secondlife.com/developers/opensource/gplv2
12 *
13 * There are special exceptions to the terms and conditions of the GPL as
14 * it is applied to this Source Code. View the full text of the exception
15 * in the file doc/FLOSS-exception.txt in this software distribution, or
16 * online at http://secondlife.com/developers/opensource/flossexception
17 *
18 * By copying, modifying or distributing this software, you acknowledge
19 * that you have read and understood your obligations described above,
20 * and agree to abide by those obligations.
21 *
22 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
23 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
24 * COMPLETENESS OR PERFORMANCE.
25 */
26
27#ifndef LL_LLIMAGEDXT_H
28#define LL_LLIMAGEDXT_H
29
30#include "llimage.h"
31
32// This class decodes and encodes LL DXT files (which may unclude uncompressed RGB or RGBA mipped data)
33
34class LLImageDXT : public LLImageFormatted
35{
36public:
37 enum EFileFormat
38 {
39 FORMAT_UNKNOWN = 0,
40 FORMAT_I8 = 1,
41 FORMAT_A8,
42 FORMAT_RGB8,
43 FORMAT_RGBA8,
44 FORMAT_DXT1,
45 FORMAT_DXT2,
46 FORMAT_DXT3,
47 FORMAT_DXT4,
48 FORMAT_DXT5,
49 FORMAT_DXR1,
50 FORMAT_DXR2,
51 FORMAT_DXR3,
52 FORMAT_DXR4,
53 FORMAT_DXR5,
54 FORMAT_NOFILE = 0xff,
55 };
56
57 struct dxtfile_header_old_t
58 {
59 S32 format;
60 S32 maxlevel;
61 S32 maxwidth;
62 S32 maxheight;
63 };
64
65 struct dxtfile_header_t
66 {
67 S32 fourcc;
68 // begin DDSURFACEDESC2 struct
69 S32 header_size; // size of the header
70 S32 flags; // flags - unused
71 S32 maxheight;
72 S32 maxwidth;
73 S32 image_size; // size of the compressed image
74 S32 depth;
75 S32 num_mips;
76 S32 reserved[11];
77 struct pixel_format
78 {
79 S32 struct_size; // size of this structure
80 S32 flags;
81 S32 fourcc;
82 S32 bit_count;
83 S32 r_mask;
84 S32 g_mask;
85 S32 b_mask;
86 S32 a_mask;
87 } pixel_fmt;
88 S32 caps[4];
89 S32 reserved2;
90 };
91
92protected:
93 /*virtual*/ ~LLImageDXT();
94
95public:
96 LLImageDXT();
97
98 /*virtual*/ BOOL updateData();
99
100 /*virtual*/ BOOL decode(LLImageRaw* raw_image, F32 time=0.0);
101 BOOL encode(const LLImageRaw* raw_image, F32 time, bool explicit_mips);
102 /*virtual*/ BOOL encode(const LLImageRaw* raw_image, F32 time=0.0);
103
104 /*virtual*/ BOOL requestDecodedData(LLPointer<LLImageRaw>& raw, S32 discard=-1, F32 decode_time=0.0);
105 /*virtual*/ void releaseDecodedData();
106
107 /*virtual*/ S32 calcHeaderSize();
108 /*virtual*/ S32 calcDataSize(S32 discard_level = 0);
109
110 void setFormat();
111 S32 getMipOffset(S32 discard);
112
113 EFileFormat getFileFormat() { return mFileFormat; }
114 bool isCompressed() { return (mFileFormat >= FORMAT_DXT1 && mFileFormat <= FORMAT_DXR5); }
115
116 bool convertToDXR(); // convert from DXT to DXR
117
118 static void checkMinWidthHeight(EFileFormat format, S32& width, S32& height);
119 static S32 formatBits(EFileFormat format);
120 static S32 formatBytes(EFileFormat format, S32 width, S32 height);
121 static S32 formatOffset(EFileFormat format, S32 width, S32 height, S32 max_width, S32 max_height);
122 static S32 formatComponents(EFileFormat format);
123
124 static EFileFormat getFormat(S32 fourcc);
125 static S32 getFourCC(EFileFormat format);
126
127 static void calcDiscardWidthHeight(S32 discard_level, EFileFormat format, S32& width, S32& height);
128 static S32 calcNumMips(S32 width, S32 height);
129
130private:
131 static void extractMip(const U8 *indata, U8* mipdata, int width, int height,
132 int mip_width, int mip_height, EFileFormat format);
133
134private:
135 EFileFormat mFileFormat;
136 S32 mHeaderSize;
137};
138
139#endif