[FFmpeg-soc] [soc]: r298 - in jpeg2000: aec.h aecenc.c

k.nowosad subversion at mplayerhq.hu
Sun Jul 1 16:48:57 CEST 2007


Author: k.nowosad
Date: Sun Jul  1 16:48:57 2007
New Revision: 298

Log:
did some simplification and changed the datatypes in AecCxState


Modified:
   jpeg2000/aec.h
   jpeg2000/aecenc.c

Modified: jpeg2000/aec.h
==============================================================================
--- jpeg2000/aec.h	(original)
+++ jpeg2000/aec.h	Sun Jul  1 16:48:57 2007
@@ -38,10 +38,10 @@
 #define AEC_CX_RL  18
 
 typedef struct {
-        unsigned int qe;
-        unsigned int nmps;
-        unsigned int nlps;
-        unsigned int sw;
+        uint16_t qe;
+        uint8_t  nmps;
+        uint8_t  nlps;
+        uint8_t  sw;
 } AecCxState;
 
 const static AecCxState cx_states[47] = {

Modified: jpeg2000/aecenc.c
==============================================================================
--- jpeg2000/aecenc.c	(original)
+++ jpeg2000/aecenc.c	Sun Jul  1 16:48:57 2007
@@ -28,85 +28,36 @@
 
 #include "aec.h"
 
-static void byteout_l(AecState *aec)
-{
-    aec->bp++;
-    *aec->bp = aec->c >> 19;
-    aec->c &= 0x7ffff;
-    aec->ct = 8;
-}
-
-static void byteout_r(AecState *aec)
-{
-    aec->bp++;
-    *aec->bp = aec->c >> 20;
-    aec->c &= 0xfffff;
-    aec->ct = 7;
-}
-
 static void byteout(AecState *aec)
 {
+retry:
     if (*aec->bp == 0xff){
-        byteout_r(aec);
+        aec->bp++;
+        *aec->bp = aec->c >> 20;
+        aec->c &= 0xfffff;
+        aec->ct = 7;
     }
-    else
-    {
-        if ((aec->c & 0x8000000) == 0){
-            byteout_l(aec);
-        }
-        else{
-            (*aec->bp)++;
-            if (*aec->bp == 0xff){
-                aec->c &= 0x7ffffff;
-                byteout_r(aec);
-            }
-            else{
-                byteout_l(aec);
-            }
-        }
+    else if ((aec->c & 0x8000000)){
+        (*aec->bp)++;
+        aec->c &= 0x7ffffff;
+        goto retry;
+    }else{
+        aec->bp++;
+        *aec->bp = aec->c >> 19;
+        aec->c &= 0x7ffff;
+        aec->ct = 8;
     }
 }
 
 static void renorme(AecState *aec)
 {
     do{
-        aec->a = aec->a << 1;
-        aec->c = aec->c << 1;
-        aec->ct--;
-        if (!aec->ct)
+        aec->a += aec->a;
+        aec->c += aec->c;
+        if (!--aec->ct)
             byteout(aec);
     }
-    while ((aec->a & 0x8000) == 0);
-}
-
-static void codelps(AecState *aec)
-{
-    int qe = cx_states[aec->curctx->state].qe;
-    aec->a -= qe;
-    if (aec->a < qe)
-        aec->c += qe;
-    else
-        aec->a = qe;
-    if (cx_states[aec->curctx->state].sw)
-        aec->curctx->mps = 1 - aec->curctx->mps;
-    aec->curctx->state = cx_states[aec->curctx->state].nlps;
-    renorme(aec);
-}
-
-static void codemps(AecState *aec)
-{
-    int qe = cx_states[aec->curctx->state].qe;
-    aec->a -= qe;
-    if ((aec->a & 0x8000) == 0){
-        if (aec->a < qe)
-            aec->a = qe;
-        else
-            aec->c += qe;
-        aec->curctx->state = cx_states[aec->curctx->state].nmps;
-        renorme(aec);
-    }
-    else
-        aec->c += qe;
+    while (!(aec->a & 0x8000));
 }
 
 static void setbits(AecState *aec)
@@ -129,20 +80,36 @@ void aec_initenc(AecState *aec, uint8_t 
     aec->c = 0;
     aec->bp = bp-1;
     aec->bpstart = bp;
-    if (*aec->bp == 0xff)
-        aec->ct = 13;
-    else
-        aec->ct = 12;
+    aec->ct = 12 + (*aec->bp == 0xff);
 }
 
 void aec_encode(AecState *aec, int cx, int d)
 {
+    int qe;
+
     aec->curctx = aec->contexts + cx;
+    qe = cx_states[aec->curctx->state].qe;
+    aec->a -= qe;
     if (aec->curctx->mps == d){
-        codemps(aec);
+        if (!(aec->a & 0x8000)){
+            if (aec->a < qe)
+                aec->a = qe;
+            else
+                aec->c += qe;
+            aec->curctx->state = cx_states[aec->curctx->state].nmps;
+            renorme(aec);
+        }
+        else
+            aec->c += qe;
     }
     else{
-        codelps(aec);
+        if (aec->a < qe)
+            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;
+        renorme(aec);
     }
 }
 



More information about the FFmpeg-soc mailing list