3 * Copyright (C) 2015-2020 William Morrow
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.
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.
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
22 //c++ -g -I../guicast test4.C ../guicast/x86_64/libguicast.a \
23 // -DHAVE_GL -DHAVE_XFT -I/usr/include/freetype2 -lGL -lX11 -lXext \
24 // -lXinerama -lXv -lpng -lfontconfig -lfreetype -lXft -pthread
31 #include <sys/types.h>
34 #include "bcwindowbase.h"
36 #include "bcsignals.h"
42 class TestWindowGUI : public BC_Window
46 TestWindowGUI(int x, int y, int w, int h);
51 class TestWindow : public Thread
55 TestWindow(int x, int y, int w, int h)
57 gui = new TestWindowGUI(x,y,w,h);
60 void draw(VFrame *vframe) {
61 gui->draw_vframe(vframe,
62 0,0,gui->get_w(),gui->get_h(),
63 0,0,vframe->get_w(),vframe->get_h(),
67 void show_text(int tx, int ty, const char *fmt, ...);
68 void close_window() { gui->close(0); }
69 ~TestWindow() { delete gui; }
70 void run() { gui->run_window(); }
74 TestWindowGUI(int x, int y, int w, int h)
75 : BC_Window("test", x,y, w,h, 100,100)
78 clear_box(0,0,get_w(),get_h());
88 void TestWindow::show_text(int tx, int ty, const char *fmt, ...)
93 vsprintf(text, fmt, ap);
95 gui->set_color(0xc080f0);
96 gui->draw_text(tx,ty, text);
100 const char *cmdl[] = {
101 "transparency", "compressed", "rgb8", "rgb565", "bgr565", "bgr888", "bgr8888", "yuv420p",
102 "yuv422p", "rgb888", "rgba8888", "rgb161616", "rgba16161616", "yuv888", "yuva8888", "yuv161616",
103 "yuva16161616", "yuv411p", "uvy422", "yuv422", "argb8888", "abgr8888", "a8", "a16",
104 "yuv101010", "vyu888", "uyva8888", "yuv444p", "yuv410p", "rgb_float", "rgba_float", "a_float",
105 "rgb_floatp", "rgba_floatp", "yuv420pi", "ayuv16161616", "grey8", "grey16", "gbrp",
108 void write_pgm(uint8_t *tp, int w, int h, const char *fmt, ...)
110 va_list ap; va_start(ap, fmt);
111 char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap);
113 FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
115 fprintf(fp,"P5\n%d %d\n255\n",w,h);
121 void write_ppm(uint8_t *tp, int w, int h, const char *fmt, ...)
123 va_list ap; va_start(ap, fmt);
124 char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap);
126 FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
128 fprintf(fp,"P6\n%d %d\n255\n",w,h);
130 if( fp != stdout ) fclose(fp);
134 int64_t tm = 0, tn = 0;
136 static int diff_vframe(VFrame &afrm, VFrame &bfrm)
139 int w = afrm.get_w(), h = afrm.get_h();
140 uint8_t **arows = afrm.get_rows();
141 uint8_t **brows = bfrm.get_rows();
143 for( int y=0; y<h; ++y ) {
144 uint8_t *ap = arows[y], *bp = brows[y];
145 for( int x=0; x<w; ++x ) {
146 for( int i=0; i<3; ++i ) {
147 int d = *ap++ - *bp++;
155 printf(" %d %d %f", m, n, (double)n/sz);
160 int main(int ac, char **av)
163 signals.initialize();
164 int fd = open("test.png",O_RDONLY);
165 if( fd < 0 ) exit(1);
166 struct stat st; fstat(fd,&st);
167 unsigned char *dat = new unsigned char[st.st_size];
168 read(fd, dat, st.st_size);
169 VFramePng ifrm(dat, st.st_size);
172 int w = ifrm.get_w(), h = ifrm.get_h();
173 TestWindow test_window(100, 100, w, h);
174 for( int fr_cmdl=1; fr_cmdl<=38; ++fr_cmdl ) {
175 if( fr_cmdl == BC_TRANSPARENCY || fr_cmdl == BC_COMPRESSED ) continue;
176 if( fr_cmdl == BC_A8 || fr_cmdl == BC_A16 ) continue;
177 if( fr_cmdl == BC_A_FLOAT || fr_cmdl == 8 ) continue;
178 VFrame afrm(w, h, fr_cmdl, -1);
179 afrm.transfer_from(&ifrm, 0);
180 for( int to_cmdl=1; to_cmdl<=38; ++to_cmdl ) {
181 if( to_cmdl == BC_TRANSPARENCY || to_cmdl == BC_COMPRESSED ) continue;
182 if( to_cmdl == BC_A8 || to_cmdl == BC_A16 ) continue;
183 if( to_cmdl == BC_A_FLOAT || to_cmdl == 8 ) continue;
184 printf("xfer_%s_to_%s ", cmdl[fr_cmdl],cmdl[to_cmdl]);
185 VFrame bfrm(w, h, to_cmdl, -1);
186 bfrm.transfer_from(&afrm, 0);
187 test_window.draw(&bfrm);
188 VFrame cfrm(w, h, BC_RGB888, -1);
189 cfrm.transfer_from(&bfrm, 0);
190 test_window.show_text(50,50, "xfer_%s_to_%s",cmdl[fr_cmdl],cmdl[to_cmdl]);
191 write_ppm(cfrm.get_data(), w,h, "/tmp/test/xfer_%s_to_%s.pgm",
192 cmdl[fr_cmdl],cmdl[to_cmdl]);
193 diff_vframe(ifrm, cfrm);
198 test_window.close_window();