40 #define HQX_HEADER_SIZE 59
50 { 0x1, 0x2, 0x4, 0x8 }, { 0x1, 0x3, 0x6, 0xC },
51 { 0x2, 0x4, 0x8, 0x10 }, { 0x3, 0x6, 0xC, 0x18 },
52 { 0x4, 0x8, 0x10, 0x20 }, { 0x6, 0xC, 0x18, 0x30 },
53 { 0x8, 0x10, 0x20, 0x40 },
54 { 0xA, 0x14, 0x28, 0x50 },
55 { 0xC, 0x18, 0x30, 0x60 },
56 { 0x10, 0x20, 0x40, 0x80 }, { 0x18, 0x30, 0x60, 0xC0 },
57 { 0x20, 0x40, 0x80, 0x100 }, { 0x30, 0x60, 0xC0, 0x180 },
58 { 0x40, 0x80, 0x100, 0x200 }, { 0x60, 0xC0, 0x180, 0x300 },
59 { 0x80, 0x100, 0x200, 0x400 }
63 16, 16, 16, 19, 19, 19, 42, 44,
64 16, 16, 19, 19, 19, 38, 43, 45,
65 16, 19, 19, 19, 40, 41, 45, 48,
66 19, 19, 19, 40, 41, 42, 46, 49,
67 19, 19, 40, 41, 42, 43, 48, 101,
68 19, 38, 41, 42, 43, 44, 98, 104,
69 42, 43, 45, 46, 48, 98, 109, 116,
70 44, 45, 48, 49, 101, 104, 116, 123,
74 16, 16, 19, 25, 26, 26, 42, 44,
75 16, 19, 25, 25, 26, 38, 43, 91,
76 19, 25, 26, 27, 40, 41, 91, 96,
77 25, 25, 27, 40, 41, 84, 93, 197,
78 26, 26, 40, 41, 84, 86, 191, 203,
79 26, 38, 41, 84, 86, 177, 197, 209,
80 42, 43, 91, 93, 191, 197, 219, 232,
81 44, 91, 96, 197, 203, 209, 232, 246,
86 int t0,
t1,
t2,
t3,
t4,
t5,
t6,
t7,
t8,
t9, tA, tB, tC, tD, tE, tF;
90 s0 = (int) blk[0 * 8] * quant[0 * 8];
91 s1 = (int) blk[1 * 8] * quant[1 * 8];
92 s2 = (int) blk[2 * 8] * quant[2 * 8];
93 s3 = (int) blk[3 * 8] * quant[3 * 8];
94 s4 = (int) blk[4 * 8] * quant[4 * 8];
95 s5 = (int) blk[5 * 8] * quant[5 * 8];
96 s6 = (int) blk[6 * 8] * quant[6 * 8];
97 s7 = (int) blk[7 * 8] * quant[7 * 8];
99 t0 = (s3 * 19266 + s5 * 12873) >> 15;
100 t1 = (s5 * 19266 - s3 * 12873) >> 15;
101 t2 = ((s7 * 4520 + s1 * 22725) >> 15) -
t0;
102 t3 = ((s1 * 4520 - s7 * 22725) >> 15) -
t1;
107 t8 = (t6 * 11585) >> 14;
108 t9 = (t7 * 11585) >> 14;
109 tA = (s2 * 8867 - s6 * 21407) >> 14;
110 tB = (s6 * 8867 + s2 * 21407) >> 14;
111 tC = (s0 >> 1) - (s4 >> 1);
112 tD = (s4 >> 1) * 2 + tC;
117 t12 = tE + (tA >> 1) * 2 - t9;
118 t13 = tF + (tB >> 1) * 2 - t4;
120 blk[0 * 8] = t13 + t4 * 2;
121 blk[1 * 8] = t12 + t9 * 2;
122 blk[2 * 8] = t11 + t8 * 2;
123 blk[3 * 8] = t10 + t5 * 2;
132 int t0,
t1,
t2,
t3,
t4,
t5,
t6,
t7,
t8,
t9, tA, tB, tC, tD, tE, tF;
135 t0 = (blk[3] * 19266 + blk[5] * 12873) >> 14;
136 t1 = (blk[5] * 19266 - blk[3] * 12873) >> 14;
137 t2 = ((blk[7] * 4520 + blk[1] * 22725) >> 14) -
t0;
138 t3 = ((blk[1] * 4520 - blk[7] * 22725) >> 14) -
t1;
143 t8 = (t6 * 11585) >> 14;
144 t9 = (t7 * 11585) >> 14;
145 tA = (blk[2] * 8867 - blk[6] * 21407) >> 14;
146 tB = (blk[6] * 8867 + blk[2] * 21407) >> 14;
147 tC = blk[0] - blk[4];
148 tD = blk[4] * 2 + tC;
153 t12 = tE + tA * 2 -
t9;
154 t13 = tF + tB * 2 -
t4;
156 blk[0] = (t13 + t4 * 2 + 4) >> 3;
157 blk[1] = (t12 + t9 * 2 + 4) >> 3;
158 blk[2] = (t11 + t8 * 2 + 4) >> 3;
159 blk[3] = (t10 + t5 * 2 + 4) >> 3;
160 blk[4] = (t10 + 4) >> 3;
161 blk[5] = (t11 + 4) >> 3;
162 blk[6] = (t12 + 4) >> 3;
163 blk[7] = (t13 + 4) >> 3;
170 for (i = 0; i < 8; i++)
172 for (i = 0; i < 8; i++)
183 for (i = 0; i < 8; i++) {
184 for (j = 0; j < 8; j++) {
185 int v = av_clip(block[j + i * 8] + 0x800, 0, 0x1000);
186 dst[j] = (v << 4) | (v >> 8);
193 int x,
int y,
int ilace,
194 int16_t *block0, int16_t *
block1,
197 int fields = ilace ? 2 : 1;
201 hqx_idct_put((uint16_t *)(p + y * lsize), lsize * fields, block0, quant);
202 hqx_idct_put((uint16_t *)(p + (y + (ilace ? 1 : 8)) * lsize),
203 lsize * fields, block1, quant);
223 const int *quants,
int dcb,
224 int16_t
block[64],
int *last_dc)
228 int run, lev, pos = 1;
230 memset(block, 0, 64 *
sizeof(*block));
236 block[0] =
sign_extend(*last_dc << (12 - dcb), 12);
278 for (i = 0; i < 8; i++) {
279 int vlc_index = ctx->
dcb - 9;
280 if (i == 0 || i == 4 || i == 6)
307 for (i = 0; i < 12; i++)
308 memset(ctx->
block[i], 0,
sizeof(**ctx->
block) * 64);
309 for (i = 0; i < 12; i++)
310 ctx->
block[i][0] = -0x800;
322 for (i = 0; i < 12; i++) {
323 if (i == 0 || i == 4 || i == 8 || i == 10)
325 if (cbp & (1 << i)) {
326 int vlc_index = ctx->
dcb - 9;
360 for (i = 0; i < 12; i++) {
361 int vlc_index = ctx->
dcb - 9;
362 if (i == 0 || i == 4 || i == 8)
391 for (i = 0; i < 16; i++)
392 memset(ctx->
block[i], 0,
sizeof(**ctx->
block) * 64);
393 for (i = 0; i < 16; i++)
394 ctx->
block[i][0] = -0x800;
403 for (i = 0; i < 16; i++) {
404 if (i == 0 || i == 4 || i == 8 || i == 12)
406 if (cbp & (1 << i)) {
407 int vlc_index = ctx->
dcb - 9;
429 0, 5, 11, 14, 2, 7, 9, 13, 1, 4, 10, 15, 3, 6, 8, 12
435 int mb_w = (ctx->
width + 15) >> 4;
436 int mb_h = (ctx->
height + 15) >> 4;
437 int grp_w = (mb_w + 4) / 5;
438 int grp_h = (mb_h + 4) / 5;
439 int grp_h_edge = grp_w * (mb_w / grp_w);
440 int grp_v_edge = grp_h * (mb_h / grp_h);
441 int grp_v_rest = mb_w - grp_h_edge;
442 int grp_h_rest = mb_h - grp_v_edge;
443 int num_mbs = mb_w * mb_h;
444 int num_tiles = (num_mbs + 479) / 480;
445 int std_tile_blocks = num_mbs / (16 * num_tiles);
446 int g_tile = slice_no * num_tiles;
447 int blk_addr, loc_addr, mb_x, mb_y, pos, loc_row, i;
448 int tile_blocks, tile_limit, tile_no;
450 for (tile_no = 0; tile_no < num_tiles; tile_no++, g_tile++) {
451 tile_blocks = std_tile_blocks;
453 if (g_tile < num_mbs - std_tile_blocks * 16 * num_tiles) {
454 tile_limit = num_mbs / (16 * num_tiles);
457 for (i = 0; i < tile_blocks; i++) {
459 blk_addr = g_tile + 16 * num_tiles * i;
461 blk_addr = tile_no + 16 * num_tiles * i +
463 loc_row = grp_h * (blk_addr / (grp_h * mb_w));
464 loc_addr = blk_addr % (grp_h * mb_w);
465 if (loc_row >= grp_v_edge) {
466 mb_x = grp_w * (loc_addr / (grp_h_rest * grp_w));
467 pos = loc_addr % (grp_h_rest * grp_w);
469 mb_x = grp_w * (loc_addr / (grp_h * grp_w));
470 pos = loc_addr % (grp_h * grp_w);
472 if (mb_x >= grp_h_edge) {
473 mb_x += pos % grp_v_rest;
474 mb_y = loc_row + (pos / grp_v_rest);
477 mb_y = loc_row + (pos / grp_w);
479 decode_func(ctx, pic, gb, mb_x * 16, mb_y * 16);
487 int *got_picture_ptr,
AVPacket *avpkt)
492 uint32_t info_tag, info_offset;
498 uint32_t slice_off[17];
507 if (info_tag ==
MKTAG(
'I',
'N',
'F',
'O')) {
508 info_offset =
AV_RL32(src + 4);
509 if (info_offset > UINT32_MAX - 8 || info_offset + 8 > avpkt->
size) {
511 "Invalid INFO header offset: 0x%08"PRIX32
" is too large.\n",
522 data_start = src - avpkt->
data;
523 data_size = avpkt->
size - data_start;
530 if (src[0] !=
'H' || src[1] !=
'Q') {
536 ctx->
dcb = (src[3] & 3) + 8;
539 for (i = 0; i < 17; i++)
540 slice_off[i] =
AV_RB24(src + 8 + i * 3);
586 for (slice = 0; slice < 16; slice++) {
588 slice_off[slice] >= slice_off[slice + 1] ||
589 slice_off[slice + 1] > data_size) {
594 slice_off[slice + 1] - slice_off[slice]);
606 *got_picture_ptr = 1;
617 for (i = 0; i < 3; i++) {