| 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 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
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 0 taken 65536 times.
✓ Branch 1 taken 1 times.
|
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 0 taken 65536 times.
✓ Branch 1 taken 1 times.
|
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 0 taken 65536 times.
✓ Branch 1 taken 1 times.
|
65537 | for(i=0; i<width*height; i++) |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 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 0 taken 65536 times.
✓ Branch 1 taken 1 times.
|
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 0 taken 65536 times.
✓ Branch 1 taken 1 times.
|
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 0 taken 65536 times.
✓ Branch 1 taken 1 times.
|
65537 | for(i=0; i<width*height; i++) |
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 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 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for(level=0; level<s.spatial_decomposition_count; level++){ |
| 90 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 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 0 taken 6 times.
✓ Branch 1 taken 4 times.
|
10 | if(orientation&1) buf+=w; |
| 98 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 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 0 taken 2560 times.
✓ Branch 1 taken 10 times.
|
2570 | for(y=0; y<height; y++){ |
| 104 |
2/2✓ Branch 0 taken 655360 times.
✓ Branch 1 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 0 taken 330240 times.
✓ Branch 1 taken 325120 times.
✓ Branch 2 taken 43520 times.
✓ Branch 3 taken 611840 times.
✓ Branch 4 taken 21930 times.
✓ Branch 5 taken 21590 times.
✓ Branch 6 taken 2890 times.
✓ Branch 7 taken 40630 times.
✓ Branch 8 taken 867 times.
✓ Branch 9 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 0 taken 1290 times.
✓ Branch 1 taken 1270 times.
✓ Branch 2 taken 170 times.
✓ Branch 3 taken 2390 times.
✓ Branch 4 taken 51 times.
✓ Branch 5 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 0 taken 9 times.
✓ Branch 1 taken 1 times.
|
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 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for(level=0; level<s.spatial_decomposition_count; level++){ |
| 119 | 3 | printf(" {"); | |
| 120 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 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 0 taken 256 times.
✓ Branch 1 taken 1 times.
|
257 | for(y=0; y<height; y++){ |
| 129 |
2/2✓ Branch 0 taken 65536 times.
✓ Branch 1 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 0 taken 256 times.
✓ Branch 1 taken 1 times.
|
257 | for(y=0; y<height; y++){ |
| 136 |
2/2✓ Branch 0 taken 65536 times.
✓ Branch 1 taken 256 times.
|
65792 | for(x=0; x<width; x++){ |
| 137 | 65536 | int64_t d= buffer[0][x + y*width]; | |
| 138 |
8/8✓ Branch 0 taken 33024 times.
✓ Branch 1 taken 32512 times.
✓ Branch 2 taken 4352 times.
✓ Branch 3 taken 61184 times.
✓ Branch 4 taken 2193 times.
✓ Branch 5 taken 2159 times.
✓ Branch 6 taken 289 times.
✓ Branch 7 taken 4063 times.
|
65536 | if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d); |
| 139 | } | ||
| 140 |
4/4✓ Branch 0 taken 129 times.
✓ Branch 1 taken 127 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 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 |