~ubuntu-branches/ubuntu/natty/gavl/natty

« back to all changes in this revision

Viewing changes to src/colorspace_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2006-05-17 14:24:46 UTC
  • Revision ID: james.westby@ubuntu.com-20060517142446-iqm0jgfbkmy27n5w
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <gavl.h>
 
2
//#include "colorspace.h" // Common routines
 
3
#include <stdio.h>
 
4
#include <png.h>
 
5
#include <unistd.h>
 
6
#include <stdlib.h>
 
7
 
 
8
#include <accel.h>
 
9
 
 
10
#define ALL_PIXELFORMATS
 
11
#define IN_PIXELFORMAT GAVL_YUV_444_P
 
12
#define OUT_PIXELFORMAT GAVL_YUV_444_P_16
 
13
 
 
14
// Masks for BGR16 and RGB16 formats
 
15
 
 
16
#define RGB16_LOWER_MASK  0x001f
 
17
#define RGB16_MIDDLE_MASK 0x07e0
 
18
#define RGB16_UPPER_MASK  0xf800
 
19
 
 
20
// Extract unsigned char RGB values from 15 bit pixels
 
21
 
 
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)
 
25
 
 
26
#define RGB15_LOWER_MASK  0x001f
 
27
#define RGB15_MIDDLE_MASK 0x3e0
 
28
#define RGB15_UPPER_MASK  0x7C00
 
29
 
 
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)
 
33
 
 
34
// ((((((src[2]<<5)&0xff00)|src[1])<<6)&0xfff00)|src[0])>>3;
 
35
 
 
36
#define TEST_PICTURE_WIDTH  320
 
37
#define TEST_PICTURE_HEIGHT 256
 
38
 
 
39
/*
 
40
 *   Some braindead YUV conversion (but works at least :-)
 
41
 */
 
42
 
 
43
static int * r_to_y = (int*)0;
 
44
static int * g_to_y = (int*)0;
 
45
static int * b_to_y = (int*)0;
 
46
 
 
47
static int * r_to_u = (int*)0;
 
48
static int * g_to_u = (int*)0;
 
49
static int * b_to_u = (int*)0;
 
50
 
 
51
static int * r_to_v = (int*)0;
 
52
static int * g_to_v = (int*)0;
 
53
static int * b_to_v = (int*)0;
 
54
 
 
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;
 
60
 
 
61
/* JPEG Quantization */
 
62
 
 
63
static int * r_to_yj = (int*)0;
 
64
static int * g_to_yj = (int*)0;
 
65
static int * b_to_yj = (int*)0;
 
66
 
 
67
static int * r_to_uj = (int*)0;
 
68
static int * g_to_uj = (int*)0;
 
69
static int * b_to_uj = (int*)0;
 
70
 
 
71
static int * r_to_vj = (int*)0;
 
72
static int * g_to_vj = (int*)0;
 
73
static int * b_to_vj = (int*)0;
 
74
 
 
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;
 
80
 
 
81
 
 
82
 
 
83
void init_yuv()
 
84
  {
 
85
  int i;
 
86
  
 
87
  r_to_y = malloc(0x100 * sizeof(int));
 
88
  g_to_y = malloc(0x100 * sizeof(int));
 
89
  b_to_y = malloc(0x100 * sizeof(int));
 
90
 
 
91
  r_to_u = malloc(0x100 * sizeof(int));
 
92
  g_to_u = malloc(0x100 * sizeof(int));
 
93
  b_to_u = malloc(0x100 * sizeof(int));
 
94
 
 
95
  r_to_v = malloc(0x100 * sizeof(int));
 
96
  g_to_v = malloc(0x100 * sizeof(int));
 
97
  b_to_v = malloc(0x100 * sizeof(int));
 
98
 
 
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));
 
104
 
 
105
  /* JPEG Quantization */
 
106
 
 
107
  r_to_yj = malloc(0x100 * sizeof(int));
 
108
  g_to_yj = malloc(0x100 * sizeof(int));
 
109
  b_to_yj = malloc(0x100 * sizeof(int));
 
110
 
 
111
  r_to_uj = malloc(0x100 * sizeof(int));
 
112
  g_to_uj = malloc(0x100 * sizeof(int));
 
113
  b_to_uj = malloc(0x100 * sizeof(int));
 
114
 
 
115
  r_to_vj = malloc(0x100 * sizeof(int));
 
116
  g_to_vj = malloc(0x100 * sizeof(int));
 
117
  b_to_vj = malloc(0x100 * sizeof(int));
 
118
 
 
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));
 
124
  
 
125
  
 
126
  for(i = 0; i < 0x100; i++)
 
127
    {
 
128
    // RGB to YUV conversion
 
129
 
 
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);
 
133
    
 
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);
 
137
    
 
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);
 
141
 
 
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);
 
145
    
 
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);
 
149
    
 
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);
 
153
 
 
154
 
 
155
    // YUV to RGB conversion
 
156
 
 
157
    y_to_rgb[i] = (int)(1.164*(i-16)) * 0x10000;
 
158
    
 
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);
 
163
 
 
164
    /* JPEG Quantization */
 
165
 
 
166
    yj_to_rgb[i] = (int)(i * 0x10000);
 
167
    
 
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);
 
172
    
 
173
    }
 
174
  }
 
175
 
 
176
#define RECLIP(color) (uint8_t)((color>0xFF)?0xff:((color<0)?0:color))
 
177
 
 
178
#define RECLIP_16(color) (uint16_t)((color>0xFFFF)?0xFFFF:((color<0)?0:color))
 
179
 
 
180
#define RECLIP_FLOAT(color) (float)((color>1.0)?1.0:((color<0.0)?0.0:color))
 
181
 
 
182
#define YUV_2_RGB(y,u,v,r,g,b) i_tmp=(y_to_rgb[y]+v_to_r[v])>>16;\
 
183
                                r=RECLIP(i_tmp);\
 
184
                                i_tmp=(y_to_rgb[y]+u_to_g[u]+v_to_g[v])>>16;\
 
185
                                g=RECLIP(i_tmp);\
 
186
                                i_tmp=(y_to_rgb[y]+u_to_b[u])>>16;\
 
187
                                b=RECLIP(i_tmp);
 
188
 
 
189
#define YUVJ_2_RGB(y,u,v,r,g,b) i_tmp=(yj_to_rgb[y]+vj_to_r[v])>>16;\
 
190
                                r=RECLIP(i_tmp);\
 
191
                                i_tmp=(yj_to_rgb[y]+uj_to_g[u]+vj_to_g[v])>>16;\
 
192
                                g=RECLIP(i_tmp);\
 
193
                                i_tmp=(yj_to_rgb[y]+uj_to_b[u])>>16;\
 
194
                                b=RECLIP(i_tmp);
 
195
 
 
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;\
 
197
                                r=RECLIP(i_tmp);\
 
198
                                i_tmp=(y_to_rgb[y>>8]+u_to_g[u>>8]+v_to_g[v>>8])>>16;\
 
199
                                g=RECLIP(i_tmp);\
 
200
                                i_tmp=(y_to_rgb[y>>8]+u_to_b[u>>8])>>16;\
 
201
                                b=RECLIP(i_tmp);
 
202
 
 
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)
 
206
  {
 
207
  int i, j;
 
208
 
 
209
  uint16_t * in_pixel;
 
210
  uint8_t  * out_pixel;
 
211
 
 
212
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
213
  uint8_t * in_pixel_save = in_frame->planes[0];
 
214
  
 
215
  for(i = 0; i < height; i++)
 
216
    {
 
217
    in_pixel = (uint16_t*)in_pixel_save;
 
218
    out_pixel = out_pixel_save;
 
219
    
 
220
    for(j = 0; j < width; j++)
 
221
      {
 
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);
 
225
      
 
226
      in_pixel++;
 
227
      out_pixel += 3;
 
228
      }
 
229
    in_pixel_save += in_frame->strides[0];
 
230
    out_pixel_save +=  out_frame->strides[0];
 
231
    }
 
232
  }
 
233
 
 
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)
 
237
  {
 
238
  int i, j;
 
239
  uint16_t * in_pixel;
 
240
  uint8_t  * out_pixel;
 
241
 
 
242
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
243
  uint8_t * in_pixel_save = in_frame->planes[0];
 
244
  
 
245
  for(i = 0; i < height; i++)
 
246
    {
 
247
    in_pixel = (uint16_t*)in_pixel_save;
 
248
    out_pixel = out_pixel_save;
 
249
    for(j = 0; j < width; j++)
 
250
      {
 
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);
 
254
 
 
255
      in_pixel++;
 
256
      out_pixel += 3;
 
257
      }
 
258
    in_pixel_save += in_frame->strides[0];
 
259
    out_pixel_save +=  out_frame->strides[0];
 
260
    }
 
261
  }
 
262
 
 
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)
 
