Upload UI
[lsnes.git] / src / library / pixfmt-rgb24.cpp
blob5ba3e6675be4f7dc066ef408636cfa535462178b
1 #include "pixfmt-rgb24.hpp"
2 #include <cstring>
4 template<bool uvswap>
5 pixel_format_rgb24<uvswap>::~pixel_format_rgb24() throw() {}
7 template<bool uvswap>
8 void pixel_format_rgb24<uvswap>::decode(uint32_t* target, const uint8_t* src, size_t width) throw()
10 if(uvswap) {
11 for(size_t i = 0; i < width; i++) {
12 target[i] = (uint32_t)src[3 * i + 2] << 16;
13 target[i] |= (uint32_t)src[3 * i + 1] << 8;
14 target[i] |= src[3 * i + 0];
16 } else {
17 for(size_t i = 0; i < width; i++) {
18 target[i] = (uint32_t)src[3 * i + 0] << 16;
19 target[i] |= (uint32_t)src[3 * i + 1] << 8;
20 target[i] |= src[3 * i + 2];
25 template<bool uvswap>
26 void pixel_format_rgb24<uvswap>::decode(uint32_t* target, const uint8_t* src, size_t width,
27 const pixel_format_aux_palette<false>& auxp) throw()
29 for(size_t i = 0; i < width; i++) {
30 target[i] = static_cast<uint32_t>(src[3 * i + (uvswap ? 2 : 0)]) << auxp.rshift;
31 target[i] |= static_cast<uint32_t>(src[3 * i + 1]) << auxp.gshift;
32 target[i] |= static_cast<uint32_t>(src[3 * i + (uvswap ? 0 : 2)]) << auxp.bshift;
36 template<bool uvswap>
37 void pixel_format_rgb24<uvswap>::decode(uint64_t* target, const uint8_t* src, size_t width,
38 const pixel_format_aux_palette<true>& auxp) throw()
40 for(size_t i = 0; i < width; i++) {
41 target[i] = static_cast<uint64_t>(src[3 * i + (uvswap ? 2 : 0)]) << auxp.rshift;
42 target[i] |= static_cast<uint64_t>(src[3 * i + 1]) << auxp.gshift;
43 target[i] |= static_cast<uint64_t>(src[3 * i + (uvswap ? 0 : 2)]) << auxp.bshift;
44 target[i] += (target[i] << 8);
48 template<bool uvswap>
49 void pixel_format_rgb24<uvswap>::set_palette(pixel_format_aux_palette<false>& auxp, uint8_t rshift, uint8_t gshift,
50 uint8_t bshift) throw(std::bad_alloc)
52 auxp.rshift = rshift;
53 auxp.gshift = gshift;
54 auxp.bshift = bshift;
55 auxp.pcache.clear();
58 template<bool uvswap>
59 void pixel_format_rgb24<uvswap>::set_palette(pixel_format_aux_palette<true>& auxp, uint8_t rshift, uint8_t gshift,
60 uint8_t bshift) throw(std::bad_alloc)
62 auxp.rshift = rshift;
63 auxp.gshift = gshift;
64 auxp.bshift = bshift;
65 auxp.pcache.clear();
68 template<bool uvswap>
69 uint8_t pixel_format_rgb24<uvswap>::get_bpp() throw()
71 return 3;
74 template<bool uvswap>
75 uint8_t pixel_format_rgb24<uvswap>::get_ss_bpp() throw()
77 return 3;
80 template<bool uvswap>
81 uint32_t pixel_format_rgb24<uvswap>::get_magic() throw()
83 if(uvswap)
84 return 0x25642332U;
85 else
86 return 0x85433684U;
89 pixel_format_rgb24<false> _pixel_format_rgb24;
90 pixel_format_rgb24<true> _pixel_format_bgr24;