[Swfdec] libswfdec/jpeg

David Schleef ds at kemper.freedesktop.org
Mon Apr 23 17:11:09 PDT 2007


 libswfdec/jpeg/Makefile.am    |    1 
 libswfdec/jpeg/cogcompat.h    |   14 +++++
 libswfdec/jpeg/jpeg.c         |  113 +++++++++++++++++++++---------------------
 libswfdec/jpeg/jpeg_debug.h   |   13 ----
 libswfdec/jpeg/jpeg_huffman.c |   27 ++++------
 5 files changed, 86 insertions(+), 82 deletions(-)

New commits:
diff-tree 3826e5d8efd94d0b67519e0837bcae24fee038c1 (from 8977e39ad9aac26c936fb40acb2080d0101b75c3)
Author: Debian User <ds at gromit.(none)>
Date:   Mon Apr 23 17:05:52 2007 -0700

    Merge changes from cog.

diff --git a/libswfdec/jpeg/Makefile.am b/libswfdec/jpeg/Makefile.am
index a46ab34..85a13df 100644
--- a/libswfdec/jpeg/Makefile.am
+++ b/libswfdec/jpeg/Makefile.am
@@ -10,6 +10,7 @@ libjpeg_la_SOURCES = \
 	jpeg_tables.c
 
 noinst_HEADERS = \
+	cogcompat.h \
 	jpeg.h \
 	jpeg_bits.h \
 	jpeg_huffman.h \
diff --git a/libswfdec/jpeg/cogcompat.h b/libswfdec/jpeg/cogcompat.h
new file mode 100644
index 0000000..bf2370f
--- /dev/null
+++ b/libswfdec/jpeg/cogcompat.h
@@ -0,0 +1,14 @@
+
+#ifndef _COG_COMPAT_H_
+#define _COG_COMPAT_H_
+
+#include <swfdec_debug.h>
+
+#define COG_LOG(...) SWFDEC_LOG(__VA_ARGS__)
+#define COG_DEBUG(...) SWFDEC_DEBUG(__VA_ARGS__)
+#define COG_INFO(...) SWFDEC_INFO(__VA_ARGS__)
+#define COG_WARNING(...) SWFDEC_WARNING(__VA_ARGS__)
+#define COG_ERROR(...) SWFDEC_ERROR(__VA_ARGS__)
+
+#endif
+
diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index 58dd755..b5d2471 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -5,7 +5,8 @@
 
 #include <liboil/liboil.h>
 #include <liboil/liboil-stdint.h>
-#include <swfdec_debug.h>
+
+#include <cogcompat.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -15,9 +16,6 @@
 #include "jpeg_internal.h"
 
 
-//#define MAX(a,b) ((a)>(b) ? (a) : (b))
-
-
 extern uint8_t jpeg_standard_tables[];
 extern int jpeg_standard_tables_size;
 
@@ -46,17 +44,21 @@ jpeg_decoder_error(JpegDecoder *dec, cha
 
   if (dec->error) return;
 
-  dec->error_message = malloc(250);
   va_start (varargs, fmt);
+#ifdef HAVE_VASPRINTF
+  vasprintf(&dec->error_message, fmt, varargs);
+#else
+  dec->error_message = malloc(250);
   vsnprintf(dec->error_message, 250 - 1, fmt, varargs);
   dec->error_message[250 - 1] = 0;
+#endif
   va_end (varargs);
 
   dec->error = TRUE;
 }
 
 #define jpeg_decoder_error(dec, ...) { \
-  SWFDEC_ERROR("decoder error: "__VA_ARGS__); \
+  COG_ERROR("decoder error: "__VA_ARGS__); \
   jpeg_decoder_error (dec, __VA_ARGS__); \
 }
 