266
  {
 
267
  int i, j;
 
268
  uint8_t * in_pixel;
 
269
  uint8_t  * out_pixel;
 
270
  
 
271
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
272
  uint8_t * in_pixel_save = in_frame->planes[0];
 
273
  
 
274
  for(i = 0; i < height; i++)
 
275
    {
 
276
    in_pixel = (uint8_t*)in_pixel_save;
 
277
    out_pixel = out_pixel_save;
 
278
    for(j = 0; j < width; j++)
 
279
      {
 
280
      out_pixel[0] = in_pixel[0];
 
281
      out_pixel[1] = in_pixel[1];
 
282
      out_pixel[2] = in_pixel[2];
 
283
      in_pixel+=4;
 
284
      out_pixel+=3;
 
285
      }
 
286
    in_pixel_save += in_frame->strides[0];
 
287
    out_pixel_save +=  out_frame->strides[0];
 
288
    }
 
289
  }
 
290
 
 
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)
 
294
  {
 
295
  int i, j;
 
296
  uint16_t * in_pixel;
 
297
  uint8_t  * out_pixel;
 
298
  
 
299
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
300
  uint8_t * in_pixel_save = in_frame->planes[0];
 
301
  
 
302
  for(i = 0; i < height; i++)
 
303
    {
 
304
    in_pixel = (uint16_t*)in_pixel_save;
 
305
    out_pixel = out_pixel_save;
 
306
    for(j = 0; j < width; j++)
 
307
      {
 
308
      out_pixel[0] = in_pixel[0] >> 8;
 
309
      out_pixel[1] = in_pixel[1] >> 8;
 
310
      out_pixel[2] = in_pixel[2] >> 8;
 
311
      in_pixel+=3;
 
312
      out_pixel+=3;
 
313
      }
 
314
    in_pixel_save += in_frame->strides[0];
 
315
    out_pixel_save +=  out_frame->strides[0];
 
316
    }
 
317
  }
 
318
 
 
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)
 
322
  {
 
323
  int i, j;
 
324
  uint16_t * in_pixel;
 
325
  uint8_t  * out_pixel;
 
326
  
 
327
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
328
  uint8_t * in_pixel_save = in_frame->planes[0];
 
329
  
 
330
  for(i = 0; i < height; i++)
 
331
    {
 
332
    in_pixel = (uint16_t*)in_pixel_save;
 
333
    out_pixel = out_pixel_save;
 
334
    for(j = 0; j < width; j++)
 
335
      {
 
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;
 
340
      in_pixel+=4;
 
341
      out_pixel+=4;
 
342
      }
 
343
    in_pixel_save += in_frame->strides[0];
 
344
    out_pixel_save +=  out_frame->strides[0];
 
345
    }
 
346
  }
 
347
 
 
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)
 
351
  {
 
352
  int i, j, i_tmp;
 
353
  uint8_t * in_pixel;
 
354
  uint8_t  * out_pixel;
 
355
  
 
356
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
357
  uint8_t * in_pixel_save = in_frame->planes[0];
 
358
  
 
359
  for(i = 0; i < height; i++)
 
360
    {
 
361
    in_pixel = in_pixel_save;
 
362
    out_pixel = out_pixel_save;
 
363
    for(j = 0; j < width; j++)
 
364
      {
 
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];
 
367
      in_pixel+=4;
 
368
      out_pixel+=4;
 
369
      }
 
370
    in_pixel_save += in_frame->strides[0];
 
371
    out_pixel_save +=  out_frame->strides[0];
 
372
    }
 
373
  }
 
374
 
 
375
 
 
376
 
 
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)
 
380
  {
 
381
  int i, j, i_tmp;
 
382
  float * in_pixel;
 
383
  uint8_t  * out_pixel;
 
384
  
 
385
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
386
  uint8_t * in_pixel_save = in_frame->planes[0];
 
387
  
 
388
  for(i = 0; i < height; i++)
 
389
    {
 
390
    in_pixel = (float*)in_pixel_save;
 
391
    out_pixel = out_pixel_save;
 
392
    for(j = 0; j < width; j++)
 
393
      {
 
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);
 
400
      in_pixel+=3;
 
401
      out_pixel+=3;
 
402
      }
 
403
    in_pixel_save += in_frame->strides[0];
 
404
    out_pixel_save +=  out_frame->strides[0];
 
405
    }
 
406
  }
 
407
 
 
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)
 
411
  {
 
412
  int i, j, i_tmp;
 
413
  float * in_pixel;
 
414
  uint8_t  * out_pixel;
 
415
  
 
416
  uint8_t  * out_pixel_save = out_frame->planes[0];
 
417
  uint8_t * in_pixel_save = in_frame->planes[0];
 
418
 
 
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++)
 
422
    {
 
423
    in_pixel = (float*)in_pixel_save;
 
424
    out_pixel = out_pixel_save;
 
425
    for(j = 0; j < width; j++)
 
426
      {
 
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);
 
435
      in_pixel+=4;
 
436
      out_pixel+=4;
 
437
      }
 
438
    in_pixel_save += in_frame->strides[0];
 
439
    out_pixel_save +=  out_frame->strides[0];
 
440
    }
 
441
  }
 
442
 
 
443
 
 
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)
 
447
  {
 
448
  int i, j, i_tmp;
 
449
  uint8_t * in_y;
 
450
  uint8_t * in_u;
 
451
  uint8_t * in_v;
 
452
 
 
453
  uint8_t * out_pixel;
 
454
 
 
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];
 
459
 
 
460
  for(i = 0; i < height/2; i++)
 
461
    {
 
462
 
 
463
    /* Even Rows */
 
464
 
 
465
    out_pixel = out_pixel_save;
 
466
    in_y = in_y_save;
 
467
    in_u = in_u_save;
 
468
    in_v = in_v_save;
 
469
    for(j = 0; j < width/2; j++)
 
470
      {
 
471
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
472
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
473
      in_y++;
 
474
      out_pixel += 3;
 
475
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
476
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
477
      in_y++;
 
478
      in_u++;
 
479
      in_v++;
 
480
      out_pixel += 3;
 
481
      }
 
482
    out_pixel_save += out_frame->strides[0];
 
483
    in_y_save += in_frame->strides[0];
 
484
 
 
485
    /* Odd Rows */
 
486
 
 
487
    out_pixel = out_pixel_save;
 
488
    in_y = in_y_save;
 
489
    in_u = in_u_save;
 
490
    in_v = in_v_save;
 
491
    for(j = 0; j < width/2; j++)
 
492
      {
 
493
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
494
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
495
      in_y++;
 
496
      out_pixel += 3;
 
497
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
498
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
499
      in_y++;
 
500
      in_u++;
 
501
      in_v++;
 
502
      out_pixel += 3;
 
503
      }
 
504
    out_pixel_save += out_frame->strides[0];
 
505
    in_y_save += in_frame->strides[0];
 
506
 
 
507
    in_u_save += in_frame->strides[1];
 
508
    in_v_save += in_frame->strides[2];
 
509
    }
 
510
  }
 
511
 
 
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)
 
515
  {
 
516
  int i, j, i_tmp;
 
517
  uint8_t * in_y;
 
518
  uint8_t * in_u;
 
519
  uint8_t * in_v;
 
520
 
 
521
  uint8_t * out_pixel;
 
522
 
 
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];
 
527
 
 
528
  for(i = 0; i < height/4; i++)
 
