[Swfdec] 3 commits - libswfdec/jpeg
David Schleef
ds at kemper.freedesktop.org
Sat Apr 28 15:48:15 PDT 2007
libswfdec/jpeg/Makefile.am | 1
libswfdec/jpeg/jpeg.c | 44 +++++++++----
libswfdec/jpeg/jpeg.h | 118 ++++++++++++++++++++++++++++++++++++-
libswfdec/jpeg/jpeg_huffman.c | 20 ++----
libswfdec/jpeg/jpeg_internal.h | 111 ----------------------------------
libswfdec/jpeg/jpeg_rgb_decoder.c | 1
libswfdec/jpeg/jpeg_rgb_internal.h | 36 -----------
7 files changed, 154 insertions(+), 177 deletions(-)
New commits:
diff-tree 936eabe443ef788a6444a1077ae571b7731b5e67 (from 32f9933e12a49588a285dd4aa2bf94b93193d8d9)
Author: David Schleef <ds at ginger.bigkitten.com>
Date: Sat Apr 28 15:48:14 2007 -0700
Differences between cog-jpeg and swfdec-jpeg
diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index cf8d0ed..b7398d7 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -4,9 +4,8 @@
#endif
#include <liboil/liboil.h>
-#include <cog/cog-stdint.h>
-#include <cog/cogdebug.h>
-#include <cog/cogutils.h>
+#include <liboil/liboil-stdint.h>
+#include <cogcompat.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/libswfdec/jpeg/jpeg.h b/libswfdec/jpeg/jpeg.h
index dcaf5fb..9caad4c 100644
--- a/libswfdec/jpeg/jpeg.h
+++ b/libswfdec/jpeg/jpeg.h
@@ -2,7 +2,7 @@
#ifndef _JPEG_DECODER_H_
#define _JPEG_DECODER_H_
-#include <cog/jpeg/jpeg_bits.h>
+#include <jpeg/jpeg_bits.h>
#include <stdint.h>
diff --git a/libswfdec/jpeg/jpeg_huffman.c b/libswfdec/jpeg/jpeg_huffman.c
index 1fc4583..d5b7f61 100644
--- a/libswfdec/jpeg/jpeg_huffman.c
+++ b/libswfdec/jpeg/jpeg_huffman.c
@@ -3,7 +3,7 @@
#include "config.h"
#endif
-#include <cog/cogdebug.h>
+#include <cogcompat.h>
#include <liboil/liboil.h>
#include <string.h>
diff-tree 32f9933e12a49588a285dd4aa2bf94b93193d8d9 (from 1ed8a178896c2d7320fc86a8516f8aab5e4f8321)
Author: David Schleef <ds at ginger.bigkitten.com>
Date: Sat Apr 28 15:39:10 2007 -0700
Removed in Cog
diff --git a/libswfdec/jpeg/jpeg_internal.h b/libswfdec/jpeg/jpeg_internal.h
deleted file mode 100644
index 35f694e..0000000
--- a/libswfdec/jpeg/jpeg_internal.h
+++ /dev/null
@@ -1,111 +0,0 @@
-
-#ifndef _JPEG_INTERNAL_H_
-#define _JPEG_INTERNAL_H_
-
-#include "jpeg.h"
-#include "jpeg_huffman.h"
-#include "jpeg_bits.h"
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-
-#define JPEG_MAX_COMPONENTS 256
-
-typedef struct _JpegScan JpegScan;
-typedef struct _JpegQuantTable JpegQuantTable;
-
-struct _JpegQuantTable {
- int pq;
- int16_t quantizer[64];
-};
-
-struct _JpegDecoder {
- int width;
- int height;
- int depth;
- int n_components;
- JpegBits bits;
- int error;
- int strict;
- char *error_message;
-
- int sof_type;
-
- int width_blocks;
- int height_blocks;
-
- int restart_interval;
-
- unsigned char *data;
- unsigned int data_len;
-
- struct{
- int id;
- int h_sample;
- int v_sample;
- int quant_table;
-
- int h_subsample;
- int v_subsample;
- unsigned char *image;
- int rowstride;
- } components[JPEG_MAX_COMPONENTS];
-
- JpegQuantTable quant_tables[4];
- 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 _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, JpegBits *bits);
-int jpeg_decoder_define_quant_table(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_define_huffman_table(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_sos(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_soi(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_eoi(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_application0(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_application_misc(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_comment(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_restart_interval(JpegDecoder *dec, JpegBits *bits);
-int jpeg_decoder_restart(JpegDecoder *dec, JpegBits *bits);
-void jpeg_decoder_decode_entropy_segment(JpegDecoder *dec);
-
-
-#endif
-
-
diff --git a/libswfdec/jpeg/jpeg_rgb_internal.h b/libswfdec/jpeg/jpeg_rgb_internal.h
deleted file mode 100644
index db8b80e..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-tree 1ed8a178896c2d7320fc86a8516f8aab5e4f8321 (from 158cee244eb9faa5c818d41b3e06a20bfbd0cbce)
Author: David Schleef <ds at ginger.bigkitten.com>
Date: Sat Apr 28 15:38:45 2007 -0700
Copy files from Cog
diff --git a/libswfdec/jpeg/Makefile.am b/libswfdec/jpeg/Makefile.am
index 85a13df..d6475cc 100644
--- a/libswfdec/jpeg/Makefile.am
+++ b/libswfdec/jpeg/Makefile.am
@@ -14,7 +14,6 @@ noinst_HEADERS = \
jpeg.h \
jpeg_bits.h \
jpeg_huffman.h \
- jpeg_internal.h \
jpeg_rgb_decoder.h
libjpeg_la_CFLAGS = $(GLOBAL_CFLAGS) $(GLIB_CFLAGS) $(LIBOIL_CFLAGS) -I$(srcdir)/..
diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index 4d2fd43..cf8d0ed 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -4,16 +4,15 @@
#endif
#include <liboil/liboil.h>
-#include <liboil/liboil-stdint.h>
-
-#include <cogcompat.h>
+#include <cog/cog-stdint.h>
+#include <cog/cogdebug.h>
+#include <cog/cogutils.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-
-#include "jpeg_internal.h"
+#include "jpeg.h"
extern uint8_t jpeg_standard_tables[];
@@ -37,7 +36,7 @@ static void jpeg_decoder_verify_header (
static void jpeg_decoder_init_decoder (JpegDecoder *dec);
-static void
+void
jpeg_decoder_error(JpegDecoder *dec, char *fmt, ...)
{
va_list varargs;
@@ -224,7 +223,7 @@ generate_code_table (int *huffsize)
}
int
-huffman_table_init_jpeg (HuffmanTable *table, JpegBits * bits)
+huffman_table_init_jpeg (JpegDecoder *decoder, HuffmanTable *table, JpegBits * bits)
{
int n_symbols;
int huffsize[16];
@@ -262,8 +261,7 @@ huffman_table_init_jpeg (HuffmanTable *t
* number of bits we think it is. This is only triggered
* for bad huffsize[] arrays. */
if (symbol >= (1U << (i + 1))) {
- /* FIXME jpeg_decoder_error() */
- COG_ERROR ("bad huffsize[] array");
+ jpeg_decoder_error (decoder, "bad huffsize[] array");
return -1;
}
@@ -461,7 +459,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
ac_table_index = dec->scan_list[i].ac_table;
quant_index = dec->scan_list[i].quant_table;
- ret = huffman_table_decode_macroblock (block,
+ ret = huffman_table_decode_macroblock (dec, block,
&dec->dc_huff_table[dc_table_index],
&dec->ac_huff_table[ac_table_index], bits2);
if (ret < 0) {
@@ -529,7 +527,7 @@ jpeg_decoder_free (JpegDecoder * dec)
{
int i;
- for (i = 0; i < JPEG_MAX_COMPONENTS; i++) {
+ for (i = 0; i < JPEG_LIMIT_COMPONENTS; i++) {
if (dec->components[i].image)
free (dec->components[i].image);
}
@@ -629,6 +627,9 @@ jpeg_decoder_decode (JpegDecoder *dec)
return FALSE;
}
}
+ if (dec->error) {
+ return FALSE;
+ }
jpeg_decoder_start_of_frame(dec, marker);
@@ -663,6 +664,9 @@ jpeg_decoder_decode (JpegDecoder *dec)
jpeg_decoder_skip (dec);
} else if (marker == JPEG_MARKER_SOS) {
jpeg_decoder_start_of_scan (dec);
+ if (dec->error) {
+ return FALSE;
+ }
jpeg_decoder_decode_entropy_segment (dec);
} else if (JPEG_MARKER_IS_RESET(marker)) {
jpeg_decoder_decode_entropy_segment (dec);
@@ -683,6 +687,9 @@ jpeg_decoder_decode (JpegDecoder *dec)
return FALSE;
}
}
+ if (dec->error) {
+ return FALSE;
+ }
return TRUE;
}
@@ -723,10 +730,13 @@ jpeg_decoder_define_huffman_tables (Jpeg
if (tc) {
hufftab = &dec->ac_huff_table[th];
- length -= huffman_table_init_jpeg (hufftab, bits);
+ length -= huffman_table_init_jpeg (dec, hufftab, bits);
} else {
hufftab = &dec->dc_huff_table[th];
- length -= huffman_table_init_jpeg (hufftab, bits);
+ length -= huffman_table_init_jpeg (dec, hufftab, bits);
+ }
+ if (dec->error) {
+ return;
}
}
if (length < 0) {
@@ -914,6 +924,10 @@ jpeg_decoder_start_of_scan (JpegDecoder
dec->scan_list[n].offset =
y * 8 * dec->components[index].rowstride + x * 8;
n++;
+ if (n > JPEG_LIMIT_SCAN_LIST_LENGTH) {
+ jpeg_decoder_error(dec, "scan list too long");
+ return;
+ }
}
}
@@ -925,6 +939,7 @@ jpeg_decoder_start_of_scan (JpegDecoder
}
dec->scan_list_length = n;
+
spectral_start = jpeg_bits_get_u8 (bits);
spectral_end = jpeg_bits_get_u8 (bits);
COG_DEBUG ("spectral range [%d,%d]", spectral_start, spectral_end);
@@ -1103,10 +1118,10 @@ jpeg_load_standard_huffman_tables (JpegD
bits->idx = 0;
bits->end = jpeg_standard_tables + jpeg_standard_tables_size;
- huffman_table_init_jpeg (&dec->dc_huff_table[0], bits);
- huffman_table_init_jpeg (&dec->ac_huff_table[0], bits);
- huffman_table_init_jpeg (&dec->dc_huff_table[1], bits);
- huffman_table_init_jpeg (&dec->ac_huff_table[1], bits);
+ huffman_table_init_jpeg (dec, &dec->dc_huff_table[0], bits);
+ huffman_table_init_jpeg (dec, &dec->ac_huff_table[0], bits);
+ huffman_table_init_jpeg (dec, &dec->dc_huff_table[1], bits);
+ huffman_table_init_jpeg (dec, &dec->ac_huff_table[1], bits);
}
diff --git a/libswfdec/jpeg/jpeg.h b/libswfdec/jpeg/jpeg.h
index 49eaf6a..dcaf5fb 100644
--- a/libswfdec/jpeg/jpeg.h
+++ b/libswfdec/jpeg/jpeg.h
@@ -2,8 +2,97 @@
#ifndef _JPEG_DECODER_H_
#define _JPEG_DECODER_H_
+#include <cog/jpeg/jpeg_bits.h>
+
#include <stdint.h>
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#define JPEG_LIMIT_COMPONENTS 256
+#define JPEG_LIMIT_SCAN_LIST_LENGTH 10
+
+
+typedef struct _JpegDecoder JpegDecoder;
+typedef struct _JpegQuantTable JpegQuantTable;
+typedef struct _HuffmanEntry HuffmanEntry;
+typedef struct _HuffmanTable HuffmanTable;
+
+struct _HuffmanEntry {
+ unsigned int symbol;
+ unsigned int mask;
+ int n_bits;
+ unsigned char value;
+};
+
+struct _HuffmanTable {
+ int len;
+ HuffmanEntry entries[256];
+};
+
+struct _JpegQuantTable {
+ int pq;
+ int16_t quantizer[64];
+};
+
+struct _JpegDecoder {
+ int width;
+ int height;
+ int depth;
+ int n_components;
+ JpegBits bits;
+ int error;
+ int strict;
+ char *error_message;
+
+ int sof_type;
+
+ int width_blocks;
+ int height_blocks;
+
+ int restart_interval;
+
+ unsigned char *data;
+ unsigned int data_len;
+
+ struct{
+ int id;
+ int h_sample;
+ int v_sample;
+ int quant_table;
+
+ int h_subsample;
+ int v_subsample;
+ unsigned char *image;
+ int rowstride;
+ } components[JPEG_LIMIT_COMPONENTS];
+
+ JpegQuantTable quant_tables[4];
+ 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[JPEG_LIMIT_SCAN_LIST_LENGTH];
+ int scan_h_subsample;
+ int scan_v_subsample;
+
+ /* scan state */
+ int x,y;
+ int dc[4];
+};
+
#define JPEG_MARKER_STUFFED 0x00
#define JPEG_MARKER_TEM 0x01
#define JPEG_MARKER_RES 0x02
@@ -53,8 +142,6 @@
#define JPEG_MARKER_IS_RESET(x) ((x)>=0xd0 && (x)<=0xd7)
-typedef struct _JpegDecoder JpegDecoder;
-
JpegDecoder *jpeg_decoder_new(void);
void jpeg_decoder_free(JpegDecoder *dec);
@@ -72,5 +159,32 @@ unsigned char *jpeg_decoder_get_argb_ima
int jpeg_decode_argb (uint8_t *data, int length, uint32_t **image,
int *width, int *height);
+void jpeg_decoder_error(JpegDecoder *dec, char *fmt, ...);
+
+int jpeg_decoder_sof_baseline_dct(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_define_quant_table(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_define_huffman_table(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_sos(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_soi(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_eoi(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_application0(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_application_misc(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_comment(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_restart_interval(JpegDecoder *dec, JpegBits *bits);
+int jpeg_decoder_restart(JpegDecoder *dec, JpegBits *bits);
+void jpeg_decoder_decode_entropy_segment(JpegDecoder *dec);
+
+
+void huffman_table_init(HuffmanTable *table);
+
+void huffman_table_dump(HuffmanTable *table);
+void huffman_table_add(HuffmanTable *table, uint32_t code, int n_bits,
+ int value);
+unsigned int huffman_table_decode_jpeg(JpegDecoder *dec, HuffmanTable *tab, JpegBits *bits);
+int huffman_table_decode_macroblock(JpegDecoder *dec, short *block, HuffmanTable *dc_tab,
+ HuffmanTable *ac_tab, JpegBits *bits);
+int huffman_table_decode(JpegDecoder *dec, HuffmanTable *dc_tab, HuffmanTable *ac_tab, JpegBits *bits);
+
+
#endif
diff --git a/libswfdec/jpeg/jpeg_huffman.c b/libswfdec/jpeg/jpeg_huffman.c
index 354916d..1fc4583 100644
--- a/libswfdec/jpeg/jpeg_huffman.c
+++ b/libswfdec/jpeg/jpeg_huffman.c
@@ -3,14 +3,12 @@
#include "config.h"
#endif
-#include <swfdec_debug.h>
+#include <cog/cogdebug.h>
#include <liboil/liboil.h>
#include <string.h>
-#include "cogcompat.h"
-
-#include "jpeg_huffman.h"
+#include "jpeg.h"
/* misc helper function definitions */
@@ -56,7 +54,7 @@ huffman_table_add (HuffmanTable * table,
}
unsigned int
-huffman_table_decode_jpeg (HuffmanTable * tab, JpegBits * bits)
+huffman_table_decode_jpeg (JpegDecoder *dec, HuffmanTable * tab, JpegBits * bits)
{
unsigned int code;
int i;
@@ -79,7 +77,7 @@ huffman_table_decode_jpeg (HuffmanTable
}
int
-huffman_table_decode_macroblock (short *block, HuffmanTable * dc_tab,
+huffman_table_decode_macroblock (JpegDecoder *dec, short *block, HuffmanTable * dc_tab,
HuffmanTable * ac_tab, JpegBits * bits)
{
int r, s, x, rs;
@@ -88,7 +86,7 @@ huffman_table_decode_macroblock (short *
memset (block, 0, sizeof (short) * 64);
- s = huffman_table_decode_jpeg (dc_tab, bits);
+ s = huffman_table_decode_jpeg (dec, dc_tab, bits);
if (s < 0)
return -1;
x = getbits (bits, s);
@@ -99,7 +97,7 @@ huffman_table_decode_macroblock (short *
block[0] = x;
for (k = 1; k < 64; k++) {
- rs = huffman_table_decode_jpeg (ac_tab, bits);
+ rs = huffman_table_decode_jpeg (dec, ac_tab, bits);
if (rs < 0) {
COG_DEBUG ("huffman error");
return -1;
@@ -121,7 +119,7 @@ huffman_table_decode_macroblock (short *
} else {
k += r;
if (k >= 64) {
- COG_ERROR ("macroblock overrun");
+ jpeg_decoder_error (dec, "macroblock overrun");
return -1;
}
x = getbits (bits, s);
@@ -137,14 +135,14 @@ huffman_table_decode_macroblock (short *
}
int
-huffman_table_decode (HuffmanTable * dc_tab, HuffmanTable * ac_tab,
+huffman_table_decode (JpegDecoder *dec, HuffmanTable * dc_tab, HuffmanTable * ac_tab,
JpegBits * bits)
{
int16_t zz[64];
int ret;
while (bits->ptr < bits->end) {
- ret = huffman_table_decode_macroblock (zz, dc_tab, ac_tab, bits);
+ ret = huffman_table_decode_macroblock (dec, zz, dc_tab, ac_tab, bits);
if (ret < 0)
return -1;
}
diff --git a/libswfdec/jpeg/jpeg_rgb_decoder.c b/libswfdec/jpeg/jpeg_rgb_decoder.c
index e1dba8a..6fc49c8 100644
--- a/libswfdec/jpeg/jpeg_rgb_decoder.c
+++ b/libswfdec/jpeg/jpeg_rgb_decoder.c
@@ -3,7 +3,6 @@
#include <string.h>
#include <stdlib.h>
-#include "jpeg_internal.h"
#include "jpeg.h"
#include <liboil/liboil.h>
More information about the Swfdec
mailing list