JSON-based controller descriptions
[lsnes.git] / src / library / pixfmt-rgb16.cpp
blob31aca65caf63bd2cf19989bff5e24ac36aefe4ef
1 #include "pixfmt-rgb16.hpp"
3 template<bool uvswap>
4 pixel_format_rgb16<uvswap>::~pixel_format_rgb16() throw()
8 template<bool uvswap>
9 void pixel_format_rgb16<uvswap>::decode(uint8_t* target, const uint8_t* src, size_t width) throw()
11 const uint16_t* _src = reinterpret_cast<const uint16_t*>(src);
12 for(size_t i = 0; i < width; i++) {
13 uint32_t word = _src[i];
14 uint64_t r = ((word >> (uvswap ? 11 : 0)) & 0x1F);
15 uint64_t g = ((word >> 5) & 0x3F);
16 uint64_t b = ((word >> (uvswap ? 0 : 11)) & 0x1F);
17 target[3 * i + 0] = ((r << 8) - r + 15) / 31;
18 target[3 * i + 1] = ((g << 8) - g + 31) / 63;
19 target[3 * i + 2] = ((b << 8) - b + 15) / 31;
23 template<bool uvswap>
24 void pixel_format_rgb16<uvswap>::decode(uint32_t* target, const uint8_t* src, size_t width,
25 const pixel_format_aux_palette<false>& auxp) throw()
27 const uint16_t* _src = reinterpret_cast<const uint16_t*>(src);
28 for(size_t i = 0; i < width; i++)
29 target[i] = auxp.pcache[_src[i]];
32 template<bool uvswap>
33 void pixel_format_rgb16<uvswap>::decode(uint64_t* target, const uint8_t* src, size_t width,
34 const pixel_format_aux_palette<true>& auxp) throw()
36 const uint16_t* _src = reinterpret_cast<const uint16_t*>(src);
37 for(size_t i = 0; i < width; i++)
38 target[i] = auxp.pcache[_src[i]];
41 template<bool uvswap>
42 void pixel_format_rgb16<uvswap>::set_palette(pixel_format_aux_palette<false>& auxp, uint8_t rshift, uint8_t gshift,
43 uint8_t bshift) throw(std::bad_alloc)
45 auxp.pcache.resize(0x10000);
46 for(size_t i = 0; i < 0x10000; i++) {
47 uint32_t r = ((i >> (uvswap ? 11 : 0)) & 0x1F);
48 uint32_t g = ((i >> 5) & 0x3F);
49 uint32_t b = ((i >> (uvswap ? 0 : 11)) & 0x1F);
50 auxp.pcache[i] = (((r << 8) - r + 15) / 31) << rshift;
51 auxp.pcache[i] += (((g << 8) - g + 31) / 63) << gshift;
52 auxp.pcache[i] += (((b << 8) - b + 15) / 31) << bshift;
54 auxp.rshift = rshift;
55 auxp.gshift = gshift;
56 auxp.bshift = bshift;
59 template<bool uvswap>
60 void pixel_format_rgb16<uvswap>::set_palette(pixel_format_aux_palette<true>& auxp, uint8_t rshift, uint8_t gshift,
61 uint8_t bshift) throw(std::bad_alloc)
63 auxp.pcache.resize(0x10000);
64 for(size_t i = 0; i < 0x10000; i++) {
65 uint64_t r = ((i >> (uvswap ? 11 : 0)) & 0x1F);
66 uint64_t g = ((i >> 5) & 0x3F);
67 uint64_t b = ((i >> (uvswap ? 0 : 11)) & 0x1F);
68 auxp.pcache[i] = (((r << 16) - r + 15) / 31) << rshift;
69 auxp.pcache[i] += (((g << 16) - g + 31) / 63) << gshift;
70 auxp.pcache[i] += (((b << 16) - b + 15) / 31) << bshift;
72 auxp.rshift = rshift;
73 auxp.gshift = gshift;
74 auxp.bshift = bshift;
77 template<bool uvswap>
78 uint8_t pixel_format_rgb16<uvswap>::get_bpp() throw()
80 return 2;
83 template<bool uvswap>
84 uint8_t pixel_format_rgb16<uvswap>::get_ss_bpp() throw()
86 return 2;
89 template<bool uvswap>
90 uint32_t pixel_format_rgb16<uvswap>::get_magic() throw()
92 if(uvswap)
93 return 0x74234643;
94 else
95 return 0x32642474;
98 pixel_format_rgb16<false> _pixel_format_rgb16;
99 pixel_format_rgb16<true> _pixel_format_bgr16;