📄 jpc_t1enc.c
字号:
one = 1 << (bitpos + JPC_NUMEXTRABITS); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, 0); } } if (term) { jpc_mqenc_flush(mqenc, term - 1); } return jpc_mqenc_error(mqenc) ? (-1) : 0;}#define rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag) \{ \ jpc_fix_t f = *(fp); \ jpc_fix_t v; \ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ v = (abs(*(dp)) & (one)) ? 1 : 0; \ if ((jpc_bitstream_putbit((out), v)) == EOF) { \ return -1; \ } \ if (v) { \ *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ v = ((*(dp) < 0) ? 1 : 0); \ if (jpc_bitstream_putbit(out, v) == EOF) { \ return -1; \ } \ JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ *(fp) |= JPC_SIG; \ } \ *(fp) |= JPC_VISIT; \ } \}static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec){ int i; int j; int k; int one; int vscanlen; int width; int height; int frowstep; int drowstep; int fstripestep; int dstripestep; jpc_fix_t *fstripestart; jpc_fix_t *dstripestart; jpc_fix_t *fp; jpc_fix_t *dp; jpc_fix_t *fvscanstart; jpc_fix_t *dvscanstart; *nmsedec = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << (bitpos + JPC_NUMEXTRABITS); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; } } if (term) { jpc_bitstream_outalign(out, 0x2a); } return 0;}/******************************************************************************\* Code for refinement pass.\******************************************************************************/#define refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag) \{ \ int v; \ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ (d) = *(dp); \ *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ jpc_mqenc_setcurctx((mqenc), JPC_GETMAGCTXNO(*(fp))); \ v = (abs(d) & (one)) ? 1 : 0; \ jpc_mqenc_putbit((mqenc), v); \ *(fp) |= JPC_REFINE; \ } \}static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec){ int i; int j; int one; int vscanlen; int d; int width; int height; int frowstep; int drowstep; int fstripestep; int dstripestep; jpc_fix_t *fstripestart; jpc_fix_t *dstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dvscanstart; jpc_fix_t *dp; jpc_fix_t *fp;int k; *nmsedec = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << (bitpos + JPC_NUMEXTRABITS); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, 0); } } if (term) { jpc_mqenc_flush(mqenc, term - 1); } return jpc_mqenc_error(mqenc) ? (-1) : 0;}#define rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag) \{ \ jpc_fix_t d; \ jpc_fix_t v; \ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ d = *(dp); \ *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ v = (abs(d) & (one)) ? 1 : 0; \ if (jpc_bitstream_putbit((out), v) == EOF) { \ return -1; \ } \ *(fp) |= JPC_REFINE; \ } \}static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec){ int i; int j; int k; int one; int vscanlen; int width; int height; int frowstep; int drowstep; int fstripestep; int dstripestep; jpc_fix_t *fstripestart; jpc_fix_t *dstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dvscanstart; jpc_fix_t *dp; jpc_fix_t *fp; *nmsedec = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << (bitpos + JPC_NUMEXTRABITS); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag); } } if (term) { jpc_bitstream_outalign(out, 0x2a); } return 0;}/******************************************************************************\* Code for cleanup pass.\******************************************************************************/#define clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, label1, label2, vcausalflag) \{ \ int f; \ int v; \label1 \ f = *(fp); \ if (!(f & (JPC_SIG | JPC_VISIT))) { \ jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ v = (abs(*(dp)) & (one)) ? 1 : 0; \ jpc_mqenc_putbit((mqenc), v); \ if (v) { \label2 \ f = *(fp); \ /* Coefficient is significant. */ \ *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ jpc_mqenc_setcurctx((mqenc), JPC_GETSCCTXNO(f)); \ v = ((*(dp) < 0) ? 1 : 0); \ jpc_mqenc_putbit((mqenc), v ^ JPC_GETSPB(f)); \ JPC_UPDATEFLAGS4((fp), (frowstep), v, vcausalflag); \ *(fp) |= JPC_SIG; \ } \ } \ *(fp) &= ~JPC_VISIT; \}static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec){ int i; int j; int k; int vscanlen; int v; int runlen; jpc_fix_t *fp; int width; int height; jpc_fix_t *dp; int one; int frowstep; int drowstep; int fstripestep; int dstripestep; jpc_fix_t *fstripestart; jpc_fix_t *dstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dvscanstart; *nmsedec = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << (bitpos + JPC_NUMEXTRABITS); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; if (vscanlen >= 4 && !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)) && (fp += frowstep, !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) { dp = dvscanstart; for (k = 0; k < vscanlen; ++k) { v = (abs(*dp) & one) ? 1 : 0; if (v) { break; } dp += drowstep; } runlen = k; if (runlen >= 4) { jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); jpc_mqenc_putbit(mqenc, 0); continue; } jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); jpc_mqenc_putbit(mqenc, 1); jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); jpc_mqenc_putbit(mqenc, runlen >> 1); jpc_mqenc_putbit(mqenc, runlen & 1); fp = fvscanstart + frowstep * runlen; dp = dvscanstart + drowstep * runlen; k = vscanlen - runlen; switch (runlen) { case 0: goto clnpass_partial0; break; case 1: goto clnpass_partial1; break; case 2: goto clnpass_partial2; break; case 3: goto clnpass_partial3; break; } } else { runlen = 0; fp = fvscanstart; dp = dvscanstart; k = vscanlen; goto clnpass_full0; } clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, clnpass_full0:, clnpass_partial0:, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, ;, clnpass_partial1:, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, ;, clnpass_partial2:, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, ;, clnpass_partial3:, 0); } } if (segsymflag) { jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); jpc_mqenc_putbit(mqenc, 1); jpc_mqenc_putbit(mqenc, 0); jpc_mqenc_putbit(mqenc, 1); jpc_mqenc_putbit(mqenc, 0); } if (term) { jpc_mqenc_flush(mqenc, term - 1); } return jpc_mqenc_error(mqenc) ? (-1) : 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -