summaryrefslogtreecommitdiff
path: root/goo
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2013-08-18 15:50:39 +0930
committerAdrian Johnson <ajohnson@redneon.com>2013-08-26 06:40:34 +0930
commite53aec2c61ba42cf0635dc05f8e27e3503c1eaac (patch)
treea5a8bb98cdb5c21c08c21cb13443314ad86f40b9 /goo
parent0ca0fcc9f536a57365048914cd8a8cc3eb5ed4fd (diff)
Refactor ImageOutputDev to facilitate adding more output formats
- Move PPM/PBM code into a NetPBMWriter class so PNGWriter and TiffWritersupport be added. - Create generic WriteRawIMage function for writing jpeg files so support for jpeg2000/jbig2 can be added.
Diffstat (limited to 'goo')
-rw-r--r--goo/Makefile.am2
-rw-r--r--goo/NetPBMWriter.cc84
-rw-r--r--goo/NetPBMWriter.h52
3 files changed, 138 insertions, 0 deletions
diff --git a/goo/Makefile.am b/goo/Makefile.am
index 0764e79c..a48b20ec 100644
--- a/goo/Makefile.am
+++ b/goo/Makefile.am
@@ -13,6 +13,7 @@ poppler_goo_include_HEADERS = \
gmem.h \
gfile.h \
FixedPoint.h \
+ NetPBMWriter.h \
PNGWriter.h \
JpegWriter.h \
TiffWriter.h \
@@ -55,6 +56,7 @@ libgoo_la_SOURCES = \
GooString.cc \
gmem.cc \
FixedPoint.cc \
+ NetPBMWriter.cc \
PNGWriter.cc \
JpegWriter.cc \
TiffWriter.cc \
diff --git a/goo/NetPBMWriter.cc b/goo/NetPBMWriter.cc
new file mode 100644
index 00000000..fca00b26
--- /dev/null
+++ b/goo/NetPBMWriter.cc
@@ -0,0 +1,84 @@
+//========================================================================
+//
+// NetPBMWriter.h
+//
+// Copyright 1998-2003 Glyph & Cog, LLC
+//
+//========================================================================
+//
+//========================================================================
+//
+// Modified under the Poppler project - http://poppler.freedesktop.org
+//
+// All changes made under the Poppler project to this file are licensed
+// under GPL version 2 or later
+//
+// Copyright (C) 2005, 2007, 2011 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2006 Rainer Keller <class321@gmx.de>
+// Copyright (C) 2008 Timothy Lee <timothy.lee@siriushk.com>
+// Copyright (C) 2008 Vasile Gaburici <gaburici@cs.umd.edu>
+// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
+// Copyright (C) 2009 William Bader <williambader@hotmail.com>
+// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
+// Copyright (C) 2012, 2013 Adrian Johnson <ajohnson@redneon.com>
+// Copyright (C) 2013 Thomas Fischer <fischer@unix-ag.uni-kl.de>
+//
+// To see a description of the changes please see the Changelog file that
+// came with your tarball or type make ChangeLog if you are building from git
+//
+//========================================================================
+
+#include "poppler-config.h"
+
+#include "NetPBMWriter.h"
+
+// Writer for the NetPBM formats (PBM and PPM)
+// This format is documented at:
+// http://netpbm.sourceforge.net/doc/pbm.html
+// http://netpbm.sourceforge.net/doc/ppm.html
+
+NetPBMWriter::NetPBMWriter(Format formatA) : format(formatA)
+{
+}
+
+bool NetPBMWriter::init(FILE *f, int widthA, int heightA, int hDPI, int vDPI)
+{
+ file = f;
+ width = widthA;
+ if (format == MONOCHROME) {
+ fprintf(file, "P4\n");
+ fprintf(file, "%d %d\n", widthA, heightA);
+ } else {
+ fprintf(file, "P6\n");
+ fprintf(file, "%d %d\n", widthA, heightA);
+ fprintf(file, "255\n");
+ }
+ return true;
+}
+
+bool NetPBMWriter::writePointers(unsigned char **rowPointers, int rowCount)
+{
+ for (int i = 0; i < rowCount; i++)
+ writeRow(&rowPointers[i]);
+ return true;
+}
+
+bool NetPBMWriter::writeRow(unsigned char **row)
+{
+ if (format == MONOCHROME) {
+ // PBM uses 0 = white, 1 = black so we need to invert the colors
+ int size = (width + 7)/8;
+ for (int i = 0; i < size; i++)
+ fputc((*row)[i] ^ 0xff, file);
+ } else {
+ fwrite(*row, 1, width*3, file);
+ }
+ return true;
+}
+
+
+bool NetPBMWriter::close()
+{
+ return true;
+}
+
diff --git a/goo/NetPBMWriter.h b/goo/NetPBMWriter.h
new file mode 100644
index 00000000..21a19ee7
--- /dev/null
+++ b/goo/NetPBMWriter.h
@@ -0,0 +1,52 @@
+//========================================================================
+//
+// NetPBMWriter.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
+// Copyright (C) 2009, 2011 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2010, 2013 Adrian Johnson <ajohnson@redneon.com>
+// Copyright (C) 2010 Brian Cameron <brian.cameron@oracle.com>
+// Copyright (C) 2011 Thomas Freitag <Thomas.Freitag@alfa.de>
+//
+//========================================================================
+
+#ifndef NETPBMWRITER_H
+#define NETPBMWRITER_H
+
+#include "poppler-config.h"
+
+#include "ImgWriter.h"
+
+// Writer for the NetPBM formats (PBM and PPM)
+// This format is documented at:
+// http://netpbm.sourceforge.net/doc/pbm.html
+// http://netpbm.sourceforge.net/doc/ppm.html
+
+class NetPBMWriter : public ImgWriter
+{
+public:
+
+ /* RGB - 3 bytes/pixel
+ * MONOCHROME - 8 pixels/byte
+ */
+ enum Format { RGB, MONOCHROME };
+
+ NetPBMWriter(Format formatA = RGB);
+ ~NetPBMWriter() {};
+
+ bool init(FILE *f, int width, int height, int hDPI, int vDPI);
+
+ bool writePointers(unsigned char **rowPointers, int rowCount);
+ bool writeRow(unsigned char **row);
+
+ bool close();
+
+private:
+ FILE *file;
+ Format format;
+ int width;
+};
+
+#endif