On 18/08/11 23:33, Albert Astals Cid wrote:
> A Dissabte, 13 d'agost de 2011, Adrian Johnson vàreu escriure:
>> I have revisited the pdftocairo patches that Stefan Thomas was working
>> on a year ago that were based on a patch I wrote back in 2009. The
>> original code had some limitations particularly when trying to support
>> all the printing options. 
> 
> Some comments:
> By moving the 
>   #if HAVE_STDINT_H
>   #include <stdint.h>
>   #elif _MSC_VER
>   ...
>   #else
>   #error No stdint.h types defined
>   #endif
> to gtypes.h you make all poppler (instead of poppler/cairo) uncompilable in 
> case of the #else, i wonder if it would make sense to keep that in the header 
> it was since we do not use it anywhere else?

I've updated patch 0001 to remove the #error.

> Where are #if CAIRO_HAS_PS_SURFACE and friends defined?

In cairo-features.h included by cairo.h. It defines the backends that
have been compiled into cairo.

> 
> You also have some whitespace mismatch that would be great if you could fix.

Patch 0003 and 0004 have been updated to ensure the indenting of the new
code is consistent with the existing code.

> 
> Finally 0008-cairo-use-cairo_show_text_glyphs-when-printing.patch touches 
> CairoOutputDev, i'd like someone else to ok this since i have no idea about 
> that? (Or you can "ok" it yourself if you agree to fix problems it might 
> bring 
> ;-))

I've asked Carlos to review this patch.

> 
> Albert
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler

>From c31e9c21565db901d4bd1027e3d90ba13d4d20aa Mon Sep 17 00:00:00 2001
From: Adrian Johnson <[email protected]>
Date: Tue, 9 Aug 2011 22:05:53 +0930
Subject: [PATCH 1/9] Use stdint.h instead of assuming the size of types

---
 configure.ac               |    1 +
 goo/gtypes.h               |   18 ++++++++++++++++++
 poppler/CairoOutputDev.cc  |    2 --
 poppler/CairoRescaleBox.cc |    2 --
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index b7af92b..8afb13b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,7 @@ AC_DEFINE_DIR(POPPLER_DATADIR, "{datarootdir}/poppler", [Poppler data dir])
 dnl ##### Checks for header files.
 AC_PATH_XTRA
 AC_HEADER_DIRENT
+AC_CHECK_HEADERS([stdint.h])
 
 dnl ##### Switch over to C++.  This will make the checks below a little
 dnl ##### bit stricter (requiring function prototypes in include files).
diff --git a/goo/gtypes.h b/goo/gtypes.h
index b7a2dd2..cb1cb89 100644
--- a/goo/gtypes.h
+++ b/goo/gtypes.h
@@ -24,6 +24,8 @@
 #ifndef GTYPES_H
 #define GTYPES_H
 
+#include "config.h"
+
 /*
  * These have stupid names to avoid conflicts with some (but not all)
  * C++ compilers which define them.
@@ -45,4 +47,20 @@ typedef unsigned short Gushort;
 typedef unsigned int Guint;
 typedef unsigned long Gulong;
 
+/*
+ * Define precise integer types.
+ */
+#if HAVE_STDINT_H
+#include <stdint.h>
+#elif _MSC_VER
+typedef signed   __int8  int8_t;
+typedef unsigned __int8  uint8_t;
+typedef signed   __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef signed   __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef signed   __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#endif
+
 #endif
diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index 477030a..6e7fd53 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -1343,8 +1343,6 @@ void CairoOutputDev::paintTransparencyGroup(GfxState * /*state*/, double * /*bbo
   popTransparencyGroup();
 }
 
-typedef unsigned int uint32_t;
-
 static uint32_t luminocity(uint32_t x)
 {
   int r = (x >> 16) & 0xff;
diff --git a/poppler/CairoRescaleBox.cc b/poppler/CairoRescaleBox.cc
index dce5ddd..fea5891 100644
--- a/poppler/CairoRescaleBox.cc
+++ b/poppler/CairoRescaleBox.cc
@@ -37,8 +37,6 @@
 #include "goo/gmem.h"
 #include "CairoRescaleBox.h"
 
-typedef unsigned short int      uint16_t;
-typedef unsigned int            uint32_t;
 
 /* we work in fixed point where 1. == 1 << 24 */
 #define FIXED_SHIFT 24
-- 
1.7.4.1

>From e9f16432eda5537f472fe1fd84cd2e51cccb3484 Mon Sep 17 00:00:00 2001
From: Adrian Johnson <[email protected]>
Date: Wed, 10 Aug 2011 18:48:15 +0930
Subject: [PATCH 3/9] png: Add additional pixel formats

RGBA is required for images with transparency. GRAY and MONOCHROME
allow PNGWriter write more compact PNG files when the images is known
to be all gray or monochrome.
---
 goo/PNGWriter.cc |   30 ++++++++++++++++++++++++++----
 goo/PNGWriter.h  |   13 ++++++++++++-
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc
index 400c515..7883c56 100644
--- a/goo/PNGWriter.cc
+++ b/goo/PNGWriter.cc
@@ -21,7 +21,7 @@
 
 #include "poppler/Error.h"
 
-PNGWriter::PNGWriter()
+PNGWriter::PNGWriter(Format formatA) : format(formatA)
 {
 }
 
@@ -61,8 +61,26 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
 	// Set up the type of PNG image and the compression level
 	png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
 
-	png_byte bit_depth = 8;
-	png_byte color_type = PNG_COLOR_TYPE_RGB;
+	png_byte bit_depth;
+	png_byte color_type;
+	switch (format) {
+		case RGB:
+			bit_depth = 8;
+			color_type = PNG_COLOR_TYPE_RGB;
+			break;
+		case RGBA:
+			bit_depth = 8;
+			color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+			break;
+		case GRAY:
+			bit_depth = 8;
+			color_type = PNG_COLOR_TYPE_GRAY;
+			break;
+		case MONOCHROME:
+			bit_depth = 1;
+			color_type = PNG_COLOR_TYPE_GRAY;
+			break;
+	}
 	png_byte interlace_type = PNG_INTERLACE_NONE;
 
 	png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
@@ -74,7 +92,11 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
 		error(-1, "error during writing png info bytes");
 		return false;
 	}
-	
+
+	// pack 1 pixel/byte rows into 8 pixels/byte
+	if (format == MONOCHROME)
+		png_set_packing(png_ptr);
+
 	return true;
 }
 
diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h
index 0f79bf9..dc06e1c 100644
--- a/goo/PNGWriter.h
+++ b/goo/PNGWriter.h
@@ -23,10 +23,20 @@
 #include <png.h>
 #include "ImgWriter.h"
 
+
+
 class PNGWriter : public ImgWriter
 {
 	public:
-		PNGWriter();
+
+		/* RGB        - 3 bytes/pixel
+		 * RGBA       - 4 bytes/pixel
+		 * GRAY       - 1 byte/pixel
+		 * MONOCHROME - 1 byte/pixel. PNGWriter will bitpack to 8 pixels/byte
+		 */
+		enum Format { RGB, RGBA, GRAY, MONOCHROME };
+
+		PNGWriter(Format format = RGB);
 		~PNGWriter();
 		
 		bool init(FILE *f, int width, int height, int hDPI, int vDPI);
@@ -37,6 +47,7 @@ class PNGWriter : public ImgWriter
 		bool close();
 	
 	private:
+		Format format;
 		png_structp png_ptr;
 		png_infop info_ptr;
 };
-- 
1.7.4.1

>From 7832d5085c080dfefdb736d76dc86f1e7e9fb1cd Mon Sep 17 00:00:00 2001
From: Adrian Johnson <[email protected]>
Date: Thu, 11 Aug 2011 21:32:53 +0930
Subject: [PATCH 4/9] png: add support for embedding ICC profile

---
 goo/PNGWriter.cc |   28 ++++++++++++++++++++++++++++
 goo/PNGWriter.h  |    8 ++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc
index 7883c56..1e78de5 100644
--- a/goo/PNGWriter.cc
+++ b/goo/PNGWriter.cc
@@ -18,17 +18,40 @@
 #ifdef ENABLE_LIBPNG
 
 #include <zlib.h>
+#include <stdlib.h>
 
 #include "poppler/Error.h"
+#include "goo/gmem.h"
 
 PNGWriter::PNGWriter(Format formatA) : format(formatA)
 {
+	icc_data = NULL;
+	icc_data_size = 0;
+	icc_name = NULL;
+	sRGB_profile = false;
 }
 
 PNGWriter::~PNGWriter()
 {
 	/* cleanup heap allocation */
 	png_destroy_write_struct(&png_ptr, &info_ptr);
+	if (icc_data) {
+		gfree(icc_data);
+		free(icc_name);
+	}
+}
+
+void PNGWriter::setICCProfile(const char *name, unsigned char *data, int size)
+{
+	icc_data = (unsigned char *)gmalloc(size);
+	memcpy(icc_data, data, size);
+	icc_data_size = size;
+	icc_name = strdup(name);
+}
+
+void PNGWriter::setSRGBProfile()
+{
+	sRGB_profile = true;
 }
 
 bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
@@ -87,6 +110,11 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
 
 	png_set_pHYs(png_ptr, info_ptr, hDPI/0.0254, vDPI/0.0254, PNG_RESOLUTION_METER);
 
+	if (icc_data)
+		png_set_iCCP(png_ptr, info_ptr, icc_name, PNG_COMPRESSION_TYPE_BASE, (char*)icc_data, icc_data_size);
+	else if (sRGB_profile)
+		png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_RELATIVE);
+
 	png_write_info(png_ptr, info_ptr);
 	if (setjmp(png_jmpbuf(png_ptr))) {
 		error(-1, "error during writing png info bytes");
diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h
index dc06e1c..ce4bbaa 100644
--- a/goo/PNGWriter.h
+++ b/goo/PNGWriter.h
@@ -38,6 +38,10 @@ class PNGWriter : public ImgWriter
 
 		PNGWriter(Format format = RGB);
 		~PNGWriter();
+
+		void setICCProfile(const char *name, unsigned char *data, int size);
+		void setSRGBProfile();
+
 		
 		bool init(FILE *f, int width, int height, int hDPI, int vDPI);
 		
@@ -50,6 +54,10 @@ class PNGWriter : public ImgWriter
 		Format format;
 		png_structp png_ptr;
 		png_infop info_ptr;
+		unsigned char *icc_data;
+		int icc_data_size;
+		char *icc_name;
+		bool sRGB_profile;
 };
 
 #endif
-- 
1.7.4.1

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to