[Swfdec] libswfdec/jpeg libswfdec/swfdec_image.c

David Schleef ds at kemper.freedesktop.org
Tue Feb 13 18:01:33 PST 2007


 libswfdec/jpeg/Makefile.am         |   18 -
 libswfdec/jpeg/bits.h              |  140 ++++++-------
 libswfdec/jpeg/huffman.c           |   67 +++---
 libswfdec/jpeg/huffman.h           |   35 +--
 libswfdec/jpeg/jpeg.c              |  217 +++++++-------------
 libswfdec/jpeg/jpeg.h              |   28 +-
 libswfdec/jpeg/jpeg_debug.h        |   25 --
 libswfdec/jpeg/jpeg_internal.h     |  143 ++++++-------
 libswfdec/jpeg/jpeg_rgb_decoder.c  |  383 ++++++++++++++++++++++---------------
 libswfdec/jpeg/jpeg_rgb_decoder.h  |   19 -
 libswfdec/jpeg/jpeg_rgb_internal.h |   36 ---
 libswfdec/jpeg/test.c              |   12 -
 libswfdec/jpeg/test_rgb.c          |   83 ++++----
 libswfdec/swfdec_image.c           |   58 ++---
 14 files changed, 605 insertions(+), 659 deletions(-)

New commits:
diff-tree 46831ced770ebb02396352f786f861624f4b424a (from 634736d7d5ba5b7e3ef43893278b95fac05a3cb2)
Author: Debian User <ds at gromit.(none)>
Date:   Tue Feb 13 17:59:48 2007 -0800

    Merge jpeg library from liboil/examples/jpeg.  The API has changed
    slightly, and the chroma upscaling has been improved significantly.

diff --git a/libswfdec/jpeg/Makefile.am b/libswfdec/jpeg/Makefile.am
index 8b5f308..88356fa 100644
--- a/libswfdec/jpeg/Makefile.am
+++ b/libswfdec/jpeg/Makefile.am
@@ -1,25 +1,21 @@
 
 
 noinst_LTLIBRARIES = libjpeg.la
+noinst_PROGRAMS = jpeg_test jpeg_rgb_test
 
 libjpeg_la_SOURCES = jpeg.c huffman.c jpeg_rgb_decoder.c
-libjpeg_la_CFLAGS = $(GLOBAL_CFLAGS) $(SWF_CFLAGS) $(GLIB_CFLAGS) $(LIBOIL_CFLAGS) \
-	-DG_LOG_DOMAIN=\"Swfdec\"
-libjpeg_la_LDFLAGS = -lm
+libjpeg_la_CFLAGS = $(GLOBAL_CFLAGS) $(LIBOIL_CFLAGS)
 
 noinst_HEADERS = bits.h huffman.h jpeg.h jpeg_debug.h \
-	jpeg_internal.h jpeg_rgb_decoder.h jpeg_rgb_internal.h
+	jpeg_internal.h
 	
 
-noinst_PROGRAMS = jpeg_test jpeg_rgb_test
 
 jpeg_test_SOURCES = test.c
-jpeg_test_CFLAGS = $(GLIB_CFLAGS)
-jpeg_test_LDFLAGS = -lm $(LIBOIL_LIBS)
-jpeg_test_LDADD = libjpeg.la $(GLIB_LIBS)
+jpeg_test_CFLAGS = $(LIBOIL_CFLAGS)
+jpeg_test_LDADD = libjpeg.la $(LIBOIL_LIBS)
 
 jpeg_rgb_test_SOURCES = test_rgb.c
-jpeg_rgb_test_CFLAGS = $(GLIB_CFLAGS)
-jpeg_rgb_test_LDFLAGS = -lm $(LIBOIL_LIBS)
-jpeg_rgb_test_LDADD = libjpeg.la $(GLIB_LIBS)
+jpeg_rgb_test_CFLAGS = $(LIBOIL_CFLAGS)
+jpeg_rgb_test_LDADD = libjpeg.la $(LIBOIL_LIBS)
 
diff --git a/libswfdec/jpeg/bits.h b/libswfdec/jpeg/bits.h
index 137b2cc..95f4e90 100644
--- a/libswfdec/jpeg/bits.h
+++ b/libswfdec/jpeg/bits.h
@@ -3,132 +3,118 @@
 #define __BITS_H__
 
 typedef struct bits_struct bits_t;
