YSTest: Video.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Video.h
浏览该文件的文档.
1 /*
2 © 2011-2015, 2018-2019 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 greater 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 {
186 using traits_type = _tTraits;
187 using StorageTraits = typename traits_type::base;
188 using ArrayType = typename StorageTraits::array;
189 using IntegerType = typename traits_type::integer;
191 template<size_t _vIdx>
192 using StoredComponentType
193 = typename StorageTraits::template component_t<_vIdx>;
195 using CMap = _tComponentMap;
196 using AType = typename traits_type::template component_t<CMap::A>;
197 using BType = typename traits_type::template component_t<CMap::B>;
198 using GType = typename traits_type::template component_t<CMap::G>;
199 using RType = typename traits_type::template component_t<CMap::R>;
201
202 using AWidth = typename traits_type::template component_width<CMap::A>;
203 using BWidth = typename traits_type::template component_width<CMap::B>;
204 using GWidth = typename traits_type::template component_width<CMap::G>;
205 using RWidth = typename traits_type::template component_width<CMap::R>;
207
208 ArrayType Bytes;
209 IntegerType Integer;
210
211 DefDeCtor(PixelQuadruple)
212 yconstfn
213 PixelQuadruple(IntegerType i) ynothrow
214 : Integer(i)
215 {}
216 yconstfn
217 PixelQuadruple(StoredComponentType<0> v0, StoredComponentType<1> v1,
218 StoredComponentType<2> v2, StoredComponentType<3> v3) ynothrow
219 : Integer(StorageTraits::pack(v0, v1, v2, v3))
220 {}
221
222 yconstfn DefCvt(const ynothrow, IntegerType, Integer)
223
224 yconstfn DefGetter(const ynothrow, AType, A,
225 traits_type::template extract<CMap::A>(Integer))
226 yconstfn DefGetter(const ynothrow, BType, B,
227 traits_type::template extract<CMap::B>(Integer))
228 yconstfn DefGetter(const ynothrow, GType, G,
229 traits_type::template extract<CMap::G>(Integer))
230 yconstfn DefGetter(const ynothrow, RType, R,
231 traits_type::template extract<CMap::R>(Integer))
233 };
234
235
236 template<size_t _vB, size_t _vG, size_t _vR, size_t _vA>
237 using BGRA = PixelQuadruple<XYZATraits<_vB, _vG, _vR, _vA>, AXYZMapping::ABGR,
238 _vB, _vG, _vR, _vA>;
239
240
241 template<size_t _vR, size_t _vG, size_t _vB, size_t _vA>
242 using RGBA = PixelQuadruple<XYZATraits<_vR, _vG, _vB, _vA>, AZYXMapping::ABGR,
243 _vR, _vG, _vB, _vA>;
244
245
246 template<size_t _vA, size_t _vR, size_t _vG, size_t _vB>
247 using ARGB = PixelQuadruple<AXYZTraits<_vA, _vR, _vG, _vB>, AZYXMapping::ABGR,
248 _vA, _vR, _vG, _vB>;
249
250
251 template<size_t _vA, size_t _vB, size_t _vG, size_t _vR>
252 using ABGR = PixelQuadruple<AXYZTraits<_vA, _vB, _vG, _vR>, AXYZMapping::ABGR,
253 _vA, _vB, _vG, _vR>;
255
256
257
258 #if YCL_DS
259
264 # define YCL_PIXEL_FORMAT_XYZ555 0xAABBCCDD
265
271 using Pixel = RGBA<5, 5, 5, 1>;
272
273 #elif YCL_Win32 || YCL_Android || YCL_Linux || YCL_OS_X
274 // TODO: Real implementation for X11.
275 # if YCL_Win32
276
281 # define YCL_PIXEL_FORMAT_XYZ888 0xAADDCCBB
282
293 using Pixel = BGRA<8, 8, 8, 8>;
294 # else
295
300 # define YCL_PIXEL_FORMAT_XYZ888 0xAABBCCDD
301
307 using Pixel = RGBA<8, 8, 8, 8>;
308 # endif
309 #else
310 # error "Unsupported platform found."
311 #endif
312
313
320 YF_API void
321 InitVideo() yimpl(ynothrow);
322
323 } // namespace platform;
324
325 #endif
326
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:157
platform::InitVideo
YF_API void InitVideo() yimpl(ynothrow)
初始化视频输出。
Definition: Video.cpp:45
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
yalignof
#define yalignof(_type)
指定特定类型的对齐。
Definition: ydef.h:1053
YSLib::IO::_tTraits
const string &path const String &path class class _tTraits
Definition: YSLib/Service/FileSystem.h:582
YF_API
#define YF_API
Definition: Platform.h:56
platform::RGBA
PixelQuadruple< XYZATraits< _vR, _vG, _vB, _vA >, AZYXMapping::ABGR, _vR, _vG, _vB, _vA > RGBA
Definition: Video.h:243
platform::IndexSpace::AXYZMapping::R
@ R
Definition: Video.h:90
platform::IndexSpace::AXYZMapping::G
@ G
Definition: Video.h:89
ystdex::nodep::ordered_bitseg_traits
按索引有序映射的特征适配模板。
Definition: bitseg.hpp:134
ystdex::integer_width
取指定整数类型的位宽度。
Definition: cstdint.hpp:104
platform::IndexSpace::AXYZIndex::X
@ X
Definition: Video.h:73
platform::IndexSpace::AXYZMapping::A
@ A
Definition: Video.h:87
ystdex::nodep::ordered_bitseg_traits::component_width
typename base::template component_width< map< _vIdx >::value > component_width
Definition: bitseg.hpp:152
platform::AXYZValueTraits::XYZBitsN
static yconstexpr const size_t XYZBitsN
Definition: Video.h:141
platform::IndexSpace::AXYZIndex::Z
@ Z
Definition: Video.h:75
bitseg.hpp
位段数据结构和访问。
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:238
platform::ynothrow
const _tString &path ynothrow
Definition: YCLib/FileSystem.h:453
platform::IndexSpace::AXYZMapping::ABGR
ABGR
Definition: Video.h:86
platform::IndexSpace::AZYXMapping::R
@ R
Definition: Video.h:105
YB_ATTR
#define YB_ATTR(...)
GNU 风格属性。
Definition: ydef.h:567
YSLib::i
return i
Definition: YCoreUtilities.h:177
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
platform::ARGB
PixelQuadruple< AXYZTraits< _vA, _vR, _vG, _vB >, AZYXMapping::ABGR, _vA, _vR, _vG, _vB > ARGB
Definition: Video.h:248
platform
默认平台命名空间。
Definition: Container.h:56
platform::IndexSpace::AZYXMapping::G
@ G
Definition: Video.h:104
platform::ABGR
PixelQuadruple< AXYZTraits< _vA, _vB, _vG, _vR >, AXYZMapping::ABGR, _vA, _vB, _vG, _vR > ABGR
Definition: Video.h:253
YModules.h
YSLib 用户界面模块配置文件。
platform::IndexSpace::AZYXMapping::ABGR
ABGR
Definition: Video.h:101
platform::IndexSpace::AXYZIndex::AXYZ
AXYZ
Definition: Video.h:71
platform::IndexSpace::AXYZIndex::A
@ A
Definition: Video.h:72
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:206
platform::IndexSpace::AXYZMapping::B
@ B
Definition: Video.h:88
platform::AXYZValueTraits::ABitsN
static yconstexpr const size_t ABitsN
Definition: Video.h:139
platform::IndexSpace::AZYXMapping::A
@ A
Definition: Video.h:102
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
platform::AXYZValueTraits
逻辑分量值特征。
Definition: Video.h:134
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
platform::IndexSpace::AXYZIndex::Y
@ Y
Definition: Video.h:74
platform::IndexSpace::AZYXMapping::B
@ B
Definition: Video.h:103
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073