summaryrefslogtreecommitdiff
path: root/src/lib/openjp2
diff options
context:
space:
mode:
authormayeut <mayeut@users.noreply.github.com>2015-07-29 00:29:49 +0200
committermayeut <mayeut@users.noreply.github.com>2015-07-29 00:29:49 +0200
commitc3d9719cd4b48ab02ab984350f267bdfea5c6611 (patch)
tree8c671a3fba1c0850b308dfaa94ce05161a78e5d9 /src/lib/openjp2
parent2263b6baccd0f6f60ac5e628ca3b072e9e5a0eff (diff)
Write COC/QCC in Main Header
Update uclouvain/openjpeg#459
Diffstat (limited to 'src/lib/openjp2')
-rw-r--r--src/lib/openjp2/j2k.c142
1 files changed, 104 insertions, 38 deletions
diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c
index 759a622e..b56b8a3d 100644
--- a/src/lib/openjp2/j2k.c
+++ b/src/lib/openjp2/j2k.c
@@ -284,6 +284,19 @@ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size ( opj_j2k_t *p_j2k,
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.
*
* @param p_tile_no the tile to output.
@@ -497,6 +510,17 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k,
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)
*
* @param p_j2k J2K codec.
@@ -567,6 +591,17 @@ static OPJ_BOOL opj_j2k_read_qcd ( opj_j2k_t *p_j2k,
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)
*
* @param p_comp_no the index of the component to output.
@@ -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 (compno = 1; compno < p_j2k->m_private_image->numcomps; ++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)
- {
+ /* 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;
-
- /* preconditions */
- assert(p_j2k != 00);
- assert(p_manager != 00);
- assert(p_stream != 00);
+ 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 (compno = 1; compno < p_j2k->m_private_image->numcomps; ++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;
+ /* 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;
}
}
- }*/
-
- if (needed != OPJ_FALSE) {
- for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++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,