Lines Matching refs:jd
133 JDEC* jd, /* Pointer to the decompressor object */ in alloc_pool() argument
142 if (jd->sz_pool >= ndata) { in alloc_pool()
143 jd->sz_pool -= ndata; in alloc_pool()
144 rp = (char*)jd->pool; /* Get start of available memory pool */ in alloc_pool()
145 jd->pool = (void*)(rp + ndata); /* Allocate requierd bytes */ in alloc_pool()
159 JDEC* jd, /* Pointer to the decompressor object */ in create_qt_tbl() argument
175 pb = alloc_pool(jd, 64 * sizeof (int32_t));/* Allocate a memory block for the table */ in create_qt_tbl()
177 jd->qttbl[i] = pb; /* Register the table */ in create_qt_tbl()
195 JDEC* jd, /* Pointer to the decompressor object */ in create_huffman_tbl() argument
212 pb = alloc_pool(jd, 16); /* Allocate a memory block for the bit distribution table */ in create_huffman_tbl()
214 jd->huffbits[num][cls] = pb; in create_huffman_tbl()
218 ph = alloc_pool(jd, np * sizeof (uint16_t));/* Allocate a memory block for the code word table */ in create_huffman_tbl()
220 jd->huffcode[num][cls] = ph; in create_huffman_tbl()
230 pd = alloc_pool(jd, np); /* Allocate a memory block for the decoded data */ in create_huffman_tbl()
232 jd->huffdata[num][cls] = pd; in create_huffman_tbl()
245 tbl_ac = alloc_pool(jd, HUFF_LEN * sizeof (uint16_t)); /* LUT for AC elements */ in create_huffman_tbl()
247 jd->hufflut_ac[num] = tbl_ac; in create_huffman_tbl()
250 tbl_dc = alloc_pool(jd, HUFF_LEN * sizeof (uint8_t)); /* LUT for AC elements */ in create_huffman_tbl()
252 jd->hufflut_dc[num] = tbl_dc; in create_huffman_tbl()
267 jd->longofs[num][cls] = i; /* Code table offset for long code */ in create_huffman_tbl()
283 JDEC* jd, /* Pointer to the decompressor object */ in huffext() argument
288 size_t dc = jd->dctr; in huffext()
289 uint8_t *dp = jd->dptr; in huffext()
294 const uint8_t *hb = jd->huffbits[id][cls]; /* Bit distribution table */ in huffext()
295 const uint16_t *hc = jd->huffcode[id][cls]; /* Code word table */ in huffext()
296 const uint8_t *hd = jd->huffdata[id][cls]; /* Data table */ in huffext()
299 bm = jd->dbit; /* Bit mask to extract */ in huffext()
304 dp = jd->inbuf; /* Top of input buffer */ in huffext()
305 dc = jd->infunc(jd, dp, JD_SZBUF); in huffext()
328 jd->dbit = bm; jd->dctr = dc; jd->dptr = dp; in huffext()
339 unsigned int nc, bl, wbit = jd->dbit % 32; in huffext()
340 uint32_t w = jd->wreg & ((1UL << wbit) - 1); in huffext()
344 if (jd->marker) { in huffext()
348 dp = jd->inbuf; /* Top of input buffer */ in huffext()
349 dc = jd->infunc(jd, dp, JD_SZBUF); in huffext()
355 if (d != 0) jd->marker = d; /* Not an escape of 0xFF but a marker */ in huffext()
366 jd->dctr = dc; jd->dptr = dp; in huffext()
367 jd->wreg = w; in huffext()
373 d = jd->hufflut_ac[id][d]; /* Table decode */ in huffext()
375 jd->dbit = wbit - (d >> 8); /* Snip the code length */ in huffext()
379 d = jd->hufflut_dc[id][d]; /* Table decode */ in huffext()
381 jd->dbit = wbit - (d >> 4); /* Snip the code length */ in huffext()
387 hb = jd->huffbits[id][cls] + HUFF_BIT; /* Bit distribution table */ in huffext()
388 hc = jd->huffcode[id][cls] + jd->longofs[id][cls]; /* Code word table */ in huffext()
389 hd = jd->huffdata[id][cls] + jd->longofs[id][cls]; /* Data table */ in huffext()
393 hb = jd->huffbits[id][cls]; /* Bit distribution table */ in huffext()
394 hc = jd->huffcode[id][cls]; /* Code word table */ in huffext()
395 hd = jd->huffdata[id][cls]; /* Data table */ in huffext()
404 jd->dbit = wbit - bl; /* Snip the huffman code */ in huffext()
424 JDEC* jd, /* Pointer to the decompressor object */ in bitext() argument
428 size_t dc = jd->dctr; in bitext()
429 uint8_t *dp = jd->dptr; in bitext()
433 uint8_t mbit = jd->dbit; in bitext()
439 dp = jd->inbuf; /* Top of input buffer */ in bitext()
440 dc = jd->infunc(jd, dp, JD_SZBUF); in bitext()
463 jd->dbit = mbit; jd->dctr = dc; jd->dptr = dp; in bitext()
467 unsigned int wbit = jd->dbit % 32; in bitext()
468 uint32_t w = jd->wreg & ((1UL << wbit) - 1); in bitext()
472 if (jd->marker) { in bitext()
476 dp = jd->inbuf; /* Top of input buffer */ in bitext()
477 dc = jd->infunc(jd, dp, JD_SZBUF); in bitext()
483 if (d != 0) jd->marker = d; /* Not an escape of 0xFF but a marker */ in bitext()
494 jd->wreg = w; jd->dbit = wbit - nbit; in bitext()
495 jd->dctr = dc; jd->dptr = dp; in bitext()
509 JDEC* jd, /* Pointer to the decompressor object */ in restart() argument
514 uint8_t *dp = jd->dptr; in restart()
515 size_t dc = jd->dctr; in restart()
523 dp = jd->inbuf; in restart()
524 dc = jd->infunc(jd, dp, JD_SZBUF); in restart()
532 jd->dptr = dp; jd->dctr = dc; jd->dbit = 0; in restart()
543 if (jd->marker) { /* Generate a maker if it has been detected */ in restart()
544 marker = 0xFF00 | jd->marker; in restart()
545 jd->marker = 0; in restart()
550 dp = jd->inbuf; in restart()
551 dc = jd->infunc(jd, dp, JD_SZBUF); in restart()
557 jd->dptr = dp; jd->dctr = dc; in restart()
565 jd->dbit = 0; /* Discard stuff bits */ in restart()
568 jd->dcv[2] = jd->dcv[1] = jd->dcv[0] = 0; /* Reset DC offset */ in restart()
703 JDEC* jd /* Pointer to the decompressor object */ in mcu_load() argument
706 int32_t *tmp = (int32_t*)jd->workbuf; /* Block working buffer for de-quantize and IDCT */ in mcu_load()
713 nby = jd->msx * jd->msy; /* Number of Y blocks (1, 2 or 4) */ in mcu_load()
714 bp = jd->mcubuf; /* Pointer to the first block of MCU */ in mcu_load()
719 if (cmp && jd->ncomp != 3) { /* Clear C blocks if not exist (monochrome image) */ in mcu_load()
726 d = huffext(jd, id, 0); /* Extract a huffman coded data (bit length) */ in mcu_load()
729 d = jd->dcv[cmp]; /* DC value of previous block */ in mcu_load()
731 e = bitext(jd, bc); /* Extract data bits */ in mcu_load()
736 jd->dcv[cmp] = (int16_t)d; /* Save current DC value for next block */ in mcu_load()
738 dqf = jd->qttbl[jd->qtid[cmp]]; /* De-quantizer table ID for this component */ in mcu_load()
745 d = huffext(jd, id, 1); /* Extract a huffman coded value (zero runs and bit length) */ in mcu_load()
752 d = bitext(jd, bc); /* Extract data bits */ in mcu_load()
762 …if (z == 1 || (JD_USE_SCALE && jd->scale == 3)) { /* If no AC element or scale ratio is 1/8, IDCT … in mcu_load()
789 JDEC* jd, /* Pointer to the decompressor object */ in mcu_output() argument
803 mx = jd->msx * 8; my = jd->msy * 8; /* MCU size (pixel) */ in mcu_output()
804 …rx = (img_x + mx <= jd->width) ? mx : jd->width - img_x; /* Output rectangular size (it may be cli… in mcu_output()
805 ry = (img_y + my <= jd->height) ? my : jd->height - img_y; in mcu_output()
807 rx >>= jd->scale; ry >>= jd->scale; in mcu_output()
809 img_x >>= jd->scale; img_y >>= jd->scale; in mcu_output()
815 if (!JD_USE_SCALE || jd->scale != 3) { /* Not for 1/8 scaling */ in mcu_output()
816 pix = (uint8_t*)jd->workbuf; in mcu_output()
820 pc = py = jd->mcubuf; in mcu_output()
845 py = jd->mcubuf + iy * 8; in mcu_output()
859 if (JD_USE_SCALE && jd->scale) { in mcu_output()
864 s = jd->scale * 2; /* Number of shifts for averaging */ in mcu_output()
865 w = 1 << jd->scale; /* Width of square */ in mcu_output()
867 op = (uint8_t*)jd->workbuf; in mcu_output()
870 pix = (uint8_t*)jd->workbuf + (iy * mx + ix) * (JD_FORMAT != 2 ? 3 : 1); in mcu_output()
894 pix = (uint8_t*)jd->workbuf; in mcu_output()
895 pc = jd->mcubuf + mx * my; in mcu_output()
899 py = jd->mcubuf; in mcu_output()
916 mx >>= jd->scale; in mcu_output()
921 s = d = (uint8_t*)jd->workbuf; in mcu_output()
936 uint8_t *s = (uint8_t*)jd->workbuf; in mcu_output()
949 return outfunc(jd, jd->workbuf, &rect) ? JDR_OK : JDR_INTR; in mcu_output()
963 JDEC* jd, /* Blank decompressor object */ in jd_prepare() argument
977 …memset(jd, 0, sizeof (JDEC)); /* Clear decompression object (this might be a problem if machine's … in jd_prepare()
978 jd->pool = pool; /* Work memroy */ in jd_prepare()
979 jd->sz_pool = sz_pool; /* Size of given work memory */ in jd_prepare()
980 jd->infunc = infunc; /* Stream input function */ in jd_prepare()
981 jd->device = dev; /* I/O device identifier */ in jd_prepare()
983 jd->inbuf = seg = alloc_pool(jd, JD_SZBUF); /* Allocate stream input buffer */ in jd_prepare()
988 if (jd->infunc(jd, seg, 1) != 1) return JDR_INP; /* Err: SOI was not detected */ in jd_prepare()
995 if (jd->infunc(jd, seg, 4) != 4) return JDR_INP; in jd_prepare()
1005 if (jd->infunc(jd, seg, len) != len) return JDR_INP; /* Load segment data */ in jd_prepare()
1007 jd->width = LDB_WORD(&seg[3]); /* Image width in unit of pixel */ in jd_prepare()
1008 jd->height = LDB_WORD(&seg[1]); /* Image height in unit of pixel */ in jd_prepare()
1009 jd->ncomp = seg[5]; /* Number of color components */ in jd_prepare()
1010 …if (jd->ncomp != 3 && jd->ncomp != 1) return JDR_FMT3; /* Err: Supports only Grayscale and Y/Cb/Cr… in jd_prepare()
1013 for (i = 0; i < jd->ncomp; i++) { in jd_prepare()
1019 jd->msx = b >> 4; jd->msy = b & 15; /* Size of MCU [blocks] */ in jd_prepare()
1023 jd->qtid[i] = seg[8 + 3 * i]; /* Get dequantizer table ID for this component */ in jd_prepare()
1024 if (jd->qtid[i] > 3) return JDR_FMT3; /* Err: Invalid ID */ in jd_prepare()
1030 if (jd->infunc(jd, seg, len) != len) return JDR_INP; /* Load segment data */ in jd_prepare()
1032 jd->nrst = LDB_WORD(seg); /* Get restart interval (MCUs) */ in jd_prepare()
1037 if (jd->infunc(jd, seg, len) != len) return JDR_INP; /* Load segment data */ in jd_prepare()
1039 rc = create_huffman_tbl(jd, seg, len); /* Create huffman tables */ in jd_prepare()
1045 if (jd->infunc(jd, seg, len) != len) return JDR_INP; /* Load segment data */ in jd_prepare()
1047 rc = create_qt_tbl(jd, seg, len); /* Create de-quantizer tables */ in jd_prepare()
1053 if (jd->infunc(jd, seg, len) != len) return JDR_INP; /* Load segment data */ in jd_prepare()
1055 if (!jd->width || !jd->height) return JDR_FMT1; /* Err: Invalid image size */ in jd_prepare()
1056 if (seg[0] != jd->ncomp) return JDR_FMT3; /* Err: Wrong color components */ in jd_prepare()
1059 for (i = 0; i < jd->ncomp; i++) { in jd_prepare()
1063 if (!jd->huffbits[n][0] || !jd->huffbits[n][1]) { /* Check huffman table for this component */ in jd_prepare()
1066 if (!jd->qttbl[jd->qtid[i]]) { /* Check dequantizer table for this component */ in jd_prepare()
1072 n = jd->msy * jd->msx; /* Number of Y blocks in the MCU */ in jd_prepare()
1076 …jd->workbuf = alloc_pool(jd, len); /* and it may occupy a part of following MCU working buffer f… in jd_prepare()
1077 if (!jd->workbuf) return JDR_MEM1; /* Err: not enough memory */ in jd_prepare()
1078 jd->mcubuf = alloc_pool(jd, (n + 2) * 64 * sizeof (jd_yuv_t)); /* Allocate MCU working buffer */ in jd_prepare()
1079 if (!jd->mcubuf) return JDR_MEM1; /* Err: not enough memory */ in jd_prepare()
1083 jd->dctr = jd->infunc(jd, seg + ofs, (size_t)(JD_SZBUF - ofs)); in jd_prepare()
1085 jd->dptr = seg + ofs - (JD_FASTDECODE ? 0 : 1); in jd_prepare()
1106 if (jd->infunc(jd, 0, len) != len) return JDR_INP; in jd_prepare()
1119 JDEC* jd, /* Initialized decompression object */ in jd_decomp() argument
1130 jd->scale = scale; in jd_decomp()
1132 mx = jd->msx * 8; my = jd->msy * 8; /* Size of the MCU (pixel) */ in jd_decomp()
1134 jd->dcv[2] = jd->dcv[1] = jd->dcv[0] = 0; /* Initialize DC values */ in jd_decomp()
1138 for (y = 0; y < jd->height; y += my) { /* Vertical loop of MCUs */ in jd_decomp()
1139 for (x = 0; x < jd->width; x += mx) { /* Horizontal loop of MCUs */ in jd_decomp()
1140 if (jd->nrst && rst++ == jd->nrst) { /* Process restart interval if enabled */ in jd_decomp()
1141 rc = restart(jd, rsc++); in jd_decomp()
1145 …rc = mcu_load(jd); /* Load an MCU (decompress huffman coded stream, dequantize and apply IDCT)… in jd_decomp()
1147 rc = mcu_output(jd, outfunc, x, y); /* Output the MCU (YCbCr to RGB, scaling and output) */ in jd_decomp()