File: psnr.c

package info (click to toggle)
gavl 1.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 14,912 kB
  • sloc: ansic: 437,319; sh: 10,487; makefile: 238
file content (590 lines) | stat: -rw-r--r-- 20,946 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/*****************************************************************
 * gavl - a general purpose audio/video processing library
 *
 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
 * gmerlin-general@lists.sourceforge.net
 * http://gmerlin.sourceforge.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * *****************************************************************/

#include <gavl.h>
#include <stdlib.h>
#include <math.h>
#include "c/colorspace_tables.h"
#include "c/colorspace_macros.h"

static void psnr_rgb_16(double * dst,
                        const uint8_t * src1, int src1_stride,
                        const uint8_t * src2, int src2_stride,
                        int w, int h)
  {
  int i, j;
  const uint16_t *s1;
  const uint16_t *s2;

  double r = 0.0, g = 0.0, b = 0.0;

  dst[0] = 0.0;
  dst[1] = 0.0;
  dst[2] = 0.0;
  
  for(i = 0; i < h; i++)
    {
    s1 = (const uint16_t *)(src1 + i * src1_stride);
    s2 = (const uint16_t *)(src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      r = RGB16_TO_R_FLOAT(*s1) - RGB16_TO_R_FLOAT(*s2);
      r *= r;
      dst[0] += r;
      
      g = RGB16_TO_G_FLOAT(*s1) - RGB16_TO_G_FLOAT(*s2);
      g *= g;
      dst[1] += g;

      b = RGB16_TO_B_FLOAT(*s1) - RGB16_TO_B_FLOAT(*s2);
      b *= b;
      dst[1] += b;

      s1++;
      s2++;
      }
    }
  }

static void psnr_rgb_15(double * dst,
                        const uint8_t * src1, int src1_stride,
                        const uint8_t * src2, int src2_stride,
                        int w, int h)
  {
  int i, j;
  const uint16_t *s1;
  const uint16_t *s2;

  double r = 0.0, g = 0.0, b = 0.0;

  dst[0] = 0.0;
  dst[1] = 0.0;
  dst[2] = 0.0;
  
  for(i = 0; i < h; i++)
    {
    s1 = (const uint16_t *)(src1 + i * src1_stride);
    s2 = (const uint16_t *)(src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      r = RGB15_TO_R_FLOAT(*s1) - RGB15_TO_R_FLOAT(*s2);
      r *= r;
      dst[0] += r;
      
      g = RGB15_TO_G_FLOAT(*s1) - RGB15_TO_G_FLOAT(*s2);
      g *= g;
      dst[1] += g;

      b = RGB15_TO_B_FLOAT(*s1) - RGB15_TO_B_FLOAT(*s2);
      b *= b;
      dst[2] += b;
      s1++;
      s2++;
      }
    }
  }

