-
Notifications
You must be signed in to change notification settings - Fork 1
/
Effects01.c
224 lines (187 loc) · 6.15 KB
/
Effects01.c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Rotation, inversion, and other simple operations.
*/
#include <stdio.h> /* fprintf */
#include <stdlib.h> /* calloc */
#include <string.h> /* memcpy */
#include "CTI.h"
#include "Images.h"
static void Config_handler(Instance *pi, void *msg);
static void Y420p_handler(Instance *pi, void *msg);
static void RGB3_handler(Instance *pi, void *data);
enum { INPUT_CONFIG, INPUT_YUV420P, INPUT_RGB3 };
static Input Effects01_inputs[] = {
[ INPUT_CONFIG ] = { .type_label = "Config_msg", .handler = Config_handler },
[ INPUT_YUV420P ] = { .type_label = "YUV420P_buffer", .handler = Y420p_handler },
[ INPUT_RGB3 ] = { .type_label = "RGB3_buffer", .handler = RGB3_handler },
};
enum { OUTPUT_YUV420P, OUTPUT_RGB3 };
static Output Effects01_outputs[] = {
[ OUTPUT_YUV420P ] = { .type_label = "YUV420P_buffer", .destination = 0L },
[ OUTPUT_RGB3 ] = { .type_label = "RGB3_buffer", .destination = 0L },
};
typedef struct {
Instance i;
uint8_t invert;
int rotate;
} Effects01_private;
static Config config_table[] = {
{ "invert", 0L, 0L, 0L, cti_set_int, offsetof(Effects01_private, invert) },
{ "rotate", 0L, 0L, 0L, cti_set_int, offsetof(Effects01_private, rotate) },
};
static void Config_handler(Instance *pi, void *data)
{
Generic_config_handler(pi, data, config_table, table_size(config_table));
}
static void invert_plane(uint8_t *p, int length)
{
int i;
for (i=0; i < length; i++) {
p[i] = 255 - p[i];
}
}
static void rotate_rgb_90(uint8_t *src, uint8_t *dst, int src_width, int src_height)
{
int src_x, src_y;
int dst_width = src_height;
for (src_y = 0; src_y < src_height; src_y++) {
uint8_t *p_in = src + src_y*src_width*3;
uint8_t *p_out = dst + (dst_width - 1 - src_y)*3;
for (src_x = 0; src_x < src_width; src_x++) {
*p_out++ = *p_in++;
*p_out++ = *p_in++;
*p_out++ = *p_in++;
p_out += (dst_width*3 - 3);
}
}
}
static void rotate_rgb_270(uint8_t *src, uint8_t *dst, int src_width, int src_height)
{
int src_x, src_y;
int dst_width = src_height;
int dst_height = src_width;
for (src_y = 0; src_y < src_height; src_y++) {
uint8_t *p_in = src + src_y*src_width*3;
uint8_t *p_out = dst + (dst_width * (dst_height - 1) + src_y) * 3;
for (src_x = 0; src_x < src_width; src_x++) {
*p_out++ = *p_in++;
*p_out++ = *p_in++;
*p_out++ = *p_in++;
p_out -= 3;
p_out -= dst_width*3;
}
}
}
static void rotate_single_90(uint8_t *src, uint8_t *dst, int src_width, int src_height)
{
int src_x, src_y;
int dst_width = src_height;
int dst_height = src_width;
for (src_y = 0; src_y < src_height; src_y++) {
uint8_t *p_in = src + src_y*src_width;
uint8_t *p_out = dst + (dst_width * (dst_height - 1) + src_y);
for (src_x = 0; src_x < src_width; src_x++) {
*p_out++ = *p_in++;
p_out -= 1;
p_out -= dst_width;
}
}
}
static void rotate_single_270(uint8_t *src, uint8_t *dst, int src_width, int src_height)
{
int src_x, src_y;
int dst_width = src_height;
int dst_height = src_width;
for (src_y = 0; src_y < src_height; src_y++) {
uint8_t *p_in = src + src_y*src_width;
uint8_t *p_out = dst + (dst_width * (dst_height - 1) + src_y);
for (src_x = 0; src_x < src_width; src_x++) {
*p_out++ = *p_in++;
p_out -= 1;
p_out -= dst_width;
}
}
}
static void Y420p_handler(Instance *pi, void *data)
{
Effects01_private *priv = (Effects01_private *)pi;
YUV420P_buffer *y420p = data;
if (!pi->outputs[OUTPUT_YUV420P].destination) {
YUV420P_buffer_release(y420p);
return;
}
if (priv->invert) {
invert_plane(y420p->y, y420p->y_length);
}
if (priv->rotate == 90) {
YUV420P_buffer *y420p_new = YUV420P_buffer_new(y420p->height, y420p->width, &y420p->c);
rotate_single_90(y420p->y, y420p_new->y, y420p->width, y420p->height);
rotate_single_90(y420p->cr, y420p_new->cr, y420p->cr_width, y420p->cr_height);
rotate_single_90(y420p->cb, y420p_new->cb, y420p->cb_width, y420p->cb_height);
YUV420P_buffer_release(y420p);
y420p = y420p_new;
}
if (priv->rotate == 270) {
YUV420P_buffer *y420p_new = YUV420P_buffer_new(y420p->height, y420p->width, &y420p->c);
rotate_single_270(y420p->y, y420p_new->y, y420p->width, y420p->height);
rotate_single_270(y420p->cr, y420p_new->cr, y420p->cr_width, y420p->cr_height);
rotate_single_270(y420p->cb, y420p_new->cb, y420p->cb_width, y420p->cb_height);
YUV420P_buffer_release(y420p);
y420p = y420p_new;
}
PostData(y420p, pi->outputs[OUTPUT_YUV420P].destination);
}
static void RGB3_handler(Instance *pi, void *data)
{
Effects01_private *priv = (Effects01_private *)pi;
RGB3_buffer *rgb3_in = data;
if (!pi->outputs[OUTPUT_RGB3].destination) {
RGB3_buffer_release(rgb3_in);
return;
}
/* Operate in-place, pass along to output... */
if (priv->invert) {
invert_plane(rgb3_in->data, rgb3_in->data_length);
}
if (priv->rotate == 90) {
RGB3_buffer *rgb3_new = RGB3_buffer_new(rgb3_in->height, rgb3_in->width, &rgb3_in->c);
rotate_rgb_90(rgb3_in->data, rgb3_new->data, rgb3_in->width, rgb3_in->height);
RGB3_buffer_release(rgb3_in);
rgb3_in = rgb3_new;
}
if (priv->rotate == 270) {
RGB3_buffer *rgb3_new = RGB3_buffer_new(rgb3_in->height, rgb3_in->width, &rgb3_in->c);
rotate_rgb_270(rgb3_in->data, rgb3_new->data, rgb3_in->width, rgb3_in->height);
RGB3_buffer_release(rgb3_in);
rgb3_in = rgb3_new;
}
PostData(rgb3_in, pi->outputs[OUTPUT_RGB3].destination);
}
static void Effects01_tick(Instance *pi)
{
Handler_message *hm;
hm = GetData(pi, 1);
if (hm) {
hm->handler(pi, hm->data);
ReleaseMessage(&hm,pi);
}
pi->counter++;
}
static void Effects01_instance_init(Instance *pi)
{
// Effects01_private *priv = (Effects01_private *)pi;
}
static Template Effects01_template = {
.label = "Effects01",
.priv_size = sizeof(Effects01_private),
.inputs = Effects01_inputs,
.num_inputs = table_size(Effects01_inputs),
.outputs = Effects01_outputs,
.num_outputs = table_size(Effects01_outputs),
.tick = Effects01_tick,
.instance_init = Effects01_instance_init,
};
void Effects01_init(void)
{
Template_register(&Effects01_template);
}