Beispiel #1
0
LLImageRaw::LLImageRaw(U16 width, U16 height, S8 components)
	: LLImageBase()
{
	//llassert( S32(width) * S32(height) * S32(components) <= MAX_IMAGE_DATA_SIZE );
	allocateDataSize(width, height, components);
	++sRawImageCount;
}
LLImageRaw::LLImageRaw(U16 width, U16 height, S8 components)
	: LLImageBase(), mCacheEntries(0)
{
	mMemType = LLMemType::MTYPE_IMAGERAW;
	llassert( S32(width) * S32(height) * S32(components) <= MAX_IMAGE_DATA_SIZE );
	allocateDataSize(width, height, components);
	++sRawImageCount;
}
Beispiel #3
0
LLImageRaw::LLImageRaw(U8 *data, U16 width, U16 height, S8 components)
	: LLImageBase()
{
	mMemType = LLMemType::MTYPE_IMAGERAW;
	if(allocateDataSize(width, height, components))
	{
		memcpy(getData(), data, width*height*components);
	}
	++sRawImageCount;
}
Beispiel #4
0
BOOL LLImageRaw::resize(U16 width, U16 height, S8 components)
{
	if ((getWidth() == width) && (getHeight() == height) && (getComponents() == components))
	{
		return TRUE;
	}
	// Reallocate the data buffer.
	deleteData();

	allocateDataSize(width,height,components);

	return TRUE;
}
Beispiel #5
0
LLImageRaw::LLImageRaw(U8 *data, U16 width, U16 height, S8 components, bool no_copy)
	: LLImageBase()
{
	if(no_copy)
	{
		setDataAndSize(data, width, height, components);
	}
	else if(allocateDataSize(width, height, components))
	{
		memcpy(getData(), data, width*height*components);
	}
	++sRawImageCount;
}
Beispiel #6
0
BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data )
{
	llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) );

	S32 old_width = getWidth();
	S32 old_height = getHeight();
	
	if( (old_width == new_width) && (old_height == new_height) )
	{
		return TRUE;  // Nothing to do.
	}

	// Reallocate the data buffer.

	if (scale_image_data)
	{
		S32 temp_data_size = old_width * new_height * getComponents();
		llassert_always(temp_data_size > 0);
		std::vector<U8> temp_buffer(temp_data_size);

		// Vertical
		for( S32 col = 0; col < old_width; col++ )
		{
			copyLineScaled( getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), old_height, new_height, old_width, old_width );
		}

		deleteData();

		U8* new_buffer = allocateDataSize(new_width, new_height, getComponents());

		// <FS:ND> Handle out of memory situations a bit more graceful than a crash
		if( !new_buffer )
			return FALSE;
		// </FS:ND>

		// Horizontal
		for( S32 row = 0; row < new_height; row++ )
		{
			copyLineScaled( &temp_buffer[0] + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 );
		}
	}
	else
	{
		// copy	out	existing image data
		S32	temp_data_size = old_width * old_height	* getComponents();
		std::vector<U8> temp_buffer(temp_data_size);
		memcpy(&temp_buffer[0],	getData(), temp_data_size);

		// allocate	new	image data,	will delete	old	data
		U8*	new_buffer = allocateDataSize(new_width, new_height, getComponents());

		// <FS:ND> Handle out of memory situations a bit more graceful than a crash
		if( !new_buffer )
			return FALSE;
		// </FS:ND>

		for( S32 row = 0; row <	new_height;	row++ )
		{
			if (row	< old_height)
			{
				memcpy(new_buffer +	(new_width * row * getComponents()), &temp_buffer[0] + (old_width *	row	* getComponents()),	getComponents()	* llmin(old_width, new_width));
				if (old_width <	new_width)
				{
					// pad out rest	of row with	black
					memset(new_buffer +	(getComponents() * ((new_width * row) +	old_width)), 0,	getComponents()	* (new_width - old_width));
				}
			}
			else
			{
				// pad remaining rows with black
				memset(new_buffer +	(new_width * row * getComponents()), 0,	new_width *	getComponents());
			}
		}
	}

	return TRUE ;
}
Beispiel #7
0
BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data )
{
	LLMemType mt1((LLMemType::EMemType)mMemType);
	llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) );

	S32 old_width = getWidth();
	S32 old_height = getHeight();
	
	if( (old_width == new_width) && (old_height == new_height) )
	{
		return TRUE;  // Nothing to do.
	}

	// Reallocate the data buffer.

	if (scale_image_data)
	{
		// Vertical
		S32 temp_data_size = old_width * new_height * getComponents();
		llassert_always(temp_data_size > 0);
		U8* temp_buffer = new U8[ temp_data_size ];
		for( S32 col = 0; col < old_width; col++ )
		{
			copyLineScaled( getData() + (getComponents() * col), temp_buffer + (getComponents() * col), old_height, new_height, old_width, old_width );
		}

		deleteData();

		U8* new_buffer = allocateDataSize(new_width, new_height, getComponents());

		// Horizontal
		for( S32 row = 0; row < new_height; row++ )
		{
			copyLineScaled( temp_buffer + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 );
		}

		// Clean up
		delete[] temp_buffer;
	}
	else
	{
		// copy	out	existing image data
		S32	temp_data_size = old_width * old_height	* getComponents();
		U8*	temp_buffer	= new U8[ temp_data_size ];
		if (!temp_buffer)
		{
			llwarns << "Out of memory in LLImageRaw::scale: old (w, h, c) = (" << old_width << ", " << old_height << ", " << (S32)getComponents() << 
				") ; new (w, h, c) = (" << new_width << ", " << new_height << ", " << (S32)getComponents() << ")" << llendl;			

			return FALSE ;
		}
		memcpy(temp_buffer,	getData(), temp_data_size);	/* Flawfinder: ignore */

		// allocate	new	image data,	will delete	old	data
		U8*	new_buffer = allocateDataSize(new_width, new_height, getComponents());

		for( S32 row = 0; row <	new_height;	row++ )
		{
			if (row	< old_height)
			{
				memcpy(new_buffer +	(new_width * row * getComponents()), temp_buffer + (old_width *	row	* getComponents()),	getComponents()	* llmin(old_width, new_width));	/* Flawfinder: ignore */
				if (old_width <	new_width)
				{
					// pad out rest	of row with	black
					memset(new_buffer +	(getComponents() * ((new_width * row) +	old_width)), 0,	getComponents()	* (new_width - old_width));
				}
			}
			else
			{
				// pad remaining rows with black
				memset(new_buffer +	(new_width * row * getComponents()), 0,	new_width *	getComponents());
			}
		}

		// Clean up
		delete[] temp_buffer;
	}

	return TRUE ;
}