Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / test5.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2017-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU 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.
9  *
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  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU 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
18  * USA
19  */
20
21
22 #include <stdio.h>
23 #include <math.h>
24 #include "bccolors.C"
25
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
29
30 int main(int ac, char **av)
31 {
32   int rgb2yuv = atoi(av[1]);
33   int color = atoi(av[2]);
34   int range = atoi(av[3]);
35
36   YUV::yuv.yuv_set_colors(color, range);
37   if( !rgb2yuv ) {
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 )
44                 continue;
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, "
51                  "  %f,%f,%f, %f\n",
52             y,u,v, fy,fu,fv, rr,gg,bb, fr,fg,fb, yy,uu,vv, d);
53         }
54       }
55     }
56   }
57   else {
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 )
64                 continue;
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, "
71                  "  %f,%f,%f, %f\n",
72             r,g,b, fr,fg,fb, yy,uu,vv, fy,fu,fv, rr,gg,bb, d);
73         }
74       }
75     }
76   }
77   return 0;
78 }
79