42 #define HQX_HEADER_SIZE 59
49 { 0x1, 0x2, 0x4, 0x8 }, { 0x1, 0x3, 0x6, 0xC },
50 { 0x2, 0x4, 0x8, 0x10 }, { 0x3, 0x6, 0xC, 0x18 },
51 { 0x4, 0x8, 0x10, 0x20 }, { 0x6, 0xC, 0x18, 0x30 },
52 { 0x8, 0x10, 0x20, 0x40 },
53 { 0xA, 0x14, 0x28, 0x50 },
54 { 0xC, 0x18, 0x30, 0x60 },
55 { 0x10, 0x20, 0x40, 0x80 }, { 0x18, 0x30, 0x60, 0xC0 },
56 { 0x20, 0x40, 0x80, 0x100 }, { 0x30, 0x60, 0xC0, 0x180 },
57 { 0x40, 0x80, 0x100, 0x200 }, { 0x60, 0xC0, 0x180, 0x300 },
58 { 0x80, 0x100, 0x200, 0x400 }
62 16, 16, 16, 19, 19, 19, 42, 44,
63 16, 16, 19, 19, 19, 38, 43, 45,
64 16, 19, 19, 19, 40, 41, 45, 48,
65 19, 19, 19, 40, 41, 42, 46, 49,
66 19, 19, 40, 41, 42, 43, 48, 101,
67 19, 38, 41, 42, 43, 44, 98, 104,
68 42, 43, 45, 46, 48, 98, 109, 116,
69 44, 45, 48, 49, 101, 104, 116, 123,
73 16, 16, 19, 25, 26, 26, 42, 44,
74 16, 19, 25, 25, 26, 38, 43, 91,
75 19, 25, 26, 27, 40, 41, 91, 96,
76 25, 25, 27, 40, 41, 84, 93, 197,
77 26, 26, 40, 41, 84, 86, 191, 203,
78 26, 38, 41, 84, 86, 177, 197, 209,
79 42, 43, 91, 93, 191, 197, 219, 232,
80 44, 91, 96, 197, 203, 209, 232, 246,
84 int x,
int y,
int ilace,
85 int16_t *block0, int16_t *
block1,
88 int fields = ilace ? 2 : 1;
93 lsize * fields, block0, quant);
94 ctx->
hqxdsp.
idct_put((uint16_t *)(p + (y + (ilace ? 1 : 8)) * lsize),
95 lsize * fields, block1, quant);
115 const int *quants,
int dcb,
116 int16_t
block[64],
int *last_dc)
120 int run, lev, pos = 1;
122 memset(block, 0, 64 *
sizeof(*block));
128 block[0] =
sign_extend(*last_dc << (12 - dcb), 12);
171 for (i = 0; i < 8; i++) {
172 int vlc_index = ctx->
dcb - 9;
173 if (i == 0 || i == 4 || i == 6)
176 ctx->
dcb, slice->
block[i], &last_dc);
201 for (i = 0; i < 12; i++)
202 memset(slice->
block[i], 0,
sizeof(**slice->
block) * 64);
203 for (i = 0; i < 12; i++)
204 slice->
block[i][0] = -0x800;
216 for (i = 0; i < 12; i++) {
217 if (i == 0 || i == 4 || i == 8 || i == 10)
219 if (cbp & (1 << i)) {
220 int vlc_index = ctx->
dcb - 9;
222 ctx->
dcb, slice->
block[i], &last_dc);
255 for (i = 0; i < 12; i++) {
256 int vlc_index = ctx->
dcb - 9;
257 if (i == 0 || i == 4 || i == 8)
260 ctx->
dcb, slice->
block[i], &last_dc);
287 for (i = 0; i < 16; i++)
288 memset(slice->
block[i], 0,
sizeof(**slice->
block) * 64);
289 for (i = 0; i < 16; i++)
290 slice->
block[i][0] = -0x800;
299 for (i = 0; i < 16; i++) {
300 if (i == 0 || i == 4 || i == 8 || i == 12)
302 if (cbp & (1 << i)) {
303 int vlc_index = ctx->
dcb - 9;
305 ctx->
dcb, slice->
block[i], &last_dc);
325 0, 5, 11, 14, 2, 7, 9, 13, 1, 4, 10, 15, 3, 6, 8, 12
330 int mb_w = (ctx->
width + 15) >> 4;
331 int mb_h = (ctx->
height + 15) >> 4;
332 int grp_w = (mb_w + 4) / 5;
333 int grp_h = (mb_h + 4) / 5;
334 int grp_h_edge = grp_w * (mb_w / grp_w);
335 int grp_v_edge = grp_h * (mb_h / grp_h);
336 int grp_v_rest = mb_w - grp_h_edge;
337 int grp_h_rest = mb_h - grp_v_edge;
338 int num_mbs = mb_w * mb_h;
339 int num_tiles = (num_mbs + 479) / 480;
340 int std_tile_blocks = num_mbs / (16 * num_tiles);
341 int g_tile = slice_no * num_tiles;
342 int blk_addr, loc_addr, mb_x, mb_y, pos, loc_row, i;
343 int tile_blocks, tile_limit, tile_no;
345 for (tile_no = 0; tile_no < num_tiles; tile_no++, g_tile++) {
346 tile_blocks = std_tile_blocks;
348 if (g_tile < num_mbs - std_tile_blocks * 16 * num_tiles) {
349 tile_limit = num_mbs / (16 * num_tiles);
352 for (i = 0; i < tile_blocks; i++) {
354 blk_addr = g_tile + 16 * num_tiles * i;
356 blk_addr = tile_no + 16 * num_tiles * i +
358 loc_row = grp_h * (blk_addr / (grp_h * mb_w));
359 loc_addr = blk_addr % (grp_h * mb_w);
360 if (loc_row >= grp_v_edge) {
361 mb_x = grp_w * (loc_addr / (grp_h_rest * grp_w));
362 pos = loc_addr % (grp_h_rest * grp_w);
364 mb_x = grp_w * (loc_addr / (grp_h * grp_w));
365 pos = loc_addr % (grp_h * grp_w);
367 if (mb_x >= grp_h_edge) {
368 mb_x += pos % grp_v_rest;
369 mb_y = loc_row + (pos / grp_v_rest);
372 mb_y = loc_row + (pos / grp_w);
374 ctx->
decode_func(ctx, slice_no, mb_x * 16, mb_y * 16);
382 int slice_no,
int threadnr)
389 slice_off[slice_no] >= slice_off[slice_no + 1] ||
390 slice_off[slice_no + 1] > ctx->
data_size) {
396 ctx->
src + slice_off[slice_no],
397 slice_off[slice_no + 1] - slice_off[slice_no]);
405 int *got_picture_ptr,
AVPacket *avpkt)
413 if (avpkt->
size < 4 + 4) {
419 if (info_tag ==
MKTAG(
'I',
'N',
'F',
'O')) {
420 int info_offset =
AV_RL32(src + 4);
421 if (info_offset > UINT32_MAX - 8 || info_offset + 8 > avpkt->
size) {
423 "Invalid INFO header offset: 0x%08"PRIX32
" is too large.\n",
433 data_start = src - avpkt->
data;
443 if (src[0] !=
'H' || src[1] !=
'Q') {
449 ctx->
dcb = (src[3] & 3) + 8;
452 for (i = 0; i < 17; i++)
503 *got_picture_ptr = 1;
514 for (i = 0; i < 3; i++) {
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
const char const char void * val
#define AV_PIX_FMT_YUVA422P16
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
ptrdiff_t const GLvoid * data
int coded_width
Bitstream width / height, may be different from width/height e.g.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static void hqx_get_ac(GetBitContext *gb, const HQXAC *ac, int *run, int *lev)
static av_cold int init(AVCodecContext *avctx)
int ff_canopus_parse_info_tag(AVCodecContext *avctx, const uint8_t *src, size_t size)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
mb_decode_func decode_func
int ff_hqx_init_vlcs(HQXContext *ctx)
void(* idct_put)(uint16_t *dst, ptrdiff_t stride, int16_t *block, const uint8_t *quant)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static av_cold int hqx_decode_init(AVCodecContext *avctx)
static int hqx_decode_frame(AVCodecContext *avctx, void *data, int *got_picture_ptr, AVPacket *avpkt)
const HQXAC ff_hqx_ac[NUM_HQX_AC]
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
static const uint8_t hqx_quant_luma[64]
static const int hqx_quants[16][4]
bitstream reader API header.
#define AV_PIX_FMT_YUV444P16
static const uint8_t hqx_quant_chroma[64]
static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int hqx_decode_close(AVCodecContext *avctx)
static int decode_slice(HQXContext *ctx, int slice_no)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int decode_block(GetBitContext *gb, VLC *vlc, const int *quants, int dcb, int16_t block[64], int *last_dc)
#define AV_PIX_FMT_YUVA444P16
const char * name
Name of the codec implementation.
Libavcodec external API header.
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...
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice_no, int threadnr)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
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.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
static const int shuffle_16[16]
static void skip_bits(GetBitContext *s, int n)
const uint8_t ff_zigzag_direct[64]
static av_const int sign_extend(int val, unsigned bits)
static int16_t block1[64]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
common internal api header.
static void put_blocks(HQXContext *ctx, int plane, int x, int y, int ilace, int16_t *block0, int16_t *block1, const uint8_t *quant)
av_cold void ff_hqxdsp_init(HQXDSPContext *c)
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.
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
#define MKTAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define AV_PIX_FMT_YUV422P16