27 #define BITSTREAM_READER_LE
44 #define MAX_INDEX (64 - 1)
50 #define ALPHA_VLC_BITS 5
64 16, 16, 19, 22, 26, 27, 29, 34,
65 16, 16, 22, 24, 27, 29, 34, 37,
66 19, 22, 26, 27, 29, 34, 34, 38,
67 22, 22, 26, 27, 29, 34, 37, 40,
68 22, 26, 27, 29, 32, 35, 40, 48,
69 26, 27, 29, 32, 35, 40, 48, 58,
70 26, 27, 29, 34, 38, 46, 56, 69,
71 27, 29, 35, 38, 46, 56, 69, 83
85 if (component == 0 || component == 3) {
127 for (y = 0; y < 8; y++) {
128 for (x = 0; x < 16; x++) {
129 last_alpha[x] -=
block[y * 16 + x];
131 memcpy(dest, last_alpha, 16);
140 const int *quant_matrix =
s->quant_matrix;
141 const uint8_t *scantable =
s->permutated_intra_scantable;
145 s->bdsp.clear_block(
block);
148 last_dc[component] -= dc_offset;
149 block[scantable[0]] = last_dc[component];
172 #if MIN_CACHE_BITS < 6 + 6 + 12
173 #error MIN_CACHE_BITS is too small for the escape code, add UPDATE_CACHE
190 s->idsp.idct_put(dest, linesize,
block);
197 int linesize_y =
frame->linesize[0] * line_stride;
198 int linesize_cb =
frame->linesize[1] * line_stride;
199 int linesize_cr =
frame->linesize[2] * line_stride;
203 if (
s->alpha_type != SHQ_NO_ALPHA)
204 linesize_a =
frame->linesize[3] * line_stride;
206 for (
int y = 0; y <
frame->height; y += 16 * line_stride) {
207 int last_dc[4] = { 1024, 1024, 1024, 1024 };
208 uint8_t *dest_y, *dest_cb, *dest_cr, *dest_a;
209 uint8_t last_alpha[16];
210 int x =
frame->width - 8;
212 dest_y =
frame->data[0] +
frame->linesize[0] * (y + field_number) + x;
213 if (
s->subsampling == SHQ_SUBSAMPLING_420) {
214 dest_cb =
frame->data[1] +
frame->linesize[1] * (y/2 + field_number) + x / 2;
215 dest_cr =
frame->data[2] +
frame->linesize[2] * (y/2 + field_number) + x / 2;
218 dest_cb =
frame->data[1] +
frame->linesize[1] * (y + field_number) + x / 2;
219 dest_cr =
frame->data[2] +
frame->linesize[2] * (y + field_number) + x / 2;
221 if (
s->alpha_type != SHQ_NO_ALPHA) {
222 memset(last_alpha, 255,
sizeof(last_alpha));
223 dest_a =
frame->data[3] +
frame->linesize[3] * (y + field_number) + x;
239 if (
s->subsampling != SHQ_SUBSAMPLING_420) {
246 if (
s->alpha_type == SHQ_RLE_ALPHA) {
252 }
else if (
s->alpha_type == SHQ_DCT_ALPHA) {
270 int ret, slice_number, slice_offsets[5];
271 int linesize_y =
frame->linesize[0] * line_stride;
272 int linesize_cb =
frame->linesize[1] * line_stride;
273 int linesize_cr =
frame->linesize[2] * line_stride;
277 if (
s->alpha_type != SHQ_NO_ALPHA)
278 linesize_a =
frame->linesize[3] * line_stride;
280 if (end < start || end - start < 3 || end > buf_size)
283 slice_offsets[0] = start;
284 slice_offsets[4] = end;
285 for (slice_number = 1; slice_number < 4; slice_number++) {
286 uint32_t last_offset, slice_len;
288 last_offset = slice_offsets[slice_number - 1];
289 slice_len =
AV_RL24(buf + last_offset);
290 slice_offsets[slice_number] = last_offset + slice_len;
292 if (slice_len < 3 || slice_offsets[slice_number] > end - 3)
296 for (slice_number = 0; slice_number < 4; slice_number++) {
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) {
394 if (
s->subsampling != SHQ_SUBSAMPLING_444 && (
frame->width & 15))
410 const uint8_t *buf = avpkt->
data;
411 int buf_size = avpkt->
size;
413 uint32_t second_field_offset;
416 if (buf_size < 4 || avctx->width < 8 || avctx->
width % 8 != 0)
418 if (buf_size < avctx->
width*avctx->
height / 64 / 4)
428 second_field_offset =
AV_RL24(buf + 1);
429 if (second_field_offset >= buf_size - 3) {
439 frame->key_frame = 1;
441 if (second_field_offset == 4 || second_field_offset == (buf_size-4)) {
471 uint16_t run_code[134], level_code[266];
472 uint8_t
run_bits[134], level_bits[266];
473 int16_t run_symbols[134], level_symbols[266];
482 run_symbols[entry] = 0;
486 for (
i = 0;
i < 4; ++
i) {
487 run_code[entry] = (
i << 2) | 1;
489 run_symbols[entry] =
i + 1;
494 for (
i = 0;
i < 128; ++
i) {
495 run_code[entry] = (
i << 3) | 7;
497 run_symbols[entry] =
i;
504 run_symbols[entry] = -1;
513 run_symbols, 2, 2, 160);
518 for (sign = 0; sign <= 1; ++sign) {
520 level_code[entry] = (sign << 1) | 1;
521 level_bits[entry] = 2;
522 level_symbols[entry] = sign ? -1 : 1;
526 for (
i = 0;
i < 4; ++
i) {
527 level_code[entry] = (
i << 3) | (sign << 2) | 2;
528 level_bits[entry] = 5;
529 level_symbols[entry] = sign ? -(
i + 2) : (
i + 2);
540 for (
i = 0;
i < 256; ++
i) {
541 level_code[entry] =
i << 2;
542 level_bits[entry] = 10;
543 level_symbols[entry] =
i;
553 level_symbols, 2, 2, 288);
588 s->idsp.idct_permutation);
591 case MKTAG(
'S',
'H',
'Q',
'0'):
592 s->subsampling = SHQ_SUBSAMPLING_420;
593 s->alpha_type = SHQ_NO_ALPHA;
596 case MKTAG(
'S',
'H',
'Q',
'1'):
597 s->subsampling = SHQ_SUBSAMPLING_420;
598 s->alpha_type = SHQ_RLE_ALPHA;
601 case MKTAG(
'S',
'H',
'Q',
'2'):
602 s->subsampling = SHQ_SUBSAMPLING_422;
603 s->alpha_type = SHQ_NO_ALPHA;
606 case MKTAG(
'S',
'H',
'Q',
'3'):
607 s->subsampling = SHQ_SUBSAMPLING_422;
608 s->alpha_type = SHQ_RLE_ALPHA;
611 case MKTAG(
'S',
'H',
'Q',
'4'):
612 s->subsampling = SHQ_SUBSAMPLING_444;
613 s->alpha_type = SHQ_NO_ALPHA;
616 case MKTAG(
'S',
'H',
'Q',
'5'):
617 s->subsampling = SHQ_SUBSAMPLING_444;
618 s->alpha_type = SHQ_RLE_ALPHA;
621 case MKTAG(
'S',
'H',
'Q',
'7'):
622 s->subsampling = SHQ_SUBSAMPLING_422;
623 s->alpha_type = SHQ_DCT_ALPHA;
626 case MKTAG(
'S',
'H',
'Q',
'9'):
627 s->subsampling = SHQ_SUBSAMPLING_444;
628 s->alpha_type = SHQ_DCT_ALPHA;