38 for(
int y = 0; y < img.GetHeight(); y++ )
40 for(
int x = 0; x < img.GetWidth(); x++ )
42 int r = img.GetRed( x, y );
43 int g = img.GetGreen( x, y );
44 int b = img.GetBlue( x, y );
45 int a = img.GetAlpha( x, y );
48 r = std::min( r >> roundBits << roundBits, 0xFF );
49 g = std::min( g >> roundBits << roundBits, 0xFF );
50 b = std::min( b >> roundBits << roundBits, 0xFF );
51 a = std::min( a >> roundBits << roundBits, 0xFF );
53 img.SetRGB( x, y, r, g, b );
54 img.SetAlpha( x, y, a );
58 std::unordered_map<uint32_t, SHAPE_POLY_SET> colorPolys;
61 for(
int y = 0; y < img.GetHeight(); y++ )
63 for(
int x = 0; x < img.GetWidth(); x++ )
65 uint32_t r = img.GetRed( x, y );
66 uint32_t g = img.GetGreen( x, y );
67 uint32_t b = img.GetBlue( x, y );
68 uint32_t a = img.GetAlpha( x, y );
72 uint32_t
color = r | ( g << 8 ) | ( b << 16 ) | ( a << 24 );
77 chain.
Append( x * pixelScale.
x, y * pixelScale.
y,
true );
78 chain.
Append( ( x + 1 ) * pixelScale.
x, y * pixelScale.
y, true );
79 chain.
Append( ( x + 1 ) * pixelScale.
x, ( y + 1 ) * pixelScale.
y,
true );
80 chain.
Append( x * pixelScale.
x, ( y + 1 ) * pixelScale.
y, true );
88 for(
auto& [
color, polySet] : colorPolys )
92 for(
int i = 0; i < polySet.OutlineCount(); i++ )
108 std::unordered_map<uint32_t, SHAPE_POLY_SET> colorPolys =
111 for(
auto& [
color, polySet] : colorPolys )
117 std::unique_ptr<LIB_SHAPE> shape =
120 shape->SetPolyShape( poly );
122 int r =
color & 0xFF;
123 int g = (
color >> 8 ) & 0xFF;
124 int b = (
color >> 16 ) & 0xFF;
125 int a = (
color >> 24 ) & 0xFF;
127 shape->SetWidth( -1 );
129 shape->SetFillColor(
COLOR4D( r / 255.0, g / 255.0, b / 255.0, a / 255.0 ) );
131 shape->SetUnit( unit );
133 shape->Offset( offset );
147 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(LIB_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