huffmancode to decode in real-time for motion-jpeg

Dependents:   BaseJpegDecode_example SimpleJpegDecode_example Dumb_box_rev2

example code:

Import programBaseJpegDecode_example

BaseJpegDeocde exampe program

Import programSimpleJpegDecode_example

convert JPEG stream data to bitmap, BaseJpegDecode example program

Revision:
3:a7547692071d
Parent:
2:5b1dd4e34857
Child:
4:e243fa781e5c
--- a/BaseJpegDecode.cpp	Tue Oct 30 13:22:08 2012 +0000
+++ b/BaseJpegDecode.cpp	Mon Nov 05 22:47:05 2012 +0000
@@ -45,7 +45,7 @@
 
 BaseJpegDecode::BaseJpegDecode()
 {
-    m_yblocks = JPEG_MCU_YBLOCKS; // 2 or 4
+    yblock = JPEG_MCU_YBLOCK; // 2 or 4
     clear();
     pHD = new HuffmanDecode;
     DBG_ASSERT(pHD);
@@ -92,20 +92,22 @@
 {
     switch(pos) {
         case 1:
-        case 3:
-            m_param1 = c<<8;
+            height = (height&0x00ff) | (c<<8);
             break;
         case 2:
-            height = m_param1 | c;
+            height = (height&0xff00) | c;
+            break;
+        case 3:
+            width = (width&0x00ff) | (c<<8);
             break;
         case 4:
-            width = m_param1 | c;
+            width = (width&0xff00) | c;
             break;
         case 7:
             if (c == 0x22) {
-                m_yblocks = 4;
+                yblock = 4;
             } else if (c == 0x21) {
-                m_yblocks = 2;
+                yblock = 2;
             } else {
                 DBG_ASSERT(c == 0x22 || c == 0x21);
             }
@@ -188,7 +190,7 @@
     m_bitpat += c;
     while(m_bitpat.size() > 0) {
         int tc = (m_scan == 0) ? HT_DC : HT_AC;
-        int th = (m_block < m_yblocks) ? 0 : 1;
+        int th = (m_block < yblock) ? 0 : 1;
         DBG("%d %d %08x %d\n", tc, th, m_bitpat.peek(32), m_bitpat.size());
         if (m_huff == NULL) {
             m_huff = pHD->Lookup(tc, th, &m_bitpat);
@@ -204,9 +206,9 @@
         int value = pHD->getValue(m_huff, &m_bitpat);
         if (tc == HT_DC) {
             int sc = 0; // Y
-            if (m_block == m_yblocks) {
+            if (m_block == yblock) {
                 sc = 1; // Cb
-            } else if (m_block == (m_yblocks+1)) {
+            } else if (m_block == (yblock+1)) {
                 sc = 2; // Cr
             }
             value += m_pre_DC_value[sc];
@@ -229,7 +231,7 @@
             }
             if (m_scan >= 64) {
                 m_scan = 0;
-                if (++m_block >= (m_yblocks+2)) {
+                if (++m_block >= (yblock+2)) {
                     m_block = 0;
                     m_mcu++;
                 }