[cairo-commit] 5 commits - src/cairo-pdf-surface.c src/cairo-png.c src/cairo-ps-surface.c test/imagediff.c test/Makefile.am test/mime-data.c test/mime-data.pdf.ref.png test/mime-data.ps.ref.png test/pdf-mime-data.c test/scarab.jpg

Chris Wilson ickle at kemper.freedesktop.org
Tue Nov 4 05:16:57 PST 2008


 src/cairo-pdf-surface.c    |    2 +-
 src/cairo-png.c            |   11 +++++++----
 src/cairo-ps-surface.c     |    5 ++---
 test/Makefile.am           |    8 ++++++--
 test/imagediff.c           |   17 +++++++++++++++++
 test/mime-data.c           |    6 +++++-
 test/mime-data.pdf.ref.png |binary
 test/mime-data.ps.ref.png  |binary
 test/pdf-mime-data.c       |   44 ++++++++++++++++++++++++++++++++------------
 test/scarab.jpg            |binary
 10 files changed, 70 insertions(+), 23 deletions(-)

New commits:
commit c13a09ddb411287224c15728b14f23fef472f7d0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 4 13:00:36 2008 +0000

    [test] Use a different jpeg image for mime-data
    
    Detect when we successfully encode the JPEG data from the mime-type by
    using a completely image.

diff --git a/test/Makefile.am b/test/Makefile.am
index bbf3970..1bc5c47 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -694,6 +694,8 @@ REFERENCE_IMAGES = \
 	meta-surface-pattern.svg12.argb32.ref.png	\
 	meta-surface-pattern.svg12.rgb24.ref.png	\
 	mime-data.ref.png	\
+	mime-data.ps.ref.png	\
+	mime-data.pdf.ref.png	\
 	miter-precision.ref.png \
 	miter-precision.ps2.ref.png	\
 	miter-precision.ps3.ref.png	\
@@ -1002,6 +1004,7 @@ EXTRA_DIST +=		\
 make-html.pl		\
 romedalen.jpg		\
 romedalen.png		\
+scarab.jpg		\
 surface-source.c	\
 $(REFERENCE_IMAGES)
 
