Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/camera/buffer_decoder.h
11352 views
1
/**************************************************************************/
2
/* buffer_decoder.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/io/image.h"
34
#include "core/templates/vector.h"
35
36
class CameraFeed;
37
38
struct StreamingBuffer {
39
void *start = nullptr;
40
size_t length = 0;
41
};
42
43
class BufferDecoder {
44
protected:
45
CameraFeed *camera_feed = nullptr;
46
Ref<Image> image;
47
int width = 0;
48
int height = 0;
49
50
public:
51
virtual void decode(StreamingBuffer p_buffer) = 0;
52
53
BufferDecoder(CameraFeed *p_camera_feed);
54
virtual ~BufferDecoder() {}
55
};
56
57
class AbstractYuyvBufferDecoder : public BufferDecoder {
58
protected:
59
int *component_indexes = nullptr;
60
61
public:
62
AbstractYuyvBufferDecoder(CameraFeed *p_camera_feed);
63
~AbstractYuyvBufferDecoder();
64
};
65
66
class SeparateYuyvBufferDecoder : public AbstractYuyvBufferDecoder {
67
private:
68
Vector<uint8_t> y_image_data;
69
Vector<uint8_t> cbcr_image_data;
70
Ref<Image> y_image;
71
Ref<Image> cbcr_image;
72
73
public:
74
SeparateYuyvBufferDecoder(CameraFeed *p_camera_feed);
75
virtual void decode(StreamingBuffer p_buffer) override;
76
};
77
78
class YuyvToGrayscaleBufferDecoder : public AbstractYuyvBufferDecoder {
79
private:
80
Vector<uint8_t> image_data;
81
82
public:
83
YuyvToGrayscaleBufferDecoder(CameraFeed *p_camera_feed);
84
virtual void decode(StreamingBuffer p_buffer) override;
85
};
86
87
class YuyvToRgbBufferDecoder : public AbstractYuyvBufferDecoder {
88
private:
89
Vector<uint8_t> image_data;
90
91
public:
92
YuyvToRgbBufferDecoder(CameraFeed *p_camera_feed);
93
virtual void decode(StreamingBuffer p_buffer) override;
94
};
95
96
class CopyBufferDecoder : public BufferDecoder {
97
private:
98
Vector<uint8_t> image_data;
99
bool rgba = false;
100
101
public:
102
CopyBufferDecoder(CameraFeed *p_camera_feed, bool p_rgba);
103
virtual void decode(StreamingBuffer p_buffer) override;
104
};
105
106
class JpegBufferDecoder : public BufferDecoder {
107
private:
108
Vector<uint8_t> image_data;
109
110
public:
111
JpegBufferDecoder(CameraFeed *p_camera_feed);
112
virtual void decode(StreamingBuffer p_buffer) override;
113
};
114
115