37 bool hasAlpha = img.HasAlpha();
40 for(
int y = 0; y < img.GetHeight(); y++ )
42 for(
int x = 0; x < img.GetWidth(); x++ )
44 int r = img.GetRed( x, y );
45 int g = img.GetGreen( x, y );
46 int b = img.GetBlue( x, y );
47 int a = hasAlpha ? img.GetAlpha( x, y ) : 255;
50 r = std::min( r >> roundBits << roundBits, 0xFF );
51 g = std::min( g >> roundBits << roundBits, 0xFF );
52 b = std::min( b >> roundBits << roundBits, 0xFF );
53 a = std::min( a >> roundBits << roundBits, 0xFF );
55 img.SetRGB( x, y, r, g, b );
58 img.SetAlpha( x, y, a );
62 std::unordered_map<uint32_t, SHAPE_POLY_SET> colorPolys;
65 for(
int y = 0; y < img.GetHeight(); y++ )
67 for(
int x = 0; x < img.GetWidth(); x++ )
69 uint32_t r = img.GetRed( x, y );
70 uint32_t g = img.GetGreen( x, y );
71 uint32_t b = img.GetBlue( x, y );
72 uint32_t a = hasAlpha ? img.GetAlpha( x, y ) : 255;
76 uint32_t
color = r | ( g << 8 ) | ( b << 16 ) | ( a << 24 );
81 chain.
Append( x * pixelScale.
x, y * pixelScale.
y,
true );
82 chain.
Append( ( x + 1 ) * pixelScale.
x, y * pixelScale.
y, true );
83 chain.
Append( ( x + 1 ) * pixelScale.
x, ( y + 1 ) * pixelScale.
y,
true );
84 chain.
Append( x * pixelScale.
x, ( y + 1 ) * pixelScale.
y, true );
92 for(
auto& [
color, polySet] : colorPolys )
96 for(
int i = 0; i < polySet.OutlineCount(); i++ )
112 std::unordered_map<uint32_t, SHAPE_POLY_SET> colorPolys =
115 for(
auto& [
color, polySet] : colorPolys )
123 shape->SetPolyShape( poly );
125 int r =
color & 0xFF;
126 int g = (
color >> 8 ) & 0xFF;
127 int b = (
color >> 16 ) & 0xFF;
128 int a = (
color >> 24 ) & 0xFF;
130 shape->SetWidth( -1 );
132 shape->SetFillColor(
COLOR4D( r / 255.0, g / 255.0, b / 255.0, a / 255.0 ) );
134 shape->SetUnit( unit );
136 shape->Move( offset );
150 libeditImporter.
SetScale( pixelScale );
constexpr EDA_IU_SCALE schIUScale
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
void SetScale(const VECTOR2D &aScale)
Set the scale factor affecting the imported shapes.
virtual void SetImporter(GRAPHICS_IMPORTER *aImporter)
Set the receiver of the imported shapes.
A color representation with 4 components: red, green, blue, alpha.
Define a library symbol object.
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
bool Import() override
Actually imports the file.
bool LoadFromMemory(const wxMemoryBuffer &aMemBuffer) override
Set memory buffer with content for import.
void ConvertImageToLibShapes(LIB_SYMBOL *aSymbol, int unit, wxImage img, VECTOR2D pixelScale, VECTOR2D offset)
std::unordered_map< uint32_t, SHAPE_POLY_SET > ConvertImageToPolygons(wxImage img, VECTOR2D pixelScale)
void ConvertSVGToLibShapes(LIB_SYMBOL *aSymbol, int unit, const wxMemoryBuffer &aImageData, VECTOR2D pixelScale, VECTOR2D offset)
constexpr double IUTomm(int iu) const
VECTOR2< double > VECTOR2D