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

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Sun Jan 27 11:00:50 2013 +0000
Parent:
4:e243fa781e5c
Child:
6:d7ee458cacd1
Commit message:
bug fix

Changed in this revision

BaseJpegDecode.cpp Show annotated file Show diff for this revision Revisions of this file
BaseJpegDecode.h Show annotated file Show diff for this revision Revisions of this file
--- a/BaseJpegDecode.cpp	Wed Dec 05 12:38:56 2012 +0000
+++ b/BaseJpegDecode.cpp	Sun Jan 27 11:00:50 2013 +0000
@@ -1,3 +1,4 @@
+// BaseJpegDecode.cpp 2013/1/27
 #include "mbed.h"
 #include "BaseJpegDecode.h"
 
@@ -33,12 +34,14 @@
 #define MARK_APP  0xe0
 
 #define SEQ_INIT     0
-#define SEQ_MARK     1
-#define SEQ_SEG_LEN  2
-#define SEQ_SEG_LEN2 3
-#define SEQ_SEG_BODY 4
-#define SEQ_SOS      5
-#define SEQ_SOS2     6
+#define SEQ_SOI      1
+#define SEQ_FRAME    2
+#define SEQ_MARK     3
+#define SEQ_SEG_LEN  4
+#define SEQ_SEG_LEN2 5
+#define SEQ_SEG_BODY 6
+#define SEQ_SOS      7
+#define SEQ_SOS2     8
 
 #define HT_DC 0
 #define HT_AC 1
@@ -127,12 +130,30 @@
     switch(m_seq) {
         case SEQ_INIT:
             if (c == 0xff) {
+                m_seq = SEQ_SOI;
+            }
+            break;
+        case SEQ_SOI:
+            if (c == MARK_SOI) {
+                outputMARK(c);
+                m_seq = SEQ_FRAME;
+            } else {
+                m_seq = SEQ_INIT;
+            }
+            break;
+        case SEQ_FRAME:
+            if (c == 0xff) {
                 m_seq = SEQ_MARK;
+            } else {
+                m_seq = SEQ_INIT;
             }
             break;
         case SEQ_MARK:
             outputMARK(c);
-            if (c == MARK_SOI || c == MARK_EOI) {
+            if (c == MARK_SOI) {
+                m_seq = SEQ_FRAME;
+                break;
+            } else if (c == MARK_EOI || c == 0x00) {
                 m_seq = SEQ_INIT;
                 break;
             }
@@ -165,7 +186,7 @@
                 restart();
                 break;
             }
-            m_seq = SEQ_INIT;
+            m_seq = SEQ_FRAME;
             break;
         case SEQ_SOS:
             if (c == 0xff) {
--- a/BaseJpegDecode.h	Wed Dec 05 12:38:56 2012 +0000
+++ b/BaseJpegDecode.h	Sun Jan 27 11:00:50 2013 +0000
@@ -1,3 +1,4 @@
+// BaseJpegDecode.h 2013/1/27
 #ifndef BASE_JPEG_DECODE_H
 #define BASE_JPEG_DECODE_H
 #include "bjd_config.h"
@@ -27,8 +28,7 @@
     void inputSOF(uint8_t c, int pos, int len);
     void inputScan(uint8_t c);
     void restart();
-protected:
-    int m_seq;
+    uint8_t m_seq;
     int m_mcu;
     int m_block;
     int m_scan;