-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.h
More file actions
86 lines (69 loc) · 2.28 KB
/
Copy pathcamera.h
File metadata and controls
86 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef CAMERA_H
#define CAMERA_H
#include <string.h>
#include <stdint.h>
struct _webcam_device;
typedef struct _webcam_device webcam_device_t;
typedef void (*webcam_callback_t)(webcam_device_t* device, void* data);
struct _webcam_device {
int deviceId;
int width;
int height;
int framerate;
int running;
void* stream;
webcam_callback_t callback;
};
static inline void copyImage(uint8_t *dstBuf, void* srcBuf, size_t frame_size) {
memcpy(dstBuf, srcBuf, frame_size);
}
// Function to convert YUY2 to RGB24
static void YUY2toRGB24(uint8_t *yuy2, uint8_t *rgb, int width, int height) {
for (int i = 0; i < width * height * 2; i += 4) {
uint8_t y0 = yuy2[i];
uint8_t u = yuy2[i + 1];
uint8_t y1 = yuy2[i + 2];
uint8_t v = yuy2[i + 3];
int c0 = y0 - 16;
int c1 = y1 - 16;
int d = u - 128;
int e = v - 128;
int r0 = (298 * c0 + 409 * e + 128) >> 8;
int g0 = (298 * c0 - 100 * d - 208 * e + 128) >> 8;
int b0 = (298 * c0 + 516 * d + 128) >> 8;
int r1 = (298 * c1 + 409 * e + 128) >> 8;
int g1 = (298 * c1 - 100 * d - 208 * e + 128) >> 8;
int b1 = (298 * c1 + 516 * d + 128) >> 8;
rgb[(i / 2) * 3] = (uint8_t) (r0 < 0 ? 0 : (r0 > 255 ? 255 : r0));
rgb[(i / 2) * 3 + 1] = (uint8_t) (g0 < 0 ? 0 : (g0 > 255 ? 255 : g0));
rgb[(i / 2) * 3 + 2] = (uint8_t) (b0 < 0 ? 0 : (b0 > 255 ? 255 : b0));
rgb[(i / 2 + 1) * 3] = (uint8_t) (r1 < 0 ? 0 : (r1 > 255 ? 255 : r1));
rgb[(i / 2 + 1) * 3 + 1] = (uint8_t) (g1 < 0 ? 0 : (g1 > 255 ? 255 : g1));
rgb[(i / 2 + 1) * 3 + 2] = (uint8_t) (b1 < 0 ? 0 : (b1 > 255 ? 255 : b1));
}
}
#if defined(__OBJC__)
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface WebcamVideoStream : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> {
AVCaptureSession* _captureSession;
AVCaptureDevice* _captureDevice;
AVCaptureVideoDataOutput* _captureDataOut;
AVCaptureDeviceInput* _captureDataIn;
@public
webcam_device_t* _parent;
@public
int _width;
@public
int _height;
@public
int _id;
@public
int _framerate;
}
- (BOOL)setupWithID:(int)deviceID rate:(int)framerate width:(int)w height:(int)h;
- (void)start;
- (void)stop;
@end
#endif // defined(__OBJC__)
#endif // CAMERA_H