Clean up library includes
[lsnes.git] / src / library / pixfmt-rgb15.cpp
blob6f51d3a3c2c9f435041a4b4f57242e9baec5ccf5
1 #include "pixfmt-rgb15.hpp"
3 template<bool uvswap>
4 pixel_format_rgb15<uvswap>::~pixel_format_rgb15() throw()
8 template<bool uvswap>
9 void pixel_format_rgb15<uvswap>::decode(uint8_t* target, const uint8_t* src, size_t width)
10 throw()
12 const uint16_t* _src = reinterpret_cast<const uint16_t*>(src);
13 for(size_t i = 0; i < width; i++) {
14 uint32_t word = _src[i];
15 uint64_t r = ((word >> (uvswap ? 10 : 0)) & 0x1F);
16 uint64_t g = ((word >> 5) & 0x1F);
17 uint64_t b = ((word >> (uvswap ? 0 : 10)) & 0x1F);
18 target[3 * i + 0] = ((r << 8) - r + 15) / 31;
19 target[3 * i + 1] = ((g << 8) - g + 15) / 31;
20 target[3 * i + 2] = ((b << 8) - b + 15) / 31;
24 template<bool uvswap>
25 void pixel_format_rgb15<uvswap>::decode(uint32_t* target, const uint8_t* src, size_t width,
26 const pixel_format_aux_palette<false>& auxp) throw()
28 const uint16_t* _src = reinterpret_cast<const uint16_t*>(src);
29 for(size_t i = 0; i < width; i++)
30 target[i] = auxp.pcache[_src[i] & 0x7FFF];
33 template<bool uvswap>
34 void pixel_format_rgb15<uvswap>::decode(uint64_t* target, const uint8_t* src, size_t width,
35 const pixel_format_aux_palette<true>& auxp) throw()
37 const uint16_t* _src = reinterpret_cast<const uint16_t*>(src);
38 for(size_t i = 0; i < width; i++)
39 target[i] = auxp.pcache[_src[i] & 0x7FFF];
42 template<bool uvswap>
43 void pixel_format_rgb15<uvswap>::set_palette(pixel_format_aux_palette<false>& auxp, uint8_t rshift, uint8_t gshift,
44 uint8_t bshift) throw(std::bad_alloc)
46 auxp.pcache.resize(0x8000);
47 for(size_t i = 0; i < 0x8000; i++) {
48 uint32_t r = ((i >> (uvswap ? 10 : 0)) & 0x1F);
49 uint32_t g = ((i >> 5) & 0x1F);
50 uint32_t b = ((i >> (uvswap ? 0 : 10)) & 0x1F);
51 auxp.pcache[i] = (((r << 8) - r + 15) / 31) << rshift;
52 auxp.pcache[i] += (((g << 8) - g + 15) / 31) << gshift;
53 auxp.pcache[i] += (((b << 8) - b + 15) / 31) << bshift;
55 auxp.rshift = rshift;
56 auxp.gshift = gshift;
57 auxp.bshift = bshift;
60 template<bool uvswap>
61 void pixel_format_rgb15<uvswap>::set_palette(pixel_format_aux_palette<true>& auxp, uint8_t rshift, uint8_t gshift,
62 uint8_t bshift) throw(std::bad_alloc)
64 auxp.pcache.resize(0x8000);
65 for(size_t i = 0; i < 0x8000; i++) {
66 uint64_t r = ((i >> (uvswap ? 10 : 0)) & 0x1F);
67 uint64_t g = ((i >> 5) & 0x1F);
68 uint64_t b = ((i >> (uvswap ? 0 : 10)) & 0x1F);
69 auxp.pcache[i] = (((r << 16) - r + 15) / 31) << rshift;
70 auxp.pcache[i] += (((g << 16) - g + 15) / 31) << gshift;
71 auxp.pcache[i] += (((b << 16) - b + 15) / 31) << bshift;
73 auxp.rshift = rshift;
74 auxp.gshift = gshift;
75 auxp.bshift = bshift;
78 template<bool uvswap>
79 uint8_t pixel_format_rgb15<uvswap>::get_bpp() throw()
81 return 2;
84 template<bool uvswap>
85 uint8_t pixel_format_rgb15<uvswap>::get_ss_bpp() throw()
87 return 2;
90 template<bool uvswap>
91 uint32_t pixel_format_rgb15<uvswap>::get_magic() throw()
93 if(uvswap)
94 return 0x16326322;
95 else
96 return 0x74324563;
99 pixel_format_rgb15<false> _pixel_format_rgb15;
100 pixel_format_rgb15<true> _pixel_format_bgr15;