[FFmpeg-soc] [soc]: r441 - in jpeg2000: aec.h aecdec.c checkout.sh

k.nowosad subversion at mplayerhq.hu
Sun Jul 15 23:17:15 CEST 2007


Author: k.nowosad
Date: Sun Jul 15 23:17:15 2007
New Revision: 441

Log:
added arithmetic entropy decoder


Added:
   jpeg2000/aecdec.c
Modified:
   jpeg2000/aec.h
   jpeg2000/checkout.sh

Modified: jpeg2000/aec.h
==============================================================================
--- jpeg2000/aec.h	(original)
+++ jpeg2000/aec.h	Sun Jul 15 23:17:15 2007
@@ -107,6 +107,8 @@ typedef struct {
     AecContext *curctx;
 } AecState;
 
+/** encoder */
+
 void ff_aec_initenc(AecState *aec, uint8_t *bp);
 
 /**
@@ -124,4 +126,11 @@ int ff_aec_length(AecState *aec);
  * */
 int ff_aec_flush(AecState *aec);
 
+/** decoder */
+
+void ff_aec_initdec(AecState *aec, uint8_t *bp);
+
+/** returns decoded bit with context cx */
+int ff_aec_decode(AecState *aec, int cx);
+
 #endif

Added: jpeg2000/aecdec.c
==============================================================================
--- (empty file)
+++ jpeg2000/aecdec.c	Sun Jul 15 23:17:15 2007
@@ -0,0 +1,99 @@
+/*
+ * Arithmetic entropy decoder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * Arithmetic entropy decoder
+ * @file aecdec.c
+ * @author Kamil Nowosad
+ */
+
+#include "aec.h"
+
+static void bytein(AecState *aec)
+{
+    if (*aec->bp == 0xff){
+        if (*(aec->bp+1) > 0x8f)
+            aec->ct = 8;
+        else{
+            aec->bp++;
+            aec->c += 0xfe00 - (*aec->bp << 9);
+            aec->ct = 7;
+        }
+    }
+    else{
+        aec->bp++;
+        aec->c += 0xff00 - (*aec->bp << 8);
+        aec->ct = 8;
+    }
+}
+
+static int exchange(AecState *aec, int lps)
+{
+    int d;
+    if ((aec->a < cx_states[aec->curctx->state].qe) ^ (!lps)){
+        if (lps)
+            aec->a = cx_states[aec->curctx->state].qe;
+        d = aec->curctx->mps;
+        aec->curctx->state = cx_states[aec->curctx->state].nmps;
+    }
+    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;
+    }
+    // renormd:
+    do{
+        if (!aec->ct)
+            bytein(aec);
+        aec->a = aec->a << 1;
+        aec->c = aec->c << 1;
+        aec->ct--;
+    } while (!(aec->a & 0x8000));
+    return d;
+}
+
+void ff_aec_initdec(AecState *aec, uint8_t *bp)
+{
+    aec->bp = bp;
+    aec->c = (*aec->bp ^ 0xff) << 16;
+    bytein(aec);
+    aec->c = aec->c << 7;
+    aec->ct -= 7;
+    aec->a = 0x8000;
+}
+
+int ff_aec_decode(AecState *aec, int cx)
+{
+    aec->curctx = aec->contexts + cx;
+    aec->a -= cx_states[aec->curctx->state].qe;
+    if ((aec->c >> 16) < aec->a){
+        if (aec->a & 0x8000)
+            return aec->curctx->mps;
+        else
+            return exchange(aec, 0);
+    } else {
+        aec->c -= aec->a << 16;
+        return exchange(aec, 1);
+    }
+}

Modified: jpeg2000/checkout.sh
==============================================================================
--- jpeg2000/checkout.sh	(original)
+++ jpeg2000/checkout.sh	Sun Jul 15 23:17:15 2007
@@ -8,4 +8,5 @@ ln -s ../../j2kenc.c j2kenc.c
 ln -s ../../j2k.h j2k.h
 ln -s ../../aecenc.c aecenc.c
 ln -s ../../aec.h aec.h
+ln -s ../../aecdec.c aecdec.c
 echo "Done, now just do a regular configure and make to build."



More information about the FFmpeg-soc mailing list