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 565 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 568 of file KoStreamedMath.h.

◆ int_v

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

Definition at line 566 of file KoStreamedMath.h.

◆ uint_v

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

Definition at line 567 of file KoStreamedMath.h.

Constructor & Destructor Documentation

◆ PixelWrapper()

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

Definition at line 599 of file KoStreamedMath.h.

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

Member Function Documentation

◆ clearPixels()

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

Definition at line 659 of file KoStreamedMath.h.

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

◆ copyPixels()

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

Definition at line 665 of file KoStreamedMath.h.

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

◆ denormalizeAlpha()

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

Definition at line 593 of file KoStreamedMath.h.

594 {
595 const float uint16Max = 65535.0f;
596 alpha *= uint16Max;
597 }

◆ lerpMixedUintFloat()

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

Definition at line 574 of file KoStreamedMath.h.

575 {
576 return OptiRound<_impl, quint16>::roundScalar((float(b) - a) * alpha + float(a));
577 }
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 586 of file KoStreamedMath.h.

587 {
588 const float uint16Rec1 = 1.0f / 65535.0f;
589 alpha *= uint16Rec1;
590 }

◆ 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 606 of file KoStreamedMath.h.

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

581 {
583 }

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 633 of file KoStreamedMath.h.

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

Member Data Documentation

◆ mask

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

Definition at line 670 of file KoStreamedMath.h.

◆ uint16Max

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

Definition at line 671 of file KoStreamedMath.h.

◆ uint16Rec1

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

Definition at line 672 of file KoStreamedMath.h.


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