Lines Matching refs:jp2
42 /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
58 * @param jp2 the jpeg2000 file codec.
64 static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2,
72 * @param jp2 jpeg2000 file codec.
77 static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
83 * @param jp2 jpeg2000 file codec.
88 static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2,
95 * @param jp2 the jpeg2000 file codec.
101 static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2,
106 static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2,
117 * @param jp2 jpeg2000 file codec.
122 static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2,
128 * @param jp2 jpeg2000 file codec.
133 static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2,
140 * @param jp2 the jpeg2000 file codec.
145 static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
153 * @param jp2 the jpeg2000 file codec.
159 static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2,
164 static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2,
169 * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
172 * @param jp2 the jpeg2000 file codec.
176 * @return true if the JP2 Header box was successfully recognized.
178 static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2,
184 * Writes the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
186 * @param jp2 the jpeg2000 file codec.
192 static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
200 * @param jp2 the jpeg2000 file codec.
205 static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2,
213 * @param jp2 the jpeg2000 file codec.
216 static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2,
223 * @param jp2 the jpeg2000 file codec.
226 static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2,
233 * @param jp2 the jpeg2000 file codec.
236 static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2,
245 * @param jp2 the jpeg2000 file codec.
251 static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2,
260 * @param jp2 the jpeg2000 file codec.
265 static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2,
285 * @param jp2 JP2 handle
292 static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2,
300 * @param jp2 JP2 handle
308 static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2,
317 * @param jp2 the jpeg2000 file codec.
323 static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2,
336 static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2,
343 static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2,
349 * @param jp2 the jpeg2000 file header structure.
355 static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2,
363 * @param jp2 the jpeg2000 file codec to execute the procedures on.
369 static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2,
393 static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2,
399 static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2,
402 static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2,
462 static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2,
469 static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2,
561 static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2,
568 assert(jp2 != 00);
571 if (jp2->comps != NULL) {
582 opj_read_bytes(p_image_header_data, &(jp2->h), 4); /* HEIGHT */
584 opj_read_bytes(p_image_header_data, &(jp2->w), 4); /* WIDTH */
586 opj_read_bytes(p_image_header_data, &(jp2->numcomps), 2); /* NC */
589 if ((jp2->numcomps - 1U) >=
590 16384U) { /* unsigned underflow is well defined: 1U <= jp2->numcomps <= 16384U */
596 opj_free(jp2->comps);
597 jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps,
599 if (jp2->comps == 0) {
605 opj_read_bytes(p_image_header_data, &(jp2->bpc), 1); /* BPC */
608 opj_read_bytes(p_image_header_data, &(jp2->C), 1); /* C */
612 if (jp2->C != 7) {
614 "JP2 IHDR box: compression type indicate that the file is not a conforming JP2 file (%d) \n",
615 jp2->C);
618 opj_read_bytes(p_image_header_data, &(jp2->UnkC), 1); /* UnkC */
620 opj_read_bytes(p_image_header_data, &(jp2->IPR), 1); /* IPR */
623 jp2->j2k->m_cp.allow_different_bit_depth_sign = (jp2->bpc == 255);
624 jp2->j2k->ihdr_w = jp2->w;
625 jp2->j2k->ihdr_h = jp2->h;
626 jp2->has_ihdr = 1;
631 static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
638 assert(jp2 != 00);
655 opj_write_bytes(l_current_ihdr_ptr, jp2->h, 4); /* HEIGHT */
658 opj_write_bytes(l_current_ihdr_ptr, jp2->w, 4); /* WIDTH */
661 opj_write_bytes(l_current_ihdr_ptr, jp2->numcomps, 2); /* NC */
664 opj_write_bytes(l_current_ihdr_ptr, jp2->bpc, 1); /* BPC */
667 opj_write_bytes(l_current_ihdr_ptr, jp2->C, 1); /* C : Always 7 */
670 opj_write_bytes(l_current_ihdr_ptr, jp2->UnkC,
674 opj_write_bytes(l_current_ihdr_ptr, jp2->IPR,
683 static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2,
693 assert(jp2 != 00);
695 l_bpcc_size = 8 + jp2->numcomps;
711 for (i = 0; i < jp2->numcomps; ++i) {
712 opj_write_bytes(l_current_bpcc_ptr, jp2->comps[i].bpcc,
722 static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2,
732 assert(jp2 != 00);
736 if (jp2->bpc != 255) {
739 jp2->bpc);
743 if (p_bpc_header_size != jp2->numcomps) {
749 for (i = 0; i < jp2->numcomps; ++i) {
750 opj_read_bytes(p_bpc_header_data, &jp2->comps[i].bpcc,
757 static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2,
767 assert(jp2 != 00);
769 assert(jp2->color.jp2_cdef != 00);
770 assert(jp2->color.jp2_cdef->info != 00);
771 assert(jp2->color.jp2_cdef->n > 0U);
773 l_cdef_size += 6U * jp2->color.jp2_cdef->n;
788 l_value = jp2->color.jp2_cdef->n;
792 for (i = 0U; i < jp2->color.jp2_cdef->n; ++i) {
793 l_value = jp2->color.jp2_cdef->info[i].cn;
796 l_value = jp2->color.jp2_cdef->info[i].typ;
799 l_value = jp2->color.jp2_cdef->info[i].asoc;
808 static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2,
817 assert(jp2 != 00);
819 assert(jp2->meth == 1 || jp2->meth == 2);
821 switch (jp2->meth) {
826 assert(jp2->color.icc_profile_len); /* ICC profile */
827 l_colr_size += jp2->color.icc_profile_len;
847 opj_write_bytes(l_current_colr_ptr, jp2->meth, 1); /* METH */
850 opj_write_bytes(l_current_colr_ptr, jp2->precedence, 1); /* PRECEDENCE */
853 opj_write_bytes(l_current_colr_ptr, jp2->approx, 1); /* APPROX */
856 if (jp2->meth ==
858 opj_write_bytes(l_current_colr_ptr, jp2->enumcs, 4);
861 if (jp2->meth == 2) { /* ICC profile */
863 for (i = 0; i < jp2->color.icc_profile_len; ++i) {
864 opj_write_bytes(l_current_colr_ptr, jp2->color.icc_profile_buf[i], 1);
899 image->numcomps; /* FIXME image->numcomps == jp2->numcomps before color is applied ??? */
1030 /* file9.jp2 */
1162 static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2,
1178 assert(jp2 != 00);
1182 if (jp2->color.jp2_pclr) {
1244 jp2->color.jp2_pclr = jp2_pclr;
1276 static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2,
1287 assert(jp2 != 00);
1293 if (jp2->color.jp2_pclr == NULL) {
1300 * inside a JP2 Header box' :
1302 if (jp2->color.jp2_pclr->cmap) {
1307 nr_channels = jp2->color.jp2_pclr->nr_channels;
1334 jp2->color.jp2_pclr->cmap = cmap;
1402 static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2,
1413 assert(jp2 != 00);
1419 * inside a JP2 Header box.'*/
1420 if (jp2->color.jp2_cdef) {
1449 jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
1450 if (!jp2->color.jp2_cdef) {
1454 jp2->color.jp2_cdef->info = cdef_info;
1455 jp2->color.jp2_cdef->n = (OPJ_UINT16) l_value;
1457 for (i = 0; i < jp2->color.jp2_cdef->n; ++i) {
1474 static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2,
1483 assert(jp2 != 00);
1492 /* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour
1495 if (jp2->color.jp2_has_colr) {
1497 "A conforming JP2 reader shall ignore all Colour Specification boxes after the first, so we ignore this one.\n");
1502 opj_read_bytes(p_colr_header_data, &jp2->meth, 1); /* METH */
1505 opj_read_bytes(p_colr_header_data, &jp2->precedence, 1); /* PRECEDENCE */
1508 opj_read_bytes(p_colr_header_data, &jp2->approx, 1); /* APPROX */
1511 if (jp2->meth == 1) {
1518 (jp2->enumcs != 14)) { /* handled below for CIELab) */
1524 opj_read_bytes(p_colr_header_data, &jp2->enumcs, 4); /* EnumCS */
1528 if (jp2->enumcs == 14) { /* CIELab */
1573 jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab;
1574 jp2->color.icc_profile_len = 0;
1576 jp2->color.jp2_has_colr = 1;
1577 } else if (jp2->meth == 2) {
1582 jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
1583 jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1, (size_t)icc_len);
1584 if (!jp2->color.icc_profile_buf) {
1585 jp2->color.icc_profile_len = 0;
1592 jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
1595 jp2->color.jp2_has_colr = 1;
1596 } else if (jp2->meth > 2) {
1598 conforming JP2 reader shall ignore the entire Colour Specification box.*/
1601 "so we will ignore the entire Colour Specification box. \n", jp2->meth);
1603 if (jp2->color.jp2_has_colr) {
1604 jp2->j2k->enumcs = jp2->enumcs;
1609 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
1619 if (! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager)) {
1621 "Failed to decode the codestream in the JP2 file\n");
1625 if (jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) {
1626 /* Bypass all JP2 component transforms */
1630 if (!jp2->ignore_pclr_cmap_cdef) {
1631 if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) {
1636 if (jp2->enumcs == 16) {
1638 } else if (jp2->enumcs == 17) {
1640 } else if (jp2->enumcs == 18) {
1642 } else if (jp2->enumcs == 24) {
1644 } else if (jp2->enumcs == 12) {
1650 if (jp2->color.jp2_pclr) {
1652 if (!jp2->color.jp2_pclr->cmap) {
1653 opj_jp2_free_pclr(&(jp2->color));
1655 if (!opj_jp2_apply_pclr(p_image, &(jp2->color), p_manager)) {
1662 if (jp2->color.jp2_cdef) {
1663 opj_jp2_apply_cdef(p_image, &(jp2->color), p_manager);
1666 if (jp2->color.icc_profile_buf) {
1667 p_image->icc_profile_buf = jp2->color.icc_profile_buf;
1668 p_image->icc_profile_len = jp2->color.icc_profile_len;
1669 jp2->color.icc_profile_buf = NULL;
1676 static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
1694 assert(jp2 != 00);
1699 if (jp2->bpc == 255) {
1710 if (jp2->color.jp2_cdef != NULL) {
1721 l_current_writer->m_data = l_current_writer->handler(jp2,
1725 "Not enough memory to hold JP2 Header data\n");
1752 "Stream error while writing JP2 Header box\n");
1762 "Stream error while writing JP2 Header box\n");
1783 static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
1794 assert(jp2 != 00);
1796 l_ftyp_size = 16 + 4 * jp2->numcl;
1813 opj_write_bytes(l_current_data_ptr, jp2->brand, 4); /* BR */
1816 opj_write_bytes(l_current_data_ptr, jp2->minversion, 4); /* MinV */
1819 for (i = 0; i < jp2->numcl; i++) {
1820 opj_write_bytes(l_current_data_ptr, jp2->cl[i], 4); /* CL */
1835 static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2,
1843 assert(jp2 != 00);
1850 (OPJ_UINT32)(j2k_codestream_exit - jp2->j2k_codestream_offset),
1855 if (! opj_stream_seek(cio, jp2->j2k_codestream_offset, p_manager)) {
1873 static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2,
1882 assert(jp2 != 00);
1885 OPJ_UNUSED(jp2);
1902 /* JP2 decoder interface */
1905 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
1908 opj_j2k_setup_decoder(jp2->j2k, parameters);
1910 /* further JP2 initializations go here */
1911 jp2->color.jp2_has_colr = 0;
1912 jp2->comps = NULL;
1913 jp2->ignore_pclr_cmap_cdef = parameters->flags &
1917 OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads)
1919 return opj_j2k_set_threads(jp2
1923 /* JP2 encoder interface */
1926 OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2,
1939 if (!jp2 || !parameters || !image) {
1949 "Invalid number of components specified while setting up JP2 encoder\n");
1953 if (opj_j2k_setup_encoder(jp2->j2k, parameters, image,
1958 /* setup the JP2 codec */
1963 jp2->brand = JP2_JP2; /* BR */
1964 jp2->minversion = 0; /* MinV */
1965 jp2->numcl = 1;
1966 jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
1967 if (!jp2->cl) {
1969 "Not enough memory when setup the JP2 encoder\n");
1972 jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
1976 jp2->numcomps = image->numcomps; /* NC */
1977 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(
1979 if (!jp2->comps) {
1981 "Not enough memory when setup the JP2 encoder\n");
1982 /* Memory of jp2->cl will be freed by opj_jp2_destroy */
1986 jp2->h = image->y1 - image->y0; /* HEIGHT */
1987 jp2->w = image->x1 - image->x0; /* WIDTH */
1991 jp2->bpc = depth_0 + (sign << 7);
1996 jp2->bpc = 255;
1999 jp2->C = 7; /* C : Always 7 */
2000 jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */
2001 jp2->IPR = 0; /* IPR, no intellectual property */
2005 jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
2010 jp2->meth = 2;
2011 jp2->enumcs = 0;
2013 jp2->meth = 1;
2015 jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */
2017 jp2->enumcs = 17; /* greyscale */
2019 jp2->enumcs = 18; /* YUV */
2034 switch (jp2->enumcs) {
2063 jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
2064 if (!jp2->color.jp2_cdef) {
2066 "Not enough memory to setup the JP2 encoder\n");
2069 /* no memset needed, all values will be overwritten except if jp2->color.jp2_cdef->info allocation fails, */
2070 /* in which case jp2->color.jp2_cdef->info will be NULL => valid for destruction */
2071 jp2->color.jp2_cdef->info = (opj_jp2_cdef_info_t*) opj_malloc(
2073 if (!jp2->color.jp2_cdef->info) {
2076 "Not enough memory to setup the JP2 encoder\n");
2079 jp2->color.jp2_cdef->n = (OPJ_UINT16)
2082 jp2->color.jp2_cdef->info[i].cn = (OPJ_UINT16)
2084 jp2->color.jp2_cdef->info[i].typ = 0U;
2085 jp2->color.jp2_cdef->info[i].asoc = (OPJ_UINT16)(i +
2090 jp2->color.jp2_cdef->info[i].cn = (OPJ_UINT16)
2092 jp2->color.jp2_cdef->info[i].typ = 1U; /* Opacity channel */
2093 jp2->color.jp2_cdef->info[i].asoc =
2097 jp2->color.jp2_cdef->info[i].cn = (OPJ_UINT16)
2099 jp2->color.jp2_cdef->info[i].typ = 65535U;
2100 jp2->color.jp2_cdef->info[i].asoc = 65535U;
2105 jp2->precedence = 0; /* PRECEDENCE */
2106 jp2->approx = 0; /* APPROX */
2108 jp2->jpip_on = parameters->jpip_on;
2113 OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
2117 return opj_j2k_encode(jp2->j2k, stream, p_manager);
2120 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
2126 assert(jp2 != 00);
2131 if (! opj_jp2_setup_end_header_reading(jp2, p_manager)) {
2136 if (! opj_jp2_exec(jp2, jp2->m_procedure_list, cio, p_manager)) {
2140 return opj_j2k_end_decompress(jp2->j2k, cio, p_manager);
2143 OPJ_BOOL opj_jp2_end_compress(opj_jp2_t *jp2,
2149 assert(jp2 != 00);
2154 if (! opj_jp2_setup_end_header_writing(jp2, p_manager)) {
2158 if (! opj_j2k_end_compress(jp2->j2k, cio, p_manager)) {
2163 return opj_jp2_exec(jp2, jp2->m_procedure_list, cio, p_manager);
2166 static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2,
2170 assert(jp2 != 00);
2174 if (jp2->jpip_on) {
2175 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2181 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2187 if (jp2->jpip_on) {
2188 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2192 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2201 static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2,
2205 assert(jp2 != 00);
2208 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2217 static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2,
2226 assert(jp2 != 00);
2236 l_is_valid &= (jp2->jp2_state == JP2_STATE_NONE);
2239 l_is_valid &= (jp2->jp2_img_state == JP2_IMG_STATE_NONE);
2243 l_is_valid &= (jp2->j2k != 00);
2246 l_is_valid &= (jp2->m_procedure_list != 00);
2249 l_is_valid &= (jp2->m_validation_list != 00);
2253 l_is_valid &= (jp2->numcl > 0);
2255 l_is_valid &= (jp2->h > 0);
2257 l_is_valid &= (jp2->w > 0);
2259 for (i = 0; i < jp2->numcomps; ++i) {
2260 l_is_valid &= ((jp2->comps[i].bpcc & 0x7FU) <
2265 l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3));
2274 static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2,
2289 assert(jp2 != 00);
2303 if (jp2->jp2_state & JP2_STATE_HEADER) {
2304 jp2->jp2_state |= JP2_STATE_CODESTREAM;
2335 if (jp2->jp2_state & JP2_STATE_HEADER) {
2343 jp2->jp2_state |= JP2_STATE_UNKNOWN;
2386 if (! l_current_handler->handler(jp2, l_current_data, l_current_data_size,
2392 if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) {
2394 "Malformed JP2 file format: first box must be JPEG 2000 signature box\n");
2398 if (!(jp2->jp2_state & JP2_STATE_FILE_TYPE)) {
2400 "Malformed JP2 file format: second box must be file type box\n");
2404 jp2->jp2_state |= JP2_STATE_UNKNOWN;
2407 if (jp2->jp2_state & JP2_STATE_CODESTREAM) {
2409 /* Needed for data/input/nonregression/issue254.jp2 */
2433 * @param jp2 the jpeg2000 file codec to execute the procedures on.
2439 static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2,
2446 OPJ_BOOL(** l_procedure)(opj_jp2_t * jp2, opj_stream_private_t *,
2453 assert(jp2 != 00);
2458 l_procedure = (OPJ_BOOL(**)(opj_jp2_t * jp2, opj_stream_private_t *,
2462 l_result = l_result && (*l_procedure)(jp2, stream, p_manager);
2471 OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
2478 assert(jp2 != 00);
2483 if (! opj_jp2_setup_encoding_validation(jp2, p_manager)) {
2488 if (! opj_jp2_exec(jp2, jp2->m_validation_list, stream, p_manager)) {
2493 if (! opj_jp2_setup_header_writing(jp2, p_manager)) {
2498 if (! opj_jp2_exec(jp2, jp2->m_procedure_list, stream, p_manager)) {
2502 return opj_j2k_start_compress(jp2->j2k, stream, p_image, p_manager);
2543 * @param jp2 the jpeg2000 file codec.
2549 static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2,
2560 assert(jp2 != 00);
2563 if (jp2->jp2_state != JP2_STATE_NONE) {
2583 jp2->jp2_state |= JP2_STATE_SIGNATURE;
2592 * @param jp2 the jpeg2000 file codec.
2598 static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2,
2608 assert(jp2 != 00);
2611 if (jp2->jp2_state != JP2_STATE_SIGNATURE) {
2623 opj_read_bytes(p_header_data, &jp2->brand, 4); /* BR */
2626 opj_read_bytes(p_header_data, &jp2->minversion, 4); /* MinV */
2638 jp2->numcl = l_remaining_bytes >> 2;
2639 if (jp2->numcl) {
2640 jp2->cl = (OPJ_UINT32 *) opj_calloc(jp2->numcl, sizeof(OPJ_UINT32));
2641 if (jp2->cl == 00) {
2647 for (i = 0; i < jp2->numcl; ++i) {
2648 opj_read_bytes(p_header_data, &jp2->cl[i], 4); /* CLi */
2652 jp2->jp2_state |= JP2_STATE_FILE_TYPE;
2657 static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2,
2662 assert(jp2 != 00);
2666 jp2->j2k_codestream_offset = opj_stream_tell(stream);
2675 static OPJ_BOOL opj_jpip_skip_iptr(opj_jp2_t *jp2,
2680 assert(jp2 != 00);
2684 jp2->jpip_iptr_offset = opj_stream_tell(stream);
2694 * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
2697 * @param jp2 the jpeg2000 file codec.
2701 * @return true if the JP2 Header box was successfully recognized.
2703 static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2,
2716 assert(jp2 != 00);
2720 if ((jp2->jp2_state & JP2_STATE_FILE_TYPE) != JP2_STATE_FILE_TYPE) {
2726 jp2->jp2_img_state = JP2_IMG_STATE_NONE;
2734 "Stream error while reading JP2 Header box\n");
2740 "Stream error while reading JP2 Header box: box length is inconsistent.\n");
2749 if (! l_current_handler->handler(jp2, p_header_data, l_current_data_size,
2754 jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
2767 "Stream error while reading JP2 Header box: no 'ihdr' box.\n");
2771 jp2->jp2_state |= JP2_STATE_HEADER;
2772 jp2->has_jp2h = 1;
2849 opj_jp2_t *jp2,
2855 assert(jp2 != 00);
2860 if (! opj_jp2_setup_decoding_validation(jp2, p_manager)) {
2865 if (! opj_jp2_setup_header_reading(jp2
2870 if (! opj_jp2_exec(jp2, jp2->m_validation_list, p_stream, p_manager)) {
2875 if (! opj_jp2_exec(jp2, jp2->m_procedure_list, p_stream, p_manager)) {
2878 if (jp2->has_jp2h == 0) {
2882 if (jp2->has_ihdr == 0) {
2888 jp2->j2k,
2893 static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2,
2897 assert(jp2 != 00);
2900 if (! opj_procedure_list_add_procedure(jp2->m_validation_list,
2909 static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2,
2913 assert(jp2 != 00);
2916 OPJ_UNUSED(jp2);
2924 static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2,
2928 assert(jp2 != 00);
2931 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2935 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2939 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2943 if (jp2->jpip_on) {
2944 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2949 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
2959 static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2,
2963 assert(jp2 != 00);
2966 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,
3025 void opj_jp2_destroy(opj_jp2_t *jp2)
3027 if (jp2) {
3029 opj_j2k_destroy(jp2->j2k);
3030 jp2->j2k = 00;
3032 if (jp2->comps) {
3033 opj_free(jp2->comps);
3034 jp2->comps = 00;
3037 if (jp2->cl) {
3038 opj_free(jp2->cl);
3039 jp2->cl = 00;
3042 if (jp2->color.icc_profile_buf) {
3043 opj_free(jp2->color.icc_profile_buf);
3044 jp2->color.icc_profile_buf = 00;
3047 if (jp2->color.jp2_cdef) {
3048 if (jp2->color.jp2_cdef->info) {
3049 opj_free(jp2->color.jp2_cdef->info);
3050 jp2->color.jp2_cdef->info = NULL;
3053 opj_free(jp2->color.jp2_cdef);
3054 jp2->color.jp2_cdef = 00;
3057 if (jp2->color.jp2_pclr) {
3058 if (jp2->color.jp2_pclr->cmap) {
3059 opj_free(jp2->color.jp2_pclr->cmap);
3060 jp2->color.jp2_pclr->cmap = NULL;
3062 if (jp2->color.jp2_pclr->channel_sign) {
3063 opj_free(jp2->color.jp2_pclr->channel_sign);
3064 jp2->color.jp2_pclr->channel_sign = NULL;
3066 if (jp2->color.jp2_pclr->channel_size) {
3067 opj_free(jp2->color.jp2_pclr->channel_size);
3068 jp2->color.jp2_pclr->channel_size = NULL;
3070 if (jp2->color.jp2_pclr->entries) {
3071 opj_free(jp2->color.jp2_pclr->entries);
3072 jp2->color.jp2_pclr->entries = NULL;
3075 opj_free(jp2->color.jp2_pclr);
3076 jp2->color.jp2_pclr = 00;
3079 if (jp2->m_validation_list) {
3080 opj_procedure_list_destroy(jp2->m_validation_list);
3081 jp2->m_validation_list = 00;
3084 if (jp2->m_procedure_list) {
3085 opj_procedure_list_destroy(jp2->m_procedure_list);
3086 jp2->m_procedure_list = 00;
3089 opj_free(jp2);
3126 "JP2 box which are after the codestream will not be read by this function.\n");
3130 "Failed to decode the codestream in the JP2 file\n");
3135 /* Bypass all JP2 component transforms */
3184 /* JP2 encoder interface */
3189 opj_jp2_t *jp2 = (opj_jp2_t*)opj_calloc(1, sizeof(opj_jp2_t));
3190 if (jp2) {
3194 jp2->j2k = opj_j2k_create_compress();
3196 jp2->j2k = opj_j2k_create_decompress();
3199 if (jp2->j2k == 00) {
3200 opj_jp2_destroy(jp2);
3205 jp2->color.icc_profile_buf = NULL;
3206 jp2->color.icc_profile_len = 0;
3207 jp2->color.jp2_cdef = NULL;
3208 jp2->color.jp2_pclr = NULL;
3209 jp2->color.jp2_has_colr = 0;
3212 jp2->m_validation_list = opj_procedure_list_create();
3213 if (! jp2->m_validation_list) {
3214 opj_jp2_destroy(jp2);
3219 jp2->m_procedure_list = opj_procedure_list_create();
3220 if (! jp2->m_procedure_list) {
3221 opj_jp2_destroy(jp2);
3226 return jp2;
3259 static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2,
3267 assert(jp2 != 00);
3284 if (! opj_stream_seek(cio, jp2->jpip_iptr_offset, p_manager)) {
3302 static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2,
3309 OPJ_UNUSED(jp2);
3312 assert(jp2 != 00);
3337 static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2,
3344 OPJ_UNUSED(jp2);
3347 assert(jp2 != 00);