| 202 | |
| 203 | template <typename PIX, int maxValue, int srcNComps, int dstNComps, bool ignorePremult> |
| 204 | void |
| 205 | Image::copyUnProcessedChannelsForPremult(const bool premult, |
| 206 | const bool originalPremult, |
| 207 | const std::bitset<4> processChannels, |
| 208 | const RectI& roi, |
| 209 | const ImagePtr& originalImage) |
| 210 | { |
| 211 | ReadAccess acc( originalImage.get() ); |
| 212 | int dstRowElements = dstNComps * _bounds.width(); |
| 213 | PIX* dst_pixels = (PIX*)pixelAt(roi.x1, roi.y1); |
| 214 | |
| 215 | assert(dst_pixels); |
| 216 | const bool doR = !processChannels[0] && (dstNComps >= 2); |
| 217 | const bool doG = !processChannels[1] && (dstNComps >= 2); |
| 218 | const bool doB = !processChannels[2] && (dstNComps >= 3); |
| 219 | const bool doA = !processChannels[3] && (dstNComps == 1 || dstNComps == 4); |
| 220 | assert(srcNComps == 4 || !originalPremult); // only RGBA can be premult |
| 221 | assert(dstNComps == 4 || !premult); // only RGBA can be premult |
| 222 | Q_UNUSED(premult); |
| 223 | Q_UNUSED(originalPremult); |
| 224 | |
| 225 | for ( int y = roi.y1; y < roi.y2; ++y, dst_pixels += (dstRowElements - (roi.x2 - roi.x1) * dstNComps) ) { |
| 226 | for (int x = roi.x1; x < roi.x2; ++x, dst_pixels += dstNComps) { |
| 227 | const PIX* src_pixels = originalImage ? (const PIX*)acc.pixelAt(x, y) : 0; |
| 228 | PIX srcA = src_pixels ? maxValue : 0; /* be opaque for anything that doesn't contain alpha */ |
| 229 | if ( ( (srcNComps == 1) || (srcNComps == 4) ) && src_pixels ) { |
| 230 | # ifdef DEBUG_NAN |
| 231 | assert( !std::isnan(src_pixels[srcNComps - 1]) ); // check for NaN |
| 232 | # endif |
| 233 | srcA = src_pixels[srcNComps - 1]; |
| 234 | } |
| 235 | # ifdef NATRON_COPY_CHANNELS_UNPREMULT |
| 236 | PIX dstAorig = maxValue; |
| 237 | # endif |
| 238 | if ( (dstNComps == 1) || (dstNComps == 4) ) { |
| 239 | # ifdef DEBUG_NAN |
| 240 | assert( !std::isnan(dst_pixels[dstNComps - 1]) ); // check for NaN |
| 241 | # endif |
| 242 | # ifdef NATRON_COPY_CHANNELS_UNPREMULT |
| 243 | dstAorig = dst_pixels[dstNComps - 1]; |
| 244 | # endif |
| 245 | } |
| 246 | if (doR) { |
| 247 | # ifdef DEBUG_NAN |
| 248 | assert(!src_pixels || !std::isnan(src_pixels[0]) ); // check for NaN |
| 249 | assert( !std::isnan(dst_pixels[0]) ); // check for NaN |
| 250 | # endif |
| 251 | DOCHANNEL(0); |
| 252 | # ifdef DEBUG_NAN |
| 253 | assert( !std::isnan(dst_pixels[0]) ); // check for NaN |
| 254 | # endif |
| 255 | } |
| 256 | if (doG) { |
| 257 | # ifdef DEBUG_NAN |
| 258 | assert(!src_pixels || !std::isnan(src_pixels[1]) ); // check for NaN |
| 259 | assert( !std::isnan(dst_pixels[1]) ); // check for NaN |
| 260 | # endif |
| 261 | DOCHANNEL(1); |