40 #define ALPHA_COMPAND_DC_OFFSET 256
41 #define ALPHA_COMPAND_GAIN 9400
49 for (
int i = 0;
i < 64;
i++) {
67 for (
int i = 0;
i < 256;
i++)
68 s->lut[1][
i] =
i + ((768LL *
i *
i *
i) / (256 * 256 * 256));
77 s->subband_num_actual = 0;
84 memset(&
s->peak.base, 0,
sizeof(
s->peak.base));
92 s->cropped_height = 0;
97 s->lowpass_precision = 16;
100 s->difference_coding = 0;
103 if (
s->transform_type != 2)
104 s->transform_type = -1;
114 return level * quantisation;
122 for (j = 1; j <
width; j++) {
123 band[j] += band[j-1];
132 for (
i = 0;
i < length;
i++)
134 band[
i] = bytestream2_get_le16(&peak->
base);
155 uint16_t *g1 = (uint16_t *)(
frame->
data[0] + 2);
158 const int mid = 1 << (bpc - 1);
159 const int factor = 1 << (16 - bpc);
172 R = (rg - mid) * 2 +
g;
175 B = (bg - mid) * 2 +
g;
196 int width,
int linesize,
int plane)
201 even = (low[
i] - high[
i])/2;
202 odd = (low[
i] + high[
i])/2;
211 int even = (low[
i] - high[
i]) / 2;
212 int odd = (low[
i] + high[
i]) / 2;
227 s->plane[
i].idwt_size = 0;
230 s->plane[
i].subband[j] =
NULL;
232 for (j = 0; j < 10; j++)
233 s->plane[
i].l_h[j] =
NULL;
244 s->a_transform_type = INT_MIN;
250 int i, j, ret,
planes, bayer = 0;
251 int chroma_x_shift, chroma_y_shift;
262 &chroma_y_shift)) < 0)
273 int w8, h8, w4, h4, w2, h2;
274 int width = (
i || bayer) ?
s->coded_width >> chroma_x_shift :
s->coded_width;
275 int height = (
i || bayer) ?
s->coded_height >> chroma_y_shift :
s->coded_height;
281 if (chroma_y_shift && !bayer)
287 w8 =
FFALIGN(
s->plane[
i].width / 8, 8) + 64;
294 if (
s->transform_type == 0) {
296 s->plane[
i].idwt_buf =
298 s->plane[
i].idwt_tmp =
299 av_calloc(
s->plane[
i].idwt_size,
sizeof(*
s->plane[
i].idwt_tmp));
302 s->plane[
i].idwt_buf =
304 s->plane[
i].idwt_tmp =
305 av_calloc(
s->plane[
i].idwt_size,
sizeof(*
s->plane[
i].idwt_tmp));
308 if (!
s->plane[
i].idwt_buf || !
s->plane[
i].idwt_tmp)
311 s->plane[
i].subband[0] =
s->plane[
i].idwt_buf;
312 s->plane[
i].subband[1] =
s->plane[
i].idwt_buf + 2 * w8 * h8;
313 s->plane[
i].subband[2] =
s->plane[
i].idwt_buf + 1 * w8 * h8;
314 s->plane[
i].subband[3] =
s->plane[
i].idwt_buf + 3 * w8 * h8;
315 s->plane[
i].subband[4] =
s->plane[
i].idwt_buf + 2 * w4 * h4;
316 s->plane[
i].subband[5] =
s->plane[
i].idwt_buf + 1 * w4 * h4;
317 s->plane[
i].subband[6] =
s->plane[
i].idwt_buf + 3 * w4 * h4;
318 if (
s->transform_type == 0) {
319 s->plane[
i].subband[7] =
s->plane[
i].idwt_buf + 2 * w2 * h2;
320 s->plane[
i].subband[8] =
s->plane[
i].idwt_buf + 1 * w2 * h2;
321 s->plane[
i].subband[9] =
s->plane[
i].idwt_buf + 3 * w2 * h2;
324 s->plane[
i].subband[7] =
s->plane[
i].idwt_buf + 4 * w2 * h2;
325 s->plane[
i].subband[8] = frame2 + 2 * w4 * h4;
326 s->plane[
i].subband[9] = frame2 + 1 * w4 * h4;
327 s->plane[
i].subband[10] = frame2 + 3 * w4 * h4;
328 s->plane[
i].subband[11] = frame2 + 2 * w2 * h2;
329 s->plane[
i].subband[12] = frame2 + 1 * w2 * h2;
330 s->plane[
i].subband[13] = frame2 + 3 * w2 * h2;
331 s->plane[
i].subband[14] =
s->plane[
i].idwt_buf + 2 * w2 * h2;
332 s->plane[
i].subband[15] =
s->plane[
i].idwt_buf + 1 * w2 * h2;
333 s->plane[
i].subband[16] =
s->plane[
i].idwt_buf + 3 * w2 * h2;
336 if (
s->transform_type == 0) {
339 s->plane[
i].band[j][k].a_width = w8 << j;
340 s->plane[
i].band[j][k].a_height = h8 << j;
345 int t = j < 1 ? 0 : (j < 3 ? 1 : 2);
348 s->plane[
i].band[j][k].a_width = w8 << t;
349 s->plane[
i].band[j][k].a_height = h8 << t;
355 s->plane[
i].l_h[0] =
s->plane[
i].idwt_tmp;
356 s->plane[
i].l_h[1] =
s->plane[
i].idwt_tmp + 2 * w8 * h8;
358 s->plane[
i].l_h[3] =
s->plane[
i].idwt_tmp;
359 s->plane[
i].l_h[4] =
s->plane[
i].idwt_tmp + 2 * w4 * h4;
361 s->plane[
i].l_h[6] =
s->plane[
i].idwt_tmp;
362 s->plane[
i].l_h[7] =
s->plane[
i].idwt_tmp + 2 * w2 * h2;
363 if (
s->transform_type != 0) {
364 int16_t *frame2 =
s->plane[
i].idwt_tmp + 4 * w2 * h2;
366 s->plane[
i].l_h[8] = frame2;
367 s->plane[
i].l_h[9] = frame2 + 2 * w2 * h2;
371 s->a_transform_type =
s->transform_type;
372 s->a_height =
s->coded_height;
373 s->a_width =
s->coded_width;
374 s->a_format =
s->coded_format;
387 int ret = 0,
i, j, plane, got_buffer = 0;
397 uint16_t tagu = bytestream2_get_be16(&gb);
398 int16_t
tag = (int16_t)tagu;
399 int8_t tag8 = (int8_t)(tagu >> 8);
400 uint16_t abstag =
abs(
tag);
401 int8_t abs_tag8 =
abs(tag8);
402 uint16_t
data = bytestream2_get_be16(&gb);
403 if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
407 s->progressive =
data & 0x0001;
409 s->frame_type =
data;
419 }
else if (abstag ==
Version) {
423 s->coded_width =
data;
426 s->coded_height =
data;
429 s->channel_cnt =
data;
443 s->channel_num =
data;
447 if (
s->subband_num != 0 &&
data == 1 && (
s->transform_type == 0 ||
s->transform_type == 2))
450 s->subband_num =
data;
451 if ((
s->transform_type == 0 &&
s->level >=
DWT_LEVELS) ||
457 if (
s->subband_num > 3) {
470 if (
s->transform_type == 0 ||
s->transform_type == 2)
471 s->subband_num_actual =
data;
477 s->quantisation =
data;
480 for (
i = 0;
i < 8;
i++)
481 s->prescale_table[
i] = (
data >> (14 -
i * 2)) & 0x3;
489 s->band_encoding =
data;
493 s->plane[
s->channel_num].band[0][0].width =
data;
494 s->plane[
s->channel_num].band[0][0].stride =
data;
497 s->plane[
s->channel_num].band[0][0].height =
data;
499 s->sample_type =
data;
506 }
else if (
data == 1) {
511 if (
s->transform_type == -1) {
512 s->transform_type =
data;
517 }
else if (abstag >= 0x4000 && abstag <= 0x40ff) {
518 if (abstag == 0x4001)
524 s->frame_index =
data;
533 uint32_t
offset = bytestream2_get_be32(&gb);
537 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);
543 s->plane[
s->channel_num].band[
s->level][
s->subband_num].width =
data;
544 s->plane[
s->channel_num].band[
s->level][
s->subband_num].stride =
FFALIGN(
data, 8);
552 s->plane[
s->channel_num].band[
s->level][
s->subband_num].height =
data;
560 s->plane[
s->channel_num].band[
s->level][
s->subband_num].width =
data;
561 s->plane[
s->channel_num].band[
s->level][
s->subband_num].stride =
FFALIGN(
data, 8);
569 s->plane[
s->channel_num].band[
s->level][
s->subband_num].height =
data;
576 }
else if (
data >= 122 &&
data <= 128) {
578 }
else if (
data == 30) {
586 s->codebook =
data & 0xf;
587 s->difference_coding = (
data >> 4) & 1;
601 }
else if (
data == 2) {
603 }
else if (
data == 3) {
605 }
else if (
data == 4) {
615 s->cropped_height =
data;
617 s->peak.offset &= ~0xffff;
618 s->peak.offset |= (
data & 0xffff);
622 s->peak.offset &= 0xffff;
623 s->peak.offset |= (
data & 0xffffU)<<16;
627 s->peak.level =
data;
638 if (
s->channel_num >=
s->planes) {
644 if (got_buffer && (
s->coded_width ||
s->coded_height ||
s->coded_format !=
AV_PIX_FMT_NONE)) {
652 int lowpass_height =
s->plane[
s->channel_num].band[0][0].height;
653 int lowpass_width =
s->plane[
s->channel_num].band[0][0].width;
656 if (
s->coded_width) {
660 if (
s->coded_height) {
664 if (!
s->a_width && !
s->coded_width) {
665 s->coded_width = lowpass_width *
factor * 8;
668 if (!
s->a_height && !
s->coded_height) {
669 s->coded_height = lowpass_height *
factor * 8;
672 if (
s->a_width && !
s->coded_width)
673 s->coded_width =
s->a_width;
674 if (
s->a_height && !
s->coded_height)
675 s->coded_height =
s->a_height;
677 if (
s->a_width !=
s->coded_width ||
s->a_height !=
s->coded_height ||
678 s->a_format !=
s->coded_format ||
679 s->transform_type !=
s->a_transform_type) {
690 if (
s->cropped_height) {
725 if (
s->subband_num_actual == 255)
729 if (
s->transform_type !=
s->a_transform_type)
732 coeff_data =
s->plane[
s->channel_num].subband[
s->subband_num_actual];
736 int lowpass_height, lowpass_width, lowpass_a_height, lowpass_a_width;
738 if (!
s->a_width || !
s->a_height) {
743 lowpass_height =
s->plane[
s->channel_num].band[0][0].height;
744 lowpass_width =
s->plane[
s->channel_num].band[0][0].width;
745 lowpass_a_height =
s->plane[
s->channel_num].band[0][0].a_height;
746 lowpass_a_width =
s->plane[
s->channel_num].band[0][0].a_width;
748 if (lowpass_width < 3 ||
749 lowpass_width > lowpass_a_width) {
755 if (lowpass_height < 3 ||
756 lowpass_height > lowpass_a_height) {
768 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
775 av_log(avctx,
AV_LOG_DEBUG,
"Start of lowpass coeffs component %d height:%d, width:%d\n",
s->channel_num, lowpass_height, lowpass_width);
776 for (
i = 0;
i < lowpass_height;
i++) {
777 for (j = 0; j < lowpass_width; j++)
778 coeff_data[j] = bytestream2_get_be16u(&gb);
780 coeff_data += lowpass_width;
787 if (lowpass_height & 1) {
788 memcpy(&coeff_data[lowpass_height * lowpass_width],
789 &coeff_data[(lowpass_height - 1) * lowpass_width],
790 lowpass_width *
sizeof(*coeff_data));
793 s->plane[
s->channel_num].band[0][0].read_ok = 1;
795 av_log(avctx,
AV_LOG_DEBUG,
"Lowpass coefficients %d\n", lowpass_width * lowpass_height);
800 int highpass_height, highpass_width, highpass_a_width, highpass_a_height, highpass_stride, a_expected;
803 int count = 0, bytes;
805 if (!
s->a_width || !
s->a_height) {
810 highpass_height =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].height;
811 highpass_width =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].width;
812 highpass_a_width =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].a_width;
813 highpass_a_height =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].a_height;
814 highpass_stride =
s->plane[
s->channel_num].band[
s->level][
s->subband_num].stride;
815 a_expected = highpass_a_height * highpass_a_width;
823 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
828 expected = highpass_height * highpass_stride;
830 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);
838 const int lossless =
s->band_encoding == 5;
840 if (
s->codebook == 0 &&
s->transform_type == 2 &&
s->subband_num_actual == 7)
854 if (count > expected)
862 const uint16_t q =
s->quantisation;
864 for (
i = 0;
i <
run;
i++) {
865 *coeff_data |=
coeff * 256U;
870 *coeff_data++ =
coeff;
885 if (count > expected)
893 const uint16_t q =
s->quantisation;
895 for (
i = 0;
i <
run;
i++) {
896 *coeff_data |=
coeff * 256U;
901 *coeff_data++ =
coeff;
908 if (count > expected) {
915 if (
s->difference_coding)
916 difference_coding(
s->plane[
s->channel_num].subband[
s->subband_num_actual], highpass_width, highpass_height);
926 av_log(avctx,
AV_LOG_DEBUG,
"End subband coeffs %i extra %i\n", count, count - expected);
927 s->plane[
s->channel_num].band[
s->level][
s->subband_num].read_ok = 1;
929 if (
s->subband_num_actual != 255)
943 s->a_transform_type == INT_MIN) {
955 for (plane = 0; plane <
s->planes; plane++) {
959 if (
s->transform_type == 2)
962 for (o = !!
level; o < 4 ; o++) {
963 if (!
s->plane[plane].band[
level][o].read_ok) {
971 if (
s->transform_type == 0 &&
s->sample_type != 1) {
972 for (plane = 0; plane <
s->planes && !ret; plane++) {
974 int lowpass_height =
s->plane[plane].band[0][0].height;
975 int output_stride =
s->plane[plane].band[0][0].a_width;
976 int lowpass_width =
s->plane[plane].band[0][0].width;
977 int highpass_stride =
s->plane[plane].band[0][1].stride;
978 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
979 ptrdiff_t dst_linesize;
980 int16_t *low, *high, *output, *dst;
984 dst_linesize = pic->
linesize[act_plane];
986 dst_linesize = pic->
linesize[act_plane] / 2;
989 if (lowpass_height >
s->plane[plane].band[0][0].a_height || lowpass_width >
s->plane[plane].band[0][0].a_width ||
990 !highpass_stride ||
s->plane[plane].band[0][1].width >
s->plane[plane].band[0][1].a_width ||
991 lowpass_width < 3 || lowpass_height < 3) {
997 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
999 low =
s->plane[plane].subband[0];
1000 high =
s->plane[plane].subband[2];
1001 output =
s->plane[plane].l_h[0];
1002 dsp->
vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
1004 low =
s->plane[plane].subband[1];
1005 high =
s->plane[plane].subband[3];
1006 output =
s->plane[plane].l_h[1];
1008 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1010 low =
s->plane[plane].l_h[0];
1011 high =
s->plane[plane].l_h[1];
1012 output =
s->plane[plane].subband[0];
1013 dsp->
horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1015 output =
s->plane[plane].subband[0];
1016 for (
i = 0;
i < lowpass_height * 2;
i++) {
1017 for (j = 0; j < lowpass_width * 2; j++)
1020 output += output_stride * 2;
1025 lowpass_height =
s->plane[plane].band[1][1].height;
1026 output_stride =
s->plane[plane].band[1][1].a_width;
1027 lowpass_width =
s->plane[plane].band[1][1].width;
1028 highpass_stride =
s->plane[plane].band[1][1].stride;
1030 if (lowpass_height >
s->plane[plane].band[1][1].a_height || lowpass_width >
s->plane[plane].band[1][1].a_width ||
1031 !highpass_stride ||
s->plane[plane].band[1][1].width >
s->plane[plane].band[1][1].a_width ||
1032 lowpass_width < 3 || lowpass_height < 3) {
1038 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1040 low =
s->plane[plane].subband[0];
1041 high =
s->plane[plane].subband[5];
1042 output =
s->plane[plane].l_h[3];
1043 dsp->
vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1045 low =
s->plane[plane].subband[4];
1046 high =
s->plane[plane].subband[6];
1047 output =
s->plane[plane].l_h[4];
1048 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1050 low =
s->plane[plane].l_h[3];
1051 high =
s->plane[plane].l_h[4];
1052 output =
s->plane[plane].subband[0];
1053 dsp->
horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1055 output =
s->plane[plane].subband[0];
1056 for (
i = 0;
i < lowpass_height * 2;
i++) {
1057 for (j = 0; j < lowpass_width * 2; j++)
1060 output += output_stride * 2;
1064 lowpass_height =
s->plane[plane].band[2][1].height;
1065 output_stride =
s->plane[plane].band[2][1].a_width;
1066 lowpass_width =
s->plane[plane].band[2][1].width;
1067 highpass_stride =
s->plane[plane].band[2][1].stride;
1069 if (lowpass_height >
s->plane[plane].band[2][1].a_height || lowpass_width >
s->plane[plane].band[2][1].a_width ||
1070 !highpass_stride ||
s->plane[plane].band[2][1].width >
s->plane[plane].band[2][1].a_width ||
1071 lowpass_height < 3 || lowpass_width < 3 || lowpass_width * 2 >
s->plane[plane].width) {
1077 av_log(avctx,
AV_LOG_DEBUG,
"Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1078 if (
s->progressive) {
1079 low =
s->plane[plane].subband[0];
1080 high =
s->plane[plane].subband[8];
1081 output =
s->plane[plane].l_h[6];
1082 dsp->
vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1084 low =
s->plane[plane].subband[7];
1085 high =
s->plane[plane].subband[9];
1086 output =
s->plane[plane].l_h[7];
1087 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1089 dst = (int16_t *)pic->
data[act_plane];
1094 dst += pic->
linesize[act_plane] >> 1;
1096 low =
s->plane[plane].l_h[6];
1097 high =
s->plane[plane].l_h[7];
1107 for (
i = 0;
i <
s->plane[act_plane].height;
i++) {
1111 low += output_stride;
1112 high += output_stride;
1113 dst += dst_linesize;
1118 low =
s->plane[plane].subband[0];
1119 high =
s->plane[plane].subband[7];
1120 output =
s->plane[plane].l_h[6];
1121 dsp->
horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1123 low =
s->plane[plane].subband[8];
1124 high =
s->plane[plane].subband[9];
1125 output =
s->plane[plane].l_h[7];
1126 dsp->
horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1128 dst = (int16_t *)pic->
data[act_plane];
1129 low =
s->plane[plane].l_h[6];
1130 high =
s->plane[plane].l_h[7];
1131 for (
i = 0;
i <
s->plane[act_plane].height / 2;
i++) {
1133 low += output_stride * 2;
1134 high += output_stride * 2;
1139 }
else if (
s->transform_type == 2 && (avctx->
internal->
is_copy ||
s->frame_index == 1 ||
s->sample_type != 1)) {
1140 for (plane = 0; plane <
s->planes && !ret; plane++) {
1141 int lowpass_height =
s->plane[plane].band[0][0].height;
1142 int output_stride =
s->plane[plane].band[0][0].a_width;
1143 int lowpass_width =
s->plane[plane].band[0][0].width;
1144 int highpass_stride =
s->plane[plane].band[0][1].stride;
1145 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1146 int16_t *low, *high, *output, *dst;
1147 ptrdiff_t dst_linesize;
1151 dst_linesize = pic->
linesize[act_plane];
1153 dst_linesize = pic->
linesize[act_plane] / 2;
1156 if (lowpass_height >
s->plane[plane].band[0][0].a_height || lowpass_width >
s->plane[plane].band[0][0].a_width ||
1157 !highpass_stride ||
s->plane[plane].band[0][1].width >
s->plane[plane].band[0][1].a_width ||
1158 lowpass_width < 3 || lowpass_height < 3) {
1164 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1166 low =
s->plane[plane].subband[0];
1167 high =
s->plane[plane].subband[2];
1168 output =
s->plane[plane].l_h[0];
1169 dsp->
vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
1171 low =
s->plane[plane].subband[1];
1172 high =
s->plane[plane].subband[3];
1173 output =
s->plane[plane].l_h[1];
1174 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1176 low =
s->plane[plane].l_h[0];
1177 high =
s->plane[plane].l_h[1];
1178 output =
s->plane[plane].l_h[7];
1179 dsp->
horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1181 output =
s->plane[plane].l_h[7];
1182 for (
i = 0;
i < lowpass_height * 2;
i++) {
1183 for (j = 0; j < lowpass_width * 2; j++)
1186 output += output_stride * 2;
1190 lowpass_height =
s->plane[plane].band[1][1].height;
1191 output_stride =
s->plane[plane].band[1][1].a_width;
1192 lowpass_width =
s->plane[plane].band[1][1].width;
1193 highpass_stride =
s->plane[plane].band[1][1].stride;
1195 if (lowpass_height >
s->plane[plane].band[1][1].a_height || lowpass_width >
s->plane[plane].band[1][1].a_width ||
1196 !highpass_stride ||
s->plane[plane].band[1][1].width >
s->plane[plane].band[1][1].a_width ||
1197 lowpass_width < 3 || lowpass_height < 3) {
1203 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 lowpass plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1205 low =
s->plane[plane].l_h[7];
1206 high =
s->plane[plane].subband[5];
1207 output =
s->plane[plane].l_h[3];
1208 dsp->
vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1210 low =
s->plane[plane].subband[4];
1211 high =
s->plane[plane].subband[6];
1212 output =
s->plane[plane].l_h[4];
1213 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1215 low =
s->plane[plane].l_h[3];
1216 high =
s->plane[plane].l_h[4];
1217 output =
s->plane[plane].l_h[7];
1218 dsp->
horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1220 output =
s->plane[plane].l_h[7];
1221 for (
i = 0;
i < lowpass_height * 2;
i++) {
1222 for (j = 0; j < lowpass_width * 2; j++)
1224 output += output_stride * 2;
1227 low =
s->plane[plane].subband[7];
1228 high =
s->plane[plane].subband[9];
1229 output =
s->plane[plane].l_h[3];
1230 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1232 low =
s->plane[plane].subband[8];
1233 high =
s->plane[plane].subband[10];
1234 output =
s->plane[plane].l_h[4];
1235 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1237 low =
s->plane[plane].l_h[3];
1238 high =
s->plane[plane].l_h[4];
1239 output =
s->plane[plane].l_h[9];
1240 dsp->
horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1242 lowpass_height =
s->plane[plane].band[4][1].height;
1243 output_stride =
s->plane[plane].band[4][1].a_width;
1244 lowpass_width =
s->plane[plane].band[4][1].width;
1245 highpass_stride =
s->plane[plane].band[4][1].stride;
1246 av_log(avctx,
AV_LOG_DEBUG,
"temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1248 if (lowpass_height >
s->plane[plane].band[4][1].a_height || lowpass_width >
s->plane[plane].band[4][1].a_width ||
1249 !highpass_stride ||
s->plane[plane].band[4][1].width >
s->plane[plane].band[4][1].a_width ||
1250 lowpass_width < 3 || lowpass_height < 3 || lowpass_width * 2 >
s->plane[plane].width) {
1256 low =
s->plane[plane].l_h[7];
1257 high =
s->plane[plane].l_h[9];
1258 output =
s->plane[plane].l_h[7];
1259 for (
i = 0;
i < lowpass_height;
i++) {
1261 low += output_stride;
1262 high += output_stride;
1264 if (
s->progressive) {
1265 low =
s->plane[plane].l_h[7];
1266 high =
s->plane[plane].subband[15];
1267 output =
s->plane[plane].l_h[6];
1268 dsp->
vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1270 low =
s->plane[plane].subband[14];
1271 high =
s->plane[plane].subband[16];
1272 output =
s->plane[plane].l_h[7];
1273 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1275 low =
s->plane[plane].l_h[9];
1276 high =
s->plane[plane].subband[12];
1277 output =
s->plane[plane].l_h[8];
1278 dsp->
vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1280 low =
s->plane[plane].subband[11];
1281 high =
s->plane[plane].subband[13];
1282 output =
s->plane[plane].l_h[9];
1283 dsp->
vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1285 if (
s->sample_type == 1)
1288 dst = (int16_t *)pic->
data[act_plane];
1293 dst += pic->
linesize[act_plane] >> 1;
1304 low =
s->plane[plane].l_h[6];
1305 high =
s->plane[plane].l_h[7];
1306 for (
i = 0;
i <
s->plane[act_plane].height;
i++) {
1308 low += output_stride;
1309 high += output_stride;
1310 dst += dst_linesize;
1314 low =
s->plane[plane].l_h[7];
1315 high =
s->plane[plane].subband[14];
1316 output =
s->plane[plane].l_h[6];
1317 dsp->
horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1319 low =
s->plane[plane].subband[15];
1320 high =
s->plane[plane].subband[16];
1321 output =
s->plane[plane].l_h[7];
1322 dsp->
horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1324 low =
s->plane[plane].l_h[9];
1325 high =
s->plane[plane].subband[11];
1326 output =
s->plane[plane].l_h[8];
1327 dsp->
horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1329 low =
s->plane[plane].subband[12];
1330 high =
s->plane[plane].subband[13];
1331 output =
s->plane[plane].l_h[9];
1332 dsp->
horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1334 if (
s->sample_type == 1)
1337 dst = (int16_t *)pic->
data[act_plane];
1338 low =
s->plane[plane].l_h[6];
1339 high =
s->plane[plane].l_h[7];
1340 for (
i = 0;
i <
s->plane[act_plane].height / 2;
i++) {
1342 low += output_stride * 2;
1343 high += output_stride * 2;
1350 if (
s->transform_type == 2 &&
s->sample_type == 1) {
1351 int16_t *low, *high, *dst;
1352 int output_stride, lowpass_height, lowpass_width;
1353 ptrdiff_t dst_linesize;
1355 for (plane = 0; plane <
s->planes; plane++) {
1356 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1360 dst_linesize = pic->
linesize[act_plane];
1362 dst_linesize = pic->
linesize[act_plane] / 2;
1365 lowpass_height =
s->plane[plane].band[4][1].height;
1366 output_stride =
s->plane[plane].band[4][1].a_width;
1367 lowpass_width =
s->plane[plane].band[4][1].width;
1369 if (lowpass_height >
s->plane[plane].band[4][1].a_height || lowpass_width >
s->plane[plane].band[4][1].a_width ||
1370 s->plane[plane].band[4][1].width >
s->plane[plane].band[4][1].a_width ||
1371 lowpass_width < 3 || lowpass_height < 3 || lowpass_width * 2 >
s->plane[plane].width) {
1377 if (
s->progressive) {
1378 dst = (int16_t *)pic->
data[act_plane];
1379 low =
s->plane[plane].l_h[8];
1380 high =
s->plane[plane].l_h[9];
1386 dst += pic->
linesize[act_plane] >> 1;
1397 for (
i = 0;
i <
s->plane[act_plane].height;
i++) {
1399 low += output_stride;
1400 high += output_stride;
1401 dst += dst_linesize;
1404 dst = (int16_t *)pic->
data[act_plane];
1405 low =
s->plane[plane].l_h[8];
1406 high =
s->plane[plane].l_h[9];
1407 for (
i = 0;
i <
s->plane[act_plane].height / 2;
i++) {
1409 low += output_stride * 2;
1410 high += output_stride * 2;
1477 for (
int plane = 0; plane < pdst->
planes; plane++) {
static double val(void *priv, double ch)
Macro definitions for various function/variable attributes.
static av_always_inline int even(uint64_t layout)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
void ff_free_vlc(VLC *vlc)
refcounted data buffer API
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static void difference_coding(int16_t *band, int width, int height)
static av_cold int cfhd_init(AVCodecContext *avctx)
static void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high, int width, int linesize, int plane)
static void inverse_temporal_filter(int16_t *low, int16_t *high, int width)
#define ALPHA_COMPAND_GAIN
static void init_plane_defaults(CFHDContext *s)
static void process_alpha(int16_t *alpha, int width)
static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int alloc_buffers(AVCodecContext *avctx)
static void init_frame_defaults(CFHDContext *s)
#define ALPHA_COMPAND_DC_OFFSET
static void process_bayer(AVFrame *frame, int bpc)
static void peak_table(int16_t *band, Peak *peak, int length)
static av_cold int cfhd_close(AVCodecContext *avctx)
static void init_peak_table_defaults(CFHDContext *s)
static void free_buffers(CFHDContext *s)
static int dequant_and_decompand(CFHDContext *s, int level, int quantisation, int codebook)
int ff_cfhd_init_vlcs(CFHDContext *s)
av_cold void ff_cfhddsp_init(CFHDDSPContext *c, int depth, int bayer)
static const unsigned codebook[256][2]
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
channel
Use these values when setting the channel map with ebur128_set_channel().
FrameType
G723.1 frame types.
bitstream reader API header.
#define CLOSE_READER(name, gb)
#define OPEN_READER(name, gb)
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
#define UPDATE_CACHE(name, gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
static const int16_t alpha[]
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
static const struct @323 planes[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_BAYER_RGGB16
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int64_t max_pixels
The number of pixels per image to maximally accept.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int coded_width
Bitstream width / height, may be different from width/height e.g.
struct AVCodecInternal * internal
Private context used for internal data.
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int interlaced_frame
The content of the picture is interlaced.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
enum AVPixelFormat coded_format
void(* horiz_filter_clip)(int16_t *output, const int16_t *low, const int16_t *high, int width, int bpc)
void(* vert_filter)(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int width, int height)
void(* horiz_filter)(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int width, int height)
SubBand band[DWT_LEVELS_3D][4]
static const double coeff[2][5]
static const int factor[16]
static const uint8_t offset[127][2]