Lines Matching refs:jp2
64 static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2,
77 static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
88 static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2,
101 static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2,
106 static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2,
122 static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2,
133 static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2,
145 static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
159 static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2,
164 static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2,
178 static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2,
192 static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
205 static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2,
216 static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2,
226 static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2,
236 static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2,
251 static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2,
265 static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2,
292 static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2,
308 static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2,
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,
355 static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2,
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, in opj_jp2_read_ihdr() argument
568 assert(jp2 != 00); in opj_jp2_read_ihdr()
571 if (jp2->comps != NULL) { in opj_jp2_read_ihdr()
582 opj_read_bytes(p_image_header_data, &(jp2->h), 4); /* HEIGHT */ in opj_jp2_read_ihdr()
584 opj_read_bytes(p_image_header_data, &(jp2->w), 4); /* WIDTH */ in opj_jp2_read_ihdr()
586 opj_read_bytes(p_image_header_data, &(jp2->numcomps), 2); /* NC */ in opj_jp2_read_ihdr()
589 if ((jp2->numcomps - 1U) >= in opj_jp2_read_ihdr()
596 opj_free(jp2->comps); in opj_jp2_read_ihdr()
597 jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, in opj_jp2_read_ihdr()
599 if (jp2->comps == 0) { in opj_jp2_read_ihdr()
605 opj_read_bytes(p_image_header_data, &(jp2->bpc), 1); /* BPC */ in opj_jp2_read_ihdr()
608 opj_read_bytes(p_image_header_data, &(jp2->C), 1); /* C */ in opj_jp2_read_ihdr()
612 if (jp2->C != 7) { in opj_jp2_read_ihdr()
615 jp2->C); in opj_jp2_read_ihdr()
618 opj_read_bytes(p_image_header_data, &(jp2->UnkC), 1); /* UnkC */ in opj_jp2_read_ihdr()
620 opj_read_bytes(p_image_header_data, &(jp2->IPR), 1); /* IPR */ in opj_jp2_read_ihdr()
623 jp2->j2k->m_cp.allow_different_bit_depth_sign = (jp2->bpc == 255); in opj_jp2_read_ihdr()
624 jp2->j2k->ihdr_w = jp2->w; in opj_jp2_read_ihdr()
625 jp2->j2k->ihdr_h = jp2->h; in opj_jp2_read_ihdr()
626 jp2->has_ihdr = 1; in opj_jp2_read_ihdr()
631 static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, in opj_jp2_write_ihdr() argument
638 assert(jp2 != 00); in opj_jp2_write_ihdr()
655 opj_write_bytes(l_current_ihdr_ptr, jp2->h, 4); /* HEIGHT */ in opj_jp2_write_ihdr()
658 opj_write_bytes(l_current_ihdr_ptr, jp2->w, 4); /* WIDTH */ in opj_jp2_write_ihdr()
661 opj_write_bytes(l_current_ihdr_ptr, jp2->numcomps, 2); /* NC */ in opj_jp2_write_ihdr()
664 opj_write_bytes(l_current_ihdr_ptr, jp2->bpc, 1); /* BPC */ in opj_jp2_write_ihdr()
667 opj_write_bytes(l_current_ihdr_ptr, jp2->C, 1); /* C : Always 7 */ in opj_jp2_write_ihdr()
670 opj_write_bytes(l_current_ihdr_ptr, jp2->UnkC, in opj_jp2_write_ihdr()
674 opj_write_bytes(l_current_ihdr_ptr, jp2->IPR, in opj_jp2_write_ihdr()
683 static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2, in opj_jp2_write_bpcc() argument
693 assert(jp2 != 00); in opj_jp2_write_bpcc()
695 l_bpcc_size = 8 + jp2->numcomps; in opj_jp2_write_bpcc()
711 for (i = 0; i < jp2->numcomps; ++i) { in opj_jp2_write_bpcc()
712 opj_write_bytes(l_current_bpcc_ptr, jp2->comps[i].bpcc, in opj_jp2_write_bpcc()
722 static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2, in opj_jp2_read_bpcc() argument
732 assert(jp2 != 00); in opj_jp2_read_bpcc()
736 if (jp2->bpc != 255) { in opj_jp2_read_bpcc()
739 jp2->bpc); in opj_jp2_read_bpcc()
743 if (p_bpc_header_size != jp2->numcomps) { in opj_jp2_read_bpcc()
749 for (i = 0; i < jp2->numcomps; ++i) { in opj_jp2_read_bpcc()
750 opj_read_bytes(p_bpc_header_data, &jp2->comps[i].bpcc, in opj_jp2_read_bpcc()
757 static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2, in opj_jp2_write_cdef() argument
767 assert(jp2 != 00); in opj_jp2_write_cdef()
769 assert(jp2->color.jp2_cdef != 00); in opj_jp2_write_cdef()
770 assert(jp2->color.jp2_cdef->info != 00); in opj_jp2_write_cdef()
771 assert(jp2->color.jp2_cdef->n > 0U); in opj_jp2_write_cdef()
773 l_cdef_size += 6U * jp2->color.jp2_cdef->n; in opj_jp2_write_cdef()
788 l_value = jp2->color.jp2_cdef->n; in opj_jp2_write_cdef()
792 for (i = 0U; i < jp2->color.jp2_cdef->n; ++i) { in opj_jp2_write_cdef()
793 l_value = jp2->color.jp2_cdef->info[i].cn; in opj_jp2_write_cdef()
796 l_value = jp2->color.jp2_cdef->info[i].typ; in opj_jp2_write_cdef()
799 l_value = jp2->color.jp2_cdef->info[i].asoc; in opj_jp2_write_cdef()
808 static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2, in opj_jp2_write_colr() argument
817 assert(jp2 != 00); in opj_jp2_write_colr()
819 assert(jp2->meth == 1 || jp2->meth == 2); in opj_jp2_write_colr()
821 switch (jp2->meth) { in opj_jp2_write_colr()
826 assert(jp2->color.icc_profile_len); /* ICC profile */ in opj_jp2_write_colr()
827 l_colr_size += jp2->color.icc_profile_len; in opj_jp2_write_colr()
847 opj_write_bytes(l_current_colr_ptr, jp2->meth, 1); /* METH */ in opj_jp2_write_colr()
850 opj_write_bytes(l_current_colr_ptr, jp2->precedence, 1); /* PRECEDENCE */ in opj_jp2_write_colr()
853 opj_write_bytes(l_current_colr_ptr, jp2->approx, 1); /* APPROX */ in opj_jp2_write_colr()
856 if (jp2->meth == in opj_jp2_write_colr()
858 opj_write_bytes(l_current_colr_ptr, jp2->enumcs, 4); in opj_jp2_write_colr()
861 if (jp2->meth == 2) { /* ICC profile */ in opj_jp2_write_colr()
863 for (i = 0; i < jp2->color.icc_profile_len; ++i) { in opj_jp2_write_colr()
864 opj_write_bytes(l_current_colr_ptr, jp2->color.icc_profile_buf[i], 1); in opj_jp2_write_colr()
1161 static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, in opj_jp2_read_pclr() argument
1177 assert(jp2 != 00); in opj_jp2_read_pclr()
1181 if (jp2->color.jp2_pclr) { in opj_jp2_read_pclr()
1243 jp2->color.jp2_pclr = jp2_pclr; in opj_jp2_read_pclr()
1275 static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2, in opj_jp2_read_cmap() argument
1286 assert(jp2 != 00); in opj_jp2_read_cmap()
1292 if (jp2->color.jp2_pclr == NULL) { in opj_jp2_read_cmap()
1301 if (jp2->color.jp2_pclr->cmap) { in opj_jp2_read_cmap()
1306 nr_channels = jp2->color.jp2_pclr->nr_channels; in opj_jp2_read_cmap()
1333 jp2->color.jp2_pclr->cmap = cmap; in opj_jp2_read_cmap()
1401 static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2, in opj_jp2_read_cdef() argument
1412 assert(jp2 != 00); in opj_jp2_read_cdef()
1419 if (jp2->color.jp2_cdef) { in opj_jp2_read_cdef()
1448 jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); in opj_jp2_read_cdef()
1449 if (!jp2->color.jp2_cdef) { in opj_jp2_read_cdef()
1453 jp2->color.jp2_cdef->info = cdef_info; in opj_jp2_read_cdef()
1454 jp2->color.jp2_cdef->n = (OPJ_UINT16) l_value; in opj_jp2_read_cdef()
1456 for (i = 0; i < jp2->color.jp2_cdef->n; ++i) { in opj_jp2_read_cdef()
1473 static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, in opj_jp2_read_colr() argument
1482 assert(jp2 != 00); in opj_jp2_read_colr()
1494 if (jp2->color.jp2_has_colr) { in opj_jp2_read_colr()
1501 opj_read_bytes(p_colr_header_data, &jp2->meth, 1); /* METH */ in opj_jp2_read_colr()
1504 opj_read_bytes(p_colr_header_data, &jp2->precedence, 1); /* PRECEDENCE */ in opj_jp2_read_colr()
1507 opj_read_bytes(p_colr_header_data, &jp2->approx, 1); /* APPROX */ in opj_jp2_read_colr()
1510 if (jp2->meth == 1) { in opj_jp2_read_colr()
1517 (jp2->enumcs != 14)) { /* handled below for CIELab) */ in opj_jp2_read_colr()
1523 opj_read_bytes(p_colr_header_data, &jp2->enumcs, 4); /* EnumCS */ in opj_jp2_read_colr()
1527 if (jp2->enumcs == 14) { /* CIELab */ in opj_jp2_read_colr()
1572 jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab; in opj_jp2_read_colr()
1573 jp2->color.icc_profile_len = 0; in opj_jp2_read_colr()
1575 jp2->color.jp2_has_colr = 1; in opj_jp2_read_colr()
1576 } else if (jp2->meth == 2) { in opj_jp2_read_colr()
1581 jp2->color.icc_profile_len = (OPJ_UINT32)icc_len; in opj_jp2_read_colr()
1582 jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1, (size_t)icc_len); in opj_jp2_read_colr()
1583 if (!jp2->color.icc_profile_buf) { in opj_jp2_read_colr()
1584 jp2->color.icc_profile_len = 0; in opj_jp2_read_colr()
1591 jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value; in opj_jp2_read_colr()
1594 jp2->color.jp2_has_colr = 1; in opj_jp2_read_colr()
1595 } else if (jp2->meth > 2) { in opj_jp2_read_colr()
1600 "so we will ignore the entire Colour Specification box. \n", jp2->meth); in opj_jp2_read_colr()
1602 if (jp2->color.jp2_has_colr) { in opj_jp2_read_colr()
1603 jp2->j2k->enumcs = jp2->enumcs; in opj_jp2_read_colr()
1608 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, in opj_jp2_decode() argument
1618 if (! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager)) { in opj_jp2_decode()
1624 if (jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) { in opj_jp2_decode()
1629 if (!jp2->ignore_pclr_cmap_cdef) { in opj_jp2_decode()
1630 if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) { in opj_jp2_decode()
1635 if (jp2->enumcs == 16) { in opj_jp2_decode()
1637 } else if (jp2->enumcs == 17) { in opj_jp2_decode()
1639 } else if (jp2->enumcs == 18) { in opj_jp2_decode()
1641 } else if (jp2->enumcs == 24) { in opj_jp2_decode()
1643 } else if (jp2->enumcs == 12) { in opj_jp2_decode()
1649 if (jp2->color.jp2_pclr) { in opj_jp2_decode()
1651 if (!jp2->color.jp2_pclr->cmap) { in opj_jp2_decode()
1652 opj_jp2_free_pclr(&(jp2->color)); in opj_jp2_decode()
1654 if (!opj_jp2_apply_pclr(p_image, &(jp2->color), p_manager)) { in opj_jp2_decode()
1661 if (jp2->color.jp2_cdef) { in opj_jp2_decode()
1662 opj_jp2_apply_cdef(p_image, &(jp2->color), p_manager); in opj_jp2_decode()
1665 if (jp2->color.icc_profile_buf) { in opj_jp2_decode()
1666 p_image->icc_profile_buf = jp2->color.icc_profile_buf; in opj_jp2_decode()
1667 p_image->icc_profile_len = jp2->color.icc_profile_len; in opj_jp2_decode()
1668 jp2->color.icc_profile_buf = NULL; in opj_jp2_decode()
1675 static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, in opj_jp2_write_jp2h() argument
1693 assert(jp2 != 00); in opj_jp2_write_jp2h()
1698 if (jp2->bpc == 255) { in opj_jp2_write_jp2h()
1709 if (jp2->color.jp2_cdef != NULL) { in opj_jp2_write_jp2h()
1720 l_current_writer->m_data = l_current_writer->handler(jp2, in opj_jp2_write_jp2h()
1782 static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, in opj_jp2_write_ftyp() argument
1793 assert(jp2 != 00); in opj_jp2_write_ftyp()
1795 l_ftyp_size = 16 + 4 * jp2->numcl; in opj_jp2_write_ftyp()
1812 opj_write_bytes(l_current_data_ptr, jp2->brand, 4); /* BR */ in opj_jp2_write_ftyp()
1815 opj_write_bytes(l_current_data_ptr, jp2->minversion, 4); /* MinV */ in opj_jp2_write_ftyp()
1818 for (i = 0; i < jp2->numcl; i++) { in opj_jp2_write_ftyp()
1819 opj_write_bytes(l_current_data_ptr, jp2->cl[i], 4); /* CL */ in opj_jp2_write_ftyp()
1834 static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, in opj_jp2_write_jp2c() argument
1842 assert(jp2 != 00); in opj_jp2_write_jp2c()
1849 (OPJ_UINT32)(j2k_codestream_exit - jp2->j2k_codestream_offset), in opj_jp2_write_jp2c()
1854 if (! opj_stream_seek(cio, jp2->j2k_codestream_offset, p_manager)) { in opj_jp2_write_jp2c()
1872 static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2, in opj_jp2_write_jp() argument
1881 assert(jp2 != 00); in opj_jp2_write_jp()
1884 OPJ_UNUSED(jp2); in opj_jp2_write_jp()
1904 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) in opj_jp2_setup_decoder() argument
1907 opj_j2k_setup_decoder(jp2->j2k, parameters); in opj_jp2_setup_decoder()
1910 jp2->color.jp2_has_colr = 0; in opj_jp2_setup_decoder()
1911 jp2->comps = NULL; in opj_jp2_setup_decoder()
1912 jp2->ignore_pclr_cmap_cdef = parameters->flags & in opj_jp2_setup_decoder()
1916 OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads) in opj_jp2_set_threads() argument
1918 return opj_j2k_set_threads(jp2->j2k, num_threads); in opj_jp2_set_threads()
1925 OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, in opj_jp2_setup_encoder() argument
1938 if (!jp2 || !parameters || !image) { in opj_jp2_setup_encoder()
1952 if (opj_j2k_setup_encoder(jp2->j2k, parameters, image, in opj_jp2_setup_encoder()
1962 jp2->brand = JP2_JP2; /* BR */ in opj_jp2_setup_encoder()
1963 jp2->minversion = 0; /* MinV */ in opj_jp2_setup_encoder()
1964 jp2->numcl = 1; in opj_jp2_setup_encoder()
1965 jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32)); in opj_jp2_setup_encoder()
1966 if (!jp2->cl) { in opj_jp2_setup_encoder()
1971 jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */ in opj_jp2_setup_encoder()
1975 jp2->numcomps = image->numcomps; /* NC */ in opj_jp2_setup_encoder()
1976 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof( in opj_jp2_setup_encoder()
1978 if (!jp2->comps) { in opj_jp2_setup_encoder()
1985 jp2->h = image->y1 - image->y0; /* HEIGHT */ in opj_jp2_setup_encoder()
1986 jp2->w = image->x1 - image->x0; /* WIDTH */ in opj_jp2_setup_encoder()
1990 jp2->bpc = depth_0 + (sign << 7); in opj_jp2_setup_encoder()
1995 jp2->bpc = 255; in opj_jp2_setup_encoder()
1998 jp2->C = 7; /* C : Always 7 */ in opj_jp2_setup_encoder()
1999 jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */ in opj_jp2_setup_encoder()
2000 jp2->IPR = 0; /* IPR, no intellectual property */ in opj_jp2_setup_encoder()
2004 jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7); in opj_jp2_setup_encoder()
2009 jp2->meth = 2; in opj_jp2_setup_encoder()
2010 jp2->enumcs = 0; in opj_jp2_setup_encoder()
2012 jp2->meth = 1; in opj_jp2_setup_encoder()
2014 jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */ in opj_jp2_setup_encoder()
2016 jp2->enumcs = 17; /* greyscale */ in opj_jp2_setup_encoder()
2018 jp2->enumcs = 18; /* YUV */ in opj_jp2_setup_encoder()
2033 switch (jp2->enumcs) { in opj_jp2_setup_encoder()
2062 jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); in opj_jp2_setup_encoder()
2063 if (!jp2->color.jp2_cdef) { in opj_jp2_setup_encoder()
2070 jp2->color.jp2_cdef->info = (opj_jp2_cdef_info_t*) opj_malloc( in opj_jp2_setup_encoder()
2072 if (!jp2->color.jp2_cdef->info) { in opj_jp2_setup_encoder()
2078 jp2->color.jp2_cdef->n = (OPJ_UINT16) in opj_jp2_setup_encoder()
2081 jp2->color.jp2_cdef->info[i].cn = (OPJ_UINT16) in opj_jp2_setup_encoder()
2083 jp2->color.jp2_cdef->info[i].typ = 0U; in opj_jp2_setup_encoder()
2084 jp2->color.jp2_cdef->info[i].asoc = (OPJ_UINT16)(i + in opj_jp2_setup_encoder()
2089 jp2->color.jp2_cdef->info[i].cn = (OPJ_UINT16) in opj_jp2_setup_encoder()
2091 jp2->color.jp2_cdef->info[i].typ = 1U; /* Opacity channel */ in opj_jp2_setup_encoder()
2092 jp2->color.jp2_cdef->info[i].asoc = in opj_jp2_setup_encoder()
2096 jp2->color.jp2_cdef->info[i].cn = (OPJ_UINT16) in opj_jp2_setup_encoder()
2098 jp2->color.jp2_cdef->info[i].typ = 65535U; in opj_jp2_setup_encoder()
2099 jp2->color.jp2_cdef->info[i].asoc = 65535U; in opj_jp2_setup_encoder()
2104 jp2->precedence = 0; /* PRECEDENCE */ in opj_jp2_setup_encoder()
2105 jp2->approx = 0; /* APPROX */ in opj_jp2_setup_encoder()
2107 jp2->jpip_on = parameters->jpip_on; in opj_jp2_setup_encoder()
2112 OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2, in opj_jp2_encode() argument
2116 return opj_j2k_encode(jp2->j2k, stream, p_manager); in opj_jp2_encode()
2119 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, in opj_jp2_end_decompress() argument
2125 assert(jp2 != 00); in opj_jp2_end_decompress()
2130 if (! opj_jp2_setup_end_header_reading(jp2, p_manager)) { in opj_jp2_end_decompress()
2135 if (! opj_jp2_exec(jp2, jp2->m_procedure_list, cio, p_manager)) { in opj_jp2_end_decompress()
2139 return opj_j2k_end_decompress(jp2->j2k, cio, p_manager); in opj_jp2_end_decompress()
2142 OPJ_BOOL opj_jp2_end_compress(opj_jp2_t *jp2, in opj_jp2_end_compress() argument
2148 assert(jp2 != 00); in opj_jp2_end_compress()
2153 if (! opj_jp2_setup_end_header_writing(jp2, p_manager)) { in opj_jp2_end_compress()
2157 if (! opj_j2k_end_compress(jp2->j2k, cio, p_manager)) { in opj_jp2_end_compress()
2162 return opj_jp2_exec(jp2, jp2->m_procedure_list, cio, p_manager); in opj_jp2_end_compress()
2165 static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2, in opj_jp2_setup_end_header_writing() argument
2169 assert(jp2 != 00); in opj_jp2_setup_end_header_writing()
2173 if (jp2->jpip_on) { in opj_jp2_setup_end_header_writing()
2174 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_end_header_writing()
2180 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_end_header_writing()
2186 if (jp2->jpip_on) { in opj_jp2_setup_end_header_writing()
2187 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_end_header_writing()
2191 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_end_header_writing()
2200 static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2, in opj_jp2_setup_end_header_reading() argument
2204 assert(jp2 != 00); in opj_jp2_setup_end_header_reading()
2207 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_end_header_reading()
2216 static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2, in opj_jp2_default_validation() argument
2225 assert(jp2 != 00); in opj_jp2_default_validation()
2235 l_is_valid &= (jp2->jp2_state == JP2_STATE_NONE); in opj_jp2_default_validation()
2238 l_is_valid &= (jp2->jp2_img_state == JP2_IMG_STATE_NONE); in opj_jp2_default_validation()
2242 l_is_valid &= (jp2->j2k != 00); in opj_jp2_default_validation()
2245 l_is_valid &= (jp2->m_procedure_list != 00); in opj_jp2_default_validation()
2248 l_is_valid &= (jp2->m_validation_list != 00); in opj_jp2_default_validation()
2252 l_is_valid &= (jp2->numcl > 0); in opj_jp2_default_validation()
2254 l_is_valid &= (jp2->h > 0); in opj_jp2_default_validation()
2256 l_is_valid &= (jp2->w > 0); in opj_jp2_default_validation()
2258 for (i = 0; i < jp2->numcomps; ++i) { in opj_jp2_default_validation()
2259 l_is_valid &= ((jp2->comps[i].bpcc & 0x7FU) < in opj_jp2_default_validation()
2264 l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3)); in opj_jp2_default_validation()
2273 static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, in opj_jp2_read_header_procedure() argument
2288 assert(jp2 != 00); in opj_jp2_read_header_procedure()
2302 if (jp2->jp2_state & JP2_STATE_HEADER) { in opj_jp2_read_header_procedure()
2303 jp2->jp2_state |= JP2_STATE_CODESTREAM; in opj_jp2_read_header_procedure()
2334 if (jp2->jp2_state & JP2_STATE_HEADER) { in opj_jp2_read_header_procedure()
2342 jp2->jp2_state |= JP2_STATE_UNKNOWN; in opj_jp2_read_header_procedure()
2385 if (! l_current_handler->handler(jp2, l_current_data, l_current_data_size, in opj_jp2_read_header_procedure()
2391 if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) { in opj_jp2_read_header_procedure()
2397 if (!(jp2->jp2_state & JP2_STATE_FILE_TYPE)) { in opj_jp2_read_header_procedure()
2403 jp2->jp2_state |= JP2_STATE_UNKNOWN; in opj_jp2_read_header_procedure()
2406 if (jp2->jp2_state & JP2_STATE_CODESTREAM) { in opj_jp2_read_header_procedure()
2438 static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2, in opj_jp2_exec() argument
2445 OPJ_BOOL(** l_procedure)(opj_jp2_t * jp2, opj_stream_private_t *, in opj_jp2_exec()
2452 assert(jp2 != 00); in opj_jp2_exec()
2457 l_procedure = (OPJ_BOOL(**)(opj_jp2_t * jp2, opj_stream_private_t *, in opj_jp2_exec()
2461 l_result = l_result && (*l_procedure)(jp2, stream, p_manager); in opj_jp2_exec()
2470 OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2, in opj_jp2_start_compress() argument
2477 assert(jp2 != 00); in opj_jp2_start_compress()
2482 if (! opj_jp2_setup_encoding_validation(jp2, p_manager)) { in opj_jp2_start_compress()
2487 if (! opj_jp2_exec(jp2, jp2->m_validation_list, stream, p_manager)) { in opj_jp2_start_compress()
2492 if (! opj_jp2_setup_header_writing(jp2, p_manager)) { in opj_jp2_start_compress()
2497 if (! opj_jp2_exec(jp2, jp2->m_procedure_list, stream, p_manager)) { in opj_jp2_start_compress()
2501 return opj_j2k_start_compress(jp2->j2k, stream, p_image, p_manager); in opj_jp2_start_compress()
2548 static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2, in opj_jp2_read_jp() argument
2559 assert(jp2 != 00); in opj_jp2_read_jp()
2562 if (jp2->jp2_state != JP2_STATE_NONE) { in opj_jp2_read_jp()
2582 jp2->jp2_state |= JP2_STATE_SIGNATURE; in opj_jp2_read_jp()
2597 static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2, in opj_jp2_read_ftyp() argument
2607 assert(jp2 != 00); in opj_jp2_read_ftyp()
2610 if (jp2->jp2_state != JP2_STATE_SIGNATURE) { in opj_jp2_read_ftyp()
2622 opj_read_bytes(p_header_data, &jp2->brand, 4); /* BR */ in opj_jp2_read_ftyp()
2625 opj_read_bytes(p_header_data, &jp2->minversion, 4); /* MinV */ in opj_jp2_read_ftyp()
2637 jp2->numcl = l_remaining_bytes >> 2; in opj_jp2_read_ftyp()
2638 if (jp2->numcl) { in opj_jp2_read_ftyp()
2639 jp2->cl = (OPJ_UINT32 *) opj_calloc(jp2->numcl, sizeof(OPJ_UINT32)); in opj_jp2_read_ftyp()
2640 if (jp2->cl == 00) { in opj_jp2_read_ftyp()
2646 for (i = 0; i < jp2->numcl; ++i) { in opj_jp2_read_ftyp()
2647 opj_read_bytes(p_header_data, &jp2->cl[i], 4); /* CLi */ in opj_jp2_read_ftyp()
2651 jp2->jp2_state |= JP2_STATE_FILE_TYPE; in opj_jp2_read_ftyp()
2656 static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2, in opj_jp2_skip_jp2c() argument
2661 assert(jp2 != 00); in opj_jp2_skip_jp2c()
2665 jp2->j2k_codestream_offset = opj_stream_tell(stream); in opj_jp2_skip_jp2c()
2674 static OPJ_BOOL opj_jpip_skip_iptr(opj_jp2_t *jp2, in opj_jpip_skip_iptr() argument
2679 assert(jp2 != 00); in opj_jpip_skip_iptr()
2683 jp2->jpip_iptr_offset = opj_stream_tell(stream); in opj_jpip_skip_iptr()
2702 static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2, in opj_jp2_read_jp2h() argument
2715 assert(jp2 != 00); in opj_jp2_read_jp2h()
2719 if ((jp2->jp2_state & JP2_STATE_FILE_TYPE) != JP2_STATE_FILE_TYPE) { in opj_jp2_read_jp2h()
2725 jp2->jp2_img_state = JP2_IMG_STATE_NONE; in opj_jp2_read_jp2h()
2748 if (! l_current_handler->handler(jp2, p_header_data, l_current_data_size, in opj_jp2_read_jp2h()
2753 jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN; in opj_jp2_read_jp2h()
2770 jp2->jp2_state |= JP2_STATE_HEADER; in opj_jp2_read_jp2h()
2771 jp2->has_jp2h = 1; in opj_jp2_read_jp2h()
2848 opj_jp2_t *jp2, in opj_jp2_read_header() argument
2854 assert(jp2 != 00); in opj_jp2_read_header()
2859 if (! opj_jp2_setup_decoding_validation(jp2, p_manager)) { in opj_jp2_read_header()
2864 if (! opj_jp2_setup_header_reading(jp2, p_manager)) { in opj_jp2_read_header()
2869 if (! opj_jp2_exec(jp2, jp2->m_validation_list, p_stream, p_manager)) { in opj_jp2_read_header()
2874 if (! opj_jp2_exec(jp2, jp2->m_procedure_list, p_stream, p_manager)) { in opj_jp2_read_header()
2877 if (jp2->has_jp2h == 0) { in opj_jp2_read_header()
2881 if (jp2->has_ihdr == 0) { in opj_jp2_read_header()
2887 jp2->j2k, in opj_jp2_read_header()
2892 static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2, in opj_jp2_setup_encoding_validation() argument
2896 assert(jp2 != 00); in opj_jp2_setup_encoding_validation()
2899 if (! opj_procedure_list_add_procedure(jp2->m_validation_list, in opj_jp2_setup_encoding_validation()
2908 static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2, in opj_jp2_setup_decoding_validation() argument
2912 assert(jp2 != 00); in opj_jp2_setup_decoding_validation()
2915 OPJ_UNUSED(jp2); in opj_jp2_setup_decoding_validation()
2923 static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2, in opj_jp2_setup_header_writing() argument
2927 assert(jp2 != 00); in opj_jp2_setup_header_writing()
2930 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_header_writing()
2934 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_header_writing()
2938 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_header_writing()
2942 if (jp2->jpip_on) { in opj_jp2_setup_header_writing()
2943 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_header_writing()
2948 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_header_writing()
2958 static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2, in opj_jp2_setup_header_reading() argument
2962 assert(jp2 != 00); in opj_jp2_setup_header_reading()
2965 if (! opj_procedure_list_add_procedure(jp2->m_procedure_list, in opj_jp2_setup_header_reading()
3024 void opj_jp2_destroy(opj_jp2_t *jp2) in opj_jp2_destroy() argument
3026 if (jp2) { in opj_jp2_destroy()
3028 opj_j2k_destroy(jp2->j2k); in opj_jp2_destroy()
3029 jp2->j2k = 00; in opj_jp2_destroy()
3031 if (jp2->comps) { in opj_jp2_destroy()
3032 opj_free(jp2->comps); in opj_jp2_destroy()
3033 jp2->comps = 00; in opj_jp2_destroy()
3036 if (jp2->cl) { in opj_jp2_destroy()
3037 opj_free(jp2->cl); in opj_jp2_destroy()
3038 jp2->cl = 00; in opj_jp2_destroy()
3041 if (jp2->color.icc_profile_buf) { in opj_jp2_destroy()
3042 opj_free(jp2->color.icc_profile_buf); in opj_jp2_destroy()
3043 jp2->color.icc_profile_buf = 00; in opj_jp2_destroy()
3046 if (jp2->color.jp2_cdef) { in opj_jp2_destroy()
3047 if (jp2->color.jp2_cdef->info) { in opj_jp2_destroy()
3048 opj_free(jp2->color.jp2_cdef->info); in opj_jp2_destroy()
3049 jp2->color.jp2_cdef->info = NULL; in opj_jp2_destroy()
3052 opj_free(jp2->color.jp2_cdef); in opj_jp2_destroy()
3053 jp2->color.jp2_cdef = 00; in opj_jp2_destroy()
3056 if (jp2->color.jp2_pclr) { in opj_jp2_destroy()
3057 if (jp2->color.jp2_pclr->cmap) { in opj_jp2_destroy()
3058 opj_free(jp2->color.jp2_pclr->cmap); in opj_jp2_destroy()
3059 jp2->color.jp2_pclr->cmap = NULL; in opj_jp2_destroy()
3061 if (jp2->color.jp2_pclr->channel_sign) { in opj_jp2_destroy()
3062 opj_free(jp2->color.jp2_pclr->channel_sign); in opj_jp2_destroy()
3063 jp2->color.jp2_pclr->channel_sign = NULL; in opj_jp2_destroy()
3065 if (jp2->color.jp2_pclr->channel_size) { in opj_jp2_destroy()
3066 opj_free(jp2->color.jp2_pclr->channel_size); in opj_jp2_destroy()
3067 jp2->color.jp2_pclr->channel_size = NULL; in opj_jp2_destroy()
3069 if (jp2->color.jp2_pclr->entries) { in opj_jp2_destroy()
3070 opj_free(jp2->color.jp2_pclr->entries); in opj_jp2_destroy()
3071 jp2->color.jp2_pclr->entries = NULL; in opj_jp2_destroy()
3074 opj_free(jp2->color.jp2_pclr); in opj_jp2_destroy()
3075 jp2->color.jp2_pclr = 00; in opj_jp2_destroy()
3078 if (jp2->m_validation_list) { in opj_jp2_destroy()
3079 opj_procedure_list_destroy(jp2->m_validation_list); in opj_jp2_destroy()
3080 jp2->m_validation_list = 00; in opj_jp2_destroy()
3083 if (jp2->m_procedure_list) { in opj_jp2_destroy()
3084 opj_procedure_list_destroy(jp2->m_procedure_list); in opj_jp2_destroy()
3085 jp2->m_procedure_list = 00; in opj_jp2_destroy()
3088 opj_free(jp2); in opj_jp2_destroy()
3188 opj_jp2_t *jp2 = (opj_jp2_t*)opj_calloc(1, sizeof(opj_jp2_t)); in opj_jp2_create() local
3189 if (jp2) { in opj_jp2_create()
3193 jp2->j2k = opj_j2k_create_compress(); in opj_jp2_create()
3195 jp2->j2k = opj_j2k_create_decompress(); in opj_jp2_create()
3198 if (jp2->j2k == 00) { in opj_jp2_create()
3199 opj_jp2_destroy(jp2); in opj_jp2_create()
3204 jp2->color.icc_profile_buf = NULL; in opj_jp2_create()
3205 jp2->color.icc_profile_len = 0; in opj_jp2_create()
3206 jp2->color.jp2_cdef = NULL; in opj_jp2_create()
3207 jp2->color.jp2_pclr = NULL; in opj_jp2_create()
3208 jp2->color.jp2_has_colr = 0; in opj_jp2_create()
3211 jp2->m_validation_list = opj_procedure_list_create(); in opj_jp2_create()
3212 if (! jp2->m_validation_list) { in opj_jp2_create()
3213 opj_jp2_destroy(jp2); in opj_jp2_create()
3218 jp2->m_procedure_list = opj_procedure_list_create(); in opj_jp2_create()
3219 if (! jp2->m_procedure_list) { in opj_jp2_create()
3220 opj_jp2_destroy(jp2); in opj_jp2_create()
3225 return jp2; in opj_jp2_create()
3258 static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2, in opj_jpip_write_iptr() argument
3266 assert(jp2 != 00); in opj_jpip_write_iptr()
3283 if (! opj_stream_seek(cio, jp2->jpip_iptr_offset, p_manager)) { in opj_jpip_write_iptr()
3301 static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2, in opj_jpip_write_fidx() argument
3308 OPJ_UNUSED(jp2); in opj_jpip_write_fidx()
3311 assert(jp2 != 00); in opj_jpip_write_fidx()
3336 static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2, in opj_jpip_write_cidx() argument
3343 OPJ_UNUSED(jp2); in opj_jpip_write_cidx()
3346 assert(jp2 != 00); in opj_jpip_write_cidx()