From d1947e768272c703674129d5c583204ff2b59251 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 13 Jul 2016 13:36:19 +0200 Subject: Second part of new SPObject children list (bzr r14954.1.19) --- src/helper/png-write.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 9430feeff..c59db9df6 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -374,8 +374,8 @@ static void hide_other_items_recursively(SPObject *o, const std::vector // recurse if (list.end()==find(list.begin(),list.end(),o)) { - for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) { - hide_other_items_recursively(child, list, dkey); + for (auto& child: o->_children) { + hide_other_items_recursively(&child, list, dkey); } } } -- cgit v1.2.3 From 24d3f50003ca3cec6a03a7f5267cc4fe5588c69f Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 13:17:21 +0200 Subject: Renamed children list in SPObject (bzr r14954.1.21) --- src/helper/png-write.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index c59db9df6..2255157e2 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -374,7 +374,7 @@ static void hide_other_items_recursively(SPObject *o, const std::vector // recurse if (list.end()==find(list.begin(),list.end(),o)) { - for (auto& child: o->_children) { + for (auto& child: o->children) { hide_other_items_recursively(&child, list, dkey); } } -- cgit v1.2.3 From f35bb1f74a0ffeb5c6477a25e3c4cde87a97bcf1 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 12:06:06 +0200 Subject: Removed unused includes, decrease compilation time (bzr r15025) --- src/helper/png-write.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 9430feeff..e2b7e5b8c 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -14,19 +14,17 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include "ui/interface.h" #include <2geom/rect.h> #include <2geom/transforms.h> -#include #include "png-write.h" #include "io/sys.h" #include "display/drawing.h" #include "display/drawing-context.h" -#include "display/drawing-item.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" -- cgit v1.2.3 From 43b49e325db73cc19b1731db6c69545664ee8fbe Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 13:26:17 +0200 Subject: Reverted changes to r15024 after many building problems (bzr r15027) --- src/helper/png-write.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index e2b7e5b8c..9430feeff 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -14,17 +14,19 @@ */ #ifdef HAVE_CONFIG_H -#include +# include "config.h" #endif #include #include "ui/interface.h" #include <2geom/rect.h> #include <2geom/transforms.h> +#include #include "png-write.h" #include "io/sys.h" #include "display/drawing.h" #include "display/drawing-context.h" +#include "display/drawing-item.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" -- cgit v1.2.3 From 35830f456cadaecf8b8e3944e3031a1a93f6cb41 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 3 Aug 2016 15:29:38 +0200 Subject: Removed unused includes, decreased compilation time. Once again (bzr r15034) --- src/helper/png-write.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 9430feeff..e2b7e5b8c 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -14,19 +14,17 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include "ui/interface.h" #include <2geom/rect.h> #include <2geom/transforms.h> -#include #include "png-write.h" #include "io/sys.h" #include "display/drawing.h" #include "display/drawing-context.h" -#include "display/drawing-item.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" -- cgit v1.2.3 From ee2e7c9c9907008de656773b98e1239a7f1af2a9 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sun, 25 Sep 2016 23:59:45 +0200 Subject: Exposes to the user additional PNG settings: Interlacing, grayscale, bit depth, alpha, compression level, PNG pHYs dpi. Fixed bugs: - https://launchpad.net/bugs/170650 (bzr r15131) --- src/helper/png-write.cpp | 77 +++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 31 deletions(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 682aee9b2..f270dcc95 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -123,8 +123,8 @@ void PngTextList::add(gchar const* key, gchar const* text) static bool sp_png_write_rgba_striped(SPDocument *doc, gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, - int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data), - void *data) + int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth), + void *data, bool interlace, int color_type, int bit_depth, int zlib) { g_return_val_if_fail(filename != NULL, false); g_return_val_if_fail(data != NULL, false); @@ -184,22 +184,28 @@ sp_png_write_rgba_striped(SPDocument *doc, * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED */ + + png_set_compression_level(png_ptr, zlib); + png_set_IHDR(png_ptr, info_ptr, width, height, - 8, /* bit_depth */ - PNG_COLOR_TYPE_RGB_ALPHA, - PNG_INTERLACE_NONE, + bit_depth, + color_type, + interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - /* otherwise, if we are dealing with a color image then */ - sig_bit.red = 8; - sig_bit.green = 8; - sig_bit.blue = 8; - /* if the image has an alpha channel then */ - sig_bit.alpha = 8; - png_set_sBIT(png_ptr, info_ptr, &sig_bit); + if ((color_type&2) && bit_depth == 16) { + // otherwise, if we are dealing with a color image then + sig_bit.red = 8; + sig_bit.green = 8; + sig_bit.blue = 8; + // if the image has an alpha channel then + if (color_type&4) + sig_bit.alpha = 8; + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + } PngTextList textList; @@ -248,7 +254,10 @@ sp_png_write_rgba_striped(SPDocument *doc, /* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */ /* note that if sRGB is present the cHRM chunk must be ignored * on read and must be written in accordance with the sRGB profile */ - png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 + 0.5), unsigned(ydpi / 0.0254 + 0.5), PNG_RESOLUTION_METER); + if(xdpi < 0.0254 ) xdpi = 0.0255; + if(ydpi < 0.0254 ) ydpi = 0.0255; + + png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 ), unsigned(ydpi / 0.0254 ), PNG_RESOLUTION_METER); /* Write the file header information. REQUIRED */ png_write_info(png_ptr, info_ptr); @@ -271,15 +280,18 @@ sp_png_write_rgba_striped(SPDocument *doc, */ png_bytep* row_pointers = new png_bytep[ebp->sheight]; - - r = 0; - while (r < static_cast(height)) { - void *to_free; - int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data); - if (!n) break; - png_write_rows(png_ptr, row_pointers, n); - g_free(to_free); - r += n; + int number_of_passes = interlace ? png_set_interlace_handling(png_ptr) : 1; + + for(int i=0;i(height)) { + void *to_free; + int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth); + if (!n) break; + png_write_rows(png_ptr, row_pointers, n); + g_free(to_free); + r += n; + } } delete[] row_pointers; @@ -308,7 +320,7 @@ sp_png_write_rgba_striped(SPDocument *doc, * */ static int -sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data) +sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth) { struct SPEBP *ebp = (struct SPEBP *) data; @@ -343,14 +355,17 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v ebp->drawing->render(dc, bbox); cairo_surface_destroy(s); - *to_free = px; - // PNG stores data as unpremultiplied big-endian RGBA, which means // it's identical to the GdkPixbuf format. convert_pixels_argb32_to_pixbuf(px, ebp->width, num_rows, stride); + + *to_free = px; - for (int r = 0; r < num_rows; r++) { - rows[r] = px + r * stride; + // If a custom bit depth or color type is asked, then convert rgb to grayscale, etc. + if(color_type !=6 || bit_depth != 8){ + const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth); + *to_free = (void*) new_data; + free(px); } return num_rows; @@ -385,10 +400,10 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - const std::vector &items_only) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), - width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only); + width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib); } ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, @@ -397,7 +412,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - const std::vector &items_only) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); @@ -468,7 +483,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); if (ebp.px) { - write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); + write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib); g_free(ebp.px); } -- cgit v1.2.3 From efc66f4403df7128ef6ca2ac98893b477abff9bf Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 26 Sep 2016 00:50:43 +0200 Subject: minor fix (+ satisfy build bots (?)) (bzr r15132) --- src/helper/png-write.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index f270dcc95..2433e2777 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -359,14 +359,10 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v // it's identical to the GdkPixbuf format. convert_pixels_argb32_to_pixbuf(px, ebp->width, num_rows, stride); - *to_free = px; - // If a custom bit depth or color type is asked, then convert rgb to grayscale, etc. - if(color_type !=6 || bit_depth != 8){ - const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth); - *to_free = (void*) new_data; - free(px); - } + const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth); + *to_free = (void*) new_data; + free(px); return num_rows; } -- cgit v1.2.3 From b6200950a88ac9b1bb7eee4fb7f86b01e323dbcc Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 5 Jan 2017 00:08:02 +0100 Subject: antialiasing options on export (bzr r15391) --- src/helper/png-write.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/helper/png-write.cpp') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 2433e2777..e06c539d3 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -123,8 +123,8 @@ void PngTextList::add(gchar const* key, gchar const* text) static bool sp_png_write_rgba_striped(SPDocument *doc, gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, - int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth), - void *data, bool interlace, int color_type, int bit_depth, int zlib) + int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth, int antialias), + void *data, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing) { g_return_val_if_fail(filename != NULL, false); g_return_val_if_fail(data != NULL, false); @@ -286,7 +286,7 @@ sp_png_write_rgba_striped(SPDocument *doc, r = 0; while (r < static_cast(height)) { void *to_free; - int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth); + int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth, antialiasing); if (!n) break; png_write_rows(png_ptr, row_pointers, n); g_free(to_free); @@ -320,7 +320,7 @@ sp_png_write_rgba_striped(SPDocument *doc, * */ static int -sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth) +sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth, int antialiasing) { struct SPEBP *ebp = (struct SPEBP *) data; @@ -352,7 +352,7 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v dc.setOperator(CAIRO_OPERATOR_OVER); /* Render */ - ebp->drawing->render(dc, bbox); + ebp->drawing->render(dc, bbox, 0, antialiasing); cairo_surface_destroy(s); // PNG stores data as unpremultiplied big-endian RGBA, which means @@ -396,10 +396,10 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), - width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib); + width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib, antialiasing); } ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, @@ -408,7 +408,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); @@ -479,7 +479,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); if (ebp.px) { - write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib); + write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib, antialiasing); g_free(ebp.px); } -- cgit v1.2.3