Coverage Report

Created: 2026-07-30 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poppler/splash/SplashBitmap.h
Line
Count
Source
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, 2024-2026 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 "SplashErrorCodes.h"
37
#include "SplashTypes.h"
38
#include "poppler_private_export.h"
39
#include <cstdio>
40
#include <memory>
41
#include <string>
42
#include <vector>
43
44
class ImgWriter;
45
class GfxSeparationColorSpace;
46
47
//------------------------------------------------------------------------
48
// SplashBitmap
49
//------------------------------------------------------------------------
50
51
class POPPLER_PRIVATE_EXPORT SplashBitmap
52
{
53
public:
54
    // Create a new bitmap.  It will have <widthA> x <heightA> pixels in
55
    // color mode <modeA>.  Rows will be padded out to a multiple of
56
    // <rowPad> bytes.  If <topDown> is false, the bitmap will be stored
57
    // upside-down, i.e., with the last row first in memory.
58
    SplashBitmap(int widthA, int heightA, int rowPad, SplashColorMode modeA, bool alphaA, bool topDown = true, const std::vector<std::unique_ptr<GfxSeparationColorSpace>> *separationList = nullptr);
59
    static SplashBitmap *copy(const SplashBitmap *src);
60
61
    ~SplashBitmap();
62
63
    SplashBitmap(const SplashBitmap &) = delete;
64
    SplashBitmap &operator=(const SplashBitmap &) = delete;
65
66
0
    int getWidth() const { return width; }
67
0
    int getHeight() const { return height; }
68
0
    int getRowSize() const { return rowSize; }
69
0
    int getAlphaRowSize() const { return width; }
70
0
    int getRowPad() const { return rowPad; }
71
0
    SplashColorMode getMode() const { return mode; }
72
0
    SplashColorPtr getDataPtr() { return data; }
73
0
    unsigned char *getAlphaPtr() { return alpha; }
74
0
    std::vector<std::unique_ptr<GfxSeparationColorSpace>> *getSeparationList() { return separationList; }
75
0
    SplashColorConstPtr getDataPtr() const { return data; }
76
0
    const unsigned char *getAlphaPtr() const { return alpha; }
77
0
    const std::vector<std::unique_ptr<GfxSeparationColorSpace>> *getSeparationList() const { return separationList; }
78
79
    SplashError writePNMFile(char *fileName);
80
    SplashError writePNMFile(FILE *f);
81
    SplashError writeAlphaPGMFile(char *fileName);
82
83
    struct WriteImgParams
84
    {
85
        int jpegQuality = -1;
86
        bool jpegProgressive = false;
87
        std::string tiffCompression;
88
        bool jpegOptimize = false;
89
    };
90
91
    SplashError writeImgFile(SplashImageFileFormat format, const char *fileName, double hDPI, double vDPI, WriteImgParams *params = nullptr);
92
    SplashError writeImgFile(SplashImageFileFormat format, FILE *f, double hDPI, double vDPI, WriteImgParams *params = nullptr);
93
    SplashError writeImgFile(ImgWriter *writer, FILE *f, double hDPI, double vDPI, SplashColorMode imageWriterFormat);
94
95
    enum ConversionMode
96
    {
97
        conversionOpaque,
98
        conversionAlpha,
99
        conversionAlphaPremultiplied
100
    };
101
102
    bool convertToXBGR(ConversionMode conversionMode = conversionOpaque);
103
104
    void getPixel(int x, int y, SplashColorPtr pixel) const;
105
    void getRGBLine(int y, SplashColorPtr line);
106
    void getXBGRLine(int y, SplashColorPtr line, ConversionMode conversionMode = conversionOpaque);
107
    void getCMYKLine(int y, SplashColorPtr line);
108
    unsigned char getAlpha(int x, int y);
109
110
    // Caller takes ownership of the bitmap data.  The SplashBitmap
111
    // object is no longer valid -- the next call should be to the
112
    // destructor.
113
    SplashColorPtr takeData();
114
115
private:
116
    int width, height; // size of bitmap
117
    int rowPad;
118
    int rowSize; // size of one row of data, in bytes
119
                 //   - negative for bottom-up bitmaps
120
    SplashColorMode mode; // color mode
121
    SplashColorPtr data; // pointer to row zero of the color data
122
    unsigned char *alpha; // pointer to row zero of the alpha data
123
                          //   (always top-down)
124
    std::vector<std::unique_ptr<GfxSeparationColorSpace>> *separationList; // list of spot colorants and their mapping functions
125
126
    friend class Splash;
127
128
    static void setJpegParams(ImgWriter *writer, WriteImgParams *params);
129
};
130
131
#endif