../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
75 / 82
91.5%
Branches:
70 / 74
94.6%
Functions:
1 / 1
100.0%

libavcodec/tests/snowenc.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "libavcodec/snowenc.c"
22
23 #include "libavutil/lfg.h"
24 #include "libavutil/mathematics.h"
25 #include "libavutil/mem.h"
26
27 1 int main(void){
28 #define width 256
29 #define height 256
30 int buffer[2][width*height];
31 short obuffer[width*height];
32 SnowContext s;
33 int i;
34 AVLFG prng;
35 1 int ret = 0;
36 1 s.spatial_decomposition_count=6;
37 1 s.spatial_decomposition_type=1;
38
39 1 s.temp_dwt_buffer = av_calloc(width, sizeof(*s.temp_dwt_buffer));
40 1 s.temp_idwt_buffer = av_calloc(width, sizeof(*s.temp_idwt_buffer));
41
42
2/4
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 1 time.
1 if (!s.temp_dwt_buffer || !s.temp_idwt_buffer) {
43 ✗ fprintf(stderr, "Failed to allocate memory\n");
44 ✗ ret = 1;
45 ✗ goto end;
46 }
47
48 1 av_lfg_init(&prng, 1);
49
50 1 printf("testing 5/3 DWT\n");
51
2/2
✓ Branch 13 → 11 taken 65536 times.
✓ Branch 13 → 14 taken 1 time.
65537 for(i=0; i<width*height; i++)
52 65536 buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 19000 - 9000;
53
54 1 ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
55
2/2
✓ Branch 17 → 16 taken 65536 times.
✓ Branch 17 → 18 taken 1 time.
65537 for(i=0; i<width*height; i++)
56 65536 obuffer[i] = buffer[0][i];
57 1 ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
58
59
2/2
✓ Branch 24 → 20 taken 65536 times.
✓ Branch 24 → 25 taken 1 time.
65537 for(i=0; i<width*height; i++)
60
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 23 taken 65536 times.
65536 if(buffer[1][i]!= obuffer[i]) {
61 ✗ printf("fsck: %4dx%4dx %12d %7d\n",i%width, i/width, buffer[1][i], obuffer[i]);
62 ✗ ret = 1;
63 }
64
65 1 printf("testing 9/7 DWT\n");
66 1 s.spatial_decomposition_type=0;
67
2/2
✓ Branch 29 → 27 taken 65536 times.
✓ Branch 29 → 30 taken 1 time.
65537 for(i=0; i<width*height; i++)
68 65536 buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 11000 - 5000;
69
70 1 ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
71
2/2
✓ Branch 33 → 32 taken 65536 times.
✓ Branch 33 → 34 taken 1 time.
65537 for(i=0; i<width*height; i++)
72 65536 obuffer[i] = buffer[0][i];
73 1 ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
74
75
2/2
✓ Branch 40 → 36 taken 65536 times.
✓ Branch 40 → 41 taken 1 time.
65537 for(i=0; i<width*height; i++)
76
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 39 taken 65536 times.
65536 if(FFABS(buffer[1][i] - obuffer[i])>20) {
77 ✗ printf("fsck: %4dx%4d %12d %7d\n",i%width, i/width, buffer[1][i], obuffer[i]);
78 ✗ ret = 1;
79 }
80
81 {
82 int level, orientation, x, y;
83 int64_t errors[8][4];
84 1 int64_t g=0;
85
86 1 memset(errors, 0, sizeof(errors));
87 1 s.spatial_decomposition_count=3;
88 1 s.spatial_decomposition_type=0;
89
2/2
✓ Branch 76 → 42 taken 3 times.
✓ Branch 76 → 77 taken 1 time.
4 for(level=0; level<s.spatial_decomposition_count; level++){
90
2/2
✓ Branch 74 → 43 taken 10 times.
✓ Branch 74 → 75 taken 3 times.
13 for(orientation=level ? 1 : 0; orientation<4; orientation++){
91 10 int w= width >> (s.spatial_decomposition_count-level);
92 10 int h= height >> (s.spatial_decomposition_count-level);
93 10 int stride= width << (s.spatial_decomposition_count-level);
94 10 IDWTELEM *buf= obuffer;
95 10 int64_t error=0;
96
97
2/2
✓ Branch 43 → 44 taken 6 times.
✓ Branch 43 → 45 taken 4 times.
10 if(orientation&1) buf+=w;
98
2/2
✓ Branch 45 → 46 taken 6 times.
✓ Branch 45 → 47 taken 4 times.
10 if(orientation>1) buf+=stride>>1;
99
100 10 memset(obuffer, 0, sizeof(short)*width*height);
101 10 buf[w/2 + h/2*stride]= 8*256;
102 10 ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
103
2/2
✓ Branch 69 → 49 taken 2560 times.
✓ Branch 69 → 70 taken 10 times.
2570 for(y=0; y<height; y++){
104
2/2
✓ Branch 61 → 50 taken 655360 times.
✓ Branch 61 → 62 taken 2560 times.
657920 for(x=0; x<width; x++){
105 655360 int64_t d= obuffer[x + y*width];
106 655360 error += d*d;
107
10/10
✓ Branch 50 → 51 taken 330240 times.
✓ Branch 50 → 52 taken 325120 times.
✓ Branch 53 → 54 taken 43520 times.
✓ Branch 53 → 60 taken 611840 times.
✓ Branch 54 → 55 taken 21930 times.
✓ Branch 54 → 56 taken 21590 times.
✓ Branch 57 → 58 taken 2890 times.
✓ Branch 57 → 60 taken 40630 times.
✓ Branch 58 → 59 taken 867 times.
✓ Branch 58 → 60 taken 2023 times.
655360 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
108 }
109
6/6
✓ Branch 62 → 63 taken 1290 times.
✓ Branch 62 → 64 taken 1270 times.
✓ Branch 65 → 66 taken 170 times.
✓ Branch 65 → 68 taken 2390 times.
✓ Branch 66 → 67 taken 51 times.
✓ Branch 66 → 68 taken 119 times.
2560 if(FFABS(height/2-y)<9 && level==2) printf("\n");
110 }
111 10 error= (int)(sqrt(error)+0.5);
112 10 errors[level][orientation]= error;
113
2/2
✓ Branch 70 → 71 taken 9 times.
✓ Branch 70 → 72 taken 1 time.
10 if(g) g=av_gcd(g, error);
114 1 else g= error;
115 }
116 }
117 1 printf("static int const visual_weight[][4]={\n");
118
2/2
✓ Branch 86 → 79 taken 3 times.
✓ Branch 86 → 87 taken 1 time.
4 for(level=0; level<s.spatial_decomposition_count; level++){
119 3 printf(" {");
120
2/2
✓ Branch 83 → 81 taken 12 times.
✓ Branch 83 → 84 taken 3 times.
15 for(orientation=0; orientation<4; orientation++){
121 12 printf("%8"PRId64",", errors[level][orientation]/g);
122 }
123 3 printf("},\n");
124 }
125 1 printf("};\n");
126 {
127 1 memset(buffer[0], 0, sizeof(int)*width*height);
128
2/2
✓ Branch 93 → 89 taken 256 times.
✓ Branch 93 → 94 taken 1 time.
257 for(y=0; y<height; y++){
129
2/2
✓ Branch 91 → 90 taken 65536 times.
✓ Branch 91 → 92 taken 256 times.
65792 for(x=0; x<width; x++){
130 65536 int tab[4]={0,2,3,1};
131 65536 buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
132 }
133 }
134 1 ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
135
2/2
✓ Branch 114 → 96 taken 256 times.
✓ Branch 114 → 115 taken 1 time.
257 for(y=0; y<height; y++){
136
2/2
✓ Branch 107 → 97 taken 65536 times.
✓ Branch 107 → 108 taken 256 times.
65792 for(x=0; x<width; x++){
137 65536 int64_t d= buffer[0][x + y*width];
138
8/8
✓ Branch 97 → 98 taken 33024 times.
✓ Branch 97 → 99 taken 32512 times.
✓ Branch 100 → 101 taken 4352 times.
✓ Branch 100 → 106 taken 61184 times.
✓ Branch 101 → 102 taken 2193 times.
✓ Branch 101 → 103 taken 2159 times.
✓ Branch 104 → 105 taken 289 times.
✓ Branch 104 → 106 taken 4063 times.
65536 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
139 }
140
4/4
✓ Branch 108 → 109 taken 129 times.
✓ Branch 108 → 110 taken 127 times.
✓ Branch 111 → 112 taken 17 times.
✓ Branch 111 → 113 taken 239 times.
256 if(FFABS(height/2-y)<9) printf("\n");
141 }
142 }
143
144 }
145
146 1 end:
147 1 av_free(s.temp_dwt_buffer);
148 1 av_free(s.temp_idwt_buffer);
149 1 return ret;
150 }
151