-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleImage.h
67 lines (51 loc) · 1.7 KB
/
SimpleImage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef SimpleImage_h
#define SimpleImage_h
#include <string>
#include <vector>
#include <memory>
#include <OpenEXR/ImathVec.h>
#include <OpenEXR/ImfHeader.h>
#include <OpenEXR/ImathMatrix.h>
using namespace std;
// A simple container for an output EXR containing only RGBA data.
//
// This can also be used to hold a mask, in which case the data will be
// in A, and R, G, and B will be 1.
class SimpleImage
{
public:
vector<Imath::V4f> data;
int width, height;
Imf::Header header;
SimpleImage(int width, int height);
SimpleImage(const SimpleImage &cpy);
const Imath::V4f &GetRGBA(int x, int y) const { return const_cast<SimpleImage *>(this)->GetRGBA(x, y); }
Imath::V4f &GetRGBA(int x, int y)
{
const int pixelIdx = x + y*width;
return data[pixelIdx];
}
void SetColor(Imath::V4f color);
// Convert between linear color and sRGB in-place.
void LinearToSRGB();
void SRGBToLinear();
void Premultiply();
void Unpremultiply();
// Transform a normal map by a matrix. The 4th channel (w) will be left unchanged.
void TransformNormalMap(Imath::M44f matrix);
class EXRLayersToWrite
{
public:
EXRLayersToWrite(shared_ptr<const SimpleImage> image_): image(image_) { }
// The source image.
shared_ptr<const SimpleImage> image;
// The layer name to write this as, or blank for no layer.
string layerName;
// If false, write RGBA. Otherwise, write only alpha as a luminance channel (Y).
bool alphaOnly = false;
};
static void WriteImages(string filename, vector<EXRLayersToWrite> layers);
// Return true if this image is completely transparent.
bool IsEmpty() const;
};
#endif