YSTest: yblit.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
yblit.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2009 - 2013.
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 #include "YSLib/Service/yblit.h"
29
30 using namespace ystdex;
31
32 YSL_BEGIN
33
34 YSL_BEGIN_NAMESPACE(Drawing)
35
36 namespace
37 {
38
40 inline SPos
41 blit_min(SPos d)
42 {
43 return max<int>(0, -d);
44 }
45
46 inline SPos
47 blit_max(SPos s, SPos d, SDst sl, SDst dl, SDst cl)
48 {
49 return min<int>(min<int>(dl - d, sl - s), cl);
50 }
51
52 } // unnamed namespace;
53
54 bool
55 BlitBounds(const Point& dp, const Point& sp,
56 const Size& ds, const Size& ss, const Size& sc,
57 int& min_x, int& min_y, int& delta_x, int& delta_y)
58 {
59 yunseq(min_x = blit_min(dp.X), min_y = blit_min(dp.Y),
60 delta_x = blit_max(sp.X, dp.X, ss.Width, ds.Width, sc.Width),
61 delta_y = blit_max(sp.Y, dp.Y, ss.Height, ds.Height, sc.Height));
62 if(min_x < delta_x && min_y < delta_y)
63 {
64 yunseq(delta_x -= min_x, delta_y -= min_y);
65 return true;
66 }
67 return false;
68 }
69
70 template<>
71 int
72 BlitScale<false, false>(const Point& dp, const Size& ds, int, int)
73 {
74 return max<int>(0, dp.Y) * ds.Width + max<int>(0, dp.X);
75 }
76 template<>
77 int
78 BlitScale<true, false>(const Point& dp, const Size& ds, int, int delta_y)
79 {
80 return (max<int>(0, dp.Y) + delta_y - 1) * ds.Width + max<int>(0, dp.X);
81 }
82 template<>
83 int
84 BlitScale<false, true>(const Point& dp, const Size& ds, int delta_x, int)
85 {
86 return max<int>(0, dp.Y) * ds.Width + max<int>(0, dp.X) + delta_x - 1;
87 }
88 template<>
89 int
90 BlitScale<true, true>(const Point& dp, const Size& ds, int delta_x, int delta_y)
91 {
92 return (max<int>(0, dp.Y) + delta_y - 1) * ds.Width
93 + max<int>(0, dp.X) + delta_x - 1;
94 }
95
96 //显式实例化：防止链接错误。
97 template
98 void Blit<BlitLoop, false, false>(BitmapPtr, const Size&,
99 ConstBitmapPtr, const Size&,
100 const Point&, const Point&, const Size&);
101 template
102 void Blit<BlitLoop, true, true>(BitmapPtr, const Size&,
103 ConstBitmapPtr, const Size&,
104 const Point&, const Point&, const Size&);
105 template
106 void Blit<BlitTransparentLoop, false, false>(BitmapPtr, const Size&,
107 IteratorPair, const Size&,
108 const Point&, const Point&, const Size&);
109 template
110 void Blit<BlitTransparentLoop, true, true>(BitmapPtr, const Size&,
111 IteratorPair, const Size&,
112 const Point&, const Point&, const Size&);
113 template
114 void Blit<BlitBlendLoop, false, false>(BitmapPtr, const Size&,
115 IteratorPair, const Size&,
116 const Point&, const Point&, const Size&);
117 template
118 void Blit<BlitBlendLoop, true, true>(BitmapPtr, const Size&,
119 IteratorPair, const Size&,
120 const Point&, const Point&, const Size&);
121
122
123 void
124 CopyBuffer(const Graphics& dst, const Graphics& src)
125 {
126 YAssert(dst.GetBufferPtr(), "Null pointer found.");
127 YAssert(src.GetBufferPtr(), "Null pointer found.");
128 YAssert(dst.GetSize() == src.GetSize(), "Source and destination sizes"
129 "are not same.");
130
131 if(YB_LIKELY(dst.GetBufferPtr() != src.GetBufferPtr()))
132 std::copy_n(src.GetBufferPtr(), GetAreaOf(src.GetSize()),
133 dst.GetBufferPtr());
134 }
135
136 void
137 ClearImage(const Graphics& g)
138 {
139 ClearPixel(g.GetBufferPtr(), GetAreaOf(g.GetSize()));
140 }
141
142 void
143 Fill(const Graphics& g, Color c)
144 {
145 FillPixel<PixelType>(g.GetBufferPtr(), GetAreaOf(g.GetSize()), c);
146 }
147
148 YSL_END_NAMESPACE(Drawing)
149
150 YSL_END
151