static double psnr_8(const uint8_t * src1, int src1_stride,
                     const uint8_t * src2, int src2_stride,
                     int w, int h, int advance)
  {
  int i, j;
  const uint8_t *s1;
  const uint8_t *s2;
  double ret = 0;
  double diff;
  for(i = 0; i < h; i++)
    {
    s1 = (src1 + i * src1_stride);
    s2 = (src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      diff = RGB_8_TO_FLOAT(*s1) - RGB_8_TO_FLOAT(*s2);
      diff *= diff;
      ret += diff;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

static double psnr_y_8(const uint8_t * src1, int src1_stride,
                       const uint8_t * src2, int src2_stride,
                       int w, int h, int advance)
  {
  int i, j;
  const uint8_t *s1;
  const uint8_t *s2;
  double ret = 0;
  double diff;
  for(i = 0; i < h; i++)
    {
    s1 = (src1 + i * src1_stride);
    s2 = (src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      diff = Y_8_TO_FLOAT(*s1) - Y_8_TO_FLOAT(*s2);
      diff *= diff;
      ret += diff;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

static double psnr_uv_8(const uint8_t * src1, int src1_stride,
                        const uint8_t * src2, int src2_stride,
                        int w, int h, int advance)
  {
  int i, j;
  const uint8_t *s1;
  const uint8_t *s2;
  double ret = 0;
  double diff;
  for(i = 0; i < h; i++)
    {
    s1 = (src1 + i * src1_stride);
    s2 = (src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      diff = UV_8_TO_FLOAT(*s1) - UV_8_TO_FLOAT(*s2);
      diff *= diff;
      ret += diff;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

static double psnr_16(const uint8_t * src1, int src1_stride,
                      const uint8_t * src2, int src2_stride,
                      int w, int h, int advance)
  {
  int i, j;
  const uint16_t *s1;
  const uint16_t *s2;
  double ret = 0;
  double diff;
  for(i = 0; i < h; i++)
    {
    s1 = (const uint16_t *)(src1 + i * src1_stride);
    s2 = (const uint16_t *)(src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      diff = RGB_16_TO_FLOAT(*s1) - RGB_16_TO_FLOAT(*s2);
      diff *= diff;
      ret += diff;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

static double psnr_y_16(const uint8_t * src1, int src1_stride,
                        const uint8_t * src2, int src2_stride,
                        int w, int h, int advance)
  {
  int i, j;
  const uint16_t *s1;
  const uint16_t *s2;
  double ret = 0;
  double d;
  for(i = 0; i < h; i++)
    {
    s1 = (const uint16_t *)(src1 + i * src1_stride);
    s2 = (const uint16_t *)(src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      d = Y_16_TO_Y_FLOAT(*s1) - Y_16_TO_Y_FLOAT(*s2);
      d *= d;
      ret += d;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

static double psnr_uv_16(const uint8_t * src1, int src1_stride,
                        const uint8_t * src2, int src2_stride,
                        int w, int h, int advance)
  {
  int i, j;
  const uint16_t *s1;
  const uint16_t *s2;
  double ret = 0;
  double d;
  for(i = 0; i < h; i++)
    {
    s1 = (const uint16_t *)(src1 + i * src1_stride);
    s2 = (const uint16_t *)(src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      d = UV_16_TO_UV_FLOAT(*s1) - UV_16_TO_UV_FLOAT(*s2);
      d *= d;
      ret += d;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

static double psnr_float(const uint8_t * src1, int src1_stride,
                         const uint8_t * src2, int src2_stride,
                         int w, int h, int advance)
  {
  int i, j;
  const float *s1;
  const float *s2;
  double ret = 0;
  double diff;
  for(i = 0; i < h; i++)
    {
    s1 = (const float *)(src1 + i * src1_stride);
    s2 = (const float *)(src2 + i * src2_stride);
    
    for(j = 0; j < w; j++)
      {
      diff = (*s1) - (*s2);
      diff *= diff;
      ret += diff;
      s1+= advance;
      s2+= advance;
      }
    }
  ret /= (w * h);
  return ret;
  }

void gavl_video_frame_psnr(double * psnr,
                           const gavl_video_frame_t * src1,
                           const gavl_video_frame_t * src2,
                           const gavl_video_format_t * format)
  {
  int sub_h, sub_v;
  int swap_rgb = 0;
  int num_components;
  int i;
  
  switch(format->pixelformat)
    {
    case GAVL_BGR_15:
      swap_rgb = 1;
      // Fall through
    case GAVL_RGB_15:
      psnr_rgb_15(psnr,
                  src1->planes[0], src1->strides[0],
                  src2->planes[0], src2->strides[0],
                  format->image_width, format->image_height);
      break;
    case GAVL_BGR_16:
      swap_rgb = 1;
      // Fall through
    case GAVL_RGB_16:
      psnr_rgb_16(psnr,
                  src1->planes[0], src1->strides[0],
                  src2->planes[0], src2->strides[0],
                  format->image_width, format->image_height);
      break;
    case GAVL_GRAY_8:
      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 1);
      break;
    case GAVL_GRAY_16:
      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 2);
      psnr[1] = psnr_8(src1->planes[0]+1, src1->strides[0],
                      src2->planes[0]+1, src2->strides[0],
                      format->image_width, format->image_height, 2);
      break;
    case GAVL_GRAY_FLOAT:
      psnr[0] = psnr_float(src1->planes[0], src1->strides[0],
                          src2->planes[0], src2->strides[0],
                          format->image_width, format->image_height, 1);
      break;
    case GAVL_GRAYA_16:
      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 2);
      psnr[1] = psnr_8(src1->planes[0]+1, src1->strides[0],
                      src2->planes[0]+1, src2->strides[0],
                      format->image_width, format->image_height, 2);
      break;
    case GAVL_YUY2:
      /* Y */
      psnr[0] = psnr_y_8(src1->planes[0], src1->strides[0],
                        src2->planes[0], src2->strides[0],
                        format->image_width, format->image_height, 2);
      /* U */
      psnr[1] = psnr_uv_8(src1->planes[0]+1, src1->strides[0],
                         src2->planes[0], src2->strides[0],
                         format->image_width, format->image_height, 4);
      /* V */
      psnr[2] = psnr_uv_8(src1->planes[0]+3, src1->strides[0],
                         src2->planes[0], src2->strides[0],
                         format->image_width, format->image_height, 4);
      break;
    case GAVL_UYVY:
      /* Y */
      psnr[0] = psnr_y_8(src1->planes[0]+1, src1->strides[0],
                        src2->planes[0], src2->strides[0],
                        format->image_width, format->image_height, 2);
      /* U */
      psnr[1] = psnr_uv_8(src1->planes[0], src1->strides[0],
                         src2->planes[0], src2->strides[0],
                         format->image_width, format->image_height, 4);
      /* V */
      psnr[2] = psnr_uv_8(src1->planes[0]+2, src1->strides[0],
                         src2->planes[0], src2->strides[0],
                         format->image_width, format->image_height, 4);
      break;
    case GAVL_GRAYA_32:
      psnr[0] = psnr_16(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 2);
      psnr[1] = psnr_16(src1->planes[0]+2, src1->strides[0],
                      src2->planes[0]+2, src2->strides[0],
                      format->image_width, format->image_height, 2);
      break;
    case GAVL_GRAYA_FLOAT:
      psnr[0] = psnr_float(src1->planes[0], src1->strides[0],
                          src2->planes[0], src2->strides[0],
                          format->image_width, format->image_height, 2);
      psnr[1] = psnr_float(src1->planes[0]+sizeof(float), src1->strides[0],
                          src2->planes[0]+sizeof(float), src2->strides[0],
                          format->image_width, format->image_height, 2);
      break;
    case GAVL_BGR_24:
      swap_rgb = 1;
      // Fall through
    case GAVL_RGB_24:
      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 3);
      psnr[1] = psnr_8(src1->planes[0]+1, src1->strides[0],
                      src2->planes[0]+1, src2->strides[0],
                      format->image_width, format->image_height, 3);
      psnr[2] = psnr_8(src1->planes[0]+2, src1->strides[0],
                      src2->planes[0]+2, src2->strides[0],
                      format->image_width, format->image_height, 3);
      break;
    case GAVL_BGR_32:
      swap_rgb = 1;
      // Fall through
    case GAVL_RGB_32:
      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 4);
      psnr[1] = psnr_8(src1->planes[0]+1, src1->strides[0],
                      src2->planes[0]+1, src2->strides[0],
                      format->image_width, format->image_height, 4);
      psnr[2] = psnr_8(src1->planes[0]+2, src1->strides[0],
                      src2->planes[0]+2, src2->strides[0],
                      format->image_width, format->image_height, 4);
      break;
    case GAVL_RGBA_32:
      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 4);
      psnr[1] = psnr_8(src1->planes[0]+1, src1->strides[0],
                      src2->planes[0]+1, src2->strides[0],
                      format->image_width, format->image_height, 4);
      psnr[2] = psnr_8(src1->planes[0]+2, src1->strides[0],
                      src2->planes[0]+2, src2->strides[0],
                      format->image_width, format->image_height, 4);
      psnr[3] = psnr_8(src1->planes[0]+3, src1->strides[0],
                      src2->planes[0]+3, src2->strides[0],
                      format->image_width, format->image_height, 4);
      break;
    case GAVL_YUVA_32:
      psnr[0] = psnr_y_8(src1->planes[0], src1->strides[0],
                      src2->planes[0], src2->strides[0],
                      format->image_width, format->image_height, 4);
      psnr[1] = psnr_uv_8(src1->planes[0]+1, src1->strides[0],
                         src2->planes[0]+1, src2->strides[0],
                         format->image_width, format->image_height, 4);
      psnr[2] = psnr_uv_8(src1->planes[0]+2, src1->strides[0],
                         src2->planes[0]+2, src2->strides[0],
                         format->image_width, format->image_height, 4);
      psnr[3] = psnr_8(src1->planes[0]+3, src1->strides[0],
                      src2->planes[0]+3, src2->strides[0],
                      format->image_width, format->image_height, 4);
      break;
    case GAVL_RGB_48:
      psnr[0] = psnr_16(src1->planes[0], src1->strides[0],
                       src2->planes[0], src2->strides[0],
                       format->image_width, format->image_height, 3);
      psnr[1] = psnr_16(src1->planes[0]+2, src1->strides[0],
                       src2->planes[0]+2, src2->strides[0],
                       format->image_width, format->image_height, 3);
      psnr[2] = psnr_16(src1->planes[0]+4, src1->strides[0],
                       src2->planes[0]+4, src2->strides[0],
                       format->image_width, format->image_height, 3);
      break;
    case GAVL_RGBA_64:
      psnr[0] = psnr_16(src1->planes[0], src1->strides[0],
                       src2->planes[0], src2->strides[0],
                       format->image_width, format->image_height, 4);
      psnr[1] = psnr_16(src1->planes[0]+2, src1->strides[0],
                       src2->planes[0]+2, src2->strides[0],
                       format->image_width, format->image_height, 4);
      psnr[2] = psnr_16(src1->planes[0]+4, src1->strides[0],
                       src2->planes[0]+4, src2->strides[0],
                       format->image_width, format->image_height, 4);
      psnr[3] = psnr_16(src1->planes[0]+6, src1->strides[0],
                       src2->planes[0]+6, src2->strides[0],
                       format->image_width, format->image_height, 4);
      break;
    case GAVL_YUVA_64:
      psnr[0] = psnr_y_16(src1->planes[0], src1->strides[0],
                         src2->planes[0], src2->strides[0],
                         format->image_width, format->image_height, 4);
      psnr[1] = psnr_uv_16(src1->planes[0]+2, src1->strides[0],
                          src2->planes[0]+2, src2->strides[0],
                          format->image_width, format->image_height, 4);
      psnr[2] = psnr_uv_16(src1->planes[0]+4, src1->strides[0],
                          src2->planes[0]+4, src2->strides[0],
                          format->image_width, format->image_height, 4);
      psnr[3] = psnr_16(src1->planes[0]+6, src1->strides[0],
                       src2->planes[0]+6, src2->strides[0],
                       format->image_width, format->image_height, 4);
      break;
    case GAVL_RGB_FLOAT:
    case GAVL_YUV_FLOAT:
      psnr[0] = psnr_float(src1->planes[0], src1->strides[0],
                       src2->planes[0], src2->strides[0],
                       format->image_width, format->image_height, 3);
      psnr[1] = psnr_float(src1->planes[0]+sizeof(float), src1->strides[0],
                       src2->planes[0]+sizeof(float), src2->strides[0],
                       format->image_width, format->image_height, 3);
      psnr[2] = psnr_float(src1->planes[0]+2*sizeof(float), src1->strides[0],
                       src2->planes[0]+2*sizeof(float), src2->strides[0],
                       format->image_width, format->image_height, 3);
      break;
    case GAVL_RGBA_FLOAT:
    case GAVL_YUVA_FLOAT:
      psnr[0] = psnr_float(src1->planes[0], src1->strides[0],
                          src2->planes[0], src2->strides[0],
                          format->image_width, format->image_height, 4);
      psnr[1] = psnr_float(src1->planes[0]+sizeof(float), src1->strides[0],
                       src2->planes[0]+2, src2->strides[0],
                       format->image_width, format->image_height, 4);
      psnr[2] = psnr_float(src1->planes[0]+2*sizeof(float), src1->strides[0],
                       src2->planes[0]+4, src2->strides[0],
                       format->image_width, format->image_height, 4);
      psnr[4] = psnr_float(src1->planes[0]+3*sizeof(float), src1->strides[0],
                       src2->planes[0]+4, src2->strides[0],
                       format->image_width, format->image_height, 4);
      break;
    case GAVL_YUV_420_P:
    case GAVL_YUV_410_P:
    case GAVL_YUV_411_P:
    case GAVL_YUV_422_P:
    case GAVL_YUV_444_P:
      gavl_pixelformat_chroma_sub(format->pixelformat,
                                  &sub_h, &sub_v);
      psnr[0] = psnr_y_8(src1->planes[0], src1->strides[0],
                        src2->planes[0], src2->strides[0],
                        format->image_width, format->image_height, 1);
      psnr[1] = psnr_uv_8(src1->planes[1], src1->strides[1],
                        src2->planes[1], src2->strides[1],
                        format->image_width/sub_h, format->image_height/sub_v, 1);
      psnr[2] = psnr_uv_8(src1->planes[2], src1->strides[2],
                         src2->planes[2], src2->strides[2],
                         format->image_width/sub_h, format->image_height/sub_v, 1);
      break;
    case GAVL_YUVJ_420_P:
    case GAVL_YUVJ_422_P:
    case GAVL_YUVJ_444_P:
      gavl_pixelformat_chroma_sub(format->pixelformat,
                                  &sub_h, &sub_v);

      psnr[0] = psnr_8(src1->planes[0], src1->strides[0],
                     src2->planes[0], src2->strides[0],
                     format->image_width, format->image_height, 1);
      psnr[1] = psnr_8(src1->planes[1], src1->strides[1],
                     src2->planes[1], src2->strides[1],
                     format->image_width/sub_h, format->image_height/sub_v, 1);
      psnr[2] = psnr_8(src1->planes[2], src1->strides[2],
                     src2->planes[2], src2->strides[2],
                     format->image_width/sub_h, format->image_height/sub_v, 1);
      break;
    case GAVL_YUV_444_P_16:
    case GAVL_YUV_422_P_16:
      gavl_pixelformat_chroma_sub(format->pixelformat,
                                  &sub_h, &sub_v);
      psnr[0] = psnr_y_16(src1->planes[0], src1->strides[0],
                         src2->planes[0], src2->strides[0],
                         format->image_width, format->image_height, 1);
      
      psnr[1] = psnr_uv_16(src1->planes[1], src1->strides[1],
                          src2->planes[1], src2->strides[1],
                          format->image_width/sub_h, format->image_height/sub_v, 1);
      
      psnr[2] = psnr_uv_16(src1->planes[2], src1->strides[2],
                          src2->planes[2], src2->strides[2],
                          format->image_width/sub_h, format->image_height/sub_v, 1);
      break;
    case GAVL_PIXELFORMAT_NONE:
      break;
    }

  if(swap_rgb)
    {
    double swp = psnr[0];
    psnr[0] = psnr[2];
    psnr[2] = swp;
    }

  if(gavl_pixelformat_is_gray(format->pixelformat))
    num_components = 1;
  else
    num_components = 3;
  
  if(gavl_pixelformat_has_alpha(format->pixelformat))
    num_components++;
  
  for(i = 0; i < num_components; i++)
    psnr[i] = 10 * log10(1/psnr[i]);
  
  }