PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llimage/llpngwrapper.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 96 lines | 53 code | 17 blank | 26 comment | 0 complexity | 4ea6d99b502a6ced25e23af00d6f8277 MD5 | raw file
 1/*
 2 * @file llpngwrapper.h
 3 *
 4 * $LicenseInfo:firstyear=2007&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_LLPNGWRAPPER_H
27#define LL_LLPNGWRAPPER_H
28
29#include "png.h"
30#include "llimage.h"
31
32class LLPngWrapper
33{
34public:
35	LLPngWrapper();
36	virtual ~LLPngWrapper();
37
38public:
39	struct ImageInfo
40	{
41		U16 mWidth;
42		U16 mHeight;
43		S8  mComponents;
44	};
45
46	BOOL isValidPng(U8* src);
47	BOOL readPng(U8* src, LLImageRaw* rawImage, ImageInfo *infop = NULL);
48	BOOL writePng(const LLImageRaw* rawImage, U8* dst);
49	U32  getFinalSize();
50	const std::string& getErrorMessage();
51
52protected:
53	void normalizeImage();
54	void updateMetaData();
55
56private:
57
58	// Structure for writing/reading PNG data to/from memory
59	// as opposed to using a file.
60	struct PngDataInfo
61	{
62		U8 *mData;
63		U32 mOffset;
64	};
65
66	static void writeFlush(png_structp png_ptr);
67	static void errorHandler(png_structp png_ptr, png_const_charp msg);
68	static void readDataCallback(png_structp png_ptr, png_bytep dest, png_size_t length);
69	static void writeDataCallback(png_structp png_ptr, png_bytep src, png_size_t length);
70
71	void releaseResources();
72
73	png_structp mReadPngPtr;
74	png_infop mReadInfoPtr;
75	png_structp mWritePngPtr;
76	png_infop mWriteInfoPtr;
77
78	U8 **mRowPointers;
79
80	png_uint_32 mWidth;
81	png_uint_32 mHeight;
82	S32 mBitDepth;
83	S32 mColorType;
84	S32 mChannels;
85	S32 mInterlaceType;
86	S32 mCompressionType;
87	S32 mFilterMethod;
88
89	U32 mFinalSize;
90
91	F64 mGamma;
92
93	std::string mErrorMessage;
94};
95
96#endif