.gitignore added
[dotfiles/.git] / .local / include / python3.9 / pygame / camera.h
1 #ifndef CAMERA_H
2 #define CAMERA_H
3 /*
4   pygame - Python Game Library
5
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Library General Public
8   License as published by the Free Software Foundation; either
9   version 2 of the License, or (at your option) any later version.
10
11   This library 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 GNU
14   Library General Public License for more details.
15
16   You should have received a copy of the GNU Library General Public
17   License along with this library; if not, write to the Free
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 */
21
22 #include "pygame.h"
23 #include "doc/camera_doc.h"
24
25 #if defined(__unix__)
26     #include <structmember.h>
27     #include <stdio.h>
28     #include <stdlib.h>
29     #include <string.h>
30     #include <assert.h>
31
32     #include <fcntl.h>              /* low-level i/o */
33     #include <unistd.h>
34     #include <errno.h>
35     #include <sys/stat.h>
36     #include <sys/types.h>
37     #include <sys/time.h>
38     #include <sys/mman.h>
39     #include <sys/ioctl.h>
40
41     /* on freebsd there is no asm/types */
42     #ifdef linux
43         #include <asm/types.h>          /* for videodev2.h */
44     #endif
45
46     #include <linux/videodev2.h>
47 #elif defined(__APPLE__)
48     #include <AvailabilityMacros.h>
49     /* We support OSX 10.6 and below. */
50     #if __MAC_OS_X_VERSION_MAX_ALLOWED <= 1060
51         #define PYGAME_MAC_CAMERA_OLD 1
52     #endif
53 #endif
54
55 #if defined(PYGAME_MAC_CAMERA_OLD)
56         #include <QuickTime/QuickTime.h>
57         #include <QuickTime/Movies.h>
58         #include <QuickTime/ImageCompression.h>
59 #endif
60
61 /* some constants used which are not defined on non-v4l machines. */
62 #ifndef V4L2_PIX_FMT_RGB24
63     #define V4L2_PIX_FMT_RGB24 'RGB3'
64 #endif
65 #ifndef V4L2_PIX_FMT_RGB444
66     #define V4L2_PIX_FMT_RGB444 'R444'
67 #endif
68 #ifndef V4L2_PIX_FMT_YUYV
69     #define V4L2_PIX_FMT_YUYV 'YUYV'
70 #endif
71
72 #define CLEAR(x) memset (&(x), 0, sizeof (x))
73 #define SAT(c) if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
74 #define SAT2(c) ((c) & (~255) ? ((c) < 0 ? 0 : 255) : (c))
75 #define DEFAULT_WIDTH 640
76 #define DEFAULT_HEIGHT 480
77 #define RGB_OUT 1
78 #define YUV_OUT 2
79 #define HSV_OUT 4
80 #define CAM_V4L 1 /* deprecated. the incomplete support in pygame was removed */
81 #define CAM_V4L2 2
82
83 struct buffer {
84     void * start;
85     size_t length;
86 };
87
88 #if defined(__unix__)
89 typedef struct pgCameraObject {
90     PyObject_HEAD
91     char* device_name;
92     int camera_type;
93     unsigned long pixelformat;
94     unsigned int color_out;
95     struct buffer* buffers;
96     unsigned int n_buffers;
97     int width;
98     int height;
99     int size;
100     int hflip;
101     int vflip;
102     int brightness;
103     int fd;
104 } pgCameraObject;
105 #elif defined(PYGAME_MAC_CAMERA_OLD)
106 typedef struct pgCameraObject {
107     PyObject_HEAD
108     char* device_name;              /* unique name of the device */
109     OSType pixelformat;
110     unsigned int color_out;
111     SeqGrabComponent component;     /* A type used by the Sequence Grabber API */
112     SGChannel channel;              /* Channel of the Sequence Grabber */
113     GWorldPtr gworld;               /* Pointer to the struct that holds the data of the captured image */
114     Rect boundsRect;                /* bounds of the image frame */
115     long size;                      /* size of the image in our buffer to draw */
116     int hflip;
117     int vflip;
118     short depth;
119     struct buffer pixels;
120     //struct buffer tmp_pixels        /* place where the flipped image in temporarily stored if hflip or vflip is true.*/
121 } pgCameraObject;
122
123 #else
124 /* generic definition.
125 */
126
127 typedef struct pgCameraObject {
128     PyObject_HEAD
129     char* device_name;
130     int camera_type;
131     unsigned long pixelformat;
132     unsigned int color_out;
133     struct buffer* buffers;
134     unsigned int n_buffers;
135     int width;
136     int height;
137     int size;
138     int hflip;
139     int vflip;
140     int brightness;
141     int fd;
142 } pgCameraObject;
143 #endif
144
145 /* internal functions for colorspace conversion */
146 void colorspace (SDL_Surface *src, SDL_Surface *dst, int cspace);
147 void rgb24_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
148 void rgb444_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
149 void rgb_to_yuv (const void* src, void* dst, int length,
150                  unsigned long source, SDL_PixelFormat* format);
151 void rgb_to_hsv (const void* src, void* dst, int length,
152                  unsigned long source, SDL_PixelFormat* format);
153 void yuyv_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
154 void yuyv_to_yuv (const void* src, void* dst, int length, SDL_PixelFormat* format);
155 void uyvy_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
156 void uyvy_to_yuv (const void* src, void* dst, int length, SDL_PixelFormat* format);
157 void sbggr8_to_rgb (const void* src, void* dst, int width, int height,
158                     SDL_PixelFormat* format);
159 void yuv420_to_rgb (const void* src, void* dst, int width, int height,
160                     SDL_PixelFormat* format);
161 void yuv420_to_yuv (const void* src, void* dst, int width, int height,
162                     SDL_PixelFormat* format);
163
164 #if defined(__unix__)
165 /* internal functions specific to v4l2 */
166 char** v4l2_list_cameras (int* num_devices);
167 int v4l2_get_control (int fd, int id, int *value);
168 int v4l2_set_control (int fd, int id, int value);
169 PyObject* v4l2_read_raw (pgCameraObject* self);
170 int v4l2_xioctl (int fd, int request, void *arg);
171 int v4l2_process_image (pgCameraObject* self, const void *image,
172                                unsigned int buffer_size, SDL_Surface* surf);
173 int v4l2_query_buffer (pgCameraObject* self);
174 int v4l2_read_frame (pgCameraObject* self, SDL_Surface* surf);
175 int v4l2_stop_capturing (pgCameraObject* self);
176 int v4l2_start_capturing (pgCameraObject* self);
177 int v4l2_uninit_device (pgCameraObject* self);
178 int v4l2_init_mmap (pgCameraObject* self);
179 int v4l2_init_device (pgCameraObject* self);
180 int v4l2_close_device (pgCameraObject* self);
181 int v4l2_open_device (pgCameraObject* self);
182
183 #elif defined(PYGAME_MAC_CAMERA_OLD)
184 /* internal functions specific to mac */
185 char** mac_list_cameras(int* num_devices);
186 int mac_open_device (pgCameraObject* self);
187 int mac_init_device(pgCameraObject* self);
188 int mac_close_device (pgCameraObject* self);
189 int mac_start_capturing(pgCameraObject* self);
190 int mac_stop_capturing (pgCameraObject* self);
191
192 int mac_get_control(pgCameraObject* self, int id, int* value);
193 int mac_set_control(pgCameraObject* self, int id, int value);
194
195 PyObject* mac_read_raw(pgCameraObject *self);
196 int mac_read_frame(pgCameraObject* self, SDL_Surface* surf);
197 int mac_camera_idle(pgCameraObject* self);
198 int mac_copy_gworld_to_surface(pgCameraObject* self, SDL_Surface* surf);
199
200 void flip_image(const void* image, void* flipped_image, int width, int height,
201                 short depth, int hflip, int vflip);
202
203 #endif
204
205 #endif /* !CAMERA_H */