FFmpeg
Loading...
Searching...
No Matches
hqx.c
Go to the documentation of this file.
1/*
2 * Canopus HQX decoder
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <inttypes.h>
22
23#include "libavutil/frame.h"
24#include "libavutil/imgutils.h"
27#include "libavutil/thread.h"
28
29#include "avcodec.h"
30#include "canopus.h"
31#include "codec_internal.h"
32#include "get_bits.h"
33#include "thread.h"
34#include "vlc.h"
35
36#include "hqxdsp.h"
37#include "hqxvlc.h"
38#include "hq_common.h"
39
40/* HQX has four modes - 422, 444, 422alpha and 444alpha - all 12-bit */
47
48struct HQXContext;
49
50typedef int (*mb_decode_func)(struct HQXContext *ctx,
51 int slice_no, int x, int y);
52
53typedef struct HQXSlice {
55 DECLARE_ALIGNED(16, int16_t, block)[16][64];
56} HQXSlice;
57
58typedef struct HQXContext {
61
64
67
68 const uint8_t *src;
69 unsigned int data_size;
70 uint32_t slice_off[17];
71
73
76
77#define HQX_HEADER_SIZE 59
78
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)
82
83/* macroblock selects a group of 4 possible quants and
84 * a block can use any of those four quantisers
85 * one column is powers of 2, the other one is powers of 2 * 3,
86 * then there is the special one, powers of 2 * 5.
87 * We also encode the corresponding AC index in these tables in bits 29-31. */
88static const unsigned hqx_quants[16][4] = {
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) }
100};
101
102static const uint8_t hqx_quant_luma[64] = {
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,
111};
112
113static const uint8_t hqx_quant_chroma[64] = {
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,
122};
123
124static inline void put_blocks(HQXContext *ctx, int plane,
125 int x, int y, int ilace,
126 int16_t *block0, int16_t *block1,
127 const uint8_t *quant)
128{
129 int fields = ilace ? 2 : 1;
130 int lsize = ctx->pic->linesize[plane];
131 uint8_t *p = ctx->pic->data[plane] + x * 2;
132
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),
136 lsize * fields, block1, quant);
137}
138
139static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac,
140 int *runp, int *lev)
141{
142 int level, run;
143 OPEN_READER(re, gb);
144
145 UPDATE_CACHE(re, gb);
146 GET_RL_VLC(level, run, re, gb, ac->lut, ac->bits, 2, 0);
147 CLOSE_READER(re, gb);
148 *runp = run;
149 *lev = level;
150}
151
152static int decode_block(GetBitContext *gb, const VLCElem vlc[],
153 const unsigned *quants, int dcb,
154 int16_t block[64], int *last_dc)
155{
156 int run, lev, pos = 0;
157 unsigned ac_idx, q;
158 int dc;
159
160 dc = get_vlc2(gb, vlc, HQX_DC_VLC_BITS, 2);
161 *last_dc += dc;
162
163 block[0] = sign_extend(*last_dc << (12 - dcb), 12);
164
165 q = quants[get_bits(gb, 2)];
166 // ac_idx is encoded in the high bits of quants;
167 // because block is 16 bit, we do not even need to clear said bits.
168 ac_idx = q >> 29;
169
170 do {
171 hqx_get_ac(gb, &hqx_ac[ac_idx], &run, &lev);
172 pos += run;
173 if (pos > 63)
174 break;
176 } while (pos < 63);
177
178 return 0;
179}
180
181static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
182{
183 HQXSlice *slice = &ctx->slice[slice_no];
184 GetBitContext *gb = &slice->gb;
185 const unsigned *quants;
186 int flag;
187 int last_dc;
188 int i, ret;
189
190 memset(slice->block, 0, sizeof(*slice->block) * 8);
191
192 if (ctx->interlaced)
193 flag = get_bits1(gb);
194 else
195 flag = 0;
196
197 quants = hqx_quants[get_bits(gb, 4)];
198
199 for (i = 0; i < 8; i++) {
200 if (i == 0 || i == 4 || i == 6)
201 last_dc = 0;
202 ret = decode_block(gb, ctx->dc_vlc, quants,
203 ctx->dcb, slice->block[i], &last_dc);
204 if (ret < 0)
205 return ret;
206 }
207
208 put_blocks(ctx, 0, x, y, flag, slice->block[0], slice->block[2], hqx_quant_luma);
209 put_blocks(ctx, 0, x + 8, y, flag, slice->block[1], slice->block[3], hqx_quant_luma);
210 put_blocks(ctx, 2, x >> 1, y, flag, slice->block[4], slice->block[5], hqx_quant_chroma);
211 put_blocks(ctx, 1, x >> 1, y, flag, slice->block[6], slice->block[7], hqx_quant_chroma);
212
213 return 0;
214}
215
216static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
217{
218 HQXSlice *slice = &ctx->slice[slice_no];
219 GetBitContext *gb = &slice->gb;
220 int flag = 0;
221 int last_dc;
222 int i, ret;
223
224 memset(slice->block, 0, sizeof(*slice->block) * 12);
225 for (i = 0; i < 12; i++)
226 slice->block[i][0] = -0x800;
227
228 int cbp = get_vlc2(gb, ff_hq_cbp_vlc, HQ_CBP_VLC_BITS, 1);
229 if (cbp) {
230 const unsigned *quants;
231
232 if (ctx->interlaced)
233 flag = get_bits1(gb);
234
235 quants = hqx_quants[get_bits(gb, 4)];
236
237 if (cbp & 0x3) // chroma CBP - top
238 cbp |= 0x500;
239 if (cbp & 0xC) // chroma CBP - bottom
240 cbp |= 0xA00;
241 for (i = 0; i < 12; i++) {
242 if (i == 0 || i == 4 || i == 8 || i == 10)
243 last_dc = 0;
244 if (cbp & (1 << i)) {
245 ret = decode_block(gb, ctx->dc_vlc, quants,
246 ctx->dcb, slice->block[i], &last_dc);
247 if (ret < 0)
248 return ret;
249 }
250 }
251 }
252
253 put_blocks(ctx, 3, x, y, flag, slice->block[ 0], slice->block[ 2], hqx_quant_luma);
254 put_blocks(ctx, 3, x + 8, y, flag, slice->block[ 1], slice->block[ 3], hqx_quant_luma);
255 put_blocks(ctx, 0, x, y, flag, slice->block[ 4], slice->block[ 6], hqx_quant_luma);
256 put_blocks(ctx, 0, x + 8, y, flag, slice->block[ 5], slice->block[ 7], hqx_quant_luma);
257 put_blocks(ctx, 2, x >> 1, y, flag, slice->block[ 8], slice->block[ 9], hqx_quant_chroma);
258 put_blocks(ctx, 1, x >> 1, y, flag, slice->block[10], slice->block[11], hqx_quant_chroma);
259
260 return 0;
261}
262
263static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
264{
265 HQXSlice *slice = &ctx->slice[slice_no];
266 GetBitContext *gb = &slice->gb;
267 const unsigned *quants;
268 int flag;
269 int last_dc;
270 int i, ret;
271
272 memset(slice->block, 0, sizeof(*slice->block) * 12);
273
274 if (ctx->interlaced)
275 flag = get_bits1(gb);
276 else
277 flag = 0;
278
279 quants = hqx_quants[get_bits(gb, 4)];
280
281 for (i = 0; i < 12; i++) {
282 if (!(i & 3))
283 last_dc = 0;
284 ret = decode_block(gb, ctx->dc_vlc, quants,
285 ctx->dcb, slice->block[i], &last_dc);
286 if (ret < 0)
287 return ret;
288 }
289
290 put_blocks(ctx, 0, x, y, flag, slice->block[0], slice->block[ 2], hqx_quant_luma);
291 put_blocks(ctx, 0, x + 8, y, flag, slice->block[1], slice->block[ 3], hqx_quant_luma);
292 put_blocks(ctx, 2, x, y, flag, slice->block[4], slice->block[ 6], hqx_quant_chroma);
293 put_blocks(ctx, 2, x + 8, y, flag, slice->block[5], slice->block[ 7], hqx_quant_chroma);
294 put_blocks(ctx, 1, x, y, flag, slice->block[8], slice->block[10], hqx_quant_chroma);
295 put_blocks(ctx, 1, x + 8, y, flag, slice->block[9], slice->block[11], hqx_quant_chroma);
296
297 return 0;
298}
299
300static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
301{
302 HQXSlice *slice = &ctx->slice[slice_no];
303 GetBitContext *gb = &slice->gb;
304 int flag = 0;
305 int last_dc;
306 int i, ret;
307
308 memset(slice->block, 0, sizeof(*slice->block) * 16);
309 for (i = 0; i < 16; i++)
310 slice->block[i][0] = -0x800;
311
312 int cbp = get_vlc2(gb, ff_hq_cbp_vlc, HQ_CBP_VLC_BITS, 1);
313 if (cbp) {
314 const unsigned *quants;
315
316 if (ctx->interlaced)
317 flag = get_bits1(gb);
318
319 quants = hqx_quants[get_bits(gb, 4)];
320
321 cbp |= cbp << 8; // chroma CBP
322 for (i = 0; i < 16; i++) {
323 if (!(i & 3))
324 last_dc = 0;
325 if (cbp & (1 << i)) {
326 ret = decode_block(gb, ctx->dc_vlc, quants,
327 ctx->dcb, slice->block[i], &last_dc);
328 if (ret < 0)
329 return ret;
330 }
331 }
332 }
333
334 put_blocks(ctx, 3, x, y, flag, slice->block[ 0], slice->block[ 2], hqx_quant_luma);
335 put_blocks(ctx, 3, x + 8, y, flag, slice->block[ 1], slice->block[ 3], hqx_quant_luma);
336 put_blocks(ctx, 0, x, y, flag, slice->block[ 4], slice->block[ 6], hqx_quant_luma);
337 put_blocks(ctx, 0, x + 8, y, flag, slice->block[ 5], slice->block[ 7], hqx_quant_luma);
338 put_blocks(ctx, 2, x, y, flag, slice->block[ 8], slice->block[10], hqx_quant_chroma);
339 put_blocks(ctx, 2, x + 8, y, flag, slice->block[ 9], slice->block[11], hqx_quant_chroma);
340 put_blocks(ctx, 1, x, y, flag, slice->block[12], slice->block[14], hqx_quant_chroma);
341 put_blocks(ctx, 1, x + 8, y, flag, slice->block[13], slice->block[15], hqx_quant_chroma);
342
343 return 0;
344}
345
346static const int shuffle_16[16] = {
347 0, 5, 11, 14, 2, 7, 9, 13, 1, 4, 10, 15, 3, 6, 8, 12
348};
349
350static int decode_slice(HQXContext *ctx, int slice_no)
351{
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;
366
367 for (tile_no = 0; tile_no < num_tiles; tile_no++, g_tile++) {
368 tile_blocks = std_tile_blocks;
369 tile_limit = -1;
370 if (g_tile < num_mbs - std_tile_blocks * 16 * num_tiles) {
371 tile_limit = num_mbs / (16 * num_tiles);
372 tile_blocks++;
373 }
374 for (i = 0; i < tile_blocks; i++) {
375 if (i == tile_limit)
376 blk_addr = g_tile + 16 * num_tiles * i;
377 else
378 blk_addr = tile_no + 16 * num_tiles * i +
379 num_tiles * shuffle_16[(i + slice_no) & 0xF];
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);
385 } else {
386 mb_x = grp_w * (loc_addr / (grp_h * grp_w));
387 pos = loc_addr % (grp_h * grp_w);
388 }
389 if (mb_x >= grp_h_edge) {
390 mb_x += pos % grp_v_rest;
391 mb_y = loc_row + (pos / grp_v_rest);
392 } else {
393 mb_x += pos % grp_w;
394 mb_y = loc_row + (pos / grp_w);
395 }
396 ctx->decode_func(ctx, slice_no, mb_x * 16, mb_y * 16);
397 }
398 }
399
400 return 0;
401}
402
403static int decode_slice_thread(AVCodecContext *avctx, void *arg,
404 int slice_no, int threadnr)
405{
406 HQXContext *ctx = avctx->priv_data;
407 uint32_t *slice_off = ctx->slice_off;
408 int ret;
409
410 if (slice_off[slice_no] < HQX_HEADER_SIZE ||
411 slice_off[slice_no] >= slice_off[slice_no + 1] ||
412 slice_off[slice_no + 1] > ctx->data_size) {
413 av_log(avctx, AV_LOG_ERROR, "Invalid slice size %d.\n", ctx->data_size);
414 return AVERROR_INVALIDDATA;
415 }
416
417 ret = init_get_bits8(&ctx->slice[slice_no].gb,
418 ctx->src + slice_off[slice_no],
419 slice_off[slice_no + 1] - slice_off[slice_no]);
420 if (ret < 0)
421 return ret;
422
423 return decode_slice(ctx, slice_no);
424}
425
427 int *got_picture_ptr, AVPacket *avpkt)
428{
429 HQXContext *ctx = avctx->priv_data;
430 const uint8_t *src = avpkt->data;
431 uint32_t info_tag;
432 int data_start, dcb_code;
433 int i, ret;
434
435 if (avpkt->size < 4 + 4) {
436 av_log(avctx, AV_LOG_ERROR, "Frame is too small %d.\n", avpkt->size);
437 return AVERROR_INVALIDDATA;
438 }
439
440 info_tag = AV_RL32(src);
441 if (info_tag == MKTAG('I', 'N', 'F', 'O')) {
442 uint32_t info_offset = AV_RL32(src + 4);
443 if (info_offset > INT_MAX || info_offset + 8 > avpkt->size) {
444 av_log(avctx, AV_LOG_ERROR,
445 "Invalid INFO header offset: 0x%08"PRIX32" is too large.\n",
446 info_offset);
447 return AVERROR_INVALIDDATA;
448 }
449 ff_canopus_parse_info_tag(avctx, src + 8, info_offset);
450
451 info_offset += 8;
452 src += info_offset;
453 }
454
455 data_start = src - avpkt->data;
456 ctx->data_size = avpkt->size - data_start;
457 ctx->src = src;
458 ctx->pic = frame;
459
460 if (ctx->data_size < HQX_HEADER_SIZE) {
461 av_log(avctx, AV_LOG_ERROR, "Frame too small.\n");
462 return AVERROR_INVALIDDATA;
463 }
464
465 if (src[0] != 'H' || src[1] != 'Q') {
466 av_log(avctx, AV_LOG_ERROR, "Not an HQX frame.\n");
467 return AVERROR_INVALIDDATA;
468 }
469 ctx->interlaced = !(src[2] & 0x80);
470 ctx->format = src[2] & 7;
471 dcb_code = src[3] & 3;
472 ctx->width = AV_RB16(src + 4);
473 ctx->height = AV_RB16(src + 6);
474 for (i = 0; i < 17; i++)
475 ctx->slice_off[i] = AV_RB24(src + 8 + i * 3);
476
477 if (dcb_code == 0) {
478 av_log(avctx, AV_LOG_ERROR, "Invalid DC precision 8.\n");
479 return AVERROR_INVALIDDATA;
480 }
481 ctx->dc_vlc = dcb_code == 3 ? ctx->dc11_vlc.table : dc_vlc[dcb_code - 1];
482 ctx->dcb = dcb_code + 8;
483 ret = av_image_check_size(ctx->width, ctx->height, 0, avctx);
484 if (ret < 0) {
485 av_log(avctx, AV_LOG_ERROR, "Invalid stored dimensions %dx%d.\n",
486 ctx->width, ctx->height);
487 return AVERROR_INVALIDDATA;
488 }
489
490 avctx->coded_width = FFALIGN(ctx->width, 16);
491 avctx->coded_height = FFALIGN(ctx->height, 16);
492 avctx->width = ctx->width;
493 avctx->height = ctx->height;
494 avctx->bits_per_raw_sample = 10;
495
496 //The minimum size is 2bit per macroblock
497 // hqx_decode_422 & hqx_decode_444 have a unconditionally stored 4bits hqx_quants index
498 // hqx_decode_422a & hqx_decode_444a use cbp_vlc which has a minimum length of 2 bits for its VLCs
499 // The code rejects slices overlapping in their input data
500 if (avctx->coded_width / 16 * (avctx->coded_height / 16) *
501 (100 - avctx->discard_damaged_percentage) / 100 > 4LL * avpkt->size)
502 return AVERROR_INVALIDDATA;
503
504 switch (ctx->format) {
505 case HQX_422:
507 ctx->decode_func = hqx_decode_422;
508 break;
509 case HQX_444:
511 ctx->decode_func = hqx_decode_444;
512 break;
513 case HQX_422A:
515 ctx->decode_func = hqx_decode_422a;
516 break;
517 case HQX_444A:
519 ctx->decode_func = hqx_decode_444a;
520 break;
521 default:
522 av_log(avctx, AV_LOG_ERROR, "Invalid format: %d.\n", ctx->format);
523 return AVERROR_INVALIDDATA;
524 }
525
526 ret = ff_thread_get_buffer(avctx, frame, 0);
527 if (ret < 0)
528 return ret;
529
530 avctx->execute2(avctx, decode_slice_thread, NULL, NULL, 16);
531
532 *got_picture_ptr = 1;
533
534 return avpkt->size;
535}
536
538{
539 HQXContext *ctx = avctx->priv_data;
540
541 ff_vlc_free(&ctx->dc11_vlc);
542
543 return 0;
544}
545
547{
548 static AVOnce init_static_once = AV_ONCE_INIT;
549 HQXContext *ctx = avctx->priv_data;
551 dc11_vlc_lens, 1, 1, dc11_vlc_bits, 2, 2, 0);
552
553 if (ret < 0)
554 return ret;
555
556 ff_hqxdsp_init(&ctx->hqxdsp);
557
558 ff_thread_once(&init_static_once, hqx_init_static);
559
560 return 0;
561}
562
564 .p.name = "hqx",
565 CODEC_LONG_NAME("Canopus HQX"),
566 .p.type = AVMEDIA_TYPE_VIDEO,
567 .p.id = AV_CODEC_ID_HQX,
568 .priv_data_size = sizeof(HQXContext),
571 .close = hqx_decode_close,
572 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS |
574 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
575};
const FFCodec ff_hqx_decoder
Definition hqx.c:563
Libavcodec external API header.
int ff_canopus_parse_info_tag(AVCodecContext *avctx, const uint8_t *src, size_t size)
Definition canopus.c:30
#define flag(name)
Definition cbs_h264.c:60
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static LevelCodes lev[4+3+3]
Definition clearvideo.c:80
static VLCElem dc_vlc[1104]
Definition clearvideo.c:79
#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...
#define NULL
Definition coverity.c:32
static int16_t block[64]
Definition dct.c:125
static int16_t block1[64]
Definition dct.c:126
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
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.
Definition get_bits.h:645
#define CLOSE_READER(name, gb)
Definition get_bits.h:189
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
#define OPEN_READER(name, gb)
Definition get_bits.h:182
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition get_bits.h:602
#define UPDATE_CACHE(name, gb)
Definition get_bits.h:213
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_HQX
Definition codec_id.h:235
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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...
Definition imgutils.c:318
const VLCElem ff_hq_cbp_vlc[1<< HQ_CBP_VLC_BITS]
Definition hq_common.c:27
#define HQ_CBP_VLC_BITS
Definition hq_common.h:25
#define Q(q)
static int decode_slice(HQXContext *ctx, int slice_no)
Definition hqx.c:350
static const unsigned hqx_quants[16][4]
Definition hqx.c:88
static const uint8_t hqx_quant_luma[64]
Definition hqx.c:102
int(* mb_decode_func)(struct HQXContext *ctx, int slice_no, int x, int y)
Definition hqx.c:50
static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice_no, int threadnr)
Definition hqx.c:403
static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
Definition hqx.c:300
static void put_blocks(HQXContext *ctx, int plane, int x, int y, int ilace, int16_t *block0, int16_t *block1, const uint8_t *quant)
Definition hqx.c:124
static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
Definition hqx.c:216
static const int shuffle_16[16]
Definition hqx.c:346
static int decode_block(GetBitContext *gb, const VLCElem vlc[], const unsigned *quants, int dcb, int16_t block[64], int *last_dc)
Definition hqx.c:152
static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
Definition hqx.c:181
static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
Definition hqx.c:263
HQXFormat
Definition hqx.c:41
@ HQX_422A
Definition hqx.c:44
@ HQX_422
Definition hqx.c:42
@ HQX_444
Definition hqx.c:43
@ HQX_444A
Definition hqx.c:45
static av_cold int hqx_decode_close(AVCodecContext *avctx)
Definition hqx.c:537
static const uint8_t hqx_quant_chroma[64]
Definition hqx.c:113
#define HQX_HEADER_SIZE
Definition hqx.c:77
static int hqx_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_picture_ptr, AVPacket *avpkt)
Definition hqx.c:426
static void hqx_get_ac(GetBitContext *gb, const HQXAC *ac, int *runp, int *lev)
Definition hqx.c:139
static av_cold int hqx_decode_init(AVCodecContext *avctx)
Definition hqx.c:546
av_cold void ff_hqxdsp_init(HQXDSPContext *c)
Definition hqxdsp.c:128
HQX DSP routines.
av_unused static av_cold void hqx_init_static(void)
Definition hqxvlc.h:1534
static const uint16_t dc11_vlc_bits[2048]
Definition hqxvlc.h:348
static HQXAC hqx_ac[NUM_HQX_AC]
Definition hqxvlc.h:739
static const uint8_t dc11_vlc_lens[2048]
Definition hqxvlc.h:607
#define HQX_DC_VLC_BITS
Definition hqxvlc.h:31
misc image utilities
#define AV_RL32(p)
#define AV_RB24(x)
#define AV_RB16(p)
const char * arg
Definition jacosubdec.c:65
Multithreading API for decoders.
#define av_cold
Definition attributes.h:117
#define AVOnce
Definition thread.h:202
static int ff_thread_once(char *control, void(*routine)(void))
Definition thread.h:205
#define AV_ONCE_INIT
Definition thread.h:203
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFALIGN(x, a)
Definition macros.h:78
const uint8_t ff_zigzag_direct[64]
Definition mathtables.c:137
static av_const int sign_extend(int val, unsigned bits)
Definition mathops.h:135
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:603
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:602
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
Definition avcodec.h:1822
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.
Definition avcodec.h:1628
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:619
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
Definition hqxvlc.h:43
const RL_VLC_ELEM * lut
Definition hqxvlc.h:45
int bits
Definition hqxvlc.h:44
HQXDSPContext hqxdsp
Definition hqx.c:59
int height
Definition hqx.c:65
int format
Definition hqx.c:65
AVFrame * pic
Definition hqx.c:62
int interlaced
Definition hqx.c:66
int dcb
Definition hqx.c:65
HQXSlice slice[16]
Definition hqx.c:60
unsigned int data_size
Definition hqx.c:69
mb_decode_func decode_func
Definition hqx.c:63
uint32_t slice_off[17]
Definition hqx.c:70
VLC dc11_vlc
Definition hqx.c:74
int width
Definition hqx.c:65
const uint8_t * src
Definition hqx.c:68
const VLCElem * dc_vlc
Definition hqx.c:72
Definition hqx.c:53
GetBitContext gb
Definition hqx.c:54
int16_t block[16][64]
Definition hqx.c:55
Definition vlc.h:32
Definition vlc.h:50
uint8_t run
Definition svq3.c:207
uint8_t level
Definition svq3.c:208
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static AVFormatContext * ctx
Definition movenc.c:49
void ff_vlc_free(VLC *vlc)
Definition vlc.c:580
#define vlc_init(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition vlc.h:70
static const uint8_t quant[64]
Definition vmixdec.c:71