787fb4a6455fb94d429235b780580ff598604621
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bccapture.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef BCCAPTURE_H
23 #define BCCAPTURE_H
24
25 #include <sys/ipc.h>
26 #include <sys/shm.h>
27 #include <X11/Xlib.h>
28 #include <X11/extensions/XShm.h>
29
30 #include "sizes.h"
31 #include "vframe.inc"
32
33
34 class BC_Capture
35 {
36 public:
37         BC_Capture(int w, int h, const char *display_path = "");
38         virtual ~BC_Capture();
39
40         int init_window(const char *display_path);
41 // x1 and y1 are automatically adjusted if out of bounds
42         int capture_frame(VFrame *frame, int &x1, int &y1, 
43                 int do_cursor=0); // the scale of the cursor if nonzero
44         int get_w();
45         int get_h();
46
47         int w, h, default_depth;
48         unsigned char **row_data;
49
50 private:
51         int allocate_data();
52         int delete_data();
53         int get_top_w();
54         int get_top_h();
55
56         inline void import_RGB565_to_RGB888(unsigned char* &output, unsigned char* &input)
57         {
58                 *output++ = (*input & 0xf800) >> 8;
59                 *output++ = (*input & 0x7e0) >> 3;
60                 *output++ = (*input & 0x1f) << 3;
61
62                 input += 2;
63                 output += 3;
64         };
65
66         inline void import_BGR888_to_RGB888(unsigned char* &output, unsigned char* &input)
67         {
68                 *output++ = input[2];
69                 *output++ = input[1];
70                 *output++ = input[0];
71
72                 input += 3;
73                 output += 3;
74         };
75
76         inline void import_BGR8888_to_RGB888(unsigned char* &output, unsigned char* &input)
77         {
78                 *output++ = input[2];
79                 *output++ = input[1];
80                 *output++ = input[0];
81
82                 input += 4;
83                 output += 3;
84         };
85
86         int use_shm;
87         int bitmap_color_model;
88         unsigned char *data;
89         XImage *ximage;
90         XShmSegmentInfo shm_info;
91         Display* display;
92         Window rootwin;
93         Visual *vis;
94         int bits_per_pixel;
95         int screen;
96         long shm_event_type;
97         int client_byte_order, server_byte_order;
98 };
99
100 #endif