Ejemplo n.º 1
0
// static
void D3D11Utils_Texture::copyImageToTexture( const Image4f& im, std::shared_ptr< DynamicTexture2D > tex, bool flipUD )
{
	int width = im.width();
	int height = im.height();

	D3D11_MAPPED_SUBRESOURCE mapping = tex->mapForWriteDiscard();

	const float* sourceData = im.pixels();
	ubyte* destDataBytes = reinterpret_cast< ubyte* >( mapping.pData );

	// if the pitch matches and no flip is requested
	// then just directly copy
	if( mapping.RowPitch == 4 * width * sizeof( float ) && !flipUD )
	{
		float* destDataFloat = reinterpret_cast< float* >( mapping.pData );
		memcpy( destDataFloat, sourceData, 4 * width * height * sizeof( float ) );
	}
	// otherwise, have to go row by row
	else
	{
		for( int y = 0; y < height; ++y )
		{
			int yy = flipUD ? height - y - 1 : y;

			const float* sourceRow = &( sourceData[ 4 * yy * width ] );
			ubyte* destRow = &( destDataBytes[ y * mapping.RowPitch ] );

			memcpy( destRow, sourceRow, 4 * width * sizeof( float ) );
		}
	}

	tex->unmap();
}
Ejemplo n.º 2
0
// static
void FormatConversion::image4fToImage3ub( const Image4f& source, Image3ub& destination, bool flipUpDown )
{
	int width = source.width();
	int height = source.height();

	for( int y = 0; y < height; ++y )
	{
		int yy = y;
		if( flipUpDown )
		{
			yy = height - y - 1;
		}

		for( int x = 0; x < width; ++x )
		{
			Vector4f input = source.pixel( x, y );
			Vector3i output = ColorUtils::floatToInt( input ).xyz();
			destination.setPixel( x, yy, output );
		}
	}
}
Ejemplo n.º 3
0
// static
std::shared_ptr< DynamicTexture2D > D3D11Utils_Texture::createTextureFromImage( ID3D11Device* pDevice, const Image4f& im, bool flipUD )
{
	std::shared_ptr< DynamicTexture2D > pTexture( DynamicTexture2D::createFloat4( pDevice, im.width(), im.height() ) );
	copyImageToTexture( im, pTexture, flipUD );
	return pTexture;
}