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