28 #ifndef YSL_INC_Service_YPixel_h_
29 #define YSL_INC_Service_YPixel_h_ 1
32 #include YFM_YSLib_Core_YGDIBase
63 template<
typename _tOut,
typename _tIn>
67 if(FetchAlpha(*src_iter))
68 *dst_iter = *src_iter;
71 template<
typename _tOut>
75 *dst_iter = *src_iter.
base().second & 0x80 ? FetchOpaque(*src_iter)
76 : FetchOpaque(PixelType());
91 template<
size_t _vDstAlphaBits,
size_t _vSrcAlphaBits>
102 template<
typename _tDstAlpha,
typename _tSrcAlpha>
104 _tSrcAlpha, _tDstAlpha>
108 "Non-normalizable destination alpha type found.");
110 "Non-normalizable source alpha type found.");
112 return sa + da * (1 - sa);
125 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
131 "Non-normalizable destination type found.");
133 "Non-normalizable source type found.");
135 "Non-normalizable source alpha type found.");
137 "Non-normalizable alpha type found.");
139 return a != 0 ? (s < d ? _tDst(d - sa * (d - s) / a)
140 : _tDst(sa * (s - d) / a + d)) : _tDst(0);
145 template<
size_t _vDstAlphaBits>
154 template<
typename _tDstAlpha,
typename _tSrcAlpha>
159 "Non-normalizable destination alpha type found.");
161 "Non-normalizable source alpha type found.");
173 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
179 "Non-normalizable destination type found.");
181 "Non-normalizable source type found.");
183 "Non-normalizable source alpha type found.");
185 "Non-normalizable alpha type found.");
187 return a != 0 ? (sa != 0 ? (s < d ? _tDst(d - (d - s) / a)
188 : _tDst((s - d) / a + d)) : d) : _tDst(0);
193 template<
size_t _vDstAlphaBits>
204 template<
typename _tDstAlpha>
209 "Non-normalizable destination alpha type found.");
213 template<
typename _tDstAlpha,
typename _tSrcAlpha>
218 "Non-normalizable source alpha type found.");
234 template<
typename _tSrc>
240 "Non-normalizable source type found.");
244 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
250 "Non-normalizable destination type found.");
252 "Non-normalizable source alpha type found.");
254 "Non-normalizable alpha type found.");
262 template<
size_t _vSrcAlphaBits>
271 template<
typename _tDstAlpha,
typename _tSrcAlpha>
276 "Non-normalizable destination alpha type found.");
278 "Non-normalizable source alpha type found.");
290 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
296 "Non-normalizable destination type found.");
298 "Non-normalizable source type found.");
300 "Non-normalizable source alpha type found.");
302 "Non-normalizable alpha type found.");
310 template<
size_t _vSrcAlphaBits>
333 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha>
338 "Non-normalizable destination type found.");
340 "Non-normalizable source type found.");
342 "Non-normalizable source alpha type found.");
344 return s < d ? _tDst(d - sa * (d - s)) : _tDst(sa * (s - d) + d);
346 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
352 "Non-normalizable alpha type found.");
375 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha>
380 "Non-normalizable destination type found.");
382 "Non-normalizable source type found.");
384 "Non-normalizable source alpha type found.");
386 return sa != 0 ? _tDst(s) : _tDst(d);
388 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
394 "Non-normalizable alpha type found.");
419 template<
typename _tDstAlpha,
typename _tSrcAlpha>
424 "Non-normalizable destination alpha type found.");
426 "Non-normalizable source alpha type found.");
440 template<
typename _tDst,
typename _tSrc,
typename _tSrcAlpha,
446 "Non-normalizable destination type found.");
448 "Non-normalizable source type found.");
450 "Non-normalizable source alpha type found.");
452 "Non-normalizable alpha type found.");
476 template<
size_t _vSrcAlphaBits,
typename _tDstInt,
typename _tSrcInt,
477 typename _tSrcAlphaInt>
481 using namespace ystdex;
483 "Invalid integer destination type found.");
485 "Invalid integer source type found.");
487 "Invalid integer source alpha type found.");
489 ::unsigned_least_type, _vSrcAlphaBits>;
502 template<
size_t _vDstAlphaBits,
size_t _vSrcAlphaBits,
typename _tDstInt,
503 typename _tSrcInt,
typename _tSrcAlphaInt,
typename _tAlphaInt>
507 using namespace ystdex;
509 "Invalid integer destination type found.");
511 "Invalid integer source type found.");
513 "Invalid integer source alpha type found.");
515 "Invalid integer result alpha type found.");
517 ::unsigned_least_type, _vDstAlphaBits>;
519 ::unsigned_least_type, _vSrcAlphaBits>;
547 template<
size_t _vAlphaBits>
551 static_assert(_vAlphaBits > 0 && _vAlphaBits < 16 - 5,
552 "Wrong number of alpha bits found.");
554 u32 dbr((d & 0x1F) | (d << 6 & 0x1F0000)), dg(d & 0x3E0);
556 yunseq(dbr += ((((s & 0x1F) | (s << 6 & 0x1F0000)) - dbr) * a)
557 >> _vAlphaBits, dg += (((s & 0x3E0) - dg) * a) >> _vAlphaBits);
558 return (dbr & 0x1F) | (dg & 0x3E0) | (dbr >> 6 & 0x7C00) | 1 << 15;
571 template<
size_t _vSrcAlphaBits,
typename _tPixel,
typename _tSrcAlphaInt>
573 Blend(
const _tPixel& d,
const _tPixel&
s, _tSrcAlphaInt sa)
575 static_assert(std::is_integral<_tSrcAlphaInt>::value,
576 "Invalid integer source alpha type found.");
578 return Color(BlendComponent<_vSrcAlphaBits>(d.GetR(), s.GetR(), sa),
579 BlendComponent<_vSrcAlphaBits>(d.GetG(), s.GetG(), sa),
BlendComponent<
580 _vSrcAlphaBits>(d.GetB(), s.GetB(), sa), (1 << _vSrcAlphaBits) - 1);
582 template<
size_t _vSrcAlphaBits,
typename _tSrcAlphaInt>
584 Blend(
const RGBA<5, 5, 5, 1>& d,
const RGBA<5, 5, 5, 1>&
s, _tSrcAlphaInt sa)
586 static_assert(std::is_integral<_tSrcAlphaInt>::value,
587 "Invalid integer source alpha type found.");
589 return BlendCore<_vSrcAlphaBits>(d,
s, sa);
600 template<
size_t _vDstAlphaBits,
size_t _vSrcAlphaBits,
typename _tPixel,
602 typename _tSrcAlphaInt,
typename _tAlphaInt>
604 Composite(
const _tPixel& d,
const _tPixel&
s, _tSrcAlphaInt sa, _tAlphaInt a)
606 static_assert(std::is_integral<_tSrcAlphaInt>::value,
607 "Invalid integer source alpha type found.");
608 static_assert(std::is_integral<_tAlphaInt>::value,
609 "Invalid integer result alpha type found.");
611 return Color(CompositeComponent<_vDstAlphaBits, _vSrcAlphaBits>(d.GetR(),
612 s.GetR(), sa, a), CompositeComponent<_vDstAlphaBits, _vSrcAlphaBits>(
614 _vSrcAlphaBits>(d.GetB(), s.GetB(), sa, a), a);
617 template<
size_t _vDstAlphaBits,
size_t _vSrcAlphaBits,
typename _tPixel,
622 return Composite<_vDstAlphaBits, _vSrcAlphaBits>(d,
s, s.GetA(), a);
625 template<
size_t _vDstAlphaBits,
size_t _vSrcAlphaBits,
typename _tPixel>
629 using namespace ystdex;
631 ::unsigned_least_type, _vDstAlphaBits>;
633 ::unsigned_least_type, _vSrcAlphaBits>;
636 _vDstAlphaBits, _vSrcAlphaBits>::CompositeAlphaOver(pixd(d.GetA(),
649 template<
typename _tOut>
654 decltype(*dst_iter)>, PixelType>::value,
"Wrong type found.");
658 *dst_iter = Blend<8>(*dst_iter, *src_iter, a);
660 template<
typename _tOut,
typename _tIn>
666 decltype(*dst_iter)>, PixelType>::value,
"Wrong type found.");
668 const AlphaType a(*src_iter.base().second);
670 *dst_iter = Blend<8>(*dst_iter, *src_iter, a);
673 template<
typename _tOut,
typename _tIn>
678 *dst_iter)>::Trait::ABitsN, 8>(*dst_iter, *src_iter);
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
void operator()(_tOut dst_iter, ystdex::pair_iterator< ystdex::pseudo_iterator< const PixelType >, _tIn > src_iter)
yconstfn _tDstInt BlendComponent(_tDstInt d, _tSrcInt s, _tSrcAlphaInt sa)
像素分量混合。
static yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha)
Alpha 组合 Alpha 分量。
typename remove_reference< _type >::type remove_reference_t
static yconstfn _tSrc CompositeComponentOver(_tDst, _tSrc s, _tSrcAlpha, _tAlpha)
typename conditional< _bCond, _type, _type2 >::type conditional_t
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
yconstfn _tPixel Blend(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
像素混合:使用指定的源 Alpha 。
static yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
void operator()(_tOut dst_iter, IteratorPair src_iter)
#define yunseq
无序列依赖表达式组求值。
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha)
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa)
Alpha 组合非 Alpha 分量。
static yconstfn _tSrcAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha)
#define yconstfn
指定编译时常量函数。
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa)
Alpha 组合非 Alpha 分量。
static yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
const pair_type & base() const
u16 BlendCore(u32 d, u32 s, u8 a)
AXYZ1555 格式 PixelType 的 Alpha 混合。
yconstfn _tDstInt CompositeComponent(_tDstInt d, _tSrcInt s, _tSrcAlphaInt sa, _tAlphaInt a)
像素分量组合。
void operator()(_tOut &dst_iter, _tIn &src_iter)
static yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
empty_base<> raw_tag
直接构造类型(直接构造重载用)。
void operator()(_tOut &dst_iter, IteratorPair &src_iter)
static yconstfn ystdex::conditional_t<(_vDstAlphaBits< _vSrcAlphaBits), _tSrcAlpha, _tDstAlpha > CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
static yconstfn _tSrc CompositeComponentOver(_tSrc s)
Alpha 组合非 Alpha 分量。
void operator()(_tOut dst_iter, _tIn src_iter)
static yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha)
yconstfn _tPixel Composite(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa, _tAlphaInt a)
像素组合:使用指定的源 Alpha 和结果 Alpha 。