529
    {
 
530
 
 
531
    /* Even Rows */
 
532
 
 
533
    out_pixel = out_pixel_save;
 
534
    in_y = in_y_save;
 
535
    in_u = in_u_save;
 
536
    in_v = in_v_save;
 
537
    for(j = 0; j < width/4; j++)
 
538
      {
 
539
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
540
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
541
      in_y++;
 
542
      out_pixel += 3;
 
543
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
544
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
545
      in_y++;
 
546
      out_pixel += 3;
 
547
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
548
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
549
      in_y++;
 
550
      out_pixel += 3;
 
551
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
552
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
553
      in_y++;
 
554
      in_u++;
 
555
      in_v++;
 
556
      out_pixel += 3;
 
557
      }
 
558
    out_pixel_save += out_frame->strides[0];
 
559
    in_y_save += in_frame->strides[0];
 
560
 
 
561
    /* Odd Rows */
 
562
 
 
563
    out_pixel = out_pixel_save;
 
564
    in_y = in_y_save;
 
565
    in_u = in_u_save;
 
566
    in_v = in_v_save;
 
567
    for(j = 0; j < width/4; j++)
 
568
      {
 
569
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
570
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
571
      in_y++;
 
572
      out_pixel += 3;
 
573
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
574
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
575
      in_y++;
 
576
      out_pixel += 3;
 
577
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
578
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
579
      in_y++;
 
580
      out_pixel += 3;
 
581
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
582
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
583
      in_y++;
 
584
      in_u++;
 
585
      in_v++;
 
586
      out_pixel += 3;
 
587
      }
 
588
    out_pixel_save += out_frame->strides[0];
 
589
    in_y_save += in_frame->strides[0];
 
590
 
 
591
    out_pixel = out_pixel_save;
 
592
    in_y = in_y_save;
 
593
    in_u = in_u_save;
 
594
    in_v = in_v_save;
 
595
    for(j = 0; j < width/4; j++)
 
596
      {
 
597
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
598
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
599
      in_y++;
 
600
      out_pixel += 3;
 
601
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
602
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
603
      in_y++;
 
604
      out_pixel += 3;
 
605
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
606
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
607
      in_y++;
 
608
      out_pixel += 3;
 
609
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
610
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
611
      in_y++;
 
612
      in_u++;
 
613
      in_v++;
 
614
      out_pixel += 3;
 
615
      }
 
616
    out_pixel_save += out_frame->strides[0];
 
617
    in_y_save += in_frame->strides[0];
 
618
 
 
619
    out_pixel = out_pixel_save;
 
620
    in_y = in_y_save;
 
621
    in_u = in_u_save;
 
622
    in_v = in_v_save;
 
623
    for(j = 0; j < width/4; j++)
 
624
      {
 
625
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
626
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
627
      in_y++;
 
628
      out_pixel += 3;
 
629
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
630
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
631
      in_y++;
 
632
      out_pixel += 3;
 
633
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
634
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
635
      in_y++;
 
636
      out_pixel += 3;
 
637
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
638
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
639
      in_y++;
 
640
      in_u++;
 
641
      in_v++;
 
642
      out_pixel += 3;
 
643
      }
 
644
    out_pixel_save += out_frame->strides[0];
 
645
    in_y_save += in_frame->strides[0];
 
646
 
 
647
    
 
648
    in_u_save += in_frame->strides[1];
 
649
    in_v_save += in_frame->strides[2];
 
650
    }
 
651
  }
 
652
 
 
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)
 
656
  {
 
657
  int i, j, i_tmp;
 
658
  uint8_t * in_y;
 
659
  uint8_t * in_u;
 
660
  uint8_t * in_v;
 
661
 
 
662
  uint8_t * out_pixel;
 
663
 
 
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];
 
668
 
 
669
  for(i = 0; i < height/2; i++)
 
670
    {
 
671
 
 
672
    /* Even Rows */
 
673
 
 
674
    out_pixel = out_pixel_save;
 
675
    in_y = in_y_save;
 
676
    in_u = in_u_save;
 
677
    in_v = in_v_save;
 
678
    for(j = 0; j < width/2; j++)
 
679
      {
 
680
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
681
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
682
      in_y++;
 
683
      out_pixel += 3;
 
684
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
685
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
686
      in_y++;
 
687
      in_u++;
 
688
      in_v++;
 
689
      out_pixel += 3;
 
690
      }
 
691
    out_pixel_save += out_frame->strides[0];
 
692
    in_y_save += in_frame->strides[0];
 
693
 
 
694
    /* Odd Rows */
 
695
 
 
696
    out_pixel = out_pixel_save;
 
697
    in_y = in_y_save;
 
698
    in_u = in_u_save;
 
699
    in_v = in_v_save;
 
700
    for(j = 0; j < width/2; j++)
 
701
      {
 
702
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
703
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
704
      in_y++;
 
705
      out_pixel += 3;
 
706
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
707
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
708
      in_y++;
 
709
      in_u++;
 
710
      in_v++;
 
711
      out_pixel += 3;
 
712
      }
 
713
    out_pixel_save += out_frame->strides[0];
 
714
    in_y_save += in_frame->strides[0];
 
715
 
 
716
    in_u_save += in_frame->strides[1];
 
717
    in_v_save += in_frame->strides[2];
 
718
    }
 
719
  }
 
720
 
 
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)
 
724
  {
 
725
  int i, j, i_tmp;
 
726
 
 
727
  uint8_t * in_y;
 
728
  uint8_t * in_u;
 
729
  uint8_t * in_v;
 
730
 
 
731
  uint8_t * out_pixel;
 
732
 
 
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];
 
737
 
 
738
  for(i = 0; i < height; i++)
 
739
    {
 
740
    in_y = in_y_save;
 
741
    in_u = in_u_save;
 
742
    in_v = in_v_save;
 
743
    out_pixel = out_pixel_save;
 
744
    for(j = 0; j < width/2; j++)
 
745
      {
 
746
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
747
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
748
      in_y++;
 
749
      out_pixel += 3;
 
750
      
 
751
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
752
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
753
      in_y++;
 
754
      in_u++;
 
755
      in_v++;
 
756
      out_pixel += 3;
 
757
      }
 
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];
 
762
    }
 
763
  }
 
764
 
 
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)
 
768
  {
 
769
  int i, j, i_tmp;
 
770
 
 
771
  uint16_t * in_y;
 
772
  uint16_t * in_u;
 
773
  uint16_t * in_v;
 
774
 
 
775
  uint8_t * out_pixel;
 
776
 
 
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];
 
781
 
 
782
  for(i = 0; i < height; i++)
 
783
    {
 
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++)
 
789
      {
 
790
      YUV_2_RGB(((*in_y)>>8), ((*in_u)>>8), ((*in_v)>>8),
 
791
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
792
      in_y++;
 
793
      out_pixel += 3;
 
794
      
 
795
      YUV_2_RGB(((*in_y)>>8), ((*in_u)>>8), ((*in_v)>>8),
 
796
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
797
      in_y++;
 
798
      in_u++;
 
799
      in_v++;
 
800
      out_pixel += 3;
 
801
      }
 
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];
 
806
    }
 
807
  }
 
808
 
 
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)
 
812
  {
 
813
  int i, j, i_tmp;
 
814
 
 
815
  uint8_t * in_y;
 
816
  uint8_t * in_u;
 
817
  uint8_t * in_v;
 
818
 
 
819
  uint8_t * out_pixel;
 
820
 
 
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];
 
825
 
 
826
  for(i = 0; i < height; i++)
 
827
    {
 
828
    in_y = in_y_save;
 
829
    in_u = in_u_save;
 
830
    in_v = in_v_save;
 
831
    out_pixel = out_pixel_save;
 
832
    for(j = 0; j < width/4; j++)
 
833
      {
 
834
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
835
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
836
      in_y++;
 
837
      out_pixel += 3;
 
838
 
 
839
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
840
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
841
      in_y++;
 
842
      out_pixel += 3;
 
843
 
 
844
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
845
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
846
      in_y++;
 
847
      out_pixel += 3;
 
848
      
 
849
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
850
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
851
      in_y++;
 
852
      in_u++;
 
853
      in_v++;
 
854
      out_pixel += 3;
 
855
      }
 
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];
 
860
    }
 
861
  }
 
862
 
 
863
 
 
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)
 
867
  {
 
868
  int i, j, i_tmp;
 
869
 
 
870
  uint8_t * in_y;
 
871
  uint8_t * in_u;
 
872
  uint8_t * in_v;
 
873
 
 
874
  uint8_t * out_pixel;
 
875
 
 
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];
 
880
 
 
881
  for(i = 0; i < height; i++)
 
882
    {
 
883
    in_y = in_y_save;
 
884
    in_u = in_u_save;
 
885
    in_v = in_v_save;
 
886
    out_pixel = out_pixel_save;
 
887
    for(j = 0; j < width/2; j++)
 
888
      {
 
889
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
890
                 out_pixel[0], out_pixel[1], out_pixel[2]);
 
891
      in_y++;
 
892
      out_pixel += 3;
 
893
      
 
894
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
895
                 out_pixel[0], out_pixel[1], out_pixel[2]);
 
896
      in_y++;
 
897
      in_u++;
 
898
      in_v++;
 
899
      out_pixel += 3;
 
900
      }
 
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];
 
905
    }
 
906
  }
 
907
 
 
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)
 
911
  {
 
912
  int i, j, i_tmp;
 
913
 
 
914
  uint8_t * in_y;
 
915
  uint8_t * in_u;
 
916
  uint8_t * in_v;
 
917
 
 
918
  uint8_t * out_pixel;
 
919
 
 
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];
 
924
 
 
925
  for(i = 0; i < height; i++)
 
926
    {
 
927
    in_y = in_y_save;
 
928
    in_u = in_u_save;
 
929
    in_v = in_v_save;
 
930
    out_pixel = out_pixel_save;
 
931
    for(j = 0; j < width; j++)
 
932
      {
 
933
      YUV_2_RGB(*in_y, *in_u, *in_v,
 
934
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
935
      in_y++;
 
936
      in_u++;
 
937
      in_v++;
 
938
      out_pixel += 3;
 
939
      }
 
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];
 
944
    }
 
945
  }
 
946
 
 
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)
 
