예제 #1
0
SurfaceImage::SurfaceImage( cinder::Surface ciSurface ) 
	: SurfaceBase( ciSurface.getWidth(), ciSurface.getHeight() )
{
	bool needsManualCopy = true;
	cairo_format_t format = ( ciSurface.getChannelOrder().hasAlpha() ) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
	bool legalRowBytes = cairo_format_stride_for_width( format, ciSurface.getWidth() ) == ciSurface.getRowBytes();
	if( legalRowBytes && ( ciSurface.getChannelOrder() == cinder::SurfaceChannelOrder::BGRA ) ) {
		mCairoSurface = cairo_image_surface_create_for_data( const_cast<unsigned char*>( ciSurface.getData() ), CAIRO_FORMAT_ARGB32, ciSurface.getWidth(), ciSurface.getHeight(), ciSurface.getRowBytes() );
		needsManualCopy = false;
	} 
	else if( legalRowBytes && ( ciSurface.getChannelOrder() == cinder::SurfaceChannelOrder::BGRX ) ) {
		mCairoSurface = cairo_image_surface_create_for_data( const_cast<unsigned char*>( ciSurface.getData() ), CAIRO_FORMAT_RGB24, ciSurface.getWidth(), ciSurface.getHeight(), ciSurface.getRowBytes() );
		needsManualCopy = false;
	}
	else { // we can't natively represent this Surface configuration, so we'll just allocate one and manually copy it
		mCairoSurface = cairo_image_surface_create( ciSurface.hasAlpha() ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, ciSurface.getWidth(), ciSurface.getHeight() );
	}
	
	initCinderSurface( ciSurface.hasAlpha(), cairo_image_surface_get_data( mCairoSurface ), cairo_image_surface_get_stride( mCairoSurface ) );

	if( needsManualCopy )
		mCinderSurface.copyFrom( ciSurface, ciSurface.getBounds(), Vec2i::zero() );
	cairo_surface_mark_dirty( mCairoSurface );
}
예제 #2
0
SurfaceImage::SurfaceImage( const cinder::Surface &ciSurface ) 
	: SurfaceBase( ciSurface.getWidth(), ciSurface.getHeight() )
{
	if( ciSurface.getChannelOrder() == cinder::SurfaceChannelOrder::BGRA ) {
		mCairoSurface = cairo_image_surface_create_for_data( const_cast<unsigned char*>( ciSurface.getData() ), CAIRO_FORMAT_ARGB32, ciSurface.getWidth(), ciSurface.getHeight(), ciSurface.getRowBytes() );
	} 
	else if( ciSurface.getChannelOrder() == cinder::SurfaceChannelOrder::BGRX ) {
		mCairoSurface = cairo_image_surface_create_for_data( const_cast<unsigned char*>( ciSurface.getData() ), CAIRO_FORMAT_RGB24, ciSurface.getWidth(), ciSurface.getHeight(), ciSurface.getRowBytes() );
	}
	else
		throw;
	
	initCinderSurface( ciSurface.hasAlpha(), cairo_image_surface_get_data( mCairoSurface ), cairo_image_surface_get_stride( mCairoSurface ) );
}