27 #define BITSTREAM_READER_LE
40 #define MAX_INDEX (64 - 1)
46 #define ALPHA_VLC_BITS 5
62 {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
63 {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
64 {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
65 {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
66 {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
67 {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
68 {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
69 {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
70 {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
71 {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
72 {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
73 {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
74 {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
75 {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
76 {0x11,16}, {0x10,16}, {0x18,13}, {0x17,13},
77 {0x05, 5}, {0x07, 7}, {0xfc, 8}, {0x0c,10},
78 {0x14,13}, {0x18,12}, {0x14,12}, {0x13,12},
79 {0x10,12}, {0x1a,13}, {0x19,13}, {0x07, 5},
80 {0x26, 8}, {0x1c,12}, {0x13,13}, {0x1b,12},
81 {0x06, 6}, {0xfd, 8}, {0x12,12}, {0x1d,12},
82 {0x07, 6}, {0x04, 9}, {0x12,13}, {0x06, 7},
83 {0x1e,12}, {0x14,16}, {0x04, 7}, {0x15,12},
84 {0x05, 7}, {0x11,12}, {0x78, 7}, {0x11,13},
85 {0x7a, 7}, {0x10,13}, {0x21, 8}, {0x1a,16},
86 {0x25, 8}, {0x19,16}, {0x24, 8}, {0x18,16},
87 {0x05, 9}, {0x17,16}, {0x07, 9}, {0x16,16},
88 {0x0d,10}, {0x15,16}, {0x1f,12}, {0x1a,12},
89 {0x19,12}, {0x17,12}, {0x16,12}, {0x1f,13},
90 {0x1e,13}, {0x1d,13}, {0x1c,13}, {0x1b,13},
91 {0x1f,16}, {0x1e,16}, {0x1d,16}, {0x1c,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) {
188 memset(block, 0,
sizeof(block));
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);
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
270 block[scantable[i]] = (level * quant_matrix[i]) >> 4;
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;
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];
315 if ((ret =
init_get_bits8(&gb, buf + slice_begin + 3, slice_end - slice_begin - 3)) < 0)
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);
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);
334 dest_a = frame->
data[3] + frame->
linesize[3] * (y + field_number);
337 for (x = 0; x < frame->
width; x += 16) {
341 if ((ret =
decode_dct_block(s, &gb, last_dc, 0, dest_y + 8, linesize_y)) < 0)
343 if ((ret =
decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y, linesize_y)) < 0)
345 if ((ret =
decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y + 8, linesize_y)) < 0)
359 if ((ret =
decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb, linesize_cb)) < 0)
361 if ((ret =
decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr, linesize_cr)) < 0)
366 if ((ret =
decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8, linesize_cb)) < 0)
368 if ((ret =
decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8, linesize_cr)) < 0)
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)
387 if ((ret =
decode_alpha_block(s, &gb, last_alpha, dest_a + 8 * linesize_a, linesize_a)) < 0)
394 if ((ret =
decode_dct_block(s, &gb, last_dc, 3, dest_a + 8, linesize_a)) < 0)
396 if ((ret =
decode_dct_block(s, &gb, last_dc, 3, dest_a + 8 * linesize_a, linesize_a)) < 0)
398 if ((ret =
decode_dct_block(s, &gb, last_dc, 3, dest_a + 8 * linesize_a + 8, linesize_a)) < 0)
412 for (i = 0; i < 64; i++) output[i] = unscaled_quant_matrix[
ff_zigzag_direct[i]] * qscale;
416 void *
data,
int *got_frame,
421 int buf_size = avpkt->
size;
424 uint32_t second_field_offset;
431 if (quality >= 100) {
437 second_field_offset =
AV_RL24(buf + 1);
438 if (second_field_offset >= buf_size - 3) {
450 if (second_field_offset == 4) {
462 if ((ret =
decode_speedhq_field(s, buf, buf_size, frame, 1, second_field_offset, buf_size, 2)) < 0)
477 uint16_t run_code[134], level_code[266];
479 int16_t run_symbols[134], level_symbols[266];
488 run_symbols[entry] = 0;
492 for (i = 0; i < 4; ++i) {
493 run_code[entry] = (i << 2) | 1;
495 run_symbols[entry] = i + 1;
500 for (i = 0; i < 128; ++i) {
501 run_code[entry] = (i << 3) | 7;
502 run_bits[entry] = 10;
503 run_symbols[entry] = i;
510 run_symbols[entry] = -1;
519 run_symbols, 2, 2, 160);
524 for (sign = 0; sign <= 1; ++sign) {
526 level_code[entry] = (sign << 1) | 1;
527 level_bits[entry] = 2;
528 level_symbols[entry] = sign ? -1 : 1;
532 for (i = 0; i < 4; ++i) {
533 level_code[entry] = (i << 3) | (sign << 2) | 2;
534 level_bits[entry] = 5;
535 level_symbols[entry] = sign ? -(i + 2) : (i + 2);
546 for (i = 0; i < 256; ++i) {
547 level_code[entry] = i << 2;
548 level_bits[entry] = 10;
549 level_symbols[entry] = i;
559 level_symbols, 2, 2, 288);
568 uint16_t *reversed_code,
int num_entries)
571 for (i = 0; i < num_entries; i++) {
572 reversed_code[i] =
reverse(code[i], bits[i]);
578 uint16_t ff_mpeg12_vlc_dc_lum_code_reversed[12];
579 uint16_t ff_mpeg12_vlc_dc_chroma_code_reversed[12];
585 ff_mpeg12_vlc_dc_lum_code_reversed,
589 ff_mpeg12_vlc_dc_lum_code_reversed, 2, 2, 512);
592 ff_mpeg12_vlc_dc_chroma_code_reversed,
596 ff_mpeg12_vlc_dc_chroma_code_reversed, 2, 2, 514);
602 ff_rl_init(&ff_rl_speedhq, ff_speedhq_static_rl_table_store);
625 case MKTAG(
'S',
'H',
'Q',
'0'):
630 case MKTAG(
'S',
'H',
'Q',
'1'):
635 case MKTAG(
'S',
'H',
'Q',
'2'):
640 case MKTAG(
'S',
'H',
'Q',
'3'):
645 case MKTAG(
'S',
'H',
'Q',
'4'):
650 case MKTAG(
'S',
'H',
'Q',
'5'):
655 case MKTAG(
'S',
'H',
'Q',
'7'):
660 case MKTAG(
'S',
'H',
'Q',
'9'):
static int get_xbits_le(GetBitContext *s, int n)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static VLC ff_dc_alpha_level_vlc_le
This structure describes decoded (raw) audio or video data.
static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf_size, AVFrame *frame, int field_number, int start, int end, int line_stride)
static uint16_t speedhq_vlc[123][2]
ptrdiff_t const GLvoid * data
void(* clear_block)(int16_t *block)
int coded_width
Bitstream width / height, may be different from width/height e.g.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static av_cold int init(AVCodecContext *avctx)
static int decode_dct_block(const SHQContext *s, GetBitContext *gb, int last_dc[4], int component, uint8_t *dest, int linesize)
static const uint8_t unscaled_quant_matrix[64]
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
static int speedhq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_always_inline uint32_t bitswap_32(uint32_t x)
const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static VLC ff_dc_chroma_vlc_le
#define INIT_LE_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size)
const uint16_t ff_mpeg12_vlc_dc_lum_code[12]
static int decode_alpha_block(const SHQContext *s, GetBitContext *gb, uint8_t last_alpha[16], uint8_t *dest, int linesize)
Macro definitions for various function/variable attributes.
static int decode_dc_le(GetBitContext *gb, int component)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define INIT_2D_VLC_RL(rl, static_size, flags)
static VLC ff_dc_alpha_run_vlc_le
static uint32_t reverse(uint32_t num, int bits)
static av_cold int end(AVCodecContext *avctx)
#define INIT_LE_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
static const uint8_t run_bits[7][16]
bitstream reader API header.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
static av_cold void compute_alpha_vlcs(void)
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]
static const uint8_t speedhq_run[121]
const char * name
Name of the codec implementation.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
#define CLOSE_READER(name, gb)
#define GET_RL_VLC(level, run, name, gb, table, bits,max_depth, need_update)
static VLC ff_dc_lum_vlc_le
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define SKIP_BITS(name, gb, num)
static void compute_quant_matrix(int *output, int qscale)
int width
picture width / height.
const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]
#define LAST_SKIP_BITS(name, gb, num)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
uint8_t idct_permutation[64]
IDCT input permutation.
RL_VLC_ELEM * rl_vlc[32]
decoding only
#define SHOW_UBITS(name, gb, num)
#define FF_ARRAY_ELEMS(a)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
AVCodec ff_speedhq_decoder
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
static const uint8_t speedhq_level[121]
#define OPEN_READER(name, gb)
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
static av_cold int speedhq_decode_init(AVCodecContext *avctx)
enum AVColorSpace colorspace
YUV colorspace type.
#define UPDATE_CACHE_LE(name, gb)
const uint8_t ff_zigzag_direct[64]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define SHOW_SBITS(name, gb, num)
static uint8_t ff_speedhq_static_rl_table_store[2][2 *MAX_RUN+MAX_LEVEL+3]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
ScanTable intra_scantable
enum SHQContext::@116 subsampling
void(* idct_put)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
static int ff_thread_once(char *control, void(*routine)(void))
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
static void reverse_code(const uint16_t *code, const uint8_t *bits, uint16_t *reversed_code, int num_entries)
enum SHQContext::@117 alpha_type
#define LOCAL_ALIGNED_16(t, v,...)
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
static av_cold void speedhq_static_init(void)
#define MKTAG(a, b, c, d)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static RLTable ff_rl_speedhq