3 * Copyright (C) 2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 //c++ -g -I../guicast test5.C ../guicast/x86_64/libguicast.a \
27 // -DHAVE_GL -DHAVE_XFT -I/usr/include/freetype2 -lGL -lX11 -lXext \
28 // -lXinerama -lXv -lpng -lfontconfig -lfreetype -lXft -pthread
30 int main(int ac, char **av)
32 int rgb2yuv = atoi(av[1]);
33 int color = atoi(av[2]);
34 int range = atoi(av[3]);
36 YUV::yuv.yuv_set_colors(color, range);
38 for( int y=0; y<0x100; ++y ) {
39 for( int u=0; u<0x100; ++u ) {
40 for( int v=0; v<0x100; ++v ) {
41 float fy = y/255.f, fu = u/255.f - 0.5f, fv = v/255.f - 0.5f;
42 float fr, fg, fb; YUV::yuv.yuv_to_rgb_f(fr,fg,fb, fy,fu,fv);
43 if( fr<0 || fr>1 || fg<0 || fg>1 || fb<0 || fb>1 )
45 float yy, uu, vv; YUV::yuv.rgb_to_yuv_f(fr,fg,fb, yy,uu,vv);
46 float d = fabsf(fy-yy) + fabsf(fu-uu) + fabsf(fv-vv);
47 int rr = fr*256, gg = fg*256, bb = fb*256;
48 CLAMP(rr,0,255); CLAMP(gg,0,255); CLAMP(bb,0,255);
49 printf("yuv 0x%02x 0x%02x 0x%02x =%f,%f,%f, "
50 "rgb 0x%02x 0x%02x 0x%02x =%f,%f,%f, "
52 y,u,v, fy,fu,fv, rr,gg,bb, fr,fg,fb, yy,uu,vv, d);
58 for( int r=0; r<0x100; ++r ) {
59 for( int g=0; g<0x100; ++g ) {
60 for( int b=0; b<0x100; ++b ) {
61 float fr = r/255.f, fg = g/255.f, fb = b/255.f;
62 float fy, fu, fv; YUV::yuv.rgb_to_yuv_f(fr,fg,fb, fy,fu,fv);
63 if( fy<0 || fy>1 || fu<0 || fu>1 || fv<0 || fv>1 )
65 float rr, gg, bb; YUV::yuv.yuv_to_rgb_f(rr,gg,bb, fy,fu,fv);
66 float d = fabsf(fr-rr) + fabsf(fg-gg) + fabsf(fb-bb);
67 int yy = fy*256, uu = fu*256, vv = fv*256;
68 CLAMP(yy,0,255); CLAMP(uu,0,255); CLAMP(vv,0,255);
69 printf("rgb 0x%02x 0x%02x 0x%02x =%f,%f,%f, "
70 "yuv 0x%02x 0x%02x 0x%02x =%f,%f,%f, "
72 r,g,b, fr,fg,fb, yy,uu,vv, fy,fu,fv, rr,gg,bb, d);