T1: avoid pointer indirection for mqc and raw members of opj_t1_t
authorEven Rouault <even.rouault@spatialys.com>
Thu, 1 Jun 2017 09:15:25 +0000 (11:15 +0200)
committerEven Rouault <even.rouault@spatialys.com>
Fri, 2 Jun 2017 16:21:54 +0000 (18:21 +0200)
src/lib/openjp2/mqc.c
src/lib/openjp2/mqc.h
src/lib/openjp2/raw.c
src/lib/openjp2/raw.h
src/lib/openjp2/t1.c
src/lib/openjp2/t1.h

index 8a792b601760844dbaec1adc5a21b07741a87e2c..bd4054c7dd8c9c0078d7b93e019654587334801e 100644 (file)
@@ -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;
index 4a3e3c88b6c5def72bff015bb5df145a3844c898..eb44cdd650b3fe242a114ab06bbe77209b377f8b 100644 (file)
@@ -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
index 51f9149274c6d8edccbe0ad80a413a9b07bedc37..03cc90c0a2d7dfe497d5a35fc66ce96e3a6cdc4c 100644 (file)
 ==========================================================
 */
 
-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;
index dfb0ae01a6c34d62477d8b69cd2afb88a39ab12d..1f55ed5e7e61fea3fca7efe8b395db0138a6e21d 100644 (file)
@@ -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
index 2f3a96928589d14475a1589d223945decb91bb3b..b86ecf239fa682296993a5a07162a9ddb4dc468c 100644 (file)
@@ -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;
index 7e1df43484225d9e7368916e00240a4f2cebf82b..a6982ce24f483686d7d9176b2713d43648ed187e 100644 (file)
@@ -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.