950
  {
 
951
  int i, j, i_tmp;
 
952
 
 
953
  uint16_t * in_y;
 
954
  uint16_t * in_u;
 
955
  uint16_t * in_v;
 
956
 
 
957
  uint8_t * out_pixel;
 
958
 
 
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];
 
963
 
 
964
  for(i = 0; i < height; i++)
 
965
    {
 
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++)
 
971
      {
 
972
      YUV_2_RGB(((*in_y)>>8), ((*in_u)>>8), ((*in_v)>>8),
 
973
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
974
      in_y++;
 
975
      in_u++;
 
976
      in_v++;
 
977
      out_pixel += 3;
 
978
      }
 
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];
 
983
    }
 
984
  }
 
985
 
 
986
 
 
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)
 
990
  {
 
991
  int i, j, i_tmp;
 
992
 
 
993
  uint8_t * in_y;
 
994
  uint8_t * in_u;
 
995
  uint8_t * in_v;
 
996
 
 
997
  uint8_t * out_pixel;
 
998
 
 
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];
 
1003
 
 
1004
  for(i = 0; i < height; i++)
 
1005
    {
 
1006
    in_y = in_y_save;
 
1007
    in_u = in_u_save;
 
1008
    in_v = in_v_save;
 
1009
    out_pixel = out_pixel_save;
 
1010
    for(j = 0; j < width; j++)
 
1011
      {
 
1012
      YUVJ_2_RGB(*in_y, *in_u, *in_v,
 
1013
                 out_pixel[0], out_pixel[1], out_pixel[2]);
 
1014
      in_y++;
 
1015
      in_u++;
 
1016
      in_v++;
 
1017
      out_pixel += 3;
 
1018
      }
 
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];
 
1023
    }
 
1024
  }
 
1025
 
 
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)
 
1029
  {
 
1030
  int i, j, i_tmp;
 
1031
 
 
1032
  uint8_t * in_pixel;
 
1033
  uint8_t * out_pixel;
 
1034
 
 
1035
  uint8_t * out_pixel_save = out_frame->planes[0];
 
1036
  uint8_t * in_pixel_save = in_frame->planes[0];
 
1037
 
 
1038
  for(i = 0; i < height; i++)
 
1039
    {
 
1040
    in_pixel = in_pixel_save;
 
1041
    out_pixel = out_pixel_save;
 
1042
    for(j = 0; j < width/2; j++)
 
1043
      {
 
1044
      YUV_2_RGB(in_pixel[0], in_pixel[1], in_pixel[3],
 
1045
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
1046
      out_pixel+=3;
 
1047
      YUV_2_RGB(in_pixel[2], in_pixel[1], in_pixel[3],
 
1048
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
1049
      out_pixel+=3;
 
1050
      in_pixel += 4;
 
1051
      }
 
1052
    in_pixel_save += in_frame->strides[0];
 
1053
    out_pixel_save +=  out_frame->strides[0];
 
1054
    }
 
1055
  }
 
1056
 
 
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)
 
1060
  {
 
1061
  int i, j, i_tmp;
 
1062
 
 
1063
  uint8_t * in_pixel;
 
1064
  uint8_t * out_pixel;
 
1065
 
 
1066
  uint8_t * out_pixel_save = out_frame->planes[0];
 
1067
  uint8_t * in_pixel_save = in_frame->planes[0];
 
1068
 
 
1069
  for(i = 0; i < height; i++)
 
1070
    {
 
1071
    in_pixel = in_pixel_save;
 
1072
    out_pixel = out_pixel_save;
 
1073
    for(j = 0; j < width/2; j++)
 
1074
      {
 
1075
      YUV_2_RGB(in_pixel[1], in_pixel[0], in_pixel[2],
 
1076
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
1077
      out_pixel+=3;
 
1078
      YUV_2_RGB(in_pixel[3], in_pixel[0], in_pixel[2],
 
1079
                out_pixel[0], out_pixel[1], out_pixel[2]);
 
1080
      out_pixel+=3;
 
1081
      in_pixel += 4;
 
1082
      }
 
1083
    in_pixel_save += in_frame->strides[0];
 
1084
    out_pixel_save +=  out_frame->strides[0];
 
1085
    }
 
1086
  }
 
1087
 
 
1088
/*
 
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)
 
1092
 */
 
1093
 
 
1094
/* On error, FALSE is returned */
 
1095
 
 
1096
int write_file(const char * name,
 
1097
               gavl_video_frame_t * frame, gavl_video_format_t * format)
 
1098
  {
 
1099
  int color_type;  
 
1100
  int png_transforms;
 
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;
 
1104
 
 
1105
  int i;
 
1106
  char ** row_pointers;  
 
1107
  png_structp png_ptr;  png_infop info_ptr;
 
1108
  
 
1109
  FILE *fp = fopen(name, "wb");
 
1110
  if (!fp)
 
1111
    {
 
1112
    fprintf(stderr, "Cannot open file %s, exiting \n", name);
 
1113
    _exit(-1);
 
1114
    return 0;
 
1115
    }
 
1116
 
 
1117
  png_ptr = png_create_write_struct
 
1118
    (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
1119
  if (!png_ptr)
 
1120
    return 0;
 
1121
  
 
1122
  info_ptr = png_create_info_struct(png_ptr);
 
1123
  if (!info_ptr)
 
1124
    {
 
1125
    png_destroy_write_struct(&png_ptr,
 
1126
                             (png_infopp)NULL);
 
1127
    return 0;
 
1128
    }
 
1129
  
 
1130
  setjmp(png_jmpbuf(png_ptr));
 
1131
 
 
1132
  png_init_io(png_ptr, fp);
 
1133
 
 
1134
  if(gavl_pixelformat_has_alpha(format->pixelformat))
 
1135
    color_type = PNG_COLOR_TYPE_RGB_ALPHA;
 
1136
  else
 
1137
    color_type = PNG_COLOR_TYPE_RGB;
 
1138
 
 
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);
 
1143
 
 
1144
  /* Set up the temporary video frame */
 
1145
 
 
1146
  tmp_format.image_width  = format->image_width;
 
1147
  tmp_format.image_height = format->image_height;
 
1148
 
 
1149
  tmp_format.frame_width  = format->frame_width;
 
1150
  tmp_format.frame_height = format->frame_height;
 
1151
  
 
1152
  /* We convert everything to either RGB24, BGR24 or RGBA */
 
1153
  
 
1154
  switch(format->pixelformat)
 
1155
    {
 
1156
    case GAVL_BGR_15:
 
1157
    case GAVL_BGR_16:
 
1158
    case GAVL_BGR_24:
 
1159
    case GAVL_BGR_32:
 
1160
      png_transforms = PNG_TRANSFORM_BGR;
 
1161
      tmp_format.pixelformat = GAVL_BGR_24;
 
1162
      break;
 
1163
    case GAVL_RGBA_64:
 
1164
    case GAVL_RGBA_FLOAT:
 
1165
    case GAVL_YUVA_32:
 
1166
      png_transforms = PNG_TRANSFORM_IDENTITY;
 
1167
      tmp_format.pixelformat = GAVL_RGBA_32;
 
1168
      break;
 
1169
    default:
 
1170
      png_transforms = PNG_TRANSFORM_IDENTITY;
 
1171
      tmp_format.pixelformat = GAVL_RGB_24;
 
1172
    }
 
1173
 
 
1174
  /* Allocate the video frame structure */
 
1175
 
 
1176
  tmp_frame = NULL;
 
1177
 
 
1178
  switch(format->pixelformat)
 
1179
    {
 
1180
    case GAVL_RGB_15:
 
1181
    case GAVL_BGR_15:
 
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;
 
1185
      break;
 
1186
    case GAVL_RGB_16:
 
1187
    case GAVL_BGR_16:
 
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;
 
1191
      break;
 
1192
    case GAVL_RGB_24:
 
1193
    case GAVL_BGR_24:
 
1194
    case GAVL_RGBA_32:
 
1195
      out_frame = frame;
 
1196
      break;
 
1197
    case GAVL_RGB_48:
 
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;
 
1201
      break;
 
1202
    case GAVL_RGBA_64:
 
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;
 
1206
      break;
 
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;
 
1211
      break;
 
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;
 
1216
      break;
 
1217
    case GAVL_RGB_32:
 
1218
    case GAVL_BGR_32:
 
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;
 
1222
      break;
 
1223
    case GAVL_YUY2:
 
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;
 
1227
      break;
 
1228
    case GAVL_YUVA_32:
 
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;
 
1232
      break;
 
1233
    case GAVL_UYVY:
 
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;
 
1237
      break;
 
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;
 
1243
      break;
 
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;
 
1249
      break;
 
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;
 
1255
      break;
 
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;
 
1261
      break;
 
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;
 
1267
      break;
 
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;
 
1273
      break;
 
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;
 
1279
      break;
 
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;
 
1285
      break;
 
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;
 
1291
      break;
 
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;
 
1297
      break;
 
1298
    case GAVL_PIXELFORMAT_NONE:
 
1299
      break;
 
1300
    }
 
1301
 
 
1302
  /* Set up the row pointers */
 
1303
 
 
1304
  row_pointers = malloc(format->image_height * sizeof(char*));
 
1305
 
 
1306
  for(i = 0; i < format->image_height; i++)
 
1307
    row_pointers[i] =
 
1308
      (char*)(out_frame->planes[0] + i * out_frame->strides[0]);
 
1309
  
 
1310
  png_set_rows(png_ptr, info_ptr, (png_bytep*)row_pointers);
 
1311
 
 
1312
  png_write_png(png_ptr, info_ptr, png_transforms, NULL);
 
1313
 
 
1314
  free(row_pointers);
 
1315
 
 
1316
  if(tmp_frame)
 
1317
    gavl_video_frame_destroy(tmp_frame);
 
1318
  png_destroy_write_struct(&png_ptr, &info_ptr);
 
1319
  fclose(fp);
 
1320
    
 
1321
  return 1;
 
1322
  }
 
1323
 
 
1324
/**********************************************************
 
1325
 * Test picture generator
 
1326
 **********************************************************/
 
1327
 
 
1328
static uint8_t colorbar_colors[16][2][3] =
 
1329
  {
 
1330
    {
 
1331
      { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0, } /* White */
 
1332
    },
 
1333
    {
 
1334
      { 1.0, 1.0, 1.0 }, { 1.0, 1.0, 1.0, }
 
1335
    },
 
1336
    {
 
1337
      { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 0.0, }  /* Yellow */
 
1338
    },
 
1339
    {
 
1340
      { 1.0, 1.0, 1.0 }, { 1.0, 1.0, 0.0, }
 
1341
    },
 
1342
    {
 
1343
      { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 1.0, } /* Cyan */
 
1344
    },
 
1345
    {
 
1346
      { 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0, } 
 
1347
    },
 
1348
    {
 
1349
      { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, } /* Green */
 
1350
    },
 
1351
    {
 
1352
      { 1.0, 1.0, 1.0 }, { 0.0, 1.0, 0.0, } 
 
1353
    },
 
1354
    {
 
1355
      { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 1.0, } /* Magenta */
 
1356
    },
 
1357
    {
 
1358
      { 1.0, 1.0, 1.0 }, { 1.0, 0.0, 1.0, }
 
1359
    },
 
1360
    {
 
1361
      { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, } /* Red */
 
1362
    },
 
1363
    {
 
1364
      { 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0, }
 
1365
    },
 
1366
    {
 
1367
      { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, }  /* Blue */
 
1368
    },
 
1369
    {
 
1370
      { 1.0, 1.0, 1.0 }, { 0.0, 0.0, 1.0, } 
 
1371
    },
 
1372
    {
 
1373
      { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, }, /* Black */
 
1374
    },
 
1375
    {
 
1376
      { 1.0, 1.0, 1.0 }, { 0.0, 0.0, 0.0, }
 
1377
    }
 
1378
  };
 
1379
 
 
1380
// #define COLORBAR_HORIZONTAL
 
1381
 
 
1382
void get_pixel_colorbar(int x, int y,
 
1383
                        float * ret)
 
1384
  {
 
1385
  int color_index;
 
1386
  float r_tmp, g_tmp, b_tmp, alpha;
 
1387
 
 
1388
#ifdef COLORBAR_HORIZONTAL
 
1389
  alpha = (float)(TEST_PICTURE_WIDTH - x) / (float)(TEST_PICTURE_WIDTH);
 
1390
  color_index = (y * 16) / (TEST_PICTURE_HEIGHT - 1);
 
1391
#else
 
1392
  alpha = (float)(TEST_PICTURE_HEIGHT - y) / (float)(TEST_PICTURE_HEIGHT);
 
1393
  color_index = (x * 16) / (TEST_PICTURE_WIDTH - 1);
 
1394
#endif
 
1395
  if(color_index >= 16)
 
1396
    color_index = 15;
 
1397
 
 
1398
  alpha = RECLIP_FLOAT(alpha);
 
1399
  
 
1400
  /*  fprintf(stderr, "y: %d alpha: %d\n", y ,(int)alpha); */
 
1401
 
 
1402
  // colorbar_colors[16][2][3]
 
1403
  
 
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); 
 
1410
 
 
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]; */
 
1414
  
 
1415
//  a_tmp = 0xFF; /* Not used for now */
 
1416
  
 
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);
 
