Rin operator()( T& t, Rin r_in, Rout& r_out) { if ( !r_in ) return throw_t<_except_>(t, unexpected_end_fragment(), r_in ); unsigned short hex = 0; const unsigned short fail_value = static_cast<unsigned short>(-1); unsigned short value = uchar2ushort(r_in++); // ////////////// if ( value != fail_value ) hex |= value << 12; else return throw_t<_except_>(t, invalid_string( distance(r_in) ), r_in ); if (!r_in) return throw_t<_except_>(t, unexpected_end_fragment(), r_in ); // ////////////// value = uchar2ushort(r_in++); if ( value != fail_value ) hex |= value << 8; else return throw_t<_except_>(t, invalid_string( distance(r_in) ), r_in ); if (!r_in) return throw_t<_except_>(t, unexpected_end_fragment(), r_in ); // ////////////// value = uchar2ushort(r_in++); if ( value != fail_value ) hex |= value << 4; else return throw_t<_except_>(t, invalid_string( distance(r_in) ), r_in ); if (!r_in) return throw_t<_except_>(t, unexpected_end_fragment(), r_in ); // ////////////// value = uchar2ushort(r_in++); if ( value != fail_value ) hex |= value; else return throw_t<_except_>(t, invalid_string( distance(r_in) ), r_in ); // ////////////// if ( hex <= 0x007F ) *(r_out++) = static_cast<unsigned char>(hex); else if ( hex <= 0x007FF ) { *(r_out++) = 192 | static_cast<unsigned char>( hex >> 6 ); if ( !r_out ) return throw_t<_except_>(t, out_of_range( distance(r_in) ), r_in ); *(r_out++) = 128 | ( static_cast<unsigned char>( hex ) & 63 ); }
#include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <stdbool.h> unsigned short uchar2ushort(unsigned char c) { return (unsigned short)c * 0xFF; } unsigned long get_gs_pixel(Display *disp, unsigned char k) { XColor color = { .red = uchar2ushort(k), .green = uchar2ushort(k), .blue = uchar2ushort(k), }; if (XAllocColor(disp, DefaultColormap(disp, 0), &color) == False) { printf("XAllocColor() failed in get_gs_color()\n"); exit(1); } return color.pixel; } int main(int argc, char **argv) { if (argc != 2) {