From 10410fe72ec2d20f2bbdfb68a383bce1df17f35d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 1 Jun 2017 11:15:25 +0200 Subject: [PATCH] T1: avoid pointer indirection for mqc and raw members of opj_t1_t --- src/lib/openjp2/mqc.c | 13 ----------- src/lib/openjp2/mqc.h | 11 +-------- src/lib/openjp2/raw.c | 13 ----------- src/lib/openjp2/raw.h | 11 +-------- src/lib/openjp2/t1.c | 54 +++++++++++++++---------------------------- src/lib/openjp2/t1.h | 4 ++-- 6 files changed, 22 insertions(+), 84 deletions(-) diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index 8a792b60..bd4054c7 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -272,19 +272,6 @@ static void opj_mqc_setbits(opj_mqc_t *mqc) ========================================================== */ -opj_mqc_t* opj_mqc_create(void) -{ - opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); - return mqc; -} - -void opj_mqc_destroy(opj_mqc_t *mqc) -{ - if (mqc) { - opj_free(mqc); - } -} - OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { const ptrdiff_t diff = mqc->bp - mqc->start; diff --git a/src/lib/openjp2/mqc.h b/src/lib/openjp2/mqc.h index 4a3e3c88..eb44cdd6 100644 --- a/src/lib/openjp2/mqc.h +++ b/src/lib/openjp2/mqc.h @@ -86,16 +86,7 @@ typedef struct opj_mqc { /** @name Exported functions */ /*@{*/ /* ----------------------------------------------------------------------- */ -/** -Create a new MQC handle -@return Returns a new MQC handle if successful, returns NULL otherwise -*/ -opj_mqc_t* opj_mqc_create(void); -/** -Destroy a previously created MQC handle -@param mqc MQC handle to destroy -*/ -void opj_mqc_destroy(opj_mqc_t *mqc); + /** Return the number of bytes written/read since initialisation @param mqc MQC handle diff --git a/src/lib/openjp2/raw.c b/src/lib/openjp2/raw.c index 51f91492..03cc90c0 100644 --- a/src/lib/openjp2/raw.c +++ b/src/lib/openjp2/raw.c @@ -48,19 +48,6 @@ ========================================================== */ -opj_raw_t* opj_raw_create(void) -{ - opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); - return raw; -} - -void opj_raw_destroy(opj_raw_t *raw) -{ - if (raw) { - opj_free(raw); - } -} - OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) { const ptrdiff_t diff = raw->bp - raw->start; diff --git a/src/lib/openjp2/raw.h b/src/lib/openjp2/raw.h index dfb0ae01..1f55ed5e 100644 --- a/src/lib/openjp2/raw.h +++ b/src/lib/openjp2/raw.h @@ -71,16 +71,7 @@ typedef struct opj_raw { /** @name Exported functions */ /*@{*/ /* ----------------------------------------------------------------------- */ -/** -Create a new RAW handle -@return Returns a new RAW handle if successful, returns NULL otherwise -*/ -opj_raw_t* opj_raw_create(void); -/** -Destroy a previously created RAW handle -@param raw RAW handle to destroy -*/ -void opj_raw_destroy(opj_raw_t *raw); + /** Return the number of bytes written/read since initialisation @param raw RAW handle to destroy diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 2f3a9692..b86ecf23 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -379,7 +379,7 @@ static INLINE void opj_t1_enc_sigpass_step(opj_t1_t *t1, { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | T1_CHI_S) << (ci * 3U)) : ~0U; @@ -437,7 +437,7 @@ static INLINE void opj_t1_dec_sigpass_step_raw( OPJ_UINT32 ci) { OPJ_UINT32 v; - opj_raw_t *raw = t1->raw; /* RAW component */ + opj_raw_t *raw = &(t1->raw); /* RAW component */ OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | T1_CHI_S) << (ci * 3U)) : ~0U; @@ -464,7 +464,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc( { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 const flags = *flagsp; if ((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == 0U && @@ -497,7 +497,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc_vsc( { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | T1_CHI_S) << (ci * 3U)) : ~0U; @@ -829,7 +829,7 @@ static INLINE void opj_t1_enc_refpass_step(opj_t1_t *t1, { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 const shift_flags = vsc ? @@ -867,7 +867,7 @@ static INLINE void opj_t1_dec_refpass_step_raw( OPJ_UINT32 v; OPJ_INT32 t; - opj_raw_t *raw = t1->raw; /* RAW component */ + opj_raw_t *raw = &(t1->raw); /* RAW component */ if ((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == (T1_SIGMA_THIS << (ci * 3U))) { @@ -889,7 +889,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc( OPJ_UINT32 v; OPJ_INT32 t; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ if ((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == (T1_SIGMA_THIS << (ci * 3U))) { @@ -914,7 +914,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc_vsc( OPJ_UINT32 v; OPJ_INT32 t; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 const shift_flags = vsc ? @@ -1223,7 +1223,7 @@ static void opj_t1_enc_clnpass_step( { OPJ_UINT32 v; OPJ_UINT32 ci; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ const OPJ_UINT32 check = (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13 | T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); @@ -1304,7 +1304,7 @@ static void opj_t1_dec_clnpass_step_partial( OPJ_UINT32 ci) { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 lu = opj_t1_getctxtno_sc_or_spb_index( *flagsp, flagsp[-1], flagsp[1], @@ -1325,7 +1325,7 @@ static void opj_t1_dec_clnpass_step( { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ if (!(*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U)))) { OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U)); opj_mqc_setcurctx(mqc, ctxt1); @@ -1352,7 +1352,7 @@ static void opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit( { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U)); opj_mqc_setcurctx(mqc, ctxt1); @@ -1378,7 +1378,7 @@ static void opj_t1_dec_clnpass_step_vsc( { OPJ_UINT32 v; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | T1_CHI_S) << @@ -1416,7 +1416,7 @@ static void opj_t1_enc_clnpass( const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS); OPJ_UINT32 agg, runlen; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ const OPJ_UINT32 agg_mask = (cblksty & J2K_CCP_CBLKSTY_VSC) ? ~(T1_SIGMA_15 | T1_SIGMA_16 | T1_SIGMA_17 | T1_CHI_5) : @@ -1501,7 +1501,7 @@ static void opj_t1_enc_clnpass( OPJ_UINT32 i, j, k; \ OPJ_INT32 segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; \ \ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ \ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ \ \ one = 1 << bpno; \ half = one >> 1; \ @@ -1820,18 +1820,6 @@ opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder) return 00; } - /* create MQC and RAW handles */ - l_t1->mqc = opj_mqc_create(); - if (! l_t1->mqc) { - opj_t1_destroy(l_t1); - return 00; - } - - l_t1->raw = opj_raw_create(); - if (! l_t1->raw) { - opj_t1_destroy(l_t1); - return 00; - } l_t1->encoder = isEncoder; return l_t1; @@ -1849,12 +1837,6 @@ void opj_t1_destroy(opj_t1_t *p_t1) return; } - /* destroy MQC and RAW handles */ - opj_mqc_destroy(p_t1->mqc); - p_t1->mqc = 00; - opj_raw_destroy(p_t1->raw); - p_t1->raw = 00; - /* encoder uses tile buffer, so no need to free */ if (!p_t1->encoder && p_t1->data) { opj_aligned_free(p_t1->data); @@ -2047,8 +2029,8 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, OPJ_UINT32 roishift, OPJ_UINT32 cblksty) { - opj_raw_t *raw = t1->raw; /* RAW component */ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_raw_t *raw = &(t1->raw); /* RAW component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_INT32 bpno_plus_one; OPJ_UINT32 passtype; @@ -2301,7 +2283,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, { OPJ_FLOAT64 cumwmsedec = 0.0; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_UINT32 passno; OPJ_INT32 bpno; diff --git a/src/lib/openjp2/t1.h b/src/lib/openjp2/t1.h index 7e1df434..a6982ce2 100644 --- a/src/lib/openjp2/t1.h +++ b/src/lib/openjp2/t1.h @@ -183,9 +183,9 @@ Tier-1 coding (coding of code-block coefficients) typedef struct opj_t1 { /** MQC component */ - opj_mqc_t *mqc; + opj_mqc_t mqc; /** RAW component */ - opj_raw_t *raw; + opj_raw_t raw; OPJ_INT32 *data; /** Flags used by decoder and encoder.