1421
  
 
1422
  }
 
1423
 
 
1424
#define PACK_RGB16(_r,_g,_b,_pixel) \
 
1425
_pixel=((((((_r<<5)&0xff00)|_g)<<6)&0xfff00)|_b)>>3
 
1426
 
 
1427
#define PACK_RGB15(_r,_g,_b,_pixel) \
 
1428
_pixel=((((((_r<<5)&0xff00)|_g)<<5)&0xfff00)|_b)>>3
 
1429
 
 
1430
#define FLOAT_TO_8(f) (int)(f * 255.0 + 0.5)
 
1431
#define FLOAT_TO_16(f) (int)(f * 65535.0 + 0.5)
 
1432
 
 
1433
#define RGB_TO_Y() yuv_f[0] = (0.299*tmp_f[0]+0.587*tmp_f[1]+0.114*tmp_f[2])
 
1434
 
 
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])
 
1438
 
 
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
 
1442
 
 
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;
 
1446
 
 
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)
 
1450
 
 
1451
 
 
1452
gavl_video_frame_t * create_picture(gavl_pixelformat_t pixelformat,
 
1453
                                    void (*get_pixel)(int x, int y,
 
1454
                                                      float * ret))
 
1455
  
 
1456
  {
 
1457
  int r_tmp;
 
1458
  int g_tmp;
 
1459
  int b_tmp;
 
1460
  int a_tmp;
 
1461
  
 
1462
  float tmp_f[4];
 
1463
  float yuv_f[4];
 
1464
  
 
1465
  uint8_t  * pixel;
 
1466
  uint16_t * pixel_16;
 
1467
  float * pixel_float;
 
1468
  uint8_t * y;
 
1469
  uint8_t * u;
 
1470
  uint8_t * v;
 
1471
 
 
1472
  uint16_t * y_16;
 
1473
  uint16_t * u_16;
 
1474
  uint16_t * v_16;
 
1475
    
 
1476
  int row, col;
 
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;
 
1482
 
 
1483
  format.frame_width = TEST_PICTURE_WIDTH;
 
1484
  format.frame_height = TEST_PICTURE_HEIGHT;
 
1485
 
 
1486
  format.pixel_width = 1;
 
1487
  format.pixel_height = 1;
 
1488
  
 
1489
  
 
1490
  ret = gavl_video_frame_create(&format);
 
1491
 
 
1492
  switch(pixelformat)
 
1493
    {
 
1494
    case GAVL_RGB_15:
 
1495
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1496
        {
 
1497
        pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
 
1498
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1499
          {
 
1500
          get_pixel(col, row, tmp_f);
 
1501
 
 
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);
 
1508
                    
 
1509
          PACK_RGB15(r_tmp, g_tmp, b_tmp, *pixel_16);
 
1510
          pixel_16++;
 
1511
          }
 
1512
        }
 
1513
      break;
 
1514
    case GAVL_BGR_15:
 
1515
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1516
        {
 
1517
        pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
 
1518
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1519
          {
 
1520
          get_pixel(col, row, tmp_f);
 
1521
 
 
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);
 
1528
 
 
1529
          PACK_RGB15(b_tmp, g_tmp, r_tmp, *pixel_16);
 
1530
          pixel_16++;
 
1531
          }
 
1532
        }
 
1533
      break;
 
1534
    case GAVL_RGB_16:
 
1535
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1536
        {
 
1537
        pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
 
1538
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1539
          {
 
1540
          get_pixel(col, row, tmp_f);
 
1541
 
 
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);
 
1548
 
 
1549
          PACK_RGB16(r_tmp, g_tmp, b_tmp, *pixel_16);
 
1550
          pixel_16++;
 
1551
          }
 
1552
        }
 
1553
      break;
 
1554
    case GAVL_BGR_16:
 
1555
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1556
        {
 
1557
        pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
 
1558
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1559
          {
 
1560
          get_pixel(col, row, tmp_f);
 
1561
          
 
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);
 
1569
          pixel_16++;
 
1570
          }
 
1571
        }
 
1572
      break;
 
1573
    case GAVL_RGB_24:
 
1574
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1575
        {
 
1576
        pixel = ret->planes[0] + row * ret->strides[0];
 
1577
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1578
          {
 
1579
          get_pixel(col, row, tmp_f);
 
1580
          
 
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);
 
1587
 
 
1588
          pixel[0] = r_tmp;
 
1589
          pixel[1] = g_tmp;
 
1590
          pixel[2] = b_tmp;
 
1591
 
 
1592
          pixel += 3;
 
1593
          }
 
