Krita Source Code Documentation
Loading...
Searching...
No Matches
PixelWrapper< quint16, _impl > Struct Template Reference

#include <KoStreamedMath.h>

Public Types

using float_v = xsimd::batch<float, _impl>
 
using int_v = xsimd::batch<int, _impl>
 
using uint_v = xsimd::batch<unsigned int, _impl>
 

Public Member Functions

ALWAYS_INLINE void clearPixels (quint8 *dataDst)
 
ALWAYS_INLINE void copyPixels (const quint8 *dataSrc, quint8 *dataDst)
 
 PixelWrapper ()
 
ALWAYS_INLINE void read (const void *src, float_v &dst_c1, float_v &dst_c2, float_v &dst_c3, float_v &dst_alpha)
 
ALWAYS_INLINE void write (void *dst, const float_v &c1, const float_v &c2, const float_v &c3, const float_v &a)
 

Static Public Member Functions

static ALWAYS_INLINE void denormalizeAlpha (float &alpha)
 
static ALWAYS_INLINE quint16 lerpMixedUintFloat (quint16 a, quint16 b, float alpha)
 
static ALWAYS_INLINE void normalizeAlpha (float &alpha)
 
static ALWAYS_INLINE quint16 roundFloatToUint (float x)
 

Public Attributes

const uint_v mask
 
const float_v uint16Max
 
const float_v uint16Rec1
 

Detailed Description

template<class _impl>
struct PixelWrapper< quint16, _impl >

Definition at line 567 of file KoStreamedMath.h.

Member Typedef Documentation

◆ float_v

template<class _impl >
using PixelWrapper< quint16, _impl >::float_v = xsimd::batch<float, _impl>

Definition at line 570 of file KoStreamedMath.h.

◆ int_v

template<class _impl >
using PixelWrapper< quint16, _impl >::int_v = xsimd::batch<int, _impl>

Definition at line 568 of file KoStreamedMath.h.

◆ uint_v

template<class _impl >
using PixelWrapper< quint16, _impl >::uint_v = xsimd::batch<unsigned int, _impl>

Definition at line 569 of file KoStreamedMath.h.

Constructor & Destructor Documentation

◆ PixelWrapper()

template<class _impl >
PixelWrapper< quint16, _impl >::PixelWrapper ( )
inline

Definition at line 601 of file KoStreamedMath.h.

602 : mask(0xFFFF)
603 , uint16Max(65535.0f)
604 , uint16Rec1(1.0f / 65535.0f)
605 {
606 }

Member Function Documentation

◆ clearPixels()

template<class _impl >
ALWAYS_INLINE void PixelWrapper< quint16, _impl >::clearPixels ( quint8 * dataDst)
inline

Definition at line 661 of file KoStreamedMath.h.

662 {
663 memset(dataDst, 0, float_v::size * sizeof(quint16) * 4);
664 }

◆ copyPixels()

template<class _impl >
ALWAYS_INLINE void PixelWrapper< quint16, _impl >::copyPixels ( const quint8 * dataSrc,
quint8 * dataDst )
inline

Definition at line 667 of file KoStreamedMath.h.

668 {
669 memcpy(dataDst, dataSrc, float_v::size * sizeof(quint16) * 4);
670 }

◆ denormalizeAlpha()

template<class _impl >
static ALWAYS_INLINE void PixelWrapper< quint16, _impl >::denormalizeAlpha ( float & alpha)
inlinestatic

Definition at line 595 of file KoStreamedMath.h.

596 {
597 const float uint16Max = 65535.0f;
598 alpha *= uint16Max;
599 }

◆ lerpMixedUintFloat()

template<class _impl >
static ALWAYS_INLINE quint16 PixelWrapper< quint16, _impl >::lerpMixedUintFloat ( quint16 a,
quint16 b,
float alpha )
inlinestatic

Definition at line 576 of file KoStreamedMath.h.

577 {
578 return OptiRound<_impl, quint16>::roundScalar((float(b) - a) * alpha + float(a));
579 }
static ALWAYS_INLINE result_type roundScalar(const float value)

References OptiRound< _impl, result_type >::roundScalar().

◆ normalizeAlpha()

template<class _impl >
static ALWAYS_INLINE void PixelWrapper< quint16, _impl >::normalizeAlpha ( float & alpha)
inlinestatic

Definition at line 588 of file KoStreamedMath.h.

