FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/jpeg2000dwt.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 56 77 72.7%
Functions: 3 3 100.0%
Branches: 33 44 75.0%

Line Branch Exec Source
1 /*
2 * Discrete wavelet transform
3 * Copyright (c) 2007 Kamil Nowosad
4 * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <inttypes.h>
24 #include <stdio.h>
25
26 #include "libavutil/common.h"
27
28 #include "libavcodec/jpeg2000dwt.c"
29
30 #include "libavutil/lfg.h"
31
32 #define MAX_W 256
33
34 40 static int test_dwt(int *array, int *ref, int border[2][2], int decomp_levels, int type, int max_diff) {
35 int ret, j;
36 40 DWTContext s1={{{0}}}, *s= &s1;
37 40 int64_t err2 = 0;
38
39 40 ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, type);
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (ret < 0) {
41 fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
42 return 1;
43 }
44 40 ret = ff_dwt_encode(s, array);
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (ret < 0) {
46 fprintf(stderr, "ff_dwt_encode failed\n");
47 return 1;
48 }
49
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 if (type == FF_DWT97_INT) {
50 // pre-scaling to simulate dequantization which places the binary point at 1 bit above from LSB
51
2/2
✓ Branch 0 taken 147933 times.
✓ Branch 1 taken 20 times.
147953 for (j = 0; j< s->linelen[decomp_levels-1][0] * s->linelen[decomp_levels-1][1]; j++)
52 147933 array[j] <<= I_PRESHIFT;
53 }
54 40 ret = ff_dwt_decode(s, array);
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (ret < 0) {
56 fprintf(stderr, "ff_dwt_encode failed\n");
57 return 1;
58 }
59
2/2
✓ Branch 0 taken 2621440 times.
✓ Branch 1 taken 40 times.
2621480 for (j = 0; j<MAX_W * MAX_W; j++) {
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2621440 times.
2621440 if (FFABS(array[j] - (int64_t)ref[j]) > max_diff) {
61 fprintf(stderr, "missmatch at %d (%d != %d) decomp:%d border %d %d %d %d\n",
62 j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
63 return 2;
64 }
65 2621440 err2 += (array[j] - ref[j]) * (int64_t)(array[j] - ref[j]);
66 2621440 array[j] = ref[j];
67 }
68 40 ff_dwt_destroy(s);
69
70 40 printf("%s, decomp:%2d border %3d %3d %3d %3d milli-err2:%9"PRId64"\n",
71 type == FF_DWT53 ? "5/3i" : "9/7i",
72 40 decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
73
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 1000*err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
74
75 40 return 0;
76 }
77
78 20 static int test_dwtf(float *array, float *ref, int border[2][2], int decomp_levels, float max_diff) {
79 int ret, j;
80 20 DWTContext s1={{{0}}}, *s= &s1;
81 20 double err2 = 0;
82
83 20 ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, FF_DWT97);
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0) {
85 fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
86 return 1;
87 }
88 20 ret = ff_dwt_encode(s, array);
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0) {
90 fprintf(stderr, "ff_dwt_encode failed\n");
91 return 1;
92 }
93 20 ret = ff_dwt_decode(s, array);
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0) {
95 fprintf(stderr, "ff_dwt_encode failed\n");
96 return 1;
97 }
98
2/2
✓ Branch 0 taken 1310720 times.
✓ Branch 1 taken 20 times.
1310740 for (j = 0; j<MAX_W * MAX_W; j++) {
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1310720 times.
1310720 if (FFABS(array[j] - ref[j]) > max_diff) {
100 fprintf(stderr, "missmatch at %d (%f != %f) decomp:%d border %d %d %d %d\n",
101 j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
102 return 2;
103 }
104 1310720 err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
105 1310720 array[j] = ref[j];
106 }
107 20 ff_dwt_destroy(s);
108
109 20 printf("9/7f, decomp:%2d border %3d %3d %3d %3d err2:%20.3f\n",
110 20 decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
111 20 err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
112
113 20 return 0;
114 }
115
116 static int array[MAX_W * MAX_W];
117 static int ref [MAX_W * MAX_W];
118 static float arrayf[MAX_W * MAX_W];
119 static float reff [MAX_W * MAX_W];
120
121 1 int main(void) {
122 AVLFG prng;
123 int i,j;
124 int border[2][2];
125 int ret, decomp_levels;
126
127 1 av_lfg_init(&prng, 1);
128
129
2/2
✓ Branch 0 taken 65536 times.
✓ Branch 1 taken 1 times.
65537 for (i = 0; i<MAX_W * MAX_W; i++)
130 65536 arrayf[i] = reff[i] = array[i] = ref[i] = av_lfg_get(&prng) % 2048;
131
132
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
101 for (i = 0; i < 100; i++) {
133
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 100 times.
500 for (j=0; j<4; j++)
134 400 border[j>>1][j&1] = av_lfg_get(&prng) % MAX_W;
135
4/4
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 53 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 20 times.
100 if (border[0][0] >= border[0][1] || border[1][0] >= border[1][1])
136 80 continue;
137 20 decomp_levels = av_lfg_get(&prng) % FF_DWT_MAX_DECLVLS;
138
139 20 ret = test_dwt(array, ref, border, decomp_levels, FF_DWT53, 0);
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret)
141 return ret;
142
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
20 ret = test_dwt(array, ref, border, decomp_levels, FF_DWT97_INT, FFMIN(7+5*decomp_levels, 15+3*decomp_levels));
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret)
144 return ret;
145 20 ret = test_dwtf(arrayf, reff, border, decomp_levels, 0.05);
146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret)
147 return ret;
148 }
149
150 1 return 0;
151 }
152