27 int max_allocated_lines,
int line_width,
45 for (i = 0; i < max_allocated_lines; i++) {
67 return buf->
line[line];
81 assert(buf->
line[line]);
83 buffer = buf->
line[line];
110 while ((
unsigned)v > (
unsigned)m) {
119 int dst_step,
int src_step,
int ref_step,
120 int width,
int mul,
int add,
int shift,
123 const int mirror_left = !highpass;
124 const int mirror_right = (width & 1) ^ highpass;
125 const int w = (width >> 1) - 1 + (highpass & width);
128 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
130 dst[0] =
LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
135 for (i = 0; i < w; i++)
136 dst[i * dst_step] =
LIFT(src[i * src_step],
137 ((mul * (ref[i * ref_step] +
138 ref[(i + 1) * ref_step]) +
143 dst[w * dst_step] =
LIFT(src[w * src_step],
144 ((mul * 2 * ref[w * ref_step] + add) >> shift),
149 int dst_step,
int src_step,
int ref_step,
150 int width,
int mul,
int add,
int shift,
153 const int mirror_left = !highpass;
154 const int mirror_right = (width & 1) ^ highpass;
155 const int w = (width >> 1) - 1 + (highpass & width);
159 #define LIFTS(src, ref, inv) \
160 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
161 : -((-16 * (src) + (ref) + add / \
162 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
164 dst[0] =
LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
169 for (i = 0; i < w; i++)
170 dst[i * dst_step] =
LIFTS(src[i * src_step],
171 mul * (ref[i * ref_step] +
172 ref[(i + 1) * ref_step]) + add,
176 dst[w * dst_step] =
LIFTS(src[w * src_step],
177 mul * 2 * ref[w * ref_step] + add,
183 const int width2 = width >> 1;
185 const int w2 = (width + 1) >> 1;
187 for (x = 0; x < width2; x++) {
189 temp[x + w2] = b[2 * x + 1];
193 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
194 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
202 for (i = 0; i <
width; i++)
203 b1[i] -= (b0[i] + b2[i]) >> 1;
211 for (i = 0; i <
width; i++)
212 b1[i] += (b0[i] + b2[i] + 2) >> 2;
222 for (y = -2; y <
height; y += 2) {
226 if (y + 1 < (
unsigned)height)
228 if (y + 2 < (
unsigned)height)
231 if (y + 1 < (
unsigned)height)
233 if (y + 0 < (
unsigned)height)
243 const int w2 = (width + 1) >> 1;
245 lift(temp + w2, b + 1, b, 1, 2, 2, width,
W_AM,
W_AO,
W_AS, 1, 1);
246 liftS(temp, b, temp + w2, 1, 2, 1, width,
W_BM,
W_BO,
W_BS, 0, 0);
247 lift(b + w2, temp + w2, temp, 1, 1, 1, width,
W_CM,
W_CO,
W_CS, 1, 0);
248 lift(b, temp, b + w2, 1, 1, 1, width,
W_DM,
W_DO,
W_DS, 0, 0);
256 for (i = 0; i <
width; i++)
265 for (i = 0; i <
width; i++)
274 for (i = 0; i <
width; i++)
275 b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) +
W_BO * 5 + (5 << 27)) /
276 (5 * 16) - (1 << 23);
284 for (i = 0; i <
width; i++)
297 for (y = -4; y <
height; y += 2) {
301 if (y + 3 < (
unsigned)height)
303 if (y + 4 < (
unsigned)height)
306 if (y + 3 < (
unsigned)height)
308 if (y + 2 < (
unsigned)height)
310 if (y + 1 < (
unsigned)height)
312 if (y + 0 < (
unsigned)height)
323 int stride,
int type,
int decomposition_count)
327 for (level = 0; level < decomposition_count; level++) {
331 width >> level, height >> level,
336 width >> level, height >> level,
345 const int width2 = width >> 1;
346 const int w2 = (width + 1) >> 1;
349 for (x = 0; x < width2; x++) {
351 temp[2 * x + 1] = b[x + w2];
356 b[0] = temp[0] - ((temp[1] + 1) >> 1);
357 for (x = 2; x < width - 1; x += 2) {
358 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
359 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
362 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
363 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
365 b[x - 1] = temp[x - 1] + b[x - 2];
373 for (i = 0; i <
width; i++)
374 b1[i] += (b0[i] + b2[i]) >> 1;
382 for (i = 0; i <
width; i++)
383 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
387 int height,
int stride_line)
390 mirror(-1 - 1, height - 1) * stride_line);
413 mirror(y + 1, height - 1) *
416 mirror(y + 2, height - 1) *
419 if (y + 1 < (
unsigned)height && y < (
unsigned)height) {
422 for (x = 0; x <
width; x++) {
423 b2[x] -= (b1[x] + b3[x] + 2) >> 2;
424 b1[x] += (b0[x] + b2[x]) >> 1;
427 if (y + 1 < (
unsigned)
height)
429 if (y + 0 < (
unsigned)
height)
433 if (y - 1 < (
unsigned)
height)
435 if (y + 0 < (
unsigned)
height)
453 if (y + 1 < (
unsigned)height)
455 if (y + 0 < (
unsigned)height)
458 if (y - 1 < (
unsigned)height)
460 if (y + 0 < (
unsigned)height)
470 const int w2 = (width + 1) >> 1;
473 temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
474 for (x = 1; x < (width >> 1); x++) {
475 temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
476 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
479 temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
480 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
482 temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
484 b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
485 for (x = 2; x < width - 1; x += 2) {
486 b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
487 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
490 b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
491 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
493 b[x - 1] = temp[x - 1] + 3 * b[x - 2];
501 for (i = 0; i <
width; i++)
510 for (i = 0; i <
width; i++)
519 for (i = 0; i <
width; i++)
520 b1[i] += (
W_BM * (b0[i] + b2[i]) + 4 * b1[i] +
W_BO) >>
W_BS;
528 for (i = 0; i <
width; i++)
538 for (i = 0; i <
width; i++) {
541 b2[i] += (
W_BM * (b1[i] + b3[i]) + 4 * b2[i] +
W_BO) >>
W_BS;
547 int height,
int stride_line)
578 mirror(y + 3, height - 1) *
581 mirror(y + 4, height - 1) *
584 if (y > 0 && y + 4 < height) {
587 if (y + 3 < (
unsigned)height)
589 if (y + 2 < (
unsigned)height)
591 if (y + 1 < (
unsigned)height)
593 if (y + 0 < (
unsigned)height)
597 if (y - 1 < (
unsigned)height)
599 if (y + 0 < (
unsigned)height)
621 if (y + 3 < (
unsigned)height)
623 if (y + 2 < (
unsigned)height)
625 if (y + 1 < (
unsigned)height)
627 if (y + 0 < (
unsigned)height)
630 if (y - 1 < (
unsigned)height)
632 if (y + 0 < (
unsigned)height)
643 int height,
int stride_line,
int type,
644 int decomposition_count)
647 for (level = decomposition_count - 1; level >= 0; level--) {
651 stride_line << level);
655 stride_line << level);
664 int type,
int decomposition_count,
int y)
666 const int support = type == 1 ? 3 : 5;
671 for (level = decomposition_count - 1; level >= 0; level--)
672 while (cs[level].y <=
FFMIN((y >> level) + support, height >> level)) {
678 stride_line << level);
684 stride_line << level);
692 int decomposition_count)
695 for (level = decomposition_count - 1; level >= 0; level--) {
712 int decomposition_count,
int y)
714 const int support = type == 1 ? 3 : 5;
719 for (level = decomposition_count - 1; level >= 0; level--)
720 while (cs[level].y <=
FFMIN((y >> level) + support, height >> level)) {
724 height >> level, stride << level);
728 height >> level, stride << level);
735 int stride,
int type,
int decomposition_count)
740 decomposition_count);
741 for (y = 0; y <
height; y += 4)
743 decomposition_count, y);
747 int w,
int h,
int type)
750 const int dec_count = w == 8 ? 3 : 4;
751 int tmp[32 * 32], tmp2[32];
753 static const int scale[2][2][4][4] = {
756 { 268, 239, 239, 213 },
757 { 0, 224, 224, 152 },
758 { 0, 135, 135, 110 },
761 { 344, 310, 310, 280 },
762 { 0, 320, 320, 228 },
763 { 0, 175, 175, 136 },
764 { 0, 129, 129, 102 },
769 { 275, 245, 245, 218 },
770 { 0, 230, 230, 156 },
771 { 0, 138, 138, 113 },
774 { 352, 317, 317, 286 },
775 { 0, 328, 328, 233 },
776 { 0, 180, 180, 140 },
777 { 0, 132, 132, 105 },
782 for (i = 0; i < h; i++) {
783 for (j = 0; j < w; j += 4) {
784 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
785 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
786 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
787 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
797 for (level = 0; level < dec_count; level++)
798 for (ori = level ? 1 : 0; ori < 4; ori++) {
800 int sx = (ori & 1) ? size : 0;
802 int sy = (ori & 2) ? stride >> 1 : 0;
804 for (i = 0; i <
size; i++)
805 for (j = 0; j <
size; j++) {
806 int v = tmp[sx + sy + i * stride + j] *
807 scale[type][dec_count - 3][
level][ori];
817 return w_c(v, pix1, pix2, line_size, 8, h, 1);
822 return w_c(v, pix1, pix2, line_size, 8, h, 0);
827 return w_c(v, pix1, pix2, line_size, 16, h, 1);
832 return w_c(v, pix1, pix2, line_size, 16, h, 0);
837 return w_c(v, pix1, pix2, line_size, 32, h, 1);
842 return w_c(v, pix1, pix2, line_size, 32, h, 0);
#define slice_buffer_get_line(slice_buf, line_num)
#define LIFTS(src, ref, inv)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void ff_slice_buffer_release(slice_buffer *buf, int line)
static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
int ff_slice_buffer_init(slice_buffer *buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM *base_buffer)
void ff_dwt_init_x86(DWTContext *c)
static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs, slice_buffer *sb, IDWTELEM *temp, int width, int height, int stride_line)
static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb, int height, int stride_line)
static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
IDWTELEM ** line
For use by idwt and predict_slices.
void ff_dwt_init(DWTContext *c)
static int w53_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static void horizontal_decompose97i(DWTELEM *b, DWTELEM *temp, int width)
static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride)
IDWTELEM ** data_stack
Used for internal purposes.
#define MAX_DECOMPOSITIONS
static void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count)
static void spatial_decompose97i(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride)
static void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride, int type, int decomposition_count, int y)
static void horizontal_compose53i(IDWTELEM *b, IDWTELEM *temp, int width)
static int mirror(int v, int m)
Used to minimize the amount of memory used in order to optimize cache performance.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int w_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int w, int h, int type)
static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width)
void(* horizontal_compose97i)(IDWTELEM *b, IDWTELEM *temp, int width)
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)
void(* 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)
static void horizontal_decompose53i(DWTELEM *b, DWTELEM *temp, int width)
static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb, int height, int stride_line)
void ff_slice_buffer_flush(slice_buffer *buf)
void ff_dsputil_init_dwt(DSPContext *c)
IDWTELEM * ff_slice_buffer_load_line(slice_buffer *buf, int line)
static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
static int w97_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
void ff_slice_buffer_destroy(slice_buffer *buf)
void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, int height, int stride_line, int type, int decomposition_count)
static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width)
void(* vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width)
static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
static const uint16_t scale[4]
static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb, IDWTELEM *temp, int width, int height, int stride_line)
common internal and external API header
static int w53_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride)
void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height, int stride, int type, int decomposition_count)
#define LIFT(src, ref, inv)
void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs, slice_buffer *slice_buf, IDWTELEM *temp, int width, int height, int stride_line, int type, int decomposition_count, int y)
static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride)
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)
static int w97_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
IDWTELEM * base_buffer
Buffer that this structure is caching.
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)
static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width)
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, int stride, int type, int decomposition_count)