Put background color behind transparent bitmaps in eeschema printing.

Most virtual printers don't support alpha blending via AlphaBlend (MSW)
properly, nor masks.
This commit is contained in:
Alex Shvartzkop 2023-07-03 01:59:38 +03:00
parent 4cb7e92aad
commit b242779f3b
4 changed files with 29 additions and 11 deletions

View File

@ -281,7 +281,8 @@ const BOX2I BITMAP_BASE::GetBoundingBox() const
}
void BITMAP_BASE::DrawBitmap( wxDC* aDC, const VECTOR2I& aPos )
void BITMAP_BASE::DrawBitmap( wxDC* aDC, const VECTOR2I& aPos,
const KIGFX::COLOR4D& aBackgroundColor )
{
if( m_bitmap == nullptr )
return;
@ -358,7 +359,26 @@ void BITMAP_BASE::DrawBitmap( wxDC* aDC, const VECTOR2I& aPos )
aDC->SetClippingRegion( clipAreaPos, wxSize( size.x, size.y ) );
#endif
if( aBackgroundColor != COLOR4D::UNSPECIFIED && m_bitmap->HasAlpha() )
{
// Most printers don't support transparent images properly,
// so blend the image with background color.
int w = m_bitmap->GetWidth();
int h = m_bitmap->GetHeight();
wxImage image( w, h );
wxColour bgColor = aBackgroundColor.ToColour();
image.SetRGB( wxRect( 0, 0, w, h ), bgColor.Red(), bgColor.Green(), bgColor.Blue() );
image.Paste( m_bitmap->ConvertToImage(), 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE );
if( GetGRForceBlackPenState() )
image = image.ConvertToGreyscale();
aDC->DrawBitmap( wxBitmap( image ), pos.x, pos.y, true );
}
else if( GetGRForceBlackPenState() )
{
wxBitmap result( m_bitmap->ConvertToImage().ConvertToGreyscale() );
aDC->DrawBitmap( result, pos.x, pos.y, true );

View File

@ -463,7 +463,8 @@ void DS_DRAW_ITEM_BITMAP::PrintWsItem( const RENDER_SETTINGS* aSettings, const V
if( !bitmap->m_ImageBitmap )
return;
bitmap->m_ImageBitmap->DrawBitmap( aSettings->GetPrintDC(), m_pos + aOffset );
bitmap->m_ImageBitmap->DrawBitmap( aSettings->GetPrintDC(), m_pos + aOffset,
aSettings->GetBackgroundColor() );
}

View File

@ -131,7 +131,7 @@ void SCH_BITMAP::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffse
{
VECTOR2I pos = m_pos + aOffset;
m_bitmapBase->DrawBitmap( aSettings->GetPrintDC(), pos );
m_bitmapBase->DrawBitmap( aSettings->GetPrintDC(), pos, aSettings->GetBackgroundColor() );
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 jean-pierre.charras jp.charras at wanadoo.fr
* Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2013-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -29,11 +29,7 @@
#include <wx/image.h>
#include <kiid.h>
#include <math/box2.h>
namespace KIGFX
{
class COLOR4D;
}
#include <gal/color4d.h>
class LINE_READER;
class PLOTTER;
@ -134,7 +130,8 @@ public:
*/
const BOX2I GetBoundingBox() const;
void DrawBitmap( wxDC* aDC, const VECTOR2I& aPos );
void DrawBitmap( wxDC* aDC, const VECTOR2I& aPos,
const KIGFX::COLOR4D& aBackgroundColor = KIGFX::COLOR4D::UNSPECIFIED );
/**
* Reads and stores in memory an image file.