FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/imgutils.h"
24 #include "libavutil/intreadwrite.h"
25 
26 #include "avcodec.h"
27 #include "canopus.h"
28 #include "get_bits.h"
29 #include "internal.h"
30 
31 #include "hqx.h"
32 #include "hqxdsp.h"
33 
34 /* HQX has four modes - 422, 444, 422alpha and 444alpha - all 12-bit */
35 enum HQXFormat {
36  HQX_422 = 0,
40 };
41 
42 #define HQX_HEADER_SIZE 59
43 
44 /* macroblock selects a group of 4 possible quants and
45  * a block can use any of those four quantisers
46  * one column is powers of 2, the other one is powers of 2 * 3,
47  * then there is the special one, powers of 2 * 5 */
48 static const int hqx_quants[16][4] = {
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 }
59 };
60 
61 static const uint8_t hqx_quant_luma[64] = {
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,
70 };
71 
72 static const uint8_t hqx_quant_chroma[64] = {
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,
81 };
82 
83 static inline void put_blocks(HQXContext *ctx, int plane,
84  int x, int y, int ilace,
85  int16_t *block0, int16_t *block1,
86  const uint8_t *quant)
87 {
88  int fields = ilace ? 2 : 1;
89  int lsize = ctx->pic->linesize[plane];
90  uint8_t *p = ctx->pic->data[plane] + x * 2;
91 
92  ctx->hqxdsp.idct_put((uint16_t *)(p + y * lsize),
93  lsize * fields, block0, quant);
94  ctx->hqxdsp.idct_put((uint16_t *)(p + (y + (ilace ? 1 : 8)) * lsize),
95  lsize * fields, block1, quant);
96 }
97 
98 static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac,
99  int *run, int *lev)
100 {
101  int val;
102 
103  val = show_bits(gb, ac->lut_bits);
104  if (ac->lut[val].bits == -1) {
105  GetBitContext gb2 = *gb;
106  skip_bits(&gb2, ac->lut_bits);
107  val = ac->lut[val].lev + show_bits(&gb2, ac->extra_bits);
108  }
109  *run = ac->lut[val].run;
110  *lev = ac->lut[val].lev;
111  skip_bits(gb, ac->lut[val].bits);
112 }
113 
114 static int decode_block(GetBitContext *gb, VLC *vlc,
115  const int *quants, int dcb,
116  int16_t block[64], int *last_dc)
117 {
118  int q, dc;
119  int ac_idx;
120  int run, lev, pos = 1;
121 
122  memset(block, 0, 64 * sizeof(*block));
123  dc = get_vlc2(gb, vlc->table, HQX_DC_VLC_BITS, 2);
124  if (dc < 0)
125  return AVERROR_INVALIDDATA;
126  *last_dc += dc;
127 
128  block[0] = sign_extend(*last_dc << (12 - dcb), 12);
129 
130  q = quants[get_bits(gb, 2)];
131  if (q >= 128)
132  ac_idx = HQX_AC_Q128;
133  else if (q >= 64)
134  ac_idx = HQX_AC_Q64;
135  else if (q >= 32)
136  ac_idx = HQX_AC_Q32;
137  else if (q >= 16)
138  ac_idx = HQX_AC_Q16;
139  else if (q >= 8)
140  ac_idx = HQX_AC_Q8;
141  else
142  ac_idx = HQX_AC_Q0;
143 
144  do {
145  hqx_get_ac(gb, &ff_hqx_ac[ac_idx], &run, &lev);
146  pos += run;
147  if (pos >= 64)
148  break;
149  block[ff_zigzag_direct[pos++]] = lev * q;
150  } while (pos < 64);
151 
152  return 0;
153 }
154 
155 static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
156 {
157  HQXSlice *slice = &ctx->slice[slice_no];
158  GetBitContext *gb = &slice->gb;
159  const int *quants;
160  int flag;
161  int last_dc;
162  int i, ret;
163 
164  if (ctx->interlaced)
165  flag = get_bits1(gb);
166  else
167  flag = 0;
168 
169  quants = hqx_quants[get_bits(gb, 4)];
170 
171  for (i = 0; i < 8; i++) {
172  int vlc_index = ctx->dcb - 9;
173  if (i == 0 || i == 4 || i == 6)
174  last_dc = 0;
175  ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
176  ctx->dcb, slice->block[i], &last_dc);
177  if (ret < 0)
178  return ret;
179  }
180 
181  put_blocks(ctx, 0, x, y, flag, slice->block[0], slice->block[2], hqx_quant_luma);
182  put_blocks(ctx, 0, x + 8, y, flag, slice->block[1], slice->block[3], hqx_quant_luma);
183  put_blocks(ctx, 2, x >> 1, y, flag, slice->block[4], slice->block[5], hqx_quant_chroma);
184  put_blocks(ctx, 1, x >> 1, y, flag, slice->block[6], slice->block[7], hqx_quant_chroma);
185 
186  return 0;
187 }
188 
189 static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
190 {
191  HQXSlice *slice = &ctx->slice[slice_no];
192  GetBitContext *gb = &slice->gb;
193  const int *quants;
194  int flag = 0;
195  int last_dc;
196  int i, ret;
197  int cbp;
198 
199  cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
200 
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;
205  if (cbp) {
206  if (ctx->interlaced)
207  flag = get_bits1(gb);
208 
209  quants = hqx_quants[get_bits(gb, 4)];
210 
211  cbp |= cbp << 4; // alpha CBP
212  if (cbp & 0x3) // chroma CBP - top
213  cbp |= 0x500;
214  if (cbp & 0xC) // chroma CBP - bottom
215  cbp |= 0xA00;
216  for (i = 0; i < 12; i++) {
217  if (i == 0 || i == 4 || i == 8 || i == 10)
218  last_dc = 0;
219  if (cbp & (1 << i)) {
220  int vlc_index = ctx->dcb - 9;
221  ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
222  ctx->dcb, slice->block[i], &last_dc);
223  if (ret < 0)
224  return ret;
225  }
226  }
227  }
228 
229  put_blocks(ctx, 3, x, y, flag, slice->block[ 0], slice->block[ 2], hqx_quant_luma);
230  put_blocks(ctx, 3, x + 8, y, flag, slice->block[ 1], slice->block[ 3], hqx_quant_luma);
231  put_blocks(ctx, 0, x, y, flag, slice->block[ 4], slice->block[ 6], hqx_quant_luma);
232  put_blocks(ctx, 0, x + 8, y, flag, slice->block[ 5], slice->block[ 7], hqx_quant_luma);
233  put_blocks(ctx, 2, x >> 1, y, flag, slice->block[ 8], slice->block[ 9], hqx_quant_chroma);
234  put_blocks(ctx, 1, x >> 1, y, flag, slice->block[10], slice->block[11], hqx_quant_chroma);
235 
236  return 0;
237 }
238 
239 static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
240 {
241  HQXSlice *slice = &ctx->slice[slice_no];
242  GetBitContext *gb = &slice->gb;
243  const int *quants;
244  int flag;
245  int last_dc;
246  int i, ret;
247 
248  if (ctx->interlaced)
249  flag = get_bits1(gb);
250  else
251  flag = 0;
252 
253  quants = hqx_quants[get_bits(gb, 4)];
254 
255  for (i = 0; i < 12; i++) {
256  int vlc_index = ctx->dcb - 9;
257  if (i == 0 || i == 4 || i == 8)
258  last_dc = 0;
259  ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
260  ctx->dcb, slice->block[i], &last_dc);
261  if (ret < 0)
262  return ret;
263  }
264 
265  put_blocks(ctx, 0, x, y, flag, slice->block[0], slice->block[ 2], hqx_quant_luma);
266  put_blocks(ctx, 0, x + 8, y, flag, slice->block[1], slice->block[ 3], hqx_quant_luma);
267  put_blocks(ctx, 2, x, y, flag, slice->block[4], slice->block[ 6], hqx_quant_chroma);
268  put_blocks(ctx, 2, x + 8, y, flag, slice->block[5], slice->block[ 7], hqx_quant_chroma);
269  put_blocks(ctx, 1, x, y, flag, slice->block[8], slice->block[10], hqx_quant_chroma);
270  put_blocks(ctx, 1, x + 8, y, flag, slice->block[9], slice->block[11], hqx_quant_chroma);
271 
272  return 0;
273 }
274 
275 static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
276 {
277  HQXSlice *slice = &ctx->slice[slice_no];
278  GetBitContext *gb = &slice->gb;
279  const int *quants;
280  int flag = 0;
281  int last_dc;
282  int i, ret;
283  int cbp;
284 
285  cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
286 
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;
291  if (cbp) {
292  if (ctx->interlaced)
293  flag = get_bits1(gb);
294 
295  quants = hqx_quants[get_bits(gb, 4)];
296 
297  cbp |= cbp << 4; // alpha CBP
298  cbp |= cbp << 8; // chroma CBP
299  for (i = 0; i < 16; i++) {
300  if (i == 0 || i == 4 || i == 8 || i == 12)
301  last_dc = 0;
302  if (cbp & (1 << i)) {
303  int vlc_index = ctx->dcb - 9;
304  ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
305  ctx->dcb, slice->block[i], &last_dc);
306  if (ret < 0)
307  return ret;
308  }
309  }
310  }
311 
312  put_blocks(ctx, 3, x, y, flag, slice->block[ 0], slice->block[ 2], hqx_quant_luma);
313  put_blocks(ctx, 3, x + 8, y, flag, slice->block[ 1], slice->block[ 3], hqx_quant_luma);
314  put_blocks(ctx, 0, x, y, flag, slice->block[ 4], slice->block[ 6], hqx_quant_luma);
315  put_blocks(ctx, 0, x + 8, y, flag, slice->block[ 5], slice->block[ 7], hqx_quant_luma);
316  put_blocks(ctx, 2, x, y, flag, slice->block[ 8], slice->block[10], hqx_quant_chroma);
317  put_blocks(ctx, 2, x + 8, y, flag, slice->block[ 9], slice->block[11], hqx_quant_chroma);
318  put_blocks(ctx, 1, x, y, flag, slice->block[12], slice->block[14], hqx_quant_chroma);
319  put_blocks(ctx, 1, x + 8, y, flag, slice->block[13], slice->block[15], hqx_quant_chroma);
320 
321  return 0;
322 }
323 
324 static const int shuffle_16[16] = {
325  0, 5, 11, 14, 2, 7, 9, 13, 1, 4, 10, 15, 3, 6, 8, 12
326 };
327 
328 static int decode_slice(HQXContext *ctx, int slice_no)
329 {
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;
344 
345  for (tile_no = 0; tile_no < num_tiles; tile_no++, g_tile++) {
346  tile_blocks = std_tile_blocks;
347  tile_limit = -1;
348  if (g_tile < num_mbs - std_tile_blocks * 16 * num_tiles) {
349  tile_limit = num_mbs / (16 * num_tiles);
350  tile_blocks++;
351  }
352  for (i = 0; i < tile_blocks; i++) {
353  if (i == tile_limit)
354  blk_addr = g_tile + 16 * num_tiles * i;
355  else
356  blk_addr = tile_no + 16 * num_tiles * i +
357  num_tiles * shuffle_16[(i + slice_no) & 0xF];
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);
363  } else {
364  mb_x = grp_w * (loc_addr / (grp_h * grp_w));
365  pos = loc_addr % (grp_h * grp_w);
366  }
367  if (mb_x >= grp_h_edge) {
368  mb_x += pos % grp_v_rest;
369  mb_y = loc_row + (pos / grp_v_rest);
370  } else {
371  mb_x += pos % grp_w;
372  mb_y = loc_row + (pos / grp_w);
373  }
374  ctx->decode_func(ctx, slice_no, mb_x * 16, mb_y * 16);
375  }
376  }
377 
378  return 0;
379 }
380 
381 static int decode_slice_thread(AVCodecContext *avctx, void *arg,
382  int slice_no, int threadnr)
383 {
384  HQXContext *ctx = avctx->priv_data;
385  uint32_t *slice_off = ctx->slice_off;
386  int ret;
387 
388  if (slice_off[slice_no] < HQX_HEADER_SIZE ||
389  slice_off[slice_no] >= slice_off[slice_no + 1] ||
390  slice_off[slice_no + 1] > ctx->data_size) {
391  av_log(avctx, AV_LOG_ERROR, "Invalid slice size %d.\n", ctx->data_size);
392  return AVERROR_INVALIDDATA;
393  }
394 
395  ret = init_get_bits8(&ctx->slice[slice_no].gb,
396  ctx->src + slice_off[slice_no],
397  slice_off[slice_no + 1] - slice_off[slice_no]);
398  if (ret < 0)
399  return ret;
400 
401  return decode_slice(ctx, slice_no);
402 }
403 
404 static int hqx_decode_frame(AVCodecContext *avctx, void *data,
405  int *got_picture_ptr, AVPacket *avpkt)
406 {
407  HQXContext *ctx = avctx->priv_data;
408  uint8_t *src = avpkt->data;
409  uint32_t info_tag;
410  int data_start;
411  int i, ret;
412 
413  if (avpkt->size < 4 + 4) {
414  av_log(avctx, AV_LOG_ERROR, "Frame is too small %d.\n", avpkt->size);
415  return AVERROR_INVALIDDATA;
416  }
417 
418  info_tag = AV_RL32(src);
419  if (info_tag == MKTAG('I', 'N', 'F', 'O')) {
420  unsigned info_offset = AV_RL32(src + 4);
421  if (info_offset > INT_MAX || info_offset + 8 > avpkt->size) {
422  av_log(avctx, AV_LOG_ERROR,
423  "Invalid INFO header offset: 0x%08"PRIX32" is too large.\n",
424  info_offset);
425  return AVERROR_INVALIDDATA;
426  }
427  ff_canopus_parse_info_tag(avctx, src + 8, info_offset);
428 
429  info_offset += 8;
430  src += info_offset;
431  }
432 
433  data_start = src - avpkt->data;
434  ctx->data_size = avpkt->size - data_start;
435  ctx->src = src;
436  ctx->pic = data;
437 
438  if (ctx->data_size < HQX_HEADER_SIZE) {
439  av_log(avctx, AV_LOG_ERROR, "Frame too small.\n");
440  return AVERROR_INVALIDDATA;
441  }
442 
443  if (src[0] != 'H' || src[1] != 'Q') {
444  av_log(avctx, AV_LOG_ERROR, "Not an HQX frame.\n");
445  return AVERROR_INVALIDDATA;
446  }
447  ctx->interlaced = !(src[2] & 0x80);
448  ctx->format = src[2] & 7;
449  ctx->dcb = (src[3] & 3) + 8;
450  ctx->width = AV_RB16(src + 4);
451  ctx->height = AV_RB16(src + 6);
452  for (i = 0; i < 17; i++)
453  ctx->slice_off[i] = AV_RB24(src + 8 + i * 3);
454 
455  if (ctx->dcb == 8) {
456  av_log(avctx, AV_LOG_ERROR, "Invalid DC precision %d.\n", ctx->dcb);
457  return AVERROR_INVALIDDATA;
458  }
459  ret = av_image_check_size(ctx->width, ctx->height, 0, avctx);
460  if (ret < 0) {
461  av_log(avctx, AV_LOG_ERROR, "Invalid stored dimensions %dx%d.\n",
462  ctx->width, ctx->height);
463  return AVERROR_INVALIDDATA;
464  }
465 
466  avctx->coded_width = FFALIGN(ctx->width, 16);
467  avctx->coded_height = FFALIGN(ctx->height, 16);
468  avctx->width = ctx->width;
469  avctx->height = ctx->height;
470  avctx->bits_per_raw_sample = 10;
471 
472  switch (ctx->format) {
473  case HQX_422:
474  avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
476  break;
477  case HQX_444:
478  avctx->pix_fmt = AV_PIX_FMT_YUV444P16;
480  break;
481  case HQX_422A:
484  break;
485  case HQX_444A:
488  break;
489  default:
490  av_log(avctx, AV_LOG_ERROR, "Invalid format: %d.\n", ctx->format);
491  return AVERROR_INVALIDDATA;
492  }
493 
494  ret = ff_get_buffer(avctx, ctx->pic, 0);
495  if (ret < 0)
496  return ret;
497 
498  avctx->execute2(avctx, decode_slice_thread, NULL, NULL, 16);
499 
500  ctx->pic->key_frame = 1;
502 
503  *got_picture_ptr = 1;
504 
505  return avpkt->size;
506 }
507 
509 {
510  int i;
511  HQXContext *ctx = avctx->priv_data;
512 
513  ff_free_vlc(&ctx->cbp_vlc);
514  for (i = 0; i < 3; i++) {
515  ff_free_vlc(&ctx->dc_vlc[i]);
516  }
517 
518  return 0;
519 }
520 
522 {
523  HQXContext *ctx = avctx->priv_data;
524 
525  ff_hqxdsp_init(&ctx->hqxdsp);
526 
527  return ff_hqx_init_vlcs(ctx);
528 }
529 
531  .name = "hqx",
532  .long_name = NULL_IF_CONFIG_SMALL("Canopus HQX"),
533  .type = AVMEDIA_TYPE_VIDEO,
534  .id = AV_CODEC_ID_HQX,
535  .priv_data_size = sizeof(HQXContext),
538  .close = hqx_decode_close,
540  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
542 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
int plane
Definition: avisynth_c.h:422
Definition: hqx.h:47
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:771
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:378
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int dcb
Definition: hqx.h:69
HQXSlice slice[16]
Definition: hqx.h:64
int height
Definition: hqx.h:69
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int interlaced
Definition: hqx.h:70
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1878
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:247
static void hqx_get_ac(GetBitContext *gb, const HQXAC *ac, int *run, int *lev)
Definition: hqx.c:98
#define HQX_DC_VLC_BITS
Definition: hqx.h:80
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int ff_canopus_parse_info_tag(AVCodecContext *avctx, const uint8_t *src, size_t size)
Definition: canopus.c:30
Definition: hqx.c:38
GetBitContext gb
Definition: hqx.h:58
int size
Definition: avcodec.h:1602
int flag
Definition: cpu.c:34
Definition: hqx.h:35
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1904
mb_decode_func decode_func
Definition: hqx.h:67
int ff_hqx_init_vlcs(HQXContext *ctx)
Definition: hqxvlc.c:2151
void(* idct_put)(uint16_t *dst, ptrdiff_t stride, int16_t *block, const uint8_t *quant)
Definition: hqxdsp.h:33
uint8_t run
Definition: svq3.c:206
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3077
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
Definition: bytestream.h:87
AVCodec.
Definition: avcodec.h:3600
Definition: hqx.h:34
static av_cold int hqx_decode_init(AVCodecContext *avctx)
Definition: hqx.c:521
static int hqx_decode_frame(AVCodecContext *avctx, void *data, int *got_picture_ptr, AVPacket *avpkt)
Definition: hqx.c:404
static int16_t block[64]
Definition: dct.c:113
const HQXAC ff_hqx_ac[NUM_HQX_AC]
Definition: hqxvlc.c:2132
uint8_t * src
Definition: hqx.h:72
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
uint8_t
#define av_cold
Definition: attributes.h:82
uint8_t run
Definition: hqx.h:43
static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
Definition: hqx.c:189
static const uint8_t hqx_quant_luma[64]
Definition: hqx.c:61
static const int hqx_quants[16][4]
Definition: hqx.c:48
uint8_t * data
Definition: avcodec.h:1601
bitstream reader API header.
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:354
static const uint8_t hqx_quant_chroma[64]
Definition: hqx.c:72
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
AVCodec ff_hqx_decoder
Definition: hqx.c:530
const HQXLUT * lut
Definition: hqx.h:49
static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
Definition: hqx.c:155
VLC dc_vlc[3]
Definition: hqx.h:77
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static av_cold int hqx_decode_close(AVCodecContext *avctx)
Definition: hqx.c:508
static int decode_slice(HQXContext *ctx, int slice_no)
Definition: hqx.c:328
int lut_bits
Definition: hqx.h:48
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static int decode_block(GetBitContext *gb, VLC *vlc, const int *quants, int dcb, int16_t block[64], int *last_dc)
Definition: hqx.c:114
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:379
const char * arg
Definition: jacosubdec.c:66
Definition: hqx.c:37
const char * name
Name of the codec implementation.
Definition: avcodec.h:3607
Definition: hqx.h:62
Definition: vlc.h:26
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:251
Definition: hqx.h:57
Definition: hqx.h:36
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:258
int width
picture width / height.
Definition: avcodec.h:1863
AVFormatContext * ctx
Definition: movenc.c:48
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:282
int extra_bits
Definition: hqx.h:48
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:535
HQX DSP routines.
Definition: hqx.c:39
#define HQX_HEADER_SIZE
Definition: hqx.c:42
#define src
Definition: vp9dsp.c:530
int bits
Definition: vlc.h:27
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:1026
int width
Definition: hqx.h:69
static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
Definition: hqx.c:275
Definition: hqx.h:32
static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice_no, int threadnr)
Definition: hqx.c:381
Libavcodec external API header.
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
Definition: bytestream.h:87
int8_t bits
Definition: hqx.h:44
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:437
main external API structure.
Definition: avcodec.h:1676
HQXFormat
Definition: hqx.c:35
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:947
int16_t block[16][64]
Definition: hqx.h:59
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:299
int coded_height
Definition: avcodec.h:1878
static const int shuffle_16[16]
Definition: hqx.c:324
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:292
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
const uint8_t * quant
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:139
uint32_t slice_off[17]
Definition: hqx.h:74
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
int16_t lev
Definition: hqx.h:42
Definition: hqx.c:36
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:282
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:83
unsigned int data_size
Definition: hqx.h:73
av_cold void ff_hqxdsp_init(HQXDSPContext *c)
Definition: hqxdsp.c:128
void * priv_data
Definition: avcodec.h:1718
AVFrame * pic
Definition: hqx.h:66
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:3167
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
int format
Definition: hqx.h:69
VLC cbp_vlc
Definition: hqx.h:76
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:253
static int16_t block1[64]
Definition: dct.c:114
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
Definition: hqx.h:33
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: ffmpeg.c:2035
static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
Definition: hqx.c:239
#define MKTAG(a, b, c, d)
Definition: common.h:342
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1578
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:360
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:353
HQXDSPContext hqxdsp
Definition: hqx.h:63