📄 jp2_cod.c
字号:
}static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out){ jp2_cdef_t *cdef = &box->data.cdef; int i; for (i = 0; i < cdef->numchans; ++i) { fprintf(out, "channo=%d; type=%d; assoc=%d\n", cdef->ents[i].channo, cdef->ents[i].type, cdef->ents[i].assoc); }}static void jp2_colr_destroy(jp2_box_t *box){ jp2_colr_t *colr = &box->data.colr; if (colr->iccp) { free(colr->iccp); }}static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in){ jp2_cdef_t *cdef = &box->data.cdef; jp2_cdefchan_t *chan; int channo; if (jp2_getuint16(in, &cdef->numchans)) { return -1; } if (!(cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)))) { return -1; } for (channo = 0; channo < cdef->numchans; ++channo) { chan = &cdef->ents[channo]; if (jp2_getuint16(in, &chan->channo) || jp2_getuint16(in, &chan->type) || jp2_getuint16(in, &chan->assoc)) { return -1; } } return 0;}/******************************************************************************\* Box output.\******************************************************************************/int jp2_box_put(jp2_box_t *box, jas_stream_t *out){ jas_stream_t *tmpstream; bool dataflag; tmpstream = 0; dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA)); if (dataflag) { tmpstream = jas_stream_memopen(0, 0); if (box->ops->putdata) { if ((*box->ops->putdata)(box, tmpstream)) { goto error; } } box->len = jas_stream_tell(tmpstream) + JP2_BOX_HDRLEN; jas_stream_rewind(tmpstream); } /* There was code here in official Jasper to handle 64 bit lengths, but it was based on determining whether box->len fits in 32 bits. But box->len is a 32 bit data type, so it fits in 32 bits by definition. Either this encoder is incapable of making boxes with lengths that don't fit in 32 bits, or it passes invalid values of box->len to us. We assume the former because it's easier. */ if (jp2_putuint32(out, box->len)) { goto error; } if (jp2_putuint32(out, box->type)) { goto error; } if (dataflag) { if (jas_stream_copy(out, tmpstream, box->len - JP2_BOX_HDRLEN)) { goto error; } jas_stream_close(tmpstream); } return 0; abort();error: if (tmpstream) { jas_stream_close(tmpstream); } return -1;}static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out){ jp2_jp_t *jp = &box->data.jp; if (jp2_putuint32(out, jp->magic)) { return -1; } return 0;}static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out){ jp2_ftyp_t *ftyp = &box->data.ftyp; int i; if (jp2_putuint32(out, ftyp->majver) || jp2_putuint32(out, ftyp->minver)) { return -1; } for (i = 0; i < ftyp->numcompatcodes; ++i) { if (jp2_putuint32(out, ftyp->compatcodes[i])) { return -1; } } return 0;}static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out){ jp2_ihdr_t *ihdr = &box->data.ihdr; if (jp2_putuint32(out, ihdr->height) || jp2_putuint32(out, ihdr->width) || jp2_putuint16(out, ihdr->numcmpts) || jp2_putuint8(out, ihdr->bpc) || jp2_putuint8(out, ihdr->comptype) || jp2_putuint8(out, ihdr->csunk) || jp2_putuint8(out, ihdr->ipr)) { return -1; } return 0;}static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out){ jp2_bpcc_t *bpcc = &box->data.bpcc; int i; for (i = 0; i < bpcc->numcmpts; ++i) { if (jp2_putuint8(out, bpcc->bpcs[i])) { return -1; } } return 0;}static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out){ jp2_colr_t *colr = &box->data.colr; if (jp2_putuint8(out, colr->method) || jp2_putuint8(out, colr->pri) || jp2_putuint8(out, colr->approx)) { return -1; } switch (colr->method) { case JP2_COLR_ENUM: if (jp2_putuint32(out, colr->csid)) { return -1; } break; case JP2_COLR_ICC: /* XXX - not implemented */ abort(); break; } return 0;}static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out){ jp2_cdef_t *cdef = &box->data.cdef; int i; jp2_cdefchan_t *ent; if (jp2_putuint16(out, cdef->numchans)) { return -1; } for (i = 0; i < cdef->numchans; ++i) { ent = &cdef->ents[i]; if (jp2_putuint16(out, ent->channo) || jp2_putuint16(out, ent->type) || jp2_putuint16(out, ent->assoc)) { return -1; } } return 0;}/******************************************************************************\* Input operations for primitive types.\******************************************************************************/static int jp2_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;}static int jp2_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;}static int jp2_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;}static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val){ abort();}/******************************************************************************\* Output operations for primitive types.\******************************************************************************/static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val){ if (jas_stream_putc(out, val & 0xff) == EOF) { return -1; } return 0;}static int jp2_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;}static int jp2_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;}/******************************************************************************\* Miscellaneous code.\******************************************************************************/jp2_boxinfo_t *jp2_boxinfolookup(int type){ jp2_boxinfo_t *boxinfo; for (boxinfo = jp2_boxinfos; boxinfo->name; ++boxinfo) { if (boxinfo->type == type) { return boxinfo; } } return &jp2_boxinfo_unk;}static void jp2_cmap_destroy(jp2_box_t *box){ jp2_cmap_t *cmap = &box->data.cmap; if (cmap->ents) { jas_free(cmap->ents); }}static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in){ jp2_cmap_t *cmap = &box->data.cmap; jp2_cmapent_t *ent; int i; cmap->numchans = (box->len - JP2_BOX_HDRLEN) / 4; if (!(cmap->ents = jas_malloc(cmap->numchans * sizeof(jp2_cmapent_t)))) { return -1; } for (i = 0; i < cmap->numchans; ++i) { ent = &cmap->ents[i]; if (jp2_getuint16(in, &ent->cmptno) || jp2_getuint8(in, &ent->map) || jp2_getuint8(in, &ent->pcol)) { return -1; } } return 0;}static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out){ return -1;}static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out){ jp2_cmap_t *cmap = &box->data.cmap; int i; jp2_cmapent_t *ent; fprintf(stderr, "numchans = %d\n", (int) cmap->numchans); for (i = 0; i < cmap->numchans; ++i) { ent = &cmap->ents[i]; fprintf(stderr, "cmptno=%d; map=%d; pcol=%d\n", (int) ent->cmptno, (int) ent->map, (int) ent->pcol); }}static void jp2_pclr_destroy(jp2_box_t *box){ jp2_pclr_t *pclr = &box->data.pclr; if (pclr->lutdata) { jas_free(pclr->lutdata); }}static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in){ jp2_pclr_t *pclr = &box->data.pclr; int lutsize; int i; int j; int_fast32_t x; pclr->lutdata = 0; if (jp2_getuint16(in, &pclr->numlutents) || jp2_getuint8(in, &pclr->numchans)) { return -1; } lutsize = pclr->numlutents * pclr->numchans; if (!(pclr->lutdata = jas_malloc(lutsize * sizeof(int_fast32_t)))) { return -1; } if (!(pclr->bpc = jas_malloc(pclr->numchans * sizeof(uint_fast8_t)))) { return -1; } for (i = 0; i < pclr->numchans; ++i) { if (jp2_getuint8(in, &pclr->bpc[i])) { return -1; } } for (i = 0; i < pclr->numlutents; ++i) { for (j = 0; j < pclr->numchans; ++j) { if (jp2_getint(in, (pclr->bpc[j] & 0x80) != 0, (pclr->bpc[j] & 0x7f) + 1, &x)) { return -1; } pclr->lutdata[i * pclr->numchans + j] = x; } } return 0;}static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out){ /* This code from official Jasper must be part of unfinished work. It generates an unused variable warning. jp2_pclr_t *pclr = &box->data.pclr; */ return -1;}static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out){ jp2_pclr_t *pclr = &box->data.pclr; int i; int j; fprintf(out, "numents=%d; numchans=%d\n", (int) pclr->numlutents, (int) pclr->numchans); for (i = 0; i < pclr->numlutents; ++i) { for (j = 0; j < pclr->numchans; ++j) { fprintf(out, "LUT[%d][%d]=%d\n", i, j, pclr->lutdata[i * pclr->numchans + j]); } }}static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val){ int c; int i; uint_fast32_t v; int m; m = (n + 7) / 8; v = 0; for (i = 0; i < m; ++i) { if ((c = jas_stream_getc(in)) == EOF) { return -1; } v = (v << 8) | c; } v &= ONES(n); if (s) { int sb; sb = v & (1 << (8 * m - 1)); *val = ((~v) + 1) & ONES(8 * m); if (sb) { *val = -*val; } } else { *val = v; } return 0;}jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo){ int i; jp2_cdefchan_t *cdefent; for (i = 0; i < cdef->numchans; ++i) { cdefent = &cdef->ents[i]; if (cdefent->channo == channo) { return cdefent; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -