1 /*
2 * Copyright (c) 2015-2016 Kieran Kunhya <kieran@kunhya.com>
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 /**
22 * @file
23 * Cineform HD video decoder
24 */
25
32
41
42 #define ALPHA_COMPAND_DC_OFFSET 256
43 #define ALPHA_COMPAND_GAIN 9400
44
46 {
48
50
51 for (
int i = 0;
i < 64;
i++) {
53
59 }
60
64 }
65
67 }
68
69 for (
int i = 0;
i < 256;
i++)
70 s->lut[1][
i] =
i + ((768LL *
i *
i *
i) / (256 * 256 * 256));
71
73 }
74
76 {
79 s->subband_num_actual = 0;
80 }
81
83 {
86 memset(&
s->peak.base, 0,
sizeof(
s->peak.base));
87 }
88
90 {
94 s->cropped_height = 0;
99 s->lowpass_precision = 16;
102 s->difference_coding = 0;
105 if (
s->transform_type != 2)
106 s->transform_type = -1;
109 }
110
112 {
115 } else
116 return level * quantisation;
117 }
118
120 {
122 for (
int j = 1; j <
width; j++) {
123 band[j] += band[j-1];
124 }
126 }
127 }
128
130 {
131 for (
int i = 0;
i < length;
i++)
133 band[
i] = bytestream2_get_le16(&peak->
base);
134 }
135
137 {
146 }
147 }
148
150 {
151 const int linesize =
frame->linesize[0];
152 uint16_t *
r = (uint16_t *)
frame->data[0];
153 uint16_t *g1 = (uint16_t *)(
frame->data[0] + 2);
154 uint16_t *g2 = (uint16_t *)(
frame->data[0] +
frame->linesize[0]);
155 uint16_t *
b = (uint16_t *)(
frame->data[0] +
frame->linesize[0] + 2);
156 const int mid = 1 << (bpc - 1);
157 const int factor = 1 << (16 - bpc);
158
159 for (
int y = 0; y <
frame->height >> 1; y++) {
160 for (
int x = 0; x <
frame->width; x += 2) {
163
165 rg = g1[x];
166 bg = g2[x];
168 gd -= mid;
169
170 R = (rg - mid) * 2 +
g;
173 B = (bg - mid) * 2 +
g;
174
179
181 g1[x] = G1;
184 }
185
187 g1 += linesize;
188 g2 += linesize;
190 }
191 }
192
194 int width,
int linesize,
int plane)
195 {
198 int16_t odd = (low[
i] +
high[
i])/2;
201 }
202 }
203
205 {
208 int odd = (low[
i] +
high[
i]) / 2;
209
212 }
213 }
214
216 {
221 s->plane[
i].idwt_size = 0;
222
224 s->plane[
i].subband[j] =
NULL;
225
226 for (
int j = 0; j < 10; j++)
227 s->plane[
i].l_h[j] =
NULL;
228
230 p->band[j][0].read_ok =
231 p->band[j][1].read_ok =
232 p->band[j][2].read_ok =
233 p->band[j][3].read_ok = 0;
234 }
237 s->a_transform_type = INT_MIN;
238 }
239
241 {
244 int chroma_x_shift, chroma_y_shift;
245
249
251
253 &chroma_x_shift,
254 &chroma_y_shift)) < 0)
259 chroma_x_shift = 1;
260 chroma_y_shift = 1;
261 bayer = 1;
262 }
263
265 int w8, h8, w4, h4, w2, h2;
266 int width = (
i || bayer) ?
s->coded_width >> chroma_x_shift :
s->coded_width;
267 int height = (
i || bayer) ?
s->coded_height >> chroma_y_shift :
s->coded_height;
269
272
273 if (chroma_y_shift && !bayer)
278
279 w8 =
FFALIGN(
s->plane[
i].width / 8, 8) + 64;
281 w4 = w8 * 2;
282 h4 = h8 * 2;
283 w2 = w4 * 2;
284 h2 = h4 * 2;
285
286 if (
s->transform_type == 0) {
288 s->plane[
i].idwt_buf =
289 av_calloc(
s->plane[
i].idwt_size,
sizeof(*
s->plane[
i].idwt_buf));
290 s->plane[
i].idwt_tmp =
292 } else {
294 s->plane[
i].idwt_buf =
295 av_calloc(
s->plane[
i].idwt_size,
sizeof(*
s->plane[
i].idwt_buf));
296 s->plane[
i].idwt_tmp =
298 }
299
300 if (!
s->plane[
i].idwt_buf || !
s->plane[
i].idwt_tmp)
302
303 s->plane[
i].subband[0] =
s->plane[
i].idwt_buf;
304 s->plane[
i].subband[1] =
s->plane[
i].idwt_buf + 2 * w8 * h8;
305 s->plane[
i].subband[2] =
s->plane[
i].idwt_buf + 1 * w8 * h8;
306 s->plane[
i].subband[3] =
s->plane[
i].idwt_buf + 3 * w8 * h8;
307 s->plane[
i].subband[4] =
s->plane[
i].idwt_buf + 2 * w4 * h4;
308 s->plane[
i].subband[5] =
s->plane[
i].idwt_buf + 1 * w4 * h4;
309 s->plane[
i].subband[6] =
s->plane[
i].idwt_buf + 3 * w4 * h4;
310 if (
s->transform_type == 0) {
311 s->plane[
i].subband[7] =
s->plane[
i].idwt_buf + 2 * w2 * h2;
312 s->plane[
i].subband[8] =
s->plane[
i].idwt_buf + 1 * w2 * h2;
313 s->plane[
i].subband[9] =
s->plane[
i].idwt_buf + 3 * w2 * h2;
314 } else {
315 int16_t *frame2 =
316 s->plane[
i].subband[7] =
s->plane[
i].idwt_buf + 4 * w2 * h2;
317 s->plane[
i].subband[8] = frame2 + 2 * w4 * h4;
318 s->plane[
i].subband[9] = frame2 + 1 * w4 * h4;
319 s->plane[
i].subband[10] = frame2 + 3 * w4 * h4;
320 s->plane[
i].subband[11] = frame2 + 2 * w2 * h2;
321 s->plane[
i].subband[12] = frame2 + 1 * w2 * h2;
322 s->plane[
i].subband[13] = frame2 + 3 * w2 * h2;
323 s->plane[
i].subband[14] =
s->plane[
i].idwt_buf + 2 * w2 * h2;
324 s->plane[
i].subband[15] =
s->plane[
i].idwt_buf + 1 * w2 * h2;
325 s->plane[
i].subband[16] =
s->plane[
i].idwt_buf + 3 * w2 * h2;
326 }
327
328 if (
s->transform_type == 0) {
331 s->plane[
i].band[j][k].a_width = w8 << j;
332 s->plane[
i].band[j][k].a_height = h8 << j;
333 }
334 }
335 } else {
337 int t = j < 1 ? 0 : (j < 3 ? 1 : 2);
338
340 s->plane[
i].band[j][k].a_width = w8 << t;
341 s->plane[
i].band[j][k].a_height = h8 << t;
342 }
343 }
344 }
345
346 /* ll2 and ll1 commented out because they are done in-place */
347 s->plane[
i].l_h[0] =
s->plane[
i].idwt_tmp;
348 s->plane[
i].l_h[1] =
s->plane[
i].idwt_tmp + 2 * w8 * h8;
349 // s->plane[i].l_h[2] = ll2;
350 s->plane[
i].l_h[3] =
s->plane[
i].idwt_tmp;
351 s->plane[
i].l_h[4] =
s->plane[
i].idwt_tmp + 2 * w4 * h4;
352 // s->plane[i].l_h[5] = ll1;
353 s->plane[
i].l_h[6] =
s->plane[
i].idwt_tmp;
354 s->plane[
i].l_h[7] =
s->plane[
i].idwt_tmp + 2 * w2 * h2;
355 if (
s->transform_type != 0) {
356 int16_t *frame2 =
s->plane[
i].idwt_tmp + 4 * w2 * h2;
357
358 s->plane[
i].l_h[8] = frame2;
359 s->plane[
i].l_h[9] = frame2 + 2 * w2 * h2;
360 }
361 }
362
363 s->a_transform_type =
s->transform_type;
364 s->a_height =
s->coded_height;
365 s->a_width =
s->coded_width;
366 s->a_format =
s->coded_format;
367
368 return 0;
369 }
370
373 {
377 int ret = 0, got_buffer = 0;
378
381
383
385 /* Bit weird but implement the tag parsing as the spec says */
386 uint16_t tagu = bytestream2_get_be16(&gb);
387 int16_t
tag = (int16_t)tagu;
388 int8_t tag8 = (int8_t)(tagu >> 8);
389 uint16_t abstag =
abs(
tag);
390 int8_t abs_tag8 =
abs(tag8);
391 uint16_t
data = bytestream2_get_be16(&gb);
392 int16_t *coeff_data;
393
394 if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
398 s->progressive =
data & 0x0001;
400 s->frame_type =
data;
410 }
else if (abstag ==
Version) {
414 s->coded_width =
data;
417 s->coded_height =
data;
420 s->channel_cnt =
data;
424 goto end;
425 }
431 goto end;
432 }
434 s->channel_num =
data;
436 if (
s->channel_num >=
s->planes) {
439 goto end;
440 }
443 if (
s->subband_num != 0 &&
data == 1 && (
s->transform_type == 0 ||
s->transform_type == 2))
// hack
446 s->subband_num =
data;
447 if ((
s->transform_type == 0 &&
s->level >=
DWT_LEVELS) ||
451 goto end;
452 }
453 if (
s->subband_num > 3) {
456 goto end;
457 }
464 goto end;
465 }
466 if (
s->transform_type == 0 ||
s->transform_type == 2)
467 s->subband_num_actual =
data;
468 else
473 s->quantisation =
data;
476 for (
int i = 0;
i < 8;
i++)
477 s->prescale_table[
i] = (
data >> (14 -
i * 2)) & 0x3;
483 goto end;
484 }
485 s->band_encoding =
data;
489 s->plane[
s->channel_num].band[0][0].width =
data;
490 s->plane[
s->channel_num].band[0][0].stride =
data;
493 s->plane[
s->channel_num].band[0][0].height =
data;
495 s->sample_type =
data;
501 goto end;
502 }
else if (
data == 1) {
505 goto end;
506 }
507 if (
s->transform_type == -1) {
508 s->transform_type =
data;
510 } else {
512 }
513 } else if (abstag >= 0x4000 && abstag <= 0x40ff) {
514 if (abstag == 0x4001)
520 s->frame_index =
data;
526 goto end;
527 }
528 for (
int i = 0;
i <
data;
i++) {
529 uint32_t
offset = bytestream2_get_be32(&gb);
531 }
533 av_log(avctx,
AV_LOG_DEBUG,
"Highpass width %i channel %i level %i subband %i\n",
data,
s->channel_num,
s->level,
s->subband_num);
537 goto end;
538 }
539 s->plane[
s->channel_num].band[
s->level][
s->subband_num].width =
data;
540 s->plane[
s->channel_num].band[
s->level][
s->subband_num].stride =
FFALIGN(
data, 8);
546 goto end;
547 }
548 s->plane[
s->channel_num].band[
s->level][
s->subband_num].height =
data;
554 goto end;
555 }
556 s->plane[
s->channel_num].band[
s->level][
s->subband_num].width =
data;
557 s->plane[
s->channel_num].band[
s->level][
s->subband_num].stride =
FFALIGN(
data, 8);
563 goto end;
564 }
565 s->plane[
s->channel_num].band[
s->level][
s->subband_num].height =
data;
572 }
else if (
data >= 122 &&
data <= 128) {
574 }
else if (
data == 30) {
576 } else {
578 }
580 }
582 s->codebook =
data & 0xf;
583 s->difference_coding = (
data >> 4) & 1;
590 goto end;
591 }
597 }
else if (
data == 2) {
599 }
else if (
data == 3) {
601 }
else if (
data == 4) {
603 } else {
606 goto end;
607 }
611 s->cropped_height =
data;
613 s->peak.offset &= ~0xffff;
614 s->peak.offset |= (
data & 0xffff);
618 s->peak.offset &= 0xffff;
619 s->peak.offset |= (
data & 0xffff
U)<<16;
623 s->peak.level =
data;
626 ) {
628 goto end;
629 }
631 } else
633
636 int lowpass_height =
s->plane[
s->channel_num].band[0][0].height;
637 int lowpass_width =
s->plane[
s->channel_num].band[0][0].width;
639
640 if (
s->coded_width) {
642 }
643
644 if (
s->coded_height) {
646 }
647
648 if (!
s->a_width && !
s->coded_width) {
649 s->coded_width = lowpass_width *
factor * 8;
650 }
651
652 if (!
s->a_height && !
s->coded_height) {
653 s->coded_height = lowpass_height *
factor * 8;
654 }
655
656 if (
s->a_width && !
s->coded_width)
657 s->coded_width =
s->a_width;
658 if (
s->a_height && !
s->coded_height)
659 s->coded_height =
s->a_height;
660
661 if (
s->a_width !=
s->coded_width ||
s->a_height !=
s->coded_height ||
662 s->a_format !=
s->coded_format ||
663 s->transform_type !=
s->a_transform_type) {
668 }
669 }
673 if (
s->cropped_height) {
678 }
680
683
687 got_buffer = 1;
690
696 got_buffer = 1;
697 }
698
699 if (
s->subband_num_actual == 255)
701 coeff_data =
s->plane[
s->channel_num].subband[
s->subband_num_actual];
702
703 /* Lowpass coefficients */
705 int lowpass_height, lowpass_width, lowpass_a_height, lowpass_a_width;
706
707 if (!
s->a_width || !
s->a_height) {
709 goto end;
710 }
711
712 lowpass_height =
s->plane[
s->channel_num].band[0][0].height;
713 lowpass_width =
s->plane[
s->channel_num].band[0][0].width;
714 lowpass_a_height =
s->plane[
s->channel_num].band[0][0].a_height;
715 lowpass_a_width =
s->plane[
s->channel_num].band[0][0].a_width;
716
717 if (lowpass_width < 3 ||
718 lowpass_width > lowpass_a_width) {
721 goto end;
722 }
723
724 if (lowpass_height < 3 ||
725 lowpass_height > lowpass_a_height) {
728 goto end;
729 }
730
731 if (!got_buffer) {
734 goto end;
735 }
736
737 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
741 goto end;
742 }
743
744 av_log(avctx,
AV_LOG_DEBUG,
"Start of lowpass coeffs component %d height:%d, width:%d\n",
s->channel_num, lowpass_height, lowpass_width);
745 for (
int i = 0;
i < lowpass_height;
i++) {
746 for (int j = 0; j < lowpass_width; j++)
747 coeff_data[j] = bytestream2_get_be16u(&gb);
748
749 coeff_data += lowpass_width;
750 }
751
752 /* Align to mod-4 position to continue reading tags */
754
755 /* Copy last line of coefficients if odd height */
756 if (lowpass_height & 1) {
757 memcpy(&coeff_data[lowpass_height * lowpass_width],
758 &coeff_data[(lowpass_height - 1) * lowpass_width],
759 lowpass_width * sizeof(*coeff_data));
760 }
761
762 s->plane[
s->channel_num].band[0][0].read_ok = 1;
763
764 av_log(avctx,
AV_LOG_DEBUG,
"Lowpass coefficients %d\n", lowpass_width * lowpass_height);
765 }
766
769 int highpass_height, highpass_width, highpass_a_width, highpass_a_height, highpass_stride, a_expected;
770 int expected;
772 int count = 0, bytes;
773
774 if (!
s->a_width || !
s->a_height) {
776 goto end;
777 }
778
779 highpass_height =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].height;
780 highpass_width =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].width;
781 highpass_a_width =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].a_width;
782 highpass_a_height =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].a_height;
783 highpass_stride =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].stride;
784 a_expected = highpass_a_height * highpass_a_width;
785
786 if (!got_buffer) {
789 goto end;
790 }
791
792 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
795 goto end;
796 }
797 expected = highpass_height * highpass_stride;
798
799 av_log(avctx,
AV_LOG_DEBUG,
"Start subband coeffs plane %i level %i codebook %i expected %i\n",
s->channel_num,
s->level,
s->codebook, expected);
800
803 goto end;
804 {
806
807 const int lossless =
s->band_encoding == 5;
808
809 if (
s->codebook == 0 &&
s->transform_type == 2 &&
s->subband_num_actual == 7)
812 while (1) {
814
818
819 /* escape */
821 break;
822
824
825 if (count > expected)
826 break;
827
828 if (!lossless)
830 else
833 const uint16_t q =
s->quantisation;
834
835 for (
int i = 0;
i <
run;
i++) {
836 *coeff_data |=
coeff * 256
U;
837 *coeff_data++ *= q;
838 }
839 } else {
840 for (
int i = 0;
i <
run;
i++)
841 *coeff_data++ =
coeff;
842 }
843 }
844 } else {
845 while (1) {
847
851
852 /* escape */
854 break;
855
857
858 if (count > expected)
859 break;
860
861 if (!lossless)
863 else
866 const uint16_t q =
s->quantisation;
867
868 for (
int i = 0;
i <
run;
i++) {
869 *coeff_data |=
coeff * 256
U;
870 *coeff_data++ *= q;
871 }
872 } else {
873 for (
int i = 0;
i <
run;
i++)
874 *coeff_data++ =
coeff;
875 }
876 }
877 }
879 }
880
881 if (count > expected) {
884 goto end;
885 }
888 if (
s->difference_coding)
889 difference_coding(
s->plane[
s->channel_num].subband[
s->subband_num_actual], highpass_width, highpass_height);
890
895 goto end;
896 } else
898
899 av_log(avctx,
AV_LOG_DEBUG,
"End subband coeffs %i extra %i\n", count, count - expected);
900 s->plane[
s->channel_num].band[
s->level][
s->subband_num].read_ok = 1;
902 if (
s->subband_num_actual != 255)
904 }
905 }
906
911 }
912
914
916 s->a_transform_type == INT_MIN ||
920 goto end;
921 }
922
923 if (!got_buffer) {
926 goto end;
927 }
928
929 for (
int plane = 0; plane <
s->planes; plane++) {
931 if (
s->transform_type == 2)
933 continue;
934 for (
int o = !!
level; o < 4 ; o++) {
935 if (!
s->plane[plane].band[
level][o].read_ok) {
937 goto end;
938 }
939 }
940 }
941 }
942
943 if (
s->transform_type == 0 &&
s->sample_type != 1) {
944 for (
int plane = 0; plane <
s->planes && !
ret; plane++) {
945 /* level 1 */
946 int lowpass_height =
s->plane[plane].band[0][0].height;
947 int output_stride =
s->plane[plane].band[0][0].a_width;
948 int lowpass_width =
s->plane[plane].band[0][0].width;
949 int highpass_stride =
s->plane[plane].band[0][1].stride;
950 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
951 ptrdiff_t dst_linesize;
953
955 act_plane = 0;
956 dst_linesize = pic->
linesize[act_plane];
957 } else {
958 dst_linesize = pic->
linesize[act_plane] / 2;
959 }
960
961 if (lowpass_height >
s->plane[plane].band[0][0].a_height || lowpass_width >
s->plane[plane].band[0][0].a_width ||
962 !highpass_stride ||
s->plane[plane].band[0][1].width >
s->plane[plane].band[0][1].a_width ||
963 lowpass_width < 3 || lowpass_height < 3) {
966 goto end;
967 }
968
969 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
970
971 low =
s->plane[plane].subband[0];
972 high =
s->plane[plane].subband[2];
973 output =
s->plane[plane].l_h[0];
974 dsp->
vert_filter(
output, output_stride, low, lowpass_width,
high, highpass_stride, lowpass_width, lowpass_height);
975
976 low =
s->plane[plane].subband[1];
977 high =
s->plane[plane].subband[3];
978 output =
s->plane[plane].l_h[1];
979
980 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
981
982 low =
s->plane[plane].l_h[0];
983 high =
s->plane[plane].l_h[1];
984 output =
s->plane[plane].subband[0];
985 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, output_stride, lowpass_width, lowpass_height * 2);
987 output =
s->plane[plane].subband[0];
988 for (
int i = 0;
i < lowpass_height * 2;
i++) {
989 for (int j = 0; j < lowpass_width * 2; j++)
991
992 output += output_stride * 2;
993 }
994 }
995
996 /* level 2 */
997 lowpass_height =
s->plane[plane].band[1][1].height;
998 output_stride =
s->plane[plane].band[1][1].a_width;
999 lowpass_width =
s->plane[plane].band[1][1].width;
1000 highpass_stride =
s->plane[plane].band[1][1].stride;
1001
1002 if (lowpass_height >
s->plane[plane].band[1][1].a_height || lowpass_width >
s->plane[plane].band[1][1].a_width ||
1003 !highpass_stride ||
s->plane[plane].band[1][1].width >
s->plane[plane].band[1][1].a_width ||
1004 lowpass_width < 3 || lowpass_height < 3) {
1007 goto end;
1008 }
1009
1010 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1011
1012 low =
s->plane[plane].subband[0];
1013 high =
s->plane[plane].subband[5];
1014 output =
s->plane[plane].l_h[3];
1015 dsp->
vert_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1016
1017 low =
s->plane[plane].subband[4];
1018 high =
s->plane[plane].subband[6];
1019 output =
s->plane[plane].l_h[4];
1020 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1021
1022 low =
s->plane[plane].l_h[3];
1023 high =
s->plane[plane].l_h[4];
1024 output =
s->plane[plane].subband[0];
1025 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, output_stride, lowpass_width, lowpass_height * 2);
1026
1027 output =
s->plane[plane].subband[0];
1028 for (
int i = 0;
i < lowpass_height * 2;
i++) {
1029 for (int j = 0; j < lowpass_width * 2; j++)
1031
1032 output += output_stride * 2;
1033 }
1034
1035 /* level 3 */
1036 lowpass_height =
s->plane[plane].band[2][1].height;
1037 output_stride =
s->plane[plane].band[2][1].a_width;
1038 lowpass_width =
s->plane[plane].band[2][1].width;
1039 highpass_stride =
s->plane[plane].band[2][1].stride;
1040
1041 if (lowpass_height >
s->plane[plane].band[2][1].a_height || lowpass_width >
s->plane[plane].band[2][1].a_width ||
1042 !highpass_stride ||
s->plane[plane].band[2][1].width >
s->plane[plane].band[2][1].a_width ||
1043 lowpass_height < 3 || lowpass_width < 3 || lowpass_width * 2 >
s->plane[plane].width) {
1046 goto end;
1047 }
1048
1049 av_log(avctx,
AV_LOG_DEBUG,
"Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1050 if (
s->progressive) {
1051 low =
s->plane[plane].subband[0];
1052 high =
s->plane[plane].subband[8];
1053 output =
s->plane[plane].l_h[6];
1054 dsp->
vert_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1055
1056 low =
s->plane[plane].subband[7];
1057 high =
s->plane[plane].subband[9];
1058 output =
s->plane[plane].l_h[7];
1059 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1060
1061 dst = (int16_t *)pic->
data[act_plane];
1063 if (plane & 1)
1065 if (plane > 1)
1067 }
1068 low =
s->plane[plane].l_h[6];
1069 high =
s->plane[plane].l_h[7];
1070
1074 ) {
1076 goto end;
1077 }
1078
1079 for (
int i = 0;
i <
s->plane[act_plane].height;
i++) {
1083 low += output_stride;
1084 high += output_stride;
1085 dst += dst_linesize;
1086 }
1087 } else {
1090 low =
s->plane[plane].subband[0];
1091 high =
s->plane[plane].subband[7];
1092 output =
s->plane[plane].l_h[6];
1093 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1094
1095 low =
s->plane[plane].subband[8];
1096 high =
s->plane[plane].subband[9];
1097 output =
s->plane[plane].l_h[7];
1098 dsp->
horiz_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1099
1100 dst = (int16_t *)pic->
data[act_plane];
1101 low =
s->plane[plane].l_h[6];
1102 high =
s->plane[plane].l_h[7];
1103 for (
int i = 0;
i <
s->plane[act_plane].height / 2;
i++) {
1105 low += output_stride * 2;
1106 high += output_stride * 2;
1108 }
1109 }
1110 }
1111 }
else if (
s->transform_type == 2 && (avctx->
internal->
is_copy ||
s->frame_index == 1 ||
s->sample_type != 1)) {
1112 for (
int plane = 0; plane <
s->planes && !
ret; plane++) {
1113 int lowpass_height =
s->plane[plane].band[0][0].height;
1114 int output_stride =
s->plane[plane].band[0][0].a_width;
1115 int lowpass_width =
s->plane[plane].band[0][0].width;
1116 int highpass_stride =
s->plane[plane].band[0][1].stride;
1117 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1119 ptrdiff_t dst_linesize;
1120
1122 act_plane = 0;
1123 dst_linesize = pic->
linesize[act_plane];
1124 } else {
1125 dst_linesize = pic->
linesize[act_plane] / 2;
1126 }
1127
1128 if (lowpass_height >
s->plane[plane].band[0][0].a_height || lowpass_width >
s->plane[plane].band[0][0].a_width ||
1129 !highpass_stride ||
s->plane[plane].band[0][1].width >
s->plane[plane].band[0][1].a_width ||
1130 lowpass_width < 3 || lowpass_height < 3) {
1133 goto end;
1134 }
1135
1136 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1137
1138 low =
s->plane[plane].subband[0];
1139 high =
s->plane[plane].subband[2];
1140 output =
s->plane[plane].l_h[0];
1141 dsp->
vert_filter(
output, output_stride, low, lowpass_width,
high, highpass_stride, lowpass_width, lowpass_height);
1142
1143 low =
s->plane[plane].subband[1];
1144 high =
s->plane[plane].subband[3];
1145 output =
s->plane[plane].l_h[1];
1146 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1147
1148 low =
s->plane[plane].l_h[0];
1149 high =
s->plane[plane].l_h[1];
1150 output =
s->plane[plane].l_h[7];
1151 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, output_stride, lowpass_width, lowpass_height * 2);
1153 output =
s->plane[plane].l_h[7];
1154 for (
int i = 0;
i < lowpass_height * 2;
i++) {
1155 for (int j = 0; j < lowpass_width * 2; j++)
1157
1158 output += output_stride * 2;
1159 }
1160 }
1161
1162 lowpass_height =
s->plane[plane].band[1][1].height;
1163 output_stride =
s->plane[plane].band[1][1].a_width;
1164 lowpass_width =
s->plane[plane].band[1][1].width;
1165 highpass_stride =
s->plane[plane].band[1][1].stride;
1166
1167 if (lowpass_height >
s->plane[plane].band[1][1].a_height || lowpass_width >
s->plane[plane].band[1][1].a_width ||
1168 !highpass_stride ||
s->plane[plane].band[1][1].width >
s->plane[plane].band[1][1].a_width ||
1169 lowpass_width < 3 || lowpass_height < 3) {
1172 goto end;
1173 }
1174
1175 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 lowpass plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1176
1177 low =
s->plane[plane].l_h[7];
1178 high =
s->plane[plane].subband[5];
1179 output =
s->plane[plane].l_h[3];
1180 dsp->
vert_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1181
1182 low =
s->plane[plane].subband[4];
1183 high =
s->plane[plane].subband[6];
1184 output =
s->plane[plane].l_h[4];
1185 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1186
1187 low =
s->plane[plane].l_h[3];
1188 high =
s->plane[plane].l_h[4];
1189 output =
s->plane[plane].l_h[7];
1190 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, output_stride, lowpass_width, lowpass_height * 2);
1191
1192 output =
s->plane[plane].l_h[7];
1193 for (
int i = 0;
i < lowpass_height * 2;
i++) {
1194 for (int j = 0; j < lowpass_width * 2; j++)
1196 output += output_stride * 2;
1197 }
1198
1199 low =
s->plane[plane].subband[7];
1200 high =
s->plane[plane].subband[9];
1201 output =
s->plane[plane].l_h[3];
1202 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1203
1204 low =
s->plane[plane].subband[8];
1205 high =
s->plane[plane].subband[10];
1206 output =
s->plane[plane].l_h[4];
1207 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1208
1209 low =
s->plane[plane].l_h[3];
1210 high =
s->plane[plane].l_h[4];
1211 output =
s->plane[plane].l_h[9];
1212 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, output_stride, lowpass_width, lowpass_height * 2);
1213
1214 lowpass_height =
s->plane[plane].band[4][1].height;
1215 output_stride =
s->plane[plane].band[4][1].a_width;
1216 lowpass_width =
s->plane[plane].band[4][1].width;
1217 highpass_stride =
s->plane[plane].band[4][1].stride;
1218 av_log(avctx,
AV_LOG_DEBUG,
"temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1219
1220 if (lowpass_height >
s->plane[plane].band[4][1].a_height || lowpass_width >
s->plane[plane].band[4][1].a_width ||
1221 !highpass_stride ||
s->plane[plane].band[4][1].width >
s->plane[plane].band[4][1].a_width ||
1222 lowpass_width < 3 || lowpass_height < 3) {
1225 goto end;
1226 }
1227
1228 low =
s->plane[plane].l_h[7];
1229 high =
s->plane[plane].l_h[9];
1230 output =
s->plane[plane].l_h[7];
1231 for (
int i = 0;
i < lowpass_height;
i++) {
1233 low += output_stride;
1234 high += output_stride;
1235 }
1236 if (
s->progressive) {
1237 low =
s->plane[plane].l_h[7];
1238 high =
s->plane[plane].subband[15];
1239 output =
s->plane[plane].l_h[6];
1240 dsp->
vert_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1241
1242 low =
s->plane[plane].subband[14];
1243 high =
s->plane[plane].subband[16];
1244 output =
s->plane[plane].l_h[7];
1245 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1246
1247 low =
s->plane[plane].l_h[9];
1248 high =
s->plane[plane].subband[12];
1249 output =
s->plane[plane].l_h[8];
1250 dsp->
vert_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1251
1252 low =
s->plane[plane].subband[11];
1253 high =
s->plane[plane].subband[13];
1254 output =
s->plane[plane].l_h[9];
1255 dsp->
vert_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1256
1257 if (
s->sample_type == 1)
1258 continue;
1259
1260 dst = (int16_t *)pic->
data[act_plane];
1262 if (plane & 1)
1264 if (plane > 1)
1266 }
1267
1271 ) {
1273 goto end;
1274 }
1275
1276 low =
s->plane[plane].l_h[6];
1277 high =
s->plane[plane].l_h[7];
1278 for (
int i = 0;
i <
s->plane[act_plane].height;
i++) {
1280 low += output_stride;
1281 high += output_stride;
1282 dst += dst_linesize;
1283 }
1284 } else {
1286 low =
s->plane[plane].l_h[7];
1287 high =
s->plane[plane].subband[14];
1288 output =
s->plane[plane].l_h[6];
1289 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1290
1291 low =
s->plane[plane].subband[15];
1292 high =
s->plane[plane].subband[16];
1293 output =
s->plane[plane].l_h[7];
1294 dsp->
horiz_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1295
1296 low =
s->plane[plane].l_h[9];
1297 high =
s->plane[plane].subband[11];
1298 output =
s->plane[plane].l_h[8];
1299 dsp->
horiz_filter(
output, output_stride, low, output_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1300
1301 low =
s->plane[plane].subband[12];
1302 high =
s->plane[plane].subband[13];
1303 output =
s->plane[plane].l_h[9];
1304 dsp->
horiz_filter(
output, output_stride, low, highpass_stride,
high, highpass_stride, lowpass_width, lowpass_height);
1305
1306 if (
s->sample_type == 1)
1307 continue;
1308
1309 dst = (int16_t *)pic->
data[act_plane];
1310 low =
s->plane[plane].l_h[6];
1311 high =
s->plane[plane].l_h[7];
1312 for (
int i = 0;
i <
s->plane[act_plane].height / 2;
i++) {
1314 low += output_stride * 2;
1315 high += output_stride * 2;
1317 }
1318 }
1319 }
1320 }
1321
1322 if (
s->transform_type == 2 &&
s->sample_type == 1) {
1324 int output_stride, lowpass_height, lowpass_width;
1325 ptrdiff_t dst_linesize;
1326
1327 for (
int plane = 0; plane <
s->planes; plane++) {
1328 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1329
1331 act_plane = 0;
1332 dst_linesize = pic->
linesize[act_plane];
1333 } else {
1334 dst_linesize = pic->
linesize[act_plane] / 2;
1335 }
1336
1337 lowpass_height =
s->plane[plane].band[4][1].height;
1338 output_stride =
s->plane[plane].band[4][1].a_width;
1339 lowpass_width =
s->plane[plane].band[4][1].width;
1340
1341 if (lowpass_height >
s->plane[plane].band[4][1].a_height || lowpass_width >
s->plane[plane].band[4][1].a_width ||
1342 s->plane[plane].band[4][1].width >
s->plane[plane].band[4][1].a_width ||
1343 lowpass_width < 3 || lowpass_height < 3) {
1346 goto end;
1347 }
1348
1349 if (
s->progressive) {
1350 dst = (int16_t *)pic->
data[act_plane];
1351 low =
s->plane[plane].l_h[8];
1352 high =
s->plane[plane].l_h[9];
1353
1355 if (plane & 1)
1357 if (plane > 1)
1359 }
1360
1364 ) {
1366 goto end;
1367 }
1368
1369 for (
int i = 0;
i <
s->plane[act_plane].height;
i++) {
1371 low += output_stride;
1372 high += output_stride;
1373 dst += dst_linesize;
1374 }
1375 } else {
1376 dst = (int16_t *)pic->
data[act_plane];
1377 low =
s->plane[plane].l_h[8];
1378 high =
s->plane[plane].l_h[9];
1379 for (
int i = 0;
i <
s->plane[act_plane].height / 2;
i++) {
1381 low += output_stride * 2;
1382 high += output_stride * 2;
1384 }
1385 }
1386 }
1387 }
1388
1391 end:
1394
1395 *got_frame = 1;
1397 }
1398
1400 {
1402
1404
1405 return 0;
1406 }
1407
1408 #if HAVE_THREADS
1410 {
1414
1416 return 0;
1417
1424
1432
1441 }
1442
1443 for (
int plane = 0; plane < pdst->
planes; plane++) {
1447 }
1448
1449 return 0;
1450 }
1451 #endif
1452
1465 };