Write COC/QCC in Main Header

Update uclouvain/openjpeg#459
This commit is contained in:
mayeut 2015-07-29 00:29:49 +02:00
parent 2263b6bacc
commit c3d9719cd4
1 changed files with 104 additions and 38 deletions

View File

@ -283,6 +283,19 @@ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size ( opj_j2k_t *p_j2k,
OPJ_UINT32 p_tile_no,
OPJ_UINT32 p_comp_no );
/**
* Compares 2 SQcd or SQcc element, i.e. the quantization values of a band in the QCD or QCC.
*
* @param p_j2k J2K codec.
* @param p_tile_no the tile to output.
* @param p_first_comp_no the first component number to compare.
* @param p_second_comp_no the second component number to compare.
*
* @return OPJ_TRUE if equals.
*/
static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no);
/**
* Writes a SQcd or SQcc element, i.e. the quantization values of a band in the QCD or QCC.
*
@ -496,6 +509,17 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k,
OPJ_UINT32 p_header_size,
opj_event_mgr_t * p_manager);
/**
* Compares 2 COC markers (Coding style component)
*
* @param p_j2k J2K codec.
* @param p_first_comp_no the index of the first component to compare.
* @param p_second_comp_no the index of the second component to compare.
*
* @return OPJ_TRUE if equals
*/
static OPJ_BOOL opj_j2k_compare_coc(opj_j2k_t *p_j2k, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no);
/**
* Writes the COC marker (Coding style component)
*
@ -566,6 +590,17 @@ static OPJ_BOOL opj_j2k_read_qcd ( opj_j2k_t *p_j2k,
OPJ_UINT32 p_header_size,
opj_event_mgr_t * p_manager );
/**
* Compare QCC markers (quantization component)
*
* @param p_j2k J2K codec.
* @param p_first_comp_no the index of the first component to compare.
* @param p_second_comp_no the index of the second component to compare.
*
* @return OPJ_TRUE if equals.
*/
static OPJ_BOOL opj_j2k_compare_qcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no);
/**
* Writes the QCC marker (quantization component)
*
@ -2872,6 +2907,11 @@ static OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k,
return OPJ_TRUE;
}
static OPJ_BOOL opj_j2k_compare_qcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no)
{
return opj_j2k_compare_SQcd_SQcc(p_j2k,p_j2k->m_current_tile_number,p_first_comp_no, p_second_comp_no);
}
static void opj_j2k_write_qcc_in_memory( opj_j2k_t *p_j2k,
OPJ_UINT32 p_comp_no,
OPJ_BYTE * p_data,
@ -4895,27 +4935,17 @@ static OPJ_BOOL opj_j2k_write_all_coc(
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager )
{
OPJ_UINT32 compno, compno2;
OPJ_BOOL needed = OPJ_FALSE;
OPJ_UINT32 compno;
/* preconditions */
assert(p_j2k != 00);
assert(p_manager != 00);
assert(p_stream != 00);
for (compno = 0; compno < (p_j2k->m_private_image->numcomps - 1U); ++compno)
{
for (compno2 = compno = 1U; compno2 < p_j2k->m_private_image->numcomps; ++compno2)
{
if (opj_j2k_compare_coc(p_j2k, compno, compno2) == OPJ_FALSE) {
needed = OPJ_TRUE;
}
}
}
if (needed != OPJ_FALSE) {
for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno)
for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno)
{
/* cod is first component of first tile */
if (! opj_j2k_compare_coc(p_j2k, 0, compno)) {
if (! opj_j2k_write_coc(p_j2k,compno,p_stream, p_manager)) {
return OPJ_FALSE;
}
@ -4930,35 +4960,23 @@ static OPJ_BOOL opj_j2k_write_all_qcc(
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager )
{
OPJ_UINT32 compno, compno2;
OPJ_BOOL needed = OPJ_FALSE;
OPJ_UINT32 compno;
/* preconditions */
assert(p_j2k != 00);
assert(p_manager != 00);
assert(p_stream != 00);
/*
for (compno = 0; compno < (p_j2k->m_private_image->numcomps - 1U); ++compno)
{
for (compno2 = compno = 1U; compno2 < p_j2k->m_private_image->numcomps; ++compno2)
{
if (opj_j2k_compare_qcc(p_j2k, compno, compno2) == OPJ_FALSE) {
needed = OPJ_TRUE;
}
}
}*/
if (needed != OPJ_FALSE) {
for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno)
for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno)
{
/* qcd is first component of first tile */
if (! opj_j2k_compare_qcc(p_j2k, 0, compno)) {
if (! opj_j2k_write_qcc(p_j2k,compno,p_stream, p_manager)) {
return OPJ_FALSE;
}
}
return OPJ_TRUE;
}
return OPJ_TRUE;
}
static OPJ_BOOL opj_j2k_write_regions( opj_j2k_t *p_j2k,
@ -8954,6 +8972,54 @@ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size ( opj_j2k_t *p_j2k,
}
}
static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no)
{
opj_cp_t *l_cp = NULL;
opj_tcp_t *l_tcp = NULL;
opj_tccp_t *l_tccp0 = NULL;
opj_tccp_t *l_tccp1 = NULL;
OPJ_UINT32 l_band_no, l_num_bands;
/* preconditions */
assert(p_j2k != 00);
l_cp = &(p_j2k->m_cp);
l_tcp = &l_cp->tcps[p_tile_no];
l_tccp0 = &l_tcp->tccps[p_first_comp_no];
l_tccp1 = &l_tcp->tccps[p_second_comp_no];
if (l_tccp0->qntsty != l_tccp1->qntsty ) {
return OPJ_FALSE;
}
if (l_tccp0->numgbits != l_tccp1->numgbits ) {
return OPJ_FALSE;
}
if (l_tccp0->qntsty == J2K_CCP_QNTSTY_SIQNT) {
l_num_bands = 1U;
} else {
l_num_bands = l_tccp0->numresolutions * 3U - 2U;
if (l_num_bands != (l_tccp1->numresolutions * 3U - 2U)) {
return OPJ_FALSE;
}
}
for (l_band_no = 0; l_band_no < l_num_bands; ++l_band_no) {
if (l_tccp0->stepsizes[l_band_no].expn != l_tccp1->stepsizes[l_band_no].expn ) {
return OPJ_FALSE;
}
}
if (l_tccp0->qntsty != J2K_CCP_QNTSTY_NOQNT)
{
for (l_band_no = 0; l_band_no < l_num_bands; ++l_band_no) {
if (l_tccp0->stepsizes[l_band_no].mant != l_tccp1->stepsizes[l_band_no].mant ) {
return OPJ_FALSE;
}
}
}
return OPJ_TRUE;
}
static OPJ_BOOL opj_j2k_write_SQcd_SQcc( opj_j2k_t *p_j2k,
OPJ_UINT32 p_tile_no,
OPJ_UINT32 p_comp_no,