MaterialX 1.38.2
Image.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_IMAGE_H
7#define MATERIALX_IMAGE_H
8
11
13
15
16#include <MaterialXCore/Types.h>
17
18namespace MaterialX
19{
20
21class Image;
22
24using ImagePtr = shared_ptr<Image>;
25
27using ConstImagePtr = shared_ptr<const Image>;
28
30using ImageMap = std::unordered_map<string, ImagePtr>;
31
33using ImageVec = std::vector<ImagePtr>;
34
36using ImagePair = std::pair<ImagePtr, ImagePtr>;
37
39using ImageBufferDeallocator = std::function<void(void*)>;
40
43class MX_RENDER_API Image
44{
45 public:
46 enum class BaseType
47 {
48 UINT8 = 0,
49 UINT16 = 1,
50 HALF = 2,
51 FLOAT = 3
52 };
53
54 public:
56 static ImagePtr create(unsigned int width, unsigned int height, unsigned int channelCount, BaseType baseType = BaseType::UINT8)
57 {
58 return ImagePtr(new Image(width, height, channelCount, baseType));
59 }
60
61 ~Image();
62
65
67 unsigned int getWidth() const
68 {
69 return _width;
70 }
71
73 unsigned int getHeight() const
74 {
75 return _height;
76 }
77
79 unsigned int getChannelCount() const
80 {
81 return _channelCount;
82 }
83
85 BaseType getBaseType() const
86 {
87 return _baseType;
88 }
89
91 unsigned int getBaseStride() const;
92
94 unsigned int getRowStride() const
95 {
96 return _width * _channelCount * getBaseStride();
97 }
98
100 unsigned int getMaxMipCount() const;
101
105
108 void setTexelColor(unsigned int x, unsigned int y, const Color4& color);
109
112 Color4 getTexelColor(unsigned int x, unsigned int y) const;
113
117
119 Color4 getAverageColor();
120
123 bool isUniformColor(Color4* uniformColor = nullptr);
124
128
130 void setUniformColor(const Color4& color);
131
133 ImagePtr applyBoxBlur();
134
136 ImagePtr applyGaussianBlur();
137
140 ImagePair splitByLuminance(float luminance);
141
144 void writeTable(const FilePath& filePath, unsigned int channel);
145
149
151 void setResourceBuffer(void* buffer)
152 {
153 _resourceBuffer = buffer;
154 }
155
157 void* getResourceBuffer() const
158 {
159 return _resourceBuffer;
160 }
161
163 void createResourceBuffer();
164
166 void releaseResourceBuffer();
167
170 {
171 _resourceBufferDeallocator = deallocator;
172 }
173
176 {
177 return _resourceBufferDeallocator;
178 }
179
183
185 void setResourceId(unsigned int id)
186 {
187 _resourceId = id;
188 }
189
191 unsigned int getResourceId() const
192 {
193 return _resourceId;
194 }
195
197
198 protected:
199 Image(unsigned int width, unsigned int height, unsigned int channelCount, BaseType baseType);
200
201 protected:
202 unsigned int _width;
203 unsigned int _height;
204 unsigned int _channelCount;
205 BaseType _baseType;
206
207 void* _resourceBuffer;
208 ImageBufferDeallocator _resourceBufferDeallocator;
209 unsigned int _resourceId;
210};
211
213MX_RENDER_API ImagePtr createUniformImage(unsigned int width, unsigned int height, unsigned int channelCount, Image::BaseType baseType, const Color4& color);
214
216MX_RENDER_API ImagePtr createImageStrip(const vector<ImagePtr>& imageVec);
217
219MX_RENDER_API std::pair<unsigned int, unsigned int> getMaxDimensions(const vector<ImagePtr>& imageVec);
220
221} // namespace MaterialX
222
223#endif
Cross-platform support for file and search paths.
shared_ptr< const Image > ConstImagePtr
A shared pointer to a const image.
Definition: Image.h:27
std::function< void(void *)> ImageBufferDeallocator
A function to perform image buffer deallocation.
Definition: Image.h:39
std::vector< ImagePtr > ImageVec
A vetor of images.
Definition: Image.h:33
std::unordered_map< string, ImagePtr > ImageMap
A map from strings to images.
Definition: Image.h:30
std::pair< ImagePtr, ImagePtr > ImagePair
A pair of images.
Definition: Image.h:36
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:24
Data type classes.
Macros for declaring imported and exported symbols.
A four-component color value.
Definition: Types.h:389
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:28
Class representing an image in system memory.
Definition: Image.h:44
void setResourceBufferDeallocator(ImageBufferDeallocator deallocator)
Set the resource buffer deallocator for this image.
Definition: Image.h:169
BaseType getBaseType() const
Return the base type of the image.
Definition: Image.h:85
unsigned int getHeight() const
Return the height of the image.
Definition: Image.h:73
unsigned int getChannelCount() const
Return the channel count of the image.
Definition: Image.h:79
unsigned int getResourceId() const
Return the resource ID for this image.
Definition: Image.h:191
void setResourceBuffer(void *buffer)
Set the resource buffer for this image.
Definition: Image.h:151
void setResourceId(unsigned int id)
Set the resource ID for this image.
Definition: Image.h:185
unsigned int getWidth() const
Return the width of the image.
Definition: Image.h:67
static ImagePtr create(unsigned int width, unsigned int height, unsigned int channelCount, BaseType baseType=BaseType::UINT8)
Create an empty image with the given properties.
Definition: Image.h:56
void * getResourceBuffer() const
Return the resource buffer for this image.
Definition: Image.h:157
unsigned int getRowStride() const
Return the stride of an image row in bytes.
Definition: Image.h:94
ImageBufferDeallocator getResourceBufferDeallocator() const
Return the resource buffer deallocator for this image.
Definition: Image.h:175