MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / Fit

Method Fit

src/OpenColorIO/transforms/MatrixTransform.cpp:162–188  ·  view source on GitHub ↗

Fit is canonically formulated as: out = newmin + ((value-oldmin)/(oldmax-oldmin)*(newmax-newmin)) I.e., subtract the old offset, descale into the [0,1] range, scale into the new range, and add the new offset We algebraiclly manipulate the terms into y = mx + b form as: m = (newmax-newmin)/(oldmax-oldmin) b = (newmin*oldmax - newmax*oldmin) / (oldmax-oldmin) */

Source from the content-addressed store, hash-verified

160b = (newmin*oldmax - newmax*oldmin) / (oldmax-oldmin)
161*/
162void MatrixTransform::Fit(double * m44, double * offset4,
163 const double * oldmin4, const double * oldmax4,
164 const double * newmin4, const double * newmax4)
165{
166 if(!oldmin4 || !oldmax4) return;
167 if(!newmin4 || !newmax4) return;
168
169 if(m44) memset(m44, 0, 16*sizeof(double));
170 if(offset4) memset(offset4, 0, 4*sizeof(double));
171
172 for(int i=0; i<4; ++i)
173 {
174 double denom = oldmax4[i] - oldmin4[i];
175 if(IsScalarEqualToZero(denom))
176 {
177 std::ostringstream os;
178 os << "Cannot create Fit operator. ";
179 os << "Max value equals min value '";
180 os << oldmax4[i] << "' in channel index ";
181 os << i << ".";
182 throw Exception(os.str().c_str());
183 }
184
185 if(m44) m44[5*i] = (newmax4[i]-newmin4[i]) / denom;
186 if(offset4) offset4[i] = (newmin4[i]*oldmax4[i] - newmax4[i]*oldmin4[i]) / denom;
187 }
188}
189
190void MatrixTransform::Identity(double * m44, double * offset4)
191{

Callers 2

test_interfaceMethod · 0.95
test_interfaceMethod · 0.95

Calls 1

IsScalarEqualToZeroFunction · 0.85

Tested by 2

test_interfaceMethod · 0.76
test_interfaceMethod · 0.76