Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / test6.C
1 /*
2  * CINELERRA
3  * Copyright (C) 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 <stdarg.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <math.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30
31 #include "bcwindowbase.h"
32 #include "bcwindow.h"
33 #include "bcsignals.h"
34 #include "bccolors.h"
35 #include "clip.h"
36 #include "fonts.h"
37 #include "thread.h"
38 #include "vframe.h"
39
40 /*c++ -g -I/mnt1/build5/cinelerra-5.1/guicast x.C \
41   /mnt1/build5/cinelerra-5.1/guicast/x86_64/libguicast.a \
42   -DHAVE_GL -DHAVE_XFT -I/usr/include/freetype2 -lGL -lX11 -lXext \
43   -lXinerama -lXv -lpng  -lfontconfig -lfreetype -lXft -pthread */
44
45 void wheel(VFrame *dst, float cx, float cy, float rad, int bg_color)
46 {
47         int color_model = dst->get_color_model();
48         int bpp = BC_CModels::calculate_pixelsize(color_model);
49         int bg_r = (bg_color>>16) & 0xff;
50         int bg_g = (bg_color>> 8) & 0xff;
51         int bg_b = (bg_color>> 0) & 0xff;
52         int w = dst->get_w(), h = dst->get_h();
53         unsigned char **rows = dst->get_rows();
54         for( int y=0; y<h; ++y ) {
55                 unsigned char *row = rows[y];
56                 for( int x=0; x<w; ++x,row+=bpp ) {
57                         int dx = cx-x, dy = cy-y;
58                         float d = sqrt(dx*dx + dy*dy);
59                         float r, g, b;
60                         if( d < rad ) {
61                                 float h = TO_DEG(atan2(cx-x, cy-y));
62                                 if( h < 0 ) h += 360;
63                                 float s = d / rad, v = 255;
64                                 HSV::hsv_to_rgb(r, g, b, h, s, v);
65                         }
66                         else {
67                                  r = bg_r; g = bg_g; b = bg_b;
68                         }
69                         row[0] = r; row[1] = g; row[2] = b;
70                 }
71         }
72 }
73
74 class TestWindowGUI : public BC_Window
75 {
76 public:
77         VFrame *wfrm;
78         int bg;
79
80         TestWindowGUI(int x, int y, int w, int h);
81         ~TestWindowGUI();
82
83         void draw(int ww, int wh) {
84                 delete wfrm;
85                 wfrm = new VFrame(ww,wh,BC_RGB888);
86                 float wr = bmin(ww, wh)/2.25;
87                 int bg = get_bg_color();
88                 wheel(wfrm, ww/2,wh/2, wr, bg);
89                 draw_vframe(wfrm);
90                 flash();
91         }
92         int resize_event(int w, int h) {
93                 BC_WindowBase::resize_event(w, h);
94                 draw(w, h);
95                 return 0;
96         }
97 };
98
99 TestWindowGUI::
100 TestWindowGUI(int x, int y, int w, int h)
101  : BC_Window("test", x,y, w,h, 100,100)
102 {
103         wfrm = 0;
104         set_bg_color(0x885533);
105         lock_window("init");
106         clear_box(0,0,w,h);
107         flash();
108         unlock_window();
109 }
110
111 TestWindowGUI::
112 ~TestWindowGUI()
113 {
114 }
115
116
117 class TestWindow : public Thread
118 {
119         TestWindowGUI *gui;
120 public:
121         TestWindow(int x, int y, int w, int h)
122          : Thread(1,0,0) {
123                 gui = new TestWindowGUI(x,y, w,h);
124                 gui->lock_window("init");
125                 gui->resize_event(w, h);
126                 gui->unlock_window();
127                 start();
128         }
129         ~TestWindow() { delete gui; }
130         void run() { gui->run_window(); }
131         void close_window() { gui->close(0); }
132 };
133
134
135 int main(int ac, char **av)
136 {
137         BC_Signals signals;
138         signals.initialize();
139         BC_WindowBase::init_resources(1.);
140         TestWindow test_window(100, 100, 256, 256);
141         test_window.join();
142         return 0;
143 }
144