29 int max_allocated_lines,
int line_width,
47 for (i = 0; i < max_allocated_lines; i++) {
69 return buf->
line[line];
85 buffer = buf->
line[line];
88 buf->
line[line] = NULL;
112 while ((
unsigned)v > (
unsigned)m) {
121 int dst_step,
int src_step,
int ref_step,
126 const int mirror_right = (width & 1) ^ highpass;
127 const int w = (width >> 1) - 1 + (highpass & width);
130 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
132 dst[0] =
LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
137 for (i = 0; i < w; i++)
138 dst[i * dst_step] =
LIFT(src[i * src_step],
139 ((mul * (ref[i * ref_step] +
140 ref[(i + 1) * ref_step]) +
145 dst[w * dst_step] =
LIFT(src[w * src_step],
146 ((mul * 2 * ref[w * ref_step] + add) >> shift),
151 int dst_step,
int src_step,
int ref_step,
156 const int mirror_right = (width & 1) ^ highpass;
157 const int w = (width >> 1) - 1 + (highpass & width);
161 #define LIFTS(src, ref, inv) \
162 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
163 : -((-16 * (src) + (ref) + add / \
164 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
166 dst[0] =
LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
171 for (i = 0; i < w; i++)
172 dst[i * dst_step] =
LIFTS(src[i * src_step],
173 mul * (ref[i * ref_step] +
174 ref[(i + 1) * ref_step]) + add,
178 dst[w * dst_step] =
LIFTS(src[w * src_step],
179 mul * 2 * ref[w * ref_step] + add,
185 const int width2 = width >> 1;
187 const int w2 = (width + 1) >> 1;
189 for (x = 0; x < width2; x++) {
191 temp[x + w2] = b[2 * x + 1];
195 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
196 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
204 for (i = 0; i <
width; i++)
205 b1[i] -= (b0[i] + b2[i]) >> 1;
213 for (i = 0; i <
width; i++)
214 b1[i] += (b0[i] + b2[i] + 2) >> 2;
224 for (y = -2; y <
height; y += 2) {
228 if (y + 1 < (
unsigned)height)
230 if (y + 2 < (
unsigned)height)
233 if (y + 1 < (
unsigned)height)
235 if (y + 0 < (
unsigned)height)
245 const int w2 = (width + 1) >> 1;
247 lift(temp + w2, b + 1, b, 1, 2, 2, width,
W_AM,
W_AO,
W_AS, 1, 1);
248 liftS(temp, b, temp + w2, 1, 2, 1, width,
W_BM,
W_BO,
W_BS, 0, 0);
249 lift(b + w2, temp + w2, temp, 1, 1, 1, width,
W_CM,
W_CO,
W_CS, 1, 0);
250 lift(b, temp, b + w2, 1, 1, 1, width,
W_DM,
W_DO,
W_DS, 0, 0);
258 for (i = 0; i <
width; i++)
267 for (i = 0; i <
width; i++)
276 for (i = 0; i <
width; i++)
277 b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) +
W_BO * 5 + (5 << 27)) /
278 (5 * 16) - (1 << 23);
286 for (i = 0; i <
width; i++)
299 for (y = -4; y <
height; y += 2) {
303 if (y + 3 < (
unsigned)height)
305 if (y + 4 < (
unsigned)height)
308 if (y + 3 < (
unsigned)height)
310 if (y + 2 < (
unsigned)height)
312 if (y + 1 < (
unsigned)height)
314 if (y + 0 < (
unsigned)height)
325 int stride,
int type,
int decomposition_count)
329 for (level = 0; level < decomposition_count; level++) {
333 width >> level, height >> level,
338 width >> level, height >> level,
347 const int width2 = width >> 1;
348 const int w2 = (width + 1) >> 1;
351 for (x = 0; x < width2; x++) {
353 temp[2 * x + 1] = b[x + w2];
358 b[0] = temp[0] - ((temp[1] + 1) >> 1);
359 for (x = 2; x < width - 1; x += 2) {
360 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
361 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
364 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
365 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
367 b[x - 1] = temp[x - 1] + b[x - 2];
375 for (i = 0; i <
width; i++)
376 b1[i] += (b0[i] + b2[i]) >> 1;
384 for (i = 0; i <
width; i++)
385 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
389 int height,
int stride_line)
392 mirror(-1 - 1, height - 1) * stride_line);
415 mirror(y + 1, height - 1) *
418 mirror(y + 2, height - 1) *
421 if (y + 1 < (
unsigned)height && y < (
unsigned)height) {
424 for (x = 0; x <
width; x++) {
425 b2[x] -= (b1[x] + b3[x] + 2) >> 2;
426 b1[x] += (b0[x] + b2[x]) >> 1;
429 if (y + 1 < (
unsigned)
height)
431 if (y + 0 < (
unsigned)
height)
435 if (y - 1 < (
unsigned)
height)
437 if (y + 0 < (
unsigned)
height)
455 if (y + 1 < (
unsigned)height)
457 if (y + 0 < (
unsigned)height)
460 if (y - 1 < (
unsigned)height)
462 if (y + 0 < (
unsigned)height)
472 const int w2 = (width + 1) >> 1;
475 temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
476 for (x = 1; x < (width >> 1); x++) {
477 temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
478 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
481 temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
482 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
484 temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
486 b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
487 for (x = 2; x < width - 1; x += 2) {
488 b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
489 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
492 b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
493 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
495 b[x - 1] = temp[x - 1] + 3 * b[x - 2];
503 for (i = 0; i <
width; i++)
512 for (i = 0; i <
width; i++)
521 for (i = 0; i <
width; i++)
522 b1[i] += (
W_BM * (b0[i] + b2[i]) + 4 * b1[i] +
W_BO) >>
W_BS;
530 for (i = 0; i <
width; i++)
540 for (i = 0; i <
width; i++) {
543 b2[i] += (
W_BM * (b1[i] + b3[i]) + 4 * b2[i] +
W_BO) >>
W_BS;
549 int height,
int stride_line)
580 mirror(y + 3, height - 1) *
583 mirror(y + 4, height - 1) *
586 if (y > 0 && y + 4 < height) {
589 if (y + 3 < (
unsigned)height)
591 if (y + 2 < (
unsigned)height)
593 if (y + 1 < (
unsigned)height)
595 if (y + 0 < (
unsigned)height)
599 if (y - 1 < (
unsigned)height)
601 if (y + 0 < (
unsigned)height)
623 if (y + 3 < (
unsigned)height)
625 if (y + 2 < (
unsigned)height)
627 if (y + 1 < (
unsigned)height)
629 if (y + 0 < (
unsigned)height)
632 if (y - 1 < (
unsigned)height)
634 if (y + 0 < (
unsigned)height)
645 int height,
int stride_line,
int type,
646 int decomposition_count)
649 for (level = decomposition_count - 1; level >= 0; level--) {
653 stride_line << level);
657 stride_line << level);
666 int type,
int decomposition_count,
int y)
668 const int support = type == 1 ? 3 : 5;
673 for (level = decomposition_count - 1; level >= 0; level--)
674 while (cs[level].y <=
FFMIN((y >> level) + support, height >> level)) {
680 stride_line << level);
686 stride_line << level);
694 int decomposition_count)
697 for (level = decomposition_count - 1; level >= 0; level--) {
714 int decomposition_count,
int y)
716 const int support = type == 1 ? 3 : 5;
721 for (level = decomposition_count - 1; level >= 0; level--)
722 while (cs[level].y <=
FFMIN((y >> level) + support, height >> level)) {
726 height >> level, stride << level);
730 height >> level, stride << level);
737 int stride,
int type,
int decomposition_count)
742 decomposition_count);
743 for (y = 0; y <
height; y += 4)
745 decomposition_count, y);
749 int w,
int h,
int type)
752 const int dec_count = w == 8 ? 3 : 4;
753 int tmp[32 * 32], tmp2[32];
755 static const int scale[2][2][4][4] = {
758 { 268, 239, 239, 213 },
759 { 0, 224, 224, 152 },
760 { 0, 135, 135, 110 },
763 { 344, 310, 310, 280 },
764 { 0, 320, 320, 228 },
765 { 0, 175, 175, 136 },
766 { 0, 129, 129, 102 },
771 { 275, 245, 245, 218 },
772 { 0, 230, 230, 156 },
773 { 0, 138, 138, 113 },
776 { 352, 317, 317, 286 },
777 { 0, 328, 328, 233 },
778 { 0, 180, 180, 140 },
779 { 0, 132, 132, 105 },
784 for (i = 0; i < h; i++) {
785 for (j = 0; j < w; j += 4) {
786 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
787 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
788 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
789 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
799 for (level = 0; level < dec_count; level++)
800 for (ori = level ? 1 : 0; ori < 4; ori++) {
802 int sx = (ori & 1) ? size : 0;
804 int sy = (ori & 2) ? stride >> 1 : 0;
806 for (i = 0; i <
size; i++)
807 for (j = 0; j <
size; j++) {
808 int v = tmp[sx + sy + i * stride + j] *
809 scale[type][dec_count - 3][
level][ori];
819 return w_c(v, pix1, pix2, line_size, 8, h, 1);
824 return w_c(v, pix1, pix2, line_size, 8, h, 0);
829 return w_c(v, pix1, pix2, line_size, 16, h, 1);
834 return w_c(v, pix1, pix2, line_size, 16, h, 0);
839 return w_c(v, pix1, pix2, line_size, 32, h, 1);
844 return w_c(v, pix1, pix2, line_size, 32, h, 0);