WIP: create a new framework to output file information
[openjpeg.git] / libopenjpeg / t1.c
index 14d5b5cf2e12e6d37bbf9a4d3776adac74ea41fc..a5b102cb2dbbc82952bf67288c9f66dd592eff20 100644 (file)
@@ -240,6 +240,7 @@ Encode 1 code-block
 @param stepsize
 @param cblksty Code-block style
 @param numcomps
+@param mct
 @param tile
 */
 static void t1_encode_cblk(
@@ -381,9 +382,10 @@ static INLINE void t1_dec_sigpass_step_raw(
                int vsc)
 {
        int v, flag;
-       
        opj_raw_t *raw = t1->raw;       /* RAW component */
        
+       OPJ_ARG_NOT_USED(orient);
+       
        flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
        if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
                        if (raw_decode(raw)) {
@@ -822,9 +824,10 @@ static void t1_dec_clnpass_step_partial(
                int oneplushalf)
 {
        int v, flag;
-       
        opj_mqc_t *mqc = t1->mqc;       /* MQC component */
        
+       OPJ_ARG_NOT_USED(orient);
+       
        flag = *flagsp;
        mqc_setcurctx(mqc, t1_getctxno_sc(flag));
        v = mqc_decode(mqc) ^ t1_getspb(flag);
@@ -1102,7 +1105,7 @@ static double t1_getwmsedec(
        return wmsedec;
 }
 
-static bool allocate_buffers(
+static opj_bool allocate_buffers(
                opj_t1_t *t1,
                int w,
                int h)
@@ -1114,7 +1117,7 @@ static bool allocate_buffers(
                opj_aligned_free(t1->data);
                t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int));
                if(!t1->data){
-                       return false;
+                       return OPJ_FALSE;
                }
                t1->datasize=datasize;
        }
@@ -1127,7 +1130,7 @@ static bool allocate_buffers(
                opj_aligned_free(t1->flags);
                t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t));
                if(!t1->flags){
-                       return false;
+                       return OPJ_FALSE;
                }
                t1->flagssize=flagssize;
        }
@@ -1136,7 +1139,7 @@ static bool allocate_buffers(
        t1->w=w;
        t1->h=h;
 
-       return true;
+       return OPJ_TRUE;
 }
 
 /** mod fixed_quality */
@@ -1412,6 +1415,7 @@ void t1_encode_cblks(
 
                        for (bandno = 0; bandno < res->numbands; ++bandno) {
                                opj_tcd_band_t* restrict band = &res->bands[bandno];
+        int bandconst = 8192 * 8192 / ((int) floor(band->stepsize * 8192));
 
                                for (precno = 0; precno < res->pw * res->ph; ++precno) {
                                        opj_tcd_precinct_t *prc = &band->precincts[precno];
@@ -1462,7 +1466,7 @@ void t1_encode_cblks(
                                                                        datap[(j * cblk_w) + i] =
                                                                                fix_mul(
                                                                                tmp,
-                                                                               8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (11 - T1_NMSEDEC_FRACBITS);
+                                                                               bandconst) >> (11 - T1_NMSEDEC_FRACBITS);
                                                                }
                                                        }
                                                }
@@ -1578,3 +1582,74 @@ void t1_decode_cblks(
        } /* resno */
 }
 
+
+
+/* ----------------------------------------------------------------------- */
+/**
+ * Creates a new Tier 1 handle
+ * and initializes the look-up tables of the Tier-1 coder/decoder
+ * @return a new T1 handle if successful, returns NULL otherwise
+*/
+opj_t1_t* t1_create_v2()
+{
+       opj_t1_t *l_t1 = 00;
+
+       l_t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t));
+       if
+               (!l_t1)
+       {
+               return 00;
+       }
+       memset(l_t1,0,sizeof(opj_t1_t));
+
+       /* create MQC and RAW handles */
+       l_t1->mqc = mqc_create();
+       if
+               (! l_t1->mqc)
+       {
+               t1_destroy(l_t1);
+               return 00;
+       }
+       l_t1->raw = raw_create();
+       if
+               (! l_t1->raw)
+       {
+               t1_destroy(l_t1);
+               return 00;
+       }
+       return l_t1;
+}
+
+
+/**
+ * Destroys a previously created T1 handle
+ *
+ * @param p_t1 Tier 1 handle to destroy
+*/
+void t1_destroy_v2(opj_t1_t *p_t1)
+{
+       if
+               (! p_t1)
+       {
+               return;
+       }
+
+       /* destroy MQC and RAW handles */
+       mqc_destroy(p_t1->mqc);
+       p_t1->mqc = 00;
+       raw_destroy(p_t1->raw);
+       p_t1->raw = 00;
+       if
+               (p_t1->data)
+       {
+               opj_aligned_free(p_t1->data);
+               p_t1->data = 00;
+       }
+       if
+               (p_t1->flags)
+       {
+               opj_aligned_free(p_t1->flags);
+               p_t1->flags = 00;
+       }
+       opj_free(p_t1);
+}