summaryrefslogtreecommitdiff
path: root/indra/llimage/llimagetga.h
blob: b1f34dcdaddf1f90e974fe6d3579021f49d02afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/** 
 * @file llimagetga.h
 * @brief Image implementation to compresses and decompressed TGA files.
 *
 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#ifndef LL_LLIMAGETGA_H
#define LL_LLIMAGETGA_H

#include "llimage.h"

// This class compresses and decompressed TGA (targa) files

class LLImageTGA : public LLImageFormatted
{
protected:
	virtual ~LLImageTGA();
	
public:
	LLImageTGA();
	LLImageTGA(const std::string& file_name);

	/*virtual*/ std::string getExtension() { return std::string("tga"); }
	/*virtual*/ bool updateData();
	/*virtual*/ bool decode(LLImageRaw* raw_image, F32 decode_time=0.0);
	/*virtual*/ bool encode(const LLImageRaw* raw_image, F32 encode_time=0.0);

	bool			 decodeAndProcess(LLImageRaw* raw_image, F32 domain, F32 weight);
	
private:
	bool			 decodeTruecolor( LLImageRaw* raw_image, bool rle, bool flipped );

	bool			 decodeTruecolorRle8( LLImageRaw* raw_image );
	bool			 decodeTruecolorRle15( LLImageRaw* raw_image );
	bool			 decodeTruecolorRle24( LLImageRaw* raw_image );
	bool			 decodeTruecolorRle32( LLImageRaw* raw_image, bool &alpha_opaque );

	void			 decodeTruecolorPixel15( U8* dst, const U8* src );

	bool			 decodeTruecolorNonRle( LLImageRaw* raw_image, bool &alpha_opaque );
	
	bool			 decodeColorMap( LLImageRaw* raw_image, bool rle, bool flipped );

	void			 decodeColorMapPixel8(U8* dst, const U8* src);
	void			 decodeColorMapPixel15(U8* dst, const U8* src);
	void			 decodeColorMapPixel24(U8* dst, const U8* src);
	void			 decodeColorMapPixel32(U8* dst, const U8* src);

	bool			 loadFile(const std::string& file_name);
	
private:
	// Class specific data
	U32 mDataOffset; // Offset from start of data to the actual header.

	// Data from header
	U8 mIDLength;		// Length of identifier string
	U8 mColorMapType;	// 0 = No Map
	U8 mImageType;		// Supported: 2 = Uncompressed true color, 3 = uncompressed monochrome without colormap
	U8 mColorMapIndexLo;	// First color map entry (low order byte)
	U8 mColorMapIndexHi;	// First color map entry (high order byte)
	U8 mColorMapLengthLo;	// Color map length (low order byte)
	U8 mColorMapLengthHi;	// Color map length (high order byte)
	U8 mColorMapDepth;	// Size of color map entry (15, 16, 24, or 32 bits)
	U8 mXOffsetLo;		// X offset of image (low order byte)
	U8 mXOffsetHi;		// X offset of image (hi order byte)
	U8 mYOffsetLo;		// Y offset of image (low order byte)
	U8 mYOffsetHi;		// Y offset of image (hi order byte)
	U8 mWidthLo;		// Width (low order byte)
	U8 mWidthHi;		// Width (hi order byte)
	U8 mHeightLo;		// Height (low order byte)
	U8 mHeightHi;		// Height (hi order byte)
	U8 mPixelSize;		// 8, 16, 24, 32 bits per pixel
	U8 mAttributeBits;	// 4 bits: number of attributes per pixel
	U8 mOriginRightBit;	// 1 bit: origin, 0 = left, 1 = right
	U8 mOriginTopBit;	// 1 bit: origin, 0 = bottom, 1 = top
	U8 mInterleave;		// 2 bits: interleaved flag, 0 = none, 1 = interleaved 2, 2 = interleaved 4

	U8*		mColorMap;
	S32		mColorMapStart;
	S32		mColorMapLength; 
	S32		mColorMapBytesPerEntry;

	bool	mIs15Bit;

	static const U8 s5to8bits[32];
};

#endif