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
11 #include <sys/types.h>
14 #include "bcwindowbase.h"
16 #include "bcsignals.h"
22 class TestWindowGUI : public BC_Window
26 TestWindowGUI(int x, int y, int w, int h);
31 class TestWindow : public Thread
35 TestWindow(int x, int y, int w, int h)
37 gui = new TestWindowGUI(x,y,w,h);
40 void draw(VFrame *vframe) {
41 gui->draw_vframe(vframe,
42 0,0,gui->get_w(),gui->get_h(),
43 0,0,vframe->get_w(),vframe->get_h(),
47 void show_text(int tx, int ty, const char *fmt, ...);
48 void close_window() { gui->close(0); }
49 ~TestWindow() { delete gui; }
50 void run() { gui->run_window(); }
54 TestWindowGUI(int x, int y, int w, int h)
55 : BC_Window("test", x,y, w,h, 100,100)
58 clear_box(0,0,get_w(),get_h());
68 void TestWindow::show_text(int tx, int ty, const char *fmt, ...)
73 vsprintf(text, fmt, ap);
75 gui->set_color(0xc080f0);
76 gui->draw_text(tx,ty, text);
80 const char *cmdl[] = {
81 "transparency", "compressed", "rgb8", "rgb565", "bgr565", "bgr888", "bgr8888", "yuv420p",
82 "yuv422p", "rgb888", "rgba8888", "rgb161616", "rgba16161616", "yuv888", "yuva8888", "yuv161616",
83 "yuva16161616", "yuv411p", "uvy422", "yuv422", "argb8888", "abgr8888", "a8", "a16",
84 "yuv101010", "vyu888", "uyva8888", "yuv444p", "yuv410p", "rgb_float", "rgba_float", "a_float",
85 "rgb_floatp", "rgba_floatp", "yuv420pi", "ayuv16161616", "grey8", "grey16",
88 void write_pgm(uint8_t *tp, int w, int h, const char *fmt, ...)
90 va_list ap; va_start(ap, fmt);
91 char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap);
93 FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
95 fprintf(fp,"P5\n%d %d\n255\n",w,h);
101 void write_ppm(uint8_t *tp, int w, int h, const char *fmt, ...)
103 va_list ap; va_start(ap, fmt);
104 char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap);
106 FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
108 fprintf(fp,"P6\n%d %d\n255\n",w,h);
114 int main(int ac, char **av)
117 signals.initialize();
118 int fd = open("test.png",O_RDONLY);
119 if( fd < 0 ) exit(1);
120 struct stat st; fstat(fd,&st);
121 unsigned char *dat = new unsigned char[st.st_size];
122 read(fd, dat, st.st_size);
123 VFramePng ifrm(dat, st.st_size);
126 int w = ifrm.get_w(), h = ifrm.get_h();
127 TestWindow test_window(100, 100, w, h);
128 for( int fr_cmdl=1; fr_cmdl<=37; ++fr_cmdl ) {
129 if( fr_cmdl == BC_TRANSPARENCY || fr_cmdl == BC_COMPRESSED ) continue;
130 if( fr_cmdl == BC_A8 || fr_cmdl == BC_A16 ) continue;
131 if( fr_cmdl == BC_A_FLOAT || fr_cmdl == 8 ) continue;
132 VFrame afrm(w, h, fr_cmdl, -1);
133 afrm.transfer_from(&ifrm, 0);
134 for( int to_cmdl=1; to_cmdl<=37; ++to_cmdl ) {
135 if( to_cmdl == BC_TRANSPARENCY || to_cmdl == BC_COMPRESSED ) continue;
136 if( to_cmdl == BC_A8 || to_cmdl == BC_A16 ) continue;
137 if( to_cmdl == BC_A_FLOAT || to_cmdl == 8 ) continue;
138 printf("xfer_%s_to_%s\n", cmdl[fr_cmdl],cmdl[to_cmdl]);
139 VFrame bfrm(w, h, to_cmdl, -1);
140 bfrm.transfer_from(&afrm, 0);
141 test_window.draw(&bfrm);
142 VFrame cfrm(w, h, BC_RGB888, -1);
143 cfrm.transfer_from(&bfrm, 0);
144 printf("xfer_%s_to_%s\n",cmdl[fr_cmdl],cmdl[to_cmdl]);
145 test_window.show_text(50,50, "xfer_%s_to_%s",cmdl[fr_cmdl],cmdl[to_cmdl]);
146 // write_ppm(cfrm.get_data(), w,h, "/tmp/test/xfer_%s_to_%s.pgm",
147 // cmdl[fr_cmdl],cmdl[to_cmdl]);
151 test_window.close_window();