summaryrefslogtreecommitdiff
path: root/gdk-pixbuf
diff options
context:
space:
mode:
authorSven Neumann <sven@gimp.org>2005-05-24 17:09:56 +0000
committerSven Neumann <neo@src.gnome.org>2005-05-24 17:09:56 +0000
commit3bc682d0122ba5f5f644e7ceffc4e44c6c6cf68f (patch)
treece7c8b262229563fd9af2fc1f0bce23247adf286 /gdk-pixbuf
parente7a0b015f6246dbc31da43edba7f68b8defc21c5 (diff)
downloadgtk+-3bc682d0122ba5f5f644e7ceffc4e44c6c6cf68f.tar.gz
allow to specify the PNG compression level by passing a "compression"
2005-05-24 Sven Neumann <sven@gimp.org> * io-png.c: allow to specify the PNG compression level by passing a "compression" parameter to the PNG save function (bug #305337). * gdk-pixbuf-io.c (gdk_pixbuf_save): document the new parameter.
Diffstat (limited to 'gdk-pixbuf')
-rw-r--r--gdk-pixbuf/ChangeLog7
-rw-r--r--gdk-pixbuf/gdk-pixbuf-io.c10
-rw-r--r--gdk-pixbuf/io-png.c74
3 files changed, 67 insertions, 24 deletions
diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog
index d26f4a6a53..05bcfb5cc5 100644
--- a/gdk-pixbuf/ChangeLog
+++ b/gdk-pixbuf/ChangeLog
@@ -1,3 +1,10 @@
+2005-05-24 Sven Neumann <sven@gimp.org>
+
+ * io-png.c: allow to specify the PNG compression level by passing
+ a "compression" parameter to the PNG save function (bug #305337).
+
+ * gdk-pixbuf-io.c (gdk_pixbuf_save): document the new parameter.
+
2005-04-09 Matthias Clasen <mclasen@redhat.com>
* Makefile.am: Use $(NM), not nm directly. (#301299,
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index 653315e266..76b91653e3 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -1556,11 +1556,15 @@ gdk_pixbuf_real_save_to_callback (GdkPixbuf *pixbuf,
* "quality", "100", NULL);
* </programlisting></informalexample>
*
- * Currently only few parameters exist. JPEG images can be saved with a
- * "quality" parameter; its value should be in the range [0,100].
+ * Currently only few parameters exist. JPEG images can be saved with a
+ * "quality" parameter; its value should be in the range [0,100].
+ *
* Text chunks can be attached to PNG images by specifying parameters of
* the form "tEXt::key", where key is an ASCII string of length 1-79.
- * The values are UTF-8 encoded strings.
+ * The values are UTF-8 encoded strings. The PNG compression level can
+ * be specified using the "compression" parameter; it's value is in an
+ * integer in the range of [0,9].
+ *
* ICO images can be saved in depth 16, 24, or 32, by using the "depth"
* parameter. When the ICO saver is given "x_hot" and "y_hot" parameters,
* it produces a CUR instead of an ICO.
diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c
index 7e9fb36de1..25a2bb6060 100644
--- a/gdk-pixbuf/io-png.c
+++ b/gdk-pixbuf/io-png.c
@@ -789,40 +789,69 @@ static gboolean real_save_png (GdkPixbuf *pixbuf,
int has_alpha;
int bpc;
int num_keys;
+ int compression = -1;
gboolean success = TRUE;
SaveToFunctionIoPtr to_callback_ioptr;
num_keys = 0;
if (keys && *keys) {
- gchar **kiter;
- gchar *key;
- int len;
+ gchar **kiter = keys;
+ gchar **viter = values;
+
+ while (*kiter) {
+ if (strncmp (*kiter, "tEXt::", 6) == 0) {
+ gchar *key = *kiter + 6;
+ int len = strlen (key);
+ if (len <= 1 || len > 79) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_BAD_OPTION,
+ _("Keys for PNG text chunks must have at least 1 and at most 79 characters."));
+ return FALSE;
+ }
+ for (i = 0; i < len; i++) {
+ if ((guchar) key[i] > 127) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_BAD_OPTION,
+ _("Keys for PNG text chunks must be ASCII characters."));
+ return FALSE;
+ }
+ }
+ num_keys++;
+ } else if (strcmp (*kiter, "compression") == 0) {
+ char *endptr = NULL;
+ compression = strtol (*viter, &endptr, 10);
- for (kiter = keys; *kiter; kiter++) {
- if (strncmp (*kiter, "tEXt::", 6) != 0) {
- g_warning ("Bad option name '%s' passed to PNG saver", *kiter);
- return FALSE;
- }
- key = *kiter + 6;
- len = strlen (key);
- if (len <= 1 || len > 79) {
- g_set_error (error,
- GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_BAD_OPTION,
- _("Keys for PNG text chunks must have at least 1 and at most 79 characters."));
- return FALSE;
- }
- for (i = 0; i < len; i++) {
- if ((guchar) key[i] > 127) {
+ if (endptr == *viter) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_BAD_OPTION,
+ _("PNG compression level must be a value between 0 and 9; value '%s' could not be parsed."),
+ *viter);
+ return FALSE;
+ }
+ if (compression < 0 || compression > 9) {
+ /* This is a user-visible error;
+ * lets people skip the range-checking
+ * in their app.
+ */
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_BAD_OPTION,
- _("Keys for PNG text chunks must be ASCII characters."));
+ _("PNG compression level must be a value between 0 and 9; value '%d' is not allowed."),
+ compression);
return FALSE;
}
+ } else {
+ g_warning ("Bad option name '%s' passed to PNG saver",
+ *kiter);
+ return FALSE;
}
- num_keys++;
+
+ ++kiter;
+ ++viter;
}
}
@@ -900,6 +929,9 @@ static gboolean real_save_png (GdkPixbuf *pixbuf,
png_init_io (png_ptr, f);
}
+ if (compression >= 0)
+ png_set_compression_level (png_ptr, compression);
+
if (has_alpha) {
png_set_IHDR (png_ptr, info_ptr, w, h, bpc,
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,