-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConvectionKernels_UnfinishedEndpoints.h
121 lines (101 loc) · 4.62 KB
/
ConvectionKernels_UnfinishedEndpoints.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include "ConvectionKernels_Util.h"
namespace cvtt
{
namespace Internal
{
template<int TVectorSize>
class UnfinishedEndpoints
{
public:
typedef ParallelMath::Float MFloat;
typedef ParallelMath::UInt16 MUInt16;
typedef ParallelMath::UInt15 MUInt15;
typedef ParallelMath::SInt16 MSInt16;
typedef ParallelMath::SInt32 MSInt32;
UnfinishedEndpoints()
{
}
UnfinishedEndpoints(const MFloat *base, const MFloat *offset)
{
for (int ch = 0; ch < TVectorSize; ch++)
m_base[ch] = base[ch];
for (int ch = 0; ch < TVectorSize; ch++)
m_offset[ch] = offset[ch];
}
UnfinishedEndpoints(const UnfinishedEndpoints& other)
{
for (int ch = 0; ch < TVectorSize; ch++)
m_base[ch] = other.m_base[ch];
for (int ch = 0; ch < TVectorSize; ch++)
m_offset[ch] = other.m_offset[ch];
}
void FinishHDRUnsigned(int tweak, int range, MSInt16 *outEP0, MSInt16 *outEP1, ParallelMath::RoundTowardNearestForScope *roundingMode)
{
float tweakFactors[2];
Util::ComputeTweakFactors(tweak, range, tweakFactors);
for (int ch = 0; ch < TVectorSize; ch++)
{
MUInt15 channelEPs[2];
for (int epi = 0; epi < 2; epi++)
{
MFloat f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[epi], 0.0f, 31743.0f);
channelEPs[epi] = ParallelMath::RoundAndConvertToU15(f, roundingMode);
}
outEP0[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(channelEPs[0]);
outEP1[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(channelEPs[1]);
}
}
void FinishHDRSigned(int tweak, int range, MSInt16* outEP0, MSInt16* outEP1, ParallelMath::RoundTowardNearestForScope* roundingMode)
{
float tweakFactors[2];
Util::ComputeTweakFactors(tweak, range, tweakFactors);
for (int ch = 0; ch < TVectorSize; ch++)
{
MSInt16 channelEPs[2];
for (int epi = 0; epi < 2; epi++)
{
MFloat f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[epi], -31743.0f, 31743.0f);
channelEPs[epi] = ParallelMath::RoundAndConvertToS16(f, roundingMode);
}
outEP0[ch] = channelEPs[0];
outEP1[ch] = channelEPs[1];
}
}
void FinishLDR(int tweak, int range, MUInt15* outEP0, MUInt15* outEP1)
{
ParallelMath::RoundTowardNearestForScope roundingMode;
float tweakFactors[2];
Util::ComputeTweakFactors(tweak, range, tweakFactors);
for (int ch = 0; ch < TVectorSize; ch++)
{
MFloat ep0f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[0], 0.0f, 255.0f);
MFloat ep1f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[1], 0.0f, 255.0f);
outEP0[ch] = ParallelMath::RoundAndConvertToU15(ep0f, &roundingMode);
outEP1[ch] = ParallelMath::RoundAndConvertToU15(ep1f, &roundingMode);
}
}
template<int TNewVectorSize>
UnfinishedEndpoints<TNewVectorSize> ExpandTo(float filler)
{
MFloat newBase[TNewVectorSize];
MFloat newOffset[TNewVectorSize];
for (int ch = 0; ch < TNewVectorSize && ch < TVectorSize; ch++)
{
newBase[ch] = m_base[ch];
newOffset[ch] = m_offset[ch];
}
MFloat fillerV = ParallelMath::MakeFloat(filler);
for (int ch = TVectorSize; ch < TNewVectorSize; ch++)
{
newBase[ch] = fillerV;
newOffset[ch] = ParallelMath::MakeFloatZero();
}
return UnfinishedEndpoints<TNewVectorSize>(newBase, newOffset);
}
private:
MFloat m_base[TVectorSize];
MFloat m_offset[TVectorSize];
};
}
}