51 int slice_no,
int x,
int y);
77#define HQX_HEADER_SIZE 59
79#define AC_IDX(q) ((q) >= 128 ? HQX_AC_Q128 : (q) >= 64 ? HQX_AC_Q64 : \
80 (q) >= 32 ? HQX_AC_Q32 : (q) >= 16 ? HQX_AC_Q16 : \
81 (q) >= 8 ? HQX_AC_Q8 : HQX_AC_Q0)
89#define Q(q) ((unsigned)AC_IDX(q) << 29 | (q))
90 {
Q( 0x1),
Q( 0x2),
Q( 0x4),
Q( 0x8) }, {
Q( 0x1),
Q( 0x3),
Q( 0x6),
Q( 0xC) },
91 {
Q( 0x2),
Q( 0x4),
Q( 0x8),
Q( 0x10) }, {
Q( 0x3),
Q( 0x6),
Q( 0xC),
Q( 0x18) },
92 {
Q( 0x4),
Q( 0x8),
Q( 0x10),
Q( 0x20) }, {
Q( 0x6),
Q( 0xC),
Q( 0x18),
Q( 0x30) },
93 {
Q( 0x8),
Q( 0x10),
Q( 0x20),
Q( 0x40) },
94 {
Q(0xA),
Q(0x14),
Q(0x28),
Q(0x50) },
95 {
Q( 0xC),
Q(0x18),
Q( 0x30),
Q( 0x60) },
96 {
Q(0x10),
Q( 0x20),
Q( 0x40),
Q( 0x80) }, {
Q(0x18),
Q(0x30),
Q( 0x60),
Q( 0xC0) },
97 {
Q(0x20),
Q( 0x40),
Q( 0x80),
Q(0x100) }, {
Q(0x30),
Q(0x60),
Q( 0xC0),
Q(0x180) },
98 {
Q(0x40),
Q( 0x80),
Q(0x100),
Q(0x200) }, {
Q(0x60),
Q(0xC0),
Q(0x180),
Q(0x300) },
99 {
Q(0x80),
Q(0x100),
Q(0x200),
Q(0x400) }
103 16, 16, 16, 19, 19, 19, 42, 44,
104 16, 16, 19, 19, 19, 38, 43, 45,
105 16, 19, 19, 19, 40, 41, 45, 48,
106 19, 19, 19, 40, 41, 42, 46, 49,
107 19, 19, 40, 41, 42, 43, 48, 101,
108 19, 38, 41, 42, 43, 44, 98, 104,
109 42, 43, 45, 46, 48, 98, 109, 116,
110 44, 45, 48, 49, 101, 104, 116, 123,
114 16, 16, 19, 25, 26, 26, 42, 44,
115 16, 19, 25, 25, 26, 38, 43, 91,
116 19, 25, 26, 27, 40, 41, 91, 96,
117 25, 25, 27, 40, 41, 84, 93, 197,
118 26, 26, 40, 41, 84, 86, 191, 203,
119 26, 38, 41, 84, 86, 177, 197, 209,
120 42, 43, 91, 93, 191, 197, 219, 232,
121 44, 91, 96, 197, 203, 209, 232, 246,
125 int x,
int y,
int ilace,
126 int16_t *block0, int16_t *
block1,
127 const uint8_t *
quant)
129 int fields = ilace ? 2 : 1;
130 int lsize =
ctx->pic->linesize[plane];
131 uint8_t *p =
ctx->pic->data[plane] + x * 2;
133 ctx->hqxdsp.idct_put((uint16_t *)(p + y * lsize),
134 lsize * fields, block0,
quant);
135 ctx->hqxdsp.idct_put((uint16_t *)(p + (y + (ilace ? 1 : 8)) * lsize),
153 const unsigned *quants,
int dcb,
154 int16_t
block[64],
int *last_dc)
185 const unsigned *quants;
190 memset(slice->
block, 0,
sizeof(*slice->
block) * 8);
199 for (
i = 0;
i < 8;
i++) {
200 if (
i == 0 ||
i == 4 ||
i == 6)
224 memset(slice->
block, 0,
sizeof(*slice->
block) * 12);
225 for (
i = 0;
i < 12;
i++)
226 slice->
block[
i][0] = -0x800;
230 const unsigned *quants;
241 for (
i = 0;
i < 12;
i++) {
242 if (
i == 0 ||
i == 4 ||
i == 8 ||
i == 10)
244 if (cbp & (1 <<
i)) {
267 const unsigned *quants;
272 memset(slice->
block, 0,
sizeof(*slice->
block) * 12);
281 for (
i = 0;
i < 12;
i++) {
308 memset(slice->
block, 0,
sizeof(*slice->
block) * 16);
309 for (
i = 0;
i < 16;
i++)
310 slice->
block[
i][0] = -0x800;
314 const unsigned *quants;
322 for (
i = 0;
i < 16;
i++) {
325 if (cbp & (1 <<
i)) {
347 0, 5, 11, 14, 2, 7, 9, 13, 1, 4, 10, 15, 3, 6, 8, 12
352 int mb_w = (
ctx->width + 15) >> 4;
353 int mb_h = (
ctx->height + 15) >> 4;
354 int grp_w = (mb_w + 4) / 5;
355 int grp_h = (mb_h + 4) / 5;
356 int grp_h_edge = grp_w * (mb_w / grp_w);
357 int grp_v_edge = grp_h * (mb_h / grp_h);
358 int grp_v_rest = mb_w - grp_h_edge;
359 int grp_h_rest = mb_h - grp_v_edge;
360 int num_mbs = mb_w * mb_h;
361 int num_tiles = (num_mbs + 479) / 480;
362 int std_tile_blocks = num_mbs / (16 * num_tiles);
363 int g_tile = slice_no * num_tiles;
364 int blk_addr, loc_addr, mb_x, mb_y,
pos, loc_row,
i;
365 int tile_blocks, tile_limit, tile_no;
367 for (tile_no = 0; tile_no < num_tiles; tile_no++, g_tile++) {
368 tile_blocks = std_tile_blocks;
370 if (g_tile < num_mbs - std_tile_blocks * 16 * num_tiles) {
371 tile_limit = num_mbs / (16 * num_tiles);
374 for (
i = 0;
i < tile_blocks;
i++) {
376 blk_addr = g_tile + 16 * num_tiles *
i;
378 blk_addr = tile_no + 16 * num_tiles *
i +
380 loc_row = grp_h * (blk_addr / (grp_h * mb_w));
381 loc_addr = blk_addr % (grp_h * mb_w);
382 if (loc_row >= grp_v_edge) {
383 mb_x = grp_w * (loc_addr / (grp_h_rest * grp_w));
384 pos = loc_addr % (grp_h_rest * grp_w);
386 mb_x = grp_w * (loc_addr / (grp_h * grp_w));
387 pos = loc_addr % (grp_h * grp_w);
389 if (mb_x >= grp_h_edge) {
390 mb_x +=
pos % grp_v_rest;
391 mb_y = loc_row + (
pos / grp_v_rest);
394 mb_y = loc_row + (
pos / grp_w);
396 ctx->decode_func(
ctx, slice_no, mb_x * 16, mb_y * 16);
404 int slice_no,
int threadnr)
407 uint32_t *slice_off =
ctx->slice_off;
411 slice_off[slice_no] >= slice_off[slice_no + 1] ||
412 slice_off[slice_no + 1] >
ctx->data_size) {
418 ctx->src + slice_off[slice_no],
419 slice_off[slice_no + 1] - slice_off[slice_no]);
427 int *got_picture_ptr,
AVPacket *avpkt)
430 const uint8_t *
src = avpkt->
data;
432 int data_start, dcb_code;
435 if (avpkt->
size < 4 + 4) {
441 if (info_tag ==
MKTAG(
'I',
'N',
'F',
'O')) {
443 if (info_offset > INT_MAX || info_offset + 8 > avpkt->
size) {
445 "Invalid INFO header offset: 0x%08"PRIX32
" is too large.\n",
455 data_start =
src - avpkt->
data;
456 ctx->data_size = avpkt->
size - data_start;
465 if (
src[0] !=
'H' ||
src[1] !=
'Q') {
469 ctx->interlaced = !(
src[2] & 0x80);
471 dcb_code =
src[3] & 3;
474 for (
i = 0;
i < 17;
i++)
481 ctx->dc_vlc = dcb_code == 3 ?
ctx->dc11_vlc.table :
dc_vlc[dcb_code - 1];
482 ctx->dcb = dcb_code + 8;
504 switch (
ctx->format) {
532 *got_picture_ptr = 1;
const FFCodec ff_hqx_decoder
Libavcodec external API header.
int ff_canopus_parse_info_tag(AVCodecContext *avctx, const uint8_t *src, size_t size)
#define i(width, name, range_min, range_max)
static LevelCodes lev[4+3+3]
static VLCElem dc_vlc[1104]
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int16_t block1[64]
int(* init)(AVBSFContext *ctx)
reference-counted frame API
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
#define CLOSE_READER(name, gb)
static unsigned int get_bits1(GetBitContext *s)
#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 unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
const VLCElem ff_hq_cbp_vlc[1<< HQ_CBP_VLC_BITS]
static int decode_slice(HQXContext *ctx, int slice_no)
static const unsigned hqx_quants[16][4]
static const uint8_t hqx_quant_luma[64]
int(* mb_decode_func)(struct HQXContext *ctx, int slice_no, int x, int y)
static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice_no, int threadnr)
static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
static void put_blocks(HQXContext *ctx, int plane, int x, int y, int ilace, int16_t *block0, int16_t *block1, const uint8_t *quant)
static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
static const int shuffle_16[16]
static int decode_block(GetBitContext *gb, const VLCElem vlc[], const unsigned *quants, int dcb, int16_t block[64], int *last_dc)
static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
static av_cold int hqx_decode_close(AVCodecContext *avctx)
static const uint8_t hqx_quant_chroma[64]
static int hqx_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_picture_ptr, AVPacket *avpkt)
static void hqx_get_ac(GetBitContext *gb, const HQXAC *ac, int *runp, int *lev)
static av_cold int hqx_decode_init(AVCodecContext *avctx)
av_cold void ff_hqxdsp_init(HQXDSPContext *c)
av_unused static av_cold void hqx_init_static(void)
static const uint16_t dc11_vlc_bits[2048]
static HQXAC hqx_ac[NUM_HQX_AC]
static const uint8_t dc11_vlc_lens[2048]
Multithreading API for decoders.
static int ff_thread_once(char *control, void(*routine)(void))
#define MKTAG(a, b, c, d)
const uint8_t ff_zigzag_direct[64]
static av_const int sign_extend(int val, unsigned bits)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUV444P16
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
int coded_width
Bitstream width / height, may be different from width/height e.g.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
mb_decode_func decode_func
static AVFormatContext * ctx
void ff_vlc_free(VLC *vlc)
#define vlc_init(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
static const uint8_t quant[64]