Coverage Report

Created: 2025-07-16 07:53

/usr/local/include/OpenEXR/ImfPreviewImage.h
Line
Count
Source (jump to first uncovered line)
1
//
2
// SPDX-License-Identifier: BSD-3-Clause
3
// Copyright (c) Contributors to the OpenEXR Project.
4
//
5
6
#ifndef INCLUDED_IMF_PREVIEW_IMAGE_H
7
#define INCLUDED_IMF_PREVIEW_IMAGE_H
8
9
#include "ImfForward.h"
10
11
//-----------------------------------------------------------------------------
12
//
13
//  class PreviewImage -- a usually small, low-dynamic range image,
14
//  that is intended to be stored in an image file's header.
15
//
16
//  struct PreviewRgba -- holds the value of a PreviewImage pixel.
17
//
18
//-----------------------------------------------------------------------------
19
20
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
21
22
struct IMF_EXPORT_TYPE PreviewRgba
23
{
24
    unsigned char r; // Red, green and blue components of
25
    unsigned char g; // the pixel's color; intensity is
26
    unsigned char b; // proportional to pow (x/255, 2.2),
27
        // where x is r, g, or b.
28
29
    unsigned char a; // The pixel's alpha; 0 == transparent,
30
        // 255 == opaque.
31
32
    PreviewRgba (
33
        unsigned char r = 0,
34
        unsigned char g = 0,
35
        unsigned char b = 0,
36
        unsigned char a = 255)
37
2.92k
        : r (r), g (g), b (b), a (a)
38
2.92k
    {}
39
40
        bool operator==(const PreviewRgba& other) const
41
0
        {
42
0
            return r == other.r && g == other.g && b == other.b && a == other.a;
43
0
        }
44
};
45
46
class IMF_EXPORT_TYPE PreviewImage
47
{
48
public:
49
    //--------------------------------------------------------------------
50
    // Constructor:
51
    //
52
    // PreviewImage(w,h,p) constructs a preview image with w by h pixels
53
    // whose initial values are specified in pixel array p.  The x and y
54
    // coordinates of the pixels in p go from 0 to w-1, and from 0 to h-1.
55
    // The pixel with coordinates (x, y) is at address p + y*w + x.
56
    // Pixel (0, 0) is in the upper left corner of the preview image.
57
    // If p is zero, the pixels in the preview image are initialized with
58
    // (r = 0, b = 0, g = 0, a = 255).
59
    //
60
    //--------------------------------------------------------------------
61
62
    IMF_EXPORT
63
    PreviewImage (
64
        unsigned int      width    = 0,
65
        unsigned int      height   = 0,
66
        const PreviewRgba pixels[] = 0);
67
68
    //-----------------------------------------------------
69
    // Copy constructor, destructor and assignment operator
70
    //-----------------------------------------------------
71
72
    IMF_EXPORT
73
    PreviewImage (const PreviewImage& other);
74
    IMF_EXPORT
75
    ~PreviewImage ();
76
77
    IMF_EXPORT
78
    PreviewImage& operator= (const PreviewImage& other);
79
80
    //-----------------------------------------------
81
    // Access to width, height and to the pixel array
82
    //-----------------------------------------------
83
84
    inline unsigned int width () const { return _width; }
85
    inline unsigned int height () const { return _height; }
86
87
    inline PreviewRgba*       pixels () { return _pixels; }
88
    inline const PreviewRgba* pixels () const { return _pixels; }
89
90
    //----------------------------
91
    // Access to individual pixels
92
    //----------------------------
93
94
    inline PreviewRgba& pixel (unsigned int x, unsigned int y)
95
0
    {
96
0
        return _pixels[y * _width + x];
97
0
    }
98
99
    inline const PreviewRgba& pixel (unsigned int x, unsigned int y) const
100
0
    {
101
0
        return _pixels[y * _width + x];
102
0
    }
103
104
private:
105
    unsigned int _width;
106
    unsigned int _height;
107
    PreviewRgba* _pixels;
108
};
109
110
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
111
112
#endif