From 062b67e1b71ee88eb463b9653214b83f46e3e12f Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Fri, 23 Mar 2012 17:57:27 +0100 Subject: [PATCH] start abstraction of the AGG lib --- Sources/libetk/Linux.mk | 3 +- Sources/libewol/Linux.mk | 3 +- Sources/libparsersvg/Android.mk | 3 +- Sources/libparsersvg/Linux.mk | 7 +- Sources/libparsersvg/file.mk | 5 +- Sources/libparsersvg/parserSVG/Base.cpp | 21 +++- Sources/libparsersvg/parserSVG/Base.h | 47 +------- Sources/libparsersvg/parserSVG/Group.cpp | 7 +- Sources/libparsersvg/parserSVG/Group.h | 2 +- Sources/libparsersvg/parserSVG/Polygon.cpp | 43 ++++++-- Sources/libparsersvg/parserSVG/Polygon.h | 2 +- Sources/libparsersvg/parserSVG/Rectangle.cpp | 65 ++++++----- Sources/libparsersvg/parserSVG/Rectangle.h | 2 +- Sources/libparsersvg/parserSVG/Renderer.cpp | 107 ++++++++++++++++++ Sources/libparsersvg/parserSVG/Renderer.h | 109 +++++++++++++++++++ Sources/libparsersvg/parserSVG/parserSVG.cpp | 104 ++---------------- Sources/libparsersvg/parserSVG/parserSVG.h | 2 +- 17 files changed, 341 insertions(+), 191 deletions(-) create mode 100644 Sources/libparsersvg/parserSVG/Renderer.cpp create mode 100644 Sources/libparsersvg/parserSVG/Renderer.h diff --git a/Sources/libetk/Linux.mk b/Sources/libetk/Linux.mk index 0bc8a9d0..d3437028 100644 --- a/Sources/libetk/Linux.mk +++ b/Sources/libetk/Linux.mk @@ -16,7 +16,8 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \ -DETK_DEBUG_LEVEL=3 \ -DEWOL_DEBUG_LEVEL=3 \ -DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \ - -DVERSION_BUILD_TIME="\"pasd_heure\"" + -DVERSION_BUILD_TIME="\"pasd_heure\"" \ + -Wall else LOCAL_CFLAGS := -D__PLATFORM__Linux \ -Wno-write-strings \ diff --git a/Sources/libewol/Linux.mk b/Sources/libewol/Linux.mk index ce4729a0..f8add591 100644 --- a/Sources/libewol/Linux.mk +++ b/Sources/libewol/Linux.mk @@ -17,7 +17,8 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \ -DEWOL_DEBUG_LEVEL=3 \ -DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \ -DVERSION_BUILD_TIME="\"pasd_heure\"" \ - -DEWOL_USE_FREE_TYPE + -DEWOL_USE_FREE_TYPE \ + -Wall else LOCAL_CFLAGS := -D__PLATFORM__Linux \ -Wno-write-strings \ diff --git a/Sources/libparsersvg/Android.mk b/Sources/libparsersvg/Android.mk index 484806f3..47890511 100644 --- a/Sources/libparsersvg/Android.mk +++ b/Sources/libparsersvg/Android.mk @@ -15,7 +15,8 @@ LOCAL_EXPORT_LDLIBS := ifeq ($(DEBUG),1) LOCAL_CFLAGS := -D__PLATFORM__Linux \ - -DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\"" + -DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\"" \ + -Wall -Wextra else LOCAL_CFLAGS := -D__PLATFORM__Linux \ -DPARSER_SVG_VERSION_TAG_NAME="\"???-release\"" diff --git a/Sources/libparsersvg/Linux.mk b/Sources/libparsersvg/Linux.mk index c2261cc7..6f87fe4e 100644 --- a/Sources/libparsersvg/Linux.mk +++ b/Sources/libparsersvg/Linux.mk @@ -15,11 +15,12 @@ LOCAL_EXPORT_LDLIBS := ifeq ($(DEBUG),1) LOCAL_CFLAGS := -D__PLATFORM__Linux \ - -DSVG_DEBUG_LEVEL=3 - -DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\"" + -DSVG_DEBUG_LEVEL=3 \ + -DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\"" \ + -Wall else LOCAL_CFLAGS := -D__PLATFORM__Linux \ - -DSVG_DEBUG_LEVEL=1 + -DSVG_DEBUG_LEVEL=1 \ -DPARSER_SVG_VERSION_TAG_NAME="\"???-release\"" endif diff --git a/Sources/libparsersvg/file.mk b/Sources/libparsersvg/file.mk index 4ee1417e..c11aae81 100644 --- a/Sources/libparsersvg/file.mk +++ b/Sources/libparsersvg/file.mk @@ -1,8 +1,8 @@ -FILE_LIST = parserSVG/Debug.cpp \ - parserSVG/Base.cpp \ +FILE_LIST = parserSVG/Base.cpp \ parserSVG/Circle.cpp \ + parserSVG/Debug.cpp \ parserSVG/Ellipse.cpp \ parserSVG/Group.cpp \ parserSVG/Line.cpp \ @@ -11,5 +11,6 @@ FILE_LIST = parserSVG/Debug.cpp \ parserSVG/Polygon.cpp \ parserSVG/Polyline.cpp \ parserSVG/Rectangle.cpp \ + parserSVG/Renderer.cpp \ parserSVG/Stroking.cpp \ parserSVG/Text.cpp diff --git a/Sources/libparsersvg/parserSVG/Base.cpp b/Sources/libparsersvg/parserSVG/Base.cpp index 0a1806c0..f15ceb25 100644 --- a/Sources/libparsersvg/parserSVG/Base.cpp +++ b/Sources/libparsersvg/parserSVG/Base.cpp @@ -155,10 +155,13 @@ etkFloat_t svg::Base::ParseLength(const char *dataInput) { int32_t numLength = strspn(dataInput, "0123456789+-."); const char *unit = dataInput + numLength; + //SVG_INFO(" ==> \"" << dataInput << "\""); etkFloat_t n = atof(dataInput); + //SVG_INFO(" ==> ?? = " << n ); etkFloat_t font_size = 20.0; - - if (unit[0] == '\0') { + + // note : ";" is for the parsing of the style elements ... + if (unit[0] == '\0' || unit[0] == ';' ) { return n; } else if (unit[0] == '%') { // xxx % return n / 100.0 * m_paint.viewPort.x; @@ -223,11 +226,22 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node) } if ((sss = strstr(content, "stroke-width:"))) { sss += 13; + SVG_VERBOSE(" find a stroke width ... : " << sss); while( sss[0] ==' ' && sss[0]!='\0' ) { sss++; } m_paint.strokeWidth = ParseLength(sss); + SVG_VERBOSE(" ==> " << m_paint.strokeWidth); + } + if ((sss = strstr(content, "opacity:"))) { + sss += 8; + while( sss[0] ==' ' + && sss[0]!='\0' ) { + sss++; + } + etkFloat_t opacity = ParseLength(sss); + m_paint.opacity = etk_max(0.0, etk_min(1.0, opacity)); } } } @@ -557,7 +571,7 @@ const char * svg::Base::SpacingDist(int32_t spacing) } - +/* void svg::Base::AggCheckChange(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp) { if (curentPaintProp != m_paint) { @@ -569,3 +583,4 @@ void svg::Base::AggCheckChange(agg::path_storage& path, etk::VectorType #include +#include #include #include @@ -43,49 +44,6 @@ namespace svg { - #define MATRIX_SIZE (6) - class PaintState { - public : - PaintState(void) {}; - ~PaintState(void) {}; - color8_ts fill; - color8_ts stroke; - etkFloat_t strokeWidth; - coord2D_ts viewPort; - etkFloat_t matrix[MATRIX_SIZE]; - bool operator!= (const svg::PaintState& paintExt) const - { - if( fill.red != paintExt.fill.red - || fill.green != paintExt.fill.green - || fill.blue != paintExt.fill.blue - || fill.alpha != paintExt.fill.alpha) { - return true; - } - if( stroke.red != paintExt.stroke.red - || stroke.green != paintExt.stroke.green - || stroke.blue != paintExt.stroke.blue - || stroke.alpha != paintExt.stroke.alpha) { - return true; - } - if (strokeWidth != paintExt.strokeWidth) { - return true; - } - if( viewPort.x != paintExt.viewPort.x - || viewPort.y != paintExt.viewPort.y) { - return true; - } - if( matrix[0] != paintExt.matrix[0] - || matrix[1] != paintExt.matrix[1] - || matrix[2] != paintExt.matrix[2] - || matrix[3] != paintExt.matrix[3] - || matrix[4] != paintExt.matrix[4] - || matrix[5] != paintExt.matrix[5]) { - return true; - } - return false; - } - }; - class Base { protected: @@ -97,8 +55,7 @@ namespace svg ~Base(void) { }; virtual bool Parse(TiXmlNode * node); //specific drawing for AAG librairy ... - virtual void AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp) { }; - virtual void AggCheckChange(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp); + virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp) { }; virtual void Display(int32_t spacing) { }; void ParseTransform(TiXmlNode *node); diff --git a/Sources/libparsersvg/parserSVG/Group.cpp b/Sources/libparsersvg/parserSVG/Group.cpp index 525c8588..acd3b83d 100644 --- a/Sources/libparsersvg/parserSVG/Group.cpp +++ b/Sources/libparsersvg/parserSVG/Group.cpp @@ -113,14 +113,13 @@ void svg::Group::Display(int32_t spacing) SVG_DEBUG(SpacingDist(spacing) << "Group (STOP)"); } -void svg::Group::AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp) +void svg::Group::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp) { - AggCheckChange(path, colors, pathIdx, curentPaintProp); + curentPaintProp = m_paint; for (int32_t iii=0; iiiAggDraw(path, colors, pathIdx, curentPaintProp); + m_subElementList[iii]->AggDraw(myRenderer, curentPaintProp); } } - } diff --git a/Sources/libparsersvg/parserSVG/Group.h b/Sources/libparsersvg/parserSVG/Group.h index dc343b20..8ce55267 100644 --- a/Sources/libparsersvg/parserSVG/Group.h +++ b/Sources/libparsersvg/parserSVG/Group.h @@ -39,7 +39,7 @@ namespace svg ~Group(void); virtual bool Parse(TiXmlNode * node); virtual void Display(int32_t spacing); - virtual void AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp); + virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp); }; }; diff --git a/Sources/libparsersvg/parserSVG/Polygon.cpp b/Sources/libparsersvg/parserSVG/Polygon.cpp index 931d1b1c..e7c8938b 100644 --- a/Sources/libparsersvg/parserSVG/Polygon.cpp +++ b/Sources/libparsersvg/parserSVG/Polygon.cpp @@ -65,18 +65,47 @@ void svg::Polygon::Display(int32_t spacing) } -void svg::Polygon::AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void svg::Polygon::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp) { - if (m_listPoint.Size()<2) { - // nothing to draw ... - return; - } - AggCheckChange(path, colors, pathIdx, curentPaintProp); + curentPaintProp = m_paint; + agg::path_storage path; + etk::VectorType colorsList; + etk::VectorType pathListId; + + // New color. Every new color creates new path in the path object. + colorsList.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); + uint32_t tmpPathNew = path.start_new_path(); + pathListId.PushBack(tmpPathNew); + path.move_to(m_listPoint[0].x, m_listPoint[0].y); for( int32_t iii=1; iii< m_listPoint.Size(); iii++) { path.line_to(m_listPoint[iii].x, m_listPoint[iii].y); } path.close_polygon(); + + + agg::trans_affine mtx; + //mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy); + //mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult); + //mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi); + //mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0); + //mtx *= agg::trans_affine_translation(width*0.3, height/2); + mtx *= agg::trans_affine_translation(myRenderer.m_size.x*0.5, myRenderer.m_size.x/2); + + // This code renders the lion: + agg::conv_transform trans(path, mtx); + + agg::render_all_paths( myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea, trans, &colorsList[0], &pathListId[0], pathListId.Size()); } - diff --git a/Sources/libparsersvg/parserSVG/Polygon.h b/Sources/libparsersvg/parserSVG/Polygon.h index 352b050f..b2ece77c 100644 --- a/Sources/libparsersvg/parserSVG/Polygon.h +++ b/Sources/libparsersvg/parserSVG/Polygon.h @@ -44,7 +44,7 @@ namespace svg ~Polygon(void); virtual bool Parse(TiXmlNode * node); virtual void Display(int32_t spacing); - virtual void AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp); + virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp); }; }; diff --git a/Sources/libparsersvg/parserSVG/Rectangle.cpp b/Sources/libparsersvg/parserSVG/Rectangle.cpp index 73f1ffa8..267a1665 100644 --- a/Sources/libparsersvg/parserSVG/Rectangle.cpp +++ b/Sources/libparsersvg/parserSVG/Rectangle.cpp @@ -56,6 +56,14 @@ bool svg::Rectangle::Parse(TiXmlNode * node) ParsePosition(node, m_position, m_size); + const char * content = node->ToElement()->Attribute("rx"); + if (NULL != content) { + m_roundedCorner.x = ParseLength(content); + } + content = node->ToElement()->Attribute("ry"); + if (NULL != content) { + m_roundedCorner.y = ParseLength(content); + } return true; } @@ -65,33 +73,40 @@ void svg::Rectangle::Display(int32_t spacing) } - -void svg::Rectangle::AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp) +void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp) { - if (m_size.x<=0 && m_size.y<=0) { - // nothing to draw ... - return; - } - AggCheckChange(path, colors, pathIdx, curentPaintProp); - #if 1 - path.move_to(m_position.x, m_position.y); - //path.move_to(0, 0); - path.line_rel(m_size.x, 0); - path.line_rel(0, m_size.y); - path.line_rel(-m_size.x, 0); - path.line_rel(0, -m_size.y); - path.close_polygon(); - #else - + myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); // Creating a rounded rectangle - agg::rounded_rect r(m_position.x, m_position.y, m_size.x, m_size.y, m_roundedCorner.x); - r.normalize_radius(); + agg::rounded_rect rect_r(m_position.x, m_position.y, m_size.x, m_size.y, m_roundedCorner.x); + rect_r.radius(m_roundedCorner.x, m_roundedCorner.y); + rect_r.normalize_radius(); - // Drawing as an outline - agg::conv_stroke p(r); - p.width(1.0); - path.add_path(p); - #endif + myRenderer.m_rasterizer.add_path(rect_r); + agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); + + 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)); + // Drawing as an outline + agg::conv_stroke rect_p(rect_r); + rect_p.width(m_paint.strokeWidth); + myRenderer.m_rasterizer.add_path(rect_p); + agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); + } + + /* + agg::trans_affine mtx; + //mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy); + //mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult); + //mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi); + //mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0); + //mtx *= agg::trans_affine_translation(width*0.3, height/2); + mtx *= agg::trans_affine_translation(myRenderer.m_size.x*0.5, myRenderer.m_size.x/2); + + // This code renders the lion: + agg::conv_transform trans(path, mtx); + + agg::render_all_paths( myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea, trans, &colorsList[0], &pathListId[0], pathListId.Size()); + */ + } - diff --git a/Sources/libparsersvg/parserSVG/Rectangle.h b/Sources/libparsersvg/parserSVG/Rectangle.h index f163bc6a..b806d7af 100644 --- a/Sources/libparsersvg/parserSVG/Rectangle.h +++ b/Sources/libparsersvg/parserSVG/Rectangle.h @@ -40,7 +40,7 @@ namespace svg ~Rectangle(void); virtual bool Parse(TiXmlNode * node); virtual void Display(int32_t spacing); - virtual void AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp); + virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp); }; }; diff --git a/Sources/libparsersvg/parserSVG/Renderer.cpp b/Sources/libparsersvg/parserSVG/Renderer.cpp new file mode 100644 index 00000000..32c81d52 --- /dev/null +++ b/Sources/libparsersvg/parserSVG/Renderer.cpp @@ -0,0 +1,107 @@ +/** + ******************************************************************************* + * @file parserSVG/Renderer.cpp + * @brief Basic SVG renderer for the AGG librairy (Sources) + * @author Edouard DUPIN + * @date 23/03/2012 + * @par Project + * parserSVG + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include + +// 4 is for the RGBA ... +#define DATA_ALLOCATION_ELEMENT (4) + +svg::Renderer::Renderer(uint32_t width, uint32_t height) +{ + m_size.x = width; + m_size.y = height; + + int32_t dataSize = ((int32_t)width * (int32_t)height * DATA_ALLOCATION_ELEMENT); + + // allocate Data + SVG_DEBUG("Allocate buffer : " << dataSize); + + ETK_MALLOC(m_buffer, dataSize, uint8_t); + if (NULL == m_buffer) { + SVG_ERROR("Allocation of the output buffer for SVG drawing error"); + return; + } + + memset(m_buffer, 0xFF, dataSize * sizeof(uint8_t) ); + + m_renderingBuffer = new agg::rendering_buffer(m_buffer, m_size.x, m_size.y, m_size.x * DATA_ALLOCATION_ELEMENT); + if (NULL == m_renderingBuffer) { + SVG_ERROR("Allocation of the m_renderingBuffer for SVG drawing error"); + return; + } + + m_pixFrame = new agg::pixfmt_rgba32(*m_renderingBuffer); + if (NULL == m_pixFrame) { + SVG_ERROR("Allocation of the m_pixFrame for SVG drawing error"); + return; + } + + m_renderBase = new rendererBase_t(*m_pixFrame); + if (NULL == m_renderBase) { + SVG_ERROR("Allocation of the m_renderBase for SVG drawing error"); + return; + } + + m_renderArea = new rendererSolid_t(*m_renderBase); + if (NULL == m_renderArea) { + SVG_ERROR("Allocation of the m_renderArea for SVG drawing error"); + return; + } + + //m_basicMatrix *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2); + //m_basicMatrix *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult); + //m_basicMatrix *= agg::trans_affine_rotation(g_angle);// + agg::pi); + //m_basicMatrix *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0); + m_basicMatrix *= agg::trans_affine_translation(m_size.x*0.7, m_size.y/2); +} + +svg::Renderer::~Renderer(void) +{ + if (NULL != m_buffer) { + ETK_FREE(m_buffer); + m_buffer = NULL; + } +} + +// Writing the buffer to a .PPM file, assuming it has +// RGB-structure, one byte per color component +//-------------------------------------------------- +void svg::Renderer::WritePpm(etk::UString fileName) +{ + if (NULL == m_buffer) { + return; + } + FILE* fd = fopen(fileName.Utf8Data(), "wb"); + if(NULL != fd) { + int32_t sizeX = m_size.x; + int32_t sizeY = m_size.y; + SVG_DEBUG("Generate ppm : " << m_size); + fprintf(fd, "P6 %d %d 255 ", sizeX, sizeY); + for (int32_t iii=0 ; iii + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace svg +{ + #define MATRIX_SIZE (6) + class PaintState { + public : + PaintState(void) {}; + ~PaintState(void) {}; + color8_ts fill; + color8_ts stroke; + etkFloat_t strokeWidth; + coord2D_ts viewPort; + etkFloat_t matrix[MATRIX_SIZE]; + etkFloat_t opacity; //!< opacity on the result drawing ... + bool operator!= (const svg::PaintState& paintExt) const + { + if( fill.red != paintExt.fill.red + || fill.green != paintExt.fill.green + || fill.blue != paintExt.fill.blue + || fill.alpha != paintExt.fill.alpha) { + return true; + } + if( stroke.red != paintExt.stroke.red + || stroke.green != paintExt.stroke.green + || stroke.blue != paintExt.stroke.blue + || stroke.alpha != paintExt.stroke.alpha) { + return true; + } + if (strokeWidth != paintExt.strokeWidth) { + return true; + } + if( viewPort.x != paintExt.viewPort.x + || viewPort.y != paintExt.viewPort.y) { + return true; + } + if( matrix[0] != paintExt.matrix[0] + || matrix[1] != paintExt.matrix[1] + || matrix[2] != paintExt.matrix[2] + || matrix[3] != paintExt.matrix[3] + || matrix[4] != paintExt.matrix[4] + || matrix[5] != paintExt.matrix[5]) { + return true; + } + return false; + } + }; + + // basic definition type for the renderer + typedef agg::renderer_base rendererBase_t; + typedef agg::renderer_scanline_aa_solid rendererSolid_t; + + class Renderer { + private: + uint8_t * m_buffer; + public: + Renderer(uint32_t width, uint32_t height); + ~Renderer(void); + void WritePpm(etk::UString fileName); + coord2D_ts m_size; + agg::rendering_buffer * m_renderingBuffer; + agg::pixfmt_rgba32 * m_pixFrame; + rendererBase_t * m_renderBase; + rendererSolid_t * m_renderArea; + agg::rasterizer_scanline_aa<> m_rasterizer; //!< AGG renderer system + agg::scanline_p8 m_scanLine; //!< + agg::trans_affine m_basicMatrix; //!< specific render of the curent element + }; +}; + +#endif diff --git a/Sources/libparsersvg/parserSVG/parserSVG.cpp b/Sources/libparsersvg/parserSVG/parserSVG.cpp index 4fd8b3ea..ee6c42a5 100644 --- a/Sources/libparsersvg/parserSVG/parserSVG.cpp +++ b/Sources/libparsersvg/parserSVG/parserSVG.cpp @@ -219,28 +219,6 @@ bool write_ppm(const unsigned char* buf, typedef agg::rgba8 color_type; -////////////////////////////////////////////////////////////////////////////////// -// Start of AGG abstraction for SVG render ... - -typedef agg::renderer_base rendererBase_t; -typedef agg::renderer_scanline_aa_solid rendererSolid_t; -class Renderer { - private: - char * m_buffer; - public: - Renderer(uint32_t width, uint32_t height); - ~Renderer(void); - uint32_t m_sizeX; - uint32_t m_sizeY; - rendererSolid_t * m_renderArea; - agg::rasterizer_scanline_aa<> m_rasterizer; //!< AGG renderer system - agg::scanline_p8 m_scanLine; //!< - agg::trans_affine m_basicMatrix; //!< specific render of the curent element -}; - -////////////////////////////////////////////////////////////////////////////////// - - agg::rasterizer_scanline_aa<> g_rasterizer; agg::scanline_p8 g_scanline; agg::path_storage g_path; @@ -479,94 +457,30 @@ uint32_t parse_lion(agg::path_storage& path, etk::VectorType &colors return pathIdx.Size(); } - -void svg::Parser::AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp) +void svg::Parser::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp) { - SVG_ERROR("printed color X = " << m_paint.fill); - colors.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); - uint32_t tmpPathNew = path.start_new_path(); - pathIdx.PushBack(tmpPathNew); + curentPaintProp = m_paint; for (int32_t iii=0; iiiAggDraw(path, colors, pathIdx, curentPaintProp); + m_subElementList[iii]->AggDraw(myRenderer, curentPaintProp); } } - // this permit to have not the display of the layer substraction ... - path.arrange_orientations_all_paths(agg::path_flags_cw); - } -#include -#include void svg::Parser::GenerateTestFile(void) { - g_path.remove_all(); - g_colorsList.Clear(); - g_pathLdxList.Clear(); - uint32_t g_npaths = parse_lion(g_path, g_colorsList, g_pathLdxList); - agg::pod_array_adaptor path_idx(&g_pathLdxList[0], g_npaths); - agg::bounding_rect(g_path, path_idx, 0, g_npaths, &g_x1, &g_y1, &g_x2, &g_y2); - g_base_dx = (g_x2 - g_x1) / 2.0; - g_base_dy = (g_y2 - g_y1) / 2.0; - - g_path2.remove_all(); - g_colorsList2.Clear(); - g_pathLdxList2.Clear(); - PaintState curentPaintProp; - AggDraw(g_path2, g_colorsList2, g_pathLdxList2, curentPaintProp); - agg::pod_array_adaptor path_idx2(&g_pathLdxList2[0], g_pathLdxList2.Size() ); - agg::bounding_rect(g_path2, path_idx2, 0, g_pathLdxList2.Size(), &g_x12, &g_y12, &g_x22, &g_y22); - g_base_dx2 = (g_x22 - g_x12) / 2.0; - g_base_dy2 = (g_y22 - g_y12) / 2.0; - float coefmult = 2; int width = 800*coefmult; int height = 600*coefmult; - unsigned char* buffer = new unsigned char[width * height * 4]; - memset(buffer, 255, width * height * 4); - - agg::rendering_buffer rbuf(buffer, width, height, width * 4); - agg::pixfmt_rgba32 pixf(rbuf); - renderer_base rb(pixf); - renderer_solid r(rb); + svg::Renderer * myRenderer = new svg::Renderer(width,height); + AggDraw(*myRenderer, m_paint); + etk::UString tmpFileOut = "yyy_out_"; + tmpFileOut += m_fileName.GetShortFilename(); + tmpFileOut += ".ppm"; + myRenderer->WritePpm(tmpFileOut); - agg::trans_affine mtx; - mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy); - mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult); - mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi); - mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0); - mtx *= agg::trans_affine_translation(width*0.3, height/2); - - // This code renders the lion: - agg::conv_transform trans(g_path, mtx); - agg::render_all_paths(g_rasterizer, g_scanline, r, trans, &g_colorsList[0], &g_pathLdxList[0], g_npaths); - // This code renders a second svg syctem ...: - - agg::trans_affine mtx2; - mtx2 *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2); - mtx2 *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult); - mtx2 *= agg::trans_affine_rotation(g_angle);// + agg::pi); - mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0); - mtx2 *= agg::trans_affine_translation(width*0.7, height/2); - - agg::conv_transform trans2(g_path2, mtx2); - agg::render_all_paths(g_rasterizer, g_scanline, r, trans2, &g_colorsList2[0], &g_pathLdxList2[0], g_pathLdxList2.Size()); - - // Creating a rounded rectangle - agg::rounded_rect rect_r(50, 50, 100, 120, 18); - rect_r.normalize_radius(); - // Drawing as an outline - agg::conv_stroke rect_p(rect_r); - rect_p.width(1.0); - g_rasterizer.add_path(rect_p); - agg::render_scanlines(g_rasterizer, g_scanline, r); - - etk::UString tmpFileOut = etk::UString("zzz_out_") + m_fileName.GetShortFilename() + ".ppm"; - write_ppm(buffer, width, height, tmpFileOut.Utf8Data()); - - delete [] buffer; } diff --git a/Sources/libparsersvg/parserSVG/parserSVG.h b/Sources/libparsersvg/parserSVG/parserSVG.h index a317f75d..174d82fb 100644 --- a/Sources/libparsersvg/parserSVG/parserSVG.h +++ b/Sources/libparsersvg/parserSVG/parserSVG.h @@ -45,7 +45,7 @@ namespace svg bool IsLoadOk(void) { return m_loadOK; }; void DisplayDebug(void); void GenerateTestFile(void); - virtual void AggDraw(agg::path_storage& path, etk::VectorType &colors, etk::VectorType &pathIdx, PaintState &curentPaintProp); + virtual void AggDraw(svg::Renderer& myRenderer, PaintState &curentPaintProp); }; };