ImageOutputDev.h 6.15 KB
Newer Older
1 2 3 4 5 6 7 8
//========================================================================
//
// ImageOutputDev.h
//
// Copyright 1998-2003 Glyph & Cog, LLC
//
//========================================================================

9 10 11 12
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
13 14 15
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
16 17
// Copyright (C) 2006 Rainer Keller <class321@gmx.de>
// Copyright (C) 2008 Timothy Lee <timothy.lee@siriushk.com>
18
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
Jakob Voss's avatar
Jakob Voss committed
19
// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
Albert Astals Cid's avatar
Albert Astals Cid committed
20
// Copyright (C) 2012, 2013 Adrian Johnson <ajohnson@redneon.com>
21
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
22 23 24 25 26 27
//
// 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
//
//========================================================================

28 29 30
#ifndef IMAGEOUTPUTDEV_H
#define IMAGEOUTPUTDEV_H

31
#include "poppler/poppler-config.h"
32 33 34 35 36 37 38

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include <stdio.h>
#include "goo/gtypes.h"
39
#include "goo/ImgWriter.h"
40 41 42 43 44 45 46 47 48 49
#include "OutputDev.h"

class GfxState;

//------------------------------------------------------------------------
// ImageOutputDev
//------------------------------------------------------------------------

class ImageOutputDev: public OutputDev {
public:
50 51 52 53 54 55
  enum ImageType {
    imgImage,
    imgStencil,
    imgMask,
    imgSmask
  };
56 57
  enum ImageFormat {
    imgRGB,
58
    imgGray,
59 60
    imgMonochrome,
    imgCMYK
61
  };
62 63

  // Create an OutputDev which will write images to files named
Jakob Voss's avatar
Jakob Voss committed
64 65
  // <fileRoot>-NNN.<type> or <fileRoot>-PPP-NNN.<type>, if 
  // <pageNames> is set. Normally, all images are written as PBM
66 67
  // (.pbm) or PPM (.ppm) files unless PNG or Tiff output is enabled
  // (PNG is used if both are enabled).  If Jpeg is enabled, JPEG images
Jakob Voss's avatar
Jakob Voss committed
68
  // are written as JPEG (.jpg) files.
69
  ImageOutputDev(char *fileRootA, GBool pageNamesA, GBool listImagesA);
70 71 72 73

  // Destructor.
  virtual ~ImageOutputDev();

74 75 76 77 78 79 80 81 82
  // Use PNG format for output
  void enablePNG(GBool png) { outputPNG = png; }

  // Use TIFF format for output
  void enableTiff(GBool tiff) { outputTiff = tiff; }

  // Use Jpeg format for Jpeg files
  void enableJpeg(GBool jpeg) { dumpJPEG = jpeg; }

83 84 85
  // Use Jpeg2000 format for Jpeg2000 files
  void enableJpeg2000(GBool jp2) { dumpJP2 = jp2; }

86 87 88
  // Use JBIG2 format for JBIG2 files
  void enableJBig2(GBool jbig2) { dumpJBIG2 = jbig2; }

89 90 91
  // Use CCITT format for CCITT files
  void enableCCITT(GBool ccitt) { dumpCCITT = ccitt; }

92 93 94
  // Check if file was successfully created.
  virtual GBool isOk() { return ok; }

95 96 97 98 99
  // Does this device use tilingPatternFill()?  If this returns false,
  // tiling pattern fills will be reduced to a series of other drawing
  // operations.
  virtual GBool useTilingPatternFill() { return gTrue; }

100 101 102 103 104
  // Does this device use beginType3Char/endType3Char?  Otherwise,
  // text in Type 3 fonts will be drawn with drawChar/drawString.
  virtual GBool interpretType3Chars() { return gFalse; }

  // Does this device need non-text content?
105
  virtual GBool needNonText() { return gTrue; }
106

Jakob Voss's avatar
Jakob Voss committed
107
  // Start a page
108
  virtual void startPage(int pageNumA, GfxState *state, XRef *xref) 
Jakob Voss's avatar
Jakob Voss committed
109 110
			{ pageNum = pageNumA; }
 
111 112 113 114 115 116 117 118 119
  //---- get info about output device

  // Does this device use upside-down coordinates?
  // (Upside-down means (0,0) is the top left corner of the page.)
  virtual GBool upsideDown() { return gTrue; }

  // Does this device use drawChar() or drawString()?
  virtual GBool useDrawChar() { return gFalse; }

120
  //----- path painting
121
  virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
122 123 124 125 126
				  double *pmat, int paintType, int tilingType, Dict *resDict,
				  double *mat, double *bbox,
				  int x0, int y0, int x1, int y1,
				  double xStep, double yStep);

127 128 129
  //----- image drawing
  virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
			     int width, int height, GBool invert,
130
			     GBool interpolate, GBool inlineImg);
131 132
  virtual void drawImage(GfxState *state, Object *ref, Stream *str,
			 int width, int height, GfxImageColorMap *colorMap,
133
			 GBool interpolate, int *maskColors, GBool inlineImg);
134 135 136
  virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
			       int width, int height,
			       GfxImageColorMap *colorMap,
137
			       GBool interpolate,
138
			       Stream *maskStr, int maskWidth, int maskHeight,
139
			       GBool maskInvert, GBool maskInterpolate);
140 141 142
  virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
				   int width, int height,
				   GfxImageColorMap *colorMap,
143
				   GBool interpolate,
144 145
				   Stream *maskStr,
				   int maskWidth, int maskHeight,
146 147
				   GfxImageColorMap *maskColorMap,
				   GBool maskInterpolate);
148 149

private:
Jakob Voss's avatar
Jakob Voss committed
150 151
  // Sets the output filename with a given file extension
  void setFilename(const char *fileExt);
152 153 154 155 156 157
  void listImage(GfxState *state, Object *ref, Stream *str,
		 int width, int height,
		 GfxImageColorMap *colorMap,
		 GBool interpolate, GBool inlineImg,
		 ImageType imageType);
  void writeImage(GfxState *state, Object *ref, Stream *str,
158 159 160 161
                  int width, int height, GfxImageColorMap *colorMap, GBool inlineImg);
  void writeRawImage(Stream *str, const char *ext);
  void writeImageFile(ImgWriter *writer, ImageFormat format, const char *ext,
                      Stream *str, int width, int height, GfxImageColorMap *colorMap);
162 163 164

  char *fileRoot;		// root of output file names
  char *fileName;		// buffer for output file names
165
  GBool listImages;		// list images instead of dumping
166
  GBool dumpJPEG;		// set to dump native JPEG files
167
  GBool dumpJP2;		// set to dump native JPEG2000 files
168
  GBool dumpJBIG2;		// set to dump native JBIG2 files
169
  GBool dumpCCITT;		// set to dump native CCITT files
170 171
  GBool outputPNG;		// set to output in PNG format
  GBool outputTiff;		// set to output in TIFF format
Jakob Voss's avatar
Jakob Voss committed
172 173
  GBool pageNames;		// set to include page number in file names
  int pageNum;			// current page number
174 175 176 177 178
  int imgNum;			// current image number
  GBool ok;			// set up ok?
};

#endif