/* * Read the JP2H box * * JP2 Header box * */ int jp2_read_jp2h(jp2_struct_t * jp2_struct) { jp2_box_t box; jp2_read_boxhdr(&box); if (JP2_JP2H != box.type) { fprintf(stderr, "Error: Expected JP2H Marker\n"); return 1; } if (jp2_read_ihdr(jp2_struct)) return 1; if (jp2_struct->bpc == 255) if (jp2_read_bpcc(jp2_struct)) return 1; if (jp2_read_colr(jp2_struct)) return 1; if (cio_tell() - box.init_pos != box.length) { fprintf(stderr, "Error with JP2H Box\n"); return 1; } return 0; }
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) { opj_jp2_box_t box; int skip_len; opj_common_ptr cinfo = jp2->cinfo; jp2_read_boxhdr(cinfo, cio, &box); do { if (JP2_JP2H != box.type) { if (box.type == JP2_JP2C) { opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n"); return false; } cio_skip(cio, box.length - 8); jp2_read_boxhdr(cinfo, cio, &box); } } while(JP2_JP2H != box.type); if (!jp2_read_ihdr(jp2, cio)) return false; if (jp2->bpc == 255) { if (!jp2_read_bpcc(jp2, cio)) return false; } if (!jp2_read_colr(jp2, cio)) return false; skip_len = box.init_pos + box.length - cio_tell(cio); if (skip_len < 0) { opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H Box\n"); return false; } cio_skip(cio, box.init_pos + box.length - cio_tell(cio)); return true; }
opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color) { opj_jp2_box_t box; int jp2h_end; opj_common_ptr cinfo = jp2->cinfo; if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; do { if (JP2_JP2H != box.type) { if (box.type == JP2_JP2C) { opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n"); return OPJ_FALSE; } if (box.length <= 8) return OPJ_FALSE; cio_skip(cio, box.length - 8); if(cio->bp >= cio->end) return OPJ_FALSE; if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; } } while(JP2_JP2H != box.type); if (!jp2_read_ihdr(jp2, cio)) return OPJ_FALSE; jp2h_end = box.init_pos + box.length; if (jp2->bpc == 255) { if (!jp2_read_bpcc(jp2, cio)) return OPJ_FALSE; } if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; while(cio_tell(cio) < jp2h_end) { if(box.type == JP2_COLR) { if( !jp2_read_colr(jp2, cio, &box, color)) { if (box.length <= 8) return OPJ_FALSE; cio_seek(cio, box.init_pos + 8); cio_skip(cio, box.length - 8); } if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; continue; } if(box.type == JP2_CDEF && !jp2->ignore_pclr_cmap_cdef) { if( !jp2_read_cdef(jp2, cio, &box, color)) { if (box.length <= 8) return OPJ_FALSE; cio_seek(cio, box.init_pos + 8); cio_skip(cio, box.length - 8); } if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; continue; } if(box.type == JP2_PCLR && !jp2->ignore_pclr_cmap_cdef) { if( !jp2_read_pclr(jp2, cio, &box, color)) { if (box.length <= 8) return OPJ_FALSE; cio_seek(cio, box.init_pos + 8); cio_skip(cio, box.length - 8); } if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; continue; } if(box.type == JP2_CMAP && !jp2->ignore_pclr_cmap_cdef) { if( !jp2_read_cmap(jp2, cio, &box, color)) { if (box.length <= 8) return OPJ_FALSE; cio_seek(cio, box.init_pos + 8); cio_skip(cio, box.length - 8); } if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; continue; } if (box.length <= 8) return OPJ_FALSE; cio_seek(cio, box.init_pos + 8); cio_skip(cio, box.length - 8); if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; }/* while(cio_tell(cio) < box_end) */ cio_seek(cio, jp2h_end); /* Part 1, I.5.3.3 : 'must contain at least one' */ return (color->jp2_has_colr == 1); }/* jp2_read_jp2h() */