1594
        }
 
1595
      break;
 
1596
    case GAVL_BGR_24:
 
1597
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1598
        {
 
1599
        pixel = ret->planes[0] + row * ret->strides[0];
 
1600
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1601
          {
 
1602
          get_pixel(col, row, tmp_f);
 
1603
          
 
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);
 
1610
 
 
1611
          pixel[2] = r_tmp;
 
1612
          pixel[1] = g_tmp;
 
1613
          pixel[0] = b_tmp;
 
1614
          pixel += 3;
 
1615
          }
 
1616
        }
 
1617
      break;
 
1618
    case GAVL_RGB_32:
 
1619
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1620
        {
 
1621
        pixel = ret->planes[0] + row * ret->strides[0];
 
1622
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1623
          {
 
1624
          get_pixel(col, row, tmp_f);
 
1625
          
 
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);
 
1632
 
 
1633
          pixel[0] = r_tmp;
 
1634
          pixel[1] = g_tmp;
 
1635
          pixel[2] = b_tmp;
 
1636
          pixel += 4;
 
1637
          }
 
1638
        }
 
1639
      break;
 
1640
    case GAVL_BGR_32:
 
1641
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1642
        {
 
1643
        pixel = ret->planes[0] + row * ret->strides[0];
 
1644
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1645
          {
 
1646
          get_pixel(col, row, tmp_f);
 
1647
          
 
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);
 
1654
 
 
1655
          pixel[2] = r_tmp;
 
1656
          pixel[1] = g_tmp;
 
1657
          pixel[0] = b_tmp;
 
1658
          pixel += 4;
 
1659
          }
 
1660
        }
 
1661
      break;
 
1662
    case GAVL_RGBA_32:
 
1663
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1664
        {
 
1665
        pixel = ret->planes[0] + row * ret->strides[0];
 
1666
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1667
          {
 
1668
          get_pixel(col, row, tmp_f);
 
1669
          
 
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);
 
1678
 
 
1679
          pixel[0] = r_tmp;
 
1680
          pixel[1] = g_tmp;
 
1681
          pixel[2] = b_tmp;
 
1682
          pixel[3] = a_tmp;
 
1683
          pixel += 4;
 
1684
          }
 
1685
        }
 
1686
      break;
 
1687
    case GAVL_RGB_48:
 
1688
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1689
        {
 
1690
        pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
 
1691
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1692
          {
 
1693
          get_pixel(col, row, tmp_f);
 
1694
          
 
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);
 
1701
 
 
1702
          pixel_16[0] = r_tmp;
 
1703
          pixel_16[1] = g_tmp;
 
1704
          pixel_16[2] = b_tmp;
 
1705
          pixel_16 += 3;
 
1706
          }
 
1707
        }
 
1708
      break;
 
1709
    case GAVL_RGBA_64:
 
1710
      //      fprintf(stderr, "STRIDES: %d\n", ret->strides[0]);
 
1711
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1712
        {
 
1713
        pixel_16 = (uint16_t*)(ret->planes[0] + row * ret->strides[0]);
 
1714
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1715
          {
 
1716
          get_pixel(col, row, tmp_f);
 
1717
          
 
1718
          r_tmp = FLOAT_TO_16(tmp_f[0]);
 
1719
          r_tmp = RECLIP_16(r_tmp);
 
1720
 
 
1721
          g_tmp = FLOAT_TO_16(tmp_f[1]);
 
1722
          g_tmp = RECLIP_16(g_tmp);
 
1723
 
 
1724
          b_tmp = FLOAT_TO_16(tmp_f[2]);
 
1725
          b_tmp = RECLIP_16(b_tmp);
 
1726
 
 
1727
          a_tmp = FLOAT_TO_16(tmp_f[3]);
 
1728
          a_tmp = RECLIP_16(a_tmp);
 
1729
 
 
1730
          pixel_16[0] = r_tmp;
 
1731
          pixel_16[1] = g_tmp;
 
1732
          pixel_16[2] = b_tmp;
 
1733
          pixel_16[3] = a_tmp;
 
1734
          pixel_16 += 4;
 
1735
          }
 
1736
        }
 
1737
      //      gavl_video_frame_dump(ret, &format, "TEST");
 
1738
      break;
 
1739
    case GAVL_RGB_FLOAT:
 
1740
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1741
        {
 
1742
        pixel_float = (float*)(ret->planes[0] + row * ret->strides[0]);
 
1743
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1744
          {
 
1745
          get_pixel(col, row, tmp_f);
 
1746
 
 
1747
          pixel_float[0] = tmp_f[0];
 
1748
          pixel_float[1] = tmp_f[1];
 
1749
          pixel_float[2] = tmp_f[2];
 
1750
          pixel_float += 3;
 
1751
          }
 
1752
        }
 
1753
      break;
 
1754
    case GAVL_RGBA_FLOAT:
 
1755
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1756
        {
 
1757
        pixel_float = (float*)(ret->planes[0] + row * ret->strides[0]);
 
1758
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1759
          {
 
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];
 
1765
          
 
1766
          pixel_float += 4;
 
1767
          }
 
1768
        }
 
1769
      break;
 
1770
    case GAVL_YUY2:
 
1771
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1772
        {
 
1773
        pixel = ret->planes[0] + row * ret->strides[0];
 
1774
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
1775
          {
 
1776
          get_pixel(2*col, row, tmp_f);
 
1777
 
 
1778
          RGB_TO_YUV();
 
1779
          Y_TO_8(pixel[0]);
 
1780
          U_TO_8(pixel[1]);
 
1781
          V_TO_8(pixel[3]);
 
1782
          
 
1783
          get_pixel(2*col+1, row, tmp_f);
 
1784
          RGB_TO_Y();
 
1785
          Y_TO_8(pixel[2]);
 
1786
 
 
1787
          pixel+= 4;
 
1788
          }
 
1789
        }
 
1790
      break;
 
1791
    case GAVL_YUVA_32:
 
1792
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1793
        {
 
1794
        pixel = ret->planes[0] + row * ret->strides[0];
 
1795
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
1796
          {
 
1797
          get_pixel(col, row, tmp_f);
 
1798
 
 
1799
          RGB_TO_YUV();
 
1800
          Y_TO_8(pixel[0]);
 
1801
          U_TO_8(pixel[1]);
 
1802
          V_TO_8(pixel[2]);
 
1803
          a_tmp = FLOAT_TO_8(tmp_f[3]);
 
1804
          a_tmp = RECLIP(a_tmp);
 
1805
          pixel[3] = a_tmp;          
 
1806
          pixel+= 4;
 
1807
          }
 
1808
        }
 
1809
      break;
 
1810
    case GAVL_UYVY:
 
1811
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
1812
        {
 
1813
        pixel = ret->planes[0] + row * ret->strides[0];
 
1814
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
1815
          {
 
1816
          get_pixel(2*col, row, tmp_f);
 
1817
 
 
1818
          RGB_TO_YUV();
 
1819
          Y_TO_8(pixel[1]);
 
1820
          U_TO_8(pixel[0]);
 
1821
          V_TO_8(pixel[2]);
 
1822
 
 
1823
          
 
1824
          get_pixel(2*col+1, row, tmp_f);
 
1825
          RGB_TO_Y();
 
1826
          Y_TO_8(pixel[3]);
 
1827
          pixel+= 4;
 
1828
          }
 
1829
        }
 
1830
      break;
 
1831
    case GAVL_YUV_420_P:
 
1832
      for(row = 0; row < TEST_PICTURE_HEIGHT/2; row++)
 
1833
        {
 
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];
 
1837
 
 
1838
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
1839
          {
 
1840
          get_pixel(2*col, 2*row, tmp_f);
 
1841
 
 
1842
          RGB_TO_YUV();
 
1843
          Y_TO_8(*y);
 
1844
          U_TO_8(*u);
 
1845
          V_TO_8(*v);
 
1846
 
 
1847
          y++;
 
1848
          
 
1849
          get_pixel(2*col+1, 2*row, tmp_f);
 
1850
          RGB_TO_YUV();
 
1851
          Y_TO_8(*y);
 
1852
          U_TO_8(*u);
 
1853
          V_TO_8(*v);
 
1854
          
 
1855
          y++;
 
1856
          u++;
 
1857
          v++;
 
1858
          }
 
1859
 
 
1860
        y = ret->planes[0] + (2 * row + 1) * ret->strides[0];
 
1861
 
 
1862
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
1863
          {
 
1864
          get_pixel(2*col, 2*row+1, tmp_f);
 
1865
 
 
1866
          RGB_TO_Y();
 
1867
          Y_TO_8(*y);
 
1868
 
 
1869
          y++;
 
1870
          
 
1871
          get_pixel(2*col+1, 2*row+1, tmp_f);
 
1872
 
 
1873
          RGB_TO_Y();
 
1874
          Y_TO_8(*y);
 
1875
          
 
1876
          y++;
 
1877
          }
 
