MCPcopy Create free account
hub / github.com/MrKepzie/Natron / convertToFormatInternal_sameComps

Method convertToFormatInternal_sameComps

Engine/ImageConvert.cpp:137–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135///Fast version when components are the same
136template <typename SRCPIX, typename DSTPIX, int srcMaxValue, int dstMaxValue>
137void
138Image::convertToFormatInternal_sameComps(const RectI & renderWindow,
139 const Image & srcImg,
140 Image & dstImg,
141 ViewerColorSpaceEnum srcColorSpace,
142 ViewerColorSpaceEnum dstColorSpace,
143 bool copyBitmap)
144{
145 const RectI & r = srcImg._bounds;
146 RectI intersection;
147
148 if ( !renderWindow.intersect(r, &intersection) ) {
149 return;
150 }
151
152 ImageBitDepthEnum dstDepth = dstImg.getBitDepth();
153 ImageBitDepthEnum srcDepth = srcImg.getBitDepth();
154 int nComp = (int)srcImg.getComponentsCount();
155 const Color::Lut* const srcLut_ = lutFromColorspace(srcColorSpace);
156 const Color::Lut* const dstLut_ = lutFromColorspace(dstColorSpace);
157
158
159 ///no colorspace conversion applied when luts are the same
160 const Color::Lut* const srcLut = (srcLut_ == dstLut_) ? 0 : srcLut_;
161 const Color::Lut* const dstLut = (srcLut_ == dstLut_) ? 0 : dstLut_;
162 if ( intersection.isNull() ) {
163 return;
164 }
165 for (int y = 0; y < intersection.height(); ++y) {
166 // coverity[dont_call]
167 int start = rand() % intersection.width();
168 const SRCPIX* srcPixels = (const SRCPIX*)srcImg.pixelAt(intersection.x1 + start, intersection.y1 + y);
169 DSTPIX* dstPixels = (DSTPIX*)dstImg.pixelAt(intersection.x1 + start, intersection.y1 + y);
170 const SRCPIX* srcStart = srcPixels;
171 DSTPIX* dstStart = dstPixels;
172
173 for (int backward = 0; backward < 2; ++backward) {
174 int x = backward ? start - 1 : start;
175 int end = backward ? -1 : intersection.width();
176 unsigned error[3] = {
177 0x80, 0x80, 0x80
178 };
179
180 while ( x != end && x >= 0 && x < intersection.width() ) {
181 for (int k = 0; k < nComp; ++k) {
182# ifdef DEBUG
183 assert(srcPixels[k] == srcPixels[k]); // check for NaN
184# endif
185 DSTPIX pix;
186 if ( (k == 3) || (!srcLut && !dstLut) ) {
187 pix = convertPixelDepth<SRCPIX, DSTPIX>(srcPixels[k]);
188 } else {
189 float pixFloat;
190
191 if (srcLut) {
192 if (srcDepth == eImageBitDepthByte) {
193 pixFloat = srcLut->fromColorSpaceUint8ToLinearFloatFast(srcPixels[k]);
194 } else if (srcDepth == eImageBitDepthShort) {

Callers

nothing calls this directly

Tested by

no test coverage detected