PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llimage/llimagedxt.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 141 lines | 93 code | 22 blank | 26 comment | 1 complexity | e65db01d8c5dbb874bdf4de64c98af71 MD5 | raw file
  1/** 
  2 * @file llimagedxt.h
  3 *
  4 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2010, Linden Research, Inc.
  7 * 
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation;
 11 * version 2.1 of the License only.
 12 * 
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16 * Lesser General Public License for more details.
 17 * 
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21 * 
 22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23 * $/LicenseInfo$
 24 */
 25
 26#ifndef LL_LLIMAGEDXT_H
 27#define LL_LLIMAGEDXT_H
 28
 29#include "llimage.h"
 30#include "llpointer.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
 95private:
 96	BOOL encodeDXT(const LLImageRaw* raw_image, F32 decode_time, bool explicit_mips);
 97	
 98public:
 99	LLImageDXT();
100
101	/*virtual*/ std::string getExtension() { return std::string("dxt"); }
102	/*virtual*/ BOOL updateData();
103
104	/*virtual*/ BOOL decode(LLImageRaw* raw_image, F32 decode_time);
105	/*virtual*/ BOOL encode(const LLImageRaw* raw_image, F32 encode_time);
106
107	/*virtual*/ S32 calcHeaderSize();
108	/*virtual*/ S32 calcDataSize(S32 discard_level = 0);
109
110	BOOL getMipData(LLPointer<LLImageRaw>& raw, S32 discard=-1);
111	
112	void setFormat();
113	S32 getMipOffset(S32 discard);
114	
115	EFileFormat getFileFormat() { return mFileFormat; }
116	bool isCompressed() { return (mFileFormat >= FORMAT_DXT1 && mFileFormat <= FORMAT_DXR5); }
117
118	bool convertToDXR(); // convert from DXT to DXR
119	
120	static void checkMinWidthHeight(EFileFormat format, S32& width, S32& height);
121	static S32 formatBits(EFileFormat format);
122	static S32 formatBytes(EFileFormat format, S32 width, S32 height);
123	static S32 formatOffset(EFileFormat format, S32 width, S32 height, S32 max_width, S32 max_height);
124	static S32 formatComponents(EFileFormat format);
125	
126	static EFileFormat getFormat(S32 fourcc);
127	static S32 getFourCC(EFileFormat format);
128
129	static void calcDiscardWidthHeight(S32 discard_level, EFileFormat format, S32& width, S32& height);
130	static S32 calcNumMips(S32 width, S32 height);
131
132private:
133	static void extractMip(const U8 *indata, U8* mipdata, int width, int height,
134						   int mip_width, int mip_height, EFileFormat format);
135	
136private:
137	EFileFormat mFileFormat;
138	S32 mHeaderSize;
139};
140
141#endif