1878
        }
 
1879
      break;
 
1880
    case GAVL_YUV_410_P:
 
1881
      for(row = 0; row < TEST_PICTURE_HEIGHT/4; row++)
 
1882
        {
 
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];
 
1886
 
 
1887
        for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
 
1888
          {
 
1889
          get_pixel(4*col, 4*row, tmp_f);
 
1890
          RGB_TO_YUV();
 
1891
          Y_TO_8(*y);
 
1892
          U_TO_8(*u);
 
1893
          V_TO_8(*v);
 
1894
          y++;
 
1895
          
 
1896
          get_pixel(4*col+1, 4*row, tmp_f);
 
1897
          RGB_TO_Y();
 
1898
          Y_TO_8(*y);
 
1899
          
 
1900
          y++;
 
1901
          get_pixel(4*col+2, 4*row, tmp_f);
 
1902
          RGB_TO_Y();
 
1903
          Y_TO_8(*y);
 
1904
 
 
1905
          
 
1906
          y++;
 
1907
          get_pixel(4*col+3, 4*row, tmp_f);
 
1908
          RGB_TO_Y();
 
1909
          Y_TO_8(*y);
 
1910
          
 
1911
          y++;
 
1912
 
 
1913
          u++;
 
1914
          v++;
 
1915
          }
 
1916
 
 
1917
        y = ret->planes[0] + (4 * row + 1) * ret->strides[0];
 
1918
 
 
1919
        for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
 
1920
          {
 
1921
          get_pixel(4*col, 4*row+1, tmp_f);
 
1922
          RGB_TO_Y();
 
1923
          Y_TO_8(*y);
 
1924
 
 
1925
          y++;
 
1926
          
 
1927
          get_pixel(4*col+1, 4*row+1, tmp_f);
 
1928
          RGB_TO_Y();
 
1929
          Y_TO_8(*y);
 
1930
 
 
1931
          y++;
 
1932
 
 
1933
          get_pixel(4*col+2, 4*row+1, tmp_f);
 
1934
          RGB_TO_Y();
 
1935
          Y_TO_8(*y);
 
1936
 
 
1937
          y++;
 
1938
 
 
1939
          get_pixel(4*col+3, 4*row+1, tmp_f);
 
1940
          RGB_TO_Y();
 
1941
          Y_TO_8(*y);
 
1942
 
 
1943
          y++;
 
1944
          }
 
1945
 
 
1946
        y = ret->planes[0] + (4 * row + 2) * ret->strides[0];
 
1947
 
 
1948
        for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
 
1949
          {
 
1950
          get_pixel(4*col, 4*row+2, tmp_f);
 
1951
          RGB_TO_Y();
 
1952
          Y_TO_8(*y);
 
1953
 
 
1954
          y++;
 
1955
          
 
1956
          get_pixel(4*col+1, 4*row+2, tmp_f);
 
1957
          RGB_TO_Y();
 
1958
          Y_TO_8(*y);
 
1959
          y++;
 
1960
 
 
1961
          get_pixel(4*col+2, 4*row+2, tmp_f);
 
1962
          RGB_TO_Y();
 
1963
          Y_TO_8(*y);
 
1964
 
 
1965
          y++;
 
1966
 
 
1967
          get_pixel(4*col+3, 4*row+2, tmp_f);
 
1968
          RGB_TO_Y();
 
1969
          Y_TO_8(*y);
 
1970
 
 
1971
          y++;
 
1972
          }
 
1973
 
 
1974
        y = ret->planes[0] + (4 * row + 3) * ret->strides[0];
 
1975
 
 
1976
        for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
 
1977
          {
 
1978
          get_pixel(4*col, 4*row+3, tmp_f);
 
1979
          RGB_TO_Y();
 
1980
          Y_TO_8(*y);
 
1981
 
 
1982
          y++;
 
1983
          
 
1984
          get_pixel(4*col+1, 4*row+3, tmp_f);
 
1985
          RGB_TO_Y();
 
1986
          Y_TO_8(*y);
 
1987
 
 
1988
          y++;
 
1989
 
 
1990
          get_pixel(4*col+2, 4*row+3, tmp_f);
 
1991
          RGB_TO_Y();
 
1992
          Y_TO_8(*y);
 
1993
 
 
1994
          y++;
 
1995
 
 
1996
          get_pixel(4*col+3, 4*row+3, tmp_f);
 
1997
          RGB_TO_Y();
 
1998
          Y_TO_8(*y);
 
1999
 
 
2000
          y++;
 
2001
          }
 
2002
 
 
2003
        }
 
2004
      break;
 
2005
    case GAVL_YUV_422_P:
 
2006
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2007
        {
 
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];
 
2011
 
 
2012
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
2013
          {
 
2014
          get_pixel(2* col, row, tmp_f);
 
2015
 
 
2016
          RGB_TO_YUV();
 
2017
          Y_TO_8(*y);
 
2018
          U_TO_8(*u);
 
2019
          V_TO_8(*v);
 
2020
 
 
2021
          y++;
 
2022
          
 
2023
          get_pixel(2* col + 1, row, tmp_f);
 
2024
          RGB_TO_Y();
 
2025
          Y_TO_8(*y);
 
2026
          
 
2027
          y++;
 
2028
          u++;
 
2029
          v++;
 
2030
          }
 
2031
        }
 
2032
      break;
 
2033
    case GAVL_YUV_422_P_16:
 
2034
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2035
        {
 
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]);
 
2039
 
 
2040
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
2041
          {
 
2042
          get_pixel(2* col, row, tmp_f);
 
2043
 
 
2044
          RGB_TO_YUV();
 
2045
          Y_TO_16(*y_16);
 
2046
          U_TO_16(*u_16);
 
2047
          V_TO_16(*v_16);
 
2048
 
 
2049
          y_16++;
 
2050
          
 
2051
          get_pixel(2* col + 1, row, tmp_f);
 
2052
          RGB_TO_Y();
 
2053
          Y_TO_16(*y_16);
 
2054
          
 
2055
          y_16++;
 
2056
          u_16++;
 
2057
          v_16++;
 
2058
          }
 
2059
        }
 
2060
      break;
 
2061
    case GAVL_YUV_411_P:
 
2062
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2063
        {
 
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];
 
2067
 
 
2068
        for(col = 0; col < TEST_PICTURE_WIDTH/4; col++)
 
2069
          {
 
2070
          get_pixel(4* col, row, tmp_f);
 
2071
 
 
2072
          RGB_TO_YUV();
 
2073
          Y_TO_8(*y);
 
2074
          U_TO_8(*u);
 
2075
          V_TO_8(*v);
 
2076
 
 
2077
          y++;
 
2078
          
 
2079
          get_pixel(4* col + 1, row, tmp_f);
 
2080
          RGB_TO_Y();
 
2081
          Y_TO_8(*y);
 
2082
 
 
2083
          
 
2084
          y++;
 
2085
          get_pixel(4* col + 2, row, tmp_f);
 
2086
          RGB_TO_Y();
 
2087
          Y_TO_8(*y);
 
2088
          
 
2089
          y++;
 
2090
          get_pixel(4* col + 3, row, tmp_f);
 
2091
          RGB_TO_Y();
 
2092
          Y_TO_8(*y);
 
2093
          
 
2094
          y++;
 
2095
 
 
2096
          u++;
 
2097
          v++;
 
2098
          }
 
2099
        }
 
2100
      break;
 
2101
    case GAVL_YUV_444_P:
 
2102
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2103
        {
 
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];
 
2107
 
 
2108
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
2109
          {
 
2110
          get_pixel(col, row, tmp_f);
 
2111
 
 
2112
          RGB_TO_YUV();
 
2113
          Y_TO_8(*y);
 
2114
          U_TO_8(*u);
 
2115
          V_TO_8(*v);
 
2116
          
 
2117
          y++;
 
2118
          u++;
 
2119
          v++;
 
2120
          }
 
2121
        }
 
2122
      break;
 
2123
    case GAVL_YUV_444_P_16:
 
2124
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2125
        {
 
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]);
 
2129
 
 
2130
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
2131
          {
 
2132
          get_pixel(col, row, tmp_f);
 
2133
 
 
2134
          RGB_TO_YUV();
 
2135
          Y_TO_16(*y_16);
 
2136
          U_TO_16(*u_16);
 
2137
          V_TO_16(*v_16);
 
2138
          
 
2139
          y_16++;
 
2140
          u_16++;
 
2141
          v_16++;
 
2142
          }
 
2143
        }
 
2144
      break;
 
2145
    case GAVL_YUVJ_420_P:
 
2146
      for(row = 0; row < TEST_PICTURE_HEIGHT/2; row++)
 
2147
        {
 
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];
 
