summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a52ac14)
raw | patch | inline | side by side (parent: a52ac14)
author | pjrm <pjrm@users.sourceforge.net> | |
Mon, 25 Jun 2007 11:12:09 +0000 (11:12 +0000) | ||
committer | pjrm <pjrm@users.sourceforge.net> | |
Mon, 25 Jun 2007 11:12:09 +0000 (11:12 +0000) |
src/helper/png-write.cpp | patch | blob | history |
index 06f736343b8c7732ad99cb82b22fba59f5d42ba3..fb428644ceadceeb5461779fd5fa0b804dd94b26 100644 (file)
--- a/src/helper/png-write.cpp
+++ b/src/helper/png-write.cpp
/* write a png file */
typedef struct SPPNGBD {
- guchar const *px;
- int rowstride;
+ guchar const *px;
+ int rowstride;
} SPPNGBD;
static int
-sp_png_get_block_stripe (guchar const **rows, int row, int num_rows, void *data)
+sp_png_get_block_stripe(guchar const **rows, int row, int num_rows, void *data)
{
- SPPNGBD *bd = (SPPNGBD *) data;
+ SPPNGBD *bd = (SPPNGBD *) data;
- for (int r = 0; r < num_rows; r++) {
- rows[r] = bd->px + (row + r) * bd->rowstride;
- }
+ for (int r = 0; r < num_rows; r++) {
+ rows[r] = bd->px + (row + r) * bd->rowstride;
+ }
- return num_rows;
+ return num_rows;
}
int
sp_png_write_rgba(gchar const *filename, guchar const *px,
int width, int height, double xdpi, double ydpi, int rowstride)
{
- SPPNGBD bd;
+ SPPNGBD bd;
- bd.px = px;
- bd.rowstride = rowstride;
+ bd.px = px;
+ bd.rowstride = rowstride;
- return sp_png_write_rgba_striped (filename, width, height, xdpi, ydpi, sp_png_get_block_stripe, &bd);
+ return sp_png_write_rgba_striped(filename, width, height, xdpi, ydpi, sp_png_get_block_stripe, &bd);
}
int
-sp_png_write_rgba_striped (gchar const *filename, int width, int height, double xdpi, double ydpi,
- int (* get_rows) (guchar const **rows, int row, int num_rows, void *data),
- void *data)
+sp_png_write_rgba_striped(gchar const *filename, int width, int height, double xdpi, double ydpi,
+ int (* get_rows)(guchar const **rows, int row, int num_rows, void *data),
+ void *data)
{
struct SPEBP *ebp = (struct SPEBP *) data;
- FILE *fp;
- png_structp png_ptr;
- png_infop info_ptr;
- png_color_8 sig_bit;
- png_text text_ptr[3];
- png_uint_32 r;
-
- g_return_val_if_fail (filename != NULL, FALSE);
-
- /* open the file */
-
- Inkscape::IO::dump_fopen_call(filename, "M");
- fp = Inkscape::IO::fopen_utf8name(filename, "wb");
- g_return_val_if_fail (fp != NULL, FALSE);
-
- /* Create and initialize the png_struct with the desired error handler
- * functions. If you want to use the default stderr and longjump method,
- * you can supply NULL for the last three parameters. We also check that
- * the library version is compatible with the one used at compile time,
- * in case we are using dynamically linked libraries. REQUIRED.
- */
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-
- if (png_ptr == NULL) {
- fclose(fp);
- return FALSE;
- }
-
- /* Allocate/initialize the image information data. REQUIRED */
- info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL) {
- fclose(fp);
- png_destroy_write_struct(&png_ptr, NULL);
- return FALSE;
- }
-
- /* Set error handling. REQUIRED if you aren't supplying your own
- * error hadnling functions in the png_create_write_struct() call.
- */
- if (setjmp(png_ptr->jmpbuf)) {
- /* If we get here, we had a problem reading the file */
- fclose(fp);
- png_destroy_write_struct(&png_ptr, &info_ptr);
- return FALSE;
- }
-
- /* set up the output control if you are using standard C streams */
- png_init_io(png_ptr, fp);
-
- /* Set the image information here. Width and height are up to 2^31,
- * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
- * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
- * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
- * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
- * 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_IHDR(png_ptr, info_ptr,
- width,
- height,
- 8, /* bit_depth */
- PNG_COLOR_TYPE_RGB_ALPHA,
- 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);
-
- /* Made by Inkscape comment */
- text_ptr[0].key = "Software";
- text_ptr[0].text = "www.inkscape.org";
- text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
- png_set_text(png_ptr, info_ptr, text_ptr, 1);
-
- /* 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);
-
- /* Write the file header information. REQUIRED */
- png_write_info(png_ptr, info_ptr);
-
- /* Once we write out the header, the compression type on the text
- * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
- * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
- * at the end.
- */
-
- /* set up the transformations you want. Note that these are
- * all optional. Only call them if you want them.
- */
-
- /* --- CUT --- */
-
- /* The easiest way to write the image (you may have a different memory
- * layout, however, so choose what fits your needs best). You need to
- * use the first method if you aren't handling interlacing yourself.
- */
-
- png_bytep* row_pointers = new png_bytep[ebp->sheight];
-
- r = 0;
- while (r < static_cast< png_uint_32 > (height) ) {
- int n = get_rows ((unsigned char const **) row_pointers, r, height-r, data);
- if (!n) break;
- png_write_rows (png_ptr, row_pointers, n);
- r += n;
- }
+ FILE *fp;
+ png_structp png_ptr;
+ png_infop info_ptr;
+ png_color_8 sig_bit;
+ png_text text_ptr[3];
+ png_uint_32 r;
+
+ g_return_val_if_fail(filename != NULL, FALSE);
+
+ /* open the file */
+
+ Inkscape::IO::dump_fopen_call(filename, "M");
+ fp = Inkscape::IO::fopen_utf8name(filename, "wb");
+ g_return_val_if_fail(fp != NULL, FALSE);
+
+ /* Create and initialize the png_struct with the desired error handler
+ * functions. If you want to use the default stderr and longjump method,
+ * you can supply NULL for the last three parameters. We also check that
+ * the library version is compatible with the one used at compile time,
+ * in case we are using dynamically linked libraries. REQUIRED.
+ */
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ if (png_ptr == NULL) {
+ fclose(fp);
+ return FALSE;
+ }
+
+ /* Allocate/initialize the image information data. REQUIRED */
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL) {
+ fclose(fp);
+ png_destroy_write_struct(&png_ptr, NULL);
+ return FALSE;
+ }
+
+ /* Set error handling. REQUIRED if you aren't supplying your own
+ * error hadnling functions in the png_create_write_struct() call.
+ */
+ if (setjmp(png_ptr->jmpbuf)) {
+ /* If we get here, we had a problem reading the file */
+ fclose(fp);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ return FALSE;
+ }
+
+ /* set up the output control if you are using standard C streams */
+ png_init_io(png_ptr, fp);
+
+ /* Set the image information here. Width and height are up to 2^31,
+ * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
+ * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
+ * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
+ * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
+ * 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_IHDR(png_ptr, info_ptr,
+ width,
+ height,
+ 8, /* bit_depth */
+ PNG_COLOR_TYPE_RGB_ALPHA,
+ 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);
+
+ /* Made by Inkscape comment */
+ text_ptr[0].key = "Software";
+ text_ptr[0].text = "www.inkscape.org";
+ text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
+ png_set_text(png_ptr, info_ptr, text_ptr, 1);
+
+ /* 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);
+
+ /* Write the file header information. REQUIRED */
+ png_write_info(png_ptr, info_ptr);
+
+ /* Once we write out the header, the compression type on the text
+ * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
+ * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
+ * at the end.
+ */
+
+ /* set up the transformations you want. Note that these are
+ * all optional. Only call them if you want them.
+ */
+
+ /* --- CUT --- */
+
+ /* The easiest way to write the image (you may have a different memory
+ * layout, however, so choose what fits your needs best). You need to
+ * use the first method if you aren't handling interlacing yourself.
+ */
+
+ png_bytep* row_pointers = new png_bytep[ebp->sheight];
+
+ r = 0;
+ while (r < static_cast< png_uint_32 > (height) ) {
+ int n = get_rows((unsigned char const **) row_pointers, r, height-r, data);
+ if (!n) break;
+ png_write_rows(png_ptr, row_pointers, n);
+ r += n;
+ }
delete[] row_pointers;
- /* You can write optional chunks like tEXt, zTXt, and tIME at the end
- * as well.
- */
+ /* You can write optional chunks like tEXt, zTXt, and tIME at the end
+ * as well.
+ */
- /* It is REQUIRED to call this to finish writing the rest of the file */
- png_write_end(png_ptr, info_ptr);
+ /* It is REQUIRED to call this to finish writing the rest of the file */
+ png_write_end(png_ptr, info_ptr);
- /* if you allocated any text comments, free them here */
+ /* if you allocated any text comments, free them here */
- /* clean up after the write, and free any memory allocated */
- png_destroy_write_struct(&png_ptr, &info_ptr);
+ /* clean up after the write, and free any memory allocated */
+ png_destroy_write_struct(&png_ptr, &info_ptr);
- /* close the file */
- fclose(fp);
+ /* close the file */
+ fclose(fp);
- /* that's it */
- return TRUE;
+ /* that's it */
+ return TRUE;
}
}
/**
-Hide all items which are not listed in list, recursively, skipping groups and defs
-*/
+ * Hide all items that are not listed in list, recursively, skipping groups and defs.
+ */
static void
hide_other_items_recursively(SPObject *o, GSList *list, unsigned dkey)
{
- if (SP_IS_ITEM(o)
- && !SP_IS_DEFS(o)
- && !SP_IS_ROOT(o)
- && !SP_IS_GROUP(o)
- && !g_slist_find(list, o))
+ if ( SP_IS_ITEM(o)
+ && !SP_IS_DEFS(o)
+ && !SP_IS_ROOT(o)
+ && !SP_IS_GROUP(o)
+ && !g_slist_find(list, o) )
{
sp_item_invoke_hide(SP_ITEM(o), dkey);
}
- // recurse
+ // recurse
if (!g_slist_find(list, o)) {
for (SPObject *child = sp_object_first_child(o) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
hide_other_items_recursively(child, list, dkey);
}
// export with maximum blur rendering quality
- int saved_quality = prefs_get_int_attribute ("options.blurquality", "value", 0);
- prefs_set_int_attribute ("options.blurquality", "value", 2);
+ int saved_quality = prefs_get_int_attribute("options.blurquality", "value", 0);
+ prefs_set_int_attribute("options.blurquality", "value", 2);
sp_document_ensure_up_to_date(doc);
nr_object_unref((NRObject *) arena);
// restore saved blur quality
- prefs_set_int_attribute ("options.blurquality", "value", saved_quality);
+ prefs_set_int_attribute("options.blurquality", "value", saved_quality);
return write_status;
}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :