YSTest: YGDI.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

YGDI.cpp
浏览该文件的文档.
1 /*
2 © 2009-2015 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 #include "YSLib/Service/YModules.h"
29 #include YFM_YSLib_Service_YGDI
30 #include YFM_YSLib_Service_YBlend
31
32 using namespace ystdex;
33
34 namespace YSLib
35 {
36
37 namespace Drawing
38 {
39
40 Rect
41 operator+(const Rect& r, const Padding& m)
42 {
43 // XXX: Conversion to 'SPos' might be implementation-defined.
44 return Rect(r.X + m.Left, r.Y + m.Top,
45 SDst(max<SPos>(0, SPos(r.Width) - m.Left - m.Right)),
46 SDst(max<SPos>(0, SPos(r.Height) - m.Top - m.Bottom)));
47 }
48
49
50 Padding
51 FetchMargin(const Rect& r, const Size& s)
52 {
53 // XXX: Conversion to 'SPos' might be implementation-defined.
54 return Padding(r.X, SPos(s.Width) - r.X - SPos(r.Width),
55 r.Y, SPos(s.Height) - r.Y - SPos(r.Height));
56 }
57
58
59 Point
60 ClipBounds(Rect& clip, const Rect& bounds)
61 {
62 if(!clip.IsUnstrictlyEmpty() && Clip(clip, bounds))
63 return clip.GetPoint() - bounds.GetPoint();
64 clip.GetSizeRef() = {};
65 return {};
66 }
67
68 Point
69 ClipMargin(PaintContext& pc, const Padding& m, const Size& ss)
70 {
71 const Size& ds(pc.Target.GetSize());
72
73 if(GetHorizontalOf(m) < ds.Width && GetVerticalOf(m) < ds.Height)
74 {
75 const auto& pt(pc.Location);
76 const Point dp(max<int>(m.Left, pt.X), max<int>(m.Top, pt.Y));
77 const Point sp(dp - pt);
78 // XXX: Conversion to 'SPos' might be implementation-defined.
79 const SPos scx(min<SPos>(SPos(ss.Width), SPos(ds.Width) - m.Right
80 - dp.X) - sp.X), scy(min<SPos>(SPos(ss.Height), SPos(ds.Height)
81 - m.Bottom - dp.Y) - sp.Y);
82
83 if(scx > 0 && scy > 0)
84 {
85 pc.ClipArea &= Rect(dp, SDst(scx), SDst(scy));
86 return pc.ClipArea.GetPoint() - pt;
87 }
88 }
89 pc.ClipArea.GetSizeRef() = {};
90 return {};
91 }
92
93
94 ImplDeDtor(BasicImage)
95
96
97 CompactPixmap::CompactPixmap(ConstBitmapPtr i, SDst w, SDst h)
98 : BaseType()
99 // NOTE: The size member cannot be initialized just here, or it would be
100 // inconsistent with buffer pointer.
101 {
102 SetSize(w, h);
103 if(i)
104 CopyBitmapBuffer(GetBufferPtr(), i, GetSize());
105 }
106 CompactPixmap::CompactPixmap(unique_ptr<Pixel[]> p, const Size& s) ynothrow
107 : BaseType(std::move(p), s)
108 {}
109 CompactPixmap::CompactPixmap(const CompactPixmap& buf)
110 // XXX: $2015-03 @ %Documentation::Workflow::Annual2015.
111 : BaseType(), IImage()
112 {
113 SetSize(buf.GetSize());
114 if(const auto p = buf.GetBufferPtr())
115 CopyBitmapBuffer(GetBufferPtr(), p, GetSize());
116 }
117
118 void
119 CompactPixmap::SetContent(ConstBitmapPtr s, SDst w, SDst h)
120 {
121 SetSize(w, h);
122 if(YB_LIKELY(pBuffer && s))
123 CopyBitmapBuffer(pBuffer.get(), s, GetSize());
124 }
125 void
126 CompactPixmap::SetSize(const Size& s)
127 {
128 const auto area(GetAreaOf(s));
129
130 TryExpr(pBuffer.reset(YB_LIKELY(area != 0) ? new Pixel[area] : nullptr))
131 CatchThrow(std::bad_alloc&,
132 LoggedEvent("BitmapBuffer allocation failed.", Alert))
133 YAssert(bool(pBuffer) == (area != 0), "Buffer corrupted.");
134 sGraphics = s,
135 ClearImage();
136 }
137 void
138 CompactPixmap::SetSizeSwap()
139 {
140 std::swap(sGraphics.Width, sGraphics.Height);
141 ClearImage();
142 }
143
144 void
145 CompactPixmap::ClearImage() const
146 {
147 Drawing::ClearImage(GetContext());
148 }
149
150
151 CompactPixmapEx::CompactPixmapEx(ConstBitmapPtr i, SDst w, SDst h)
152 : CompactPixmapEx()
153 {
154 SetSize(w, h);
155 if(i)
156 CopyBitmapBuffer(pBuffer.get(), i, GetSize());
157 }
158 CompactPixmapEx::CompactPixmapEx(const CompactPixmapEx& buf)
159 : CompactPixmapEx()
160 {
161 SetSize(buf.GetSize());
162 if(const auto p = buf.GetBufferPtr())
163 {
164 CopyBitmapBuffer(pBuffer.get(), p, GetSize()),
165 CopyBitmapBuffer(pBufferAlpha.get(), buf.GetBufferAlphaPtr(),
166 GetSize());
167 }
168 }
169
170 void
171 CompactPixmapEx::SetSize(const Size& s)
172 {
173 const auto area(GetAreaOf(s));
174
175 try
176 {
177 unique_ptr<Pixel[]> p_new(YB_LIKELY(area != 0) ? new Pixel[area]
178 : nullptr);
179 unique_ptr<AlphaType[]> p_new_alpha(YB_LIKELY(area != 0)
180 ? new AlphaType[area] : nullptr);
181
182 yunseq(pBuffer = std::move(p_new),
183 pBufferAlpha = std::move(p_new_alpha));
184 }
185 CatchThrow(std::bad_alloc&,
186 LoggedEvent("CompactPixmapEx allocation failed.", Alert))
187 YAssert(bool(pBuffer) == (area != 0), "Buffer corrupted."),
188 YAssert(bool(pBufferAlpha) == (area != 0), "Alpha buffer corrupted.");
189 sGraphics = s,
190 ClearImage();
191 }
192
193 void
194 CompactPixmapEx::ClearImage() const
195 {
196 const auto t(size_t(GetAreaOf(sGraphics)));
197
198 ClearPixels(pBuffer.get(), t);
199 ClearPixels(pBufferAlpha.get(), t);
200 }
201
202 bool
203 CopyTo(BitmapPtr dst, const ConstGraphics& g, const Size& ds,
204 const Point& dp, const Point& sp, const Size& sc, Rotation rot)
205 {
206 if(~rot & 1 && dst && bool(g))
207 {
208 if(rot == RDeg0)
209 BlitLines<false, false>(CopyLine<true>(), dst, g.GetBufferPtr(),
210 ds, g.GetSize(), dp, sp, sc);
211 else
212 BlitLines<true, true>(CopyLine<false>(), dst, g.GetBufferPtr(),
213 ds, g.GetSize(), dp, sp, sc);
214 return true;
215 }
216 return {};
217 }
218 bool
219 CopyTo(BitmapPtr dst, const CompactPixmapEx& buf, const Size& ds,
220 const Point& dp, const Point& sp, const Size& sc, Rotation rot)
221 {
222 if(~rot & 1 && dst && bool(buf))
223 {
224 if(rot == RDeg0)
225 BlitPixels<false, false>(Shaders::BlitTransparentPoint(), dst,
226 IteratorPair(buf.GetBufferPtr(), buf.GetBufferAlphaPtr()), ds,
227 buf.GetSize(), dp, sp, sc);
228 else
229 BlitPixels<true, true>(Shaders::BlitTransparentPoint(), dst,
230 IteratorPair(buf.GetBufferPtr(), buf.GetBufferAlphaPtr()), ds,
231 buf.GetSize(), dp, sp, sc);
232 return true;
233 }
234 return {};
235 }
236
237 bool
238 BlitTo(BitmapPtr dst, const CompactPixmapEx& buf, const Size& ds,
239 const Point& dp, const Point& sp, const Size& sc, Rotation rot)
240 {
241 if(~rot & 1 && dst && bool(buf))
242 {
243 if(rot == RDeg0)
244 BlitPixels<false, false>(Shaders::BlitAlphaPoint(), dst,
245 IteratorPair(buf.GetBufferPtr(), buf.GetBufferAlphaPtr()), ds,
246 buf.GetSize(), dp, sp, sc);
247 else
248 BlitPixels<true, true>(Shaders::BlitAlphaPoint(), dst,
249 IteratorPair(buf.GetBufferPtr(), buf.GetBufferAlphaPtr()), ds,
250 buf.GetSize(), dp, sp, sc);
251 return true;
252 }
253 return {};
254 }
255
256 } // namespace Drawing;
257
258 } // namespace YSLib;
259
platform::p
while p p
Definition: YCLib/FileSystem.h:225
YSLib::Drawing::CopyTo
bool CopyTo(BitmapPtr dst, const ConstGraphics &g, const Size &ds, const Point &dp, const Point &sp, const Size &sc, Rotation rot)
Definition: YGDI.cpp:203
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
YSLib::Drawing::BlitTo
bool BlitTo(BitmapPtr dst, const CompactPixmapEx &buf, const Size &ds, const Point &dp, const Point &sp, const Size &sc, Rotation rot)
Definition: YGDI.cpp:238
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
YSLib::Text::buf
const char * buf
Definition: TextFile.h:77
ImplDeDtor
#define ImplDeDtor(_t)
Definition: YBaseMacro.h:182
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
YSLib::Drawing::CompactPixmap::SetSizeSwap
void SetSizeSwap()
交换宽和高；同时清除缓冲区。
Definition: YGDI.cpp:138
YSLib::Drawing::ClearImage
YF_API void ClearImage(const Graphics &)
清除图形接口上下文缓冲区。
Definition: YBlit.cpp:88
YSLib::Drawing::ClipBounds
Point ClipBounds(Rect &clip, const Rect &bounds)
Definition: YGDI.cpp:60
YSLib::Drawing::CopyLine
扫描线：按指定扫描顺序复制一行像素。
Definition: YBlit.h:443
YSLib::Drawing::Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: YGDIBase.h:895
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::pBuffer
PointerType pBuffer
显示缓冲区指针。
Definition: YGraphics.h:79
YSLib::Drawing::CompactPixmap::SetSize
void SetSize(const Size &) override
重新设置缓冲区大小。
Definition: YGDI.cpp:126
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YSLib::Drawing::Padding
空白样式。
Definition: YGDI.h:46
YSLib::Drawing::GBinaryGroup::X
_type X
Definition: YGDIBase.h:63
YSLib::Drawing::Size::Width
SDst Width
Definition: YGDIBase.h:302
YSLib::Drawing::CompactPixmap
标准矩形像素图缓冲区。
Definition: YGDI.h:243
YSLib::Drawing::CompactPixmap::ClearImage
virtual void ClearImage() const
清除缓冲区。
Definition: YGDI.cpp:145
platform::AlphaType
octet AlphaType
Definition: Video.h:289
YSLib::Drawing::GBinaryGroup::Y
_type Y
分量。
Definition: YGDIBase.h:63
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::s
const SizeType & s
Definition: YGraphics.h:88
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::sGraphics
SizeType sGraphics
图形区域大小。
Definition: YGraphics.h:81
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YSLib::Drawing::Padding::Right
SPos Right
Definition: YGDI.h:52
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:93
YModules.h
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:42
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
YSLib::Drawing::IteratorPair
ystdex::pair_iterator< ConstBitmapPtr, const AlphaType * > IteratorPair
Alpha 光栅化源迭代器对。
Definition: YBlit.h:562
YSLib::Drawing::Shaders::BlitTransparentPoint
像素迭代器透明操作。
Definition: YBlend.h:50
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:996
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::Drawing::Shaders::BlitAlphaPoint
像素计算：Alpha 混合。
Definition: YBlend.h:80
ystdex
特性测试宏。
Definition: ydef.h:796
YSLib::Drawing::Padding::Top
SPos Top
Definition: YGDI.h:52
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
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::operator+
Rect operator+(const Rect &r, const Padding &m)
Definition: YGDI.cpp:41
Drawing
YSLib::Drawing::ClipMargin
Point ClipMargin(PaintContext &pc, const Padding &m, const Size &ss)
Definition: YGDI.cpp:69
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
YSLib::i
return i
Definition: YCoreUtilities.h:176
YSLib::Drawing::CopyBitmapBuffer
void CopyBitmapBuffer(_tOut p_dst, _tIn p_src, const Size &s)
Definition: YGraphics.h:50
YSLib::Drawing::CopyLine< false >
Definition: YBlit.h:487
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:437
YSLib::Drawing::Size::Height
SDst Height
宽和高。
Definition: YGDIBase.h:302
YSLib::Drawing::BasicImage
使用 Graphics 定义的基本图像。
Definition: YGDI.h:204
YSLib::Drawing::Padding::Bottom
SPos Bottom
Definition: YGDI.h:52
YSLib::Drawing::RDeg0
Definition: YGDIBase.h:897
YSLib::Drawing::Padding::Left
SPos Left
空白距离：左、右、上、下。
Definition: YGDI.h:52
YSLib::Drawing::ClearPixels
_tOut ClearPixels(_tOut dst, size_t n) ynothrowv
清除指定位置的 n 个连续像素。
Definition: YBlit.h:517
YSLib::Drawing::GGraphics
二维图形接口上下文模板。
Definition: YGraphics.h:62
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
platform::Descriptions::Alert
Definition: YCommon.h:154
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:43
YSLib::Drawing::FetchMargin
Padding FetchMargin(const Rect &r, const Size &s)
Definition: YGDI.cpp:51
CatchThrow
#define CatchThrow(_ex,...)
指定抛出指定异常作为异常处理器。
Definition: YBaseMacro.h:141
YSLib::Drawing::GBinaryGroup< SPos >