1 //========================================================================
5 // Copyright 1998-2003 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2005, 2007, 2011 Albert Astals Cid <aacid@kde.org>
17 // Copyright (C) 2006 Rainer Keller <class321@gmx.de>
18 // Copyright (C) 2008 Timothy Lee <timothy.lee@siriushk.com>
19 // Copyright (C) 2008 Vasile Gaburici <gaburici@cs.umd.edu>
20 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
21 // Copyright (C) 2009 William Bader <williambader@hotmail.com>
22 // Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
23 // Copyright (C) 2012, 2013 Adrian Johnson <ajohnson@redneon.com>
24 // Copyright (C) 2013 Thomas Fischer <fischer@unix-ag.uni-kl.de>
26 // To see a description of the changes please see the Changelog file that
27 // came with your tarball or type make ChangeLog if you are building from git
29 //========================================================================
31 #include "poppler-config.h"
33 #include "NetPBMWriter.h"
35 // Writer for the NetPBM formats (PBM and PPM)
36 // This format is documented at:
37 // http://netpbm.sourceforge.net/doc/pbm.html
38 // http://netpbm.sourceforge.net/doc/ppm.html
40 NetPBMWriter::NetPBMWriter(Format formatA
) : format(formatA
)
44 bool NetPBMWriter::init(FILE *f
, int widthA
, int heightA
, int hDPI
, int vDPI
)
48 if (format
== MONOCHROME
) {
49 fprintf(file
, "P4\n");
50 fprintf(file
, "%d %d\n", widthA
, heightA
);
52 fprintf(file
, "P6\n");
53 fprintf(file
, "%d %d\n", widthA
, heightA
);
54 fprintf(file
, "255\n");
59 bool NetPBMWriter::writePointers(unsigned char **rowPointers
, int rowCount
)
61 for (int i
= 0; i
< rowCount
; i
++)
62 writeRow(&rowPointers
[i
]);
66 bool NetPBMWriter::writeRow(unsigned char **row
)
68 if (format
== MONOCHROME
) {
69 // PBM uses 0 = white, 1 = black so we need to invert the colors
70 int size
= (width
+ 7)/8;
71 for (int i
= 0; i
< size
; i
++)
72 fputc((*row
)[i
] ^ 0xff, file
);
74 fwrite(*row
, 1, width
*3, file
);
80 bool NetPBMWriter::close()