FFmpeg
snow_dwt.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (C) 2008 David Conrad
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/avassert.h"
24 #include "libavutil/common.h"
25 #include "libavutil/mem.h"
26 #include "me_cmp.h"
27 #include "snow_dwt.h"
28 
29 int ff_slice_buffer_init(slice_buffer *buf, int line_count,
30  int max_allocated_lines, int line_width,
31  IDWTELEM *base_buffer)
32 {
33  int i;
34 
35  buf->base_buffer = base_buffer;
36  buf->line_count = line_count;
37  buf->line_width = line_width;
38  buf->data_count = max_allocated_lines;
39  buf->line = av_calloc(line_count, sizeof(*buf->line));
40  if (!buf->line)
41  return AVERROR(ENOMEM);
42  buf->data_stack = av_malloc_array(max_allocated_lines, sizeof(IDWTELEM *));
43  if (!buf->data_stack) {
44  av_freep(&buf->line);
45  return AVERROR(ENOMEM);
46  }
47 
48  for (i = 0; i < max_allocated_lines; i++) {
49  buf->data_stack[i] = av_malloc_array(line_width, sizeof(IDWTELEM));
50  if (!buf->data_stack[i]) {
51  for (i--; i >=0; i--)
52  av_freep(&buf->data_stack[i]);
53  av_freep(&buf->data_stack);
54  av_freep(&buf->line);
55  return AVERROR(ENOMEM);
56  }
57  }
58 
59  buf->data_stack_top = max_allocated_lines - 1;
60  return 0;
61 }
62 
63 IDWTELEM *ff_slice_buffer_load_line(slice_buffer *buf, int line)
64 {
66 
67  av_assert0(buf->data_stack_top >= 0);
68 // av_assert1(!buf->line[line]);
69  if (buf->line[line])
70  return buf->line[line];
71 
72  buffer = buf->data_stack[buf->data_stack_top];
73  buf->data_stack_top--;
74  buf->line[line] = buffer;
75 
76  return buffer;
77 }
78 
79 void ff_slice_buffer_release(slice_buffer *buf, int line)
80 {
82 
83  av_assert1(line >= 0 && line < buf->line_count);
84  av_assert1(buf->line[line]);
85 
86  buffer = buf->line[line];
87  buf->data_stack_top++;
88  buf->data_stack[buf->data_stack_top] = buffer;
89  buf->line[line] = NULL;
90 }
91 
92 void ff_slice_buffer_flush(slice_buffer *buf)
93 {
94  int i;
95 
96  if (!buf->line)
97  return;
98 
99  for (i = 0; i < buf->line_count; i++)
100  if (buf->line[i])
102 }
103 
104 void ff_slice_buffer_destroy(slice_buffer *buf)
105 {
106  int i;
108 
109  if (buf->data_stack)
110  for (i = buf->data_count - 1; i >= 0; i--)
111  av_freep(&buf->data_stack[i]);
112  av_freep(&buf->data_stack);
113  av_freep(&buf->line);
114 }
115 
117  int dst_step, int src_step, int ref_step,
118  int width, int mul, int add, int shift,
119  int highpass, int inverse)
120 {
121  const int mirror_left = !highpass;
122  const int mirror_right = (width & 1) ^ highpass;
123  const int w = (width >> 1) - 1 + (highpass & width);
124  int i;
125 
126 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
127  if (mirror_left) {
128  dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
129  dst += dst_step;
130  src += src_step;
131  }
132 
133  for (i = 0; i < w; i++)
134  dst[i * dst_step] = LIFT(src[i * src_step],
135  ((mul * (ref[i * ref_step] +
136  ref[(i + 1) * ref_step]) +
137  add) >> shift),
138  inverse);
139 
140  if (mirror_right)
141  dst[w * dst_step] = LIFT(src[w * src_step],
142  ((mul * 2 * ref[w * ref_step] + add) >> shift),
143  inverse);
144 }
145 
147  int dst_step, int src_step, int ref_step,
148  int width, int mul, int add, int shift,
149  int highpass, int inverse)
150 {
151  const int mirror_left = !highpass;
152  const int mirror_right = (width & 1) ^ highpass;
153  const int w = (width >> 1) - 1 + (highpass & width);
154  int i;
155 
156  av_assert1(shift == 4);
157 #define LIFTS(src, ref, inv) \
158  ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
159  : -((-16 * (src) + (ref) + add / \
160  4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
161  if (mirror_left) {
162  dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
163  dst += dst_step;
164  src += src_step;
165  }
166 
167  for (i = 0; i < w; i++)
168  dst[i * dst_step] = LIFTS(src[i * src_step],
169  mul * (ref[i * ref_step] +
170  ref[(i + 1) * ref_step]) + add,
171  inverse);
172 
173  if (mirror_right)
174  dst[w * dst_step] = LIFTS(src[w * src_step],
175  mul * 2 * ref[w * ref_step] + add,
176  inverse);
177 }
178 
180 {
181  const int width2 = width >> 1;
182  int x;
183  const int w2 = (width + 1) >> 1;
184 
185  for (x = 0; x < width2; x++) {
186  temp[x] = b[2 * x];
187  temp[x + w2] = b[2 * x + 1];
188  }
189  if (width & 1)
190  temp[x] = b[2 * x];
191  lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
192  lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
193 }
194 
196  int width)
197 {
198  int i;
199 
200  for (i = 0; i < width; i++)
201  b1[i] -= (b0[i] + b2[i]) >> 1;
202 }
203 
205  int width)
206 {
207  int i;
208 
209  for (i = 0; i < width; i++)
210  b1[i] += (b0[i] + b2[i] + 2) >> 2;
211 }
212 
214  int width, int height, int stride)
215 {
216  int y;
217  DWTELEM *b0 = buffer + avpriv_mirror(-2 - 1, height - 1) * stride;
218  DWTELEM *b1 = buffer + avpriv_mirror(-2, height - 1) * stride;
219 
220  for (y = -2; y < height; y += 2) {
221  DWTELEM *b2 = buffer + avpriv_mirror(y + 1, height - 1) * stride;
222  DWTELEM *b3 = buffer + avpriv_mirror(y + 2, height - 1) * stride;
223 
224  if (y + 1 < (unsigned)height)
226  if (y + 2 < (unsigned)height)
228 
229  if (y + 1 < (unsigned)height)
231  if (y + 0 < (unsigned)height)
233 
234  b0 = b2;
235  b1 = b3;
236  }
237 }
238 
240 {
241  const int w2 = (width + 1) >> 1;
242 
243  lift(temp + w2, b + 1, b, 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1);
244  liftS(temp, b, temp + w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0);
245  lift(b + w2, temp + w2, temp, 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0);
246  lift(b, temp, b + w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0);
247 }
248 
250  int width)
251 {
252  int i;
253 
254  for (i = 0; i < width; i++)
255  b1[i] -= (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
256 }
257 
259  int width)
260 {
261  int i;
262 
263  for (i = 0; i < width; i++)
264  b1[i] += (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
265 }
266 
268  int width)
269 {
270  int i;
271 
272  for (i = 0; i < width; i++)
273  b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) + W_BO * 5 + (5 << 27)) /
274  (5 * 16) - (1 << 23);
275 }
276 
278  int width)
279 {
280  int i;
281 
282  for (i = 0; i < width; i++)
283  b1[i] += (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
284 }
285 
287  int width, int height, int stride)
288 {
289  int y;
290  DWTELEM *b0 = buffer + avpriv_mirror(-4 - 1, height - 1) * stride;
291  DWTELEM *b1 = buffer + avpriv_mirror(-4, height - 1) * stride;
292  DWTELEM *b2 = buffer + avpriv_mirror(-4 + 1, height - 1) * stride;
293  DWTELEM *b3 = buffer + avpriv_mirror(-4 + 2, height - 1) * stride;
294 
295  for (y = -4; y < height; y += 2) {
296  DWTELEM *b4 = buffer + avpriv_mirror(y + 3, height - 1) * stride;
297  DWTELEM *b5 = buffer + avpriv_mirror(y + 4, height - 1) * stride;
298 
299  if (y + 3 < (unsigned)height)
301  if (y + 4 < (unsigned)height)
303 
304  if (y + 3 < (unsigned)height)
305  vertical_decompose97iH0(b3, b4, b5, width);
306  if (y + 2 < (unsigned)height)
308  if (y + 1 < (unsigned)height)
310  if (y + 0 < (unsigned)height)
312 
313  b0 = b2;
314  b1 = b3;
315  b2 = b4;
316  b3 = b5;
317  }
318 }
319 
321  int stride, int type, int decomposition_count)
322 {
323  int level;
324 
325  for (level = 0; level < decomposition_count; level++) {
326  switch (type) {
327  case DWT_97:
329  width >> level, height >> level,
330  stride << level);
331  break;
332  case DWT_53:
334  width >> level, height >> level,
335  stride << level);
336  break;
337  }
338  }
339 }
340 
342 {
343  const int width2 = width >> 1;
344  const int w2 = (width + 1) >> 1;
345  int x;
346 
347  for (x = 0; x < width2; x++) {
348  temp[2 * x] = b[x];
349  temp[2 * x + 1] = b[x + w2];
350  }
351  if (width & 1)
352  temp[2 * x] = b[x];
353 
354  b[0] = temp[0] - ((temp[1] + 1) >> 1);
355  for (x = 2; x < width - 1; x += 2) {
356  b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
357  b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
358  }
359  if (width & 1) {
360  b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
361  b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
362  } else
363  b[x - 1] = temp[x - 1] + b[x - 2];
364 }
365 
367  int width)
368 {
369  int i;
370 
371  for (i = 0; i < width; i++)
372  b1[i] += (b0[i] + b2[i]) >> 1;
373 }
374 
376  int width)
377 {
378  int i;
379 
380  for (i = 0; i < width; i++)
381  b1[i] -= (b0[i] + b2[i] + 2) >> 2;
382 }
383 
384 static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb,
385  int height, int stride_line)
386 {
387  cs->b0 = slice_buffer_get_line(sb,
388  avpriv_mirror(-1 - 1, height - 1) * stride_line);
389  cs->b1 = slice_buffer_get_line(sb, avpriv_mirror(-1, height - 1) * stride_line);
390  cs->y = -1;
391 }
392 
394  int height, int stride)
395 {
396  cs->b0 = buffer + avpriv_mirror(-1 - 1, height - 1) * stride;
397  cs->b1 = buffer + avpriv_mirror(-1, height - 1) * stride;
398  cs->y = -1;
399 }
400 
401 static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb,
402  IDWTELEM *temp,
403  int width, int height,
404  int stride_line)
405 {
406  int y = cs->y;
407 
408  IDWTELEM *b0 = cs->b0;
409  IDWTELEM *b1 = cs->b1;
411  avpriv_mirror(y + 1, height - 1) *
412  stride_line);
414  avpriv_mirror(y + 2, height - 1) *
415  stride_line);
416 
417  if (y + 1 < (unsigned)height && y < (unsigned)height) {
418  int x;
419 
420  for (x = 0; x < width; x++) {
421  b2[x] -= (b1[x] + b3[x] + 2) >> 2;
422  b1[x] += (b0[x] + b2[x]) >> 1;
423  }
424  } else {
425  if (y + 1 < (unsigned)height)
427  if (y + 0 < (unsigned)height)
429  }
430 
431  if (y - 1 < (unsigned)height)
433  if (y + 0 < (unsigned)height)
435 
436  cs->b0 = b2;
437  cs->b1 = b3;
438  cs->y += 2;
439 }
440 
442  IDWTELEM *temp, int width, int height,
443  int stride)
444 {
445  int y = cs->y;
446  IDWTELEM *b0 = cs->b0;
447  IDWTELEM *b1 = cs->b1;
448  IDWTELEM *b2 = buffer + avpriv_mirror(y + 1, height - 1) * stride;
449  IDWTELEM *b3 = buffer + avpriv_mirror(y + 2, height - 1) * stride;
450 
451  if (y + 1 < (unsigned)height)
453  if (y + 0 < (unsigned)height)
455 
456  if (y - 1 < (unsigned)height)
458  if (y + 0 < (unsigned)height)
460 
461  cs->b0 = b2;
462  cs->b1 = b3;
463  cs->y += 2;
464 }
465 
467 {
468  const int w2 = (width + 1) >> 1;
469  int x;
470 
471  temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
472  for (x = 1; x < (width >> 1); x++) {
473  temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
474  temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
475  }
476  if (width & 1) {
477  temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
478  temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
479  } else
480  temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
481 
482  b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
483  for (x = 2; x < width - 1; x += 2) {
484  b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
485  b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
486  }
487  if (width & 1) {
488  b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
489  b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
490  } else
491  b[x - 1] = temp[x - 1] + 3 * b[x - 2];
492 }
493 
495  int width)
496 {
497  int i;
498 
499  for (i = 0; i < width; i++)
500  b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
501 }
502 
504  int width)
505 {
506  int i;
507 
508  for (i = 0; i < width; i++)
509  b1[i] -= (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
510 }
511 
513  int width)
514 {
515  int i;
516 
517  for (i = 0; i < width; i++)
518  b1[i] += (W_BM * (b0[i] + b2[i]) + 4 * b1[i] + W_BO) >> W_BS;
519 }
520 
522  int width)
523 {
524  int i;
525 
526  for (i = 0; i < width; i++)
527  b1[i] -= (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
528 }
529 
531  IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
532  int width)
533 {
534  int i;
535 
536  for (i = 0; i < width; i++) {
537  b4[i] -= (W_DM * (b3[i] + b5[i]) + W_DO) >> W_DS;
538  b3[i] -= (W_CM * (b2[i] + b4[i]) + W_CO) >> W_CS;
539  b2[i] += (W_BM * (b1[i] + b3[i]) + 4 * b2[i] + W_BO) >> W_BS;
540  b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
541  }
542 }
543 
544 static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb,
545  int height, int stride_line)
546 {
547  cs->b0 = slice_buffer_get_line(sb, avpriv_mirror(-3 - 1, height - 1) * stride_line);
548  cs->b1 = slice_buffer_get_line(sb, avpriv_mirror(-3, height - 1) * stride_line);
549  cs->b2 = slice_buffer_get_line(sb, avpriv_mirror(-3 + 1, height - 1) * stride_line);
550  cs->b3 = slice_buffer_get_line(sb, avpriv_mirror(-3 + 2, height - 1) * stride_line);
551  cs->y = -3;
552 }
553 
555  int stride)
556 {
557  cs->b0 = buffer + avpriv_mirror(-3 - 1, height - 1) * stride;
558  cs->b1 = buffer + avpriv_mirror(-3, height - 1) * stride;
559  cs->b2 = buffer + avpriv_mirror(-3 + 1, height - 1) * stride;
560  cs->b3 = buffer + avpriv_mirror(-3 + 2, height - 1) * stride;
561  cs->y = -3;
562 }
563 
565  slice_buffer * sb, IDWTELEM *temp,
566  int width, int height,
567  int stride_line)
568 {
569  int y = cs->y;
570 
571  IDWTELEM *b0 = cs->b0;
572  IDWTELEM *b1 = cs->b1;
573  IDWTELEM *b2 = cs->b2;
574  IDWTELEM *b3 = cs->b3;
576  avpriv_mirror(y + 3, height - 1) *
577  stride_line);
579  avpriv_mirror(y + 4, height - 1) *
580  stride_line);
581 
582  if (y > 0 && y + 4 < height) {
583  dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
584  } else {
585  if (y + 3 < (unsigned)height)
586  vertical_compose97iL1(b3, b4, b5, width);
587  if (y + 2 < (unsigned)height)
589  if (y + 1 < (unsigned)height)
591  if (y + 0 < (unsigned)height)
593  }
594 
595  if (y - 1 < (unsigned)height)
597  if (y + 0 < (unsigned)height)
599 
600  cs->b0 = b2;
601  cs->b1 = b3;
602  cs->b2 = b4;
603  cs->b3 = b5;
604  cs->y += 2;
605 }
606 
608  IDWTELEM *temp, int width, int height,
609  int stride)
610 {
611  int y = cs->y;
612  IDWTELEM *b0 = cs->b0;
613  IDWTELEM *b1 = cs->b1;
614  IDWTELEM *b2 = cs->b2;
615  IDWTELEM *b3 = cs->b3;
616  IDWTELEM *b4 = buffer + avpriv_mirror(y + 3, height - 1) * stride;
617  IDWTELEM *b5 = buffer + avpriv_mirror(y + 4, height - 1) * stride;
618 
619  if (y + 3 < (unsigned)height)
620  vertical_compose97iL1(b3, b4, b5, width);
621  if (y + 2 < (unsigned)height)
623  if (y + 1 < (unsigned)height)
625  if (y + 0 < (unsigned)height)
627 
628  if (y - 1 < (unsigned)height)
630  if (y + 0 < (unsigned)height)
632 
633  cs->b0 = b2;
634  cs->b1 = b3;
635  cs->b2 = b4;
636  cs->b3 = b5;
637  cs->y += 2;
638 }
639 
640 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
641  int height, int stride_line, int type,
642  int decomposition_count)
643 {
644  int level;
645  for (level = decomposition_count - 1; level >= 0; level--) {
646  switch (type) {
647  case DWT_97:
649  stride_line << level);
650  break;
651  case DWT_53:
653  stride_line << level);
654  break;
655  }
656  }
657 }
658 
660  slice_buffer *slice_buf, IDWTELEM *temp,
661  int width, int height, int stride_line,
662  int type, int decomposition_count, int y)
663 {
664  const int support = type == 1 ? 3 : 5;
665  int level;
666  if (type == 2)
667  return;
668 
669  for (level = decomposition_count - 1; level >= 0; level--)
670  while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
671  switch (type) {
672  case DWT_97:
673  spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf, temp,
674  width >> level,
675  height >> level,
676  stride_line << level);
677  break;
678  case DWT_53:
679  spatial_compose53i_dy_buffered(cs + level, slice_buf, temp,
680  width >> level,
681  height >> level,
682  stride_line << level);
683  break;
684  }
685  }
686 }
687 
689  int height, int stride, int type,
690  int decomposition_count)
691 {
692  int level;
693  for (level = decomposition_count - 1; level >= 0; level--) {
694  switch (type) {
695  case DWT_97:
697  stride << level);
698  break;
699  case DWT_53:
701  stride << level);
702  break;
703  }
704  }
705 }
706 
708  IDWTELEM *temp, int width, int height,
709  int stride, int type,
710  int decomposition_count, int y)
711 {
712  const int support = type == 1 ? 3 : 5;
713  int level;
714  if (type == 2)
715  return;
716 
717  for (level = decomposition_count - 1; level >= 0; level--)
718  while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
719  switch (type) {
720  case DWT_97:
722  height >> level, stride << level);
723  break;
724  case DWT_53:
726  height >> level, stride << level);
727  break;
728  }
729  }
730 }
731 
733  int stride, int type, int decomposition_count)
734 {
736  int y;
738  decomposition_count);
739  for (y = 0; y < height; y += 4)
741  decomposition_count, y);
742 }
743 
744 static inline int w_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size,
745  int w, int h, int type)
746 {
747  int s, i, j;
748  const int dec_count = w == 8 ? 3 : 4;
749  int tmp[32 * 32], tmp2[32];
750  int level, ori;
751  static const int scale[2][2][4][4] = {
752  {
753  { // 9/7 8x8 dec=3
754  { 268, 239, 239, 213 },
755  { 0, 224, 224, 152 },
756  { 0, 135, 135, 110 },
757  },
758  { // 9/7 16x16 or 32x32 dec=4
759  { 344, 310, 310, 280 },
760  { 0, 320, 320, 228 },
761  { 0, 175, 175, 136 },
762  { 0, 129, 129, 102 },
763  }
764  },
765  {
766  { // 5/3 8x8 dec=3
767  { 275, 245, 245, 218 },
768  { 0, 230, 230, 156 },
769  { 0, 138, 138, 113 },
770  },
771  { // 5/3 16x16 or 32x32 dec=4
772  { 352, 317, 317, 286 },
773  { 0, 328, 328, 233 },
774  { 0, 180, 180, 140 },
775  { 0, 132, 132, 105 },
776  }
777  }
778  };
779 
780  for (i = 0; i < h; i++) {
781  for (j = 0; j < w; j += 4) {
782  tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) * (1 << 4);
783  tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) * (1 << 4);
784  tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) * (1 << 4);
785  tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) * (1 << 4);
786  }
787  pix1 += line_size;
788  pix2 += line_size;
789  }
790 
791  ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count);
792 
793  s = 0;
794  av_assert1(w == h);
795  for (level = 0; level < dec_count; level++)
796  for (ori = level ? 1 : 0; ori < 4; ori++) {
797  int size = w >> (dec_count - level);
798  int sx = (ori & 1) ? size : 0;
799  int stride = 32 << (dec_count - level);
800  int sy = (ori & 2) ? stride >> 1 : 0;
801 
802  for (i = 0; i < size; i++)
803  for (j = 0; j < size; j++) {
804  int v = tmp[sx + sy + i * stride + j] *
805  scale[type][dec_count - 3][level][ori];
806  s += FFABS(v);
807  }
808  }
809  av_assert1(s >= 0);
810  return s >> 9;
811 }
812 
813 static int w53_8_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
814 {
815  return w_c(v, pix1, pix2, line_size, 8, h, 1);
816 }
817 
818 static int w97_8_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
819 {
820  return w_c(v, pix1, pix2, line_size, 8, h, 0);
821 }
822 
823 static int w53_16_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
824 {
825  return w_c(v, pix1, pix2, line_size, 16, h, 1);
826 }
827 
828 static int w97_16_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
829 {
830  return w_c(v, pix1, pix2, line_size, 16, h, 0);
831 }
832 
833 int ff_w53_32_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
834 {
835  return w_c(v, pix1, pix2, line_size, 32, h, 1);
836 }
837 
838 int ff_w97_32_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
839 {
840  return w_c(v, pix1, pix2, line_size, 32, h, 0);
841 }
842 
844 {
845  c->w53[0] = w53_16_c;
846  c->w53[1] = w53_8_c;
847  c->w97[0] = w97_16_c;
848  c->w97[1] = w97_8_c;
849 }
850 
852 {
853  c->vertical_compose97i = snow_vertical_compose97i;
854  c->horizontal_compose97i = snow_horizontal_compose97i;
855  c->inner_add_yblock = ff_snow_inner_add_yblock;
856 
857 #if ARCH_X86 && HAVE_MMX
859 #endif
860 }
861 
862 
ff_dwt_init_x86
void ff_dwt_init_x86(SnowDWTContext *c)
Definition: snowdsp.c:881
spatial_compose97i_dy
static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride)
Definition: snow_dwt.c:607
level
uint8_t level
Definition: svq3.c:205
spatial_compose53i_dy
static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride)
Definition: snow_dwt.c:441
MAX_DECOMPOSITIONS
#define MAX_DECOMPOSITIONS
Definition: dirac_dwt.h:30
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
W_AO
#define W_AO
Definition: snow_dwt.h:75
LIFT
#define LIFT(src, ref, inv)
inverse
inverse
Definition: af_crystalizer.c:122
W_BO
#define W_BO
Definition: snow_dwt.h:80
w97_16_c
static int w97_16_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
Definition: snow_dwt.c:828
W_DS
#define W_DS
Definition: snow_dwt.h:89
snow_horizontal_compose97i
static void snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width)
Definition: snow_dwt.c:466
spatial_compose53i_dy_buffered
static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb, IDWTELEM *temp, int width, int height, int stride_line)
Definition: snow_dwt.c:401
ff_slice_buffer_flush
void ff_slice_buffer_flush(slice_buffer *buf)
Definition: snow_dwt.c:92
W_AM
#define W_AM
Definition: snow_dwt.h:74
vertical_decompose97iL1
static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
Definition: snow_dwt.c:277
vertical_compose53iL0
static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
Definition: snow_dwt.c:375
DWT_97
#define DWT_97
Definition: snow_dwt.h:70
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
w
uint8_t w
Definition: llviddspenc.c:38
vertical_decompose97iH1
static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
Definition: snow_dwt.c:258
b
#define b
Definition: input.c:41
DWT_53
#define DWT_53
Definition: snow_dwt.h:71
vertical_compose97iL1
static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
Definition: snow_dwt.c:521
SnowDWTContext::vertical_compose97i
void(* vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width)
Definition: snow_dwt.h:59
SnowDWTContext
Definition: snow_dwt.h:58
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:320
horizontal_decompose97i
static void horizontal_decompose97i(DWTELEM *b, DWTELEM *temp, int width)
Definition: snow_dwt.c:239
W_CS
#define W_CS
Definition: snow_dwt.h:85
vertical_compose53iH0
static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
Definition: snow_dwt.c:366
w53_8_c
static int w53_8_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
Definition: snow_dwt.c:813
spatial_compose97i_dy_buffered
static void spatial_compose97i_dy_buffered(SnowDWTContext *dsp, DWTCompose *cs, slice_buffer *sb, IDWTELEM *temp, int width, int height, int stride_line)
Definition: snow_dwt.c:564
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:2034
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:732
ff_slice_buffer_init
int ff_slice_buffer_init(slice_buffer *buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM *base_buffer)
Definition: snow_dwt.c:29
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ff_dwt_init
av_cold void ff_dwt_init(SnowDWTContext *c)
Definition: snow_dwt.c:851
DWTCompose
Definition: dirac_dwt.h:32
w97_8_c
static int w97_8_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
Definition: snow_dwt.c:818
DWTCompose::b1
IDWTELEM * b1
Definition: snow_dwt.h:38
ff_slice_buffer_destroy
void ff_slice_buffer_destroy(slice_buffer *buf)
Definition: snow_dwt.c:104
avassert.h
DWTCompose::b0
IDWTELEM * b0
Definition: snow_dwt.h:37
av_cold
#define av_cold
Definition: attributes.h:90
DWTCompose::y
int y
Definition: dirac_dwt.h:34
ff_spatial_idwt_buffered_init
void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, int height, int stride_line, int type, int decomposition_count)
Definition: snow_dwt.c:640
b3
static double b3(void *priv, double x, double y)
Definition: vf_xfade.c:2036
s
#define s(width, name)
Definition: cbs_vp9.c:198
W_DO
#define W_DO
Definition: snow_dwt.h:88
snow_vertical_compose97i
static void snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width)
Definition: snow_dwt.c:530
spatial_compose97i_buffered_init
static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb, int height, int stride_line)
Definition: snow_dwt.c:544
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
highpass
@ highpass
Definition: af_biquads.c:85
W_BM
#define W_BM
Definition: snow_dwt.h:79
vertical_compose97iH1
static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
Definition: snow_dwt.c:503
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
ff_snow_inner_add_yblock
void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t **block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer *sb, int add, uint8_t *dst8)
Definition: snow.c:30
MECmpContext
Definition: me_cmp.h:55
liftS
static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse)
Definition: snow_dwt.c:146
NULL
#define NULL
Definition: coverity.c:32
ff_slice_buffer_load_line
IDWTELEM * ff_slice_buffer_load_line(slice_buffer *buf, int line)
Definition: snow_dwt.c:63
W_AS
#define W_AS
Definition: snow_dwt.h:76
spatial_decompose97i
static void spatial_decompose97i(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride)
Definition: snow_dwt.c:286
ff_w53_32_c
int ff_w53_32_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
Definition: snow_dwt.c:833
spatial_compose53i_buffered_init
static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb, int height, int stride_line)
Definition: snow_dwt.c:384
avpriv_mirror
static av_always_inline av_const int avpriv_mirror(int x, int w)
Definition: internal.h:154
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_dsputil_init_dwt
av_cold void ff_dsputil_init_dwt(MECmpContext *c)
Definition: snow_dwt.c:843
spatial_idwt_init
static void spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count)
Definition: snow_dwt.c:688
W_DM
#define W_DM
Definition: snow_dwt.h:87
DWTCompose::b3
IDWTELEM * b3
Definition: snow_dwt.h:40
vertical_compose97iL0
static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
Definition: snow_dwt.c:512
height
#define height
Definition: dsp.h:85
vertical_decompose53iH0
static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
Definition: snow_dwt.c:195
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
size
int size
Definition: twinvq_data.h:10344
ff_slice_buffer_release
void ff_slice_buffer_release(slice_buffer *buf, int line)
Definition: snow_dwt.c:79
LIFTS
#define LIFTS(src, ref, inv)
b2
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:2035
line
Definition: graph2dot.c:48
attributes.h
snow_dwt.h
SnowDWTContext::horizontal_compose97i
void(* horizontal_compose97i)(IDWTELEM *b, IDWTELEM *temp, int width)
Definition: snow_dwt.h:62
DWTELEM
int DWTELEM
Definition: dirac_dwt.h:26
w53_16_c
static int w53_16_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
Definition: snow_dwt.c:823
vertical_decompose97iH0
static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
Definition: snow_dwt.c:249
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
lift
static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse)
Definition: snow_dwt.c:116
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
horizontal_compose53i
static void horizontal_compose53i(IDWTELEM *b, IDWTELEM *temp, int width)
Definition: snow_dwt.c:341
common.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
av_always_inline
#define av_always_inline
Definition: attributes.h:49
spatial_idwt_slice
static void spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride, int type, int decomposition_count, int y)
Definition: snow_dwt.c:707
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
stride
#define stride
Definition: h264pred_template.c:537
W_BS
#define W_BS
Definition: snow_dwt.h:81
spatial_decompose53i
static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride)
Definition: snow_dwt.c:213
me_cmp.h
vertical_decompose53iL0
static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
Definition: snow_dwt.c:204
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
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
temp
else temp
Definition: vf_mcdeint.c:263
W_CM
#define W_CM
Definition: snow_dwt.h:83
slice_buffer_get_line
#define slice_buffer_get_line(slice_buf, line_num)
Definition: snow_dwt.h:91
mem.h
spatial_compose97i_init
static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
Definition: snow_dwt.c:554
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
W_CO
#define W_CO
Definition: snow_dwt.h:84
ff_w97_32_c
int ff_w97_32_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int h)
Definition: snow_dwt.c:838
IDWTELEM
short IDWTELEM
Definition: dirac_dwt.h:27
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:2033
vertical_decompose97iL0
static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
Definition: snow_dwt.c:267
h
h
Definition: vp9dsp_template.c:2070
width
#define width
Definition: dsp.h:85
ff_spatial_idwt_buffered_slice
void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs, slice_buffer *slice_buf, IDWTELEM *temp, int width, int height, int stride_line, int type, int decomposition_count, int y)
Definition: snow_dwt.c:659
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73
w_c
static int w_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t line_size, int w, int h, int type)
Definition: snow_dwt.c:744
spatial_compose53i_init
static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
Definition: snow_dwt.c:393
src
#define src
Definition: vp8dsp.c:248
horizontal_decompose53i
static void horizontal_decompose53i(DWTELEM *b, DWTELEM *temp, int width)
Definition: snow_dwt.c:179
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40
DWTCompose::b2
IDWTELEM * b2
Definition: snow_dwt.h:39
vertical_compose97iH0
static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
Definition: snow_dwt.c:494