[FFmpeg-soc] [soc]: r1028 - in jpeg2000: aec.c aec.h aecdec.c aecenc.c
k.nowosad
subversion at mplayerhq.hu
Sun Aug 19 17:29:10 CEST 2007
Author: k.nowosad
Date: Sun Aug 19 17:29:10 2007
New Revision: 1028
Log:
optimized the context state stuff
Modified:
jpeg2000/aec.c
jpeg2000/aec.h
jpeg2000/aecdec.c
jpeg2000/aecenc.c
Modified: jpeg2000/aec.c
==============================================================================
--- jpeg2000/aec.c (original)
+++ jpeg2000/aec.c Sun Aug 19 17:29:10 2007
@@ -27,7 +27,14 @@
#include "aec.h"
-const AecCxState cx_states[47] = {
+typedef struct {
+ uint16_t qe;
+ uint8_t nmps;
+ uint8_t nlps;
+ uint8_t sw;
+} AecCxState;
+
+const static AecCxState cx_states[47] = {
{0x5601, 1, 1, 1},
{0x3401, 2, 6, 0},
{0x1801, 3, 9, 0},
@@ -77,11 +84,26 @@ const AecCxState cx_states[47] = {
{0x5601, 46, 46, 0}
};
+uint16_t ff_aec_qe [2*47];
+uint8_t ff_aec_nlps[2*47];
+uint8_t ff_aec_nmps[2*47];
+
void ff_aec_init_contexts(AecState *aec)
{
- memset(aec->contexts, 0, sizeof(aec->contexts));
- aec->contexts[AEC_CX_UNI].state = 46;
- aec->contexts[AEC_CX_RL].state = 3;
- aec->contexts[0].state = 4;
- aec->curctx = aec->contexts;
+ int i;
+ memset(aec->cx_states, 0, sizeof(aec->cx_states));
+ aec->cx_states[AEC_CX_UNI] = 2 * 46;
+ aec->cx_states[AEC_CX_RL] = 2 * 3;
+ aec->cx_states[0] = 2 * 4;
+ aec->curcxstate = aec->cx_states;
+
+ for (i = 0; i < 47; i++){
+ ff_aec_qe[2*i ] =
+ ff_aec_qe[2*i+1] = cx_states[i].qe;
+
+ ff_aec_nlps[2*i ] = 2*cx_states[i].nlps + cx_states[i].sw;
+ ff_aec_nlps[2*i+1] = 2*cx_states[i].nlps + 1 - cx_states[i].sw;
+ ff_aec_nmps[2*i ] = 2*cx_states[i].nmps;
+ ff_aec_nmps[2*i+1] = 2*cx_states[i].nmps + 1;
+ }
}
Modified: jpeg2000/aec.h
==============================================================================
--- jpeg2000/aec.h (original)
+++ jpeg2000/aec.h Sun Aug 19 17:29:10 2007
@@ -36,27 +36,17 @@
#define AEC_CX_UNI 17
#define AEC_CX_RL 18
-typedef struct {
- uint16_t qe;
- uint8_t nmps;
- uint8_t nlps;
- uint8_t sw;
-} AecCxState;
-
-extern const AecCxState cx_states[47];
-
-typedef struct {
- unsigned int state;
- unsigned int mps;
-} AecContext;
+extern uint16_t ff_aec_qe[2*47];
+extern uint8_t ff_aec_nlps[2*47];
+extern uint8_t ff_aec_nmps[2*47];
typedef struct {
uint8_t *bp, *bpstart;
unsigned int a;
unsigned int c;
unsigned int ct;
- AecContext contexts[19];
- AecContext *curctx;
+ uint8_t cx_states[19];
+ uint8_t *curcxstate;
} AecState;
/** encoder */
Modified: jpeg2000/aecdec.c
==============================================================================
--- jpeg2000/aecdec.c (original)
+++ jpeg2000/aecdec.c Sun Aug 19 17:29:10 2007
@@ -48,19 +48,17 @@ static void bytein(AecState *aec)
static int exchange(AecState *aec, int lps)
{
int d;
- if ((aec->a < cx_states[aec->curctx->state].qe) ^ (!lps)){
+ if ((aec->a < ff_aec_qe[*aec->curcxstate]) ^ (!lps)){
if (lps)
- aec->a = cx_states[aec->curctx->state].qe;
- d = aec->curctx->mps;
- aec->curctx->state = cx_states[aec->curctx->state].nmps;
+ aec->a = ff_aec_qe[*aec->curcxstate];
+ d = *aec->curcxstate & 1;
+ *aec->curcxstate = ff_aec_nmps[*aec->curcxstate];
}
else{
if (lps)
- aec->a = cx_states[aec->curctx->state].qe;
- d = 1 - aec->curctx->mps;
- if (cx_states[aec->curctx->state].sw)
- aec->curctx->mps ^= 1;
- aec->curctx->state = cx_states[aec->curctx->state].nlps;
+ aec->a = ff_aec_qe[*aec->curcxstate];
+ d = 1 - (*aec->curcxstate & 1);
+ *aec->curcxstate = ff_aec_nlps[*aec->curcxstate];
}
// renormd:
do{
@@ -86,11 +84,11 @@ void ff_aec_initdec(AecState *aec, uint8
int ff_aec_decode(AecState *aec, int cx)
{
- aec->curctx = aec->contexts + cx;
- aec->a -= cx_states[aec->curctx->state].qe;
+ aec->curcxstate = aec->cx_states + cx;
+ aec->a -= ff_aec_qe[*aec->curcxstate];
if ((aec->c >> 16) < aec->a){
if (aec->a & 0x8000)
- return aec->curctx->mps;
+ return *aec->curcxstate & 1;
else
return exchange(aec, 0);
} else {
Modified: jpeg2000/aecenc.c
==============================================================================
--- jpeg2000/aecenc.c (original)
+++ jpeg2000/aecenc.c Sun Aug 19 17:29:10 2007
@@ -79,16 +79,16 @@ void ff_aec_encode(AecState *aec, int cx
{
int qe;
- aec->curctx = aec->contexts + cx;
- qe = cx_states[aec->curctx->state].qe;
+ aec->curcxstate = aec->cx_states + cx;
+ qe = ff_aec_qe[*aec->curcxstate];
aec->a -= qe;
- if (aec->curctx->mps == d){
+ if (*aec->curcxstate & 1 == d){
if (!(aec->a & 0x8000)){
if (aec->a < qe)
aec->a = qe;
else
aec->c += qe;
- aec->curctx->state = cx_states[aec->curctx->state].nmps;
+ *aec->curcxstate = ff_aec_nmps[*aec->curcxstate];
renorme(aec);
} else
aec->c += qe;
@@ -97,8 +97,7 @@ void ff_aec_encode(AecState *aec, int cx
aec->c += qe;
else
aec->a = qe;
- aec->curctx->mps ^= cx_states[aec->curctx->state].sw;
- aec->curctx->state = cx_states[aec->curctx->state].nlps;
+ *aec->curcxstate = ff_aec_nlps[*aec->curcxstate];
renorme(aec);
}
}
More information about the FFmpeg-soc
mailing list