Example #1
0
Texture::Texture( const Channel8u &channel, Format format )
	: mObj( shared_ptr<Obj>( new Obj( channel.getWidth(), channel.getHeight() ) ) )
{
	if( format.mInternalFormat < 0 )
		format.mInternalFormat = GL_LUMINANCE;

	mObj->mInternalFormat = format.mInternalFormat;
	mObj->mTarget = format.mTarget;

	// if the data is not already contiguous, we'll need to create a block of memory that is
	if( ( channel.getIncrement() != 1 ) || ( channel.getRowBytes() != channel.getWidth() * sizeof(uint8_t) ) ) {
		shared_ptr<uint8_t> data( new uint8_t[channel.getWidth() * channel.getHeight()], checked_array_deleter<uint8_t>() );
		uint8_t *dest = data.get();
		const int8_t inc = channel.getIncrement();
		const int32_t width = channel.getWidth();
		for( int y = 0; y < channel.getHeight(); ++y ) {
			const uint8_t *src = channel.getData( 0, y );
			for( int x = 0; x < width; ++x ) {
				*dest++ = *src;
				src += inc;
			}
		}
	
		init( data.get(), channel.getRowBytes() / channel.getIncrement(), GL_LUMINANCE, GL_UNSIGNED_BYTE, format );
	}
	else
		init( channel.getData(), channel.getRowBytes() / channel.getIncrement(), GL_LUMINANCE, GL_UNSIGNED_BYTE, format );
}
Example #2
0
Surface8u colorizeBodyIndex( const Channel8u& bodyIndexChannel )
{
    Surface8u surface;
    if ( bodyIndexChannel ) {
        surface = Surface8u( bodyIndexChannel.getWidth(), bodyIndexChannel.getHeight(), true, SurfaceChannelOrder::RGBA );
        Channel8u::ConstIter iterChannel	= bodyIndexChannel.getIter();
        Surface8u::Iter iterSurface			= surface.getIter();
        while ( iterChannel.line() && iterSurface.line() ) {
            while ( iterChannel.pixel() && iterSurface.pixel() ) {
                size_t index				= (size_t)iterChannel.v();
                ColorA8u color( getBodyColor( index ), 0xFF );
                if ( index == 0 || index > BODY_COUNT ) {
                    color.a					= 0x00;
                }
                iterSurface.r()				= color.r;
                iterSurface.g()				= color.g;
                iterSurface.b()				= color.b;
                iterSurface.a()				= color.a;
            }
        }
    }
    return surface;
}