2
//#include "colorspace.h" // Common routines
10
#define ALL_PIXELFORMATS
11
#define IN_PIXELFORMAT GAVL_YUV_444_P
12
#define OUT_PIXELFORMAT GAVL_YUV_444_P_16
14
// Masks for BGR16 and RGB16 formats
16
#define RGB16_LOWER_MASK 0x001f
17
#define RGB16_MIDDLE_MASK 0x07e0
18
#define RGB16_UPPER_MASK 0xf800
20
// Extract unsigned char RGB values from 15 bit pixels
22
#define RGB16_TO_R(pixel) ((pixel & RGB16_UPPER_MASK)>>8)
23
#define RGB16_TO_G(pixel) ((pixel & RGB16_MIDDLE_MASK)>>3)
24
#define RGB16_TO_B(pixel) ((pixel & RGB16_LOWER_MASK)<<3)
26
#define RGB15_LOWER_MASK 0x001f
27
#define RGB15_MIDDLE_MASK 0x3e0
28
#define RGB15_UPPER_MASK 0x7C00
30
#define RGB15_TO_R(pixel) ((pixel & RGB15_UPPER_MASK)>>7)
31
#define RGB15_TO_G(pixel) ((pixel & RGB15_MIDDLE_MASK)>>2)
32
#define RGB15_TO_B(pixel) ((pixel & RGB15_LOWER_MASK)<<3)
34
// ((((((src[2]<<5)&0xff00)|src[1])<<6)&0xfff00)|src[0])>>3;
36
#define TEST_PICTURE_WIDTH 320
37
#define TEST_PICTURE_HEIGHT 256
40
* Some braindead YUV conversion (but works at least :-)
43
static int * r_to_y = (int*)0;
44
static int * g_to_y = (int*)0;
45
static int * b_to_y = (int*)0;
47
static int * r_to_u = (int*)0;
48
static int * g_to_u = (int*)0;
49
static int * b_to_u = (int*)0;
51
static int * r_to_v = (int*)0;
52
static int * g_to_v = (int*)0;
53
static int * b_to_v = (int*)0;
55
static int * y_to_rgb = (int*)0;
56
static int * v_to_r = (int*)0;
57
static int * u_to_g = (int*)0;
58
static int * v_to_g = (int*)0;
59
static int * u_to_b = (int*)0;
61
/* JPEG Quantization */
63
static int * r_to_yj = (int*)0;
64
static int * g_to_yj = (int*)0;
65
static int * b_to_yj = (int*)0;
67
static int * r_to_uj = (int*)0;
68
static int * g_to_uj = (int*)0;
69
static int * b_to_uj = (int*)0;
71
static int * r_to_vj = (int*)0;
72
static int * g_to_vj = (int*)0;
73
static int * b_to_vj = (int*)0;
75
static int * yj_to_rgb = (int*)0;
76
static int * vj_to_r = (int*)0;
77
static int * uj_to_g = (int*)0;
78
static int * vj_to_g = (int*)0;
79
static int * uj_to_b = (int*)0;
87
r_to_y = malloc(0x100 * sizeof(int));
88
g_to_y = malloc(0x100 * sizeof(int));
89
b_to_y = malloc(0x100 * sizeof(int));
91
r_to_u = malloc(0x100 * sizeof(int));
92
g_to_u = malloc(0x100 * sizeof(int));
93
b_to_u = malloc(0x100 * sizeof(int));
95
r_to_v = malloc(0x100 * sizeof(int));
96
g_to_v = malloc(0x100 * sizeof(int));
97
b_to_v = malloc(0x100 * sizeof(int));
99
y_to_rgb = malloc(0x100 * sizeof(int));
100
v_to_r = malloc(0x100 * sizeof(int));
101
u_to_g = malloc(0x100 * sizeof(int));
102
v_to_g = malloc(0x100 * sizeof(int));
103
u_to_b = malloc(0x100 * sizeof(int));
105
/* JPEG Quantization */
107
r_to_yj = malloc(0x100 * sizeof(int));
108
g_to_yj = malloc(0x100 * sizeof(int));
109
b_to_yj = malloc(0x100 * sizeof(int));
111
r_to_uj = malloc(0x100 * sizeof(int));
112
g_to_uj = malloc(0x100 * sizeof(int));
113
b_to_uj = malloc(0x100 * sizeof(int));
115
r_to_vj = malloc(0x100 * sizeof(int));
116
g_to_vj = malloc(0x100 * sizeof(int));
117
b_to_vj = malloc(0x100 * sizeof(int));
119
yj_to_rgb = malloc(0x100 * sizeof(int));
120
vj_to_r = malloc(0x100 * sizeof(int));
121
uj_to_g = malloc(0x100 * sizeof(int));
122
vj_to_g = malloc(0x100 * sizeof(int));
123
uj_to_b = malloc(0x100 * sizeof(int));
126
for(i = 0; i < 0x100; i++)
128
// RGB to YUV conversion
130
r_to_y[i] = (int)(0.257*0x10000 * i + 16 * 0x10000);
131
g_to_y[i] = (int)(0.504*0x10000 * i);
132
b_to_y[i] = (int)(0.098*0x10000 * i);
134
r_to_u[i] = (int)(-0.148*0x10000 * i);
135
g_to_u[i] = (int)(-0.291*0x10000 * i);
136
b_to_u[i] = (int)( 0.439*0x10000 * i + 0x800000);
138
r_to_v[i] = (int)( 0.439*0x10000 * i);
139
g_to_v[i] = (int)(-0.368*0x10000 * i);
140
b_to_v[i] = (int)(-0.071*0x10000 * i + 0x800000);
142
r_to_yj[i] = (int)((0.29900)*0x10000 * i);
143
g_to_yj[i] = (int)((0.58700)*0x10000 * i);
144
b_to_yj[i] = (int)((0.11400)*0x10000 * i);
146
r_to_uj[i] = (int)(-(0.16874)*0x10000 * i);
147
g_to_uj[i] = (int)(-(0.33126)*0x10000 * i);
148
b_to_uj[i] = (int)( (0.50000)*0x10000 * i + 0x800000);
150
r_to_vj[i] = (int)( (0.50000)*0x10000 * i);
151
g_to_vj[i] = (int)(-(0.41869)*0x10000 * i);
152
b_to_vj[i] = (int)(-(0.08131)*0x10000 * i + 0x800000);
155
// YUV to RGB conversion
157
y_to_rgb[i] = (int)(1.164*(i-16)) * 0x10000;
159
v_to_r[i] = (int)( 1.596 * (i - 0x80) * 0x10000);
160
u_to_g[i] = (int)(-0.392 * (i - 0x80) * 0x10000);
161
v_to_g[i] = (int)(-0.813 * (i - 0x80) * 0x10000);
162
u_to_b[i] = (int)( 2.017 * (i - 0x80) * 0x10000);
164
/* JPEG Quantization */
166
yj_to_rgb[i] = (int)(i * 0x10000);
168
vj_to_r[i] = (int)( 1.40200 * (i - 0x80) * 0x10000);
169
uj_to_g[i] = (int)(-0.34414 * (i - 0x80) * 0x10000);
170
vj_to_g[i] = (int)(-0.71414 * (i - 0x80) * 0x10000);
171
uj_to_b[i] = (int)( 1.77200 * (i - 0x80) * 0x10000);
176
#define RECLIP(color) (uint8_t)((color>0xFF)?0xff:((color<0)?0:color))
178
#define RECLIP_16(color) (uint16_t)((color>0xFFFF)?0xFFFF:((color<0)?0:color))
180
#define RECLIP_FLOAT(color) (float)((color>1.0)?1.0:((color<0.0)?0.0:color))
182
#define YUV_2_RGB(y,u,v,r,g,b) i_tmp=(y_to_rgb[y]+v_to_r[v])>>16;\
184
i_tmp=(y_to_rgb[y]+u_to_g[u]+v_to_g[v])>>16;\
186
i_tmp=(y_to_rgb[y]+u_to_b[u])>>16;\
189
#define YUVJ_2_RGB(y,u,v,r,g,b) i_tmp=(yj_to_rgb[y]+vj_to_r[v])>>16;\
191
i_tmp=(yj_to_rgb[y]+uj_to_g[u]+vj_to_g[v])>>16;\
193
i_tmp=(yj_to_rgb[y]+uj_to_b[u])>>16;\
196
#define YUV_16_2_RGB(y,u,v,r,g,b) i_tmp=(y_to_rgb[y>>8]+v_to_r[v>>8])>>16;\
198
i_tmp=(y_to_rgb[y>>8]+u_to_g[u>>8]+v_to_g[v>>8])>>16;\
200
i_tmp=(y_to_rgb[y>>8]+u_to_b[u>>8])>>16;\
203
static void convert_15_to_24(gavl_video_frame_t * in_frame,
204
gavl_video_frame_t * out_frame,
205
int width, int height)
212
uint8_t * out_pixel_save = out_frame->planes[0];
213
uint8_t * in_pixel_save = in_frame->planes[0];
215
for(i = 0; i < height; i++)
217
in_pixel = (uint16_t*)in_pixel_save;
218
out_pixel = out_pixel_save;
220
for(j = 0; j < width; j++)
222
out_pixel[0] = RGB15_TO_R(*in_pixel);
223
out_pixel[1] = RGB15_TO_G(*in_pixel);
224
out_pixel[2] = RGB15_TO_B(*in_pixel);
229
in_pixel_save += in_frame->strides[0];
230
out_pixel_save += out_frame->strides[0];
234
static void convert_16_to_24(gavl_video_frame_t * in_frame,
235
gavl_video_frame_t * out_frame,
236
int width, int height)
242
uint8_t * out_pixel_save = out_frame->planes[0];
243
uint8_t * in_pixel_save = in_frame->planes[0];
245
for(i = 0; i < height; i++)
247
in_pixel = (uint16_t*)in_pixel_save;
248
out_pixel = out_pixel_save;
249
for(j = 0; j < width; j++)
251
out_pixel[0] = RGB16_TO_R(*in_pixel);
252
out_pixel[1] = RGB16_TO_G(*in_pixel);
253
out_pixel[2] = RGB16_TO_B(*in_pixel);
258
in_pixel_save += in_frame->strides[0];
259
out_pixel_save += out_frame->strides[0];
263
static void convert_32_to_24(gavl_video_frame_t * in_frame,
264
gavl_video_frame_t * out_frame,
265
int width, int height)
271
uint8_t * out_pixel_save = out_frame->planes[0];
272
uint8_t * in_pixel_save = in_frame->planes[0];
274
for(i = 0; i < height; i++)
276
in_pixel = (uint8_t*)in_pixel_save;
277
out_pixel = out_pixel_save;
278
for(j = 0; j < width; j++)
280
out_pixel[0] = in_pixel[0];
281
out_pixel[1] = in_pixel[1];
282
out_pixel[2] = in_pixel[2];
286
in_pixel_save += in_frame->strides[0];
287
out_pixel_save += out_frame->strides[0];
291
static void convert_48_to_24(gavl_video_frame_t * in_frame,
292
gavl_video_frame_t * out_frame,
293
int width, int height)
299
uint8_t * out_pixel_save = out_frame->planes[0];
300
uint8_t * in_pixel_save = in_frame->planes[0];
302
for(i = 0; i < height; i++)
304
in_pixel = (uint16_t*)in_pixel_save;
305
out_pixel = out_pixel_save;
306
for(j = 0; j < width; j++)
308
out_pixel[0] = in_pixel[0] >> 8;
309
out_pixel[1] = in_pixel[1] >> 8;
310
out_pixel[2] = in_pixel[2] >> 8;
314
in_pixel_save += in_frame->strides[0];
315
out_pixel_save += out_frame->strides[0];
319
static void convert_64_to_32(gavl_video_frame_t * in_frame,
320
gavl_video_frame_t * out_frame,
321
int width, int height)
327
uint8_t * out_pixel_save = out_frame->planes[0];
328
uint8_t * in_pixel_save = in_frame->planes[0];
330
for(i = 0; i < height; i++)
332
in_pixel = (uint16_t*)in_pixel_save;
333
out_pixel = out_pixel_save;
334
for(j = 0; j < width; j++)
336
out_pixel[0] = in_pixel[0] >> 8;
337
out_pixel[1] = in_pixel[1] >> 8;
338
out_pixel[2] = in_pixel[2] >> 8;
339
out_pixel[3] = in_pixel[3] >> 8;
343
in_pixel_save += in_frame->strides[0];
344
out_pixel_save += out_frame->strides[0];
348
static void convert_YUVA_32_to_RGBA_32(gavl_video_frame_t * in_frame,
349
gavl_video_frame_t * out_frame,
350
int width, int height)
356
uint8_t * out_pixel_save = out_frame->planes[0];
357
uint8_t * in_pixel_save = in_frame->planes[0];
359
for(i = 0; i < height; i++)
361
in_pixel = in_pixel_save;
362
out_pixel = out_pixel_save;
363
for(j = 0; j < width; j++)
365
YUV_2_RGB(in_pixel[0], in_pixel[1], in_pixel[2], out_pixel[0], out_pixel[1], out_pixel[2]);
366
out_pixel[3] = in_pixel[3];
370
in_pixel_save += in_frame->strides[0];
371
out_pixel_save += out_frame->strides[0];
377
static void convert_float_to_24(gavl_video_frame_t * in_frame,
378
gavl_video_frame_t * out_frame,
379
int width, int height)
385
uint8_t * out_pixel_save = out_frame->planes[0];
386
uint8_t * in_pixel_save = in_frame->planes[0];
388
for(i = 0; i < height; i++)
390
in_pixel = (float*)in_pixel_save;
391
out_pixel = out_pixel_save;
392
for(j = 0; j < width; j++)
394
i_tmp = (int)(in_pixel[0] * 255.0 + 0.5);
395
out_pixel[0] = RECLIP(i_tmp);
396
i_tmp = (int)(in_pixel[1] * 255.0 + 0.5);
397
out_pixel[1] = RECLIP(i_tmp);
398
i_tmp = (int)(in_pixel[2] * 255.0 + 0.5);
399
out_pixel[2] = RECLIP(i_tmp);
403
in_pixel_save += in_frame->strides[0];
404
out_pixel_save += out_frame->strides[0];
408
static void convert_float_to_32(gavl_video_frame_t * in_frame,
409
gavl_video_frame_t * out_frame,
410
int width, int height)
416
uint8_t * out_pixel_save = out_frame->planes[0];
417
uint8_t * in_pixel_save = in_frame->planes[0];
419
// fprintf(stderr, "convert_float_to_32: %d %d\n",
420
// in_frame->strides[0], out_frame->strides[0]);
421
for(i = 0; i < height; i++)
423
in_pixel = (float*)in_pixel_save;
424
out_pixel = out_pixel_save;
425
for(j = 0; j < width; j++)
427
i_tmp = (int)(in_pixel[0] * 255.0 + 0.5);
428
out_pixel[0] = RECLIP(i_tmp);
429
i_tmp = (int)(in_pixel[1] * 255.0 + 0.5);
430
out_pixel[1] = RECLIP(i_tmp);
431
i_tmp = (int)(in_pixel[2] * 255.0 + 0.5);
432
out_pixel[2] = RECLIP(i_tmp);
433
i_tmp = (int)(in_pixel[3] * 255.0 + 0.5);
434
out_pixel[3] = RECLIP(i_tmp);
438
in_pixel_save += in_frame->strides[0];
439
out_pixel_save += out_frame->strides[0];
444
static void convert_YUV_420_P_to_RGB24(gavl_video_frame_t * in_frame,
445
gavl_video_frame_t * out_frame,
446
int width, int height)
455
uint8_t * out_pixel_save = out_frame->planes[0];
456
uint8_t * in_y_save = in_frame->planes[0];
457
uint8_t * in_u_save = in_frame->planes[1];
458
uint8_t * in_v_save = in_frame->planes[2];
460
for(i = 0; i < height/2; i++)
465
out_pixel = out_pixel_save;
469
for(j = 0; j < width/2; j++)
471
YUV_2_RGB(*in_y, *in_u, *in_v,
472
out_pixel[0], out_pixel[1], out_pixel[2]);
475
YUV_2_RGB(*in_y, *in_u, *in_v,
476
out_pixel[0], out_pixel[1], out_pixel[2]);
482
out_pixel_save += out_frame->strides[0];
483
in_y_save += in_frame->strides[0];
487
out_pixel = out_pixel_save;
491
for(j = 0; j < width/2; j++)
493
YUV_2_RGB(*in_y, *in_u, *in_v,
494
out_pixel[0], out_pixel[1], out_pixel[2]);
497
YUV_2_RGB(*in_y, *in_u, *in_v,
498
out_pixel[0], out_pixel[1], out_pixel[2]);
504
out_pixel_save += out_frame->strides[0];
505
in_y_save += in_frame->strides[0];
507
in_u_save += in_frame->strides[1];
508
in_v_save += in_frame->strides[2];
512
static void convert_YUV_410_P_to_RGB24(gavl_video_frame_t * in_frame,
513
gavl_video_frame_t * out_frame,
514
int width, int height)
523
uint8_t * out_pixel_save = out_frame->planes[0];
524
uint8_t * in_y_save = in_frame->planes[0];
525
uint8_t * in_u_save = in_frame->planes[1];
526
uint8_t * in_v_save = in_frame->planes[2];
528
for(i = 0; i < height/4; i++)
533
out_pixel = out_pixel_save;
537
for(j = 0; j < width/4; j++)
539
YUV_2_RGB(*in_y, *in_u, *in_v,
540
out_pixel[0], out_pixel[1], out_pixel[2]);
543
YUV_2_RGB(*in_y, *in_u, *in_v,
544
out_pixel[0], out_pixel[1], out_pixel[2]);
547
YUV_2_RGB(*in_y, *in_u, *in_v,
548
out_pixel[0], out_pixel[1], out_pixel[2]);
551
YUV_2_RGB(*in_y, *in_u, *in_v,
552
out_pixel[0], out_pixel[1], out_pixel[2]);
558
out_pixel_save += out_frame->strides[0];
559
in_y_save += in_frame->strides[0];
563
out_pixel = out_pixel_save;
567
for(j = 0; j < width/4; j++)
569
YUV_2_RGB(*in_y, *in_u, *in_v,
570
out_pixel[0], out_pixel[1], out_pixel[2]);
573
YUV_2_RGB(*in_y, *in_u, *in_v,
574
out_pixel[0], out_pixel[1], out_pixel[2]);
577
YUV_2_RGB(*in_y, *in_u, *in_v,
578
out_pixel[0], out_pixel[1], out_pixel[2]);
581
YUV_2_RGB(*in_y, *in_u, *in_v,
582
out_pixel[0], out_pixel[1], out_pixel[2]);
588
out_pixel_save += out_frame->strides[0];
589
in_y_save += in_frame->strides[0];
591
out_pixel = out_pixel_save;
595
for(j = 0; j < width/4; j++)
597
YUV_2_RGB(*in_y, *in_u, *in_v,
598
out_pixel[0], out_pixel[1], out_pixel[2]);
601
YUV_2_RGB(*in_y, *in_u, *in_v,
602
out_pixel[0], out_pixel[1], out_pixel[2]);
605
YUV_2_RGB(*in_y, *in_u, *in_v,
606
out_pixel[0], out_pixel[1], out_pixel[2]);
609
YUV_2_RGB(*in_y, *in_u, *in_v,
610
out_pixel[0], out_pixel[1], out_pixel[2]);
616
out_pixel_save += out_frame->strides[0];
617
in_y_save += in_frame->strides[0];
619
out_pixel = out_pixel_save;
623
for(j = 0; j < width/4; j++)
625
YUV_2_RGB(*in_y, *in_u, *in_v,
626
out_pixel[0], out_pixel[1], out_pixel[2]);
629
YUV_2_RGB(*in_y, *in_u, *in_v,
630
out_pixel[0], out_pixel[1], out_pixel[2]);
633
YUV_2_RGB(*in_y, *in_u, *in_v,
634
out_pixel[0], out_pixel[1], out_pixel[2]);
637
YUV_2_RGB(*in_y, *in_u, *in_v,
638
out_pixel[0], out_pixel[1], out_pixel[2]);
644
out_pixel_save += out_frame->strides[0];
645
in_y_save += in_frame->strides[0];
648
in_u_save += in_frame->strides[1];
649
in_v_save += in_frame->strides[2];
653
static void convert_YUVJ_420_P_to_RGB24(gavl_video_frame_t * in_frame,
654
gavl_video_frame_t * out_frame,
655
int width, int height)
664
uint8_t * out_pixel_save = out_frame->planes[0];
665
uint8_t * in_y_save = in_frame->planes[0];
666
uint8_t * in_u_save = in_frame->planes[1];
667
uint8_t * in_v_save = in_frame->planes[2];
669
for(i = 0; i < height/2; i++)
674
out_pixel = out_pixel_save;
678
for(j = 0; j < width/2; j++)
680
YUVJ_2_RGB(*in_y, *in_u, *in_v,
681
out_pixel[0], out_pixel[1], out_pixel[2]);
684
YUVJ_2_RGB(*in_y, *in_u, *in_v,
685
out_pixel[0], out_pixel[1], out_pixel[2]);
691
out_pixel_save += out_frame->strides[0];
692
in_y_save += in_frame->strides[0];
696
out_pixel = out_pixel_save;
700
for(j = 0; j < width/2; j++)
702
YUVJ_2_RGB(*in_y, *in_u, *in_v,
703
out_pixel[0], out_pixel[1], out_pixel[2]);
706
YUVJ_2_RGB(*in_y, *in_u, *in_v,
707
out_pixel[0], out_pixel[1], out_pixel[2]);
713
out_pixel_save += out_frame->strides[0];
714
in_y_save += in_frame->strides[0];
716
in_u_save += in_frame->strides[1];
717
in_v_save += in_frame->strides[2];
721
static void convert_YUV_422_P_to_RGB24(gavl_video_frame_t * in_frame,
722
gavl_video_frame_t * out_frame,
723
int width, int height)
733
uint8_t * out_pixel_save = out_frame->planes[0];
734
uint8_t * in_y_save = in_frame->planes[0];
735
uint8_t * in_u_save = in_frame->planes[1];
736
uint8_t * in_v_save = in_frame->planes[2];
738
for(i = 0; i < height; i++)
743
out_pixel = out_pixel_save;
744
for(j = 0; j < width/2; j++)
746
YUV_2_RGB(*in_y, *in_u, *in_v,
747
out_pixel[0], out_pixel[1], out_pixel[2]);
751
YUV_2_RGB(*in_y, *in_u, *in_v,
752
out_pixel[0], out_pixel[1], out_pixel[2]);
758
out_pixel_save += out_frame->strides[0];
759
in_y_save += in_frame->strides[0];
760
in_u_save += in_frame->strides[1];
761
in_v_save += in_frame->strides[2];
765
static void convert_YUV_422_P_16_to_RGB24(gavl_video_frame_t * in_frame,
766
gavl_video_frame_t * out_frame,
767
int width, int height)
777
uint8_t * out_pixel_save = out_frame->planes[0];
778
uint8_t * in_y_save = in_frame->planes[0];
779
uint8_t * in_u_save = in_frame->planes[1];
780
uint8_t * in_v_save = in_frame->planes[2];
782
for(i = 0; i < height; i++)
784
in_y = (uint16_t*)in_y_save;
785
in_u = (uint16_t*)in_u_save;
786
in_v = (uint16_t*)in_v_save;
787
out_pixel = out_pixel_save;
788
for(j = 0; j < width/2; j++)
790
YUV_2_RGB(((*in_y)>>8), ((*in_u)>>8), ((*in_v)>>8),
791
out_pixel[0], out_pixel[1], out_pixel[2]);
795
YUV_2_RGB(((*in_y)>>8), ((*in_u)>>8), ((*in_v)>>8),
796
out_pixel[0], out_pixel[1], out_pixel[2]);
802
out_pixel_save += out_frame->strides[0];
803
in_y_save += in_frame->strides[0];
804
in_u_save += in_frame->strides[1];
805
in_v_save += in_frame->strides[2];
809
static void convert_YUV_411_P_to_RGB24(gavl_video_frame_t * in_frame,
810
gavl_video_frame_t * out_frame,
811
int width, int height)
821
uint8_t * out_pixel_save = out_frame->planes[0];
822
uint8_t * in_y_save = in_frame->planes[0];
823
uint8_t * in_u_save = in_frame->planes[1];
824
uint8_t * in_v_save = in_frame->planes[2];
826
for(i = 0; i < height; i++)
831
out_pixel = out_pixel_save;
832
for(j = 0; j < width/4; j++)
834
YUV_2_RGB(*in_y, *in_u, *in_v,
835
out_pixel[0], out_pixel[1], out_pixel[2]);
839
YUV_2_RGB(*in_y, *in_u, *in_v,
840
out_pixel[0], out_pixel[1], out_pixel[2]);
844
YUV_2_RGB(*in_y, *in_u, *in_v,
845
out_pixel[0], out_pixel[1], out_pixel[2]);
849
YUV_2_RGB(*in_y, *in_u, *in_v,
850
out_pixel[0], out_pixel[1], out_pixel[2]);
856
out_pixel_save += out_frame->strides[0];
857
in_y_save += in_frame->strides[0];
858
in_u_save += in_frame->strides[1];
859
in_v_save += in_frame->strides[2];
864
static void convert_YUVJ_422_P_to_RGB24(gavl_video_frame_t * in_frame,
865
gavl_video_frame_t * out_frame,
866
int width, int height)
876
uint8_t * out_pixel_save = out_frame->planes[0];
877
uint8_t * in_y_save = in_frame->planes[0];
878
uint8_t * in_u_save = in_frame->planes[1];
879
uint8_t * in_v_save = in_frame->planes[2];
881
for(i = 0; i < height; i++)
886
out_pixel = out_pixel_save;
887
for(j = 0; j < width/2; j++)
889
YUVJ_2_RGB(*in_y, *in_u, *in_v,
890
out_pixel[0], out_pixel[1], out_pixel[2]);
894
YUVJ_2_RGB(*in_y, *in_u, *in_v,
895
out_pixel[0], out_pixel[1], out_pixel[2]);
901
out_pixel_save += out_frame->strides[0];
902
in_y_save += in_frame->strides[0];
903
in_u_save += in_frame->strides[1];
904
in_v_save += in_frame->strides[2];
908
static void convert_YUV_444_P_to_RGB24(gavl_video_frame_t * in_frame,
909
gavl_video_frame_t * out_frame,
910
int width, int height)
920
uint8_t * out_pixel_save = out_frame->planes[0];
921
uint8_t * in_y_save = in_frame->planes[0];
922
uint8_t * in_u_save = in_frame->planes[1];
923
uint8_t * in_v_save = in_frame->planes[2];
925
for(i = 0; i < height; i++)
930
out_pixel = out_pixel_save;
931
for(j = 0; j < width; j++)
933
YUV_2_RGB(*in_y, *in_u, *in_v,
934
out_pixel[0], out_pixel[1], out_pixel[2]);
940
out_pixel_save += out_frame->strides[0];
941
in_y_save += in_frame->strides[0];
942
in_u_save += in_frame->strides[1];
943
in_v_save += in_frame->strides[2];
947
static void convert_YUV_444_P_16_to_RGB24(gavl_video_frame_t * in_frame,
948
gavl_video_frame_t * out_frame,
949
int width, int height)
959
uint8_t * out_pixel_save = out_frame->planes[0];
960
uint8_t * in_y_save = in_frame->planes[0];
961
uint8_t * in_u_save = in_frame->planes[1];
962
uint8_t * in_v_save = in_frame->planes[2];
964
for(i = 0; i < height; i++)
966
in_y = (uint16_t*)in_y_save;
967
in_u = (uint16_t*)in_u_save;
968
in_v = (uint16_t*)in_v_save;
969
out_pixel = out_pixel_save;
970
for(j = 0; j < width; j++)
972
YUV_2_RGB(((*in_y)>>8), ((*in_u)>>8), ((*in_v)>>8),
973
out_pixel[0], out_pixel[1], out_pixel[2]);
979
out_pixel_save += out_frame->strides[0];
980
in_y_save += in_frame->strides[0];
981
in_u_save += in_frame->strides[1];
982
in_v_save += in_frame->strides[2];
987
static void convert_YUVJ_444_P_to_RGB24(gavl_video_frame_t * in_frame,
988
gavl_video_frame_t * out_frame,
989
int width, int height)
999
uint8_t * out_pixel_save = out_frame->planes[0];
1000
uint8_t * in_y_save = in_frame->planes[0];
1001
uint8_t * in_u_save = in_frame->planes[1];
1002
uint8_t * in_v_save = in_frame->planes[2];
1004
for(i = 0; i < height; i++)
1009
out_pixel = out_pixel_save;
1010
for(j = 0; j < width; j++)
1012
YUVJ_2_RGB(*in_y, *in_u, *in_v,
1013
out_pixel[0], out_pixel[1], out_pixel[2]);
1019
out_pixel_save += out_frame->strides[0];
1020
in_y_save += in_frame->strides[0];
1021
in_u_save += in_frame->strides[1];
1022
in_v_save += in_frame->strides[2];
1026
static void convert_YUY2_to_RGB24(gavl_video_frame_t * in_frame,
1027
gavl_video_frame_t * out_frame,
1028
int width, int height)
1033
uint8_t * out_pixel;
1035
uint8_t * out_pixel_save = out_frame->planes[0];
1036
uint8_t * in_pixel_save = in_frame->planes[0];
1038
for(i = 0; i < height; i++)
1040
in_pixel = in_pixel_save;
1041
out_pixel = out_pixel_save;
1042
for(j = 0; j < width/2; j++)
1044
YUV_2_RGB(in_pixel[0], in_pixel[1], in_pixel[3],
1045
out_pixel[0], out_pixel[1], out_pixel[2]);
1047
YUV_2_RGB(in_pixel[2], in_pixel[1], in_pixel[3],
1048
out_pixel[0], out_pixel[1], out_pixel[2]);
1052
in_pixel_save += in_frame->strides[0];
1053
out_pixel_save += out_frame->strides[0];
1057
static void convert_UYVY_to_RGB24(gavl_video_frame_t * in_frame,
1058
gavl_video_frame_t * out_frame,
1059
int width, int height)
1064
uint8_t * out_pixel;
1066
uint8_t * out_pixel_save = out_frame->planes[0];
1067
uint8_t * in_pixel_save = in_frame->planes[0];
1069
for(i = 0; i < height; i++)
1071
in_pixel = in_pixel_save;
1072
out_pixel = out_pixel_save;
1073
for(j = 0; j < width/2; j++)
1075
YUV_2_RGB(in_pixel[1], in_pixel[0], in_pixel[2],
1076
out_pixel[0], out_pixel[1], out_pixel[2]);
1078
YUV_2_RGB(in_pixel[3], in_pixel[0], in_pixel[2],
1079
out_pixel[0], out_pixel[1], out_pixel[2]);
1083
in_pixel_save += in_frame->strides[0];
1084
out_pixel_save += out_frame->strides[0];
1089
* This function writes a png file of the video frame in the given format
1090
* The format can have all supported colorspaces, so we'll convert them
1091
* without the use of gavl (i.e. in less optimized but bugfree code)
1094
/* On error, FALSE is returned */
1096
int write_file(const char * name,
1097
gavl_video_frame_t * frame, gavl_video_format_t * format)
1101
gavl_video_frame_t * tmp_frame;
1102
gavl_video_frame_t * out_frame = (gavl_video_frame_t *)0;
1103
gavl_video_format_t tmp_format;
1106
char ** row_pointers;
1107
png_structp png_ptr; png_infop info_ptr;
1109
FILE *fp = fopen(name, "wb");
1112
fprintf(stderr, "Cannot open file %s, exiting \n", name);
1117
png_ptr = png_create_write_struct
1118
(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
1122
info_ptr = png_create_info_struct(png_ptr);
1125
png_destroy_write_struct(&png_ptr,
1130
setjmp(png_jmpbuf(png_ptr));
1132
png_init_io(png_ptr, fp);
1134
if(gavl_pixelformat_has_alpha(format->pixelformat))
1135
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1137
color_type = PNG_COLOR_TYPE_RGB;
1139
png_set_IHDR(png_ptr, info_ptr, format->image_width, format->image_height,
1140
8, color_type, PNG_INTERLACE_NONE,
1141
PNG_COMPRESSION_TYPE_DEFAULT,
1142
PNG_FILTER_TYPE_DEFAULT);
1144
/* Set up the temporary video frame */
1146
tmp_format.image_width = format->image_width;
1147
tmp_format.image_height = format->image_height;
1149
tmp_format.frame_width = format->frame_width;
1150
tmp_format.frame_height = format->frame_height;
1152
/* We convert everything to either RGB24, BGR24 or RGBA */
1154
switch(format->pixelformat)
1160
png_transforms = PNG_TRANSFORM_BGR;
1161
tmp_format.pixelformat = GAVL_BGR_24;
1164
case GAVL_RGBA_FLOAT:
1166
png_transforms = PNG_TRANSFORM_IDENTITY;
1167
tmp_format.pixelformat = GAVL_RGBA_32;
1170
png_transforms = PNG_TRANSFORM_IDENTITY;
1171
tmp_format.pixelformat = GAVL_RGB_24;
1174
/* Allocate the video frame structure */
1178
switch(format->pixelformat)
1182
tmp_frame = gavl_video_frame_create(&tmp_format);
1183
convert_15_to_24(frame, tmp_frame, format->image_width, format->image_height);
1184
out_frame = tmp_frame;
1188
tmp_frame = gavl_video_frame_create(&tmp_format);
1189
convert_16_to_24(frame, tmp_frame, format->image_width, format->image_height);
1190
out_frame = tmp_frame;
1198
tmp_frame = gavl_video_frame_create(&tmp_format);
1199
convert_48_to_24(frame, tmp_frame, format->image_width, format->image_height);
1200
out_frame = tmp_frame;
1203
tmp_frame = gavl_video_frame_create(&tmp_format);
1204
convert_64_to_32(frame, tmp_frame, format->image_width, format->image_height);
1205
out_frame = tmp_frame;
1207
case GAVL_RGB_FLOAT:
1208
tmp_frame = gavl_video_frame_create(&tmp_format);
1209
convert_float_to_24(frame, tmp_frame, format->image_width, format->image_height);
1210
out_frame = tmp_frame;
1212
case GAVL_RGBA_FLOAT:
1213
tmp_frame = gavl_video_frame_create(&tmp_format);
1214
convert_float_to_32(frame, tmp_frame, format->image_width, format->image_height);
1215
out_frame = tmp_frame;
1219
tmp_frame = gavl_video_frame_create(&tmp_format);
1220
convert_32_to_24(frame, tmp_frame, format->image_width, format->image_height);
1221
out_frame = tmp_frame;
1224
tmp_frame = gavl_video_frame_create(&tmp_format);
1225
convert_YUY2_to_RGB24(frame, tmp_frame, format->image_width, format->image_height);
1226
out_frame = tmp_frame;
1229
tmp_frame = gavl_video_frame_create(&tmp_format);
1230
convert_YUVA_32_to_RGBA_32(frame, tmp_frame, format->image_width, format->image_height);
1231
out_frame = tmp_frame;
1234
tmp_frame = gavl_video_frame_create(&tmp_format);
1235
convert_UYVY_to_RGB24(frame, tmp_frame, format->image_width, format->image_height);
1236
out_frame = tmp_frame;
1238
case GAVL_YUV_420_P:
1239
tmp_frame = gavl_video_frame_create(&tmp_format);
1240
convert_YUV_420_P_to_RGB24(frame, tmp_frame, format->image_width,
1241
format->image_height);
1242
out_frame = tmp_frame;
1244
case GAVL_YUV_410_P:
1245
tmp_frame = gavl_video_frame_create(&tmp_format);
1246
convert_YUV_410_P_to_RGB24(frame, tmp_frame, format->image_width,
1247
format->image_height);
1248
out_frame = tmp_frame;
1250
case GAVL_YUV_422_P:
1251
tmp_frame = gavl_video_frame_create(&tmp_format);
1252
convert_YUV_422_P_to_RGB24(frame, tmp_frame, format->image_width,
1253
format->image_height);
1254
out_frame = tmp_frame;
1256
case GAVL_YUV_422_P_16:
1257
tmp_frame = gavl_video_frame_create(&tmp_format);
1258
convert_YUV_422_P_16_to_RGB24(frame, tmp_frame, format->image_width,
1259
format->image_height);
1260
out_frame = tmp_frame;
1262
case GAVL_YUV_411_P:
1263
tmp_frame = gavl_video_frame_create(&tmp_format);
1264
convert_YUV_411_P_to_RGB24(frame, tmp_frame, format->image_width,
1265
format->image_height);
1266
out_frame = tmp_frame;
1268
case GAVL_YUV_444_P:
1269
tmp_frame = gavl_video_frame_create(&tmp_format);
1270
convert_YUV_444_P_to_RGB24(frame, tmp_frame, format->image_width,
1271
format->image_height);
1272
out_frame = tmp_frame;
1274
case GAVL_YUV_444_P_16:
1275
tmp_frame = gavl_video_frame_create(&tmp_format);
1276
convert_YUV_444_P_16_to_RGB24(frame, tmp_frame, format->image_width,
1277
format->image_height);
1278
out_frame = tmp_frame;
1280
case GAVL_YUVJ_420_P:
1281
tmp_frame = gavl_video_frame_create(&tmp_format);
1282
convert_YUVJ_420_P_to_RGB24(frame, tmp_frame, format->image_width,
1283
format->image_height);
1284
out_frame = tmp_frame;
1286
case GAVL_YUVJ_422_P:
1287
tmp_frame = gavl_video_frame_create(&tmp_format);
1288
convert_YUVJ_422_P_to_RGB24(frame, tmp_frame, format->image_width,
1289
format->image_height);
1290
out_frame = tmp_frame;
1292
case GAVL_YUVJ_444_P:
1293
tmp_frame = gavl_video_frame_create(&tmp_format);
1294
convert_YUVJ_444_P_to_RGB24(frame, tmp_frame, format->image_width,
1295
format->image_height);
1296
out_frame = tmp_frame;
1298
case GAVL_PIXELFORMAT_NONE:
1302
/* Set up the row pointers */
1304
row_pointers = malloc(format->image_height * sizeof(char*));
1306
for(i = 0; i < format->image_height; i++)
1308
(char*)(out_frame->planes[0] + i * out_frame->strides[0]);
1310
png_set_rows(png_ptr, info_ptr, (png_bytep*)row_pointers);
1312
png_write_png(png_ptr, info_ptr, png_transforms, NULL);
1317
gavl_video_frame_destroy(tmp_frame);
1318
png_destroy_write_struct(&png_ptr, &info_ptr);
1324
/**********************************************************
1325
* Test picture generator
1326
**********************************************************/
1328
static uint8_t colorbar_colors[16][2][3] =
1331
{ 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0, } /* White */
1334
{ 1.0, 1.0, 1.0 }, { 1.0, 1.0, 1.0, }
1337
{ 0.0, 0.0, 0.0 }, { 1.0, 1.0, 0.0, } /* Yellow */
1340
{ 1.0, 1.0, 1.0 }, { 1.0, 1.0, 0.0, }
1343
{ 0.0, 0.0, 0.0 }, { 0.0, 1.0, 1.0, } /* Cyan */
1346
{ 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0, }
1349
{ 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, } /* Green */
1352
{ 1.0, 1.0, 1.0 }, { 0.0, 1.0, 0.0, }
1355
{ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 1.0, } /* Magenta */
1358
{ 1.0, 1.0, 1.0 }, { 1.0, 0.0, 1.0, }
1361
{ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, } /* Red */
1364
{ 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0, }
1367
{ 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, } /* Blue */
1370
{ 1.0, 1.0, 1.0 }, { 0.0, 0.0, 1.0, }
1373
{ 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, }, /* Black */
1376
{ 1.0, 1.0, 1.0 }, { 0.0, 0.0, 0.0, }
1380
// #define COLORBAR_HORIZONTAL
1382
void get_pixel_colorbar(int x, int y,
1386
float r_tmp, g_tmp, b_tmp, alpha;
1388
#ifdef COLORBAR_HORIZONTAL
1389
alpha = (float)(TEST_PICTURE_WIDTH - x) / (float)(TEST_PICTURE_WIDTH);
1390
color_index = (y * 16) / (TEST_PICTURE_HEIGHT - 1);
1392
alpha = (float)(TEST_PICTURE_HEIGHT - y) / (float)(TEST_PICTURE_HEIGHT);
1393
color_index = (x * 16) / (TEST_PICTURE_WIDTH - 1);
1395
if(color_index >= 16)
1398
alpha = RECLIP_FLOAT(alpha);
1400
/* fprintf(stderr, "y: %d alpha: %d\n", y ,(int)alpha); */
1402
// colorbar_colors[16][2][3]
1404
r_tmp = (colorbar_colors[color_index][0][0] * (1.0 - alpha) +
1405
colorbar_colors[color_index][1][0] * alpha);
1406
g_tmp = (colorbar_colors[color_index][0][1] * (1.0 - alpha) +
1407
colorbar_colors[color_index][1][1] * alpha);
1408
b_tmp = (colorbar_colors[color_index][0][2] * (1.0 - alpha) +
1409
colorbar_colors[color_index][1][2] * alpha);
1411
/* r_tmp = colorbar_colors[color_index][1][0]; */
1412
/* g_tmp = colorbar_colors[color_index][1][1]; */
1413
/* b_tmp = colorbar_colors[color_index][1][2]; */
1415
// a_tmp = 0xFF; /* Not used for now */
1417
ret[0] = RECLIP_FLOAT(r_tmp);
1418
ret[1] = RECLIP_FLOAT(g_tmp);
1419
ret[2] = RECLIP_FLOAT(b_tmp);
1420
ret[3] = RECLIP_FLOAT(alpha);
1424
#define PACK_RGB16(_r,_g,_b,_pixel) \
1425
_pixel=((((((_r<<5)&0xff00)|_g)<<6)&0xfff00)|_b)>>3
1427
#define PACK_RGB15(_r,_g,_b,_pixel) \
1428
_pixel=((((((_r<<5)&0xff00)|_g)<<5)&0xfff00)|_b)>>3
1430
#define FLOAT_TO_8(f) (int)(f * 255.0 + 0.5)
1431
#define FLOAT_TO_16(f) (int)(f * 65535.0 + 0.5)
1433
#define RGB_TO_Y() yuv_f[0] = (0.299*tmp_f[0]+0.587*tmp_f[1]+0.114*tmp_f[2])
1435
#define RGB_TO_YUV() RGB_TO_Y(); \
1436
yuv_f[1] = (-0.168736 * tmp_f[0] -0.331264 * tmp_f[1] + 0.500 * tmp_f[2]); \
1437
yuv_f[2] = (0.500 * tmp_f[0] -0.418688 * tmp_f[1] - 0.081312 * tmp_f[2])
1439
#define Y_TO_8(d) d=(int)(yuv_f[0]*219.0+0.5)+16
1440
#define U_TO_8(d) d=(int)(yuv_f[1]*224.0+0.5)+128
1441
#define V_TO_8(d) d=(int)(yuv_f[2]*224.0+0.5)+128
1443
#define Y_TO_16(d) d=((int)(yuv_f[0]*219.0+0.5)+16) << 8;
1444
#define U_TO_16(d) d=((int)(yuv_f[1]*224.0+0.5)+128) << 8;
1445
#define V_TO_16(d) d=((int)(yuv_f[2]*224.0+0.5)+128) << 8;
1447
#define YJ_TO_8(d) d=RECLIP((int)(yuv_f[0]*255.0+0.5))
1448
#define UJ_TO_8(d) d=RECLIP((int)(yuv_f[1]*255.0+0.5)+128)
1449
#define VJ_TO_8(d) d=RECLIP((int)(yuv_f[2]*255.0+0.5)+128)
1452
gavl_video_frame_t * create_picture(gavl_pixelformat_t pixelformat,
1453
void (*get_pixel)(int x, int y,
1466
uint16_t * pixel_16;
1467
float * pixel_float;
1477
gavl_video_frame_t * ret;
1478
gavl_video_format_t format;
1479
format.pixelformat = pixelformat;
1480
format.image_width = TEST_PICTURE_WIDTH;
1481
format.image_height = TEST_PICTURE_HEIGHT;
1483
format.frame_width = TEST_PICTURE_WIDTH;
1484
format.frame_height = TEST_PICTURE_HEIGHT;
1486
format.pixel_width = 1;
1487
format.pixel_height = 1;
1490
ret = gavl_video_frame_create(&format);
1495
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1497
pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
1498
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1500
get_pixel(col, row, tmp_f);
1502
r_tmp = FLOAT_TO_8(tmp_f[0]);
1503
r_tmp = RECLIP(r_tmp);
1504
g_tmp = FLOAT_TO_8(tmp_f[1]);
1505
g_tmp = RECLIP(g_tmp);
1506
b_tmp = FLOAT_TO_8(tmp_f[2]);
1507
b_tmp = RECLIP(b_tmp);
1509
PACK_RGB15(r_tmp, g_tmp, b_tmp, *pixel_16);
1515
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1517
pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
1518
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1520
get_pixel(col, row, tmp_f);
1522
r_tmp = FLOAT_TO_8(tmp_f[0]);
1523
r_tmp = RECLIP(r_tmp);
1524
g_tmp = FLOAT_TO_8(tmp_f[1]);
1525
g_tmp = RECLIP(g_tmp);
1526
b_tmp = FLOAT_TO_8(tmp_f[2]);
1527
b_tmp = RECLIP(b_tmp);
1529
PACK_RGB15(b_tmp, g_tmp, r_tmp, *pixel_16);
1535
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1537
pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
1538
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1540
get_pixel(col, row, tmp_f);
1542
r_tmp = FLOAT_TO_8(tmp_f[0]);
1543
r_tmp = RECLIP(r_tmp);
1544
g_tmp = FLOAT_TO_8(tmp_f[1]);
1545
g_tmp = RECLIP(g_tmp);
1546
b_tmp = FLOAT_TO_8(tmp_f[2]);
1547
b_tmp = RECLIP(b_tmp);
1549
PACK_RGB16(r_tmp, g_tmp, b_tmp, *pixel_16);
1555
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1557
pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
1558
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1560
get_pixel(col, row, tmp_f);
1562
r_tmp = FLOAT_TO_8(tmp_f[0]);
1563
r_tmp = RECLIP(r_tmp);
1564
g_tmp = FLOAT_TO_8(tmp_f[1]);
1565
g_tmp = RECLIP(g_tmp);
1566
b_tmp = FLOAT_TO_8(tmp_f[2]);
1567
b_tmp = RECLIP(b_tmp);
1568
PACK_RGB16(b_tmp, g_tmp, r_tmp, *pixel_16);
1574
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1576
pixel = ret->planes[0] + row * ret->strides[0];
1577
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1579
get_pixel(col, row, tmp_f);
1581
r_tmp = FLOAT_TO_8(tmp_f[0]);
1582
r_tmp = RECLIP(r_tmp);
1583
g_tmp = FLOAT_TO_8(tmp_f[1]);
1584
g_tmp = RECLIP(g_tmp);
1585
b_tmp = FLOAT_TO_8(tmp_f[2]);
1586
b_tmp = RECLIP(b_tmp);
1597
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1599
pixel = ret->planes[0] + row * ret->strides[0];
1600
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1602
get_pixel(col, row, tmp_f);
1604
r_tmp = FLOAT_TO_8(tmp_f[0]);
1605
r_tmp = RECLIP(r_tmp);
1606
g_tmp = FLOAT_TO_8(tmp_f[1]);
1607
g_tmp = RECLIP(g_tmp);
1608
b_tmp = FLOAT_TO_8(tmp_f[2]);
1609
b_tmp = RECLIP(b_tmp);
1619
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1621
pixel = ret->planes[0] + row * ret->strides[0];
1622
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1624
get_pixel(col, row, tmp_f);
1626
r_tmp = FLOAT_TO_8(tmp_f[0]);
1627
r_tmp = RECLIP(r_tmp);
1628
g_tmp = FLOAT_TO_8(tmp_f[1]);
1629
g_tmp = RECLIP(g_tmp);
1630
b_tmp = FLOAT_TO_8(tmp_f[2]);
1631
b_tmp = RECLIP(b_tmp);
1641
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1643
pixel = ret->planes[0] + row * ret->strides[0];
1644
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1646
get_pixel(col, row, tmp_f);
1648
r_tmp = FLOAT_TO_8(tmp_f[0]);
1649
r_tmp = RECLIP(r_tmp);
1650
g_tmp = FLOAT_TO_8(tmp_f[1]);
1651
g_tmp = RECLIP(g_tmp);
1652
b_tmp = FLOAT_TO_8(tmp_f[2]);
1653
b_tmp = RECLIP(b_tmp);
1663
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1665
pixel = ret->planes[0] + row * ret->strides[0];
1666
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1668
get_pixel(col, row, tmp_f);
1670
r_tmp = FLOAT_TO_8(tmp_f[0]);
1671
r_tmp = RECLIP(r_tmp);
1672
g_tmp = FLOAT_TO_8(tmp_f[1]);
1673
g_tmp = RECLIP(g_tmp);
1674
b_tmp = FLOAT_TO_8(tmp_f[2]);
1675
b_tmp = RECLIP(b_tmp);
1676
a_tmp = FLOAT_TO_8(tmp_f[3]);
1677
a_tmp = RECLIP(a_tmp);
1688
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1690
pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
1691
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1693
get_pixel(col, row, tmp_f);
1695
r_tmp = FLOAT_TO_16(tmp_f[0]);
1696
r_tmp = RECLIP_16(r_tmp);
1697
g_tmp = FLOAT_TO_16(tmp_f[1]);
1698
g_tmp = RECLIP_16(g_tmp);
1699
b_tmp = FLOAT_TO_16(tmp_f[2]);
1700
b_tmp = RECLIP_16(b_tmp);
1702
pixel_16[0] = r_tmp;
1703
pixel_16[1] = g_tmp;
1704
pixel_16[2] = b_tmp;
1710
// fprintf(stderr, "STRIDES: %d\n", ret->strides[0]);
1711
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1713
pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
1714
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1716
get_pixel(col, row, tmp_f);
1718
r_tmp = FLOAT_TO_16(tmp_f[0]);
1719
r_tmp = RECLIP_16(r_tmp);
1721
g_tmp = FLOAT_TO_16(tmp_f[1]);
1722
g_tmp = RECLIP_16(g_tmp);
1724
b_tmp = FLOAT_TO_16(tmp_f[2]);
1725
b_tmp = RECLIP_16(b_tmp);
1727
a_tmp = FLOAT_TO_16(tmp_f[3]);
1728
a_tmp = RECLIP_16(a_tmp);
1730
pixel_16[0] = r_tmp;
1731
pixel_16[1] = g_tmp;
1732
pixel_16[2] = b_tmp;
1733
pixel_16[3] = a_tmp;
1737
// gavl_video_frame_dump(ret, &format, "TEST");
1739
case GAVL_RGB_FLOAT:
1740
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1742
pixel_float = (float*)(ret->planes[0] + row * ret->strides[0]);
1743
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1745
get_pixel(col, row, tmp_f);
1747
pixel_float[0] = tmp_f[0];
1748
pixel_float[1] = tmp_f[1];
1749
pixel_float[2] = tmp_f[2];
1754
case GAVL_RGBA_FLOAT:
1755
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1757
pixel_float = (float*)(ret->planes[0] + row * ret->strides[0]);
1758
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1760
get_pixel(col, row, tmp_f);
1761
pixel_float[0] = tmp_f[0];
1762
pixel_float[1] = tmp_f[1];
1763
pixel_float[2] = tmp_f[2];
1764
pixel_float[3] = tmp_f[3];
1771
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1773
pixel = ret->planes[0] + row * ret->strides[0];
1774
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
1776
get_pixel(2*col, row, tmp_f);
1783
get_pixel(2*col+1, row, tmp_f);
1792
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1794
pixel = ret->planes[0] + row * ret->strides[0];
1795
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
1797
get_pixel(col, row, tmp_f);
1803
a_tmp = FLOAT_TO_8(tmp_f[3]);
1804
a_tmp = RECLIP(a_tmp);
1811
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
1813
pixel = ret->planes[0] + row * ret->strides[0];
1814
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
1816
get_pixel(2*col, row, tmp_f);
1824
get_pixel(2*col+1, row, tmp_f);
1831
case GAVL_YUV_420_P:
1832
for(row = 0; row < TEST_PICTURE_HEIGHT/2; row++)
1834
y = ret->planes[0] + 2 * row * ret->strides[0];
1835
u = ret->planes[1] + row * ret->strides[1];
1836
v = ret->planes[2] + row * ret->strides[2];
1838
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
1840
get_pixel(2*col, 2*row, tmp_f);
1849
get_pixel(2*col+1, 2*row, tmp_f);
1860
y = ret->planes[0] + (2 * row + 1) * ret->strides[0];
1862
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
1864
get_pixel(2*col, 2*row+1, tmp_f);
1871
get_pixel(2*col+1, 2*row+1, tmp_f);
1880
case GAVL_YUV_410_P:
1881
for(row = 0; row < TEST_PICTURE_HEIGHT/4; row++)
1883
y = ret->planes[0] + 4 * row * ret->strides[0];
1884
u = ret->planes[1] + row * ret->strides[1];
1885
v = ret->planes[2] + row * ret->strides[2];
1887
for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
1889
get_pixel(4*col, 4*row, tmp_f);
1896
get_pixel(4*col+1, 4*row, tmp_f);
1901
get_pixel(4*col+2, 4*row, tmp_f);
1907
get_pixel(4*col+3, 4*row, tmp_f);
1917
y = ret->planes[0] + (4 * row + 1) * ret->strides[0];
1919
for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
1921
get_pixel(4*col, 4*row+1, tmp_f);
1927
get_pixel(4*col+1, 4*row+1, tmp_f);
1933
get_pixel(4*col+2, 4*row+1, tmp_f);
1939
get_pixel(4*col+3, 4*row+1, tmp_f);
1946
y = ret->planes[0] + (4 * row + 2) * ret->strides[0];
1948
for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
1950
get_pixel(4*col, 4*row+2, tmp_f);
1956
get_pixel(4*col+1, 4*row+2, tmp_f);
1961
get_pixel(4*col+2, 4*row+2, tmp_f);
1967
get_pixel(4*col+3, 4*row+2, tmp_f);
1974
y = ret->planes[0] + (4 * row + 3) * ret->strides[0];
1976
for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
1978
get_pixel(4*col, 4*row+3, tmp_f);
1984
get_pixel(4*col+1, 4*row+3, tmp_f);
1990
get_pixel(4*col+2, 4*row+3, tmp_f);
1996
get_pixel(4*col+3, 4*row+3, tmp_f);
2005
case GAVL_YUV_422_P:
2006
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2008
y = ret->planes[0] + row * ret->strides[0];
2009
u = ret->planes[1] + row * ret->strides[1];
2010
v = ret->planes[2] + row * ret->strides[2];
2012
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
2014
get_pixel(2* col, row, tmp_f);
2023
get_pixel(2* col + 1, row, tmp_f);
2033
case GAVL_YUV_422_P_16:
2034
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2036
y_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
2037
u_16 = (uint16_t*)(ret->planes[1] + row * ret->strides[1]);
2038
v_16 = (uint16_t*)(ret->planes[2] + row * ret->strides[2]);
2040
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
2042
get_pixel(2* col, row, tmp_f);
2051
get_pixel(2* col + 1, row, tmp_f);
2061
case GAVL_YUV_411_P:
2062
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2064
y = ret->planes[0] + row * ret->strides[0];
2065
u = ret->planes[1] + row * ret->strides[1];
2066
v = ret->planes[2] + row * ret->strides[2];
2068
for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
2070
get_pixel(4* col, row, tmp_f);
2079
get_pixel(4* col + 1, row, tmp_f);
2085
get_pixel(4* col + 2, row, tmp_f);
2090
get_pixel(4* col + 3, row, tmp_f);
2101
case GAVL_YUV_444_P:
2102
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2104
y = ret->planes[0] + row * ret->strides[0];
2105
u = ret->planes[1] + row * ret->strides[1];
2106
v = ret->planes[2] + row * ret->strides[2];
2108
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
2110
get_pixel(col, row, tmp_f);
2123
case GAVL_YUV_444_P_16:
2124
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2126
y_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
2127
u_16 = (uint16_t*)(ret->planes[1] + row * ret->strides[1]);
2128
v_16 = (uint16_t*)(ret->planes[2] + row * ret->strides[2]);
2130
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
2132
get_pixel(col, row, tmp_f);
2145
case GAVL_YUVJ_420_P:
2146
for(row = 0; row < TEST_PICTURE_HEIGHT/2; row++)
2148
y = ret->planes[0] + 2 * row * ret->strides[0];
2149
u = ret->planes[1] + row * ret->strides[1];
2150
v = ret->planes[2] + row * ret->strides[2];
2152
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
2154
get_pixel(2*col, 2*row, tmp_f);
2163
get_pixel(2*col+1, 2*row, tmp_f);
2173
y = ret->planes[0] + (2 * row + 1) * ret->strides[0];
2175
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
2177
get_pixel(2*col, 2*row+1, tmp_f);
2183
get_pixel(2*col+1, 2*row+1, tmp_f);
2191
case GAVL_YUVJ_422_P:
2192
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2194
y = ret->planes[0] + row * ret->strides[0];
2195
u = ret->planes[1] + row * ret->strides[1];
2196
v = ret->planes[2] + row * ret->strides[2];
2198
for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
2200
get_pixel(2* col, row, tmp_f);
2209
get_pixel(2* col + 1, row, tmp_f);
2220
case GAVL_YUVJ_444_P:
2221
for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
2223
y = ret->planes[0] + row * ret->strides[0];
2224
u = ret->planes[1] + row * ret->strides[1];
2225
v = ret->planes[2] + row * ret->strides[2];
2227
for(col = 0; col < TEST_PICTURE_WIDTH; col++)
2229
get_pixel(col, row, tmp_f);
2240
case GAVL_PIXELFORMAT_NONE:
2247
int main(int argc, char ** argv)
2249
#ifdef ALL_PIXELFORMATS
2252
const char * tmp1, * tmp2;
2253
char filename_buffer[128];
2255
float background[3] = { 1.0, 0.0, 0.0 };
2257
gavl_video_format_t input_format;
2258
gavl_video_format_t output_format;
2260
gavl_video_frame_t * input_frame;
2261
gavl_video_frame_t * output_frame;
2263
gavl_video_options_t * opt;
2265
gavl_video_converter_t * cnv = gavl_video_converter_create();
2266
opt = gavl_video_converter_get_options(cnv);
2268
memset(&input_format, 0, sizeof(input_format));
2269
memset(&output_format, 0, sizeof(output_format));
2271
input_format.image_width = TEST_PICTURE_WIDTH;
2272
input_format.image_height = TEST_PICTURE_HEIGHT;
2274
input_format.frame_width = TEST_PICTURE_WIDTH;
2275
input_format.frame_height = TEST_PICTURE_HEIGHT;
2277
input_format.pixel_width = 1;
2278
input_format.pixel_height = 1;
2280
output_format.frame_width = TEST_PICTURE_WIDTH;
2281
output_format.frame_height = TEST_PICTURE_HEIGHT;
2283
output_format.image_width = TEST_PICTURE_WIDTH;
2284
output_format.image_height = TEST_PICTURE_HEIGHT;
2286
output_format.pixel_width = 1;
2287
output_format.pixel_height = 1;
2291
#ifdef ALL_PIXELFORMATS
2292
for(i = 0; i < gavl_num_pixelformats(); i++)
2294
input_format.pixelformat = gavl_get_pixelformat(i);
2296
input_format.pixelformat = IN_PIXELFORMAT;
2298
input_frame = create_picture(input_format.pixelformat,
2299
get_pixel_colorbar);
2301
tmp1 = gavl_pixelformat_to_string(input_format.pixelformat);
2302
sprintf(filename_buffer, "0test_%s.png", tmp1);
2304
write_file(filename_buffer,
2305
input_frame, &input_format);
2307
#ifdef ALL_PIXELFORMATS
2308
for(j = 0; j < gavl_num_pixelformats(); j++)
2310
output_format.pixelformat = gavl_get_pixelformat(j);
2312
output_format.pixelformat = OUT_PIXELFORMAT;
2315
gavl_video_options_set_defaults(opt);
2317
gavl_video_options_set_alpha_mode(opt, GAVL_ALPHA_IGNORE);
2318
gavl_video_options_set_background_color(opt, background);
2320
#ifdef ALL_PIXELFORMATS
2321
if(input_format.pixelformat == output_format.pixelformat)
2325
output_frame = gavl_video_frame_create(&output_format);
2326
fprintf(stderr, "************* Pixelformat conversion ");
2327
fprintf(stderr, "%s -> ", tmp1);
2328
tmp2 = gavl_pixelformat_to_string(output_format.pixelformat);
2330
fprintf(stderr, "%s *************\n", tmp2);
2332
// gavl_video_options_set_accel_flags(opt, GAVL_ACCEL_C);
2333
gavl_video_options_set_quality(opt, 5);
2334
gavl_video_frame_clear(output_frame, &output_format);
2336
if(gavl_video_converter_init(cnv, &input_format, &output_format) <= 0)
2338
fprintf(stderr, "No Conversion defined yet or not necessary\n");
2342
fprintf(stderr, "ANSI C Version: ");
2343
gavl_video_convert(cnv, input_frame, output_frame);
2346
/* Now, do some conversions */
2348
sprintf(filename_buffer, "%s_to_%s_c.png", tmp1, tmp2);
2349
write_file(filename_buffer,
2350
output_frame, &output_format);
2351
fprintf(stderr, "Wrote %s\n", filename_buffer);
2354
/* Now, initialize with MMX */
2357
gavl_video_options_set_accel_flags(opt, GAVL_ACCEL_MMX);
2359
gavl_video_frame_clear(output_frame, &output_format);
2360
sprintf(filename_buffer, "%s_to_%s_mmx.png", tmp1, tmp2);
2361
if(gavl_video_converter_init(cnv, &input_format, &output_format) == -1)
2362
fprintf(stderr, "No MMX Conversion defined yet\n");
2365
fprintf(stderr, "MMX Version: ");
2366
gavl_video_convert(cnv, input_frame, output_frame);
2368
write_file(filename_buffer,
2369
output_frame, &output_format);
2370
fprintf(stderr, "Wrote %s\n", filename_buffer);
2373
gavl_video_options_set_accel_flags(opt, GAVL_ACCEL_MMXEXT);
2375
gavl_video_frame_clear(output_frame, &output_format);
2376
sprintf(filename_buffer, "%s_to_%s_mmxext.png", tmp1, tmp2);
2377
if(gavl_video_converter_init(cnv, &input_format, &output_format) == -1)
2378
fprintf(stderr, "No MMXEXT Conversion defined yet\n");
2381
fprintf(stderr, "MMXEXT Version: ");
2382
gavl_video_convert(cnv, input_frame, output_frame);
2384
write_file(filename_buffer,
2385
output_frame, &output_format);
2386
fprintf(stderr, "Wrote %s\n", filename_buffer);
2389
gavl_video_frame_destroy(output_frame);
2391
#ifdef ALL_PIXELFORMATS