2151
 
 
2152
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
2153
          {
 
2154
          get_pixel(2*col, 2*row, tmp_f);
 
2155
 
 
2156
          RGB_TO_YUV();
 
2157
          YJ_TO_8(*y);
 
2158
          UJ_TO_8(*u);
 
2159
          VJ_TO_8(*v);
 
2160
 
 
2161
          y++;
 
2162
          
 
2163
          get_pixel(2*col+1, 2*row, tmp_f);
 
2164
 
 
2165
          RGB_TO_Y();
 
2166
          YJ_TO_8(*y);
 
2167
          
 
2168
          y++;
 
2169
          u++;
 
2170
          v++;
 
2171
          }
 
2172
 
 
2173
        y = ret->planes[0] + (2 * row + 1) * ret->strides[0];
 
2174
 
 
2175
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
2176
          {
 
2177
          get_pixel(2*col, 2*row+1, tmp_f);
 
2178
          RGB_TO_Y();
 
2179
          YJ_TO_8(*y);
 
2180
 
 
2181
          y++;
 
2182
          
 
2183
          get_pixel(2*col+1, 2*row+1, tmp_f);
 
2184
          RGB_TO_Y();
 
2185
          YJ_TO_8(*y);
 
2186
          
 
2187
          y++;
 
2188
          }
 
2189
        }
 
2190
      break;
 
2191
    case GAVL_YUVJ_422_P:
 
2192
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2193
        {
 
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];
 
2197
 
 
2198
        for(col = 0; col < TEST_PICTURE_WIDTH/2; col++)
 
2199
          {
 
2200
          get_pixel(2* col, row, tmp_f);
 
2201
 
 
2202
          RGB_TO_YUV();
 
2203
          YJ_TO_8(*y);
 
2204
          UJ_TO_8(*u);
 
2205
          VJ_TO_8(*v);
 
2206
 
 
2207
          y++;
 
2208
          
 
2209
          get_pixel(2* col + 1, row, tmp_f);
 
2210
          RGB_TO_Y();
 
2211
          YJ_TO_8(*y);
 
2212
 
 
2213
          
 
2214
          y++;
 
2215
          u++;
 
2216
          v++;
 
2217
          }
 
2218
        }
 
2219
      break;
 
2220
    case GAVL_YUVJ_444_P:
 
2221
      for(row = 0; row < TEST_PICTURE_HEIGHT; row++)
 
2222
        {
 
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];
 
2226
 
 
2227
        for(col = 0; col < TEST_PICTURE_WIDTH; col++)
 
2228
          {
 
2229
          get_pixel(col, row, tmp_f);
 
2230
          RGB_TO_YUV();
 
2231
          YJ_TO_8(*y);
 
2232
          UJ_TO_8(*u);
 
2233
          VJ_TO_8(*v);
 
2234
          y++;
 
2235
          u++;
 
2236
          v++;
 
2237
          }
 
2238
        }
 
2239
      break;
 
2240
    case GAVL_PIXELFORMAT_NONE:
 
2241
      break;
 
2242
    }
 
2243
  
 
2244
  return  ret;
 
2245
  }
 
2246
 
 
2247
int main(int argc, char ** argv)
 
2248
  {
 
2249
#ifdef ALL_PIXELFORMATS
 
2250
  int i, j;
 
2251
#endif
 
2252
  const char * tmp1, * tmp2;
 
2253
  char filename_buffer[128];
 
2254
 
 
2255
  float background[3] = { 1.0, 0.0, 0.0 };
 
2256
    
 
2257
  gavl_video_format_t input_format;
 
2258
  gavl_video_format_t output_format;
 
2259
 
 
2260
  gavl_video_frame_t * input_frame;
 
2261
  gavl_video_frame_t * output_frame;
 
2262
  
 
2263
  gavl_video_options_t * opt;
 
2264
 
 
2265
  gavl_video_converter_t * cnv = gavl_video_converter_create();
 
2266
  opt = gavl_video_converter_get_options(cnv);
 
2267
 
 
2268
  memset(&input_format, 0, sizeof(input_format));
 
2269
  memset(&output_format, 0, sizeof(output_format));
 
2270
  
 
2271
  input_format.image_width = TEST_PICTURE_WIDTH;
 
2272
  input_format.image_height = TEST_PICTURE_HEIGHT;
 
2273
  
 
2274
  input_format.frame_width = TEST_PICTURE_WIDTH;
 
2275
  input_format.frame_height = TEST_PICTURE_HEIGHT;
 
2276
  
 
2277
  input_format.pixel_width = 1;
 
2278
  input_format.pixel_height = 1;
 
2279
  
 
2280
  output_format.frame_width = TEST_PICTURE_WIDTH;
 
2281
  output_format.frame_height = TEST_PICTURE_HEIGHT;
 
2282
 
 
2283
  output_format.image_width = TEST_PICTURE_WIDTH;
 
2284
  output_format.image_height = TEST_PICTURE_HEIGHT;
 
2285
 
 
2286
  output_format.pixel_width = 1;
 
2287
  output_format.pixel_height = 1;
 
2288
 
 
2289
  init_yuv();
 
2290
 
 
2291
#ifdef ALL_PIXELFORMATS
 
2292
  for(i = 0; i < gavl_num_pixelformats(); i++)
 
2293
    {
 
2294
    input_format.pixelformat = gavl_get_pixelformat(i);
 
2295
#else
 
2296
    input_format.pixelformat = IN_PIXELFORMAT;
 
2297
#endif
 
2298
    input_frame = create_picture(input_format.pixelformat,
 
2299
                                 get_pixel_colorbar);
 
2300
 
 
2301
    tmp1 = gavl_pixelformat_to_string(input_format.pixelformat);
 
2302
    sprintf(filename_buffer, "0test_%s.png", tmp1);
 
2303
    
 
2304
    write_file(filename_buffer,
 
2305
                 input_frame, &input_format);
 
2306
 
 
2307
#ifdef ALL_PIXELFORMATS
 
2308
    for(j = 0; j < gavl_num_pixelformats(); j++)
 
2309
      {
 
2310
      output_format.pixelformat = gavl_get_pixelformat(j);
 
2311
#else
 
2312
      output_format.pixelformat = OUT_PIXELFORMAT;
 
2313
#endif
 
2314
 
 
2315
      gavl_video_options_set_defaults(opt);
 
2316
 
 
2317
      gavl_video_options_set_alpha_mode(opt, GAVL_ALPHA_IGNORE);
 
2318
      gavl_video_options_set_background_color(opt, background);
 
2319
 
 
2320
#ifdef ALL_PIXELFORMATS
 
2321
      if(input_format.pixelformat == output_format.pixelformat)
 
2322
        continue;
 
2323
#endif
 
2324
      
 
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);
 
2329
      
 
2330
      fprintf(stderr, "%s *************\n", tmp2);
 
2331
 
 
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);
 
2335
      
 
2336
      if(gavl_video_converter_init(cnv, &input_format, &output_format) <= 0)
 
2337
        {
 
2338
        fprintf(stderr, "No Conversion defined yet or not necessary\n");
 
2339
        }
 
2340
      else
 
2341
        {
 
2342
        fprintf(stderr, "ANSI C Version: ");
 
2343
        gavl_video_convert(cnv, input_frame, output_frame);
 
2344
        }
 
2345
      
 
2346
      /* Now, do some conversions */
 
2347
 
 
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);
 
2352
      
 
2353
      
 
2354
      /* Now, initialize with MMX */
 
2355
 
 
2356
#if 0
 
2357
      gavl_video_options_set_accel_flags(opt, GAVL_ACCEL_MMX);
 
2358
      
 
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");
 
2363
      else
 
2364
        {
 
2365
        fprintf(stderr, "MMX Version:    ");
 
2366
        gavl_video_convert(cnv, input_frame, output_frame);
 
2367
        }
 
2368
      write_file(filename_buffer,
 
2369
                 output_frame, &output_format);
 
2370
      fprintf(stderr, "Wrote %s\n", filename_buffer);
 
2371
      
 
2372
      
 
2373
      gavl_video_options_set_accel_flags(opt, GAVL_ACCEL_MMXEXT);
 
2374
 
 
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");
 
2379
      else
 
2380
        {
 
2381
        fprintf(stderr, "MMXEXT Version:    ");
 
2382
        gavl_video_convert(cnv, input_frame, output_frame);
 
2383
        }
 
2384
      write_file(filename_buffer,
 
2385
                 output_frame, &output_format);
 
2386
      fprintf(stderr, "Wrote %s\n", filename_buffer);
 
2387
#endif
 
2388
      
 
2389
      gavl_video_frame_destroy(output_frame);
 
2390
 
 
2391
#ifdef ALL_PIXELFORMATS
 
2392
      }
 
2393
    }
 
2394
#endif  
 
2395
  
 
2396
  return 0;
 
2397
  }