PageRenderTime 318ms CodeModel.GetById 112ms app.highlight 8ms RepoModel.GetById 195ms app.codeStats 1ms

/indra/llimage/llimagedimensionsinfo.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 136 lines | 85 code | 21 blank | 30 comment | 1 complexity | 5c00898b9d606f4c03a60698d9c822ef MD5 | raw file
  1/** 
  2 * @file llimagedimentionsinfo.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
 27#ifndef LL_LLIMAGEDIMENSIONSINFO_H
 28#define LL_LLIMAGEDIMENSIONSINFO_H
 29
 30//-----------------------------------------------------------------------------
 31// LLImageDimensionsInfo
 32// helper class to get image dimensions WITHOUT loading image to memore
 33// usefull when image may be too large...
 34//-----------------------------------------------------------------------------
 35class LLImageDimensionsInfo
 36{
 37public:
 38	LLImageDimensionsInfo():
 39		mData(NULL)
 40		,mHeight(0)
 41		,mWidth(0)
 42	{}
 43	~LLImageDimensionsInfo()
 44	{
 45		clean();
 46	}
 47
 48	bool load(const std::string& src_filename,U32 codec);
 49	S32 getWidth() const { return mWidth;}
 50	S32 getHeight() const { return mHeight;}
 51
 52	const std::string& getLastError()
 53	{
 54		return mLastError;
 55	}
 56protected:
 57
 58	void clean()
 59	{
 60		mInfile.close();
 61		delete[] mData;
 62		mData = NULL;
 63		mWidth = 0;
 64		mHeight = 0;
 65	}
 66
 67	U8* getData()
 68	{
 69		return mData;
 70	}
 71
 72
 73	void setLastError(const std::string& message, const std::string& filename)
 74	{
 75		std::string error = message;
 76		if (!filename.empty())
 77			error += std::string(" FILE: ") + filename;
 78		mLastError = error;
 79	}
 80
 81
 82	bool getImageDimensionsBmp();
 83	bool getImageDimensionsTga();
 84	bool getImageDimensionsPng();
 85	bool getImageDimensionsJpeg();
 86	
 87	S32 read_s32()
 88	{
 89		char p[4];
 90		mInfile.read(&p[0],4);
 91		S32 temp =	(((S32)p[3])       & 0x000000FF) |
 92					(((S32)p[2] << 8 ) & 0x0000FF00) |
 93					(((S32)p[1] << 16) & 0x00FF0000) |
 94					(((S32)p[0] << 24) & 0xFF000000);
 95
 96		return temp;
 97	}
 98	S32 read_reverse_s32()
 99	{
100		char p[4];
101		mInfile.read(&p[0],4);
102		S32 temp =	(((S32)p[0])       & 0x000000FF) |
103					(((S32)p[1] << 8 ) & 0x0000FF00) |
104					(((S32)p[2] << 16) & 0x00FF0000) |
105					(((S32)p[3] << 24) & 0xFF000000);
106
107		return temp;
108	}
109
110	U8 read_byte()
111	{
112		U8 bt;
113		mInfile.read(&bt,1);
114		return bt;
115	}
116
117	U16 read_short()
118	{
119		return read_byte() << 8 | read_byte();
120	}
121
122	/// Check if the file is not shorter than min_len bytes.
123	bool checkFileLength(S32 min_len);
124
125protected:
126	LLAPRFile mInfile ;
127	std::string mSrcFilename;
128
129	std::string mLastError;
130
131	U8* mData;
132
133	S32 mWidth;
134	S32 mHeight;
135};
136#endif