30 int max_allocated_lines,
int line_width,
48 for (i = 0; i < max_allocated_lines; i++) {
70 return buf->
line[line];
86 buffer = buf->
line[line];
113 while ((
unsigned)v > (
unsigned)m) {
122 int dst_step,
int src_step,
int ref_step,
126 const int mirror_left = !highpass;
127 const int mirror_right = (width & 1) ^ highpass;
128 const int w = (width >> 1) - 1 + (highpass & width);
131 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
133 dst[0] =
LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
138 for (i = 0; i < w; i++)
139 dst[i * dst_step] =
LIFT(src[i * src_step],
140 ((mul * (ref[i * ref_step] +
141 ref[(i + 1) * ref_step]) +
146 dst[w * dst_step] =
LIFT(src[w * src_step],
147 ((mul * 2 * ref[w * ref_step] + add) >> shift),
152 int dst_step,
int src_step,
int ref_step,
156 const int mirror_left = !highpass;
157 const int mirror_right = (width & 1) ^ highpass;
158 const int w = (width >> 1) - 1 + (highpass & width);
162 #define LIFTS(src, ref, inv) \
163 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
164 : -((-16 * (src) + (ref) + add / \
165 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
167 dst[0] =
LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
172 for (i = 0; i < w; i++)
173 dst[i * dst_step] =
LIFTS(src[i * src_step],
174 mul * (ref[i * ref_step] +
175 ref[(i + 1) * ref_step]) + add,
179 dst[w * dst_step] =
LIFTS(src[w * src_step],
180 mul * 2 * ref[w * ref_step] + add,
186 const int width2 = width >> 1;
188 const int w2 = (width + 1) >> 1;
190 for (x = 0; x < width2; x++) {
192 temp[x + w2] = b[2 * x + 1];
196 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
197 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
205 for (i = 0; i <
width; i++)
206 b1[i] -= (b0[i] + b2[i]) >> 1;
214 for (i = 0; i <
width; i++)
215 b1[i] += (b0[i] + b2[i] + 2) >> 2;
225 for (y = -2; y <
height; y += 2) {
229 if (y + 1 < (
unsigned)height)
231 if (y + 2 < (
unsigned)height)
234 if (y + 1 < (
unsigned)height)
236 if (y + 0 < (
unsigned)height)
246 const int w2 = (width + 1) >> 1;
248 lift(temp + w2, b + 1, b, 1, 2, 2, width,
W_AM,
W_AO,
W_AS, 1, 1);
249 liftS(temp, b, temp + w2, 1, 2, 1, width,
W_BM,
W_BO,
W_BS, 0, 0);
250 lift(b + w2, temp + w2, temp, 1, 1, 1, width,
W_CM,
W_CO,
W_CS, 1, 0);
251 lift(b, temp, b + w2, 1, 1, 1, width,
W_DM,
W_DO,
W_DS, 0, 0);
259 for (i = 0; i <
width; i++)
268 for (i = 0; i <
width; i++)
277 for (i = 0; i <
width; i++)
278 b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) +
W_BO * 5 + (5 << 27)) /
279 (5 * 16) - (1 << 23);
287 for (i = 0; i <
width; i++)
300 for (y = -4; y <
height; y += 2) {
304 if (y + 3 < (
unsigned)height)
306 if (y + 4 < (
unsigned)height)
309 if (y + 3 < (
unsigned)height)
311 if (y + 2 < (
unsigned)height)
313 if (y + 1 < (
unsigned)height)
315 if (y + 0 < (
unsigned)height)
326 int stride,
int type,
int decomposition_count)
330 for (level = 0; level < decomposition_count; level++) {
334 width >> level, height >> level,
339 width >> level, height >> level,
348 const int width2 = width >> 1;
349 const int w2 = (width + 1) >> 1;
352 for (x = 0; x < width2; x++) {
354 temp[2 * x + 1] = b[x + w2];
359 b[0] = temp[0] - ((temp[1] + 1) >> 1);
360 for (x = 2; x < width - 1; x += 2) {
361 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
362 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
365 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
366 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
368 b[x - 1] = temp[x - 1] + b[x - 2];
376 for (i = 0; i <
width; i++)
377 b1[i] += (b0[i] + b2[i]) >> 1;
385 for (i = 0; i <
width; i++)
386 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
390 int height,
int stride_line)
393 mirror(-1 - 1, height - 1) * stride_line);
416 mirror(y + 1, height - 1) *
419 mirror(y + 2, height - 1) *
422 if (y + 1 < (
unsigned)height && y < (
unsigned)height) {
425 for (x = 0; x <
width; x++) {
426 b2[x] -= (b1[x] + b3[x] + 2) >> 2;
427 b1[x] += (b0[x] + b2[x]) >> 1;
430 if (y + 1 < (
unsigned)
height)
432 if (y + 0 < (
unsigned)
height)
436 if (y - 1 < (
unsigned)
height)
438 if (y + 0 < (
unsigned)
height)
456 if (y + 1 < (
unsigned)height)
458 if (y + 0 < (
unsigned)height)
461 if (y - 1 < (
unsigned)height)
463 if (y + 0 < (
unsigned)height)
473 const int w2 = (width + 1) >> 1;
476 temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
477 for (x = 1; x < (width >> 1); x++) {
478 temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
479 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
482 temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
483 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
485 temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
487 b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
488 for (x = 2; x < width - 1; x += 2) {
489 b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
490 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
493 b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
494 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
496 b[x - 1] = temp[x - 1] + 3 * b[x - 2];
504 for (i = 0; i <
width; i++)
513 for (i = 0; i <
width; i++)
522 for (i = 0; i <
width; i++)
523 b1[i] += (
W_BM * (b0[i] + b2[i]) + 4 * b1[i] +
W_BO) >>
W_BS;
531 for (i = 0; i <
width; i++)
541 for (i = 0; i <
width; i++) {
544 b2[i] += (
W_BM * (b1[i] + b3[i]) + 4 * b2[i] +
W_BO) >>
W_BS;
550 int height,
int stride_line)
581 mirror(y + 3, height - 1) *
584 mirror(y + 4, height - 1) *
587 if (y > 0 && y + 4 < height) {
590 if (y + 3 < (
unsigned)height)
592 if (y + 2 < (
unsigned)height)
594 if (y + 1 < (
unsigned)height)
596 if (y + 0 < (
unsigned)height)
600 if (y - 1 < (
unsigned)height)
602 if (y + 0 < (
unsigned)height)
624 if (y + 3 < (
unsigned)height)
626 if (y + 2 < (
unsigned)height)
628 if (y + 1 < (
unsigned)height)
630 if (y + 0 < (
unsigned)height)
633 if (y - 1 < (
unsigned)height)
635 if (y + 0 < (
unsigned)height)
646 int height,
int stride_line,
int type,
647 int decomposition_count)
650 for (level = decomposition_count - 1; level >= 0; level--) {
654 stride_line << level);
658 stride_line << level);
667 int type,
int decomposition_count,
int y)
669 const int support = type == 1 ? 3 : 5;
674 for (level = decomposition_count - 1; level >= 0; level--)
675 while (cs[level].y <=
FFMIN((y >> level) + support, height >> level)) {
681 stride_line << level);
687 stride_line << level);
695 int decomposition_count)
698 for (level = decomposition_count - 1; level >= 0; level--) {
715 int decomposition_count,
int y)
717 const int support = type == 1 ? 3 : 5;
722 for (level = decomposition_count - 1; level >= 0; level--)
723 while (cs[level].y <=
FFMIN((y >> level) + support, height >> level)) {
727 height >> level, stride << level);
731 height >> level, stride << level);
738 int stride,
int type,
int decomposition_count)
743 decomposition_count);
744 for (y = 0; y <
height; y += 4)
746 decomposition_count, y);
750 int w,
int h,
int type)
753 const int dec_count = w == 8 ? 3 : 4;
754 int tmp[32 * 32], tmp2[32];
756 static const int scale[2][2][4][4] = {
759 { 268, 239, 239, 213 },
760 { 0, 224, 224, 152 },
761 { 0, 135, 135, 110 },
764 { 344, 310, 310, 280 },
765 { 0, 320, 320, 228 },
766 { 0, 175, 175, 136 },
767 { 0, 129, 129, 102 },
772 { 275, 245, 245, 218 },
773 { 0, 230, 230, 156 },
774 { 0, 138, 138, 113 },
777 { 352, 317, 317, 286 },
778 { 0, 328, 328, 233 },
779 { 0, 180, 180, 140 },
780 { 0, 132, 132, 105 },
785 for (i = 0; i < h; i++) {
786 for (j = 0; j < w; j += 4) {
787 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
788 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
789 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
790 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
800 for (level = 0; level < dec_count; level++)
801 for (ori = level ? 1 : 0; ori < 4; ori++) {
803 int sx = (ori & 1) ? size : 0;
805 int sy = (ori & 2) ? stride >> 1 : 0;
807 for (i = 0; i <
size; i++)
808 for (j = 0; j <
size; j++) {
809 int v = tmp[sx + sy + i * stride + j] *
810 scale[type][dec_count - 3][
level][ori];
820 return w_c(v, pix1, pix2, line_size, 8, h, 1);
825 return w_c(v, pix1, pix2, line_size, 8, h, 0);
830 return w_c(v, pix1, pix2, line_size, 16, h, 1);
835 return w_c(v, pix1, pix2, line_size, 16, h, 0);
840 return w_c(v, pix1, pix2, line_size, 32, h, 1);
845 return w_c(v, pix1, pix2, line_size, 32, h, 0);
871 for (i = 0; i < w2; i++) {
872 dst[2*i ] = (src0[i] + add) >> shift;
873 dst[2*i+1] = (src1[i] + add) >> shift;
879 const int w2 = w >> 1;
883 for (x = 1; x < w2; x++) {
894 const int w2 = w >> 1;
898 for (x = 1; x < w2; x++)
903 tmp[w2+1] = tmp[w2] = tmp[w2-1];
905 for (x = 0; x < w2; x++) {
906 b[2*x ] = (tmp[x] + 1)>>1;
907 b[2*x+1] = (
COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
913 const int w2 = w >> 1;
918 for (x = 2; x < w2-1; x++)
924 tmp[w2+1] = tmp[w2] = tmp[w2-1];
926 for (x = 0; x < w2; x++) {
927 b[2*x ] = (tmp[x] + 1)>>1;
928 b[2*x+1] = (
COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
935 const int w2 = w >> 1;
938 for (x = 0; x < w2; x++) {
943 interleave(b, temp, temp+w2, w2, shift, shift);
958 const int w2 = w >> 1;
962 for (x = 0; x < w2; x++) {
963 for (i = 0; i < 8; i++)
964 v[i] = b[av_clip(x-3+i, 0, w2-1)];
968 for (x = 0; x < w2; x++) {
969 for (i = 0; i < 8; i++)
970 v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
979 const int w2 = w >> 1;
983 for (x = 1; x < w2; x++) {
991 b[0] = (b0 + 1) >> 1;
992 for (x = 1; x < w2; x++) {
995 b[2*x-1] = (b1 + 1) >> 1;
996 b[2*x ] = (b2 + 1) >> 1;
1006 for(i=0; i<
width; i++){
1016 for(i=0; i<
width; i++){
1026 for(i=0; i<
width; i++){
1035 for (i = 0; i <
width; i++) {
1045 for(i=0; i<
width; i++){
1046 dst[i] =
COMPOSE_FIDELITYiH0(b[0][i], b[1][i], b[2][i], b[3][i], dst[i], b[4][i], b[5][i], b[6][i], b[7][i]);
1054 for(i=0; i<
width; i++){
1055 dst[i] =
COMPOSE_FIDELITYiL0(b[0][i], b[1][i], b[2][i], b[3][i], dst[i], b[4][i], b[5][i], b[6][i], b[7][i]);
1063 for(i=0; i<
width; i++){
1072 for(i=0; i<
width; i++){
1081 for(i=0; i<
width; i++){
1090 for(i=0; i<
width; i++){
1104 for (i = 0; i < 6; i++)
1109 if(y+5<(
unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width);
1110 if(y+1<(
unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1115 for (i = 0; i < 6; i++)
1131 if(y+1<(
unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1132 if(y+0<(
unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1151 for (i = 0; i < 8; i++)
1156 if(y+5<(
unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
1157 if(y+1<(
unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1162 for (i = 0; i < 8; i++)
1171 int y = d->
cs[level].
y;
1175 vertical_compose(b0, b1, width);
1191 for (y = 1; y <
height; y += 2) {
1192 for (i = 0; i < 8; i++)
1193 b[i] = d->
buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
1194 vertical_compose_h0(d->
buffer + y*stride, b, width);
1197 for (y = 0; y <
height; y += 2) {
1198 for (i = 0; i < 8; i++)
1199 b[i] = d->
buffer + av_clip((y-7 + 2*i), 1, height-1)*
stride;
1200 vertical_compose_l0(d->
buffer + y*stride, b, width);
1203 for (y = 0; y <
height; y++)
1219 for (i = 0; i < 4; i++)
1224 if(y+3<(
unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
1225 if(y+2<(
unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
1226 if(y+1<(
unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1227 if(y+0<(
unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1232 for (i = 0; i < 4; i++)
1256 cs->
b[0] = buffer + av_clip(-5-1, 0, height-2)*
stride;
1257 cs->
b[1] = buffer + av_clip(-5 , 1, height-1)*
stride;
1258 cs->
b[2] = buffer + av_clip(-5+1, 0, height-2)*
stride;
1259 cs->
b[3] = buffer + av_clip(-5+2, 1, height-1)*
stride;
1260 cs->
b[4] = buffer + av_clip(-5+3, 0, height-2)*
stride;
1261 cs->
b[5] = buffer + av_clip(-5+4, 1, height-1)*
stride;
1267 cs->
b[0] = buffer + av_clip(-5-1, 0, height-2)*
stride;
1268 cs->
b[1] = buffer + av_clip(-5 , 1, height-1)*
stride;
1269 cs->
b[2] = buffer + av_clip(-5+1, 0, height-2)*
stride;
1270 cs->
b[3] = buffer + av_clip(-5+2, 1, height-1)*
stride;
1271 cs->
b[4] = buffer + av_clip(-5+3, 0, height-2)*
stride;
1272 cs->
b[5] = buffer + av_clip(-5+4, 1, height-1)*
stride;
1273 cs->
b[6] = buffer + av_clip(-5+5, 0, height-2)*
stride;
1274 cs->
b[7] = buffer + av_clip(-5+6, 1, height-1)*
stride;
1291 for(level=decomposition_count-1; level>=0; level--){
1292 int hl = height >>
level;
1293 int stride_l = stride <<
level;
1384 while (d->
cs[level].
y <=
FFMIN((y>>level)+support, hl))
1398 for (y = 0; y < d.
height; y += 4)