YSTest: YBlit.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YBlit.h
浏览该文件的文档.
1 /*
2 © 2009-2016, 2019-2020 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_YBlit_h_
29 #define YSL_INC_Service_YBlit_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YGraphics
33 #include YFM_YSLib_Core_YCoreUtilities
34 #include <ystdex/iterator.hpp> // for mandated header;
35 #include <ystdex/rational.hpp>
36
37 namespace YSLib
38 {
39
40 namespace Drawing
41 {
42
47 struct VerticalLineTransfomer
48 {
56 template<typename _tOut, typename _tIn>
57 void
58 operator()(_tOut dst_iter, size_t n, SDst dw, _tIn src_iter) const
59 {
60 using ystdex::is_undereferenceable;
61
62 YAssert(n == 0 || !is_undereferenceable(dst_iter),
63 "Invalid iterator found.");
64 while(n-- != 0)
65 {
66 *dst_iter = *src_iter;
67 yunseq(++src_iter, dst_iter += dw);
68 }
69 }
70 };
71
72
82 YF_API bool
83 BlitBounds(const Point&, const Point&, const Size&, const Size&, const Size&,
84 SDst&, SDst&, SDst&, SDst&);
85
86
91 template<bool _bDec>
92 YB_ATTR_nodiscard YB_STATELESS yconstfn size_t
93 BlitScaleComponent(SPos d, SPos s, SDst delta) ynothrow
94 {
95 return size_t(ystdex::max<SPos>(0, s < 0 ? d - s : d))
96 + size_t(_bDec ? delta - 1 : 0);
97 }
98
99
120 template<bool _bDec, typename _tScalar, typename _tDiff, typename _tOut,
121 typename _tIn, typename _fBlitLoop>
122 void
123 BlitScan(_fBlitLoop loop, _tOut dst, _tIn src, _tScalar d_width,
124 _tScalar s_width, _tDiff delta_x, _tDiff delta_y)
125 {
126 loop(dst, src, delta_x, delta_y, _tDiff(_bDec ? -1 : 1) * _tDiff(d_width)
127 - delta_x, _tDiff(s_width) - delta_x);
128 }
129
130
165 template<bool _bSwapLR, bool _bSwapUD, typename _tOut, typename _tIn,
166 typename _fBlitLoop>
167 void
168 Blit(_fBlitLoop loop, _tOut dst, _tIn src, const Size& ds, const Size& ss,
169 const Point& dp, const Point& sp, const Size& sc)
170 {
171 SDst min_x, min_y, delta_x, delta_y;
172
173 // XXX: Conversion to 'difference_type' might be implementation-defined.
174 if(BlitBounds(dp, sp, ds, ss, sc, min_x, min_y, delta_x, delta_y))
175 BlitScan<_bSwapLR != _bSwapUD>(loop, dst + typename
176 std::iterator_traits<_tOut>::difference_type(BlitScaleComponent<
177 _bSwapUD>(dp.Y, sp.Y, delta_y) * ds.Width + BlitScaleComponent<
178 _bSwapLR>(dp.X, sp.X, delta_x)), src + typename
179 std::iterator_traits<_tIn>::difference_type((_bSwapUD ? ss.Height
180 - delta_y - min_y : min_y) * ss.Width + (_bSwapLR ? ss.Width
181 - delta_x - min_x : min_x)), ds.Width, ss.Width, delta_x, delta_y);
182 }
183
184
191 template<bool _bDec>
192 struct BlitScannerLoop
193 {
195 template<typename _tOut, typename _tIn, typename _fBlitScanner>
196 void
197 operator()(_fBlitScanner scanner, _tOut dst_iter, _tIn src_iter,
198 SDst delta_x, SDst delta_y, SPos dst_inc, SPos src_inc) const
199 {
200 while(delta_y-- > 0)
201 {
202 scanner(dst_iter, src_iter, delta_x);
203 // NOTE: See $2015-02 @ %Documentation::Workflow.
204 if(YB_LIKELY(delta_y != 0))
205 yunseq(src_iter += src_inc,
206 ystdex::delta_assign<_bDec>(dst_iter, dst_inc));
207 }
208 }
209 };
210
211
233 template<bool _bSwapLR, bool _bSwapUD, typename _tOut, typename _tIn,
234 typename _fBlitScanner>
235 inline void
236 BlitLines(_fBlitScanner scanner, _tOut dst, _tIn src, const Size& ds,
237 const Size& ss, const Point& dp, const Point& sp, const Size& sc)
238 {
239 using namespace std::placeholders;
240
241 Blit<_bSwapLR, _bSwapUD, _tOut, _tIn>(std::bind(BlitScannerLoop<!_bSwapLR>(
242 ), scanner, _1, _2, _3, _4, _5, _6), dst, src, ds, ss, dp, sp, sc);
243 }
244
245
253 template<bool _bDec>
254 struct BlitLineLoop
255 {
256 template<typename _tOut, typename _tIn, typename _fPixelShader>
257 void
258 operator()(_fPixelShader shader, _tOut& dst_iter, _tIn& src_iter,
259 SDst delta_x)
260 {
261 for(SDst x(0); x < delta_x; ++x)
262 {
263 shader(dst_iter, src_iter);
264 ++src_iter;
265 ystdex::xcrease<_bDec>(dst_iter);
266 }
267 }
268 };
269
270
293 template<bool _bSwapLR, bool _bSwapUD, typename _tOut, typename _tIn,
294 typename _fPixelShader>
295 inline void
296 BlitPixels(_fPixelShader shader, _tOut dst, _tIn src, const Size& ds,
297 const Size& ss, const Point& dp, const Point& sp, const Size& sc)
298 {
299 BlitLines<_bSwapLR, _bSwapUD, _tOut, _tIn>(
300 [shader](_tOut& dst_iter, _tIn& src_iter, SDst delta_x){
301 BlitLineLoop<!_bSwapLR>()(shader, dst_iter, src_iter, delta_x);
302 }, dst, src, ds, ss, dp, sp, sc);
303 }
304
305
321
323
324
333 template<typename _func, typename _tOut, typename _tIn>
334 inline void
335 BlitRect(_func f, _tOut dst, _tIn src, const Size& ds, const Size& ss,
336 const Point& dp, const Point& sp, const Size& sc)
337 {
338 f(dst, src, ds, ss, dp, sp, sc);
339 }
340 template<typename _func, typename _tOut, typename _tIn>
341 inline void
342 BlitRect(_func f, _tOut dst, _tIn src, const Size& ds, const Point& sp,
343 const Size& sc)
344 {
345 Drawing::BlitRect(f, dst, src, ds, ds, sp, sp, sc);
346 }
348 template<typename _func, typename _tOut, typename _tIn>
350 inline void
351 BlitRect(_func f, _tOut dst, _tIn src, const Size& ds, const Rect& r)
352 {
353 Drawing::BlitRect(f, dst, src, ds, r.GetPoint(), r.GetSize());
354 }
356
364 template<typename _func, typename _tOut, typename _tIn>
365 inline void
366 BlitRect(_func f, _tOut dst, _tIn src, SDst dw, SDst dh, SPos x, SPos y, SDst w,
367 SDst h)
368 {
369 Drawing::BlitRect(f, dst, src, {dw, dh}, {x, y}, {w, h});
370 }
372
373
380 template<typename _tOut, typename _tIn, typename _fBlitScanner,
382 typename... _tParams>
383 inline void
384 BlitRectLines(_fBlitScanner scanner, _tOut dst, _tIn src, _tParams&&... args)
385 {
386 using namespace std::placeholders;
387
388 BlitRect(std::bind(Drawing::BlitLines<false, false, _tOut, _tIn,
389 _fBlitScanner>, scanner, _1, _2, _3, _4, _5, _6, _7), dst, src,
390 yforward(args)...);
391 }
392
394 template<typename _tOut, typename _tIn, typename _fPixelShader,
395 typename... _tParams>
396 inline void
397 BlitRectPixels(_fPixelShader shader, _tOut dst, _tIn src, _tParams&&... args)
398 {
399 using namespace std::placeholders;
400
401 BlitRect(std::bind(Drawing::BlitPixels<false, false, _tOut, _tIn,
402 _fPixelShader>, shader, _1, _2, _3, _4, _5, _6, _7), dst, src,
403 yforward(args)...);
404 }
406
407
408
418 template<typename _func>
419 inline void
420 DispatchTranspose(ystdex::false_, _func updater, const ConstGraphics& src)
421 {
422 updater(src.GetBufferPtr(), src.GetSize(), Point());
423 }
424 template<typename _func>
425 inline void
426 DispatchTranspose(ystdex::true_, _func updater, const ConstGraphics& src)
427 {
428 updater(ystdex::make_transposed(src.GetBufferPtr(), src.GetWidth(),
429 src.GetHeight(), 0U), Transpose(src.GetSize()),
430 RotateCenter(src.GetSize()));
431 }
433
434
442 template<bool _bDec>
443 struct CopyLine
444 {
452 template<typename _tOut, typename _tIn>
454 void
455 operator()(_tOut& dst_iter, _tIn& src_iter, SDst delta_x) const
456 {
457 using ystdex::is_undereferenceable;
458
459 YAssert(delta_x == 0 || !is_undereferenceable(dst_iter),
460 "Invalid output iterator found."),
461 YAssert(delta_x == 0 || !is_undereferenceable(src_iter),
462 "Invalid input iterator found.");
463 std::copy_n(src_iter, delta_x, dst_iter);
464 // NOTE: Possible undefined behavior. See $2015-02
465 // @ %Documentation::Workflow.
466 yunseq(src_iter += delta_x, dst_iter += delta_x);
467 }
469 template<typename _tOut, typename _tPixel>
470 void
471 operator()(_tOut& dst_iter, ystdex::pseudo_iterator<_tPixel> src_iter,
472 SDst delta_x) const
473 {
474 using ystdex::is_undereferenceable;
475
476 YAssert(delta_x == 0 || !is_undereferenceable(dst_iter),
477 "Invalid output iterator found."),
478 std::fill_n(dst_iter, delta_x, Deref(src_iter));
479 // NOTE: Possible undefined behavior. See $2015-02
480 // @ %Documentation::Workflow.
481 dst_iter += delta_x;
482 }
484 };
485
486 template<>
487 struct CopyLine<false>
488 {
493 template<typename _tOut, typename _tIn>
494 void
495 operator()(_tOut& dst_iter, _tIn& src_iter, SDst delta_x) const
496 {
497 while(delta_x-- > 0)
498 *dst_iter-- = *src_iter++;
499 }
500 };
502
503
515 template<typename _tOut>
516 inline _tOut
517 ClearPixels(_tOut dst, size_t n) ynothrowv
518 {
519 ClearSequence(dst, n);
520 return dst;
521 }
522
524 template<typename _tPixel, typename _tOut>
525 inline void
526 FillPixels(_tOut dst_iter, size_t n, _tPixel c)
527 {
528 CopyLine<true>()(dst_iter, ystdex::pseudo_iterator<_tPixel>(c), SDst(n));
529 }
530
535 template<typename _tPixel, typename _tOut>
536 inline void
537 FillVerticalLine(_tOut dst, size_t n, SDst dw, _tPixel c)
538 {
539 VerticalLineTransfomer()(dst, n, dw, ystdex::pseudo_iterator<_tPixel>(c));
540 }
542
547 template<typename _tPixel, typename _tOut, typename... _tParams>
548 inline void
549 FillRectRaw(_tOut dst, _tPixel c, _tParams&&... args)
550 {
551 Drawing::BlitRectLines(CopyLine<true>(), dst,
552 ystdex::pseudo_iterator<_tPixel>(c), yforward(args)...);
553 }
554
555
560 using IteratorPair = ystdex::pair_iterator<ConstBitmapPtr, const AlphaType*>;
561
562
567 template<class _fTransformPixel>
568 bool
569 TransformRect(const Graphics& g, const Point& pt, const Size& s,
570 _fTransformPixel tp)
571 {
572 if(YB_LIKELY(g))
573 {
574 Drawing::BlitPixels<false, false>(
575 [tp](BitmapPtr dst_iter, ConstBitmapPtr){
576 tp(dst_iter);
577 }, g.GetBufferPtr(), g.GetBufferPtr(), g.GetSize(), g.GetSize(), pt,
578 pt, s);
579 return true;
580 }
581 return {};
582 }
587 template<class _fTransformPixel>
588 inline bool
589 TransformRect(const Graphics& g, const Rect& r, _fTransformPixel tp)
590 {
591 return Drawing::TransformRect<_fTransformPixel>(g, r.GetPoint(),
592 r.GetSize(), tp);
593 }
594
595
603 YF_API void
604 CopyBuffer(const Graphics&, const ConstGraphics&);
605
610 YF_API void
611 ClearImage(const Graphics&);
612
617 YF_API void
618 Fill(const Graphics&, Color);
619
620 } // namespace Drawing;
621
622 } // namespace YSLib;
623
624 #endif
625
YSLib::ClearSequence
void ClearSequence(_tOut dst, size_t n) ynothrowv
清除指定的连续对象。
Definition: YCoreUtilities.h:359
YSLib::Drawing::FillRectRaw
void FillRectRaw(_tOut dst, _tPixel c, _tParams &&... args)
使用指定像素填充指定的标准矩形区域。
Definition: YBlit.h:549
YSLib::Drawing::ClearImage
YF_API void ClearImage(const Graphics &)
清除图形接口上下文缓冲区。
Definition: YBlit.cpp:87
rational.hpp
有理数运算。
YSLib::Drawing::BlitLineLoop::operator()
void operator()(_fPixelShader shader, _tOut &dst_iter, _tIn &src_iter, SDst delta_x)
Definition: YBlit.h:258
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
YSLib::Drawing::Size::Width
SDst Width
宽和高。
Definition: YGDIBase.h:545
YSLib::Drawing::VerticalLineTransfomer
竖直线转换器。
Definition: YBlit.h:48
YSLib::Drawing::TransformRect
bool TransformRect(const Graphics &g, const Point &pt, const Size &s, _fTransformPixel tp)
以像素为单位变换标准矩形。
Definition: YBlit.h:569
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::Drawing::Size::Height
SDst Height
Definition: YGDIBase.h:545
YSLib::Drawing::c
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect Color c
Definition: YDraw.h:174
YSLib::Drawing::BlitRectLines
void BlitRectLines(_fBlitScanner scanner, _tOut dst, _tIn src, _tParams &&... args)
根据指定批量操作（块传输扫描器或像素着色器）函数对象对矩形像素块进行批量操作。
Definition: YBlit.h:384
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::Drawing::x
const TextState &ts const TextState &ts const TextState &ts TextState SPos x
Definition: TextBase.h:190
YSLib::Drawing::DispatchTranspose
void DispatchTranspose(ystdex::false_, _func updater, const ConstGraphics &src)
分派用于着色器更新的可能转置的图像。
Definition: YBlit.h:420
YSLib::Drawing::BlitScannerLoop::operator()
void operator()(_fBlitScanner scanner, _tOut dst_iter, _tIn src_iter, SDst delta_x, SDst delta_y, SPos dst_inc, SPos src_inc) const
Definition: YBlit.h:197
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:142
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::Drawing::BlitScaleComponent
YB_ATTR_nodiscard YB_STATELESS yconstfn size_t BlitScaleComponent(SPos d, SPos s, SDst delta) ynothrow
块传输偏移分量计算器。
Definition: YBlit.h:93
YSLib::Drawing::CopyLine::operator()
void operator()(_tOut &dst_iter, _tIn &src_iter, SDst delta_x) const
复制迭代器指定的一行像素。
Definition: YBlit.h:455
YSLib::Drawing::BlitScan
void BlitScan(_fBlitLoop loop, _tOut dst, _tIn src, _tScalar d_width, _tScalar s_width, _tDiff delta_x, _tDiff delta_y)
块传输扫描函数模板。
Definition: YBlit.h:123
YSLib::Drawing::sp
dst sp
Definition: YGDI.h:442
ystdex::make_transposed
transposed_iterator< decay_t< _tIter > > make_transposed(_tIter &&i, _tSize w, _tSize h, _tIndex idx)
Definition: iterator.hpp:1083
CHRLib::f
f(d, s)
YSLib::Drawing::BlitRect
void BlitRect(_func f, _tOut dst, _tIn src, const Size &ds, const Size &ss, const Point &dp, const Point &sp, const Size &sc)
矩形块传输函数模板。
Definition: YBlit.h:335
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
YSLib::Drawing::Fill
YF_API void Fill(const Graphics &, Color)
使用指定颜色填充图形接口上下文缓冲区。
Definition: YBlit.cpp:93
YSLib::Drawing::VerticalLineTransfomer::operator()
void operator()(_tOut dst_iter, size_t n, SDst dw, _tIn src_iter) const
渲染竖直线上的像素。
Definition: YBlit.h:58
YSLib::Drawing::dp
dst dp
Definition: YGDI.h:442
YSLib::Drawing::BlitLineLoop
块传输扫描点循环操作。
Definition: YBlit.h:255
YSLib::Drawing::Blit
void Blit(_fBlitLoop loop, _tOut dst, _tIn src, const Size &ds, const Size &ss, const Point &dp, const Point &sp, const Size &sc)
块传输函数模板。
Definition: YBlit.h:168
YSLib::YAssert
YAssert(!(v< Deref(a)), "Value less than lower bound found.")
YSLib::Drawing::GGraphics
二维图形接口上下文模板。
Definition: YGraphics.h:63
YSLib::Drawing::CopyBuffer
YF_API void CopyBuffer(const Graphics &, const ConstGraphics &)
以第一参数作为目标，复制第二参数的缓冲区内容。
Definition: YBlit.cpp:77
YSLib::Drawing::BlitLines
void BlitLines(_fBlitScanner scanner, _tOut dst, _tIn src, const Size &ds, const Size &ss, const Point &dp, const Point &sp, const Size &sc)
扫描线块传输函数模板。
Definition: YBlit.h:236
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
YSLib::Drawing::src
src
Definition: YGDI.h:442
ystdex::tuple_iterator
元组迭代器。
Definition: iterator.hpp:621
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
YSLib::Drawing::BlitPixels
void BlitPixels(_fPixelShader shader, _tOut dst, _tIn src, const Size &ds, const Size &ss, const Point &dp, const Point &sp, const Size &sc)
像素块传输函数模板。
Definition: YBlit.h:296
iterator.hpp
通用迭代器。
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::Drawing::ClearPixels
_tOut ClearPixels(_tOut dst, size_t n) ynothrowv
显示缓存操作：清除/以纯色像素填充。
Definition: YBlit.h:517
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::BlitScannerLoop
块传输扫描线循环操作。
Definition: YBlit.h:193
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
YSLib::Drawing::CopyLine
扫描线：按指定扫描顺序复制一行像素。
Definition: YBlit.h:444
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib::Drawing::BlitBounds
YF_API bool BlitBounds(const Point &, const Point &, const Size &, const Size &, const Size &, SDst &, SDst &, SDst &, SDst &)
块传输边界计算器。
Definition: YBlit.cpp:58
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
YSLib::Drawing::CopyLine< false >::operator()
void operator()(_tOut &dst_iter, _tIn &src_iter, SDst delta_x) const
Definition: YBlit.h:495
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::Drawing::Transpose
YB_ATTR_nodiscard YB_PURE yconstfn _tBinary Transpose(const _tBinary &obj) ynothrow
转置。
Definition: YGDIBase.h:453
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:827
YModules.h
YSLib 用户界面模块配置文件。
ystdex::is_undereferenceable
bool is_undereferenceable(const _tIter &)
Definition: deref_op.hpp:46
YSLib::Drawing::FillVerticalLine
void FillVerticalLine(_tOut dst, size_t n, SDst dw, _tPixel c)
使用 n 个指定像素竖直填充指定位置。
Definition: YBlit.h:537
YSLib::Drawing::ynothrow
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE const Padding & ynothrow
Definition: YGDI.h:132
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::pseudo_iterator
伪迭代器。
Definition: iterator.hpp:55
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YSLib::Drawing::BlitRectPixels
void BlitRectPixels(_fPixelShader shader, _tOut dst, _tIn src, _tParams &&... args)
Definition: YBlit.h:397
YSLib::size_t
YF_API const char size_t
Definition: YException.h:149
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:96
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
ystdex::false_
bool_< false > false_
Definition: integral_constant.hpp:110
YSLib::Drawing::FillPixels
void FillPixels(_tOut dst_iter, size_t n, _tPixel c)
使用 n 个指定像素连续填充指定位置。
Definition: YBlit.h:526
YSLib::args
YB_ATTR_nodiscard YB_PURE typename _tParams && args
Definition: ValueNode.h:1299
YSLib::Drawing::CopyLine::operator()
void operator()(_tOut &dst_iter, ystdex::pseudo_iterator< _tPixel > src_iter, SDst delta_x) const
Definition: YBlit.h:471
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073