@@ -316,8 +316,9 @@ size_t ImageRegionIterator::getMemoryNeededForRemainingRegions() const
316
316
return memoryNeededForRemainingRegions;
317
317
}
318
318
319
- // These Swizzles makes sure copying from srcFormat image to promotedFormat image is consistent and extra "unused" channels will be ZERO and alpha will be ONE
320
- struct FourComponentSwizzle
319
+ // This Swizzles makes sure copying from srcFormat image to promotedFormat image is consistent and extra "unused" channels will be ZERO and alpha will be ONE
320
+ template <unsigned int SRC_CHANNELS>
321
+ struct PromotionComponentSwizzle
321
322
{
322
323
template <typename InT, typename OutT>
323
324
void operator ()(const InT* in, OutT* out) const
@@ -326,51 +327,21 @@ struct FourComponentSwizzle
326
327
using out_t = std::conditional_t <std::is_void_v<OutT>, uint64_t , OutT>;
327
328
328
329
reinterpret_cast <out_t *>(out)[0u ] = reinterpret_cast <const in_t *>(in)[0u ];
329
- reinterpret_cast <out_t *>(out)[1u ] = reinterpret_cast <const in_t *>(in)[1u ];
330
- reinterpret_cast <out_t *>(out)[2u ] = reinterpret_cast <const in_t *>(in)[2u ];
331
- reinterpret_cast <out_t *>(out)[3u ] = reinterpret_cast <const in_t *>(in)[3u ];
332
- }
333
- };
334
- struct ThreeComponentSwizzle
335
- {
336
- template <typename InT, typename OutT>
337
- void operator ()(const InT* in, OutT* out) const
338
- {
339
- using in_t = std::conditional_t <std::is_void_v<InT>, uint64_t , InT>;
340
- using out_t = std::conditional_t <std::is_void_v<OutT>, uint64_t , OutT>;
341
330
342
- reinterpret_cast <out_t *>(out)[0u ] = reinterpret_cast <const in_t *>(in)[0u ];
343
- reinterpret_cast <out_t *>(out)[1u ] = reinterpret_cast <const in_t *>(in)[1u ];
344
- reinterpret_cast <out_t *>(out)[2u ] = reinterpret_cast <const in_t *>(in)[2u ];
345
- reinterpret_cast <out_t *>(out)[3u ] = static_cast <in_t >(1 );
346
- }
347
- };
348
- struct TwoComponentSwizzle
349
- {
350
- template <typename InT, typename OutT>
351
- void operator ()(const InT* in, OutT* out) const
352
- {
353
- using in_t = std::conditional_t <std::is_void_v<InT>, uint64_t , InT>;
354
- using out_t = std::conditional_t <std::is_void_v<OutT>, uint64_t , OutT>;
331
+ if constexpr (SRC_CHANNELS > 1 )
332
+ reinterpret_cast <out_t *>(out)[1u ] = reinterpret_cast <const in_t *>(in)[1u ];
333
+ else
334
+ reinterpret_cast <out_t *>(out)[1u ] = static_cast <in_t >(0 );
355
335
356
- reinterpret_cast <out_t *>(out)[0u ] = reinterpret_cast <const in_t *>(in)[0u ];
357
- reinterpret_cast <out_t *>(out)[1u ] = reinterpret_cast <const in_t *>(in)[1u ];
358
- reinterpret_cast <out_t *>(out)[2u ] = static_cast <in_t >(0 );
359
- reinterpret_cast <out_t *>(out)[3u ] = static_cast <in_t >(1 );
360
- }
361
- };
362
- struct OneComponentSwizzle
363
- {
364
- template <typename InT, typename OutT>
365
- void operator ()(const InT* in, OutT* out) const
366
- {
367
- using in_t = std::conditional_t <std::is_void_v<InT>, uint64_t , InT>;
368
- using out_t = std::conditional_t <std::is_void_v<OutT>, uint64_t , OutT>;
336
+ if constexpr (SRC_CHANNELS > 2 )
337
+ reinterpret_cast <out_t *>(out)[2u ] = reinterpret_cast <const in_t *>(in)[2u ];
338
+ else
339
+ reinterpret_cast <out_t *>(out)[2u ] = static_cast <in_t >(0 );
369
340
370
- reinterpret_cast < out_t *>(out)[ 0u ] = reinterpret_cast < const in_t *>(in)[ 0u ];
371
- reinterpret_cast <out_t *>(out)[1u ] = static_cast < in_t >( 0 ) ;
372
- reinterpret_cast < out_t *>(out)[ 2u ] = static_cast < in_t >( 0 );
373
- reinterpret_cast <out_t *>(out)[3u ] = static_cast <in_t >(1 );
341
+ if constexpr (SRC_CHANNELS > 3 )
342
+ reinterpret_cast <out_t *>(out)[3u ] = reinterpret_cast < const in_t *>(in)[ 3u ] ;
343
+ else
344
+ reinterpret_cast <out_t *>(out)[3u ] = static_cast <in_t >(1 );
374
345
}
375
346
};
376
347
@@ -413,13 +384,13 @@ bool performCopy(
413
384
{
414
385
auto srcChannelCount = asset::getFormatChannelCount (srcImageFormat);
415
386
if (srcChannelCount == 1u )
416
- performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, OneComponentSwizzle >>(inCPUImage, outCPUImage, region);
387
+ performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, PromotionComponentSwizzle< 1u > >>(inCPUImage, outCPUImage, region);
417
388
else if (srcChannelCount == 2u )
418
- performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, TwoComponentSwizzle >>(inCPUImage, outCPUImage, region);
389
+ performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, PromotionComponentSwizzle< 2u > >>(inCPUImage, outCPUImage, region);
419
390
else if (srcChannelCount == 3u )
420
- performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, ThreeComponentSwizzle >>(inCPUImage, outCPUImage, region);
391
+ performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, PromotionComponentSwizzle< 3u > >>(inCPUImage, outCPUImage, region);
421
392
else
422
- performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, FourComponentSwizzle >>(inCPUImage, outCPUImage, region);
393
+ performCopyUsingImageFilter<asset::CSwizzleAndConvertImageFilter<asset::EF_UNKNOWN, asset::EF_UNKNOWN, PromotionComponentSwizzle< 4u > >>(inCPUImage, outCPUImage, region);
423
394
}
424
395
}
425
396
0 commit comments