Coverage Report

Created: 2025-07-23 08:13

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