-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEXROperation.cpp
87 lines (74 loc) · 2.22 KB
/
EXROperation.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "EXROperation.h"
#include "DeepImage.h"
#include "DeepImageUtil.h"
#include <OpenEXR/ImfChannelList.h>
bool SharedConfig::ParseOption(string opt, string value)
{
if(opt == "input")
{
inputFilenames.push_back(value);
return true;
}
else if(opt == "output")
{
outputPath = value;
return true;
}
else if(opt == "units")
{
if(value == "cm")
worldSpaceScale = 100;
else if(value == "meters")
worldSpaceScale = 100; // cm per meter
else if(value == "feet")
worldSpaceScale = 30.48f; // cm per foot
else
worldSpaceScale = (float) atof(value.c_str());
if(worldSpaceScale < 0.0001f)
throw StringException("Invalid world space scale: " + value);
}
else if(opt == "id")
{
// Change the name of the layer used for IDs.
explicitIdChannel = value;
return true;
}
return false;
}
string SharedConfig::GetIdChannel(const Imf::Header &header) const
{
if(!explicitIdChannel.empty())
return explicitIdChannel;
// If no ID channel was specified explicitly with --id, search for both "ID" and "id".
if(header.channels().findChannel("id") != NULL)
return "id";
else
return "ID";
}
shared_ptr<DeepImage> EXROperationState::GetOutputImage()
{
if(newImage)
return newImage;
newImage = make_shared<DeepImage>(image->width, image->height);
newImage->header = image->header;
for(auto it: image->channels)
{
string name = it.first;
shared_ptr<const DeepImageChannel> channel = it.second;
shared_ptr<DeepImageChannel> newChannel(channel->CreateSameType(newImage->sampleCount));
newImage->channels[name] = newChannel;
}
waitingImages.push_back(newImage);
return newImage;
}
void EXROperationState::CombineWaitingImages()
{
if(waitingImages.empty())
return;
// Add the old image first, so we copy its attributes.
waitingImages.insert(waitingImages.begin(), image);
image = DeepImageUtil::CombineImages(waitingImages);
waitingImages.clear();
// Sort samples in the combined image.
DeepImageUtil::SortSamplesByDepth(image);
}