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
21OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
22
23
24struct IMF_EXPORT_TYPE PreviewRgba
25{
26 unsigned char r; // Red, green and blue components of
27 unsigned char g; // the pixel's color; intensity is
28 unsigned char b; // proportional to pow (x/255, 2.2),
29 // where x is r, g, or b.
30
31 unsigned char a; // The pixel's alpha; 0 == transparent,
32 // 255 == opaque.
33
34 PreviewRgba (unsigned char r = 0,
35 unsigned char g = 0,
36 unsigned char b = 0,
37 unsigned char a = 255)
38 : r(r), g(g), b(b), a(a) {}
39};
40
41
42class IMF_EXPORT_TYPE PreviewImage
43{
44 public:
45
46 //--------------------------------------------------------------------
47 // Constructor:
48 //
49 // PreviewImage(w,h,p) constructs a preview image with w by h pixels
50 // whose initial values are specified in pixel array p. The x and y
51 // coordinates of the pixels in p go from 0 to w-1, and from 0 to h-1.
52 // The pixel with coordinates (x, y) is at address p + y*w + x.
53 // Pixel (0, 0) is in the upper left corner of the preview image.
54 // If p is zero, the pixels in the preview image are initialized with
55 // (r = 0, b = 0, g = 0, a = 255).
56 //
57 //--------------------------------------------------------------------
58
59 IMF_EXPORT
60 PreviewImage (unsigned int width = 0,
61 unsigned int height = 0,
62 const PreviewRgba pixels[] = 0);
63
64 //-----------------------------------------------------
65 // Copy constructor, destructor and assignment operator
66 //-----------------------------------------------------
67
68 IMF_EXPORT
69 PreviewImage (const PreviewImage &other);
70 IMF_EXPORT
71 ~PreviewImage ();
72
73 IMF_EXPORT
74 PreviewImage & operator = (const PreviewImage &other);
75
76
77 //-----------------------------------------------
78 // Access to width, height and to the pixel array
79 //-----------------------------------------------
80
81 inline
82 unsigned int width () const {return _width;}
83 inline
84 unsigned int height () const {return _height;}
85
86 inline
87 PreviewRgba * pixels () {return _pixels;}
88 inline
89 const PreviewRgba * pixels () const {return _pixels;}
90
91
92 //----------------------------
93 // Access to individual pixels
94 //----------------------------
95
96 inline
97 PreviewRgba & pixel (unsigned int x, unsigned int y)
98 {return _pixels[y * _width + x];}
99
100 inline
101 const PreviewRgba & pixel (unsigned int x, unsigned int y) const
102 {return _pixels[y * _width + x];}
103
104 private:
105
106 unsigned int _width;
107 unsigned int _height;
108 PreviewRgba * _pixels;
109};
110
111
112OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
113
114#endif
115

source code of include/OpenEXR/ImfPreviewImage.h