summaryrefslogtreecommitdiff
path: root/libopenjpeg/mqc.c
diff options
context:
space:
mode:
authorAntonin Descampe <antonin@gmail.com>2008-07-31 18:47:41 +0000
committerAntonin Descampe <antonin@gmail.com>2008-07-31 18:47:41 +0000
commit7caaea18b728ead4e45226aafc09dba01e514a2d (patch)
tree1d5d19df20b82cee63a7de94fc8e04e8426cb7c7 /libopenjpeg/mqc.c
parent8407e057c9e10c8fc2b5f4be56e603fae3f9063d (diff)
Deleting obsolete files and directories, adding v2-specific files and directories, updating existing files to v2. See README.v2 for more info
Diffstat (limited to 'libopenjpeg/mqc.c')
-rw-r--r--libopenjpeg/mqc.c64
1 files changed, 35 insertions, 29 deletions
diff --git a/libopenjpeg/mqc.c b/libopenjpeg/mqc.c
index 9aa9d2c2..e6cfd325 100644
--- a/libopenjpeg/mqc.c
+++ b/libopenjpeg/mqc.c
@@ -5,6 +5,7 @@
* Copyright (c) 2002-2003, Yannick Verschueren
* 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
@@ -29,7 +30,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "opj_includes.h"
+#include "mqc.h"
+#include "t1.h"
+#include "opj_malloc.h"
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
/*@{*/
@@ -68,13 +71,13 @@ FIXME: documentation ???
@param mqc MQC handle
@return
*/
-static int mqc_mpsexchange(opj_mqc_t *mqc);
+static OPJ_INT32 mqc_mpsexchange(opj_mqc_t *mqc);
/**
FIXME: documentation ???
@param mqc MQC handle
@return
*/
-static int mqc_lpsexchange(opj_mqc_t *mqc);
+static OPJ_INT32 mqc_lpsexchange(opj_mqc_t *mqc);
/**
Input a byte
@param mqc MQC handle
@@ -264,15 +267,15 @@ static void mqc_codelps(opj_mqc_t *mqc) {
}
static void mqc_setbits(opj_mqc_t *mqc) {
- unsigned int tempc = mqc->c + mqc->a;
+ OPJ_UINT32 tempc = mqc->c + mqc->a;
mqc->c |= 0xffff;
if (mqc->c >= tempc) {
mqc->c -= 0x8000;
}
}
-static int mqc_mpsexchange(opj_mqc_t *mqc) {
- int d;
+static OPJ_INT32 mqc_mpsexchange(opj_mqc_t *mqc) {
+ OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = 1 - (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nlps;
@@ -284,8 +287,8 @@ static int mqc_mpsexchange(opj_mqc_t *mqc) {
return d;
}
-static int mqc_lpsexchange(opj_mqc_t *mqc) {
- int d;
+static OPJ_INT32 mqc_lpsexchange(opj_mqc_t *mqc) {
+ OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (*mqc->curctx)->mps;
@@ -301,7 +304,7 @@ static int mqc_lpsexchange(opj_mqc_t *mqc) {
static void mqc_bytein(opj_mqc_t *mqc) {
if (mqc->bp != mqc->end) {
- unsigned int c;
+ OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
@@ -350,28 +353,31 @@ opj_mqc_t* mqc_create(void) {
}
void mqc_destroy(opj_mqc_t *mqc) {
- if(mqc) {
+ if
+ (mqc)
+ {
opj_free(mqc);
}
}
-int mqc_numbytes(opj_mqc_t *mqc) {
+OPJ_UINT32 mqc_numbytes(opj_mqc_t *mqc) {
return mqc->bp - mqc->start;
}
-void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) {
+void mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->bp = bp - 1;
+ *(mqc->bp) = 0;
mqc->ct = 12;
- if (*mqc->bp == 0xff) {
+ /*if (*mqc->bp == 0xff) {
mqc->ct = 13;
- }
+ }*/
mqc->start = bp;
}
-void mqc_encode(opj_mqc_t *mqc, int d) {
+void mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
if ((*mqc->curctx)->mps == d) {
mqc_codemps(mqc);
} else {
@@ -399,7 +405,7 @@ void mqc_bypass_init_enc(opj_mqc_t *mqc) {
} */
}
-void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
+void mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
@@ -413,8 +419,8 @@ void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
}
}
-int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
- unsigned char bit_padding;
+OPJ_UINT32 mqc_bypass_flush_enc(opj_mqc_t *mqc) {
+ OPJ_BYTE bit_padding;
bit_padding = 0;
@@ -440,11 +446,11 @@ void mqc_reset_enc(opj_mqc_t *mqc) {
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
}
-int mqc_restart_enc(opj_mqc_t *mqc) {
- int correction = 1;
+OPJ_UINT32 mqc_restart_enc(opj_mqc_t *mqc) {
+ OPJ_UINT32 correction = 1;
/* <flush part> */
- int n = 27 - 15 - mqc->ct;
+ OPJ_INT32 n = 27 - 15 - mqc->ct;
mqc->c <<= mqc->ct;
while (n > 0) {
mqc_byteout(mqc);
@@ -469,7 +475,7 @@ void mqc_restart_init_enc(opj_mqc_t *mqc) {
}
void mqc_erterm_enc(opj_mqc_t *mqc) {
- int k = 11 - mqc->ct + 1;
+ OPJ_INT32 k = 11 - mqc->ct + 1;
while (k > 0) {
mqc->c <<= mqc->ct;
@@ -484,7 +490,7 @@ void mqc_erterm_enc(opj_mqc_t *mqc) {
}
void mqc_segmark_enc(opj_mqc_t *mqc) {
- int i;
+ OPJ_UINT32 i;
mqc_setcurctx(mqc, 18);
for (i = 1; i < 5; i++) {
@@ -492,7 +498,7 @@ void mqc_segmark_enc(opj_mqc_t *mqc) {
}
}
-void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
+void mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
@@ -505,8 +511,8 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
mqc->a = 0x8000;
}
-int mqc_decode(opj_mqc_t *mqc) {
- int d;
+OPJ_UINT32 mqc_decode(opj_mqc_t *mqc) {
+ OPJ_INT32 d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
d = mqc_lpsexchange(mqc);
@@ -521,17 +527,17 @@ int mqc_decode(opj_mqc_t *mqc) {
}
}
- return d;
+ return (OPJ_UINT32)d;
}
void mqc_resetstates(opj_mqc_t *mqc) {
- int i;
+ OPJ_UINT32 i;
for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states;
}
}
-void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) {
+void mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) {
mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
}