YSTest: Video.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

Video.h
浏览该文件的文档.
1 /*
2 © 2011-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 #ifndef YCL_INC_Video_h_
29 #define YCL_INC_Video_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YCLib_YCommon // for std::is_signed, std::is_unsigned;
33 #include <ystdex/bitseg.hpp> // for ystdex::integer_width,
34 // ystdex::ordered_bitseg_traits, ystdex::bitseg_traits;
35
36 namespace platform
37 {
38
39 #if YCL_Win32
40 using SPos = long;
41 using SDst = unsigned long;
42 #else
43 using SPos = std::int16_t;
44 using SDst = std::uint16_t;
45 #endif
46
48
49 static_assert(std::is_signed<SPos>(),
50 "Only signed integer is supported for screen position measurement.");
51 static_assert(std::is_unsigned<SDst>(),
52 "Only unsigned integer is supported for screen destination measurement.");
53 static_assert(ystdex::integer_width<SDst>() >= ystdex::integer_width<SPos>(),
54 "Max value of screen destination shall be grater than max value of screen"
55 " position.");
57
58
60
61 inline namespace IndexSpace
63 {
64
66 namespace AXYZIndex
67 {
68
70 enum AXYZ : size_t
71 {
72 A = 0,
73 X = 1,
74 Y = 2,
75 Z = 3
76 };
77
78 } // namespace AXYZIndex;
79
81 namespace AXYZMapping
82 {
83
85 enum ABGR : size_t
86 {
87 A = AXYZIndex::A,
88 B = AXYZIndex::X,
89 G = AXYZIndex::Y,
90 R = AXYZIndex::Z
91 };
92
93 } // namespace AXYZMapping;
94
96 namespace AZYXMapping
97 {
98
100 enum ABGR : size_t
101 {
102 A = AXYZIndex::A,
103 B = AXYZIndex::Z,
104 G = AXYZIndex::Y,
105 R = AXYZIndex::X
106 };
107
108 } // namespace AZYXMapping;
109
110 } // inline namespace IndexSpace;
111
112
114
115
117
130 template<class _tBitSegTraits, size_t _vIdxA, size_t _vIdxX, size_t _vIdxY,
131 size_t _vIdxZ>
132 struct AXYZValueTraits : ystdex::ordered_bitseg_traits<_tBitSegTraits, _vIdxA,
133 _vIdxX, _vIdxY, _vIdxZ>
134 {
135 using Base = ystdex::ordered_bitseg_traits<_tBitSegTraits, _vIdxA, _vIdxX,
136 _vIdxY, _vIdxZ>;
137
138 static yconstexpr const size_t ABitsN
139 = Base::template component_width<AXYZIndex::A>::value;
140 static yconstexpr const size_t XYZBitsN
141 = Base::template component_width<AXYZIndex::X>::value
142 + Base::template component_width<AXYZIndex::Y>::value
143 + Base::template component_width<AXYZIndex::Z>::value;
144 };
145
146
148
149 template<size_t _vA, size_t _vX, size_t _vY, size_t _vZ>
151 using AXYZTraits
152 = AXYZValueTraits<ystdex::bitseg_traits<_vA, _vX, _vY, _vZ>, 0, 1, 2, 3>;
153
155 template<size_t _vX, size_t _vY, size_t _vZ, size_t _vA>
156 using XYZATraits
157 = AXYZValueTraits<ystdex::bitseg_traits<_vX, _vY, _vZ, _vA>, 3, 0, 1, 2>;
159
160
161
162
180 template<class _tTraits, typename _tComponentMap, size_t _v1, size_t _v2,
181 size_t _v3, size_t _v4>
182 union YB_ATTR(packed) YB_ATTR(aligned(yalignof(typename _tTraits::integer)))
183 PixelQuadruple
184 {
185 using Traits = _tTraits;
186 using StorageTraits = typename _tTraits::base;
187 using ArrayType = typename StorageTraits::array;
188 using IntegerType = typename Traits::integer;
190 template<size_t _vIdx>
191 using StoredComponentType
192 = typename StorageTraits::template component_t<_vIdx>;
194 using CMap = _tComponentMap;
195 using AType = typename Traits::template component_t<CMap::A>;
196 using BType = typename Traits::template component_t<CMap::B>;
197 using GType = typename Traits::template component_t<CMap::G>;
198 using RType = typename Traits::template component_t<CMap::R>;
199
200 ArrayType Bytes;
201 IntegerType Integer;
202
203 DefDeCtor(PixelQuadruple)
204 yconstfn
205 PixelQuadruple(IntegerType i) ynothrow
206 : Integer(i)
207 {}
208 yconstfn
209 PixelQuadruple(StoredComponentType<0> v0, StoredComponentType<1> v1,
210 StoredComponentType<2> v2, StoredComponentType<3> v3) ynothrow
211 : Integer(Traits::base::pack(v0, v1, v2, v3))
212 {}
213
214 yconstfn DefCvt(const ynothrow, IntegerType, Integer)
215
216 yconstfn DefGetter(const ynothrow, AType, A,
217 Traits::template extract<CMap::A>(Integer))
218 yconstfn DefGetter(const ynothrow, BType, B,
219 Traits::template extract<CMap::B>(Integer))
220 yconstfn DefGetter(const ynothrow, GType, G,
221 Traits::template extract<CMap::G>(Integer))
222 yconstfn DefGetter(const ynothrow, RType, R,
223 Traits::template extract<CMap::R>(Integer))
225 };
226
227
228 template<size_t _vB, size_t _vG, size_t _vR, size_t _vA>
229 using BGRA = PixelQuadruple<XYZATraits<_vB, _vG, _vR, _vA>, AXYZMapping::ABGR,
230 _vB, _vG, _vR, _vA>;
231
232
233 template<size_t _vR, size_t _vG, size_t _vB, size_t _vA>
234 using RGBA = PixelQuadruple<XYZATraits<_vR, _vG, _vB, _vA>, AZYXMapping::ABGR,
235 _vR, _vG, _vB, _vA>;
236
237
238 template<size_t _vA, size_t _vR, size_t _vG, size_t _vB>
239 using ARGB = PixelQuadruple<AXYZTraits<_vA, _vR, _vG, _vB>, AZYXMapping::ABGR,
240 _vA, _vR, _vG, _vB>;
241
242
243 template<size_t _vA, size_t _vB, size_t _vG, size_t _vR>
244 using ABGR = PixelQuadruple<AXYZTraits<_vA, _vB, _vG, _vR>, AXYZMapping::ABGR,
245 _vA, _vB, _vG, _vR>;
247
248
249
251
252 using MonoType = octet;
253 using AlphaType = octet;
255
256 #if YCL_DS
257
262 # define YCL_PIXEL_FORMAT_XYZ555 0xAABBCCDD
263
269 using Pixel = RGBA<5, 5, 5, 1>;
275 yconstfn PDefH(AlphaType, FetchAlpha, Pixel px) ynothrow
276 ImplRet(px.GetA() != 0 ? 0xFF : 0)
277
283 yconstfn PDefH(Pixel, FetchOpaque, Pixel px) ynothrow
284 ImplRet(px.Integer | 1 << 15)
285
286
290 yconstfn PDefH(std::uint16_t, FetchPixel, MonoType r, MonoType g, MonoType b)
291 ynothrow
292 ImplRet(r >> 3 | std::uint16_t(g >> 3) << 5 | std::uint16_t(b >> 3) << 10)
293
294 # define DefColorH_(hex, name) name = \
295 (FetchPixel(((hex) >> 16) & 0xFF, ((hex) >> 8) & 0xFF, (hex) & 0xFF) \
296 | 1 << 15)
297 #elif YCL_Win32 || YCL_Android || YCL_Linux || YCL_OS_X
298 // TODO: Real implementation for X11.
299 # if YCL_Win32
300
305 # define YCL_PIXEL_FORMAT_XYZ888 0xAADDCCBB
306
317 using Pixel = BGRA<8, 8, 8, 8>;
318 # else
319
324 # define YCL_PIXEL_FORMAT_XYZ888 0xAABBCCDD
325
331 using Pixel = RGBA<8, 8, 8, 8>;
332 # endif
333
338 yconstfn PDefH(AlphaType, FetchAlpha, Pixel px) ynothrow
339 ImplRet(px.GetA())
340
346 yconstfn PDefH(Pixel, FetchOpaque, Pixel px) ynothrow
347 # if YCL_Win32
348 ImplRet({px.GetB(), px.GetG(), px.GetR(), 0xFF})
349 # else
350 ImplRet({px.GetB(), px.GetG(), px.GetR(), 0xFF})
351 # endif
352
358 yconstfn PDefH(std::uint32_t, FetchPixel,
359 AlphaType r, AlphaType g, AlphaType b) ynothrow
360 ImplRet(std::uint32_t(r) | std::uint32_t(g) << 8 | std::uint32_t(b) << 16)
361
362
369 # define DefColorH_(hex, name) \
370 name = (FetchPixel(((hex) >> 16) & 0xFF, \
371 ((hex) >> 8) & 0xFF, (hex) & 0xFF) << 8 | 0xFF)
372 #else
373 # error "Unsupported platform found."
374 #endif
375
376
378 namespace ColorSpace
379 {
380 // #define DefColorA(r, g, b, name) name = ARGB16(1, r, g, b),
381 #define HexAdd0x(hex) 0x##hex
382 #define DefColorH(hex_, name) DefColorH_(HexAdd0x(hex_), name)
383
389 enum ColorSet : Pixel::Traits::integer
390 {
391 DefColorH(00FFFF, Aqua),
392 DefColorH(000000, Black),
393 DefColorH(0000FF, Blue),
394 DefColorH(FF00FF, Fuchsia),
395 DefColorH(808080, Gray),
396 DefColorH(008000, Green),
397 DefColorH(00FF00, Lime),
398 DefColorH(800000, Maroon),
399 DefColorH(000080, Navy),
400 DefColorH(808000, Olive),
401 DefColorH(800080, Purple),
402 DefColorH(FF0000, Red),
403 DefColorH(C0C0C0, Silver),
404 DefColorH(008080, Teal),
405 DefColorH(FFFFFF, White),
406 DefColorH(FFFF00, Yellow)
407 };
408
409 #undef DefColorH
410 #undef DefColorH_
411 #undef HexAdd0x
412 } // namespace ColorSpace;
413
414
416 class YF_API Color
417 {
418 public:
419 using ColorSet = ColorSpace::ColorSet;
420
421 private:
426 MonoType r = 0, g = 0, b = 0;
431 AlphaType a = 0;
432
433 public:
438 yconstfn
439 Color() = default;
444 yconstfn
445 Color(Pixel px) ynothrow
446 #if YCL_DS
447 : r(px.GetR() << 3), g(px.GetG() << 3), b(px.GetB() << 3),
448 a(FetchAlpha(px) ? 0xFF : 0x00)
449 #elif YCL_Win32 || YCL_Linux || YCL_OS_X
450 : r(px.GetR()), g(px.GetG()), b(px.GetB()), a(px.GetA())
451 #endif
452 {}
457 yconstfn
458 Color(ColorSet cs) ynothrow
459 #if YCL_DS
460 : Color(Pixel(cs))
461 #elif YCL_Win32 || YCL_Android || YCL_Linux || YCL_OS_X
462 : r((cs & 0xFF00) >> 8), g((cs & 0xFF0000) >> 16),
463 b((cs & 0xFF000000) >> 24), a(0xFF)
464 #endif
465 {}
470 yconstfn
471 Color(MonoType r_, MonoType g_, MonoType b_, AlphaType a_ = 0xFF) ynothrow
472 : r(r_), g(g_), b(b_), a(a_)
473 {}
479 template<typename _tScalar>
480 yconstfn
481 Color(_tScalar r_, _tScalar g_, _tScalar b_, AlphaType a_ = 0xFF) ynothrow
482 : Color(MonoType(r_), MonoType(g_), MonoType(b_), a_)
483 {}
484
489 yconstfn
490 operator Pixel() const ynothrow
491 {
492 #if YCL_DS
493 return int(a != 0) << 15 | FetchPixel(r, g, b);
494 #elif YCL_Win32
495 return {b, g, r, a};
496 #elif YCL_Android || YCL_Linux || YCL_OS_X
497 return {r, g, b, a};
498 #endif
499 }
500
505 yconstfn DefGetter(const ynothrow, MonoType, A, a)
510 yconstfn DefGetter(const ynothrow, MonoType, B, b)
515 yconstfn DefGetter(const ynothrow, MonoType, G, g)
520 yconstfn DefGetter(const ynothrow, MonoType, R, r)
521 };
522
523
528 YF_API bool
529 InitVideo();
530
531 } // namespace platform;
532
533 #endif
534
ystdex::ordered_bitseg_traits< _tBitSegTraits, _vIdxA, _vIdxX, _vIdxY, _vIdxZ >::component_width
typename base::template component_width< map< _vIdx >::value > component_width
Definition: bitseg.hpp:145
platform::AXYZValueTraits::XYZBitsN
static yconstexpr const size_t XYZBitsN
Definition: Video.h:141
platform::IndexSpace::AXYZIndex::Z
Definition: Video.h:75
platform::ARGB
PixelQuadruple< AXYZTraits< _vA, _vR, _vG, _vB >, AZYXMapping::ABGR, _vA, _vR, _vG, _vB > ARGB
Definition: Video.h:240
platform::IndexSpace::AZYXMapping::R
Definition: Video.h:105
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
platform::MonoType
octet MonoType
Definition: Video.h:252
bitseg.hpp
位段数据结构和访问。
yalignof
#define yalignof(_type)
指定特定类型的对齐。
Definition: ydef.h:660
platform
默认平台命名空间。
Definition: Container.h:47
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
platform::Color::ColorSet
ColorSpace::ColorSet ColorSet
Definition: Video.h:419
platform::ColorSpace::ColorSet
ColorSet
默认颜色集。
Definition: Video.h:389
ystdex::integer_width
取指定整数类型的位宽度。
Definition: cstdint.hpp:101
platform::PDefH
const string const char *sig PDefH(string, ComposeMessageWithSignature, const char *msg, const char *sig) ImplRet(string(Nonnull(msg))+" @ "+Nonnull(sig)) template< class _type > inline YB_NONNULL(2) string ComposeMessageWithSignature(const _type &msg
platform::RGBA
PixelQuadruple< XYZATraits< _vR, _vG, _vB, _vA >, AZYXMapping::ABGR, _vR, _vG, _vB, _vA > RGBA
Definition: Video.h:235
platform::IndexSpace::AXYZIndex::AXYZ
AXYZ
Definition: Video.h:70
Color
Pixel Color
Definition: CharRenderer.cpp:58
platform::Color::Color
yconstfn Color(MonoType r_, MonoType g_, MonoType b_, AlphaType a_=0xFF) ynothrow
构造：使用 RGB 值和 alpha 位。
Definition: Video.h:471
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
platform::IndexSpace::AZYXMapping::ABGR
ABGR
Definition: Video.h:100
platform::ImplRet
const string const char *sig ImplRet(msg+" @ "+Nonnull(sig)) inline YB_NONNULL(1
platform::IndexSpace::AXYZIndex::X
Definition: Video.h:73
platform::ABGR
PixelQuadruple< AXYZTraits< _vA, _vB, _vG, _vR >, AXYZMapping::ABGR, _vA, _vB, _vG, _vR > ABGR
Definition: Video.h:245
platform::IndexSpace::AZYXMapping::A
Definition: Video.h:102
YSLib::Consoles::Blue
Definition: YConsole.h:62
YB_ATTR
#define YB_ATTR(...)
GNU 风格属性。
Definition: ydef.h:353
DefColorH
#define DefColorH(hex_, name)
Definition: Video.h:382
platform::AlphaType
octet AlphaType
Definition: Video.h:253
YSLib::Consoles::Red
Definition: YConsole.h:65
platform::IndexSpace::AXYZMapping::ABGR
ABGR
Definition: Video.h:85
platform::Color::Color
yconstfn Color(ColorSet cs) ynothrow
构造：使用默认颜色。
Definition: Video.h:458
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:167
platform::Color::Color
yconstfn Color(_tScalar r_, _tScalar g_, _tScalar b_, AlphaType a_=0xFF) ynothrow
构造：使用相同类型转换为单色的 RGB 值和 alpha位。
Definition: Video.h:481
platform::IndexSpace::AXYZMapping::A
Definition: Video.h:87
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:157
platform::AXYZValueTraits
Definition: Video.h:132
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
platform::IndexSpace::AZYXMapping::B
Definition: Video.h:103
YSLib::i
return i
Definition: YCoreUtilities.h:176
YF_API
#define YF_API
Definition: Platform.h:56
YModules.h
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
platform::IndexSpace::AXYZIndex::Y
Definition: Video.h:74
platform::Color
颜色。
Definition: Video.h:416
platform::BGRA
(packed) YB_ATTR(aligned(yalignof(typename _tTraits PixelQuadruple< XYZATraits< _vB, _vG, _vR, _vA >, AXYZMapping::ABGR, _vB, _vG, _vR, _vA > BGRA
像素四元组。
Definition: Video.h:230
YSLib::Consoles::Green
Definition: YConsole.h:63
ColorSpace
std
Definition: memory.hpp:1183
YSLib::Consoles::Yellow
Definition: YConsole.h:67
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
platform::AXYZValueTraits::ABitsN
static yconstexpr const size_t ABitsN
Definition: Video.h:139
YSLib::Consoles::Black
Definition: YConsole.h:53
platform::IndexSpace::AZYXMapping::G
Definition: Video.h:104
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:206
ystdex::ordered_bitseg_traits
按索引有序映射的特征适配模板。
Definition: bitseg.hpp:126
platform::IndexSpace::AXYZIndex::A
Definition: Video.h:72
platform::IndexSpace::AXYZMapping::R
Definition: Video.h:90
YSLib::IO::int
YF_API int
Definition: File.h:51
platform::IndexSpace::AXYZMapping::G
Definition: Video.h:89
YSLib::Consoles::Gray
Definition: YConsole.h:60
ystdex::octet
void octet
Definition: ydef.h:844
platform::Color::Color
yconstfn Color(Pixel px) ynothrow
构造：使用本机颜色对象。
Definition: Video.h:445
platform::InitVideo
YF_API bool InitVideo()
初始化视频输出。
Definition: Video.cpp:43
YSLib::Consoles::White
Definition: YConsole.h:68
platform::IndexSpace::AXYZMapping::B
Definition: Video.h:88
platform::ynothrow
const _tString &path ynothrow
Definition: YCLib/FileSystem.h:274