2 //c++ -g -I../guicast testwindow.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>
15 #include "bcsignals.h"
21 class TestWindowGUI : public BC_Window
25 TestWindowGUI(int x, int y, int w, int h);
30 class TestWindow : public Thread
34 TestWindow(int x, int y, int w, int h)
36 gui = new TestWindowGUI(x,y,w,h);
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(),
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(); }
53 TestWindowGUI(int x, int y, int w, int h)
54 : BC_Window("test", x,y, w,h, 100,100)
57 clear_box(0,0,get_w(),get_h());
67 void TestWindow::show_text(int tx, int ty, const char *fmt, ...)
72 vsprintf(text, fmt, ap);
74 gui->set_color(0xc080f0);
75 gui->draw_text(tx,ty, text);
79 const char *cmdl[] = {
80 "transparency", "compressed", "rgb8", "rgb565", "bgr565", "bgr888", "bgr8888", "yuv420p",
81 "none", "rgb888", "rgba8888", "rgb161616", "rgba16161616", "yuv888", "yuva8888", "yuv161616",
82 "yuva16161616", "yuv422p", "yuv411p", "yuv422", "argb8888", "abgr8888", "a8", "a16",
83 "yuv101010", "vyu888", "uyva8888", "yuv444p", "yuv410p", "rgb_float", "rgba_float", "a_float",
87 void write_pbm(uint8_t *tp, int w, int h, const char *fmt, ...)
89 va_list ap; va_start(ap, fmt);
90 char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap);
92 FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
94 fprintf(fp,"P5\n%d %d\n255\n",w,h);
100 void write_pgm(uint8_t *tp, int w, int h, const char *fmt, ...)
102 va_list ap; va_start(ap, fmt);
103 char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap);
105 FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
107 fprintf(fp,"P6\n%d %d\n255\n",w,h);
113 int main(int ac, char **av)
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 VFrame ifrm(dat, st.st_size);
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<=32; ++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_pgm(cfrm.get_data(), w,h, "/tmp/test/xfer_%s_to_%s.pgm",
145 cmdl[fr_cmdl],cmdl[to_cmdl]);
149 test_window.close_window();