[gdk-pixbuf] Fix denisty unit reading during incremental loading. Add tests for reading density units.
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] Fix denisty unit reading during incremental loading. Add tests for reading density units.
- Date: Wed, 22 Oct 2014 16:23:42 +0000 (UTC)
commit de9338004126415873d2db41d0fb9b41858c2d31
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 22 12:06:30 2014 -0400
Fix denisty unit reading during incremental loading. Add tests for reading density units.
gdk-pixbuf/io-jpeg.c | 22 ++++++++++
gdk-pixbuf/io-png.c | 16 ++++++++
tests/Makefile.am | 9 ++++
tests/dpi.jpeg | Bin 0 -> 1890 bytes
tests/dpi.png | Bin 0 -> 2723 bytes
tests/pixbuf-dpi.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 153 insertions(+), 0 deletions(-)
---
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c
index c43aee6..4fefb8c 100644
--- a/gdk-pixbuf/io-jpeg.c
+++ b/gdk-pixbuf/io-jpeg.c
@@ -923,6 +923,7 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
gint width, height;
char otag_str[5];
gchar *icc_profile_base64;
+ char *density_str;
JpegExifContext exif_context = { 0, };
gboolean retval;
@@ -1060,6 +1061,27 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
retval = FALSE;
goto out;
}
+
+ switch (cinfo->density_unit) {
+ case 1:
+ /* Dots per inch (no conversion required) */
+ density_str = g_strdup_printf ("%d", cinfo->X_density);
+ gdk_pixbuf_set_option (context->pixbuf, "x-dpi", density_str);
+ g_free (density_str);
+ density_str = g_strdup_printf ("%d", cinfo->Y_density);
+ gdk_pixbuf_set_option (context->pixbuf, "y-dpi", density_str);
+ g_free (density_str);
+ break;
+ case 2:
+ /* Dots per cm - convert into dpi */
+ density_str = g_strdup_printf ("%d", DPCM_TO_DPI (cinfo->X_density));
+ gdk_pixbuf_set_option (context->pixbuf, "x-dpi", density_str);
+ g_free (density_str);
+ density_str = g_strdup_printf ("%d", DPCM_TO_DPI (cinfo->Y_density));
+ gdk_pixbuf_set_option (context->pixbuf, "y-dpi", density_str);
+ g_free (density_str);
+ break;
+ }
/* if orientation tag was found set an option to remember its value */
if (exif_context.orientation != 0) {
diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c
index c1e6bcd..7099f82 100644
--- a/gdk-pixbuf/io-png.c
+++ b/gdk-pixbuf/io-png.c
@@ -632,6 +632,10 @@ png_info_callback (png_structp png_read_ptr,
const gchar *icc_profile_title;
const gchar *icc_profile;
png_uint_32 icc_profile_size;
+ png_uint_32 x_resolution;
+ png_uint_32 y_resolution;
+ int unit_type;
+ gchar *density_str;
guint32 retval;
gint compression_type;
@@ -711,6 +715,18 @@ png_info_callback (png_structp png_read_ptr,
}
#endif
+#ifdef PNG_pHYs_SUPPORTED
+ retval = png_get_pHYs (png_read_ptr, png_info_ptr, &x_resolution, &y_resolution, &unit_type);
+ if (retval != 0 && unit_type == PNG_RESOLUTION_METER) {
+ density_str = g_strdup_printf ("%d", DPM_TO_DPI (x_resolution));
+ gdk_pixbuf_set_option (lc->pixbuf, "x-dpi", density_str);
+ g_free (density_str);
+ density_str = g_strdup_printf ("%d", DPM_TO_DPI (y_resolution));
+ gdk_pixbuf_set_option (lc->pixbuf, "y-dpi", density_str);
+ g_free (density_str);
+ }
+#endif
+
/* Notify the client that we are ready to go */
if (lc->prepare_func)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1c17877..868da9d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,6 +28,7 @@ test_programs = \
pixbuf-randomly-modified \
pixbuf-threads \
pixbuf-icc \
+ pixbuf-dpi \
pixbuf-stream \
pixbuf-resource \
pixbuf-scale \
@@ -41,6 +42,8 @@ dist_installed_test_data = \
test-animation.ani \
icc-profile.jpeg \
icc-profile.png \
+ dpi.jpeg \
+ dpi.png \
$(wildcard $(srcdir)/test-images/*)
pixbuf_icc_SOURCES = \
@@ -49,6 +52,12 @@ pixbuf_icc_SOURCES = \
test-common.h \
$(NULL)
+pixbuf_dpi_SOURCES = \
+ pixbuf-dpi.c \
+ test-common.c \
+ test-common.h \
+ $(NULL)
+
pixbuf_scale_SOURCES = \
pixbuf-scale.c \
test-common.c \
diff --git a/tests/dpi.jpeg b/tests/dpi.jpeg
new file mode 100644
index 0000000..b70d167
Binary files /dev/null and b/tests/dpi.jpeg differ
diff --git a/tests/dpi.png b/tests/dpi.png
new file mode 100644
index 0000000..33aaf44
Binary files /dev/null and b/tests/dpi.png differ
diff --git a/tests/pixbuf-dpi.c b/tests/pixbuf-dpi.c
new file mode 100644
index 0000000..51613e0
--- /dev/null
+++ b/tests/pixbuf-dpi.c
@@ -0,0 +1,106 @@
+/* -*- Mode: C; c-basic-offset: 2; -*- */
+/* GdkPixbuf library - test loaders
+ *
+ * Copyright (C) 2014 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Robert Ancell
+ */
+
+#include <string.h>
+
+#include "config.h"
+#include "gdk-pixbuf/gdk-pixbuf.h"
+#include "test-common.h"
+
+static void
+test_incremental (gconstpointer data)
+{
+ const gchar *filename = data;
+ GdkPixbufLoader *loader;
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ const gchar *x_dpi, *y_dpi;
+ gchar *contents;
+ gsize size;
+
+ if (!format_supported (filename))
+ {
+ g_test_skip ("format not supported");
+ return;
+ }
+
+ g_file_get_contents (g_test_get_filename (G_TEST_DIST, filename, NULL), &contents, &size, &error);
+ g_assert_no_error (error);
+
+ loader = gdk_pixbuf_loader_new ();
+
+ gdk_pixbuf_loader_write (loader, (const guchar*)contents, size, &error);
+ g_assert_no_error (error);
+
+ gdk_pixbuf_loader_close (loader, &error);
+ g_assert_no_error (error);
+
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+ x_dpi = gdk_pixbuf_get_option (pixbuf, "x-dpi");
+ y_dpi = gdk_pixbuf_get_option (pixbuf, "y-dpi");
+ g_assert (x_dpi != NULL);
+ g_assert (y_dpi != NULL);
+ g_assert (strcmp (x_dpi, "300") == 0);
+ g_assert (strcmp (y_dpi, "600") == 0);
+
+ g_object_unref (loader);
+ g_free (contents);
+}
+
+static void
+test_nonincremental (gconstpointer data)
+{
+ const gchar *filename = data;
+ GError *error = NULL;
+ GdkPixbuf *pixbuf;
+ const gchar *x_dpi, *y_dpi;
+
+ if (!format_supported (filename))
+ {
+ g_test_skip ("format not supported");
+ return;
+ }
+
+ pixbuf = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, filename, NULL), &error);
+ g_assert_no_error (error);
+
+ x_dpi = gdk_pixbuf_get_option (pixbuf, "x-dpi");
+ y_dpi = gdk_pixbuf_get_option (pixbuf, "y-dpi");
+ g_assert (x_dpi != NULL);
+ g_assert (y_dpi != NULL);
+ g_assert (strcmp (x_dpi, "300") == 0);
+ g_assert (strcmp (y_dpi, "600") == 0);
+
+ g_object_unref (pixbuf);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_data_func ("/pixbuf/dpi/png", "dpi.png", test_nonincremental);
+ g_test_add_data_func ("/pixbuf/dpi/jpeg", "dpi.jpeg", test_nonincremental);
+ g_test_add_data_func ("/pixbuf/dpi/png/incremental", "dpi.png", test_incremental);
+ g_test_add_data_func ("/pixbuf/dpi/jpeg/incremental", "dpi.jpeg", test_incremental);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]