From 5da4e186644bfeb5d129de47bb77e8a6f05f6ddc Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 7 Feb 2019 21:26:27 -0800 Subject: [PATCH] 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 --- common/gal/cairo/cairo_gal.cpp | 7 ++++++- common/gal/opengl/opengl_gal.cpp | 5 ++++- eeschema/sch_bitmap.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index d198c9c53c..1f5871c6e6 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -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; diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index e8b41b8023..e3703bd6d0 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -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; } } diff --git a/eeschema/sch_bitmap.cpp b/eeschema/sch_bitmap.cpp index e8af80ec6d..6bdc9fe122 100644 --- a/eeschema/sch_bitmap.cpp +++ b/eeschema/sch_bitmap.cpp @@ -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; }