PageRenderTime 16ms CodeModel.GetById 6ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llimage/llimagej2c.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 166 lines | 89 code | 25 blank | 52 comment | 0 complexity | a9124e85835bc408f7c6d1fa7866b3a3 MD5 | raw file
  1/** 
  2 * @file llimagej2c.h
  3 * @brief Image implmenation for jpeg2000.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLIMAGEJ2C_H
 28#define LL_LLIMAGEJ2C_H
 29
 30#include "llimage.h"
 31#include "llassettype.h"
 32#include "llmetricperformancetester.h"
 33
 34class LLImageJ2CImpl;
 35class LLImageCompressionTester ;
 36
 37class LLImageJ2C : public LLImageFormatted
 38{
 39protected:
 40	virtual ~LLImageJ2C();
 41
 42public:
 43	LLImageJ2C();
 44
 45	// Base class overrides
 46	/*virtual*/ std::string getExtension() { return std::string("j2c"); }
 47	/*virtual*/ BOOL updateData();
 48	/*virtual*/ BOOL decode(LLImageRaw *raw_imagep, F32 decode_time);
 49	/*virtual*/ BOOL decodeChannels(LLImageRaw *raw_imagep, F32 decode_time, S32 first_channel, S32 max_channel_count);
 50	/*virtual*/ BOOL encode(const LLImageRaw *raw_imagep, F32 encode_time);
 51	/*virtual*/ S32 calcHeaderSize();
 52	/*virtual*/ S32 calcDataSize(S32 discard_level = 0);
 53	/*virtual*/ S32 calcDiscardLevelBytes(S32 bytes);
 54	/*virtual*/ S8  getRawDiscardLevel();
 55	// Override these so that we don't try to set a global variable from a DLL
 56	/*virtual*/ void resetLastError();
 57	/*virtual*/ void setLastError(const std::string& message, const std::string& filename = std::string());
 58	
 59	BOOL initDecode(LLImageRaw &raw_image, int discard_level, int* region);
 60	BOOL initEncode(LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels);
 61	
 62	// Encode with comment text 
 63	BOOL encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time=0.0);
 64
 65	BOOL validate(U8 *data, U32 file_size);
 66	BOOL loadAndValidate(const std::string &filename);
 67
 68	// Encode accessors
 69	void setReversible(const BOOL reversible); // Use non-lossy?
 70	void setRate(F32 rate);
 71	void setMaxBytes(S32 max_bytes);
 72	S32 getMaxBytes() const { return mMaxBytes; }
 73
 74	static S32 calcHeaderSizeJ2C();
 75	static S32 calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 rate = 0.f);
 76
 77	static std::string getEngineInfo();
 78
 79protected:
 80	friend class LLImageJ2CImpl;
 81	friend class LLImageJ2COJ;
 82	friend class LLImageJ2CKDU;
 83	friend class LLImageCompressionTester;
 84	void decodeFailed();
 85	void updateRawDiscardLevel();
 86
 87	S32 mMaxBytes; // Maximum number of bytes of data to use...
 88	
 89	S32 mDataSizes[MAX_DISCARD_LEVEL+1];		// Size of data required to reach a given level
 90	U32 mAreaUsedForDataSizeCalcs;				// Height * width used to calculate mDataSizes
 91
 92	S8  mRawDiscardLevel;
 93	F32 mRate;
 94	BOOL mReversible;
 95	LLImageJ2CImpl *mImpl;
 96	std::string mLastError;
 97
 98    // Image compression/decompression tester
 99	static LLImageCompressionTester* sTesterp;
100};
101
102// Derive from this class to implement JPEG2000 decoding
103class LLImageJ2CImpl
104{
105public:
106	virtual ~LLImageJ2CImpl();
107protected:
108	// Find out the image size and number of channels.
109	// Return value:
110	// true: image size and number of channels was determined
111	// false: error on decode
112	virtual BOOL getMetadata(LLImageJ2C &base) = 0;
113	// Decode the raw image optionally aborting (to continue later) after
114	// decode_time seconds.  Decode at most max_channel_count and start
115	// decoding channel first_channel.
116	// Return value:
117	// true: decoding complete (even if it failed)
118	// false: time expired while decoding
119	virtual BOOL decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count) = 0;
120	virtual BOOL encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time=0.0,
121							BOOL reversible=FALSE) = 0;
122	virtual BOOL initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level = -1, int* region = NULL) = 0;
123	virtual BOOL initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size = -1, int precincts_size = -1, int levels = 0) = 0;
124
125	friend class LLImageJ2C;
126};
127
128#define LINDEN_J2C_COMMENT_PREFIX "LL_"
129
130//
131// This class is used for performance data gathering only.
132// Tracks the image compression / decompression data,
133// records and outputs them to the log file.
134//
135class LLImageCompressionTester : public LLMetricPerformanceTesterBasic
136{
137    public:
138        LLImageCompressionTester();
139        ~LLImageCompressionTester();
140        
141        void updateDecompressionStats(const F32 deltaTime) ;
142        void updateDecompressionStats(const S32 bytesIn, const S32 bytesOut) ;
143        void updateCompressionStats(const F32 deltaTime) ;
144        void updateCompressionStats(const S32 bytesIn, const S32 bytesOut) ;
145    
146    protected:
147        /*virtual*/ void outputTestRecord(LLSD* sd);
148        
149    private:
150        //
151        // Data size
152        //
153        U32 mTotalBytesInDecompression;     // Total bytes fed to decompressor
154        U32 mTotalBytesOutDecompression;    // Total bytes produced by decompressor
155        U32 mTotalBytesInCompression;       // Total bytes fed to compressor
156        U32 mTotalBytesOutCompression;      // Total bytes produced by compressor
157		U32 mRunBytesInDecompression;		// Bytes fed to decompressor in this run
158		U32 mRunBytesInCompression;			// Bytes fed to compressor in this run
159        //
160        // Time
161        //
162        F32 mTotalTimeDecompression;        // Total time spent in computing decompression
163        F32 mTotalTimeCompression;          // Total time spent in computing compression
164    };
165
166#endif