FFmpeg
Loading...
Searching...
No Matches
snowenc.c
Go to the documentation of this file.
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"
25#include "libavutil/mem.h"
26
27int main(void){
28#define width 256
29#define height 256
30 int buffer[2][width*height];
31 short obuffer[width*height];
33 int i;
34 AVLFG prng;
35 int ret = 0;
36 s.spatial_decomposition_count=6;
37 s.spatial_decomposition_type=1;
38
39 s.temp_dwt_buffer = av_calloc(width, sizeof(*s.temp_dwt_buffer));
40 s.temp_idwt_buffer = av_calloc(width, sizeof(*s.temp_idwt_buffer));
41
42 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 av_lfg_init(&prng, 1);
49
50 printf("testing 5/3 DWT\n");
51 for(i=0; i<width*height; i++)
52 buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 19000 - 9000;
53
54 ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
55 for(i=0; i<width*height; i++)
56 obuffer[i] = buffer[0][i];
57 ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
58
59 for(i=0; i<width*height; i++)
60 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 printf("testing 9/7 DWT\n");
66 s.spatial_decomposition_type=0;
67 for(i=0; i<width*height; i++)
68 buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 11000 - 5000;
69
70 ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
71 for(i=0; i<width*height; i++)
72 obuffer[i] = buffer[0][i];
73 ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
74
75 for(i=0; i<width*height; i++)
76 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 int64_t g=0;
85
86 memset(errors, 0, sizeof(errors));
87 s.spatial_decomposition_count=3;
88 s.spatial_decomposition_type=0;
89 for(level=0; level<s.spatial_decomposition_count; level++){
90 for(orientation=level ? 1 : 0; orientation<4; orientation++){
91 int w= width >> (s.spatial_decomposition_count-level);
92 int h= height >> (s.spatial_decomposition_count-level);
93 int stride= width << (s.spatial_decomposition_count-level);
94 IDWTELEM *buf= obuffer;
95 int64_t error=0;
96
97 if(orientation&1) buf+=w;
98 if(orientation>1) buf+=stride>>1;
99
100 memset(obuffer, 0, sizeof(short)*width*height);
101 buf[w/2 + h/2*stride]= 8*256;
102 ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
103 for(y=0; y<height; y++){
104 for(x=0; x<width; x++){
105 int64_t d= obuffer[x + y*width];
106 error += d*d;
107 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
108 }
109 if(FFABS(height/2-y)<9 && level==2) printf("\n");
110 }
111 error= (int)(sqrt(error)+0.5);
112 errors[level][orientation]= error;
113 if(g) g=av_gcd(g, error);
114 else g= error;
115 }
116 }
117 printf("static int const visual_weight[][4]={\n");
118 for(level=0; level<s.spatial_decomposition_count; level++){
119 printf(" {");
120 for(orientation=0; orientation<4; orientation++){
121 printf("%8"PRId64",", errors[level][orientation]/g);
122 }
123 printf("},\n");
124 }
125 printf("};\n");
126 {
127 memset(buffer[0], 0, sizeof(int)*width*height);
128 for(y=0; y<height; y++){
129 for(x=0; x<width; x++){
130 int tab[4]={0,2,3,1};
131 buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
132 }
133 }
134 ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
135 for(y=0; y<height; y++){
136 for(x=0; x<width; x++){
137 int64_t d= buffer[0][x + y*width];
138 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
139 }
140 if(FFABS(height/2-y)<9) printf("\n");
141 }
142 }
143
144 }
145
146end:
147 av_free(s.temp_dwt_buffer);
148 av_free(s.temp_idwt_buffer);
149 return ret;
150}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
long long int64_t
Definition coverity.c:34
__device__ int printf(const char *,...)
short IDWTELEM
Definition dirac_dwt.h:28
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition mathematics.c:37
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition lfg.c:32
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition lfg.h:53
uint8_t w
Definition llvidencdsp.c:39
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride, int type, int decomposition_count)
Definition snow_dwt.c:732
void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride, int type, int decomposition_count)
Definition snow_dwt.c:320
Context structure for the Lagged Fibonacci PRNG.
Definition lfg.h:33
uint8_t level
Definition svq3.c:208
#define stride
#define av_free(p)
static void error(const char *err)
static void prng(CheckasmRand *restrict xs, uint8_t *restrict buf, size_t size)
Definition utils.c:154
static char buffer[20]
Definition seek.c:32
int main(void)
Definition snowenc.c:27
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static const struct twinvq_data tab
const char * g
Definition vf_curves.c:128