@@ -67,12 +69,12 @@ jpeg_decoder_verify_header (JpegDecoder 
   int i;
 
   if (dec->sof_type != JPEG_MARKER_SOF_0) {
-    SWFDEC_ERROR("only handle baseline DCT");
+    COG_ERROR("only handle baseline DCT");
     dec->error = TRUE;
   }
 
   if (dec->width < 1) {
-    SWFDEC_ERROR("height can't be 0");
+    COG_ERROR("height can't be 0");
     dec->error = TRUE;
   }
 
@@ -81,7 +83,7 @@ jpeg_decoder_verify_header (JpegDecoder 
       /* baseline DCT */
       max_quant_table = 3;
       if (dec->depth != 8) {
-        SWFDEC_ERROR("depth must be 8 (%d)", dec->depth);
+        COG_ERROR("depth must be 8 (%d)", dec->depth);
         dec->error = TRUE;
       }
       break;
@@ -89,7 +91,7 @@ jpeg_decoder_verify_header (JpegDecoder 
       /* extended DCT */
       max_quant_table = 3;
       if (dec->depth != 8 && dec->depth != 12) {
-        SWFDEC_ERROR("depth must be 8 or 12 (%d)", dec->depth);
+        COG_ERROR("depth must be 8 or 12 (%d)", dec->depth);
         dec->error = TRUE;
       }
       break;
@@ -97,7 +99,7 @@ jpeg_decoder_verify_header (JpegDecoder 
       /* progressive DCT */
       max_quant_table = 3;
       if (dec->depth != 8 && dec->depth != 12) {
-        SWFDEC_ERROR("depth must be 8 or 12 (%d)", dec->depth);
+        COG_ERROR("depth must be 8 or 12 (%d)", dec->depth);
         dec->error = TRUE;
       }
       break;
@@ -105,7 +107,7 @@ jpeg_decoder_verify_header (JpegDecoder 
       /* lossless DCT */
       max_quant_table = 0;
       if (dec->depth < 2 || dec->depth > 16) {
-        SWFDEC_ERROR("depth must be between 2 and 16 (%d)", dec->depth);
+        COG_ERROR("depth must be between 2 and 16 (%d)", dec->depth);
         dec->error = TRUE;
       }
       break;
@@ -114,32 +116,32 @@ jpeg_decoder_verify_header (JpegDecoder 
   }
 
   if (dec->n_components < 0 || dec->n_components > 255) {
-    SWFDEC_ERROR("n_components must be in the range 0-255 (%d)",
+    COG_ERROR("n_components must be in the range 0-255 (%d)",
         dec->n_components);
     dec->error = TRUE;
   }
   if (dec->sof_type == JPEG_MARKER_SOF_2 && dec->n_components > 4) {
-    SWFDEC_ERROR("n_components must be <= 4 for progressive DCT (%d)",
+    COG_ERROR("n_components must be <= 4 for progressive DCT (%d)",
         dec->n_components);
     dec->error = TRUE;
   }
 
   for (i = 0; i < dec->n_components; i++) {
     if (dec->components[i].id < 0 || dec->components[i].id > 255) {
-      SWFDEC_ERROR("component ID out of range");
+      COG_ERROR("component ID out of range");
       dec->error = TRUE;
       break;
     }
     if (dec->components[i].h_sample < 1 || dec->components[i].h_sample > 4 ||
         dec->components[i].v_sample < 1 || dec->components[i].v_sample > 4) {
-      SWFDEC_ERROR("sample factor(s) for component %d out of range %d %d",
+      COG_ERROR("sample factor(s) for component %d out of range %d %d",
           i, dec->components[i].h_sample, dec->components[i].v_sample);
       dec->error = TRUE;
       break;
     }
     if (dec->components[i].quant_table < 0 ||
         dec->components[i].quant_table > max_quant_table) {
-      SWFDEC_ERROR("quant table for component %d out of range (%d)",
+      COG_ERROR("quant table for component %d out of range (%d)",
           i, dec->components[i].quant_table);
       dec->error = TRUE;
       break;
@@ -211,7 +213,7 @@ generate_code_table (int *huffsize)
   k = 0;
   for (i = 0; i < 16; i++) {
     for (j = 0; j < huffsize[i]; j++) {
-      SWFDEC_DEBUG ("huffcode[%d] = %s", k,
+      COG_DEBUG ("huffcode[%d] = %s", k,
           sprintbits (str, code >> (15 - i), i + 1));
       code++;
       k++;
@@ -261,7 +263,7 @@ huffman_table_init_jpeg (HuffmanTable *t
      * for bad huffsize[] arrays. */
     if (symbol >= (1U << (i + 1))) {
       /* FIXME jpeg_decoder_error() */
-      SWFDEC_DEBUG ("bad huffsize[] array");
+      COG_ERROR ("bad huffsize[] array");
       return -1;
     }
 
@@ -282,7 +284,7 @@ jpeg_decoder_find_component_by_id (JpegD
     if (dec->components[i].id == id)
       return i;
   }
-  SWFDEC_DEBUG ("undefined component id %d", id);
+  COG_DEBUG ("undefined component id %d", id);
   return 0;
 }
 
@@ -291,10 +293,10 @@ jpeg_decoder_application0 (JpegDecoder *
 {
   int length;
 
-  SWFDEC_DEBUG ("app0");
+  COG_DEBUG ("app0");
 
   length = get_be_u16 (bits);
-  SWFDEC_DEBUG ("length=%d", length);
+  COG_DEBUG ("length=%d", length);
 
   if (memcmp (bits->ptr, "JFIF", 4) == 0 && bits->ptr[4] == 0) {
     int version;
@@ -304,7 +306,7 @@ jpeg_decoder_application0 (JpegDecoder *
     int x_thumbnail;
     int y_thumbnail;
 
-    SWFDEC_DEBUG ("JFIF");
+    COG_DEBUG ("JFIF");
     bits->ptr += 5;
 
     version = get_be_u16 (bits);
@@ -314,17 +316,17 @@ jpeg_decoder_application0 (JpegDecoder *
     x_thumbnail = get_u8 (bits);
     y_thumbnail = get_u8 (bits);
 
-    SWFDEC_DEBUG ("version = %04x", version);
-    SWFDEC_DEBUG ("units = %d", units);
-    SWFDEC_DEBUG ("x_density = %d", x_density);
-    SWFDEC_DEBUG ("y_density = %d", y_density);
-    SWFDEC_DEBUG ("x_thumbnail = %d", x_thumbnail);
-    SWFDEC_DEBUG ("y_thumbnail = %d", y_thumbnail);
+    COG_DEBUG ("version = %04x", version);
+    COG_DEBUG ("units = %d", units);
+    COG_DEBUG ("x_density = %d", x_density);
+    COG_DEBUG ("y_density = %d", y_density);
+    COG_DEBUG ("x_thumbnail = %d", x_thumbnail);
+    COG_DEBUG ("y_thumbnail = %d", y_thumbnail);
 
   }
 
   if (memcmp (bits->ptr, "JFXX", 4) == 0 && bits->ptr[4] == 0) {
-    SWFDEC_DEBUG ("JFIF extension (not handled)");
+    COG_DEBUG ("JFIF extension (not handled)");
     bits->ptr += length - 2;
   }
 
@@ -336,12 +338,12 @@ jpeg_decoder_application_misc (JpegDecod
 {
   int length;
 
-  SWFDEC_DEBUG ("appX");
+  COG_DEBUG ("appX");
 
   length = get_be_u16 (bits);
-  SWFDEC_DEBUG ("length=%d", length);
+  COG_DEBUG ("length=%d", length);
 
-  SWFDEC_DEBUG ("JPEG application tag X ignored");
+  COG_DEBUG ("JPEG application tag X ignored");
   //dumpbits (bits);
 
   bits->ptr += length - 2;
@@ -354,10 +356,10 @@ jpeg_decoder_comment (JpegDecoder * dec,
 {
   int length;
 
-  SWFDEC_DEBUG ("comment");
+  COG_DEBUG ("comment");
 
   length = get_be_u16 (bits);
-  SWFDEC_DEBUG ("length=%d", length);
+  COG_DEBUG ("length=%d", length);
 
   //dumpbits (bits);
 
@@ -371,13 +373,13 @@ jpeg_decoder_restart_interval (JpegDecod
 {
   int length;
 
-  SWFDEC_DEBUG ("comment");
+  COG_DEBUG ("comment");
 
   length = get_be_u16 (bits);
-  SWFDEC_DEBUG ("length=%d", length);
+  COG_DEBUG ("length=%d", length);
 
   dec->restart_interval = get_be_u16 (bits);
-  SWFDEC_DEBUG ("restart_interval=%d", dec->restart_interval);
+  COG_DEBUG ("restart_interval=%d", dec->restart_interval);
 
   return length;
 }
@@ -385,7 +387,7 @@ jpeg_decoder_restart_interval (JpegDecod
 int
 jpeg_decoder_restart (JpegDecoder * dec, JpegBits * bits)
 {
-  SWFDEC_DEBUG ("restart");
+  COG_DEBUG ("restart");
 
   return 0;
 }
@@ -411,11 +413,12 @@ jpeg_decoder_decode_entropy_segment (Jpe
   maxlen = jpeg_bits_available (bits) - 1;
   j = 0;
   while (len < maxlen) {
-    if (bits->ptr[len] == 0xff && bits->ptr[len + 1] != 0x00)
+    if (bits->ptr[len] == 0xff && bits->ptr[len + 1] != 0x00) {
       break;
+    }
     len++;
   }
-  SWFDEC_DEBUG ("entropy length = %d", len);
+  COG_DEBUG ("entropy length = %d", len);
 
   /* we allocate extra space, since the getbits() code can
    * potentially read past the end of the buffer */
@@ -448,7 +451,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
       unsigned char *ptr;
       int component_index;
 
-      SWFDEC_DEBUG ("%d,%d: component=%d dc_table=%d ac_table=%d",
+      COG_DEBUG ("%d,%d: component=%d dc_table=%d ac_table=%d",
           x, y,
           dec->scan_list[i].component_index,
           dec->scan_list[i].dc_table, dec->scan_list[i].ac_table);
@@ -462,7 +465,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
           &dec->dc_huff_table[dc_table_index],
           &dec->ac_huff_table[ac_table_index], bits2);
       if (ret < 0) {
-        SWFDEC_DEBUG ("%d,%d: component=%d dc_table=%d ac_table=%d",
+        COG_DEBUG ("%d,%d: component=%d dc_table=%d ac_table=%d",
             x, y,
             dec->scan_list[i].component_index,
             dec->scan_list[i].dc_table, dec->scan_list[i].ac_table);
@@ -470,7 +473,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
         break;
       }
 
-      SWFDEC_DEBUG ("using quant table %d", quant_index);
+      COG_DEBUG ("using quant table %d", quant_index);
       oil_mult8x8_s16 (block2, block, dec->quant_tables[quant_index].quantizer,
           sizeof (short) * 8, sizeof(short) * 8, sizeof (short) * 8);
       dec->dc[component_index] += block2[0];
@@ -685,7 +688,7 @@ jpeg_decoder_define_huffman_tables (Jpeg
   int x;
   HuffmanTable *hufftab;
 
-  SWFDEC_DEBUG ("define huffman tables");
+  COG_DEBUG ("define huffman tables");
 
   length = jpeg_bits_get_u16_be (bits);
   if (length < 2) {
@@ -701,7 +704,7 @@ jpeg_decoder_define_huffman_tables (Jpeg
     tc = x >> 4;
     th = x & 0xf;
 
-    SWFDEC_DEBUG ("huff table type %d (%s) index %d", tc, tc ? "ac" : "dc", th);
+    COG_DEBUG ("huff table type %d (%s) index %d", tc, tc ? "ac" : "dc", th);
     if (tc > 1 || th > 3) {
       jpeg_decoder_error(dec, "huffman table type or index out of range");
       return;
@@ -731,7 +734,7 @@ jpeg_decoder_define_quantization_tables 
   int tq;
   int i;
 
-  SWFDEC_INFO ("define quantization table");
+  COG_INFO ("define quantization table");
 
   length = jpeg_bits_get_u16_be (bits);
   if (length < 2) {
@@ -806,7 +809,7 @@ jpeg_decoder_start_of_frame (JpegDecoder
   int i;
   int length;
 
-  SWFDEC_INFO ("start of frame");
+  COG_INFO ("start of frame");
 
   dec->sof_type = marker;
 
@@ -823,7 +826,7 @@ jpeg_decoder_start_of_frame (JpegDecoder
   dec->width = jpeg_bits_get_u16_be (bits);
   dec->n_components = jpeg_bits_get_u8 (bits);
 
-  SWFDEC_DEBUG (
+  COG_DEBUG (
       "frame_length=%d depth=%d height=%d width=%d n_components=%d", length,
       dec->depth, dec->height, dec->width, dec->n_components);
 
@@ -838,7 +841,7 @@ jpeg_decoder_start_of_frame (JpegDecoder
     dec->components[i].v_sample = getbits (bits, 4);
     dec->components[i].quant_table = get_u8 (bits);
 
-    SWFDEC_DEBUG (
+    COG_DEBUG (
         "[%d] id=%d h_sample=%d v_sample=%d quant_table=%d", i,
         dec->components[i].id, dec->components[i].h_sample,
         dec->components[i].v_sample, dec->components[i].quant_table);
@@ -859,10 +862,10 @@ jpeg_decoder_start_of_scan (JpegDecoder 
   int tmp;
   int n_components;
 
-  SWFDEC_DEBUG ("start of scan");
+  COG_DEBUG ("start of scan");
 
   length = jpeg_bits_get_u16_be (bits);
-  SWFDEC_DEBUG ("length=%d", length);
+  COG_DEBUG ("length=%d", length);
 
   n_components = jpeg_bits_get_u8 (bits);
   n = 0;
@@ -906,18 +909,18 @@ jpeg_decoder_start_of_scan (JpegDecoder 
     dec->scan_h_subsample = MAX (dec->scan_h_subsample, h_subsample);
     dec->scan_v_subsample = MAX (dec->scan_v_subsample, v_subsample);
 
-    SWFDEC_DEBUG ("component %d: index=%d dc_table=%d ac_table=%d n=%d",
+    COG_DEBUG ("component %d: index=%d dc_table=%d ac_table=%d n=%d",
         component_id, index, dc_table, ac_table, n);
   }
   dec->scan_list_length = n;
 
   spectral_start = jpeg_bits_get_u8 (bits);
   spectral_end = jpeg_bits_get_u8 (bits);
-  SWFDEC_DEBUG ("spectral range [%d,%d]", spectral_start, spectral_end);
+  COG_DEBUG ("spectral range [%d,%d]", spectral_start, spectral_end);
   tmp = jpeg_bits_get_u8 (bits);
   approx_high = tmp >> 4;
   approx_low = tmp & 0xf;
-  SWFDEC_DEBUG ("approx range [%d,%d]", approx_low, approx_high);
+  COG_DEBUG ("approx range [%d,%d]", approx_low, approx_high);
 
   dec->x = 0;
   dec->y = 0;
diff --git a/libswfdec/jpeg/jpeg_debug.h b/libswfdec/jpeg/jpeg_debug.h
deleted file mode 100644
index 921a74b..0000000
--- a/libswfdec/jpeg/jpeg_debug.h
+++ /dev/null
@@ -1,13 +0,0 @@
-
-#ifndef _JPEG_DEBUG_H_
-#define _JPEG_DEBUG_H_
-
-#define JPEG_DEBUG(n, format...)	do{ \
-	if((n)<=JPEG_DEBUG_LEVEL)jpeg_debug((n),format); \
-}while(0)
-#define JPEG_DEBUG_LEVEL 4
-
-void jpeg_debug(int n, const char *format, ... );
-
-#endif
-
diff --git a/libswfdec/jpeg/jpeg_huffman.c b/libswfdec/jpeg/jpeg_huffman.c
index fffaeb0..354916d 100644
--- a/libswfdec/jpeg/jpeg_huffman.c
+++ b/libswfdec/jpeg/jpeg_huffman.c
@@ -8,6 +8,8 @@
 
 #include <string.h>
 
+#include "cogcompat.h"
+
 #include "jpeg_huffman.h"
 
 /* misc helper function definitions */
@@ -15,9 +17,6 @@
 static char *sprintbits (char *str, unsigned int bits, int n);
 
 
-//#define TRUE 1
-//#define FALSE 0
-
 void
 huffman_table_dump (HuffmanTable * table)
 {
@@ -27,13 +26,13 @@ huffman_table_dump (HuffmanTable * table
   int i;
   HuffmanEntry *entry;
 
-  SWFDEC_DEBUG ("dumping huffman table %p", table);
+  COG_DEBUG ("dumping huffman table %p", table);
   for (i = 0; i < table->len; i++) {
     entry = table->entries + i;
     n_bits = entry->n_bits;
     code = entry->symbol >> (16 - n_bits);
     sprintbits (str, code, n_bits);
-    SWFDEC_DEBUG ("%s --> %d", str, entry->value);
+    COG_DEBUG ("%s --> %d", str, entry->value);
   }
 }
 
@@ -70,11 +69,11 @@ huffman_table_decode_jpeg (HuffmanTable 
     if ((code & entry->mask) == entry->symbol) {
       code = getbits (bits, entry->n_bits);
       sprintbits (str, code, entry->n_bits);
-      SWFDEC_DEBUG ("%s --> %d", str, entry->value);
+      COG_DEBUG ("%s --> %d", str, entry->value);
       return entry->value;
     }
   }
-  SWFDEC_ERROR ("huffman sync lost");
+  COG_ERROR ("huffman sync lost");
 
   return -1;
 }
@@ -96,33 +95,33 @@ huffman_table_decode_macroblock (short *
   if ((x >> (s - 1)) == 0) {
     x -= (1 << s) - 1;
   }
-  SWFDEC_DEBUG ("s=%d (block[0]=%d)", s, x);
+  COG_DEBUG ("s=%d (block[0]=%d)", s, x);
   block[0] = x;
 
   for (k = 1; k < 64; k++) {
     rs = huffman_table_decode_jpeg (ac_tab, bits);
     if (rs < 0) {
-      SWFDEC_DEBUG ("huffman error");
+      COG_DEBUG ("huffman error");
       return -1;
     }
     if (bits->ptr > bits->end) {
-      SWFDEC_DEBUG ("overrun");
+      COG_DEBUG ("overrun");
       return -1;
     }
     s = rs & 0xf;
     r = rs >> 4;
     if (s == 0) {
       if (r == 15) {
-        SWFDEC_DEBUG ("r=%d s=%d (skip 16)", r, s);
+        COG_DEBUG ("r=%d s=%d (skip 16)", r, s);
         k += 15;
       } else {
-        SWFDEC_DEBUG ("r=%d s=%d (eob)", r, s);
+        COG_DEBUG ("r=%d s=%d (eob)", r, s);
         break;
       }
     } else {
       k += r;
       if (k >= 64) {
-        SWFDEC_ERROR ("macroblock overrun");
+        COG_ERROR ("macroblock overrun");
         return -1;
       }
       x = getbits (bits, s);
@@ -131,7 +130,7 @@ huffman_table_decode_macroblock (short *
         x -= (1 << s) - 1;
       }
       block[k] = x;
-      SWFDEC_DEBUG ("r=%d s=%d (%s -> block[%d]=%d)", r, s, str, k, x);
+      COG_DEBUG ("r=%d s=%d (%s -> block[%d]=%d)", r, s, str, k, x);
     }
   }
   return 0;


More information about the Swfdec mailing list