merged hv7 mod
[goodguy/history.git] / cinelerra-5.1 / guicast / test4.C
1
2 //c++ -g -I../guicast test4.C ../guicast/x86_64/libguicast.a \
3 // -DHAVE_GL -DHAVE_XFT -I/usr/include/freetype2 -lGL -lX11 -lXext \
4 // -lXinerama -lXv -lpng  -lfontconfig -lfreetype -lXft -pthread
5
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13
14 #include "bcwindow.h"
15 #include "bcsignals.h"
16 #include "bccolors.h"
17 #include "fonts.h"
18 #include "thread.h"
19 #include "vframe.h"
20
21 class TestWindowGUI : public BC_Window
22 {
23 public:
24
25         TestWindowGUI(int x, int y, int w, int h);
26         ~TestWindowGUI();
27 };
28
29
30 class TestWindow : public Thread
31 {
32         TestWindowGUI *gui;
33 public:
34         TestWindow(int x, int y, int w, int h)
35          : Thread(1,0,0) {
36                 gui = new TestWindowGUI(x,y,w,h);
37                 start();
38         }
39         void draw(VFrame *vframe) {
40                 gui->draw_vframe(vframe,
41                         0,0,gui->get_w(),gui->get_h(),
42                         0,0,vframe->get_w(),vframe->get_h(),
43                         0);
44                 gui->flash();
45         }
46         void show_text(int tx, int ty, const char *fmt, ...);
47         void close_window() { gui->close(0); }
48         ~TestWindow() { delete gui; }
49         void run() { gui->run_window(); }
50 };
51
52 TestWindowGUI::
53 TestWindowGUI(int x, int y, int w, int h)
54  : BC_Window("test", x,y, w,h, 100,100)
55 {
56         set_bg_color(BLACK);
57         clear_box(0,0,get_w(),get_h());
58         flash();
59         set_font(MEDIUMFONT);
60 }
61
62 TestWindowGUI::
63 ~TestWindowGUI()
64 {
65 }
66
67 void TestWindow::show_text(int tx, int ty, const char *fmt, ...)
68 {
69         char text[1024];
70         va_list ap;
71         va_start(ap, fmt);
72         vsprintf(text, fmt, ap);
73         va_end(ap);
74         gui->set_color(0xc080f0);
75         gui->draw_text(tx,ty, text);
76         gui->flash();
77 }
78
79 const char *cmdl[] = {
80  "transparency", "compressed", "rgb8", "rgb565", "bgr565", "bgr888", "bgr8888", "yuv420p",
81  "yuv422p", "rgb888", "rgba8888", "rgb161616", "rgba16161616", "yuv888", "yuva8888", "yuv161616",
82  "yuva16161616", "yuv411p", "uvy422", "yuv422", "argb8888", "abgr8888", "a8", "a16",
83  "yuv101010", "vyu888", "uyva8888", "yuv444p", "yuv410p", "rgb_float", "rgba_float", "a_float",
84  "rgb_floatp", "rgba_floatp", "yuv420pi",
85 };
86
87 void write_pgm(uint8_t *tp, int w, int h, const char *fmt, ...)
88 {
89   va_list ap;    va_start(ap, fmt);
90   char fn[256];  vsnprintf(fn, sizeof(fn), fmt, ap);
91   va_end(ap);
92   FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
93   if( fp ) {
94     fprintf(fp,"P5\n%d %d\n255\n",w,h);
95     fwrite(tp,w,h,fp);
96     fclose(fp);
97   }
98 }
99
100 void write_ppm(uint8_t *tp, int w, int h, const char *fmt, ...)
101 {
102   va_list ap;    va_start(ap, fmt);
103   char fn[256];  vsnprintf(fn, sizeof(fn), fmt, ap);
104   va_end(ap);
105   FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
106   if( fp ) {
107     fprintf(fp,"P6\n%d %d\n255\n",w,h);
108     fwrite(tp,3*w,h,fp);
109     fclose(fp);
110   }
111 }
112
113 int main(int ac, char **av)
114 {
115         BC_Signals signals;
116         signals.initialize();
117         int fd = open("test.png",O_RDONLY);
118         if( fd < 0 ) exit(1);
119         struct stat st;  fstat(fd,&st);
120         unsigned char *dat = new unsigned char[st.st_size];
121         read(fd, dat, st.st_size);
122         VFramePng ifrm(dat, st.st_size);
123         delete [] dat;
124         close(fd);
125         int w = ifrm.get_w(), h = ifrm.get_h();
126         TestWindow test_window(100, 100, w, h);
127         for( int fr_cmdl=1; fr_cmdl<=34; ++fr_cmdl ) {
128                 if( fr_cmdl == BC_TRANSPARENCY || fr_cmdl == BC_COMPRESSED ) continue;
129                 if( fr_cmdl == BC_A8 || fr_cmdl == BC_A16 ) continue;
130                 if( fr_cmdl == BC_A_FLOAT || fr_cmdl == 8 ) continue;
131                 VFrame afrm(w, h, fr_cmdl, -1);
132                 afrm.transfer_from(&ifrm, 0);
133                 for( int to_cmdl=1; to_cmdl<=32; ++to_cmdl ) {
134                         if( to_cmdl == BC_TRANSPARENCY || to_cmdl == BC_COMPRESSED ) continue;
135                         if( to_cmdl == BC_A8 || to_cmdl == BC_A16 ) continue;
136                         if( to_cmdl == BC_A_FLOAT || to_cmdl == 8 ) continue;
137                         VFrame bfrm(w, h, to_cmdl, -1);
138                         bfrm.transfer_from(&afrm, 0);
139                         test_window.draw(&bfrm);
140                         VFrame cfrm(w, h, BC_RGB888, -1);
141                         cfrm.transfer_from(&bfrm, 0);
142                         printf("xfer_%s_to_%s\n",cmdl[fr_cmdl],cmdl[to_cmdl]);
143                         test_window.show_text(50,50, "xfer_%s_to_%s",cmdl[fr_cmdl],cmdl[to_cmdl]);
144 //                      write_ppm(cfrm.get_data(), w,h, "/tmp/test/xfer_%s_to_%s.pgm",
145 //                              cmdl[fr_cmdl],cmdl[to_cmdl]);
146 //                      usleep(100000);
147                 }
148         }
149         test_window.close_window();
150         test_window.join();
151         return 0;
152 }
153