1//========================================================================
2//
3// SplashBitmap.h
4//
5//========================================================================
6
7//========================================================================
8//
9// Modified under the Poppler project - http://poppler.freedesktop.org
10//
11// All changes made under the Poppler project to this file are licensed
12// under GPL version 2 or later
13//
14// Copyright (C) 2007 Ilmari Heikkinen <ilmari.heikkinen@gmail.com>
15// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
16// Copyright (C) 2009, 2012, 2018, 2021, 2022 Albert Astals Cid <aacid@kde.org>
17// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
18// Copyright (C) 2010, 2017 Adrian Johnson <ajohnson@redneon.com>
19// Copyright (C) 2010 Harry Roberts <harry.roberts@midnight-labs.org>
20// Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
21// Copyright (C) 2010 William Bader <williambader@hotmail.com>
22// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
23// Copyright (C) 2015 Adam Reichold <adamreichold@myopera.com>
24// Copyright (C) 2016 Kenji Uno <ku@digitaldolphins.jp>
25// Copyright (C) 2018 Martin Packman <gzlist@googlemail.com>
26// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
27//
28// To see a description of the changes please see the Changelog file that
29// came with your tarball or type make ChangeLog if you are building from git
30//
31//========================================================================
32
33#ifndef SPLASHBITMAP_H
34#define SPLASHBITMAP_H
35
36#include "SplashTypes.h"
37#include "poppler_private_export.h"
38#include <cstdio>
39#include <string>
40#include <vector>
41
42class ImgWriter;
43class GfxSeparationColorSpace;
44
45//------------------------------------------------------------------------
46// SplashBitmap
47//------------------------------------------------------------------------
48
49class POPPLER_PRIVATE_EXPORT SplashBitmap
50{
51public:
52 // Create a new bitmap. It will have <widthA> x <heightA> pixels in
53 // color mode <modeA>. Rows will be padded out to a multiple of
54 // <rowPad> bytes. If <topDown> is false, the bitmap will be stored
55 // upside-down, i.e., with the last row first in memory.
56 SplashBitmap(int widthA, int heightA, int rowPad, SplashColorMode modeA, bool alphaA, bool topDown = true, const std::vector<GfxSeparationColorSpace *> *separationList = nullptr);
57 static SplashBitmap *copy(const SplashBitmap *src);
58
59 ~SplashBitmap();
60
61 SplashBitmap(const SplashBitmap &) = delete;
62 SplashBitmap &operator=(const SplashBitmap &) = delete;
63
64 int getWidth() const { return width; }
65 int getHeight() const { return height; }
66 int getRowSize() const { return rowSize; }
67 int getAlphaRowSize() const { return width; }
68 int getRowPad() const { return rowPad; }
69 SplashColorMode getMode() const { return mode; }
70 SplashColorPtr getDataPtr() { return data; }
71 unsigned char *getAlphaPtr() { return alpha; }
72 std::vector<GfxSeparationColorSpace *> *getSeparationList() { return separationList; }
73 SplashColorConstPtr getDataPtr() const { return data; }
74 const unsigned char *getAlphaPtr() const { return alpha; }
75 const std::vector<GfxSeparationColorSpace *> *getSeparationList() const { return separationList; }
76
77 SplashError writePNMFile(char *fileName);
78 SplashError writePNMFile(FILE *f);
79 SplashError writeAlphaPGMFile(char *fileName);
80
81 struct WriteImgParams
82 {
83 int jpegQuality = -1;
84 bool jpegProgressive = false;
85 std::string tiffCompression;
86 bool jpegOptimize = false;
87 };
88
89 SplashError writeImgFile(SplashImageFileFormat format, const char *fileName, double hDPI, double vDPI, WriteImgParams *params = nullptr);
90 SplashError writeImgFile(SplashImageFileFormat format, FILE *f, double hDPI, double vDPI, WriteImgParams *params = nullptr);
91 SplashError writeImgFile(ImgWriter *writer, FILE *f, double hDPI, double vDPI, SplashColorMode imageWriterFormat);
92
93 enum ConversionMode
94 {
95 conversionOpaque,
96 conversionAlpha,
97 conversionAlphaPremultiplied
98 };
99
100 bool convertToXBGR(ConversionMode conversionMode = conversionOpaque);
101
102 void getPixel(int x, int y, SplashColorPtr pixel);
103 void getRGBLine(int y, SplashColorPtr line);
104 void getXBGRLine(int y, SplashColorPtr line, ConversionMode conversionMode = conversionOpaque);
105 void getCMYKLine(int y, SplashColorPtr line);
106 unsigned char getAlpha(int x, int y);
107
108 // Caller takes ownership of the bitmap data. The SplashBitmap
109 // object is no longer valid -- the next call should be to the
110 // destructor.
111 SplashColorPtr takeData();
112
113private:
114 int width, height; // size of bitmap
115 int rowPad;
116 int rowSize; // size of one row of data, in bytes
117 // - negative for bottom-up bitmaps
118 SplashColorMode mode; // color mode
119 SplashColorPtr data; // pointer to row zero of the color data
120 unsigned char *alpha; // pointer to row zero of the alpha data
121 // (always top-down)
122 std::vector<GfxSeparationColorSpace *> *separationList; // list of spot colorants and their mapping functions
123
124 friend class Splash;
125
126 void setJpegParams(ImgWriter *writer, WriteImgParams *params);
127};
128
129#endif
130

source code of poppler/splash/SplashBitmap.h