ConvertImageToPolygons: fix images with no alpha.

Fixes KICAD-714
This commit is contained in:
Alex Shvartzkop 2024-02-06 21:38:00 +03:00
parent 08b02f2a1a
commit 65c0a0a629
1 changed files with 7 additions and 3 deletions

View File

@ -34,6 +34,8 @@
std::unordered_map<uint32_t, SHAPE_POLY_SET> ConvertImageToPolygons( wxImage img,
VECTOR2D pixelScale )
{
bool hasAlpha = img.HasAlpha();
// Quantize the image
for( int y = 0; y < img.GetHeight(); y++ )
{
@ -42,7 +44,7 @@ std::unordered_map<uint32_t, SHAPE_POLY_SET> ConvertImageToPolygons( wxImage im
int r = img.GetRed( x, y );
int g = img.GetGreen( x, y );
int b = img.GetBlue( x, y );
int a = img.GetAlpha( x, y );
int a = hasAlpha ? img.GetAlpha( x, y ) : 255;
int roundBits = 5; // 32
r = std::min( r >> roundBits << roundBits, 0xFF );
@ -51,6 +53,8 @@ std::unordered_map<uint32_t, SHAPE_POLY_SET> ConvertImageToPolygons( wxImage im
a = std::min( a >> roundBits << roundBits, 0xFF );
img.SetRGB( x, y, r, g, b );
if( hasAlpha )
img.SetAlpha( x, y, a );
}
}
@ -65,7 +69,7 @@ std::unordered_map<uint32_t, SHAPE_POLY_SET> ConvertImageToPolygons( wxImage im
uint32_t r = img.GetRed( x, y );
uint32_t g = img.GetGreen( x, y );
uint32_t b = img.GetBlue( x, y );
uint32_t a = img.GetAlpha( x, y );
uint32_t a = hasAlpha ? img.GetAlpha( x, y ) : 255;
if( a > 0 )
{