YSTest: Video.h 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
Video.h
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2012 - 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 #ifndef YCL_INC_VIDEO_H_
29 #define YCL_INC_VIDEO_H_ 1
30
31 #include "ycommon.h"
32
33 namespace platform
34 {
35
36 typedef std::int16_t SPos;
37 typedef std::uint16_t SDst;
38
39 #if YCL_DS
40
44 # define YCL_PIXEL_FORMAT_AXYZ1555
45
50 typedef std::uint16_t PixelType;
55 yconstfn std::uint8_t
56 FetchAlpha(PixelType px)
57 {
58 return px & 1 << 15 ? 0xFF : 0;
59 }
60
65 yconstfn PixelType
66 FetchOpaque(PixelType px)
67 {
68 return px | 1 << 15;
69 }
70
71 /*
72 \brief 使用 8 位 RGB 构造本机类型像素。
73 \since build 313
74 */
75 yconstfn PixelType
76 FetchPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b)
77 {
78 return r >> 3 | std::uint16_t(g >> 3) << 5 | std::uint16_t(b >> 3) << 10;
79 }
80
81 # define DefColorH_(hex, name) name = \
82 (FetchPixel(((hex) >> 16) & 0xFF, ((hex) >> 8) & 0xFF, (hex) & 0xFF) \
83 | 1 << 15)
84 #elif YCL_MINGW32
85
93 typedef struct
94 {
95 std::uint8_t rgbBlue;
96 std::uint8_t rgbGreen;
97 std::uint8_t rgbRed;
98 std::uint8_t rgbReserved;
99 } PixelType;
100
105 yconstfn std::uint8_t
106 FetchAlpha(PixelType px)
107 {
108 return px.rgbReserved;
109 }
110
115 yconstfn PixelType
116 FetchOpaque(PixelType px)
117 {
118 return {px.rgbBlue, px.rgbGreen, px.rgbRed, 0xFF};
119 }
120
121 /*
122 \brief 使用 8 位 RGB 构造 std::uint32_t 像素。
123 \since build 313
124 */
125 yconstfn std::uint32_t
126 FetchPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b)
127 {
128 return r | g << 8 | std::uint32_t(b) << 16;
129 }
130
137 # define DefColorH_(hex, name) name = (FetchPixel((((hex) >> 16) & 0xFF), \
138 (((hex) >> 8) & 0xFF), ((hex) & 0xFF)) << 8 | 0xFF)
139 #else
140 # error Unsupported platform found!
141 #endif
142
143 typedef PixelType* BitmapPtr;
144 typedef const PixelType* ConstBitmapPtr;
145
146
148 namespace ColorSpace
149 {
150 // #define DefColorA(r, g, b, name) name = ARGB16(1, r, g, b),
151 #define HexAdd0x(hex) 0x##hex
152 #define DefColorH(hex_, name) DefColorH_(HexAdd0x(hex_), name)
153
158 #if YCL_DS
159 typedef enum : PixelType
160 #else
161 typedef enum : std::uint32_t
162 #endif
163 {
164 DefColorH(00FFFF, Aqua),
165 DefColorH(000000, Black),
166 DefColorH(0000FF, Blue),
167 DefColorH(FF00FF, Fuchsia),
168 DefColorH(808080, Gray),
169 DefColorH(008000, Green),
170 DefColorH(00FF00, Lime),
171 DefColorH(800000, Maroon),
172 DefColorH(000080, Navy),
173 DefColorH(808000, Olive),
174 DefColorH(800080, Purple),
175 DefColorH(FF0000, Red),
176 DefColorH(C0C0C0, Silver),
177 DefColorH(008080, Teal),
178 DefColorH(FFFFFF, White),
179 DefColorH(FFFF00, Yellow)
180 } ColorSet;
181
182 #undef DefColorH
183 #undef DefColorH_
184 #undef HexAdd0x
185 } // namespace ColorSpace;
186
187
189 class YF_API Color
190 {
191 public:
192 typedef ColorSpace::ColorSet ColorSet;
193 typedef std::uint8_t MonoType;
194 typedef std::uint8_t AlphaType;
195
196 private:
201 MonoType r, g, b;
206 AlphaType a;
207
208 public:
213 yconstfn
214 Color() ynothrow
215 : r(0), g(0), b(0), a(0)
216 {}
221 yconstfn
222 Color(PixelType px) ynothrow
223 #if YCL_DS
224 : r(px << 3 & 248), g(px >> 2 & 248), b(px >> 7 & 248),
225 a(FetchAlpha(px) ? 0xFF : 0x00)
226 #elif YCL_MINGW32
227 : r(px.rgbRed), g(px.rgbGreen), b(px.rgbBlue), a(px.rgbReserved)
228 #else
229 # error Unsupport platform found!
230 #endif
231 {}
232 #if YCL_MINGW32
233
237 yconstfn
238 Color(ColorSet cs) ynothrow
239 : r((cs & 0xFF00) >> 8), g((cs & 0xFF0000) >> 16),
240 b((cs & 0xFF000000) >> 24), a(0xFF)
241 {}
242 #endif
243
247 yconstfn
248 Color(MonoType r_, MonoType g_, MonoType b_, AlphaType a_ = 0xFF) ynothrow
249 : r(r_), g(g_), b(b_), a(a_)
250 {}
256 template<typename _tScalar>
257 yconstfn
258 Color(_tScalar r_, _tScalar g_, _tScalar b_, AlphaType a_ = 0xFF) ynothrow
259 : Color(MonoType(r_), MonoType(g_), MonoType(b_), a_)
260 {}
261
266 yconstfn
267 operator PixelType() const ynothrow
268 {
269 #if YCL_DS
270 return int(a != 0) << 15 | FetchPixel(r, g, b);
271 #elif YCL_MINGW32
272 return {b, g, r, a};
273 #else
274 # error Unsupport platform found!
275 #endif
276 }
277
282 yconstfn MonoType
283 GetR() const ynothrow
284 {
285 return r;
286 }
291 yconstfn MonoType
292 GetG() const ynothrow
293 {
294 return g;
295 }
300 yconstfn MonoType
301 GetB() const ynothrow
302 {
303 return b;
304 }
309 yconstfn AlphaType
310 GetA() const ynothrow
311 {
312 return a;
313 }
314 };
315
316
321 namespace Consoles
322 {
323
328 typedef enum
329 {
330 Black = 0,
331 DarkBlue,
332 DarkGreen,
333 DarkCyan,
334 DarkRed,
335 DarkMagenta,
336 DarkYellow,
337 Gray,
338 DarkGray,
339 Blue,
340 Green,
341 Cyan,
342 Red,
343 Magenta,
344 Yellow,
345 White
346 } Color;
347
353 yconstexpr platform::Color ConsoleColors[]{ColorSpace::Black, ColorSpace::Navy,
354 ColorSpace::Green, ColorSpace::Teal, ColorSpace::Maroon, ColorSpace::Purple,
355 ColorSpace::Olive, ColorSpace::Silver, ColorSpace::Gray, ColorSpace::Blue,
356 ColorSpace::Lime, ColorSpace::Aqua, ColorSpace::Red, ColorSpace::Yellow,
357 ColorSpace::Fuchsia, ColorSpace::White};
358
359 } // namespace Consoles;
360
365 YF_API void
366 YConsoleInit(std::uint8_t dspIndex,
367 Color fc = ColorSpace::White, Color bc = ColorSpace::Black);
368
369
374 YF_API bool
375 InitVideo();
376
377 } // namespace platform;
378
379
380 namespace platform_ex
381 {
382
383 #if YCL_DS
384
388 YF_API void
389 ResetVideo();
390
391
395 YF_API platform::BitmapPtr
396 InitScrUp(int&);
397
401 YF_API platform::BitmapPtr
402 InitScrDown(int&);
403
409 YF_API void
410 ScreenSynchronize(platform::PixelType*, const platform::PixelType*) ynothrow;
411 #endif
412
413 } // namespace platform_ex;
414
415 #endif
416