YSTest: YPixel.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YPixel.h
浏览该文件的文档.
1 /*
2 © 2010-2016, 2018 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YSL_INC_Service_YPixel_h_
29 #define YSL_INC_Service_YPixel_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YGDIBase // for Color;
33 #include <ystdex/rational.hpp>
34
35 namespace YSLib
36 {
37
38 namespace Drawing
39 {
40
52 template<class _tPixel>
53 using MaskTrait = typename _tPixel::traits_type;
54
55
56 template<class _tPixel, class _tMask>
57 using EnableForMask = ystdex::enable_when<std::is_same<ystdex::detected_or_t<
58 void, MaskTrait, _tPixel>, _tMask>::value>;
60
61
66 namespace Shaders
67 {
68
79 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits>
80 struct GPixelCompositor
81 {
90 template<typename _tDstAlpha, typename _tSrcAlpha>
91 YB_ATTR_nodiscard YB_STATELESS static yconstfn ystdex::conditional_t<
92 (_vDstAlphaBits < _vSrcAlphaBits), _tSrcAlpha, _tDstAlpha>
93 CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
94 {
95 static_assert(ystdex::is_normalizable<_tDstAlpha>(),
96 "Non-normalizable destination alpha type found.");
97 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
98 "Non-normalizable source alpha type found.");
99
100 return sa + da * (_tSrcAlpha(1) - sa);
101 }
102
113 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
114 typename _tAlpha>
115 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
116 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
117 {
118 static_assert(ystdex::is_normalizable<_tDst>(),
119 "Non-normalizable destination type found.");
120 static_assert(ystdex::is_normalizable<_tSrc>(),
121 "Non-normalizable source type found.");
122 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
123 "Non-normalizable source alpha type found.");
124 static_assert(ystdex::is_normalizable<_tAlpha>(),
125 "Non-normalizable alpha type found.");
126
127 return a != _tAlpha(0) ? (s < d ? _tDst(d - sa * (d - s) / a)
128 : _tDst(sa * (s - d) / a + d)) : _tDst(0);
129 }
130 };
131
133 template<size_t _vDstAlphaBits>
134 struct GPixelCompositor<_vDstAlphaBits, 1>
135 {
142 template<typename _tDstAlpha, typename _tSrcAlpha>
143 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDstAlpha
144 CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
145 {
146 static_assert(ystdex::is_normalizable<_tDstAlpha>(),
147 "Non-normalizable destination alpha type found.");
148 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
149 "Non-normalizable source alpha type found.");
150
151 return sa != 0 ? _tDstAlpha(1) : da;
152 }
153
161 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
162 typename _tAlpha>
163 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
164 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
165 {
166 static_assert(ystdex::is_normalizable<_tDst>(),
167 "Non-normalizable destination type found.");
168 static_assert(ystdex::is_normalizable<_tSrc>(),
169 "Non-normalizable source type found.");
170 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
171 "Non-normalizable source alpha type found.");
172 static_assert(ystdex::is_normalizable<_tAlpha>(),
173 "Non-normalizable alpha type found.");
174
175 return a != _tAlpha(0) ? (sa != _tSrcAlpha(0) ? (s < d
176 ? _tDst(d - (d - s) / a) : _tDst((s - d) / a + d)) : d) : _tDst(0);
177 }
178 };
179
181 template<size_t _vDstAlphaBits>
182 struct GPixelCompositor<_vDstAlphaBits, 0>
183 {
192 template<typename _tDstAlpha>
193 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDstAlpha
194 CompositeAlphaOver(_tDstAlpha)
195 {
196 static_assert(ystdex::is_normalizable<_tDstAlpha>(),
197 "Non-normalizable destination alpha type found.");
198
199 return _tDstAlpha(1);
200 }
201 template<typename _tDstAlpha, typename _tSrcAlpha>
202 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDstAlpha
203 CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha)
204 {
205 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
206 "Non-normalizable source alpha type found.");
207
208 return CompositeAlphaOver(da);
209 }
211
222 template<typename _tSrc>
224 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tSrc
225 CompositeComponentOver(_tSrc s)
226 {
227 static_assert(ystdex::is_normalizable<_tSrc>(),
228 "Non-normalizable source type found.");
229
230 return s;
231 }
232 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
233 typename _tAlpha>
234 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tSrc
235 CompositeComponentOver(_tDst, _tSrc s, _tSrcAlpha, _tAlpha)
236 {
237 static_assert(ystdex::is_normalizable<_tSrc>(),
238 "Non-normalizable destination type found.");
239 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
240 "Non-normalizable source alpha type found.");
241 static_assert(ystdex::is_normalizable<_tAlpha>(),
242 "Non-normalizable alpha type found.");
243
244 return CompositeComponentOver(s);
245 }
247 };
248
250 template<size_t _vSrcAlphaBits>
251 struct GPixelCompositor<1, _vSrcAlphaBits>
252 {
259 template<typename _tDstAlpha, typename _tSrcAlpha>
260 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tSrcAlpha
261 CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
262 {
263 static_assert(ystdex::is_normalizable<_tDstAlpha>(),
264 "Non-normalizable destination alpha type found.");
265 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
266 "Non-normalizable source alpha type found.");
267
268 return da != 0 ? _tSrcAlpha(1) : sa;
269 }
270
278 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
279 typename _tAlpha>
280 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
281 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
282 {
283 static_assert(ystdex::is_normalizable<_tDst>(),
284 "Non-normalizable destination type found.");
285 static_assert(ystdex::is_normalizable<_tSrc>(),
286 "Non-normalizable source type found.");
287 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
288 "Non-normalizable source alpha type found.");
289 static_assert(ystdex::is_normalizable<_tAlpha>(),
290 "Non-normalizable alpha type found.");
291
292 return a != _tAlpha(0) ? GPixelCompositor<0, _vSrcAlphaBits>
293 ::CompositeComponentOver(d, s, sa) : _tDst(0);
294 }
295 };
296
298 template<size_t _vSrcAlphaBits>
299 struct GPixelCompositor<0, _vSrcAlphaBits> : private GPixelCompositor<2, 0>
300 {
309 using GPixelCompositor<2, 0>::CompositeAlphaOver;
310
320 template<typename _tDst, typename _tSrc, typename _tSrcAlpha>
321 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
322 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa)
323 {
324 static_assert(ystdex::is_normalizable<_tDst>(),
325 "Non-normalizable destination type found.");
326 static_assert(ystdex::is_normalizable<_tSrc>(),
327 "Non-normalizable source type found.");
328 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
329 "Non-normalizable source alpha type found.");
330
331 return s < d ? _tDst(d - sa * (d - s)) : _tDst(sa * (s - d) + d);
332 }
333 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
334 typename _tAlpha>
335 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
336 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha)
337 {
338 static_assert(ystdex::is_normalizable<_tAlpha>(),
339 "Non-normalizable alpha type found.");
340
341 return CompositeComponentOver(d, s, sa);
342 }
344 };
345
347 template<>
348 struct GPixelCompositor<0, 1> : private GPixelCompositor<2, 0>
349 {
350 using GPixelCompositor<2, 0>::CompositeAlphaOver;
351
362 template<typename _tDst, typename _tSrc, typename _tSrcAlpha>
363 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
364 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa)
365 {
366 static_assert(ystdex::is_normalizable<_tDst>(),
367 "Non-normalizable destination type found.");
368 static_assert(ystdex::is_normalizable<_tSrc>(),
369 "Non-normalizable source type found.");
370 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
371 "Non-normalizable source alpha type found.");
372
373 return sa != 0 ? _tDst(s) : _tDst(d);
374 }
375 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
376 typename _tAlpha>
377 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
378 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha)
379 {
380 static_assert(ystdex::is_normalizable<_tAlpha>(),
381 "Non-normalizable alpha type found.");
382
383 return CompositeComponentOver(d, s, sa);
384 }
386 };
387
392 template<>
393 struct GPixelCompositor<1, 0> : public GPixelCompositor<2, 0>
394 {};
395
397 template<>
398 struct GPixelCompositor<1, 1>
399 {
406 template<typename _tDstAlpha, typename _tSrcAlpha>
407 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDstAlpha
408 CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
409 {
410 static_assert(ystdex::is_normalizable<_tDstAlpha>(),
411 "Non-normalizable destination alpha type found.");
412 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
413 "Non-normalizable source alpha type found.");
414
415 return sa != 0 || da != 0 ? _tDstAlpha(1) : _tDstAlpha(0);
416 }
417
426 template<typename _tDst, typename _tSrc, typename _tSrcAlpha,
427 typename _tAlpha>
428 YB_ATTR_nodiscard YB_STATELESS static yconstfn _tDst
429 CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
430 {
431 static_assert(ystdex::is_normalizable<_tDst>(),
432 "Non-normalizable destination type found.");
433 static_assert(ystdex::is_normalizable<_tSrc>(),
434 "Non-normalizable source type found.");
435 static_assert(ystdex::is_normalizable<_tSrcAlpha>(),
436 "Non-normalizable source alpha type found.");
437 static_assert(ystdex::is_normalizable<_tAlpha>(),
438 "Non-normalizable alpha type found.");
439
440 return a != _tAlpha(0) ? GPixelCompositor<0, 1>
441 ::CompositeComponentOver(d, s, sa) : _tDst(0);
442 }
443 };
444
446 template<>
447 struct GPixelCompositor<0, 0> : private GPixelCompositor<2, 0>
448 {
449 using GPixelCompositor<2, 0>::CompositeAlphaOver;
450
451 using GPixelCompositor<2, 0>::CompositeComponentOver;
452 };
454
455
462 template<size_t _vSrcAlphaBits, typename _tDstInt, typename _tSrcInt,
463 typename _tSrcAlphaInt>
464 YB_ATTR_nodiscard YB_STATELESS yconstfn _tDstInt
465 BlendComponent(_tDstInt d, _tSrcInt s, _tSrcAlphaInt sa)
466 {
467 using namespace ystdex;
468 static_assert(integer_width<_tDstInt>::value == _vSrcAlphaBits,
469 "Invalid integer destination type found.");
470 static_assert(integer_width<_tSrcInt>::value == _vSrcAlphaBits,
471 "Invalid integer source type found.");
472 static_assert(integer_width<_tSrcAlphaInt>::value == _vSrcAlphaBits,
473 "Invalid integer source alpha type found.");
474 using pix = make_fixed_t<_vSrcAlphaBits>;
475
476 // TODO: Handle truncation properly.
477 return _tDstInt(
478 GPixelCompositor<1, _vSrcAlphaBits>::CompositeComponentOver(pix(d,
479 raw_tag()), pix(s, raw_tag()), pix(sa, raw_tag()), pix(1)).get());
480 }
481
488 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits, typename _tDstInt,
489 typename _tSrcInt, typename _tSrcAlphaInt, typename _tAlphaInt>
490 YB_ATTR_nodiscard YB_STATELESS yconstfn _tDstInt
491 CompositeComponent(_tDstInt d, _tSrcInt s, _tSrcAlphaInt sa, _tAlphaInt a)
492 {
493 using namespace ystdex;
494 static_assert(integer_width<_tDstInt>::value == _vSrcAlphaBits,
495 "Invalid integer destination type found.");
496 static_assert(integer_width<_tSrcInt>::value == _vSrcAlphaBits,
497 "Invalid integer source type found.");
498 static_assert(integer_width<_tSrcAlphaInt>::value == _vSrcAlphaBits,
499 "Invalid integer source alpha type found.");
500 static_assert(integer_width<_tAlphaInt>::value > _vDstAlphaBits,
501 "Invalid integer result alpha type found.");
502 using pixd = make_fixed_t<_vDstAlphaBits>;
503 using pix = make_fixed_t<_vSrcAlphaBits>;
504
505 // TODO: Handle truncation properly.
506 return _tDstInt(GPixelCompositor<_vDstAlphaBits, _vSrcAlphaBits>
507 ::CompositeComponentOver(pix(d, raw_tag()), pix(s, raw_tag()),
508 pix(sa, raw_tag()), pixd(a, raw_tag())).get());
509 }
510
511
532 template<size_t _vAlphaBits>
533 YB_ATTR_nodiscard YB_STATELESS std::uint16_t
534 BlendCore(std::uint32_t d, std::uint32_t s, std::uint8_t a)
535 {
536 static_assert(_vAlphaBits > 0 && _vAlphaBits < 16 - 5,
537 "Wrong number of alpha bits found.");
538 std::uint32_t dbr((d & 0x1F) | (d << 6 & 0x1F0000)), dg(d & 0x3E0);
539
540 yunseq(dbr += ((((s & 0x1F) | (s << 6 & 0x1F0000)) - dbr) * a)
541 >> _vAlphaBits, dg += (((s & 0x3E0) - dg) * a) >> _vAlphaBits);
542 return (dbr & 0x1F) | (dg & 0x3E0) | (dbr >> 6 & 0x7C00);
543 }
544
545
557 #if YB_IMPL_GNUCPP
558 template<typename _tPixel, typename = void>
559 struct GBlender : GBlender<_tPixel, _t<std::is_same<
560 ystdex::detected_or_t<void, MaskTrait, _tPixel>, XYZATraits<5, 5, 5, 1>>>>
561 {};
562 #else
563 template<typename _tPixel, typename = void>
564 struct GBlender : GBlender<_tPixel, ystdex::when<true>>
565 {};
566 #endif
567
568 #if YB_IMPL_GNUCPP
569 template<typename _tPixel>
570 struct GBlender<_tPixel, ystdex::false_>
571 #else
572 template<typename _tPixel, bool _bCond>
573 struct GBlender<_tPixel, ystdex::when<_bCond>>
574 #endif
575 {
581 template<size_t _vSrcAlphaBits, typename _tSrcAlphaInt>
582 YB_ATTR_nodiscard YB_PURE static yconstfn _tPixel
583 Blend(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa)
584 {
585 static_assert(std::is_integral<_tSrcAlphaInt>(),
586 "Invalid integer source alpha type found.");
587
588 // TODO: Use pixel instead of %Color to avoid truncation.
589 return Color(BlendComponent<_vSrcAlphaBits>(d.GetR(), s.GetR(), sa),
590 BlendComponent<_vSrcAlphaBits>(d.GetG(), s.GetG(), sa),
591 BlendComponent<_vSrcAlphaBits>(d.GetB(), s.GetB(), sa),
592 AlphaType((1 << _vSrcAlphaBits) - 1));
593 }
594
595 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits,
596 typename _tSrcAlphaInt>
597 YB_ATTR_nodiscard YB_PURE static yconstfn _tPixel
598 BlendAlpha(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa)
599 {
600 static_assert(std::is_integral<_tSrcAlphaInt>(),
601 "Invalid integer source alpha type found.");
602 using namespace ystdex;
603 using pixd = make_fixed_t<_vDstAlphaBits>;
604 using pix = make_fixed_t<_vSrcAlphaBits>;
605
606 // TODO: Use pixel instead of %Color to avoid truncation.
607 return Color(BlendComponent<_vSrcAlphaBits>(d.GetR(), s.GetR(), sa),
608 BlendComponent<_vSrcAlphaBits>(d.GetG(), s.GetG(), sa),
609 BlendComponent<_vSrcAlphaBits>(d.GetB(), s.GetB(), sa),
610 AlphaType(GPixelCompositor<_vDstAlphaBits, _vSrcAlphaBits>
611 ::CompositeAlphaOver(pixd(d.GetA(), raw_tag()),
612 pix(sa, raw_tag())).get()));
613 }
615
620 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits,
621 typename _tSrcAlphaInt, typename _tAlphaInt>
622 YB_ATTR_nodiscard YB_PURE static yconstfn _tPixel
623 Composite(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa,
624 _tAlphaInt a)
625 {
626 static_assert(std::is_integral<_tSrcAlphaInt>(),
627 "Invalid integer source alpha type found.");
628 static_assert(std::is_integral<_tAlphaInt>(),
629 "Invalid integer result alpha type found.");
630
631 // TODO: Use pixel instead of %Color to avoid truncation.
632 return Color(CompositeComponent<_vDstAlphaBits, _vSrcAlphaBits>(
633 d.GetR(), s.GetR(), sa, a), CompositeComponent<_vDstAlphaBits,
634 _vSrcAlphaBits>(d.GetG(), s.GetG(), sa, a), CompositeComponent<
635 _vDstAlphaBits, _vSrcAlphaBits>(d.GetB(), s.GetB(), sa, a),
636 AlphaType(a));
637 }
638 };
639
644 #if YB_IMPL_GNUCPP
645 template<typename _tPixel>
646 struct GBlender<_tPixel, ystdex::true_>
647 #else
648 template<typename _tPixel>
649 struct GBlender<_tPixel, EnableForMask<_tPixel, XYZATraits<5, 5, 5, 1>>>
650 #endif
651 {
652 template<size_t _vSrcAlphaBits, typename _tSrcAlphaInt>
653 YB_ATTR_nodiscard YB_PURE static yconstfn _tPixel
654 Blend(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa)
655 {
656 static_assert(std::is_integral<_tSrcAlphaInt>(),
657 "Invalid integer source alpha type found.");
658
659 return BlendCore<_vSrcAlphaBits>(d, s, sa) | 1 << 15;
660 }
661
662 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits,
663 typename _tSrcAlphaInt>
664 YB_ATTR_nodiscard YB_PURE static yconstfn _tPixel
665 BlendAlpha(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa)
666 {
667 static_assert(std::is_integral<_tSrcAlphaInt>(),
668 "Invalid integer source alpha type found.");
669 using namespace ystdex;
670 using pixd = make_fixed_t<_vDstAlphaBits>;
671 using pix = make_fixed_t<_vSrcAlphaBits>;
672
673 return BlendCore<_vSrcAlphaBits>(d, s, sa) | (GPixelCompositor<
674 _vDstAlphaBits, _vSrcAlphaBits>::CompositeAlphaOver(pixd(d.GetA(),
675 raw_tag()), pix(sa, raw_tag())).get() != 0 ? 1 << 15 : 0);
676 }
677
678 template<size_t, size_t _vSrcAlphaBits, typename _tSrcAlphaInt,
679 typename _tAlphaInt>
680 YB_ATTR_nodiscard YB_PURE static yconstfn _tPixel
681 Composite(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa,
682 _tAlphaInt a)
683 {
684 static_assert(std::is_integral<_tSrcAlphaInt>(),
685 "Invalid integer source alpha type found.");
686 static_assert(std::is_integral<_tAlphaInt>(),
687 "Invalid integer alpha type found.");
688
689 return BlendCore<_vSrcAlphaBits>(d, s, sa) | ((a != 0) ? 1 << 15 : 0);
690 }
691 };
692
693
699 template<size_t _vSrcAlphaBits, typename _tPixel, typename _tSrcAlphaInt>
700 YB_ATTR_nodiscard YB_PURE yconstfn _tPixel
701 Blend(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa)
702 {
703 return GBlender<_tPixel>::template Blend<_vSrcAlphaBits>(d, s, sa);
704 }
705
706
708
709
715 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits, typename _tPixel,
716 typename _tSrcAlphaInt>
717 YB_ATTR_nodiscard YB_PURE yconstfn _tPixel
718 BlendAlpha(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa)
719 {
720 return GBlender<_tPixel>::template BlendAlpha<_vDstAlphaBits,
721 _vSrcAlphaBits>(d, s, sa);
722 }
723
724
726
727 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits, typename _tPixel,
729 typename _tSrcAlphaInt, typename _tAlphaInt>
730 YB_ATTR_nodiscard YB_PURE yconstfn _tPixel
731 Composite(const _tPixel& d, const _tPixel& s, _tSrcAlphaInt sa, _tAlphaInt a)
732 {
733 return GBlender<_tPixel>::template Composite<_vDstAlphaBits,
734 _vSrcAlphaBits>(d, s, sa, a);
735 }
737
738 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits, typename _tPixel,
740 typename _tAlphaInt>
741 YB_ATTR_nodiscard YB_PURE yconstfn _tPixel
742 Composite(const _tPixel& d, const _tPixel& s, _tAlphaInt a)
743 {
744 return Composite<_vDstAlphaBits, _vSrcAlphaBits>(d, s, s.GetA(), a);
745 }
747 template<size_t _vDstAlphaBits, size_t _vSrcAlphaBits, typename _tPixel>
748 YB_ATTR_nodiscard YB_PURE yconstfn _tPixel
749 Composite(const _tPixel& d, const _tPixel& s)
750 {
751 using namespace ystdex;
752 using pixd = make_fixed_t<_vDstAlphaBits>;
753 using pix = make_fixed_t<_vSrcAlphaBits>;
754
755 return Composite<_vDstAlphaBits, _vSrcAlphaBits>(d, s, GPixelCompositor<
756 _vDstAlphaBits, _vSrcAlphaBits>::CompositeAlphaOver(pixd(d.GetA(),
757 raw_tag()), pix(s.GetA(), raw_tag())).get());
758 }
760
761
762
763
764 } // namespace Shaders;
765
766 } // namespace Drawing;
767
768 } // namespace YSLib;
769
770 #endif
771
YSLib::Drawing::Shaders::GPixelCompositor< 0, _vSrcAlphaBits >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha)
Definition: YPixel.h:336
rational.hpp
有理数运算。
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:128
ystdex::cpp2014::conditional_t
typename conditional< _bCond, _type, _type2 >::type conditional_t
Definition: meta.hpp:202
YSLib::Drawing::Shaders::BlendComponent
YB_ATTR_nodiscard YB_STATELESS yconstfn _tDstInt BlendComponent(_tDstInt d, _tSrcInt s, _tSrcAlphaInt sa)
像素分量混合。
Definition: YPixel.h:465
YSLib::Drawing::Shaders::GPixelCompositor< 1, _vSrcAlphaBits >::CompositeAlphaOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tSrcAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
Definition: YPixel.h:261
YSLib::Drawing::Shaders::GPixelCompositor< _vDstAlphaBits, 0 >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tSrc CompositeComponentOver(_tSrc s)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:225
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
ystdex::detected_or_t
_t< detected_or< _tDefault, _gOp, _tParams... > > detected_or_t
Definition: meta.hpp:407
YSLib::Drawing::Shaders::GBlender
分发像素混合操作。
Definition: YPixel.h:565
YSLib::Drawing::Shaders::GBlender< _tPixel, ystdex::when< _bCond > >::Composite
YB_ATTR_nodiscard static YB_PURE yconstfn _tPixel Composite(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa, _tAlphaInt a)
Definition: YPixel.h:623
YSLib::Drawing::Shaders::GPixelCompositor< 0, 1 >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha)
Definition: YPixel.h:378
YSLib::Drawing::Shaders::GBlender< _tPixel, ystdex::when< _bCond > >::BlendAlpha
YB_ATTR_nodiscard static YB_PURE yconstfn _tPixel BlendAlpha(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
Definition: YPixel.h:598
YSLib::Drawing::Shaders::Blend
YB_ATTR_nodiscard YB_PURE yconstfn _tPixel Blend(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
像素混合：使用指定的源 Alpha 。
Definition: YPixel.h:701
YSLib::Drawing::Shaders::GBlender< _tPixel, EnableForMask< _tPixel, XYZATraits< 5, 5, 5, 1 > > >::Composite
YB_ATTR_nodiscard static YB_PURE yconstfn _tPixel Composite(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa, _tAlphaInt a)
Definition: YPixel.h:681
YSLib::Drawing::Shaders::BlendAlpha
YB_ATTR_nodiscard YB_PURE yconstfn _tPixel BlendAlpha(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
Alpha 像素混合：使用指定的源 Alpha 同时组合透明背景 Alpha 。
Definition: YPixel.h:718
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:142
YSLib::Drawing::Shaders::BlendCore
YB_ATTR_nodiscard YB_STATELESS std::uint16_t BlendCore(std::uint32_t d, std::uint32_t s, std::uint8_t a)
AXYZ1555 格式 Pixel 的 Alpha 混合。
Definition: YPixel.h:534
YSLib::Drawing::Shaders::GPixelCompositor::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:116
YSLib::Drawing::Shaders::GPixelCompositor< 1, 1 >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:429
YSLib::Drawing::Shaders::GPixelCompositor< 0, _vSrcAlphaBits >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:322
ystdex::integer_width
取指定整数类型的位宽度。
Definition: cstdint.hpp:104
YSLib::Drawing::Shaders::CompositeComponent
YB_ATTR_nodiscard YB_STATELESS yconstfn _tDstInt CompositeComponent(_tDstInt d, _tSrcInt s, _tSrcAlphaInt sa, _tAlphaInt a)
像素分量组合。
Definition: YPixel.h:491
YSLib::Drawing::Shaders::GPixelCompositor< _vDstAlphaBits, 1 >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:164
YSLib::Drawing::EnableForMask
ystdex::enable_when< std::is_same< ystdex::detected_or_t< void, MaskTrait, _tPixel >, _tMask >::value > EnableForMask
Definition: YPixel.h:58
YSLib::Drawing::get
YB_ATTR_nodiscard YB_PURE yconstfn _type & get(GBinaryGroup< _type > &val)
取分量。
Definition: YGDIBase.h:484
YSLib::Drawing::Shaders::GPixelCompositor< _vDstAlphaBits, 1 >::CompositeAlphaOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
Definition: YPixel.h:144
YSLib::Drawing::Shaders::GPixelCompositor< _vDstAlphaBits, 0 >::CompositeAlphaOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha)
Alpha 组合 Alpha 分量。
Definition: YPixel.h:194
ystdex::fixed_point
通用定点数。
Definition: rational.hpp:164
YSLib::Drawing::Shaders::GPixelCompositor< 1, _vSrcAlphaBits >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa, _tAlpha a)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:281
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
ystdex::enable_when
enable_if_t< _bCond, when< true > > enable_when
类似 enable_if_t 的元函数，但具有较低匹配优先级，避免偏特化歧义。
Definition: meta.hpp:322
YSLib::Drawing::Shaders::GPixelCompositor< _vDstAlphaBits, 0 >::CompositeAlphaOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha)
Definition: YPixel.h:203
ystdex::raw_tag
直接构造类型（直接构造重载用）。
Definition: ydef.h:1432
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
YSLib::Drawing::Shaders::GBlender< _tPixel, EnableForMask< _tPixel, XYZATraits< 5, 5, 5, 1 > > >::Blend
YB_ATTR_nodiscard static YB_PURE yconstfn _tPixel Blend(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
Definition: YPixel.h:654
YSLib::Drawing::AlphaType
octet AlphaType
Alpha 分量类型。
Definition: YGDIBase.h:49
YSLib::Drawing::Shaders::GPixelCompositor
像素组合器。
Definition: YPixel.h:81
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
YModules.h
YSLib 用户界面模块配置文件。
YSLib::Drawing::Shaders::GPixelCompositor< 1, 1 >::CompositeAlphaOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDstAlpha CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
Definition: YPixel.h:408
YSLib::Drawing::Shaders::GBlender< _tPixel, EnableForMask< _tPixel, XYZATraits< 5, 5, 5, 1 > > >::BlendAlpha
YB_ATTR_nodiscard static YB_PURE yconstfn _tPixel BlendAlpha(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
Definition: YPixel.h:665
YSLib::Drawing::Shaders::GBlender< _tPixel, ystdex::when< _bCond > >::Blend
YB_ATTR_nodiscard static YB_PURE yconstfn _tPixel Blend(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa)
Definition: YPixel.h:583
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::Drawing::Shaders::GPixelCompositor< 0, 1 >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tDst CompositeComponentOver(_tDst d, _tSrc s, _tSrcAlpha sa)
Alpha 组合非 Alpha 分量。
Definition: YPixel.h:364
YSLib::size_t
YF_API const char size_t
Definition: YException.h:149
ystdex::false_
bool_< false > false_
Definition: integral_constant.hpp:110
YSLib::Drawing::MaskTrait
typename _tPixel::traits_type MaskTrait
Definition: YPixel.h:53
YSLib::Drawing::Shaders::GPixelCompositor::CompositeAlphaOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn ystdex::conditional_t<(_vDstAlphaBits< _vSrcAlphaBits), _tSrcAlpha, _tDstAlpha > CompositeAlphaOver(_tDstAlpha da, _tSrcAlpha sa)
Alpha 组合 Alpha 分量。
Definition: YPixel.h:93
YSLib::Drawing::Shaders::Composite
YB_ATTR_nodiscard YB_PURE yconstfn _tPixel Composite(const _tPixel &d, const _tPixel &s, _tSrcAlphaInt sa, _tAlphaInt a)
像素组合：使用指定的源 Alpha 和结果 Alpha 。
Definition: YPixel.h:731
YSLib::Drawing::Shaders::GPixelCompositor< _vDstAlphaBits, 0 >::CompositeComponentOver
YB_ATTR_nodiscard static YB_STATELESS yconstfn _tSrc CompositeComponentOver(_tDst, _tSrc s, _tSrcAlpha, _tAlpha)
Definition: YPixel.h:235
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::is_normalizable
判断类型是否可满足正规化要求：在 0 和 1 之间存在值进行表示。
Definition: rational.hpp:129
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168