Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename PixelType>
- struct waveshare5in65f_palette {
- private:
- constexpr static gfx::gfx_result index_to_mapped(int idx,PixelType* result) {
- switch(idx) {
- case 0:
- return gfx::convert(gfx::rgb_pixel<16>(0,0,0),result);
- case 1:
- return gfx::convert(gfx::rgb_pixel<16>(31,63,31),result);
- case 2:
- return gfx::convert(gfx::rgb_pixel<16>(0,63,0),result);
- case 3:
- return gfx::convert(gfx::rgb_pixel<16>(0,0,31),result);
- case 4:
- return gfx::convert(gfx::rgb_pixel<16>(31,0,0),result);
- case 5:
- return gfx::convert(gfx::rgb_pixel<16>(31,63,0),result);
- default: //case 6:
- return gfx::convert(gfx::rgb_pixel<16>(31,31,0),result);
- }
- }
- public:
- using type = waveshare5in65f_palette;
- using pixel_type = gfx::pixel<gfx::channel_traits<gfx::channel_name::index,4,0,6>>;
- using mapped_pixel_type = PixelType;
- constexpr static const bool writable = false;
- constexpr static const size_t size = 7;
- gfx::gfx_result map(pixel_type pixel,mapped_pixel_type* mapped_pixel) const {
- return index_to_mapped(pixel.channel<gfx::channel_name::index>(),mapped_pixel);
- }
- gfx::gfx_result nearest(mapped_pixel_type mapped_pixel,pixel_type* pixel) const {
- if(nullptr==pixel) {
- return gfx::gfx_result::invalid_argument;
- }
- mapped_pixel_type mpx;
- gfx::gfx_result r = index_to_mapped(0,&mpx);
- if(gfx::gfx_result::success!=r) {
- return r;
- }
- double least = mpx.difference(mapped_pixel);
- if(0.0==least) {
- pixel->native_value = 0;
- return gfx::gfx_result::success;
- }
- int ii=0;
- for(int i = 1;i<size;++i) {
- r=index_to_mapped(i,&mpx);
- if(gfx::gfx_result::success!=r) {
- return r;
- }
- double cmp = mpx.difference(mapped_pixel);
- if(0.0==cmp) {
- ii=i;
- least = 0.0;
- break;
- }
- if(cmp<least) {
- least = cmp;
- ii=i;
- }
- }
- pixel->channel<gfx::channel_name::index>(ii);
- return gfx::gfx_result::success;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement