Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extern/libopenjpeg/mqc.c')
-rw-r--r--extern/libopenjpeg/mqc.c230
1 files changed, 106 insertions, 124 deletions
diff --git a/extern/libopenjpeg/mqc.c b/extern/libopenjpeg/mqc.c
index 18fcc476059..14129fbf4e5 100644
--- a/extern/libopenjpeg/mqc.c
+++ b/extern/libopenjpeg/mqc.c
@@ -1,17 +1,10 @@
/*
- * The copyright in this software is being made available under the 2-clauses
- * BSD License, included below. This software may be subject to other third
- * party and contributor rights, including patent rights, and no such rights
- * are granted under this license.
- *
- * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
- * Copyright (c) 2002-2014, Professor Benoit Macq
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
+ * Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
- * Copyright (c) 2003-2007, Francois-Olivier Devaux
- * Copyright (c) 2003-2014, Antonin Descampe
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
- * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -49,49 +42,49 @@ Output a byte, doing bit-stuffing if necessary.
After a 0xff byte, the next byte must be smaller than 0x90.
@param mqc MQC handle
*/
-static void opj_mqc_byteout(opj_mqc_t *mqc);
+static void mqc_byteout(opj_mqc_t *mqc);
/**
Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000
@param mqc MQC handle
*/
-static void opj_mqc_renorme(opj_mqc_t *mqc);
+static void mqc_renorme(opj_mqc_t *mqc);
/**
Encode the most probable symbol
@param mqc MQC handle
*/
-static void opj_mqc_codemps(opj_mqc_t *mqc);
+static void mqc_codemps(opj_mqc_t *mqc);
/**
Encode the most least symbol
@param mqc MQC handle
*/
-static void opj_mqc_codelps(opj_mqc_t *mqc);
+static void mqc_codelps(opj_mqc_t *mqc);
/**
Fill mqc->c with 1's for flushing
@param mqc MQC handle
*/
-static void opj_mqc_setbits(opj_mqc_t *mqc);
+static void mqc_setbits(opj_mqc_t *mqc);
/**
-FIXME DOC
+FIXME: documentation ???
@param mqc MQC handle
@return
*/
-static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc);
+static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc);
/**
-FIXME DOC
+FIXME: documentation ???
@param mqc MQC handle
@return
*/
-static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc);
+static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc);
/**
Input a byte
@param mqc MQC handle
*/
-static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc);
+static INLINE void mqc_bytein(opj_mqc_t *const mqc);
/**
Renormalize mqc->a and mqc->c while decoding
@param mqc MQC handle
*/
-static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc);
+static INLINE void mqc_renormd(opj_mqc_t *const mqc);
/*@}*/
/*@}*/
@@ -202,16 +195,16 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
==========================================================
*/
-void opj_mqc_byteout(opj_mqc_t *mqc) {
+static void mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->bp++;
- *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
+ *mqc->bp = mqc->c >> 20;
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++;
- *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
+ *mqc->bp = mqc->c >> 19;
mqc->c &= 0x7ffff;
mqc->ct = 8;
} else {
@@ -219,12 +212,12 @@ void opj_mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->c &= 0x7ffffff;
mqc->bp++;
- *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
+ *mqc->bp = mqc->c >> 20;
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
mqc->bp++;
- *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
+ *mqc->bp = mqc->c >> 19;
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
@@ -232,18 +225,18 @@ void opj_mqc_byteout(opj_mqc_t *mqc) {
}
}
-void opj_mqc_renorme(opj_mqc_t *mqc) {
+static void mqc_renorme(opj_mqc_t *mqc) {
do {
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
if (mqc->ct == 0) {
- opj_mqc_byteout(mqc);
+ mqc_byteout(mqc);
}
} while ((mqc->a & 0x8000) == 0);
}
-void opj_mqc_codemps(opj_mqc_t *mqc) {
+static void mqc_codemps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) {
@@ -252,13 +245,13 @@ void opj_mqc_codemps(opj_mqc_t *mqc) {
mqc->c += (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nmps;
- opj_mqc_renorme(mqc);
+ mqc_renorme(mqc);
} else {
mqc->c += (*mqc->curctx)->qeval;
}
}
-void opj_mqc_codelps(opj_mqc_t *mqc) {
+static void mqc_codelps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval;
@@ -266,39 +259,39 @@ void opj_mqc_codelps(opj_mqc_t *mqc) {
mqc->a = (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nlps;
- opj_mqc_renorme(mqc);
+ mqc_renorme(mqc);
}
-void opj_mqc_setbits(opj_mqc_t *mqc) {
- OPJ_UINT32 tempc = mqc->c + mqc->a;
+static void mqc_setbits(opj_mqc_t *mqc) {
+ unsigned int tempc = mqc->c + mqc->a;
mqc->c |= 0xffff;
if (mqc->c >= tempc) {
mqc->c -= 0x8000;
}
}
-static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
- OPJ_INT32 d;
+static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc) {
+ int d;
if (mqc->a < (*mqc->curctx)->qeval) {
- d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
+ d = 1 - (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
- d = (OPJ_INT32)(*mqc->curctx)->mps;
+ d = (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
return d;
}
-static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
- OPJ_INT32 d;
+static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc) {
+ int d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
- d = (OPJ_INT32)(*mqc->curctx)->mps;
+ d = (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
- d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
+ d = 1 - (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nlps;
}
@@ -306,16 +299,16 @@ static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
}
#ifdef MQC_PERF_OPT
-static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) {
+static INLINE void mqc_bytein(opj_mqc_t *const mqc) {
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
}
#else
-static void opj_mqc_bytein(opj_mqc_t *const mqc) {
+static void mqc_bytein(opj_mqc_t *const mqc) {
if (mqc->bp != mqc->end) {
- OPJ_UINT32 c;
+ unsigned int c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
@@ -342,10 +335,10 @@ static void opj_mqc_bytein(opj_mqc_t *const mqc) {
}
#endif
-static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
+static INLINE void mqc_renormd(opj_mqc_t *const mqc) {
do {
if (mqc->ct == 0) {
- opj_mqc_bytein(mqc);
+ mqc_bytein(mqc);
}
mqc->a <<= 1;
mqc->c <<= 1;
@@ -359,7 +352,7 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
==========================================================
*/
-opj_mqc_t* opj_mqc_create(void) {
+opj_mqc_t* mqc_create(void) {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT
mqc->buffer = NULL;
@@ -367,26 +360,23 @@ opj_mqc_t* opj_mqc_create(void) {
return mqc;
}
-void opj_mqc_destroy(opj_mqc_t *mqc) {
+void mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
#ifdef MQC_PERF_OPT
- opj_free(mqc->buffer);
+ if (mqc->buffer) {
+ opj_free(mqc->buffer);
+ }
#endif
opj_free(mqc);
}
}
-OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) {
- const ptrdiff_t diff = mqc->bp - mqc->start;
-#if 0
- assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
-#endif
- return (OPJ_UINT32)diff;
+int mqc_numbytes(opj_mqc_t *mqc) {
+ return mqc->bp - mqc->start;
}
-void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
- /* TODO MSD: need to take a look to the v2 version */
- opj_mqc_setcurctx(mqc, 0);
+void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) {
+ mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->bp = bp - 1;
@@ -397,27 +387,27 @@ void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
mqc->start = bp;
}
-void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
+void mqc_encode(opj_mqc_t *mqc, int d) {
if ((*mqc->curctx)->mps == d) {
- opj_mqc_codemps(mqc);
+ mqc_codemps(mqc);
} else {
- opj_mqc_codelps(mqc);
+ mqc_codelps(mqc);
}
}
-void opj_mqc_flush(opj_mqc_t *mqc) {
- opj_mqc_setbits(mqc);
+void mqc_flush(opj_mqc_t *mqc) {
+ mqc_setbits(mqc);
mqc->c <<= mqc->ct;
- opj_mqc_byteout(mqc);
+ mqc_byteout(mqc);
mqc->c <<= mqc->ct;
- opj_mqc_byteout(mqc);
+ mqc_byteout(mqc);
if (*mqc->bp != 0xff) {
mqc->bp++;
}
}
-void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) {
+void mqc_bypass_init_enc(opj_mqc_t *mqc) {
mqc->c = 0;
mqc->ct = 8;
/*if (*mqc->bp == 0xff) {
@@ -425,12 +415,12 @@ void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) {
} */
}
-void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
+void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
mqc->bp++;
- *mqc->bp = (OPJ_BYTE)mqc->c;
+ *mqc->bp = mqc->c;
mqc->ct = 8;
if (*mqc->bp == 0xff) {
mqc->ct = 7;
@@ -439,19 +429,19 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
}
}
-OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
- OPJ_BYTE bit_padding;
+int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
+ unsigned char bit_padding;
bit_padding = 0;
if (mqc->ct != 0) {
while (mqc->ct > 0) {
mqc->ct--;
- mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
+ mqc->c += bit_padding << mqc->ct;
bit_padding = (bit_padding + 1) & 0x01;
}
mqc->bp++;
- *mqc->bp = (OPJ_BYTE)mqc->c;
+ *mqc->bp = mqc->c;
mqc->ct = 8;
mqc->c = 0;
}
@@ -459,32 +449,32 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
return 1;
}
-void opj_mqc_reset_enc(opj_mqc_t *mqc) {
- opj_mqc_resetstates(mqc);
- opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
- opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
- opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
+void mqc_reset_enc(opj_mqc_t *mqc) {
+ mqc_resetstates(mqc);
+ mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
+ mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
+ mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
}
-OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) {
- OPJ_UINT32 correction = 1;
+int mqc_restart_enc(opj_mqc_t *mqc) {
+ int correction = 1;
/* <flush part> */
- OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
+ int n = 27 - 15 - mqc->ct;
mqc->c <<= mqc->ct;
while (n > 0) {
- opj_mqc_byteout(mqc);
- n -= (OPJ_INT32)mqc->ct;
+ mqc_byteout(mqc);
+ n -= mqc->ct;
mqc->c <<= mqc->ct;
}
- opj_mqc_byteout(mqc);
+ mqc_byteout(mqc);
return correction;
}
-void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
+void mqc_restart_init_enc(opj_mqc_t *mqc) {
/* <Re-init part> */
- opj_mqc_setcurctx(mqc, 0);
+ mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->ct = 12;
@@ -494,52 +484,45 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
}
}
-void opj_mqc_erterm_enc(opj_mqc_t *mqc) {
- OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
+void mqc_erterm_enc(opj_mqc_t *mqc) {
+ int k = 11 - mqc->ct + 1;
while (k > 0) {
mqc->c <<= mqc->ct;
mqc->ct = 0;
- opj_mqc_byteout(mqc);
- k -= (OPJ_INT32)mqc->ct;
+ mqc_byteout(mqc);
+ k -= mqc->ct;
}
if (*mqc->bp != 0xff) {
- opj_mqc_byteout(mqc);
+ mqc_byteout(mqc);
}
}
-void opj_mqc_segmark_enc(opj_mqc_t *mqc) {
- OPJ_UINT32 i;
- opj_mqc_setcurctx(mqc, 18);
+void mqc_segmark_enc(opj_mqc_t *mqc) {
+ int i;
+ mqc_setcurctx(mqc, 18);
for (i = 1; i < 5; i++) {
- opj_mqc_encode(mqc, i % 2);
+ mqc_encode(mqc, i % 2);
}
}
-OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
- opj_mqc_setcurctx(mqc, 0);
+void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
+ mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
mqc->bp = bp;
if (len==0) mqc->c = 0xff << 16;
- else mqc->c = (OPJ_UINT32)(*mqc->bp << 16);
+ else mqc->c = *mqc->bp << 16;
-#ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */
+#ifdef MQC_PERF_OPT
{
- OPJ_UINT32 c;
- OPJ_UINT32 *ip;
- OPJ_BYTE *end = mqc->end - 1;
- void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32));
- if (! new_buffer) {
- opj_free(mqc->buffer);
- mqc->buffer = NULL;
- return OPJ_FALSE;
- }
- mqc->buffer = new_buffer;
-
- ip = (OPJ_UINT32 *) mqc->buffer;
+ unsigned int c;
+ unsigned int *ip;
+ unsigned char *end = mqc->end - 1;
+ mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
+ ip = (unsigned int *) mqc->buffer;
while (bp < end) {
c = *(bp + 1);
@@ -570,41 +553,40 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
mqc->bp = mqc->buffer;
}
#endif
- opj_mqc_bytein(mqc);
+ mqc_bytein(mqc);
mqc->c <<= 7;
mqc->ct -= 7;
mqc->a = 0x8000;
- return OPJ_TRUE;
}
-OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
- OPJ_INT32 d;
+int mqc_decode(opj_mqc_t *const mqc) {
+ int d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
- d = opj_mqc_lpsexchange(mqc);
- opj_mqc_renormd(mqc);
+ d = mqc_lpsexchange(mqc);
+ mqc_renormd(mqc);
} else {
mqc->c -= (*mqc->curctx)->qeval << 16;
if ((mqc->a & 0x8000) == 0) {
- d = opj_mqc_mpsexchange(mqc);
- opj_mqc_renormd(mqc);
+ d = mqc_mpsexchange(mqc);
+ mqc_renormd(mqc);
} else {
- d = (OPJ_INT32)(*mqc->curctx)->mps;
+ d = (*mqc->curctx)->mps;
}
}
return d;
}
-void opj_mqc_resetstates(opj_mqc_t *mqc) {
- OPJ_UINT32 i;
+void mqc_resetstates(opj_mqc_t *mqc) {
+ int i;
for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states;
}
}
-void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) {
- mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
+void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) {
+ mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
}