beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / goo / NetPBMWriter.cc
blobfca00b26b1ae64dc50980f39116b6bd92ccbbaf1
1 //========================================================================
2 //
3 // NetPBMWriter.h
4 //
5 // Copyright 1998-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8 //
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)
46 file = f;
47 width = widthA;
48 if (format == MONOCHROME) {
49 fprintf(file, "P4\n");
50 fprintf(file, "%d %d\n", widthA, heightA);
51 } else {
52 fprintf(file, "P6\n");
53 fprintf(file, "%d %d\n", widthA, heightA);
54 fprintf(file, "255\n");
56 return true;
59 bool NetPBMWriter::writePointers(unsigned char **rowPointers, int rowCount)
61 for (int i = 0; i < rowCount; i++)
62 writeRow(&rowPointers[i]);
63 return true;
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);
73 } else {
74 fwrite(*row, 1, width*3, file);
76 return true;
80 bool NetPBMWriter::close()
82 return true;