27 #define BITSTREAM_READER_LE
45 #define MAX_INDEX (64 - 1)
51 #define ALPHA_VLC_BITS 5
67 16, 16, 19, 22, 26, 27, 29, 34,
68 16, 16, 22, 24, 27, 29, 34, 37,
69 19, 22, 26, 27, 29, 34, 34, 38,
70 22, 22, 26, 27, 29, 34, 37, 40,
71 22, 26, 27, 29, 32, 35, 40, 48,
72 26, 27, 29, 32, 35, 40, 48, 58,
73 26, 27, 29, 34, 38, 46, 56, 69,
74 27, 29, 35, 38, 46, 56, 69, 83
88 if (component == 0 || component == 3) {
130 for (y = 0; y < 8; y++) {
131 for (x = 0; x < 16; x++) {
132 last_alpha[x] -=
block[y * 16 + x];
134 memcpy(dest, last_alpha, 16);
143 const int *quant_matrix =
s->quant_matrix;
144 const uint8_t *scantable =
s->permutated_intra_scantable;
148 s->bdsp.clear_block(
block);
151 last_dc[component] -= dc_offset;
152 block[scantable[0]] = last_dc[component];
175 #if MIN_CACHE_BITS < 6 + 6 + 12
176 #error MIN_CACHE_BITS is too small for the escape code, add UPDATE_CACHE
193 s->idsp.idct_put(dest, linesize,
block);
200 int linesize_y =
frame->linesize[0] * line_stride;
201 int linesize_cb =
frame->linesize[1] * line_stride;
202 int linesize_cr =
frame->linesize[2] * line_stride;
206 if (
s->alpha_type != SHQ_NO_ALPHA)
207 linesize_a =
frame->linesize[3] * line_stride;
209 for (
int y = 0; y <
frame->height; y += 16 * line_stride) {
210 int last_dc[4] = { 1024, 1024, 1024, 1024 };
211 uint8_t *dest_y, *dest_cb, *dest_cr, *dest_a;
212 uint8_t last_alpha[16];
213 int x =
frame->width - 8;
215 dest_y =
frame->data[0] +
frame->linesize[0] * (y + field_number) + x;
216 if (
s->subsampling == SHQ_SUBSAMPLING_420) {
217 dest_cb =
frame->data[1] +
frame->linesize[1] * (y/2 + field_number) + x / 2;
218 dest_cr =
frame->data[2] +
frame->linesize[2] * (y/2 + field_number) + x / 2;
221 dest_cb =
frame->data[1] +
frame->linesize[1] * (y + field_number) + x / 2;
222 dest_cr =
frame->data[2] +
frame->linesize[2] * (y + field_number) + x / 2;
224 if (
s->alpha_type != SHQ_NO_ALPHA) {
225 memset(last_alpha, 255,
sizeof(last_alpha));
226 dest_a =
frame->data[3] +
frame->linesize[3] * (y + field_number) + x;
242 if (
s->subsampling != SHQ_SUBSAMPLING_420) {
249 if (
s->alpha_type == SHQ_RLE_ALPHA) {
255 }
else if (
s->alpha_type == SHQ_DCT_ALPHA) {
273 int ret, x, y, slice_offsets[5];
275 int linesize_y =
frame->linesize[0] * line_stride;
276 int linesize_cb =
frame->linesize[1] * line_stride;
277 int linesize_cr =
frame->linesize[2] * line_stride;
281 if (
s->alpha_type != SHQ_NO_ALPHA)
282 linesize_a =
frame->linesize[3] * line_stride;
284 if (end < start || end - start < 3 || end > buf_size)
287 slice_offsets[0] = start;
288 slice_offsets[4] = end;
289 for (x = 1; x < 4; x++) {
290 uint32_t last_offset, slice_len;
292 last_offset = slice_offsets[x - 1];
293 slice_len =
AV_RL24(buf + last_offset);
294 slice_offsets[x] = last_offset + slice_len;
296 if (slice_len < 3 || slice_offsets[x] > end - 3)
300 slice_begin = slice_offsets[slice_number];
301 slice_end = slice_offsets[slice_number + 1];
306 for (y = slice_number * 16 * line_stride; y <
frame->height; y += line_stride * 64) {
307 uint8_t *dest_y, *dest_cb, *dest_cr, *dest_a;
308 int last_dc[4] = { 1024, 1024, 1024, 1024 };
309 uint8_t last_alpha[16];
311 memset(last_alpha, 255,
sizeof(last_alpha));
313 dest_y =
frame->data[0] +
frame->linesize[0] * (y + field_number);
314 if (
s->subsampling == SHQ_SUBSAMPLING_420) {
315 dest_cb =
frame->data[1] +
frame->linesize[1] * (y/2 + field_number);
316 dest_cr =
frame->data[2] +
frame->linesize[2] * (y/2 + field_number);
318 dest_cb =
frame->data[1] +
frame->linesize[1] * (y + field_number);
319 dest_cr =
frame->data[2] +
frame->linesize[2] * (y + field_number);
321 if (
s->alpha_type != SHQ_NO_ALPHA) {
322 dest_a =
frame->data[3] +
frame->linesize[3] * (y + field_number);
325 for (x = 0; x <
frame->width - 8 * (
s->subsampling != SHQ_SUBSAMPLING_444); x += 16) {
345 if (
s->subsampling != SHQ_SUBSAMPLING_420) {
352 if (
s->subsampling == SHQ_SUBSAMPLING_444) {
358 if ((
ret =
decode_dct_block(
s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb + 8, linesize_cb)) < 0)
360 if ((
ret =
decode_dct_block(
s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr + 8, linesize_cr)) < 0)
371 if (
s->alpha_type == SHQ_RLE_ALPHA) {
378 }
else if (
s->alpha_type == SHQ_DCT_ALPHA) {
393 if (
s->subsampling != SHQ_SUBSAMPLING_444 && (
frame->width & 15) && slice_number == 3)
410 int field_number = jobnr / 4;
411 int slice_number = jobnr % 4;
414 if (field_number == 0)
430 const uint8_t *buf = avpkt->
data;
431 int buf_size = avpkt->
size;
435 if (buf_size < 4 || avctx->width < 8 || avctx->
width % 8 != 0)
437 if (buf_size < avctx->
width*avctx->
height / 64 / 4)
450 s->second_field_offset =
AV_RL24(buf + 1);
451 if (
s->second_field_offset >= buf_size - 3) {
464 if (
s->second_field_offset == 4 ||
s->second_field_offset == (buf_size-4)) {
492 uint16_t run_code[134], level_code[266];
493 uint8_t
run_bits[134], level_bits[266];
494 int16_t run_symbols[134], level_symbols[266];
503 run_symbols[
entry] = 0;
507 for (
i = 0;
i < 4; ++
i) {
508 run_code[
entry] = (
i << 2) | 1;
510 run_symbols[
entry] =
i + 1;
515 for (
i = 0;
i < 128; ++
i) {
516 run_code[
entry] = (
i << 3) | 7;
525 run_symbols[
entry] = -1;
539 for (sign = 0; sign <= 1; ++sign) {
541 level_code[
entry] = (sign << 1) | 1;
542 level_bits[
entry] = 2;
543 level_symbols[
entry] = sign ? -1 : 1;
547 for (
i = 0;
i < 4; ++
i) {
548 level_code[
entry] = (
i << 3) | (sign << 2) | 2;
549 level_bits[
entry] = 5;
550 level_symbols[
entry] = sign ? -(
i + 2) : (
i + 2);
561 for (
i = 0;
i < 256; ++
i) {
562 level_code[
entry] =
i << 2;
563 level_bits[
entry] = 10;
609 s->idsp.idct_permutation);
612 case MKTAG(
'S',
'H',
'Q',
'0'):
613 s->subsampling = SHQ_SUBSAMPLING_420;
614 s->alpha_type = SHQ_NO_ALPHA;
617 case MKTAG(
'S',
'H',
'Q',
'1'):
618 s->subsampling = SHQ_SUBSAMPLING_420;
619 s->alpha_type = SHQ_RLE_ALPHA;
622 case MKTAG(
'S',
'H',
'Q',
'2'):
623 s->subsampling = SHQ_SUBSAMPLING_422;
624 s->alpha_type = SHQ_NO_ALPHA;
627 case MKTAG(
'S',
'H',
'Q',
'3'):
628 s->subsampling = SHQ_SUBSAMPLING_422;
629 s->alpha_type = SHQ_RLE_ALPHA;
632 case MKTAG(
'S',
'H',
'Q',
'4'):
633 s->subsampling = SHQ_SUBSAMPLING_444;
634 s->alpha_type = SHQ_NO_ALPHA;
637 case MKTAG(
'S',
'H',
'Q',
'5'):
638 s->subsampling = SHQ_SUBSAMPLING_444;
639 s->alpha_type = SHQ_RLE_ALPHA;
642 case MKTAG(
'S',
'H',
'Q',
'7'):
643 s->subsampling = SHQ_SUBSAMPLING_422;
644 s->alpha_type = SHQ_DCT_ALPHA;
647 case MKTAG(
'S',
'H',
'Q',
'9'):
648 s->subsampling = SHQ_SUBSAMPLING_444;
649 s->alpha_type = SHQ_DCT_ALPHA;