From 2037fb3efc117050ef7d32385f93cad3eec3e822 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 21 Aug 2012 18:12:13 +0200 Subject: [PATCH] Move to the agg color system --- parserSVG/Base.cpp | 34 +++++++++++++++++----------------- parserSVG/Base.h | 4 ++-- parserSVG/Circle.cpp | 8 ++++---- parserSVG/Ellipse.cpp | 8 ++++---- parserSVG/Line.cpp | 2 +- parserSVG/Path.cpp | 8 ++++---- parserSVG/Polygon.cpp | 8 ++++---- parserSVG/Polyline.cpp | 2 +- parserSVG/Rectangle.cpp | 8 ++++---- parserSVG/Renderer.h | 6 +++--- parserSVG/parserSVG.cpp | 11 ++--------- 11 files changed, 46 insertions(+), 53 deletions(-) diff --git a/parserSVG/Base.cpp b/parserSVG/Base.cpp index ec9221e..b0cb336 100644 --- a/parserSVG/Base.cpp +++ b/parserSVG/Base.cpp @@ -221,14 +221,14 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) const char * content = node->ToElement()->Attribute("fill"); if (NULL != content) { m_paint.fill = ParseColor(content); - if (m_paint.fill.alpha == 0) { + if (m_paint.fill.a == 0) { fillNone = true; } } content = node->ToElement()->Attribute("stroke"); if (NULL != content) { m_paint.stroke = ParseColor(content); - if (m_paint.stroke.alpha == 0) { + if (m_paint.stroke.a == 0) { strokeNone = true; } } @@ -240,20 +240,20 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) if (NULL != content) { float opacity = ParseLength(content); opacity = etk_max(0.0, etk_min(1.0, opacity)); - m_paint.fill.alpha = opacity*0xFF; - m_paint.stroke.alpha = opacity*0xFF; + m_paint.fill.a = opacity*0xFF; + m_paint.stroke.a = opacity*0xFF; } content = node->ToElement()->Attribute("fill-opacity"); if (NULL != content) { float opacity = ParseLength(content); opacity = etk_max(0.0, etk_min(1.0, opacity)); - m_paint.fill.alpha = opacity*0xFF; + m_paint.fill.a = opacity*0xFF; } content = node->ToElement()->Attribute("stroke-opacity"); if (NULL != content) { float opacity = ParseLength(content); opacity = etk_max(0.0, etk_min(1.0, opacity)); - m_paint.stroke.alpha = opacity*0xFF; + m_paint.stroke.a = opacity*0xFF; } content = node->ToElement()->Attribute("fill-rule"); if (NULL != content) { @@ -303,13 +303,13 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) if (0 == strcmp(outputType, "fill") ) { m_paint.fill = ParseColor(outputValue); SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.fill); - if (m_paint.fill.alpha == 0) { + if (m_paint.fill.a == 0) { fillNone = true; } } else if (0 == strcmp(outputType, "stroke") ) { m_paint.stroke = ParseColor(outputValue); SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.stroke); - if (m_paint.stroke.alpha == 0) { + if (m_paint.stroke.a == 0) { strokeNone = true; } } else if (0 == strcmp(outputType, "stroke-width") ) { @@ -318,18 +318,18 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) } else if (0 == strcmp(outputType, "opacity") ) { float opacity = ParseLength(outputValue); opacity = etk_max(0.0, etk_min(1.0, opacity)); - m_paint.fill.alpha = opacity*0xFF; - m_paint.stroke.alpha = opacity*0xFF; + m_paint.fill.a = opacity*0xFF; + m_paint.stroke.a = opacity*0xFF; SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.fill); } else if (0 == strcmp(outputType, "fill-opacity") ) { float opacity = ParseLength(outputValue); opacity = etk_max(0.0, etk_min(1.0, opacity)); - m_paint.fill.alpha = opacity*0xFF; + m_paint.fill.a = opacity*0xFF; SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.fill); } else if (0 == strcmp(outputType, "stroke-opacity") ) { float opacity = ParseLength(outputValue); opacity = etk_max(0.0, etk_min(1.0, opacity)); - m_paint.stroke.alpha = opacity*0xFF; + m_paint.stroke.a = opacity*0xFF; SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.stroke); } else if (0 == strcmp(outputType, "fill-rule") ) { if (0 == strcmp(outputValue, "nonzero") ) { @@ -370,10 +370,10 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) } // check if somewere none is set to the filling: if (true == fillNone) { - m_paint.fill.alpha = 0; + m_paint.fill.a = 0; } if (true == strokeNone) { - m_paint.stroke.alpha = 0; + m_paint.stroke.a = 0; } } @@ -407,9 +407,9 @@ bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen) * @param[in] inputData Data C String with the xml definition * @return the parsed color */ -etk::Color svg::Base::ParseColor(const char *inputData) +draw::Color svg::Base::ParseColor(const char *inputData) { - etk::Color localColor = etk::color::white; + draw::Color localColor = draw::color::white; size_t len = strlen(inputData); @@ -460,7 +460,7 @@ void svg::Base::AggCheckChange(agg::path_storage& path, etk::Vector if (curentPaintProp != m_paint) { SVG_INFO("add path color = " << m_paint.fill); // New color. Every new color creates new path in the path object. - colors.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + colors.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.a)); uint32_t tmpPathNew = path.start_new_path(); pathIdx.PushBack(tmpPathNew); curentPaintProp = m_paint; diff --git a/parserSVG/Base.h b/parserSVG/Base.h index 8c179ad..f03e41d 100644 --- a/parserSVG/Base.h +++ b/parserSVG/Base.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -64,7 +64,7 @@ namespace svg void ParsePosition(const TiXmlNode *node, Vector2D &pos, Vector2D &size); float ParseLength(const char *dataInput); void ParsePaintAttr(const TiXmlNode *node); - etk::Color ParseColor(const char *inputData); + draw::Color ParseColor(const char *inputData); }; }; diff --git a/parserSVG/Circle.cpp b/parserSVG/Circle.cpp index 9b35f90..aa7e074 100644 --- a/parserSVG/Circle.cpp +++ b/parserSVG/Circle.cpp @@ -83,7 +83,7 @@ void svg::Circle::Display(int32_t spacing) void svg::Circle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a)); // Creating an ellipse agg::ellipse myCircle(m_position.x, m_position.y, m_radius, m_radius, 0); @@ -94,14 +94,14 @@ void svg::Circle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra // set the filling mode : myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); - if (m_paint.fill.alpha != 0x00) { + if (m_paint.fill.a != 0x00) { agg::conv_transform trans(myCircle, mtx); myRenderer.m_rasterizer.add_path(trans); agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); } - if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) { + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke myCircleStroke(myCircle); myCircleStroke.width(m_paint.strokeWidth); diff --git a/parserSVG/Ellipse.cpp b/parserSVG/Ellipse.cpp index 510f7fc..d6a9d8a 100644 --- a/parserSVG/Ellipse.cpp +++ b/parserSVG/Ellipse.cpp @@ -86,7 +86,7 @@ void svg::Ellipse::Display(int32_t spacing) void svg::Ellipse::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a)); // Creating an ellipse agg::ellipse myEllipse(m_c.x, m_c.y, m_r.x, m_r.y, 0); @@ -97,14 +97,14 @@ void svg::Ellipse::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr // set the filling mode : myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); - if (m_paint.fill.alpha != 0x00) { + if (m_paint.fill.a != 0x00) { agg::conv_transform trans(myEllipse, mtx); myRenderer.m_rasterizer.add_path(trans); agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); } - if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) { + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke myEllipseStroke(myEllipse); myEllipseStroke.width(m_paint.strokeWidth); diff --git a/parserSVG/Line.cpp b/parserSVG/Line.cpp index b2fa28b..963c9c2 100644 --- a/parserSVG/Line.cpp +++ b/parserSVG/Line.cpp @@ -112,7 +112,7 @@ void svg::Line::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans mtx *= basicTrans; if (m_paint.strokeWidth > 0) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke myPolygonStroke(path); myPolygonStroke.width(m_paint.strokeWidth); diff --git a/parserSVG/Path.cpp b/parserSVG/Path.cpp index eebecd3..63d1729 100644 --- a/parserSVG/Path.cpp +++ b/parserSVG/Path.cpp @@ -347,7 +347,7 @@ void svg::Path::Display(int32_t spacing) void svg::Path::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a)); agg::path_storage path; path.start_new_path(); @@ -421,15 +421,15 @@ void svg::Path::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans mtx *= basicTrans; agg::conv_curve curve(path); - if (m_paint.fill.alpha != 0x00) { + if (m_paint.fill.a != 0x00) { agg::conv_transform, agg::trans_affine> trans(curve, mtx); // set the filling mode : myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); myRenderer.m_rasterizer.add_path(trans); agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); } - if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) { + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke > myPolygonStroke(curve); myPolygonStroke.width(m_paint.strokeWidth); diff --git a/parserSVG/Polygon.cpp b/parserSVG/Polygon.cpp index 3777411..b0d565a 100644 --- a/parserSVG/Polygon.cpp +++ b/parserSVG/Polygon.cpp @@ -82,7 +82,7 @@ void svg::Polygon::Display(int32_t spacing) void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a)); agg::path_storage path; path.start_new_path(); @@ -121,7 +121,7 @@ void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr agg::trans_affine mtx = m_transformMatrix; mtx *= basicTrans; - if (m_paint.fill.alpha != 0x00) { + if (m_paint.fill.a != 0x00) { agg::conv_transform trans(path, mtx); // set the filling mode : myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); @@ -129,8 +129,8 @@ void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); } - if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) { + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke myPolygonStroke(path); myPolygonStroke.width(m_paint.strokeWidth); diff --git a/parserSVG/Polyline.cpp b/parserSVG/Polyline.cpp index 5955b10..0686319 100644 --- a/parserSVG/Polyline.cpp +++ b/parserSVG/Polyline.cpp @@ -114,7 +114,7 @@ void svg::Polyline::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicT mtx *= basicTrans; if (m_paint.strokeWidth > 0) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke myPolygonStroke(path); myPolygonStroke.width(m_paint.strokeWidth); diff --git a/parserSVG/Rectangle.cpp b/parserSVG/Rectangle.cpp index 5577abd..2eebc2f 100644 --- a/parserSVG/Rectangle.cpp +++ b/parserSVG/Rectangle.cpp @@ -79,7 +79,7 @@ void svg::Rectangle::Display(int32_t spacing) void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a)); // Creating a rounded rectangle agg::rounded_rect rect_r(m_position.x, m_position.y, m_position.x+m_size.x, m_position.y+m_size.y, m_roundedCorner.x); rect_r.radius(m_roundedCorner.x, m_roundedCorner.y); @@ -89,7 +89,7 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic // herited modifications ... mtx *= basicTrans; - if (m_paint.fill.alpha != 0x00) { + if (m_paint.fill.a != 0x00) { agg::conv_transform trans(rect_r, mtx); // set the filling mode : myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); @@ -97,8 +97,8 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); } - if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) { - myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); + if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) { + myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a)); // Drawing as an outline agg::conv_stroke rect_p(rect_r); // set the filling mode : diff --git a/parserSVG/Renderer.h b/parserSVG/Renderer.h index 07c6d04..8268b8a 100644 --- a/parserSVG/Renderer.h +++ b/parserSVG/Renderer.h @@ -26,7 +26,7 @@ #define __SVG_RENDERER_H__ #include -#include +#include #include #include @@ -54,8 +54,8 @@ namespace svg class PaintState { public: - etk::Color fill; - etk::Color stroke; + draw::Color fill; + draw::Color stroke; float strokeWidth; bool flagEvenOdd; lineCap_te lineCap; diff --git a/parserSVG/parserSVG.cpp b/parserSVG/parserSVG.cpp index d74379d..711d850 100644 --- a/parserSVG/parserSVG.cpp +++ b/parserSVG/parserSVG.cpp @@ -52,15 +52,8 @@ svg::Parser::Parser(etk::File fileName) : m_renderedElement(NULL) m_fileName = fileName; m_version = "0.0"; m_loadOK = true; - m_paint.fill.red = 0xFF; - m_paint.fill.green = 0; - m_paint.fill.blue = 0; - m_paint.fill.alpha = 0xFF; - - m_paint.stroke.red = 0xFF; - m_paint.stroke.green = 0xFF; - m_paint.stroke.blue = 0xFF; - m_paint.stroke.alpha = 0; + m_paint.fill = (int32_t)0xFF0000FF; + m_paint.stroke = (int32_t)0xFFFFFF00; m_paint.strokeWidth = 1.0; m_paint.viewPort.x = 255;