-struct bits_struct
-{
-  unsigned char *ptr;
-  int idx;
-  unsigned char *end;
+struct bits_struct {
+	unsigned char *ptr;
+	int idx;
+	unsigned char *end;
 };
 
-static inline int
-bits_needbits (bits_t * b, int n_bytes)
+static inline int bits_needbits(bits_t *b, int n_bytes)
 {
-  if (b->ptr == NULL)
-    return 1;
-  if (b->ptr + n_bytes > b->end)
-    return 1;
+	if(b->ptr==NULL)return 1;
+	if(b->ptr + n_bytes > b->end)return 1;
 
-  return 0;
+	return 0;
 }
 
-static inline int
-getbit (bits_t * b)
+static inline int getbit(bits_t *b)
 {
-  int r;
+	int r;
 
-  r = ((*b->ptr) >> (7 - b->idx)) & 1;
+	r = ((*b->ptr)>>(7-b->idx))&1;
 
-  b->idx++;
-  if (b->idx >= 8) {
-    b->ptr++;
-    b->idx = 0;
-  }
+	b->idx++;
+	if(b->idx>=8){
+		b->ptr++;
+		b->idx = 0;
+	}
 
-  return r;
+	return r;
 }
 
-static inline unsigned int
-getbits (bits_t * b, int n)
+static inline unsigned int getbits(bits_t *b, int n)
 {
-  unsigned long r = 0;
-  int i;
+	unsigned long r = 0;
+	int i;
 
-  for (i = 0; i < n; i++) {
-    r <<= 1;
-    r |= getbit (b);
-  }
+	for(i=0;i<n;i++){
+		r <<=1;
+		r |= getbit(b);
+	}
 
-  return r;
+	return r;
 }
 
-static inline unsigned int
-peekbits (bits_t * b, int n)
+static inline unsigned int peekbits(bits_t *b, int n)
 {
-  bits_t tmp = *b;
+	bits_t tmp = *b;
 
-  return getbits (&tmp, n);
+	return getbits(&tmp, n);
 }
 
-static inline int
-getsbits (bits_t * b, int n)
+static inline int getsbits(bits_t *b, int n)
 {
-  unsigned long r = 0;
-  int i;
+	unsigned long r = 0;
+	int i;
 
-  if (n == 0)
-    return 0;
-  r = -getbit (b);
-  for (i = 1; i < n; i++) {
-    r <<= 1;
-    r |= getbit (b);
-  }
+	if(n==0)return 0;
+	r = -getbit(b);
+	for(i=1;i<n;i++){
+		r <<=1;
+		r |= getbit(b);
+	}
 
-  return r;
+	return r;
 }
 
-static inline unsigned int
-peek_u8 (bits_t * b)
+static inline unsigned int peek_u8(bits_t *b)
 {
-  return *b->ptr;
+	return *b->ptr;
 }
 
-static inline unsigned int
-get_u8 (bits_t * b)
+static inline unsigned int get_u8(bits_t *b)
 {
-  return *b->ptr++;
+	return *b->ptr++;
 }
 
-static inline unsigned int
-get_u16 (bits_t * b)
+static inline unsigned int get_u16(bits_t *b)
 {
-  unsigned int r;
+	unsigned int r;
 
-  r = b->ptr[0] | (b->ptr[1] << 8);
-  b->ptr += 2;
+	r = b->ptr[0] | (b->ptr[1]<<8);
+	b->ptr+=2;
 
-  return r;
+	return r;
 }
 
-static inline unsigned int
-get_be_u16 (bits_t * b)
+static inline unsigned int get_be_u16(bits_t *b)
 {
-  unsigned int r;
+	unsigned int r;
 
-  r = (b->ptr[0] << 8) | b->ptr[1];
-  b->ptr += 2;
+	r = (b->ptr[0]<<8) | b->ptr[1];
+	b->ptr+=2;
 
-  return r;
+	return r;
 }
 
-static inline unsigned int
-get_u32 (bits_t * b)
+static inline unsigned int get_u32(bits_t *b)
 {
-  unsigned int r;
+	unsigned int r;
 
-  r = b->ptr[0] | (b->ptr[1] << 8) | (b->ptr[2] << 16) | (b->ptr[3] << 24);
-  b->ptr += 4;
+	r = b->ptr[0] | (b->ptr[1]<<8) | (b->ptr[2]<<16) | (b->ptr[3]<<24);
+	b->ptr+=4;
 
-  return r;
+	return r;
 }
 
-static inline void
-syncbits (bits_t * b)
+static inline void syncbits(bits_t *b)
 {
-  if (b->idx) {
-    b->ptr++;
-    b->idx = 0;
-  }
+	if(b->idx){
+		b->ptr++;
+		b->idx=0;
+	}
 
 }
 
 #endif
+
diff --git a/libswfdec/jpeg/huffman.c b/libswfdec/jpeg/huffman.c
index e395547..6fb04ca 100644
--- a/libswfdec/jpeg/huffman.c
+++ b/libswfdec/jpeg/huffman.c
@@ -4,19 +4,25 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <glib.h>
 #include <string.h>
 
+#include <liboil/liboil.h>
+//#include <liboil/liboildebug.h>
+
+#define OIL_DEBUG(...) do { } while (0)
+
 #include "huffman.h"
 #include "jpeg_debug.h"
 
+#define DEBUG printf
+
 /* misc helper function definitions */
 
 static char *sprintbits (char *str, unsigned int bits, int n);
 
-#undef JPEG_LOG
-#define JPEG_LOG(...)
 
+#define TRUE 1
+#define FALSE 0
 
 void
 huffman_table_dump (HuffmanTable * table)
@@ -24,16 +30,16 @@ huffman_table_dump (HuffmanTable * table
   unsigned int n_bits;
   unsigned int code;
   char str[33];
-  unsigned int i;
+  int i;
   HuffmanEntry *entry;
 
-  JPEG_LOG ("dumping huffman table %p", table);
+  OIL_DEBUG ("dumping huffman table %p", table);
   for (i = 0; i < table->len; i++) {
-    entry = &g_array_index (table, HuffmanEntry, i);
+    entry = table->entries + i;
     n_bits = entry->n_bits;
     code = entry->symbol >> (16 - n_bits);
     sprintbits (str, code, n_bits);
-    JPEG_LOG ("%s --> %d", str, entry->value);
+    OIL_DEBUG ("%s --> %d", str, entry->value);
   }
 }
 
@@ -42,7 +48,8 @@ huffman_table_new (void)
 {
   HuffmanTable *table;
 
-  table = g_array_new (FALSE, TRUE, sizeof (HuffmanEntry));
+  table = malloc (sizeof(HuffmanTable));
+  memset (table, 0, sizeof(HuffmanTable));
 
   return table;
 }
@@ -50,41 +57,41 @@ huffman_table_new (void)
 void
 huffman_table_free (HuffmanTable * table)
 {
-  g_array_free (table, TRUE);
+  free (table);
 }
 
 void
-huffman_table_add (HuffmanTable * table, guint32 code, gint n_bits, gint value)
+huffman_table_add (HuffmanTable * table, uint32_t code, int n_bits, int value)
 {
-  HuffmanEntry entry;
+  HuffmanEntry *entry = table->entries + table->len;
 
-  entry.value = value;
-  entry.symbol = code << (16 - n_bits);
-  entry.mask = 0xffff ^ (0xffff >> n_bits);
-  entry.n_bits = n_bits;
+  entry->value = value;
+  entry->symbol = code << (16 - n_bits);
+  entry->mask = 0xffff ^ (0xffff >> n_bits);
+  entry->n_bits = n_bits;
 
-  g_array_append_val (table, entry);
+  table->len++;
 }
 
 unsigned int
 huffman_table_decode_jpeg (HuffmanTable * tab, bits_t * bits)
 {
   unsigned int code;
-  unsigned int i;
+  int i;
   char str[33];
   HuffmanEntry *entry;
 
   code = peekbits (bits, 16);
   for (i = 0; i < tab->len; i++) {
-    entry = &g_array_index (tab, HuffmanEntry, i);
+    entry = tab->entries + i;
     if ((code & entry->mask) == entry->symbol) {
       code = getbits (bits, entry->n_bits);
       sprintbits (str, code, entry->n_bits);
-      JPEG_LOG ("%s --> %d", str, entry->value);
+      OIL_DEBUG ("%s --> %d", str, entry->value);
       return entry->value;
     }
   }
-  JPEG_ERROR ("huffman sync lost");
+  printf ("huffman sync lost");
 
   return -1;
 }
@@ -95,7 +102,7 @@ huffman_table_decode_macroblock (short *
 {
   int r, s, x, rs;
   int k;
-  //char str[33] = "NA";
+  char str[33];
 
   memset (block, 0, sizeof (short) * 64);
 
@@ -106,42 +113,42 @@ huffman_table_decode_macroblock (short *
   if ((x >> (s - 1)) == 0) {
     x -= (1 << s) - 1;
   }
-  JPEG_LOG ("s=%d (block[0]=%d)", s, x);
+  OIL_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) {
-      JPEG_ERROR ("huffman error");
+      OIL_DEBUG ("huffman error");
       return -1;
     }
     if (bits->ptr > bits->end) {
-      JPEG_ERROR ("overrun");
+      OIL_DEBUG ("overrun");
       return -1;
     }
     s = rs & 0xf;
     r = rs >> 4;
     if (s == 0) {
       if (r == 15) {
-        JPEG_LOG ("r=%d s=%d (skip 16)", r, s);
+        OIL_DEBUG ("r=%d s=%d (skip 16)", r, s);
         k += 15;
       } else {
-        JPEG_LOG ("r=%d s=%d (eob)", r, s);
+        OIL_DEBUG ("r=%d s=%d (eob)", r, s);
         break;
       }
     } else {
       k += r;
       if (k >= 64) {
-        JPEG_ERROR ("macroblock overrun");
+        printf ("macroblock overrun");
         return -1;
       }
       x = getbits (bits, s);
-      //sprintbits (str, x, s);
+      sprintbits (str, x, s);
       if ((x >> (s - 1)) == 0) {
         x -= (1 << s) - 1;
       }
       block[k] = x;
-      //JPEG_LOG ("r=%d s=%d (%s -> block[%d]=%d)", r, s, str, k, x);
+      OIL_DEBUG ("r=%d s=%d (%s -> block[%d]=%d)", r, s, str, k, x);
     }
   }
   return 0;
@@ -163,7 +170,7 @@ huffman_table_decode (HuffmanTable * dc_
 
     q = zz;
     for (i = 0; i < 8; i++) {
-      JPEG_LOG ("%3d %3d %3d %3d %3d %3d %3d %3d",
+      DEBUG ("%3d %3d %3d %3d %3d %3d %3d %3d",
           q[0], q[1], q[2], q[3], q[4], q[5], q[6], q[7]);
       q += 8;
     }
diff --git a/libswfdec/jpeg/huffman.h b/libswfdec/jpeg/huffman.h
index c0262f3..e3bd94a 100644
--- a/libswfdec/jpeg/huffman.h
+++ b/libswfdec/jpeg/huffman.h
@@ -2,31 +2,36 @@
 #ifndef _HUFFMAN_H_
 #define _HUFFMAN_H_
 
-#include <glib.h>
+#include <liboil/liboil-stdint.h>
+
 #include "bits.h"
 
-typedef struct huffman_entry_struct HuffmanEntry;
-typedef GArray HuffmanTable;
+typedef struct _HuffmanEntry HuffmanEntry;
+typedef struct _HuffmanTable HuffmanTable;
 
-struct huffman_entry_struct
-{
+struct _HuffmanEntry {
   unsigned int symbol;
   unsigned int mask;
   int n_bits;
   unsigned char value;
 };
 
+struct _HuffmanTable {
+  int len;
+  HuffmanEntry entries[256];
+};
+
 
-void huffman_table_dump (HuffmanTable * table);
-HuffmanTable *huffman_table_new (void);
-void huffman_table_free (HuffmanTable * table);
-void huffman_table_add (HuffmanTable * table, guint32 code, gint n_bits,
-    gint value);
-unsigned int huffman_table_decode_jpeg (HuffmanTable * tab, bits_t * bits);
-int huffman_table_decode_macroblock (short *block, HuffmanTable * dc_tab,
-    HuffmanTable * ac_tab, bits_t * bits);
-int huffman_table_decode (HuffmanTable * dc_tab, HuffmanTable * ac_tab,
-    bits_t * bits);
+void huffman_table_dump(HuffmanTable *table);
+HuffmanTable *huffman_table_new(void);
+void huffman_table_free(HuffmanTable *table);
+void huffman_table_add(HuffmanTable *table, uint32_t code, int n_bits,
+	int value);
+unsigned int huffman_table_decode_jpeg(HuffmanTable *tab, bits_t *bits);
+int huffman_table_decode_macroblock(short *block, HuffmanTable *dc_tab,
+	HuffmanTable *ac_tab, bits_t *bits);
+int huffman_table_decode(HuffmanTable *dc_tab, HuffmanTable *ac_tab, bits_t *bits);
 
 
 #endif
+
diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index 7813bf8..06c60c5 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -4,14 +4,21 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <glib.h>
 #include <string.h>
 #include <ctype.h>
+#include <limits.h>
+#include <liboil/liboil-stdint.h>
 #include <liboil/liboil.h>
+//#include <liboil/liboildebug.h>
+#include <stdarg.h>
+
+#define OIL_DEBUG(...) do {} while (0)
 
 #include "jpeg_internal.h"
 
 
+#define MAX(a,b) ((a)>(b) ? (a) : (b))
+
 
 #define JPEG_MARKER_STUFFED		0x00
 #define JPEG_MARKER_TEM			0x01
@@ -58,7 +65,7 @@
 
 struct jpeg_marker_struct
 {
-  int tag;
+  unsigned int tag;
   int (*func) (JpegDecoder * dec, bits_t * bits);
   char *name;
   unsigned int flags;
@@ -90,13 +97,13 @@ static struct jpeg_marker_struct jpeg_ma
   {0xc6, NULL, "differential progressive DCT"},
   {0xc7, NULL, "differential lossless (sequential)"},
   {0xc8, NULL, "reserved"},
-  {0xc9, NULL, "extended sequential DCT"},
-  {0xca, NULL, "progressive DCT"},
-  {0xcb, NULL, "lossless (sequential)"},
+  {0xc9, NULL, "extended sequential DCT (arith)"},
+  {0xca, NULL, "progressive DCT (arith)"},
+  {0xcb, NULL, "lossless (sequential) (arith)"},
   {0xcc, NULL, "define arithmetic coding conditioning(s)"},
-  {0xcd, NULL, "differential sequential DCT"},
-  {0xce, NULL, "differential progressive DCT"},
-  {0xcf, NULL, "differential lossless (sequential)"},
+  {0xcd, NULL, "differential sequential DCT (arith)"},
+  {0xce, NULL, "differential progressive DCT (arith)"},
+  {0xcf, NULL, "differential lossless (sequential) (arith)"},
 
   {0xd0, jpeg_decoder_restart, "restart0", JPEG_ENTROPY_SEGMENT},
   {0xd1, jpeg_decoder_restart, "restart1", JPEG_ENTROPY_SEGMENT},
@@ -191,9 +198,6 @@ static unsigned char std_tables[] = {
 /* misc helper function declarations */
 
 static void dumpbits (bits_t * bits);
-#if 0
-static char *sprintbits (char *str, unsigned int bits, int n);
-#endif
 
 static void huffman_table_load_std_jpeg (JpegDecoder * dec);
 
@@ -219,7 +223,7 @@ jpeg_decoder_sof_baseline_dct (JpegDecod
   int rowstride;
   int max_h_oversample = 0, max_v_oversample = 0;
 
-  JPEG_DEBUG ("start of frame (baseline DCT)");
+  OIL_DEBUG ("start of frame (baseline DCT)");
 
   length = get_be_u16 (bits);
   bits->end = bits->ptr + length - 2;
@@ -229,8 +233,9 @@ jpeg_decoder_sof_baseline_dct (JpegDecod
   dec->width = get_be_u16 (bits);
   dec->n_components = get_u8 (bits);
 
-  JPEG_DEBUG ("frame_length=%d depth=%d height=%d width=%d n_components=%d",
-      length, dec->depth, dec->height, dec->width, dec->n_components);
+  OIL_DEBUG (
+      "frame_length=%d depth=%d height=%d width=%d n_components=%d", length,
+      dec->depth, dec->height, dec->width, dec->n_components);
 
   for (i = 0; i < dec->n_components; i++) {
     dec->components[i].id = get_u8 (bits);
@@ -238,10 +243,9 @@ jpeg_decoder_sof_baseline_dct (JpegDecod
     dec->components[i].v_oversample = getbits (bits, 4);
     dec->components[i].quant_table = get_u8 (bits);
 
-    JPEG_DEBUG ("[%d] id=%d h_oversample=%d v_oversample=%d quant_table=%d",
-        i,
-        dec->components[i].id,
-        dec->components[i].h_oversample,
+    OIL_DEBUG (
+        "[%d] id=%d h_oversample=%d v_oversample=%d quant_table=%d", i,
+        dec->components[i].id, dec->components[i].h_oversample,
         dec->components[i].v_oversample, dec->components[i].quant_table);
 
     max_h_oversample = MAX (max_h_oversample, dec->components[i].h_oversample);
@@ -263,13 +267,11 @@ jpeg_decoder_sof_baseline_dct (JpegDecod
         (dec->height_blocks * 8 * max_v_oversample /
         dec->components[i].v_subsample);
     dec->components[i].rowstride = rowstride;
-    dec->components[i].image = g_malloc (image_size);
+    dec->components[i].image = malloc (image_size);
   }
 
-#ifdef JPEG_DEBUG_ON
   if (bits->end != bits->ptr)
-    JPEG_WARNING ("endptr != bits");
-#endif
+    OIL_DEBUG ("endptr != bits");
 
   return length;
 }
@@ -283,7 +285,7 @@ jpeg_decoder_define_quant_table (JpegDec
   int i;
   short *q;
 
-  JPEG_DEBUG ("define quantization table");
+  OIL_DEBUG ("define quantization table");
 
   length = get_be_u16 (bits);
   bits->end = bits->ptr + length - 2;
@@ -303,9 +305,9 @@ jpeg_decoder_define_quant_table (JpegDec
       }
     }
 
-    JPEG_LOG ("quant table index %d:", tq);
+    OIL_DEBUG ("quant table index %d:", tq);
     for (i = 0; i < 8; i++) {
-      JPEG_LOG ("%3d %3d %3d %3d %3d %3d %3d %3d",
+      OIL_DEBUG ("%3d %3d %3d %3d %3d %3d %3d %3d",
           q[0], q[1], q[2], q[3], q[4], q[5], q[6], q[7]);
       q += 8;
     }
@@ -314,31 +316,6 @@ jpeg_decoder_define_quant_table (JpegDec
   return length;
 }
 
-void
-generate_code_table (int *huffsize)
-{
-  int code;
-  int i;
-  int j;
-  int k;
-  //char str[33];
-
-  //int l;
-
-  code = 0;
-  k = 0;
-  for (i = 0; i < 16; i++) {
-    for (j = 0; j < huffsize[i]; j++) {
-      JPEG_LOG ("huffcode[%d] = %s", k,
-          sprintbits (str, code >> (15 - i), i + 1));
-      code++;
-      k++;
-    }
-    code <<= 1;
-  }
-
-}
-
 HuffmanTable *
 huffman_table_new_jpeg (bits_t * bits)
 {
@@ -375,8 +352,8 @@ huffman_table_new_jpeg (bits_t * bits)
     /* This checks that our symbol is actually less than the
      * number of bits we think it is.  This is only triggered
      * for bad huffsize[] arrays. */
-    if ( symbol >= (unsigned int) (1 << (i + 1))) {
-      JPEG_WARNING ("bad huffsize[] array");
+    if (symbol >= (1U << (i + 1))) {
+      OIL_DEBUG ("bad huffsize[] array");
       return NULL;
     }
 
@@ -396,7 +373,7 @@ jpeg_decoder_define_huffman_table (JpegD
   int th;
   HuffmanTable *hufftab;
 
-  JPEG_DEBUG ("define huffman table");
+  OIL_DEBUG ("define huffman table");
 
   length = get_be_u16 (bits);
   bits->end = bits->ptr + length - 2;
@@ -405,8 +382,8 @@ jpeg_decoder_define_huffman_table (JpegD
     tc = getbits (bits, 4);
     th = getbits (bits, 4);
 
-    JPEG_DEBUG ("huff table index %d:", th);
-    JPEG_DEBUG ("type %d (%s)", tc, tc ? "ac" : "dc");
+    OIL_DEBUG ("huff table index %d:", th);
+    OIL_DEBUG ("type %d (%s)", tc, tc ? "ac" : "dc");
 
     hufftab = huffman_table_new_jpeg (bits);
     if (tc) {
@@ -440,7 +417,7 @@ dumpbits (bits_t * bits)
     for (j = 0; j < 8; j++) {
       s[j + 24] = (isprint (p[j])) ? p[j] : '.';
     }
-    JPEG_DEBUG ("%s", s);
+    OIL_DEBUG ("%s", s);
     p += 8;
   }
 
@@ -455,7 +432,7 @@ jpeg_decoder_find_component_by_id (JpegD
     if (dec->components[i].id == id)
       return i;
   }
-  JPEG_DEBUG ("undefined component id %d", id);
+  OIL_DEBUG ("undefined component id %d", id);
   return 0;
 }
 
@@ -472,11 +449,11 @@ jpeg_decoder_sos (JpegDecoder * dec, bit
   int approx_low;
   int n;
 
-  JPEG_DEBUG ("start of scan");
+  OIL_DEBUG ("start of scan");
 
   length = get_be_u16 (bits);
   bits->end = bits->ptr + length - 2;
-  JPEG_DEBUG ("length=%d", length);
+  OIL_DEBUG ("length=%d", length);
 
   n_components = get_u8 (bits);
   n = 0;
@@ -521,27 +498,25 @@ jpeg_decoder_sos (JpegDecoder * dec, bit
 
     syncbits (bits);
 
-    JPEG_DEBUG ("component %d: index=%d dc_table=%d ac_table=%d n=%d",
+    OIL_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 = get_u8 (bits);
   spectral_end = get_u8 (bits);
-  JPEG_DEBUG ("spectral range [%d,%d]", spectral_start, spectral_end);
+  OIL_DEBUG ("spectral range [%d,%d]", spectral_start, spectral_end);
   approx_high = getbits (bits, 4);
   approx_low = getbits (bits, 4);
-  JPEG_DEBUG ("approx range [%d,%d]", approx_low, approx_high);
+  OIL_DEBUG ("approx range [%d,%d]", approx_low, approx_high);
   syncbits (bits);
 
   dec->x = 0;
   dec->y = 0;
   dec->dc[0] = dec->dc[1] = dec->dc[2] = dec->dc[3] = 128 * 8;
 
-#ifdef JPEG_DEBUG_ON
   if (bits->end != bits->ptr)
-    JPEG_DEBUG ("endptr != bits");
-#endif
+    OIL_DEBUG ("endptr != bits");
 
   return length;
 }
@@ -551,10 +526,10 @@ jpeg_decoder_application0 (JpegDecoder *
 {
   int length;
 
-  JPEG_DEBUG ("app0");
+  OIL_DEBUG ("app0");
 
   length = get_be_u16 (bits);
-  JPEG_DEBUG ("length=%d", length);
+  OIL_DEBUG ("length=%d", length);
 
   if (memcmp (bits->ptr, "JFIF", 4) == 0 && bits->ptr[4] == 0) {
     int version;
@@ -564,7 +539,7 @@ jpeg_decoder_application0 (JpegDecoder *
     int x_thumbnail;
     int y_thumbnail;
 
-    JPEG_DEBUG ("JFIF");
+    OIL_DEBUG ("JFIF");
     bits->ptr += 5;
 
     version = get_be_u16 (bits);
@@ -574,17 +549,17 @@ jpeg_decoder_application0 (JpegDecoder *
     x_thumbnail = get_u8 (bits);
     y_thumbnail = get_u8 (bits);
 
-    JPEG_DEBUG ("version = %04x", version);
-    JPEG_DEBUG ("units = %d", units);
-    JPEG_DEBUG ("x_density = %d", x_density);
-    JPEG_DEBUG ("y_density = %d", y_density);
-    JPEG_DEBUG ("x_thumbnail = %d", x_thumbnail);
-    JPEG_DEBUG ("y_thumbnail = %d", y_thumbnail);
+    OIL_DEBUG ("version = %04x", version);
+    OIL_DEBUG ("units = %d", units);
+    OIL_DEBUG ("x_density = %d", x_density);
+    OIL_DEBUG ("y_density = %d", y_density);
+    OIL_DEBUG ("x_thumbnail = %d", x_thumbnail);
+    OIL_DEBUG ("y_thumbnail = %d", y_thumbnail);
 
   }
 
   if (memcmp (bits->ptr, "JFXX", 4) == 0 && bits->ptr[4] == 0) {
-    JPEG_WARNING ("JFIF extension (not handled)");
+    OIL_DEBUG ("JFIF extension (not handled)");
     bits->ptr += length - 2;
   }
 
@@ -596,12 +571,12 @@ jpeg_decoder_application_misc (JpegDecod
 {
   int length;
 
-  JPEG_DEBUG ("appX");
+  OIL_DEBUG ("appX");
 
   length = get_be_u16 (bits);
-  JPEG_DEBUG ("length=%d", length);
+  OIL_DEBUG ("length=%d", length);
 
-  JPEG_INFO ("JPEG application tag X ignored");
+  OIL_DEBUG ("JPEG application tag X ignored");
   dumpbits (bits);
 
   bits->ptr += length - 2;
@@ -614,10 +589,10 @@ jpeg_decoder_comment (JpegDecoder * dec,
 {
   int length;
 
-  JPEG_DEBUG ("comment");
+  OIL_DEBUG ("comment");
 
   length = get_be_u16 (bits);
-  JPEG_DEBUG ("length=%d", length);
+  OIL_DEBUG ("length=%d", length);
 
   dumpbits (bits);
 
@@ -631,13 +606,13 @@ jpeg_decoder_restart_interval (JpegDecod
 {
   int length;
 
-  JPEG_DEBUG ("comment");
+  OIL_DEBUG ("comment");
 
   length = get_be_u16 (bits);
-  JPEG_DEBUG ("length=%d", length);
+  OIL_DEBUG ("length=%d", length);
 
   dec->restart_interval = get_be_u16 (bits);
-  JPEG_DEBUG ("restart_interval=%d", dec->restart_interval);
+  OIL_DEBUG ("restart_interval=%d", dec->restart_interval);
 
   return length;
 }
@@ -645,7 +620,7 @@ jpeg_decoder_restart_interval (JpegDecod
 int
 jpeg_decoder_restart (JpegDecoder * dec, bits_t * bits)
 {
-  JPEG_DEBUG ("restart");
+  OIL_DEBUG ("restart");
 
   return 0;
 }
@@ -673,11 +648,11 @@ jpeg_decoder_decode_entropy_segment (Jpe
     }
     len++;
   }
-  JPEG_DEBUG ("entropy length = %d", len);
+  OIL_DEBUG ("entropy length = %d", len);
 
   /* we allocate extra space, since the getbits() code can
    * potentially read past the end of the buffer */
-  newptr = g_malloc (len + 2);
+  newptr = malloc (len + 2);
   for (i = 0; i < len; i++) {
     newptr[j] = bits->ptr[i];
     j++;
@@ -697,9 +672,8 @@ jpeg_decoder_decode_entropy_segment (Jpe
   x = dec->x;
   y = dec->y;
   n = dec->restart_interval;
-  if (n == 0)
-    n = G_MAXINT;
-  while (go && n-- > 0) {
+  if (n == 0) n = INT_MAX;
+  while (n-- > 0) {
     for (i = 0; i < dec->scan_list_length; i++) {
       int dc_table_index;
       int ac_table_index;
@@ -707,7 +681,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
       unsigned char *ptr;
       int component_index;
 
-      JPEG_LOG ("%d,%d: component=%d dc_table=%d ac_table=%d",
+      OIL_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);
@@ -721,7 +695,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) {
-        JPEG_LOG ("%d,%d: component=%d dc_table=%d ac_table=%d",
+        OIL_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);
@@ -729,7 +703,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
         break;
       }
 
-      JPEG_LOG ("using quant table %d", quant_index);
+      OIL_DEBUG ("using quant table %d", quant_index);
       oil_mult8x8_s16 (block2, block, dec->quant_table[quant_index],
           sizeof (short) * 8, sizeof(short) * 8, sizeof (short) * 8);
       dec->dc[component_index] += block2[0];
@@ -760,7 +734,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
   }
   dec->x = x;
   dec->y = y;
-  g_free (newptr);
+  free (newptr);
 }
 
 
@@ -772,7 +746,8 @@ jpeg_decoder_new (void)
 
   oil_init ();
 
-  dec = g_new0 (JpegDecoder, 1);
+  dec = malloc (sizeof(JpegDecoder));
+  memset (dec, 0, sizeof(JpegDecoder));
 
   huffman_table_load_std_jpeg (dec);
 
@@ -791,13 +766,13 @@ jpeg_decoder_free (JpegDecoder * dec)
 
   for (i = 0; i < JPEG_N_COMPONENTS; i++) {
     if (dec->components[i].image)
-      g_free (dec->components[i].image);
+      free (dec->components[i].image);
   }
 
   if (dec->data)
-    g_free (dec->data);
+    free (dec->data);
 
-  g_free (dec);
+  free (dec);
 }
 
 int
@@ -807,7 +782,7 @@ jpeg_decoder_addbits (JpegDecoder * dec,
 
   offset = dec->bits.ptr - dec->data;
 
-  dec->data = g_realloc (dec->data, dec->data_len + len);
+  dec->data = realloc (dec->data, dec->data_len + len);
   memcpy (dec->data + dec->data_len, data, len);
   dec->data_len += len;
 
@@ -881,7 +856,7 @@ jpeg_decoder_parse (JpegDecoder * dec)
   bits_t *bits = &dec->bits;
   bits_t b2;
   unsigned int x;
-  int tag;
+  unsigned int tag;
   int i;
 
   while (bits->ptr < bits->end) {
@@ -893,13 +868,13 @@ jpeg_decoder_parse (JpegDecoder * dec)
         x = get_u8 (bits);
         n++;
       }
-      JPEG_DEBUG ("lost sync, skipped %d bytes", n);
+      OIL_DEBUG ("lost sync, skipped %d bytes", n);
     }
     while (x == 0xff) {
       x = get_u8 (bits);
     }
     tag = x;
-    JPEG_DEBUG ("tag %02x", tag);
+    OIL_DEBUG ("tag %02x", tag);
 
     b2 = *bits;
 
@@ -908,11 +883,11 @@ jpeg_decoder_parse (JpegDecoder * dec)
         break;
       }
     }
-    JPEG_DEBUG ("tag: %s", jpeg_markers[i].name);
+    OIL_DEBUG ("tag: %s", jpeg_markers[i].name);
     if (jpeg_markers[i].func) {
       jpeg_markers[i].func (dec, &b2);
     } else {
-      JPEG_WARNING ("unhandled or illegal JPEG marker (0x%02x)", tag);
+      OIL_DEBUG ("unhandled or illegal JPEG marker (0x%02x)", tag);
       dumpbits (&b2);
     }
     if (jpeg_markers[i].flags & JPEG_ENTROPY_SEGMENT) {
@@ -926,43 +901,8 @@ jpeg_decoder_parse (JpegDecoder * dec)
 }
 
 
-int jpeg_decoder_verbose_level = -1;
-
-void
-jpeg_debug (int n, const char *format, ...)
-{
-  va_list args;
-
-  if (n > jpeg_decoder_verbose_level)
-    return;
-
-  fflush (stdout);
-  fprintf (stderr, "JPEG_DEBUG: ");
-  va_start (args, format);
-  vfprintf (stderr, format, args);
-  va_end (args);
-}
-
-
 /* misc helper functins */
 
-#if 0
-static char *
-sprintbits (char *str, unsigned int bits, int n)
-{
-  int i;
-  int bit = 1 << (n - 1);
-
-  for (i = 0; i < n; i++) {
-    str[i] = (bits & bit) ? '1' : '0';
-    bit >>= 1;
-  }
-  str[i] = 0;
-
-  return str;
-}
-#endif
-
 static void
 huffman_table_load_std_jpeg (JpegDecoder * dec)
 {
@@ -977,3 +917,4 @@ huffman_table_load_std_jpeg (JpegDecoder
   dec->dc_huff_table[1] = huffman_table_new_jpeg (bits);
   dec->ac_huff_table[1] = huffman_table_new_jpeg (bits);
 }
+
diff --git a/libswfdec/jpeg/jpeg.h b/libswfdec/jpeg/jpeg.h
index 45838f1..fac03bc 100644
--- a/libswfdec/jpeg/jpeg.h
+++ b/libswfdec/jpeg/jpeg.h
@@ -2,21 +2,23 @@
 #ifndef _JPEG_DECODER_H_
 #define _JPEG_DECODER_H_
 
-typedef struct jpeg_decoder_struct JpegDecoder;
+typedef struct _JpegDecoder JpegDecoder;
 
 
-JpegDecoder *jpeg_decoder_new (void);
-void jpeg_decoder_free (JpegDecoder * dec);
-int jpeg_decoder_addbits (JpegDecoder * dec, unsigned char *data,
-    unsigned int len);
-int jpeg_decoder_parse (JpegDecoder * dec);
-int jpeg_decoder_get_image_size (JpegDecoder * dec, int *width, int *height);
-int jpeg_decoder_get_component_size (JpegDecoder * dec, int id,
-    int *width, int *height);
-int jpeg_decoder_get_component_subsampling (JpegDecoder * dec, int id,
-    int *h_subsample, int *v_subsample);
-int jpeg_decoder_get_component_ptr (JpegDecoder * dec, int id,
-    unsigned char **image, int *rowstride);
+JpegDecoder *jpeg_decoder_new(void);
+void jpeg_decoder_free(JpegDecoder *dec);
+int jpeg_decoder_addbits(JpegDecoder *dec, unsigned char *data, unsigned int len);
+int jpeg_decoder_parse(JpegDecoder *dec);
+int jpeg_decoder_get_image_size(JpegDecoder *dec, int *width, int *height);
+int jpeg_decoder_get_component_size(JpegDecoder *dec, int id,
+	int *width, int *height);
+int jpeg_decoder_get_component_subsampling(JpegDecoder *dec, int id,
+	int *h_subsample, int *v_subsample);
+int jpeg_decoder_get_component_ptr(JpegDecoder *dec, int id,
+	unsigned char **image, int *rowstride);
+
+unsigned char *jpeg_decoder_get_argb_image (JpegDecoder *dec);
 
 
 #endif
+
diff --git a/libswfdec/jpeg/jpeg_debug.h b/libswfdec/jpeg/jpeg_debug.h
index 6bd5732..921a74b 100644
--- a/libswfdec/jpeg/jpeg_debug.h
+++ b/libswfdec/jpeg/jpeg_debug.h
@@ -2,27 +2,12 @@
 #ifndef _JPEG_DEBUG_H_
 #define _JPEG_DEBUG_H_
 
-#include <libswfdec/swfdec_debug.h>
+#define JPEG_DEBUG(n, format...)	do{ \
+	if((n)<=JPEG_DEBUG_LEVEL)jpeg_debug((n),format); \
+}while(0)
+#define JPEG_DEBUG_LEVEL 4
 
-//#define JPEG_DEBUG_ON
+void jpeg_debug(int n, const char *format, ... );
 
-#define JPEG_ERROR(...) \
-    JPEG_DEBUG_LEVEL(SWFDEC_LEVEL_ERROR, __VA_ARGS__)
-#define JPEG_WARNING(...) \
-    JPEG_DEBUG_LEVEL(SWFDEC_LEVEL_WARNING, __VA_ARGS__)
-#define JPEG_INFO(...) \
-    JPEG_DEBUG_LEVEL(SWFDEC_LEVEL_INFO, __VA_ARGS__)
-#define JPEG_DEBUG(...) \
-    JPEG_DEBUG_LEVEL(SWFDEC_LEVEL_DEBUG, __VA_ARGS__)
-#define JPEG_LOG(...) \
-    JPEG_DEBUG_LEVEL(SWFDEC_LEVEL_LOG, __VA_ARGS__)
-
-#ifdef JPEG_DEBUG_ON
-#define JPEG_DEBUG_LEVEL(level,...) \
-    swfdec_debug_log ((level), __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
-#else
-#define JPEG_DEBUG_LEVEL(level,...)
 #endif
 
-
-#endif
diff --git a/libswfdec/jpeg/jpeg_internal.h b/libswfdec/jpeg/jpeg_internal.h
index df0896a..2ff43f2 100644
--- a/libswfdec/jpeg/jpeg_internal.h
+++ b/libswfdec/jpeg/jpeg_internal.h
@@ -12,90 +12,87 @@
 //#define N_COMPONENTS 256
 #define JPEG_N_COMPONENTS 4
 
-typedef struct jpeg_scan_struct JpegScan;
+typedef struct _JpegScan JpegScan;
 
 #define JPEG_ENTROPY_SEGMENT 0x0001
 #define JPEG_LENGTH 0x0002
 
-struct jpeg_decoder_struct
-{
-  int width;
-  int height;
-  int depth;
-  int n_components;
-  bits_t bits;
-
-  int width_blocks;
-  int height_blocks;
-
-  int restart_interval;
-
-  unsigned char *data;
-  unsigned int data_len;
-
-  struct
-  {
-    int id;
-    int h_oversample;
-    int v_oversample;
-    int h_subsample;
-    int v_subsample;
-    int quant_table;
-    unsigned char *image;
-    int rowstride;
-  } components[JPEG_N_COMPONENTS];
-
-  short quant_table[4][64];
-  HuffmanTable *dc_huff_table[4];
-  HuffmanTable *ac_huff_table[4];
-
-  int scan_list_length;
-  struct
-  {
-    int component_index;
-    int dc_table;
-    int ac_table;
-    int quant_table;
-    int x;
-    int y;
-    int offset;
-  } scan_list[10];
-  int scan_h_subsample;
-  int scan_v_subsample;
-
-  /* scan state */
-  int x, y;
-  int dc[4];
+struct _JpegDecoder {
+	int width;
+	int height;
+	int depth;
+	int n_components;
+	bits_t bits;
+
+	int width_blocks;
+	int height_blocks;
+
+	int restart_interval;
+
+	unsigned char *data;
+	unsigned int data_len;
+
+	struct{
+		int id;
+		int h_oversample;
+		int v_oversample;
+		int h_subsample;
+		int v_subsample;
+		int quant_table;
+		unsigned char *image;
+		int rowstride;
+	} components[JPEG_N_COMPONENTS];
+
+	short quant_table[4][64];
+	HuffmanTable *dc_huff_table[4];
+	HuffmanTable *ac_huff_table[4];
+
+	int scan_list_length;
+	struct{
+		int component_index;
+		int dc_table;
+		int ac_table;
+		int quant_table;
+		int x;
+		int y;
+		int offset;
+	}scan_list[10];
+	int scan_h_subsample;
+	int scan_v_subsample;
+
+	/* scan state */
+	int x,y;
+	int dc[4];
 };
 
-struct jpeg_scan_struct
-{
-  int length;
-
-  int n_components;
-  struct
-  {
-    int index;
-    int dc_table;
-    int ac_table;
-  } block_list[10];
+struct _JpegScan {
+	int length;
+	
+	int n_components;
+	struct {
+		int index;
+		int dc_table;
+		int ac_table;
+	}block_list[10];
 };
 
 
 /* jpeg.c */
 
-int jpeg_decoder_sof_baseline_dct (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_define_quant_table (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_define_huffman_table (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_sos (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_soi (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_eoi (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_application0 (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_application_misc (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_comment (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_restart_interval (JpegDecoder * dec, bits_t * bits);
-int jpeg_decoder_restart (JpegDecoder * dec, bits_t * bits);
-void jpeg_decoder_decode_entropy_segment (JpegDecoder * dec, bits_t * bits);
+int jpeg_decoder_sof_baseline_dct(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_define_quant_table(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_define_huffman_table(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_sos(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_soi(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_eoi(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_application0(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_application_misc(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_comment(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_restart_interval(JpegDecoder *dec, bits_t *bits);
+int jpeg_decoder_restart(JpegDecoder *dec, bits_t *bits);
+void jpeg_decoder_decode_entropy_segment(JpegDecoder *dec, bits_t *bits);
 
 
 #endif
+
+
diff --git a/libswfdec/jpeg/jpeg_rgb_decoder.c b/libswfdec/jpeg/jpeg_rgb_decoder.c
index 5240b08..02af436 100644
--- a/libswfdec/jpeg/jpeg_rgb_decoder.c
+++ b/libswfdec/jpeg/jpeg_rgb_decoder.c
@@ -1,14 +1,42 @@
 
-#include <glib.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
-#include "jpeg_rgb_internal.h"
+#include "jpeg_internal.h"
 #include "jpeg.h"
 
+#include <liboil/liboil.h>
+#include <liboil/liboildebug.h>
+//#include <liboil/liboilcolorspace.h>
+
+#define oil_argb(a,r,g,b) \
+  ((oil_clamp_255(a)<<24) | \
+   (oil_clamp_255(r)<<16) | \
+   (oil_clamp_255(g)<<8) | \
+   (oil_clamp_255(b)<<0))
+#define oil_clamp_255(x) oil_max(0,oil_min((x),255))
+#define oil_min(x,y) ((x)<(y)?(x):(y))
+#define oil_max(x,y) ((x)>(y)?(x):(y))
+
+#define CLAMP(x,a,b) ((x)<(a) ? (a) : ((x)>(b) ? (b) : (x)))
+
+static int16_t jfif_matrix[24] = {
+  0,      0,      -8192,   -8192,
+  16384,  0,      0,       0,
+  0,      16384,  16384,   16384,
+  0,      0,      -5638,   29032,
+  0,      22970,  -11700,  0,
+  0, 0, 0, 0
+};
+
+
+unsigned char * get_argb_444 (JpegDecoder *dec);
+unsigned char * get_argb_422 (JpegDecoder *dec);
+unsigned char * get_argb_422v (JpegDecoder *dec);
+unsigned char * get_argb_420 (JpegDecoder *dec);
 
-static void convert (JpegRGBDecoder * rgbdec);
-
+#if 0
 static void imagescale2h_u8 (unsigned char *dest, int d_rowstride,
     unsigned char *src, int src_rowstride, int width, int height);
 static void imagescale2v_u8 (unsigned char *dest, int d_rowstride,
@@ -17,56 +45,231 @@ static void imagescale2h2v_u8 (unsigned 
     unsigned char *src, int src_rowstride, int width, int height);
 static void scanlinescale2_u8 (unsigned char *dest, unsigned char *src,
     int len);
+#endif
 
 
-JpegRGBDecoder *
-jpeg_rgb_decoder_new (void)
+unsigned char *
+jpeg_decoder_get_argb_image (JpegDecoder *dec)
 {
-  JpegRGBDecoder *rgbdec;
 
-  rgbdec = g_new0 (JpegRGBDecoder, 1);
+  if (dec->n_components == 3) {
+    if (dec->components[0].h_subsample == 1 &&
+        dec->components[0].v_subsample == 1 &&
+        dec->components[1].h_subsample == dec->components[2].h_subsample &&
+        dec->components[1].v_subsample == dec->components[2].v_subsample) {
+      if (dec->components[1].h_subsample == 1 &&
+          dec->components[1].v_subsample == 1) {
+        return get_argb_444 (dec);
+      } else if (dec->components[1].h_subsample == 2 &&
+          dec->components[1].v_subsample == 1) {
+        return get_argb_422 (dec);
+      } else if (dec->components[1].h_subsample == 1 &&
+          dec->components[1].v_subsample == 2) {
+        return get_argb_422v (dec);
+      } else if (dec->components[1].h_subsample == 2 &&
+          dec->components[1].v_subsample == 2) {
+        return get_argb_420 (dec);
+      }
+    }
+  }
 
-  rgbdec->dec = jpeg_decoder_new ();
+  return NULL;
+}
 
-  return rgbdec;
+static void
+yuv_mux (uint32_t *dest, uint8_t *src_y, uint8_t *src_u, uint8_t *src_v,
+    int n)
+{
+  int i;
+  for (i = 0; i < n; i++) {
+    dest[i] = oil_argb(255, src_y[i], src_u[i], src_v[i]);
+  }
 }
 
-void
-jpeg_rgb_decoder_free (JpegRGBDecoder * rgbdec)
+static void
+upsample (uint8_t *d, uint8_t *s, int n)
 {
   int i;
 
-  jpeg_decoder_free (rgbdec->dec);
+  d[0] = s[0];
 
-  for (i = 0; i < 3; i++) {
-    if (rgbdec->component[i].alloc) {
-      g_free (rgbdec->component[i].image);
-    }
+  for (i = 0; i < n-3; i+=2) {
+    d[i + 1] = (3*s[i/2] + s[i/2+1] + 2)>>2;
+    d[i + 2] = (s[i/2] + 3*s[i/2+1] + 2)>>2;
   }
 
-  g_free (rgbdec);
-}
+  if (n&1) {
+    i = n-3;
+    d[n-2] = s[n/2];
+    d[n-1] = s[n/2];
+  } else {
+    d[n-1] = s[n/2-1];
+  }
 
-int
-jpeg_rgb_decoder_addbits (JpegRGBDecoder * dec, unsigned char *data,
-    unsigned int len)
-{
-  return jpeg_decoder_addbits (dec->dec, data, len);
 }
 
-int
-jpeg_rgb_decoder_parse (JpegRGBDecoder * dec)
+unsigned char *
+get_argb_444 (JpegDecoder *dec)
 {
-  return jpeg_decoder_parse (dec->dec);
+  uint32_t *tmp;
+  uint32_t *argb_image;
+  uint8_t *yp, *up, *vp;
+  uint32_t *argbp;
+  int j;
+
+  tmp = malloc (4 * dec->width * dec->height);
+  argb_image = malloc (4 * dec->width * dec->height);
+
+  yp = dec->components[0].image;
+  up = dec->components[1].image;
+  vp = dec->components[2].image;
+  argbp = argb_image;
+  for(j=0;j<dec->height;j++){
+    yuv_mux (tmp, yp, up, vp, dec->width);
+    oil_colorspace_argb(argbp, tmp, jfif_matrix, dec->width);
+    yp += dec->components[0].rowstride;
+    up += dec->components[1].rowstride;
+    vp += dec->components[2].rowstride;
+    argbp += dec->width;
+  }
+  free(tmp);
+  return (unsigned char *)argb_image;
 }
 
-int
-jpeg_rgb_decoder_get_image_size (JpegRGBDecoder * rgbdec,
-    int *width, int *height)
+unsigned char *
+get_argb_422 (JpegDecoder *dec)
 {
-  return jpeg_decoder_get_image_size (rgbdec->dec, width, height);
+  uint32_t *tmp;
+  uint8_t *tmp_u;
+  uint8_t *tmp_v;
+  uint32_t *argb_image;
+  uint8_t *yp, *up, *vp;
+  uint32_t *argbp;
+  int j;
+
+  tmp = malloc (4 * dec->width * dec->height);
+  tmp_u = malloc (dec->width);
+  tmp_v = malloc (dec->width);
+  argb_image = malloc (4 * dec->width * dec->height);
+
+  yp = dec->components[0].image;
+  up = dec->components[1].image;
+  vp = dec->components[2].image;
+  argbp = argb_image;
+  for(j=0;j<dec->height;j++){
+    upsample (tmp_u, up, dec->width);
+    upsample (tmp_v, vp, dec->width);
+    yuv_mux (tmp, yp, tmp_u, tmp_v, dec->width);
+    oil_colorspace_argb(argbp, tmp, jfif_matrix, dec->width);
+    yp += dec->components[0].rowstride;
+    up += dec->components[1].rowstride;
+    vp += dec->components[2].rowstride;
+    argbp += dec->width;
+  }
+  free(tmp);
+  free(tmp_u);
+  free(tmp_v);
+  return (unsigned char *)argb_image;
+}
+
+unsigned char *
+get_argb_422v (JpegDecoder *dec)
+{
+  uint32_t *tmp;
+  uint8_t *tmp_u;
+  uint8_t *tmp_v;
+  uint32_t *argb_image;
+  uint8_t *yp, *up, *vp;
+  uint32_t *argbp;
+  int halfheight;
+  int j;
+
+  tmp = malloc (4 * dec->width * dec->height);
+  tmp_u = malloc (dec->width);
+  tmp_v = malloc (dec->width);
+  argb_image = malloc (4 * dec->width * dec->height);
+
+  yp = dec->components[0].image;
+  up = dec->components[1].image;
+  vp = dec->components[2].image;
+  argbp = argb_image;
+  halfheight = (dec->height+1)>>1;
+  for(j=0;j<dec->height;j++){
+    uint32_t weight = 192 - 128*(j&1);
+
+    oil_merge_linear_u8(tmp_u,
+        up + dec->components[1].rowstride * CLAMP((j-1)/2,0,halfheight-1),
+        up + dec->components[1].rowstride * CLAMP((j+1)/2,0,halfheight-1),
+        &weight, dec->width);
+    oil_merge_linear_u8(tmp_v,
+        vp + dec->components[2].rowstride * CLAMP((j-1)/2,0,halfheight-1),
+        vp + dec->components[2].rowstride * CLAMP((j+1)/2,0,halfheight-1),
+        &weight, dec->width);
+
+    yuv_mux (tmp, yp, tmp_u, tmp_v, dec->width);
+    oil_colorspace_argb(argbp, tmp, jfif_matrix, dec->width);
+    yp += dec->components[0].rowstride;
+    argbp += dec->width;
+  }
+  free(tmp);
+  free(tmp_u);
+  free(tmp_v);
+  return (unsigned char *)argb_image;
+}
+
+unsigned char *
+get_argb_420 (JpegDecoder *dec)
+{
+  uint32_t *tmp;
+  uint8_t *tmp_u;
+  uint8_t *tmp_v;
+  uint8_t *tmp1;
+  uint32_t *argb_image;
+  uint8_t *yp, *up, *vp;
+  uint32_t *argbp;
+  int j;
+  int halfwidth;
+  int halfheight;
+
+  halfwidth = (dec->width + 1)>>1;
+  tmp = malloc (4 * dec->width * dec->height);
+  tmp_u = malloc (dec->width);
+  tmp_v = malloc (dec->width);
+  tmp1 = malloc (halfwidth);
+  argb_image = malloc (4 * dec->width * dec->height);
+
+  yp = dec->components[0].image;
+  up = dec->components[1].image;
+  vp = dec->components[2].image;
+  argbp = argb_image;
+  halfheight = (dec->height+1)>>1;
+  for(j=0;j<dec->height;j++){
+    uint32_t weight = 192 - 128*(j&1);
+
+    oil_merge_linear_u8(tmp1,
+        up + dec->components[1].rowstride * CLAMP((j-1)/2,0,halfheight-1),
+        up + dec->components[1].rowstride * CLAMP((j+1)/2,0,halfheight-1),
+        &weight, halfwidth);
+    upsample (tmp_u, tmp1, dec->width);
+    oil_merge_linear_u8(tmp1,
+        vp + dec->components[2].rowstride * CLAMP((j-1)/2,0,halfheight-1),
+        vp + dec->components[2].rowstride * CLAMP((j+1)/2,0,halfheight-1),
+        &weight, halfwidth);
+    upsample (tmp_v, tmp1, dec->width);
+
+    yuv_mux (tmp, yp, tmp_u, tmp_v, dec->width);
+    oil_colorspace_argb(argbp, tmp, jfif_matrix, dec->width);
+    yp += dec->components[0].rowstride;
+    argbp += dec->width;
+  }
+  free(tmp);
+  free(tmp_u);
+  free(tmp_v);
+  free(tmp1);
+  return (unsigned char *)argb_image;
 }
 
+#if 0
 int
 jpeg_rgb_decoder_get_image (JpegRGBDecoder * rgbdec,
     unsigned char **image, int *rowstride, int *width, int *height)
@@ -84,7 +287,7 @@ jpeg_rgb_decoder_get_image (JpegRGBDecod
         rgbdec->component[i].v_subsample > 1) {
       unsigned char *dest;
 
-      dest = g_malloc (rgbdec->width * rgbdec->height);
+      dest = malloc (rgbdec->width * rgbdec->height);
       if (rgbdec->component[i].v_subsample > 1) {
         if (rgbdec->component[i].h_subsample > 1) {
           imagescale2h2v_u8 (dest,
@@ -111,7 +314,7 @@ jpeg_rgb_decoder_get_image (JpegRGBDecod
     }
   }
 
-  rgbdec->image = g_malloc (rgbdec->width * rgbdec->height * 4);
+  rgbdec->image = malloc (rgbdec->width * rgbdec->height * 4);
 
   convert (rgbdec);
 
@@ -126,120 +329,6 @@ jpeg_rgb_decoder_get_image (JpegRGBDecod
 
   return 0;
 }
-
-
-/* from the JFIF spec */
-#if 0
-#define CONVERT(r, g, b, y, u, v) G_STMT_START{ \
-  (r) = CLAMP((y) + 1.402*((v)-128),0,255); \
-  (g) = CLAMP((y) - 0.34414*((u)-128) - 0.71414*((v)-128),0,255); \
-  (b) = CLAMP((y) + 1.772*((u)-128),0,255); \
-}G_STMT_END
-#else
-#define SCALEBITS 10
-#define ONE_HALF  (1 << (SCALEBITS - 1))
-#define FIX(x)	  ((int) ((x) * (1<<SCALEBITS) + 0.5))
-#define CONVERT(r, g, b, y, u, v) G_STMT_START{ \
-    int cb = (u) - 128;\
-    int cr = (v) - 128;\
-    int cy = (y) << SCALEBITS;\
-    int r_add = cy + FIX(1.40200) * cr + ONE_HALF;\
-    int g_add = cy - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
-    int b_add = cy + FIX(1.77200) * cb + ONE_HALF;\
-    r_add = CLAMP (r_add, 0, 255 << SCALEBITS);\
-    g_add = CLAMP (g_add, 0, 255 << SCALEBITS);\
-    b_add = CLAMP (b_add, 0, 255 << SCALEBITS);\
-    r = r_add >> SCALEBITS; \
-    g = g_add >> SCALEBITS; \
-    b = b_add >> SCALEBITS; \
-}G_STMT_END
-
 #endif
 
-static void
-convert (JpegRGBDecoder * rgbdec)
-{
-  int x, y;
-  unsigned char *yp;
-  unsigned char *up;
-  unsigned char *vp;
-  unsigned char *rgbp;
-
-  rgbp = rgbdec->image;
-  yp = rgbdec->component[0].image;
-  up = rgbdec->component[1].image;
-  vp = rgbdec->component[2].image;
-  for (y = 0; y < rgbdec->height; y++) {
-    for (x = 0; x < rgbdec->width; x++) {
-#if G_LITTLE_ENDIAN == G_BYTE_ORDER
-      CONVERT (rgbp[2], rgbp[1], rgbp[0], yp[x], up[x], vp[x]);
-      rgbp[3] = 0xFF;
-#else
-      rgbp[0] = 0xFF;
-      CONVERT (rgbp[1], rgbp[2], rgbp[3], yp[x], up[x], vp[x]);
-#endif
-      rgbp += 4;
-    }
-    yp += rgbdec->component[0].rowstride;
-    up += rgbdec->component[1].rowstride;
-    vp += rgbdec->component[2].rowstride;
-  }
-}
-
-
-static void
-imagescale2h_u8 (unsigned char *dest, int d_rowstride,
-    unsigned char *src, int s_rowstride, int width, int height)
-{
-  int i;
-
-  for (i = 0; i < height; i++) {
-    scanlinescale2_u8 (dest + i * d_rowstride, src + i * s_rowstride, width);
-  }
-
-}
-
-static void
-imagescale2v_u8 (unsigned char *dest, int d_rowstride,
-    unsigned char *src, int s_rowstride, int width, int height)
-{
-  int i;
-
-  for (i = 0; i < height; i++) {
-    memcpy (dest + i * d_rowstride, src + (i / 2) * s_rowstride, width);
-  }
-
-}
-
-static void
-imagescale2h2v_u8 (unsigned char *dest, int d_rowstride,
-    unsigned char *src, int s_rowstride, int width, int height)
-{
-  int i;
-
-  for (i = 0; i < height; i++) {
-    scanlinescale2_u8 (dest + i * d_rowstride,
-        src + (i / 2) * s_rowstride, width);
-  }
-
-}
 
-static void
-scanlinescale2_u8 (unsigned char *dest, unsigned char *src, int len)
-{
-  int i;
-
-  for (i = 0; i < len - 3; i += 2){
-    dest[i] = src[i/2];
-    dest[i+1] = (src[i/2] + src[i/2+1] + 1)/2;
-  }
-  if (len & 1) {
-    dest[i] = src[i/2];
-    dest[i+1] = (src[i/2] + src[i/2+1] + 1)/2;
-    dest[i+2] = src[i/2 + 1];
-  } else {
-    dest[i] = src[i/2];
-    dest[i+1] = src[i/2];
-  }
-
-}
diff --git a/libswfdec/jpeg/jpeg_rgb_decoder.h b/libswfdec/jpeg/jpeg_rgb_decoder.h
deleted file mode 100644
index 0459c67..0000000
--- a/libswfdec/jpeg/jpeg_rgb_decoder.h
+++ /dev/null
@@ -1,19 +0,0 @@
-
-#ifndef _JPEG_RGB_DECODER_H_
-#define _JPEG_RGB_DECODER_H_
-
-typedef struct jpeg_rgb_decoder_struct JpegRGBDecoder;
-
-
-JpegRGBDecoder *jpeg_rgb_decoder_new (void);
-void jpeg_rgb_decoder_free (JpegRGBDecoder * dec);
-int jpeg_rgb_decoder_addbits (JpegRGBDecoder * dec, unsigned char *data,
-    unsigned int len);
-int jpeg_rgb_decoder_parse (JpegRGBDecoder * dec);
-int jpeg_rgb_decoder_get_image_size (JpegRGBDecoder * rgbdec,
-    int *width, int *height);
-int jpeg_rgb_decoder_get_image (JpegRGBDecoder * dec,
-    unsigned char **image, int *rowstride, int *width, int *height);
-
-
-#endif
diff --git a/libswfdec/jpeg/jpeg_rgb_internal.h b/libswfdec/jpeg/jpeg_rgb_internal.h
deleted file mode 100644
index 1e317be..0000000
--- a/libswfdec/jpeg/jpeg_rgb_internal.h
+++ /dev/null
@@ -1,36 +0,0 @@
-
-#ifndef _JPEG_INTERNAL_H_
-#define _JPEG_INTERNAL_H_
-
-#include "jpeg.h"
-#include "jpeg_rgb_decoder.h"
-#include "bits.h"
-
-
-#define JPEG_DEBUG(n, format...)	do{ \
-	if((n)<=JPEG_DEBUG_LEVEL)jpeg_debug((n),format); \
-}while(0)
-#define JPEG_DEBUG_LEVEL 4
-
-
-struct jpeg_rgb_decoder_struct
-{
-  JpegDecoder *dec;
-
-  unsigned char *image;
-  int height, width;
-
-  struct
-  {
-    unsigned char *image;
-    int rowstride;
-    int h_subsample;
-    int v_subsample;
-    int alloc;
-  } component[3];
-};
-
-/* jpeg_rgb_decoder.c */
-
-
-#endif
diff --git a/libswfdec/jpeg/test.c b/libswfdec/jpeg/test.c
index 4d248e2..0ebdae0 100644
--- a/libswfdec/jpeg/test.c
+++ b/libswfdec/jpeg/test.c
@@ -4,7 +4,6 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <glib.h>
 
 #include "jpeg.h"
 
@@ -67,7 +66,7 @@ getfile (char *path, int *n_bytes)
     return NULL;
   }
 
-  ptr = g_malloc (st.st_size);
+  ptr = malloc (st.st_size);
   if (!ptr) {
     close (fd);
     return NULL;
@@ -75,7 +74,7 @@ getfile (char *path, int *n_bytes)
 
   ret = read (fd, ptr, st.st_size);
   if (ret != st.st_size) {
-    g_free (ptr);
+    free (ptr);
     close (fd);
     return NULL;
   }
@@ -107,10 +106,3 @@ dump_pgm (unsigned char *ptr, int rowstr
     ptr += rowstride;
   }
 }
-
-void
-swfdec_debug_log (int level, const char *file, const char *function,
-    int line, const char *format, ...)
-{
-
-}
diff --git a/libswfdec/jpeg/test_rgb.c b/libswfdec/jpeg/test_rgb.c
index dde2c00..c74c4de 100644
--- a/libswfdec/jpeg/test_rgb.c
+++ b/libswfdec/jpeg/test_rgb.c
@@ -4,55 +4,64 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <glib.h>
 
-#include "jpeg_rgb_decoder.h"
+#include <liboil/liboil.h>
+//#include <liboil/liboilcolorspace.h>
+
+#define oil_argb_R(color) (((color)>>16)&0xff)
+#define oil_argb_G(color) (((color)>>8)&0xff)
+#define oil_argb_B(color) (((color)>>0)&0xff)
+
+
+
+#include "jpeg.h"
 
 /* getfile */
 
 void *getfile (char *path, int *n_bytes);
-static void dump_pnm (unsigned char *ptr, int rowstride, int width, int height);
+static void dump_pnm (uint32_t *ptr, int rowstride, int width, int height);
 
 int
-main2 (int argc, char *argv[])
+main (int argc, char *argv[])
 {
   unsigned char *data;
   int len;
-  JpegRGBDecoder *dec;
-  char *fn = "biglebowski.jpg";
-  unsigned char *ptr;
-  int rowstride;
+  JpegDecoder *dec;
+  char *fn;
+  uint32_t *image;
   int width;
   int height;
 
-  dec = jpeg_rgb_decoder_new ();
+  dec = jpeg_decoder_new ();
 
-  if (argc > 1)
-    fn = argv[1];
+  if (argc < 2) {
+    printf("jpeg_rgb_test <file.jpg>\n");
+    exit(1);
+  }
+  fn = argv[1];
   data = getfile (fn, &len);
 
-  jpeg_rgb_decoder_addbits (dec, data, len);
-  jpeg_rgb_decoder_parse (dec);
+  if (data == NULL) {
+    printf("cannot read file %s\n", fn);
+    exit(1);
+  }
 
-  jpeg_rgb_decoder_get_image (dec, &ptr, &rowstride, &width, &height);
+  jpeg_decoder_addbits (dec, data, len);
+  jpeg_decoder_parse (dec);
 
-  dump_pnm (ptr, rowstride, width, height);
+  jpeg_decoder_get_image_size (dec, &width, &height);
 
-  g_free (ptr);
+  image = (uint32_t *)jpeg_decoder_get_argb_image (dec);
 
-  jpeg_rgb_decoder_free (dec);
-  g_free (data);
+  dump_pnm (image, width*4, width, height);
 
-  return 0;
-}
-
-int
-main (int argc, char *argv[])
-{
-  return main2 (argc, argv);
-}
+  free (image);
 
+  jpeg_decoder_free (dec);
+  free (data);
 
+  return 0;
+}
 
 
 
@@ -76,7 +85,7 @@ getfile (char *path, int *n_bytes)
     return NULL;
   }
 
-  ptr = g_malloc (st.st_size);
+  ptr = malloc (st.st_size);
   if (!ptr) {
     close (fd);
     return NULL;
@@ -84,7 +93,7 @@ getfile (char *path, int *n_bytes)
 
   ret = read (fd, ptr, st.st_size);
   if (ret != st.st_size) {
-    g_free (ptr);
+    free (ptr);
     close (fd);
     return NULL;
   }
@@ -97,7 +106,7 @@ getfile (char *path, int *n_bytes)
 }
 
 static void
-dump_pnm (unsigned char *ptr, int rowstride, int width, int height)
+dump_pnm (uint32_t *ptr, int rowstride, int width, int height)
 {
   int x, y;
 
@@ -107,22 +116,14 @@ dump_pnm (unsigned char *ptr, int rowstr
 
   for (y = 0; y < height; y++) {
     for (x = 0; x < width; x++) {
-      printf ("%d ", ptr[x * 4 + 0]);
-      printf ("%d ", ptr[x * 4 + 1]);
-      printf ("%d ", ptr[x * 4 + 2]);
+      printf ("%d ", oil_argb_R(ptr[x]));
+      printf ("%d ", oil_argb_G(ptr[x]));
+      printf ("%d ", oil_argb_B(ptr[x]));
       if ((x & 15) == 15) {
         printf ("\n");
       }
     }
     printf ("\n");
-    ptr += rowstride;
+    ptr += rowstride/4;
   }
 }
-
-
-void
-swfdec_debug_log (int level, const char *file, const char *function,
-    int line, const char *format, ...)
-{
-
-}
diff --git a/libswfdec/swfdec_image.c b/libswfdec/swfdec_image.c
index 0dee685..4d59b99 100644
--- a/libswfdec/swfdec_image.c
+++ b/libswfdec/swfdec_image.c
@@ -27,7 +27,7 @@
 #include <zlib.h>
 #include <string.h>
 
-#include "jpeg_rgb_decoder.h"
+#include "jpeg.h"
 #include "swfdec_image.h"
 #include "swfdec_cache.h"
 #include "swfdec_debug.h"
@@ -133,24 +133,24 @@ tag_func_define_bits_jpeg (SwfdecSwfDeco
 static void
 swfdec_image_jpeg_load (SwfdecImage *image)
 {
-  JpegRGBDecoder *dec;
+  JpegDecoder *dec;
 
-  dec = jpeg_rgb_decoder_new ();
+  dec = jpeg_decoder_new ();
 
-  jpeg_rgb_decoder_addbits (dec, image->jpegtables->data,
+  jpeg_decoder_addbits (dec, image->jpegtables->data,
       image->jpegtables->length);
-  jpeg_rgb_decoder_addbits (dec, image->raw_data->data + 2,
+  jpeg_decoder_addbits (dec, image->raw_data->data + 2,
       image->raw_data->length - 2);
-  jpeg_rgb_decoder_parse (dec);
-  jpeg_rgb_decoder_get_image_size (dec, &image->width, &image->height);
+  jpeg_decoder_parse (dec);
+  jpeg_decoder_get_image_size (dec, &image->width, &image->height);
   if (image->width == 0 || image->height == 0) {
-    jpeg_rgb_decoder_free (dec);
+    jpeg_decoder_free (dec);
     return;
   }
   swfdec_cached_load (SWFDEC_CACHED (image), 4 * image->width * image->height);
-  jpeg_rgb_decoder_get_image (dec, &image->data,
-      &image->rowstride, NULL, NULL);
-  jpeg_rgb_decoder_free (dec);
+  image->data = jpeg_decoder_get_argb_image (dec);
+  image->rowstride = image->width * 4;
+  jpeg_decoder_free (dec);
 
   SWFDEC_LOG ("  width = %d", image->width);
   SWFDEC_LOG ("  height = %d", image->height);
@@ -181,22 +181,22 @@ tag_func_define_bits_jpeg_2 (SwfdecSwfDe
 static void
 swfdec_image_jpeg2_load (SwfdecImage *image)
 {
-  JpegRGBDecoder *dec;
+  JpegDecoder *dec;
 
-  dec = jpeg_rgb_decoder_new ();
+  dec = jpeg_decoder_new ();
 
-  jpeg_rgb_decoder_addbits (dec, image->raw_data->data + 2,
+  jpeg_decoder_addbits (dec, image->raw_data->data + 2,
       image->raw_data->length - 2);
-  jpeg_rgb_decoder_parse (dec);
-  jpeg_rgb_decoder_get_image_size (dec, &image->width, &image->height);
+  jpeg_decoder_parse (dec);
+  jpeg_decoder_get_image_size (dec, &image->width, &image->height);
   if (image->width == 0 || image->height == 0) {
-    jpeg_rgb_decoder_free (dec);
+    jpeg_decoder_free (dec);
     return;
   }
   swfdec_cached_load (SWFDEC_CACHED (image), 4 * image->width * image->height);
-  jpeg_rgb_decoder_get_image (dec, &image->data,
-      &image->rowstride, &image->width, &image->height);
-  jpeg_rgb_decoder_free (dec);
+  image->data = jpeg_decoder_get_argb_image (dec);
+  image->rowstride = image->width * 4;
+  jpeg_decoder_free (dec);
 
   SWFDEC_LOG ("  width = %d", image->width);
   SWFDEC_LOG ("  height = %d", image->height);
@@ -225,7 +225,7 @@ tag_func_define_bits_jpeg_3 (SwfdecSwfDe
 static void
 swfdec_image_jpeg3_load (SwfdecImage *image)
 {
-  JpegRGBDecoder *dec;
+  JpegDecoder *dec;
   SwfdecBits bits;
   SwfdecBuffer *buffer;
   int jpeg_length;
@@ -237,20 +237,20 @@ swfdec_image_jpeg3_load (SwfdecImage *im
   if (buffer == NULL)
     return;
 
-  dec = jpeg_rgb_decoder_new ();
+  dec = jpeg_decoder_new ();
 
-  jpeg_rgb_decoder_addbits (dec, buffer->data, buffer->length);
+  jpeg_decoder_addbits (dec, buffer->data, buffer->length);
   swfdec_buffer_unref (buffer);
-  jpeg_rgb_decoder_parse (dec);
-  jpeg_rgb_decoder_get_image_size (dec, &image->width, &image->height);
+  jpeg_decoder_parse (dec);
+  jpeg_decoder_get_image_size (dec, &image->width, &image->height);
   if (image->width == 0 || image->height == 0) {
-    jpeg_rgb_decoder_free (dec);
+    jpeg_decoder_free (dec);
     return;
   }
   swfdec_cached_load (SWFDEC_CACHED (image), 4 * image->width * image->height);
-  jpeg_rgb_decoder_get_image (dec, &image->data,
-      &image->rowstride, &image->width, &image->height);
-  jpeg_rgb_decoder_free (dec);
+  image->data = jpeg_decoder_get_argb_image (dec);
+  image->rowstride = image->width;
+  jpeg_decoder_free (dec);
 
   buffer = swfdec_bits_decompress (&bits, -1, image->width * image->height);
   if (buffer) {


More information about the Swfdec mailing list