bitmaps: Handle mask colors

Some transparent bitmaps use masking colors to show the binary
opaque/transparent.

Fixes: lp:1814893
* https://bugs.launchpad.net/kicad/+bug/1814893
This commit is contained in:
Seth Hillbrand 2019-02-07 21:26:27 -08:00
parent 7789ec4bf1
commit 5da4e18664
3 changed files with 11 additions and 3 deletions

View File

@ -300,6 +300,9 @@ void CAIRO_GAL_BASE::DrawBitmap( const BITMAP_BASE& aBitmap )
unsigned char* pix_buffer = cairo_image_surface_get_data( image );
// The pixel buffer of the initial bitmap:
auto bm_pix_buffer = (( BITMAP_BASE&)aBitmap).GetImageData();
uint32_t mask_color = ( bm_pix_buffer->GetMaskRed() << 16 )+
( bm_pix_buffer->GetMaskGreen() << 8 ) +
( bm_pix_buffer->GetMaskBlue() );
// Copy the source bitmap to the cairo bitmap buffer.
// In cairo bitmap buffer, a ARGB32 bitmap is an ARGB pixel packed into a uint_32
@ -315,8 +318,10 @@ void CAIRO_GAL_BASE::DrawBitmap( const BITMAP_BASE& aBitmap )
if( bm_pix_buffer->HasAlpha() )
pixel += bm_pix_buffer->GetAlpha( col, row ) << 24;
else if( bm_pix_buffer->HasMask() && pixel == mask_color )
pixel += ( wxALPHA_TRANSPARENT << 24 );
else
pixel += ( 0xff << 24 );
pixel += ( wxALPHA_OPAQUE << 24 );
// Write the pixel to the cairo image buffer:
uint32_t* pix_ptr = (uint32_t*) pix_buffer;

View File

@ -158,8 +158,11 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
if( imgData->HasAlpha() )
p[3] = imgData->GetAlpha( x, y );
else if( imgData->HasMask() && p[0] == imgData->GetMaskRed() &&
p[1] == imgData->GetMaskGreen() && p[2] == imgData->GetMaskBlue() )
p[3] = wxALPHA_TRANSPARENT;
else
p[3] = 255;
p[3] = wxALPHA_OPAQUE;
}
}

View File

@ -234,5 +234,5 @@ BITMAP_DEF SCH_BITMAP::GetMenuImage() const
void SCH_BITMAP::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = LAYER_WORKSHEET;
aLayers[0] = LAYER_DRAW_BITMAPS;
}