589 {
590 const float uint16Rec1 = 1.0f / 65535.0f;
591 alpha *= uint16Rec1;
592 }

◆ read()

template<class _impl >
ALWAYS_INLINE void PixelWrapper< quint16, _impl >::read ( const void * src,
float_v & dst_c1,
float_v & dst_c2,
float_v & dst_c3,
float_v & dst_alpha )
inline

Definition at line 608 of file KoStreamedMath.h.

609 {
610 // struct PackedPixel {
611 // float rrgg;
612 // float bbaa;
613 // }
614#if XSIMD_VERSION_MAJOR < 10
615 uint_v pixelsC1C2;
616 uint_v pixelsC3Alpha;
617 KoRgbaInterleavers<16>::deinterleave(src, pixelsC1C2, pixelsC3Alpha);
618#else
619 const auto *srcPtr = static_cast<const typename uint_v::value_type *>(src);
620 const auto idx1 = xsimd::detail::make_sequence_as_batch<int_v>() * 2; // stride == 2
621 const auto idx2 = idx1 + 1; // offset 1 == 2nd members
622
623 const auto pixelsC1C2 = uint_v::gather(srcPtr, idx1);
624 const auto pixelsC3Alpha = uint_v::gather(srcPtr, idx2);
625#endif
626
627 dst_c1 = xsimd::to_float(xsimd::bitwise_cast_compat<int>(pixelsC1C2 & mask)); // r
628 dst_c2 = xsimd::to_float(xsimd::bitwise_cast_compat<int>((pixelsC1C2 >> 16) & mask)); // g
629 dst_c3 = xsimd::to_float(xsimd::bitwise_cast_compat<int>((pixelsC3Alpha & mask))); // b
630 dst_alpha = xsimd::to_float(xsimd::bitwise_cast_compat<int>((pixelsC3Alpha >> 16) & mask)); // a
631
632 dst_alpha *= uint16Rec1;
633 }
xsimd::batch< unsigned int, _impl > uint_v

◆ roundFloatToUint()

template<class _impl >
static ALWAYS_INLINE quint16 PixelWrapper< quint16, _impl >::roundFloatToUint ( float x)
inlinestatic

Definition at line 582 of file KoStreamedMath.h.

583 {
585 }

References OptiRound< _impl, result_type >::roundScalar().

◆ write()

template<class _impl >
ALWAYS_INLINE void PixelWrapper< quint16, _impl >::write ( void * dst,
const float_v & c1,
const float_v & c2,
const float_v & c3,
const float_v & a )
inline

Definition at line 635 of file KoStreamedMath.h.

636 {
637 const auto alpha = a * uint16Max;
638
639 const auto v1 = xsimd::bitwise_cast_compat<unsigned int>(xsimd::nearbyint_as_int(c1));
640 const auto v2 = xsimd::bitwise_cast_compat<unsigned int>(xsimd::nearbyint_as_int(c2));
641 const auto v3 = xsimd::bitwise_cast_compat<unsigned int>(xsimd::nearbyint_as_int(c3));
642 const auto v4 = xsimd::bitwise_cast_compat<unsigned int>(xsimd::nearbyint_as_int(alpha));
643
644 const auto c1c2 = ((v2 & mask) << 16) | (v1 & mask);
645 const auto c3ca = ((v4 & mask) << 16) | (v3 & mask);
646
647#if XSIMD_VERSION_MAJOR < 10
648 KoRgbaInterleavers<16>::interleave(dst, c1c2, c3ca);
649#else
650 auto dstPtr = reinterpret_cast<typename int_v::value_type *>(dst);
651
652 const auto idx1 = xsimd::detail::make_sequence_as_batch<int_v>() * 2;
653 const auto idx2 = idx1 + 1;
654
655 c1c2.scatter(dstPtr, idx1);
656 c3ca.scatter(dstPtr, idx2);
657#endif
658 }

Member Data Documentation

◆ mask

template<class _impl >
const uint_v PixelWrapper< quint16, _impl >::mask

Definition at line 672 of file KoStreamedMath.h.

◆ uint16Max

template<class _impl >
const float_v PixelWrapper< quint16, _impl >::uint16Max

Definition at line 673 of file KoStreamedMath.h.

◆ uint16Rec1

template<class _impl >
const float_v PixelWrapper< quint16, _impl >::uint16Rec1

Definition at line 674 of file KoStreamedMath.h.


The documentation for this struct was generated from the following file: