Coverage Report

Created: 2025-07-11 06:50

/src/xpdf-4.05/splash/SplashBitmap.h
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// SplashBitmap.h
4
//
5
// Copyright 2003-2013 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#ifndef SPLASHBITMAP_H
10
#define SPLASHBITMAP_H
11
12
#include <aconf.h>
13
14
#include <stdio.h>
15
#include <limits.h>
16
// older compilers won't define SIZE_MAX in stdint.h without this
17
#ifndef __STDC_LIMIT_MACROS
18
#  define __STDC_LIMIT_MACROS 1
19
#endif
20
#include <stdint.h>
21
#include "SplashTypes.h"
22
23
//------------------------------------------------------------------------
24
25
// ssize_t isn't well-defined, so define our own
26
#if SIZE_MAX == UINT_MAX
27
  typedef int SplashBitmapRowSize;
28
# define SplashBitmapRowSizeMax INT_MAX
29
#else
30
  typedef long long SplashBitmapRowSize;
31
# define SplashBitmapRowSizeMax LLONG_MAX
32
#endif
33
34
//------------------------------------------------------------------------
35
// SplashBitmap
36
//------------------------------------------------------------------------
37
38
class SplashBitmap {
39
public:
40
41
  // Create a new bitmap.  It will have <widthA> x <heightA> pixels in
42
  // color mode <modeA>.  Rows will be padded out to a multiple of
43
  // <rowPad> bytes.  If <topDown> is false, the bitmap will be stored
44
  // upside-down, i.e., with the last row first in memory.
45
  SplashBitmap(int widthA, int heightA, int rowPad,
46
         SplashColorMode modeA, GBool alphaA,
47
         GBool topDown, SplashBitmap *parentA);
48
49
  ~SplashBitmap();
50
51
0
  int getWidth() { return width; }
52
0
  int getHeight() { return height; }
53
0
  SplashBitmapRowSize getRowSize() { return rowSize; }
54
0
  size_t getAlphaRowSize() { return alphaRowSize; }
55
0
  SplashColorMode getMode() { return mode; }
56
0
  SplashColorPtr getDataPtr() { return data; }
57
0
  Guchar *getAlphaPtr() { return alpha; }
58
59
  SplashError writePNMFile(char *fileName);
60
  SplashError writePNMFile(FILE *f);
61
  SplashError writeAlphaPGMFile(char *fileName);
62
63
  void getPixel(int x, int y, SplashColorPtr pixel);
64
  Guchar getAlpha(int x, int y);
65
66
  // Caller takes ownership of the bitmap data.  The SplashBitmap
67
  // object is no longer valid -- the next call should be to the
68
  // destructor.
69
  SplashColorPtr takeData();
70
71
private:
72
73
  int width, height;    // size of bitmap
74
  SplashBitmapRowSize rowSize;  // size of one row of data, in bytes
75
        //   - negative for bottom-up bitmaps
76
  size_t alphaRowSize;    // size of one row of alpha, in bytes
77
  SplashColorMode mode;   // color mode
78
  SplashColorPtr data;    // pointer to row zero of the color data
79
  Guchar *alpha;    // pointer to row zero of the alpha data
80
        //   (always top-down)
81
82
  // save the last-allocated (large) bitmap data and reuse if possible
83
  SplashBitmap *parent;
84
  SplashColorPtr oldData;
85
  Guchar *oldAlpha;
86
  SplashBitmapRowSize oldRowSize;
87
  size_t oldAlphaRowSize;
88
  int oldHeight;
89
90
  friend class Splash;
91
};
92
93
94
#endif