📄 jpc_cs.c
字号:
uint_fast8_t tmp; poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) : (ms->len / 7); if (!(poc->pchgs = jas_malloc(poc->numpchgs * sizeof(jpc_pocpchg_t)))) { goto error; } for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, ++pchg) { if (jpc_getuint8(in, &pchg->rlvlnostart)) { goto error; } if (cstate->numcomps > 256) { if (jpc_getuint16(in, &pchg->compnostart)) { goto error; } } else { if (jpc_getuint8(in, &tmp)) { goto error; }; pchg->compnostart = tmp; } if (jpc_getuint16(in, &pchg->lyrnoend) || jpc_getuint8(in, &pchg->rlvlnoend)) { goto error; } if (cstate->numcomps > 256) { if (jpc_getuint16(in, &pchg->compnoend)) { goto error; } } else { if (jpc_getuint8(in, &tmp)) { goto error; } pchg->compnoend = tmp; } if (jpc_getuint8(in, &pchg->prgord)) { goto error; } if (pchg->rlvlnostart > pchg->rlvlnoend || pchg->compnostart > pchg->compnoend) { goto error; } } return 0;error: jpc_poc_destroyparms(ms); return -1;}static int jpc_poc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out){ jpc_poc_t *poc = &ms->parms.poc; jpc_pocpchg_t *pchg; int pchgno; for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, ++pchg) { if (jpc_putuint8(out, pchg->rlvlnostart) || ((cstate->numcomps > 256) ? jpc_putuint16(out, pchg->compnostart) : jpc_putuint8(out, pchg->compnostart)) || jpc_putuint16(out, pchg->lyrnoend) || jpc_putuint8(out, pchg->rlvlnoend) || ((cstate->numcomps > 256) ? jpc_putuint16(out, pchg->compnoend) : jpc_putuint8(out, pchg->compnoend)) || jpc_putuint8(out, pchg->prgord)) { return -1; } } return 0;}static int jpc_poc_dumpparms(jpc_ms_t *ms, FILE *out){ jpc_poc_t *poc = &ms->parms.poc; jpc_pocpchg_t *pchg; int pchgno; for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, ++pchg) { fprintf(out, "po[%d] = %d; ", pchgno, pchg->prgord); fprintf(out, "cs[%d] = %d; ce[%d] = %d; ", pchgno, pchg->compnostart, pchgno, pchg->compnoend); fprintf(out, "rs[%d] = %d; re[%d] = %d; ", pchgno, pchg->rlvlnostart, pchgno, pchg->rlvlnoend); fprintf(out, "le[%d] = %d\n", pchgno, pchg->lyrnoend); } return 0;}/******************************************************************************\* CRG marker segment operations.\******************************************************************************/static void jpc_crg_destroyparms(jpc_ms_t *ms){ jpc_crg_t *crg = &ms->parms.crg; if (crg->comps) { jas_free(crg->comps); }}static int jpc_crg_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in){ jpc_crg_t *crg = &ms->parms.crg; jpc_crgcomp_t *comp; uint_fast16_t compno; crg->numcomps = cstate->numcomps; if (!(crg->comps = jas_malloc(cstate->numcomps * sizeof(uint_fast16_t)))) { return -1; } for (compno = 0, comp = crg->comps; compno < cstate->numcomps; ++compno, ++comp) { if (jpc_getuint16(in, &comp->hoff) || jpc_getuint16(in, &comp->voff)) { jpc_crg_destroyparms(ms); return -1; } } return 0;}static int jpc_crg_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out){ jpc_crg_t *crg = &ms->parms.crg; int compno; jpc_crgcomp_t *comp; /* Eliminate compiler warning about unused variables. */ cstate = 0; for (compno = 0, comp = crg->comps; compno < crg->numcomps; ++compno, ++comp) { if (jpc_putuint16(out, comp->hoff) || jpc_putuint16(out, comp->voff)) { return -1; } } return 0;}static int jpc_crg_dumpparms(jpc_ms_t *ms, FILE *out){ jpc_crg_t *crg = &ms->parms.crg; int compno; jpc_crgcomp_t *comp; for (compno = 0, comp = crg->comps; compno < crg->numcomps; ++compno, ++comp) { fprintf(out, "hoff[%d] = %d; voff[%d] = %d\n", compno, comp->hoff, compno, comp->voff); } return 0;}/******************************************************************************\* Operations for COM marker segment.\******************************************************************************/static void jpc_com_destroyparms(jpc_ms_t *ms){ jpc_com_t *com = &ms->parms.com; if (com->data) { jas_free(com->data); }}static int jpc_com_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in){ jpc_com_t *com = &ms->parms.com; /* Eliminate compiler warning about unused variables. */ cstate = 0; if (jpc_getuint16(in, &com->regid)) { return -1; } com->len = ms->len - 2; if (com->len > 0) { if (!(com->data = jas_malloc(com->len))) { return -1; } if (jas_stream_read(in, com->data, com->len) != JAS_CAST(int, com->len)) { return -1; } } else { com->data = 0; } return 0;}static int jpc_com_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out){ jpc_com_t *com = &ms->parms.com; /* Eliminate compiler warning about unused variables. */ cstate = 0; if (jpc_putuint16(out, com->regid)) { return -1; } if (jas_stream_write(out, com->data, com->len) != JAS_CAST(int, com->len)) { return -1; } return 0;}static int jpc_com_dumpparms(jpc_ms_t *ms, FILE *out){ jpc_com_t *com = &ms->parms.com; unsigned int i; int printable; fprintf(out, "regid = %d;\n", com->regid); printable = 1; for (i = 0; i < com->len; ++i) { if (!isprint(com->data[i])) { printable = 0; break; } } if (printable) { fprintf(out, "data = "); fwrite(com->data, sizeof(char), com->len, out); fprintf(out, "\n"); } return 0;}/******************************************************************************\* Operations for unknown types of marker segments.\******************************************************************************/static void jpc_unk_destroyparms(jpc_ms_t *ms){ jpc_unk_t *unk = &ms->parms.unk; if (unk->data) { jas_free(unk->data); }}static int jpc_unk_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in){ jpc_unk_t *unk = &ms->parms.unk; /* Eliminate compiler warning about unused variables. */ cstate = 0; if (ms->len > 0) { if (!(unk->data = jas_malloc(ms->len * sizeof(unsigned char)))) { return -1; } if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) { jas_free(unk->data); return -1; } unk->len = ms->len; } else { unk->data = 0; unk->len = 0; } return 0;}static int jpc_unk_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out){ /* Eliminate compiler warning about unused variables. */ cstate = 0; ms = 0; out = 0; /* If this function is called, we are trying to write an unsupported type of marker segment. Return with an error indication. */ return -1;}static int jpc_unk_dumpparms(jpc_ms_t *ms, FILE *out){ unsigned int i; jpc_unk_t *unk = &ms->parms.unk; for (i = 0; i < unk->len; ++i) { fprintf(out, "%02x ", unk->data[i]); } return 0;}/******************************************************************************\* Primitive I/O operations.\******************************************************************************/int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val){ int c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } if (val) { *val = c; } return 0;}int jpc_putuint8(jas_stream_t *out, uint_fast8_t val){ if (jas_stream_putc(out, val & 0xff) == EOF) { return -1; } return 0;}int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val){ uint_fast16_t v; int c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = (v << 8) | c; if (val) { *val = v; } return 0;}int jpc_putuint16(jas_stream_t *out, uint_fast16_t val){ if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF || jas_stream_putc(out, val & 0xff) == EOF) { return -1; } return 0;}int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val){ uint_fast32_t v; int c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = (v << 8) | c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = (v << 8) | c; if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = (v << 8) | c; if (val) { *val = v; } return 0;}int jpc_putuint32(jas_stream_t *out, uint_fast32_t val){ if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF || jas_stream_putc(out, (val >> 16) & 0xff) == EOF || jas_stream_putc(out, (val >> 8) & 0xff) == EOF || jas_stream_putc(out, val & 0xff) == EOF) { return -1; } return 0;}/******************************************************************************\* Miscellany\******************************************************************************/static jpc_mstabent_t *jpc_mstab_lookup(int id){ jpc_mstabent_t *mstabent; for (mstabent = jpc_mstab;; ++mstabent) { if (mstabent->id == id || mstabent->id < 0) { return mstabent; } } assert(0); return 0;}int jpc_validate(jas_stream_t *in){ int n; int i; unsigned char buf[2]; assert(JAS_STREAM_MAXPUTBACK >= 2); if ((n = jas_stream_read(in, (char *) buf, 2)) < 0) { return -1; } for (i = n - 1; i >= 0; --i) { if (jas_stream_ungetc(in, buf[i]) == EOF) { return -1; } } if (n < 2) { return -1; } if (buf[0] == (JPC_MS_SOC >> 8) && buf[1] == (JPC_MS_SOC & 0xff)) { return 0; } return -1;}int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long len){ return jas_stream_copy(out, in, len);}int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long len){ return jas_stream_copy(out, in, len);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -