I merged pdftopng to pdftoppm. It works as "pdftoppm -png" now. Maybe
it should be something like "pdf2image" in the future and get more
format to support.
On Sun, Jun 7, 2009 at 6:15 AM, Albert Astals Cid<[email protected]> wrote:
> A Divendres, 29 de maig de 2009, Shen Liang va escriure:
>> patch for pdftopng
>
> The SplashBitmap::writePNGFile implementation has lots of commented code
> (either remove it if not needed or uncomment it if needed) and also doesn't
> implement nor gives errors case splashModeMono8: and some others.
>
> Also pdftopng.cc is 99.01% similar to pdftoppm.cc it would be a great idea if
> the code was either merged in and splitted into a separate file. Having
> duplicate code is a nightmare when speaking of maintainership.
>
> Albert
>
>>
>> ---------- Forwarded message ----------
>> From: Shen Liang <[email protected]>
>> Date: Tue, May 26, 2009 at 12:47 PM
>> Subject: Re: [poppler] Fwd: Donate some codes for poppler
>> To: Albert Astals Cid <[email protected]>
>>
>>
>> I'm sorry I got a mistake on the attach.
>>
>> On Sat, May 23, 2009 at 5:57 PM, Albert Astals Cid <[email protected]> wrote:
>> > A Divendres, 22 de maig de 2009, Shen Liang va escriure:
>> >> I'd like to donate some codes for Poppler. I added pdftopng by
>> >> modifying pdftoppm. The codes were quit dirty now, and I will do more
>> >> later.
>> >
>> > Hi, thanks for contributing to poppler :-)
>> >
>> > Unfortunately the zip you attach is not correct.
>> >
>> > First for pdftopng you are attaching a shell scripts instead of the code.
>> >
>> > Second for already existing files like SplashBitmap.[cc|h] you should
>> > attach a diff file as generated by git diff if you use git or diff -u if
>> > you are working on released tarballs.
>> >
>> > Albert
>> >
>> > _______________________________________________
>> > poppler mailing list
>> > [email protected]
>> > http://lists.freedesktop.org/mailman/listinfo/poppler
>>
>> --
>> Help Si Chuan Students
>> 帮助四川灾区学生
>> https://match.sichuanteachers.org
>> 四川教师志愿者组织
>
>
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
--
Help Si Chuan Students
帮助四川灾区学生
https://match.sichuanteachers.org
四川教师志愿者组织
--- /mnt/sda8/projects/poppler-0.10.0/splash/!SplashBitmap.cc 2008-09-20 22:08:50.000000000 +0800
+++ /mnt/sda8/projects/poppler-0.10.0/splash/SplashBitmap.cc 2009-06-14 17:19:20.000000000 +0800
@@ -30,6 +30,7 @@
#include "SplashErrorCodes.h"
#include "SplashBitmap.h"
+#include <png.h>
//------------------------------------------------------------------------
// SplashBitmap
//------------------------------------------------------------------------
@@ -237,3 +238,83 @@
Guchar SplashBitmap::getAlpha(int x, int y) {
return alpha[y * width + x];
}
+
+SplashError SplashBitmap::writePNGFile(char *fileName) {
+ FILE *f;
+ SplashColorPtr row, p;
+ int x, y;
+
+ if (!(f = fopen(fileName, "wb"))) {
+ return splashErrOpenFile;
+ }
+
+ png_byte color_type;
+ png_byte bit_depth;
+ png_byte interlace_type;
+
+ png_structp png_ptr;
+ png_infop info_ptr;
+
+ png_bytep row_pointers[height];
+ /* initialize stuff */
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ if (!png_ptr)
+ fprintf (stderr, "png_create_write_struct failed");
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ fprintf (stderr, "png_create_info_struct failed");
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ fprintf (stderr, "png_create_info_struct failed");
+
+ png_init_io(png_ptr, f);
+
+ /* write header */
+ if (setjmp(png_jmpbuf(png_ptr)))
+ fprintf (stderr, "Error during writing header");
+
+ bit_depth = 8;
+ color_type = PNG_COLOR_TYPE_RGB;
+ interlace_type = PNG_INTERLACE_ADAM7;//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);
+
+ png_write_info(png_ptr, info_ptr);
+
+ switch (mode) {
+
+ case splashModeMono1:
+ break;
+
+ case splashModeMono8:
+ break;
+
+ case splashModeRGB8:
+ row = data;
+
+ for (y=0; y<height; ++y) {
+ row_pointers[y] = row;
+ row += rowSize;
+ }
+ png_write_image(png_ptr, row_pointers);
+ break;
+ }
+
+ /* write bytes */
+ if (setjmp(png_jmpbuf(png_ptr)))
+ fprintf (stderr, "Error during writing bytes");
+
+ /* end write */
+ if (setjmp(png_jmpbuf(png_ptr)))
+ fprintf (stderr, "Error during end of write");
+
+ png_write_end(png_ptr, info_ptr);
+
+ /* cleanup heap allocation */
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ fclose(f);
+ return splashOk;
+}
--- /mnt/sda8/projects/poppler/utils/pdftoppm.cc 2008-10-30 22:07:20.000000000 +0800
+++ /mnt/sda8/projects/poppler-0.10.0/utils/pdftoppm.cc 2009-06-14 17:45:15.000000000 +0800
@@ -47,6 +47,7 @@
static int sz = 0;
static GBool mono = gFalse;
static GBool gray = gFalse;
+static GBool png = gFalse;
static char enableFreeTypeStr[16] = "";
static char antialiasStr[16] = "";
static char vectorAntialiasStr[16] = "";
@@ -82,7 +83,8 @@
"generate a monochrome PBM file"},
{"-gray", argFlag, &gray, 0,
"generate a grayscale PGM file"},
-
+ {"-png", argFlag, &png, 0,
+ "generate a PNG file"},
#if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
{"-freetype", argString, enableFreeTypeStr, sizeof(enableFreeTypeStr),
"enable FreeType font rasterizer: yes, no"},
@@ -129,9 +131,17 @@
x, y, w, h
);
if (ppmFile != NULL) {
- splashOut->getBitmap()->writePNMFile(ppmFile);
+ if (png) {
+ splashOut->getBitmap()->writePNGFile(ppmFile);
+ } else {
+ splashOut->getBitmap()->writePNMFile(ppmFile);
+ }
} else {
- splashOut->getBitmap()->writePNMFile(stdout);
+ if (png) {
+ splashOut->getBitmap()->writePNGFile(ppmFile);
+ } else {
+ splashOut->getBitmap()->writePNMFile(stdout);
+ }
}
}
@@ -251,7 +261,7 @@
if (ppmRoot != NULL) {
snprintf(ppmFile, PPM_FILE_SZ, "%.*s-%0*d.%s",
PPM_FILE_SZ - 32, ppmRoot, pg_num_len, pg,
- mono ? "pbm" : gray ? "pgm" : "ppm");
+ png ? "png" : mono ? "pbm" : gray ? "pgm" : "ppm");
savePageSlice(doc, splashOut, pg, x, y, w, h, pg_w, pg_h, ppmFile);
} else {
savePageSlice(doc, splashOut, pg, x, y, w, h, pg_w, pg_h, NULL);
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler