PageRenderTime 364ms CodeModel.GetById 191ms app.highlight 8ms RepoModel.GetById 163ms app.codeStats 0ms

/indra/llkdu/llkdumem.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 145 lines | 102 code | 17 blank | 26 comment | 2 complexity | 79d48c2253e16f3f591660e6b167c054 MD5 | raw file
  1/** 
  2 * @file llkdumem.h
  3 * @brief Helper class for kdu memory management
  4 *
  5 * $LicenseInfo:firstyear=2010&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_LLKDUMEM_H
 28#define LL_LLKDUMEM_H
 29
 30// Support classes for reading and writing from memory buffers in KDU
 31#include "kdu_image.h"
 32#include "kdu_elementary.h"
 33#include "kdu_messaging.h"
 34#include "kdu_params.h"
 35#include "kdu_compressed.h"
 36#include "kdu_sample_processing.h"
 37#include "image_local.h"
 38#include "stdtypes.h"
 39
 40class LLKDUMemSource: public kdu_compressed_source
 41{
 42public:
 43	LLKDUMemSource(U8 *input_buffer, U32 size)
 44	{
 45		mData = input_buffer;
 46		mSize = size;
 47		mCurPos = 0;
 48	}
 49
 50	~LLKDUMemSource()
 51	{
 52	}
 53
 54	int read(kdu_byte *buf, int num_bytes)
 55	{
 56		U32 num_out;
 57		num_out = num_bytes;
 58
 59		if ((mSize - mCurPos) < (U32)num_bytes)
 60		{
 61			num_out = mSize -mCurPos;
 62		}
 63		memcpy(buf, mData + mCurPos, num_out);
 64		mCurPos += num_out;
 65		return num_out;
 66	}
 67
 68	void reset()
 69	{
 70		mCurPos = 0;
 71	}
 72
 73private:
 74	U8 *mData;
 75	U32 mSize;
 76	U32 mCurPos;
 77};
 78
 79class LLKDUMemTarget: public kdu_compressed_target
 80{
 81public:
 82	LLKDUMemTarget(U8 *output_buffer, U32 &output_size, const U32 buffer_size)
 83	{
 84		mData = output_buffer;
 85		mSize = buffer_size;
 86		mCurPos = 0;
 87		mOutputSize = &output_size;
 88	}
 89
 90	~LLKDUMemTarget()
 91	{
 92	}
 93
 94	bool write(const kdu_byte *buf, int num_bytes)
 95	{
 96		U32 num_out;
 97		num_out = num_bytes;
 98
 99		if ((mSize - mCurPos) < (U32)num_bytes)
100		{
101			num_out = mSize - mCurPos;
102			memcpy(mData + mCurPos, buf, num_out);
103			return false;
104		}
105		memcpy(mData + mCurPos, buf, num_out);
106		mCurPos += num_out;
107		*mOutputSize = mCurPos;
108		return true;
109	}
110	
111private:
112	U8 *mData;
113	U32 mSize;
114	U32 mCurPos;
115	U32 *mOutputSize;
116};
117
118class LLKDUMemIn : public kdu_image_in_base
119{
120public:
121	LLKDUMemIn(const U8 *data,
122				const U32 size,
123				const U16 rows,
124				const U16 cols,
125				U8 in_num_components,
126				siz_params *siz);
127	~LLKDUMemIn();
128
129	bool get(int comp_idx, kdu_line_buf &line, int x_tnum);
130
131private:
132	const U8 *mData;
133	int first_comp_idx;
134	int num_components;
135	int rows, cols;
136	int alignment_bytes; // Number of 0's at end of each line.
137	int precision[3];
138	image_line_buf *incomplete_lines; // Each "sample" represents a full pixel
139	image_line_buf *free_lines;
140	int num_unread_rows;
141
142	U32 mCurPos;
143	U32 mDataSize;
144};
145#endif