| 2429 | |
| 2430 | template <typename PIX, int maxValue, int srcNComps, int dstNComps> |
| 2431 | static void |
| 2432 | convertNatronImageToCairoImageForComponents(unsigned char* cairoImg, |
| 2433 | std::size_t stride, |
| 2434 | Image* image, |
| 2435 | const RectI& roi, |
| 2436 | const RectI& dstBounds, |
| 2437 | double shapeColor[3]) |
| 2438 | { |
| 2439 | unsigned char* dstPix = cairoImg; |
| 2440 | |
| 2441 | dstPix += ( (roi.y1 - dstBounds.y1) * stride + (roi.x1 - dstBounds.x1) ); |
| 2442 | |
| 2443 | Image::ReadAccess acc = image->getReadRights(); |
| 2444 | |
| 2445 | for (int y = 0; y < roi.height(); ++y, dstPix += stride) { |
| 2446 | const PIX* srcPix = (const PIX*)acc.pixelAt(roi.x1, roi.y1 + y); |
| 2447 | assert(srcPix); |
| 2448 | |
| 2449 | for (int x = 0; x < roi.width(); ++x) { |
| 2450 | # ifdef DEBUG_NAN |
| 2451 | for (int c = 0; c < srcNComps; ++c) { |
| 2452 | assert( !std::isnan(srcPix[x * srcNComps + c]) ); // check for NaN |
| 2453 | } |
| 2454 | # endif |
| 2455 | if (dstNComps == 1) { |
| 2456 | dstPix[x] = (float)srcPix[x * srcNComps] * (255.f / maxValue); |
| 2457 | } else if (dstNComps == 4) { |
| 2458 | if (srcNComps == 4) { |
| 2459 | //We are in the !buildUp case, do exactly the opposite that is done in convertNatronImageToCairoImageForComponents |
| 2460 | dstPix[x * dstNComps + 0] = shapeColor[2] == 0 ? 0 : (float)(srcPix[x * srcNComps + 2] * (255.f / maxValue) ) / shapeColor[2]; |
| 2461 | dstPix[x * dstNComps + 1] = shapeColor[1] == 0 ? 0 : (float)(srcPix[x * srcNComps + 1] * (255.f / maxValue) ) / shapeColor[1]; |
| 2462 | dstPix[x * dstNComps + 2] = shapeColor[0] == 0 ? 0 : (float)(srcPix[x * srcNComps + 0] * (255.f / maxValue) ) / shapeColor[0]; |
| 2463 | dstPix[x * dstNComps + 3] = 255; //(float)srcPix[x * srcNComps + 3] * (255.f / maxValue); |
| 2464 | } else { |
| 2465 | assert(srcNComps == 1); |
| 2466 | float pix = (float)srcPix[x]; |
| 2467 | dstPix[x * dstNComps + 0] = pix * (255.f / maxValue); |
| 2468 | dstPix[x * dstNComps + 1] = pix * (255.f / maxValue); |
| 2469 | dstPix[x * dstNComps + 2] = pix * (255.f / maxValue); |
| 2470 | dstPix[x * dstNComps + 3] = pix * (255.f / maxValue); |
| 2471 | } |
| 2472 | } |
| 2473 | // no need to check for NaN, dstPix is unsigned char |
| 2474 | } |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | template <typename PIX, int maxValue, int srcComps> |
| 2479 | static void |
nothing calls this directly
no test coverage detected