diff --git a/test/mime-data.c b/test/mime-data.c
index b364915..dd1e095 100644
--- a/test/mime-data.c
+++ b/test/mime-data.c
@@ -35,7 +35,11 @@ read_jpg_file (const cairo_test_context_t *ctx,
 	       unsigned char **data_out,
 	       unsigned int *length_out)
 {
-    const char jpg_filename[] = "romedalen.jpg";
+    /* Deliberately use a non-matching jpeg image, so that we can identify
+     * when the JPEG representation is used in preference to the image
+     * surface.
+     */
+    const char jpg_filename[] = "scarab.jpg";
     FILE *file;
     unsigned char *buf;
     unsigned int len;
diff --git a/test/mime-data.pdf.ref.png b/test/mime-data.pdf.ref.png
new file mode 100644
index 0000000..f04fe6c
Binary files /dev/null and b/test/mime-data.pdf.ref.png differ
diff --git a/test/mime-data.ps.ref.png b/test/mime-data.ps.ref.png
new file mode 100644
index 0000000..43d1032
Binary files /dev/null and b/test/mime-data.ps.ref.png differ
diff --git a/test/scarab.jpg b/test/scarab.jpg
new file mode 100644
index 0000000..6a66ff7
Binary files /dev/null and b/test/scarab.jpg differ
commit 8407470409ad9cb93263a1c2da7dd7446d3f897e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 4 12:45:47 2008 +0000

    [test] Adapt pdf-mime-data for non-srcdir build.
    
    Need to look for reference/input images from srcdir as well.

diff --git a/test/Makefile.am b/test/Makefile.am
index 8319c30..bbf3970 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1002,7 +1002,6 @@ EXTRA_DIST +=		\
 make-html.pl		\
 romedalen.jpg		\
 romedalen.png		\
-romedalen.jpg		\
 surface-source.c	\
 $(REFERENCE_IMAGES)
 
@@ -1219,6 +1218,7 @@ CLEANFILES +=					\
 	pdf-surface-source.pdf			\
 	ps-surface-source.ps			\
 	pdf-features.pdf			\
+	pdf-mime-data.out*			\
 	ps-features.ps				\
 	svg-clip.svg				\
 	svg-surface.svg				\
diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c
index 11076ea..c949335 100644
--- a/test/pdf-mime-data.c
+++ b/test/pdf-mime-data.c
@@ -24,12 +24,13 @@
  * Author: Adrian Johnson <ajohnson at redneon.com>
  */
 
+#include "cairo-test.h"
+
 #include <stdio.h>
+#include <errno.h>
 #include <cairo.h>
 #include <cairo-pdf.h>
 
-#include "cairo-test.h"
-
 /* This test checks that the mime data is correctly used by the PDF
  * surface when embedding images..
  */
@@ -40,13 +41,30 @@
 
 
 static cairo_test_status_t
-read_file (const char *file, unsigned char **data, unsigned int *len)
+read_file (const cairo_test_context_t *ctx,
+	   const char *file,
+	   unsigned char **data,
+	   unsigned int *len)
 {
     FILE *fp;
 
     fp = fopen (file, "rb");
-    if (fp == NULL)
-	return CAIRO_TEST_FAILURE;
+    if (file == NULL) {
+	char filename[4096];
+
+	/* try again with srcdir */
+	snprintf (filename, sizeof (filename),
+		  "%s/%s", ctx->srcdir, file);
+	fp = fopen (filename, "rb");
+    }
+    if (fp == NULL) {
+	switch (errno) {
+	case ENOMEM:
+	    return CAIRO_TEST_NO_MEMORY;
+	default:
+	    return CAIRO_TEST_FAILURE;
+	}
+    }
 
     fseek (fp, 0, SEEK_END);
     *len = ftell(fp);
@@ -65,7 +83,7 @@ read_file (const char *file, unsigned char **data, unsigned int *len)
 static cairo_test_status_t
 preamble (cairo_test_context_t *ctx)
 {
-    const char *filename = "pdf-mime-data-out.pdf";
+    const char *filename = "pdf-mime-data.out.pdf";
     cairo_surface_t *image;
     cairo_surface_t *surface;
     cairo_t *cr;
@@ -82,7 +100,7 @@ preamble (cairo_test_context_t *ctx)
 	return CAIRO_TEST_UNTESTED;
 
     image = cairo_image_surface_create_from_png (IMAGE_FILE ".png");
-    test_status = read_file (IMAGE_FILE ".jpg", &data, &len);
+    test_status = read_file (ctx, IMAGE_FILE ".jpg", &data, &len);
     if (test_status) {
 	cairo_test_log (ctx, "Could not read input jpeg file %s\n", IMAGE_FILE ".jpg");
 	return test_status;
@@ -114,22 +132,24 @@ preamble (cairo_test_context_t *ctx)
 
     printf ("pdf-mime-data: Please check %s to ensure it looks/prints correctly.\n", filename);
 
-    sprintf (command, "pdfimages -j %s pdf-mime-data-out", filename);
+    sprintf (command, "pdfimages -j %s pdf-mime-data.out", filename);
     exit_status = system (command);
     if (exit_status) {
 	cairo_test_log (ctx, "pdfimages failed with exit status %d\n", exit_status);
 	return CAIRO_TEST_FAILURE;
     }
 
-    test_status = read_file (IMAGE_FILE ".jpg", &data, &len);
+    test_status = read_file (ctx, IMAGE_FILE ".jpg", &data, &len);
     if (test_status) {
 	cairo_test_log (ctx, "Could not read input jpeg file %s\n", IMAGE_FILE ".jpg");
 	return test_status;
     }
 
-    test_status = read_file ("pdf-mime-data-out-000.jpg", &out_data, &out_len);
+    test_status = read_file (ctx, "pdf-mime-data.out-000.jpg", &out_data, &out_len);
     if (test_status) {
-	cairo_test_log (ctx, "Could not read input jpeg file %s\n", "pdf-mime-data-out-000.jpg");
+	cairo_test_log (ctx,
+			"Could not read input jpeg file %s\n",
+			"pdf-mime-data.out-000.jpg");
 	return test_status;
     }
 
@@ -145,7 +165,7 @@ preamble (cairo_test_context_t *ctx)
 
 CAIRO_TEST (pdf_mime_data,
 	    "Check mime data correctly used by PDF surface",
-	    "pdf", /* keywords */
+	    "pdf, mime-data", /* keywords */
 	    NULL, /* requirements */
 	    0, 0,
 	    preamble, NULL)
commit 8007618837c0292b6ebc6a4f954c5049d4e99d8a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 4 12:31:10 2008 +0000

    [test] Fix compilation of imagediff.
    
    imagediff broke once again.

diff --git a/test/Makefile.am b/test/Makefile.am
index ce17cce..8319c30 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1149,7 +1149,8 @@ imagediff_SOURCES = \
 	buffer-diff.c	\
 	buffer-diff.h
 imagediff_LDADD = \
-	$(top_builddir)/test/pdiff/libpdiff.la
+	$(top_builddir)/test/pdiff/libpdiff.la \
+	$(top_builddir)/src/libcairo.la
 
 png_flatten_SOURCES = png-flatten.c
 png_flatten_LDADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD)
diff --git a/test/imagediff.c b/test/imagediff.c
index 424ca6d..6ebbcfc 100644
--- a/test/imagediff.c
+++ b/test/imagediff.c
@@ -46,6 +46,23 @@ _xunlink (const char *pathname)
     }
 }
 
+void
+cairo_test_logv (const cairo_test_context_t *ctx,
+		 const char *fmt, va_list va)
+{
+    vfprintf (stderr, fmt, va);
+}
+
+void
+cairo_test_log (const cairo_test_context_t *ctx, const char *fmt, ...)
+{
+    va_list va;
+
+    va_start (va, fmt);
+    vfprintf (stderr, fmt, va);
+    va_end (va);
+}
+
 /* Flatten an ARGB surface by blending it over white. The resulting
  * surface, (still in ARGB32 format, but with only alpha==1.0
  * everywhere) is returned in the same surface pointer.
commit 282d7744275f623ce550638df953ef279d2209f0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 4 12:53:15 2008 +0000

    [mime-type] Request the mime-data for the source surface, not ourselves!
    
    Fixup a typo I introduced that caused us to request the jpeg data for the
    destination surface and not the source.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 7bcb057..6edea4a 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1563,7 +1563,7 @@ _cairo_pdf_surface_emit_jpeg_image (cairo_pdf_surface_t   *surface,
     unsigned int mime_data_length;
     cairo_jpeg_info_t info;
 
-    cairo_surface_get_mime_data (&surface->base, CAIRO_MIME_TYPE_JPEG,
+    cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG,
 				 &mime_data, &mime_data_length);
     if (mime_data == NULL)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index e0db575..5dcdce5 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -2130,11 +2130,10 @@ _cairo_ps_surface_emit_jpeg_image (cairo_ps_surface_t    *surface,
     unsigned int mime_data_length;
     cairo_jpeg_info_t info;
 
-    cairo_surface_get_mime_data (&surface->base, CAIRO_MIME_TYPE_JPEG,
+    cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG,
 				 &mime_data, &mime_data_length);
-    if (mime_data == NULL) {
+    if (mime_data == NULL)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
 
     status = _cairo_jpeg_get_info (mime_data, mime_data_length, &info);
     if (status)
commit aa616abc9ab02e333cf0cad4f524b15c710bf449
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 4 11:18:22 2008 +0000

    [png] Use RGB for opaque images.
    
    If the ARGB32 is opaque, discard the alpha channel - so we should generate
    byte identical output to the reference images.

diff --git a/src/cairo-png.c b/src/cairo-png.c
index 06e7cb5..4721825 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -190,7 +190,10 @@ write_png (cairo_surface_t	*surface,
     switch (image->format) {
     case CAIRO_FORMAT_ARGB32:
 	depth = 8;
-	png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+	if (_cairo_image_analyze_transparency (image) == CAIRO_IMAGE_IS_OPAQUE)
+	    png_color_type = PNG_COLOR_TYPE_RGB;
+	else
+	    png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
 	break;
     case CAIRO_FORMAT_RGB24:
 	depth = 8;
@@ -237,12 +240,12 @@ write_png (cairo_surface_t	*surface,
      */
     png_write_info (png, info);
 
-    if (image->format == CAIRO_FORMAT_ARGB32)
+    if (png_color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
 	png_set_write_user_transform_fn (png, unpremultiply_data);
-    else if (image->format == CAIRO_FORMAT_RGB24)
+    } else if (png_color_type == PNG_COLOR_TYPE_RGB) {
 	png_set_write_user_transform_fn (png, convert_data_to_bytes);
-    if (image->format == CAIRO_FORMAT_RGB24)
 	png_set_filler (png, 0, PNG_FILLER_AFTER);
+    }
 
     png_write_image (png, rows);
     png_write_end (png, info);


More information about the cairo-commit mailing list