FFmpeg
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 #undef malloc
24 #undef free
25 #undef printf
26 
27 #include "libavutil/lfg.h"
28 #include "libavutil/mathematics.h"
29 
30 int main(void){
31 #define width 256
32 #define height 256
33  int buffer[2][width*height];
34  short obuffer[width*height];
35  SnowContext s;
36  int i;
37  AVLFG prng;
38  int ret = 0;
39  s.spatial_decomposition_count=6;
40  s.spatial_decomposition_type=1;
41 
42  s.temp_dwt_buffer = av_calloc(width, sizeof(*s.temp_dwt_buffer));
43  s.temp_idwt_buffer = av_calloc(width, sizeof(*s.temp_idwt_buffer));
44 
45  if (!s.temp_dwt_buffer || !s.temp_idwt_buffer) {
46  fprintf(stderr, "Failed to allocate memory\n");
47  return 1;
48  }
49 
50  av_lfg_init(&prng, 1);
51 
52  printf("testing 5/3 DWT\n");
53  for(i=0; i<width*height; i++)
54  buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 19000 - 9000;
55 
56  ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
57  for(i=0; i<width*height; i++)
58  obuffer[i] = buffer[0][i];
59  ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
60 
61  for(i=0; i<width*height; i++)
62  if(buffer[1][i]!= obuffer[i]) {
63  printf("fsck: %4dx%4dx %12d %7d\n",i%width, i/width, buffer[1][i], obuffer[i]);
64  ret = 1;
65  }
66 
67  printf("testing 9/7 DWT\n");
68  s.spatial_decomposition_type=0;
69  for(i=0; i<width*height; i++)
70  buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 11000 - 5000;
71 
72  ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
73  for(i=0; i<width*height; i++)
74  obuffer[i] = buffer[0][i];
75  ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
76 
77  for(i=0; i<width*height; i++)
78  if(FFABS(buffer[1][i] - obuffer[i])>20) {
79  printf("fsck: %4dx%4d %12d %7d\n",i%width, i/width, buffer[1][i], obuffer[i]);
80  ret = 1;
81  }
82 
83  {
84  int level, orientation, x, y;
85  int64_t errors[8][4];
86  int64_t g=0;
87 
88  memset(errors, 0, sizeof(errors));
89  s.spatial_decomposition_count=3;
90  s.spatial_decomposition_type=0;
91  for(level=0; level<s.spatial_decomposition_count; level++){
92  for(orientation=level ? 1 : 0; orientation<4; orientation++){
93  int w= width >> (s.spatial_decomposition_count-level);
94  int h= height >> (s.spatial_decomposition_count-level);
95  int stride= width << (s.spatial_decomposition_count-level);
96  IDWTELEM *buf= obuffer;
97  int64_t error=0;
98 
99  if(orientation&1) buf+=w;
100  if(orientation>1) buf+=stride>>1;
101 
102  memset(obuffer, 0, sizeof(short)*width*height);
103  buf[w/2 + h/2*stride]= 8*256;
104  ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
105  for(y=0; y<height; y++){
106  for(x=0; x<width; x++){
107  int64_t d= obuffer[x + y*width];
108  error += d*d;
109  if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
110  }
111  if(FFABS(height/2-y)<9 && level==2) printf("\n");
112  }
113  error= (int)(sqrt(error)+0.5);
114  errors[level][orientation]= error;
115  if(g) g=av_gcd(g, error);
116  else g= error;
117  }
118  }
119  printf("static int const visual_weight[][4]={\n");
120  for(level=0; level<s.spatial_decomposition_count; level++){
121  printf(" {");
122  for(orientation=0; orientation<4; orientation++){
123  printf("%8"PRId64",", errors[level][orientation]/g);
124  }
125  printf("},\n");
126  }
127  printf("};\n");
128  {
129  memset(buffer[0], 0, sizeof(int)*width*height);
130  for(y=0; y<height; y++){
131  for(x=0; x<width; x++){
132  int tab[4]={0,2,3,1};
133  buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
134  }
135  }
136  ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
137  for(y=0; y<height; y++){
138  for(x=0; x<width; x++){
139  int64_t d= buffer[0][x + y*width];
140  if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
141  }
142  if(FFABS(height/2-y)<9) printf("\n");
143  }
144  }
145 
146  }
147  return ret;
148 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
level
uint8_t level
Definition: svq3.c:204
errors
FFmpeg currently uses a custom build this text attempts to document some of its obscure features and options Makefile the full command issued by make and its output will be shown on the screen DBG Preprocess x86 external assembler files to a dbg asm file in the object which then gets compiled Helps in developing those assembler files DESTDIR Destination directory for the install useful to prepare packages or install FFmpeg in cross environments GEN Set to ‘1’ to generate the missing or mismatched references Makefile builds all the libraries and the executables fate Run the fate test note that you must have installed it fate list List all fate regression test targets install Install libraries and programs examples Build all examples located in doc examples checkheaders Check headers dependencies alltools Build all tools in tools directory config Reconfigure the project with the current configuration tools target_dec_< decoder > _fuzzer Build fuzzer to fuzz the specified decoder tools target_bsf_< filter > _fuzzer Build fuzzer to fuzz the specified bitstream filter Useful standard make this is useful to reduce unneeded rebuilding when changing but note that you must force rebuilds of files that actually need it by hand then make j< num > Rebuild with multiple jobs at the same time Faster on multi processor systems make k Continue build in case of errors
Definition: build_system.txt:64
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
int64_t
long long int64_t
Definition: coverity.c:34
main
int main(void)
Definition: snowenc.c:30
w
uint8_t w
Definition: llviddspenc.c:38
mathematics.h
SnowContext
Definition: snow.h:113
ff_spatial_dwt
void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride, int type, int decomposition_count)
Definition: snow_dwt.c:319
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
ff_spatial_idwt
void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride, int type, int decomposition_count)
Definition: snow_dwt.c:731
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
g
const char * g
Definition: vf_curves.c:127
lfg.h
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
printf
printf("static const uint8_t my_array[100] = {\n")
snowenc.c
height
#define height
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
stride
#define stride
Definition: h264pred_template.c:537
ret
ret
Definition: filter_design.txt:187
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
d
d
Definition: ffmpeg_filter.c:409
IDWTELEM
short IDWTELEM
Definition: dirac_dwt.h:27
h
h
Definition: vp9dsp_template.c:2038
int
int
Definition: ffmpeg_filter.c:409