27 #define BITSTREAM_READER_LE
40 #define MAX_INDEX (64 - 1)
46 #define ALPHA_VLC_BITS 5
62 {0x0001, 2}, {0x0003, 3}, {0x000E, 4}, {0x0007, 5},
63 {0x0017, 5}, {0x0028, 6}, {0x0008, 6}, {0x006F, 7},
64 {0x001F, 7}, {0x00C4, 8}, {0x0044, 8}, {0x005F, 8},
65 {0x00DF, 8}, {0x007F, 8}, {0x00FF, 8}, {0x3E00, 14},
66 {0x1E00, 14}, {0x2E00, 14}, {0x0E00, 14}, {0x3600, 14},
67 {0x1600, 14}, {0x2600, 14}, {0x0600, 14}, {0x3A00, 14},
68 {0x1A00, 14}, {0x2A00, 14}, {0x0A00, 14}, {0x3200, 14},
69 {0x1200, 14}, {0x2200, 14}, {0x0200, 14}, {0x0C00, 15},
70 {0x7400, 15}, {0x3400, 15}, {0x5400, 15}, {0x1400, 15},
71 {0x6400, 15}, {0x2400, 15}, {0x4400, 15}, {0x0400, 15},
72 {0x0002, 3}, {0x000C, 5}, {0x004F, 7}, {0x00E4, 8},
73 {0x0004, 8}, {0x0D00, 13}, {0x1500, 13}, {0x7C00, 15},
74 {0x3C00, 15}, {0x5C00, 15}, {0x1C00, 15}, {0x6C00, 15},
75 {0x2C00, 15}, {0x4C00, 15}, {0xC800, 16}, {0x4800, 16},
76 {0x8800, 16}, {0x0800, 16}, {0x0300, 13}, {0x1D00, 13},
77 {0x0014, 5}, {0x0070, 7}, {0x003F, 8}, {0x00C0, 10},
78 {0x0500, 13}, {0x0180, 12}, {0x0280, 12}, {0x0C80, 12},
79 {0x0080, 12}, {0x0B00, 13}, {0x1300, 13}, {0x001C, 5},
80 {0x0064, 8}, {0x0380, 12}, {0x1900, 13}, {0x0D80, 12},
81 {0x0018, 6}, {0x00BF, 8}, {0x0480, 12}, {0x0B80, 12},
82 {0x0038, 6}, {0x0040, 9}, {0x0900, 13}, {0x0030, 7},
83 {0x0780, 12}, {0x2800, 16}, {0x0010, 7}, {0x0A80, 12},
84 {0x0050, 7}, {0x0880, 12}, {0x000F, 7}, {0x1100, 13},
85 {0x002F, 7}, {0x0100, 13}, {0x0084, 8}, {0x5800, 16},
86 {0x00A4, 8}, {0x9800, 16}, {0x0024, 8}, {0x1800, 16},
87 {0x0140, 9}, {0xE800, 16}, {0x01C0, 9}, {0x6800, 16},
88 {0x02C0, 10}, {0xA800, 16}, {0x0F80, 12}, {0x0580, 12},
89 {0x0980, 12}, {0x0E80, 12}, {0x0680, 12}, {0x1F00, 13},
90 {0x0F00, 13}, {0x1700, 13}, {0x0700, 13}, {0x1B00, 13},
91 {0xF800, 16}, {0x7800, 16}, {0xB800, 16}, {0x3800, 16},
98 1, 2, 3, 4, 5, 6, 7, 8,
99 9, 10, 11, 12, 13, 14, 15, 16,
100 17, 18, 19, 20, 21, 22, 23, 24,
101 25, 26, 27, 28, 29, 30, 31, 32,
102 33, 34, 35, 36, 37, 38, 39, 40,
103 1, 2, 3, 4, 5, 6, 7, 8,
104 9, 10, 11, 12, 13, 14, 15, 16,
105 17, 18, 19, 20, 1, 2, 3, 4,
106 5, 6, 7, 8, 9, 10, 11, 1,
107 2, 3, 4, 5, 1, 2, 3, 4,
108 1, 2, 3, 1, 2, 3, 1, 2,
109 1, 2, 1, 2, 1, 2, 1, 2,
110 1, 2, 1, 2, 1, 2, 1, 2,
111 1, 2, 1, 1, 1, 1, 1, 1,
112 1, 1, 1, 1, 1, 1, 1, 1,
117 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0,
122 1, 1, 1, 1, 1, 1, 1, 1,
123 1, 1, 1, 1, 1, 1, 1, 1,
124 1, 1, 1, 1, 2, 2, 2, 2,
125 2, 2, 2, 2, 2, 2, 2, 3,
126 3, 3, 3, 3, 4, 4, 4, 4,
127 5, 5, 5, 6, 6, 6, 7, 7,
128 8, 8, 9, 9, 10, 10, 11, 11,
129 12, 12, 13, 13, 14, 14, 15, 15,
130 16, 16, 17, 18, 19, 20, 21, 22,
131 23, 24, 25, 26, 27, 28, 29, 30,
145 16, 16, 19, 22, 26, 27, 29, 34,
146 16, 16, 22, 24, 27, 29, 34, 37,
147 19, 22, 26, 27, 29, 34, 34, 38,
148 22, 22, 26, 27, 29, 34, 37, 40,
149 22, 26, 27, 29, 32, 35, 40, 48,
150 26, 27, 29, 32, 35, 40, 48, 58,
151 26, 27, 29, 34, 38, 46, 56, 69,
152 27, 29, 35, 38, 46, 56, 69, 83
166 if (component == 0 || component == 3) {
212 for (y = 0; y < 8; y++) {
213 for (x = 0; x < 16; x++) {
214 last_alpha[x] -=
block[y * 16 + x];
216 memcpy(dest, last_alpha, 16);
225 const int *quant_matrix =
s->quant_matrix;
226 const uint8_t *scantable =
s->intra_scantable.permutated;
230 s->bdsp.clear_block(
block);
233 last_dc[component] -= dc_offset;
234 block[scantable[0]] = last_dc[component];
257 #if MIN_CACHE_BITS < 6 + 6 + 12
258 #error MIN_CACHE_BITS is too small for the escape code, add UPDATE_CACHE
275 s->idsp.idct_put(dest, linesize,
block);
282 int ret, slice_number, slice_offsets[5];
283 int linesize_y =
frame->linesize[0] * line_stride;
284 int linesize_cb =
frame->linesize[1] * line_stride;
285 int linesize_cr =
frame->linesize[2] * line_stride;
288 if (
s->alpha_type != SHQ_NO_ALPHA)
289 linesize_a =
frame->linesize[3] * line_stride;
291 if (
end < start ||
end - start < 3 || end > buf_size)
294 slice_offsets[0] = start;
295 slice_offsets[4] =
end;
296 for (slice_number = 1; slice_number < 4; slice_number++) {
297 uint32_t last_offset, slice_len;
299 last_offset = slice_offsets[slice_number - 1];
300 slice_len =
AV_RL24(buf + last_offset);
301 slice_offsets[slice_number] = last_offset + slice_len;
303 if (slice_len < 3 || slice_offsets[slice_number] >
end - 3)
307 for (slice_number = 0; slice_number < 4; slice_number++) {
312 slice_begin = slice_offsets[slice_number];
313 slice_end = slice_offsets[slice_number + 1];
318 for (y = slice_number * 16 * line_stride; y <
frame->height; y += line_stride * 64) {
319 uint8_t *dest_y, *dest_cb, *dest_cr, *dest_a;
320 int last_dc[4] = { 1024, 1024, 1024, 1024 };
323 memset(last_alpha, 255,
sizeof(last_alpha));
325 dest_y =
frame->data[0] +
frame->linesize[0] * (y + field_number);
326 if (
s->subsampling == SHQ_SUBSAMPLING_420) {
327 dest_cb =
frame->data[1] +
frame->linesize[1] * (y/2 + field_number);
328 dest_cr =
frame->data[2] +
frame->linesize[2] * (y/2 + field_number);
330 dest_cb =
frame->data[1] +
frame->linesize[1] * (y + field_number);
331 dest_cr =
frame->data[2] +
frame->linesize[2] * (y + field_number);
333 if (
s->alpha_type != SHQ_NO_ALPHA) {
334 dest_a =
frame->data[3] +
frame->linesize[3] * (y + field_number);
337 for (x = 0; x <
frame->width; x += 16) {
357 if (
s->subsampling != SHQ_SUBSAMPLING_420) {
364 if (
s->subsampling == SHQ_SUBSAMPLING_444) {
370 if ((
ret =
decode_dct_block(
s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb + 8, linesize_cb)) < 0)
372 if ((
ret =
decode_dct_block(
s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr + 8, linesize_cr)) < 0)
383 if (
s->alpha_type == SHQ_RLE_ALPHA) {
390 }
else if (
s->alpha_type == SHQ_DCT_ALPHA) {
416 void *
data,
int *got_frame,
421 int buf_size = avpkt->
size;
424 uint32_t second_field_offset;
427 if (buf_size < 4 || avctx->
width < 8)
437 second_field_offset =
AV_RL24(buf + 1);
438 if (second_field_offset >= buf_size - 3) {
448 frame->key_frame = 1;
450 if (second_field_offset == 4) {
480 uint16_t run_code[134], level_code[266];
482 int16_t run_symbols[134], level_symbols[266];
491 run_symbols[entry] = 0;
495 for (
i = 0;
i < 4; ++
i) {
496 run_code[entry] = (
i << 2) | 1;
498 run_symbols[entry] =
i + 1;
503 for (
i = 0;
i < 128; ++
i) {
504 run_code[entry] = (
i << 3) | 7;
506 run_symbols[entry] =
i;
513 run_symbols[entry] = -1;
522 run_symbols, 2, 2, 160);
527 for (sign = 0; sign <= 1; ++sign) {
529 level_code[entry] = (sign << 1) | 1;
530 level_bits[entry] = 2;
531 level_symbols[entry] = sign ? -1 : 1;
535 for (
i = 0;
i < 4; ++
i) {
536 level_code[entry] = (
i << 3) | (sign << 2) | 2;
537 level_bits[entry] = 5;
538 level_symbols[entry] = sign ? -(
i + 2) : (
i + 2);
549 for (
i = 0;
i < 256; ++
i) {
550 level_code[entry] =
i << 2;
551 level_bits[entry] = 10;
552 level_symbols[entry] =
i;
562 level_symbols, 2, 2, 288);
571 uint16_t *reversed_code,
int num_entries)
574 for (
i = 0;
i < num_entries;
i++) {
581 uint16_t ff_mpeg12_vlc_dc_lum_code_reversed[12];
582 uint16_t ff_mpeg12_vlc_dc_chroma_code_reversed[12];
587 ff_mpeg12_vlc_dc_lum_code_reversed,
591 ff_mpeg12_vlc_dc_lum_code_reversed, 2, 2, 512);
594 ff_mpeg12_vlc_dc_chroma_code_reversed,
598 ff_mpeg12_vlc_dc_chroma_code_reversed, 2, 2, 514);
623 case MKTAG(
'S',
'H',
'Q',
'0'):
624 s->subsampling = SHQ_SUBSAMPLING_420;
625 s->alpha_type = SHQ_NO_ALPHA;
628 case MKTAG(
'S',
'H',
'Q',
'1'):
629 s->subsampling = SHQ_SUBSAMPLING_420;
630 s->alpha_type = SHQ_RLE_ALPHA;
633 case MKTAG(
'S',
'H',
'Q',
'2'):
634 s->subsampling = SHQ_SUBSAMPLING_422;
635 s->alpha_type = SHQ_NO_ALPHA;
638 case MKTAG(
'S',
'H',
'Q',
'3'):
639 s->subsampling = SHQ_SUBSAMPLING_422;
640 s->alpha_type = SHQ_RLE_ALPHA;
643 case MKTAG(
'S',
'H',
'Q',
'4'):
644 s->subsampling = SHQ_SUBSAMPLING_444;
645 s->alpha_type = SHQ_NO_ALPHA;
648 case MKTAG(
'S',
'H',
'Q',
'5'):
649 s->subsampling = SHQ_SUBSAMPLING_444;
650 s->alpha_type = SHQ_RLE_ALPHA;
653 case MKTAG(
'S',
'H',
'Q',
'7'):
654 s->subsampling = SHQ_SUBSAMPLING_422;
655 s->alpha_type = SHQ_DCT_ALPHA;
658 case MKTAG(
'S',
'H',
'Q',
'9'):
659 s->subsampling = SHQ_SUBSAMPLING_444;
660 s->alpha_type = SHQ_DCT_ALPHA;