BaseJpegDeocde exampe program

Dependencies:   BaseJpegDecode Terminal BaseUsbHost mbed mbed-rtos

Fork of BaseJpegDecode by Norimasa Okamoto

Revision:
1:58dfd5386a92
Parent:
0:7121d9fb45f4
--- a/HuffmanDecode.cpp	Sun Oct 07 12:03:40 2012 +0000
+++ b/HuffmanDecode.cpp	Mon Oct 08 11:38:57 2012 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 #include "HuffmanDecode.h"
-
+#include "HuffmanCodeTable.h"
 #if 1
 #define DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);} while(0);
 #define DBG_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
@@ -403,6 +403,39 @@
     return NULL;
 }
 
+struct sthtinfo {
+    const Huff* huff_table;
+    const uint8_t* index_table;
+    int max_code_size;
+};
+
+const struct sthtinfo htinfo[2][2] = {
+    {{HT_DC_0, HT_DC_0_index,  9}, {HT_DC_1, HT_DC_1_index, 11}},
+    {{HT_AC_0, HT_AC_0_index, 16}, {HT_AC_1, HT_AC_1_index, 16}},
+};
+
+Huff* HuffmanDecode::Lookup2(int tc, int th, BitPattern* bitpat)
+{
+    const struct sthtinfo* info = &htinfo[tc][th];
+
+    int pat_size = bitpat->size();
+    uint32_t pat = bitpat->peek(pat_size);
+    if (pat_size > info->max_code_size) {
+        pat >>= (pat_size-info->max_code_size);
+    } else if (pat_size < info->max_code_size) {
+        pat <<= (info->max_code_size-pat_size);
+    }
+    int index = info->index_table[pat];
+    if (index == 0xff) {
+        return NULL;
+    }
+    Huff* huff = (Huff*)&(info->huff_table[index]);
+    if (huff->code_size > pat_size) {
+        return NULL;
+    }
+    return huff;
+}
+
 int HuffmanDecode::getValue(Huff* huff, BitPattern* bitpat)
 {
     int value = bitpat->get(huff->value_size);