48
//! \note I assume that *in* contains only value between [0,1]
49
void gamma_levels_array(const pfs::Array2D* in, pfs::Array2D* out,
50
float black_in, float white_in,
51
float black_out, float white_out, float gamma)
53
// same formula used inside GammaAndLevels::refreshLUT()
54
//float value = powf( ( ((float)(i)/255.0f) - bin ) / (win-bin), expgamma);
55
//LUT[i] = clamp(blackout+value*(whiteout-blackout),0,255);
57
const float* in_vector = in->getRawData();
58
float* out_vector = out->getRawData();
60
const int ELEMS = in->getCols()*in->getRows();
64
#pragma omp parallel for
65
for (int idx = 0; idx < ELEMS; ++idx)
67
float tmp = (in_vector[idx] - black_in)/(white_in - black_in);
68
tmp = powf(tmp, gamma);
70
tmp = black_out + tmp*(white_out-black_out);
72
out_vector[idx] = clamp(tmp, 0.0f, 1.0f);
77
#pragma omp parallel for
78
for (int idx = 0; idx < ELEMS; ++idx)
80
float tmp = (in_vector[idx] - black_in)/(white_in - black_in);
81
//tmp = powf(tmp, gamma);
83
tmp = black_out + tmp*(white_out-black_out);
85
out_vector[idx] = clamp(tmp, 0.0f, 1.0f);
48
////! \note I assume that *in* contains only value between [0,1]
49
//void gamma_levels_array(const pfs::Array2D* in, pfs::Array2D* out,
50
// float black_in, float white_in,
51
// float black_out, float white_out, float gamma)
53
// // same formula used inside GammaAndLevels::refreshLUT()
54
// //float value = powf( ( ((float)(i)/255.0f) - bin ) / (win-bin), expgamma);
55
// //LUT[i] = clamp(blackout+value*(whiteout-blackout),0,255);
57
// const float* in_vector = in->getRawData();
58
// float* out_vector = out->getRawData();
60
// const int ELEMS = in->getCols()*in->getRows();
64
//#pragma omp parallel for
65
// for (int idx = 0; idx < ELEMS; ++idx)
67
// float tmp = (in_vector[idx] - black_in)/(white_in - black_in);
68
// tmp = powf(tmp, gamma);
70
// tmp = black_out + tmp*(white_out-black_out);
72
// out_vector[idx] = clamp(tmp, 0.0f, 1.0f);
77
//#pragma omp parallel for
78
// for (int idx = 0; idx < ELEMS; ++idx)
80
// float tmp = (in_vector[idx] - black_in)/(white_in - black_in);
81
// //tmp = powf(tmp, gamma);
83
// tmp = black_out + tmp*(white_out-black_out);
85
// out_vector[idx] = clamp(tmp, 0.0f, 1.0f);
95
pfs::Frame* gamma_levels(pfs::Frame* inFrame, float black_in, float white_in,
96
float black_out, float white_out, float gamma)
95
pfs::Frame* gamma_levels(pfs::Frame* inFrame,
96
float black_in, float white_in,
97
float black_out, float white_out,
98
100
#ifdef TIMER_PROFILING
99
101
msec_timer f_timer;
104
106
<< "White in =" << white_in << "white out =" << white_out
105
107
<< "Gamma =" << gamma;
109
109
const int outWidth = inFrame->getWidth();
110
110
const int outHeight = inFrame->getHeight();
112
pfs::Frame *outFrame = pfsio.createFrame(outWidth, outHeight);
114
pfs::ChannelIterator *it = inFrame->getChannels();
116
while (it->hasNext())
112
pfs::Frame* outFrame = new pfs::Frame(outWidth, outHeight);
114
pfs::Channel *Xc, *Yc, *Zc;
115
inFrame->getXYZChannels( Xc, Yc, Zc );
116
assert( Xc != NULL && Yc != NULL && Zc != NULL );
118
const float* R_i = Xc->getRawData();
119
const float* G_i = Yc->getRawData();
120
const float* B_i = Zc->getRawData();
122
outFrame->createXYZChannels( Xc, Yc, Zc );
123
assert( Xc != NULL && Yc != NULL && Zc != NULL );
125
float* R_o = Xc->getRawData();
126
float* G_o = Yc->getRawData();
127
float* B_o = Zc->getRawData();
129
// float exp_gamma = 1.f/gamma;
130
for (int idx = 0; idx < outWidth*outHeight; ++idx)
118
pfs::Channel *inCh = it->getNext();
119
pfs::Channel *outCh = outFrame->createChannel(inCh->getName());
121
pfs::Array2D* inArray2D = inCh->getChannelData();
122
pfs::Array2D* outArray2D = outCh->getChannelData();
124
gamma_levels_array(inArray2D, outArray2D, black_in, white_in,
125
black_out, white_out, gamma);
132
float red = R_i[idx];
133
float green = G_i[idx];
134
float blue = B_i[idx];
136
float L = 0.2126f * red
138
+ 0.0722f * blue; // number between [0..1]
140
float c = powf(L, gamma - 1.0f);
142
red = (red - black_in) / (white_in - black_in);
145
green = (green - black_in) / (white_in - black_in);
148
blue = (blue - black_in) / (white_in - black_in);
151
R_o[idx] = clamp(black_out + red * (white_out - black_out), 0.f, 1.f);
152
G_o[idx] = clamp(black_out + green * (white_out - black_out), 0.f, 1.f);
153
B_o[idx] = clamp(black_out + blue * (white_out - black_out), 0.f, 1.f);
128
156
pfs::copyTags(inFrame, outFrame);