From 4adcb962d555cba7af8e1de42d203f03d28d81a5 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 1 Jun 2009 22:25:13 +0200 Subject: [PATCH] Move some parts of the driver code into its own function. --- driver.c | 39 ++++++++++++++++----------------------- driver.h | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 driver.h diff --git a/driver.c b/driver.c index dfa61dd..c4f48ac 100644 --- a/driver.c +++ b/driver.c @@ -5,24 +5,11 @@ #include "bytesource.h" #include "choice.h" #include "dehuff.h" +#include "driver.h" #include "idct.h" #include "input.h" #include "zigzag.h" -struct jpeg_image { - unsigned precision; - unsigned width, height; - unsigned num_components; - unsigned hsample[256], vsample[256], qtable[256]; - unsigned max_hsample, max_vsample; - unsigned stride[256]; - unsigned num_blocks_horizontal, num_blocks_vertical; - uint32_t qvalues[256][DCTSIZE2]; - void* idct_data[256]; - uint8_t* pixel_data[256]; - uint8_t* pixel_write_pointer[256]; -}; - ssize_t stdio_read(void* userdata, uint8_t* buf, size_t count) { return fread(buf, 1, count, (FILE*)userdata); @@ -261,14 +248,12 @@ void skip_segment(struct byte_source* source) } } -int main(void) +void read_jpeg(struct jpeg_image* jpeg, FILE *input) { - struct jpeg_image jpeg; - memset(&jpeg, 0, sizeof(jpeg)); - init_choices(); - + memset(jpeg, 0, sizeof(*jpeg)); + struct byte_source source; - init_byte_source(&source, stdio_read, stdin); + init_byte_source(&source, stdio_read, input); huffman_tables_t tables; @@ -306,11 +291,11 @@ int main(void) break; case 0xdb: /* DQT */ - read_dqt(&source, &jpeg); + read_dqt(&source, jpeg); break; case 0xc0: /* SOF0 (baseline DCT, Huffman encoded) */ - read_sof(&source, &jpeg); + read_sof(&source, jpeg); break; case 0xd8: /* SOI */ @@ -324,7 +309,7 @@ int main(void) break; case 0xda: /* SOS (start of scan) */ - read_scan(&source, &jpeg, &tables); + read_scan(&source, jpeg, &tables); break; default: fprintf(stderr, "Error: Unknown marker 0x%02x\n", m2); @@ -332,3 +317,11 @@ int main(void) } } } + +int main(void) +{ + init_choices(); + + struct jpeg_image jpeg; + read_jpeg(&jpeg, stdin); +} diff --git a/driver.h b/driver.h new file mode 100644 index 0000000..2a359d5 --- /dev/null +++ b/driver.h @@ -0,0 +1,23 @@ +#ifndef _DRIVER_H +#define _DRIVER_H 1 + +#include +#include "idct.h" + +struct jpeg_image { + unsigned precision; + unsigned width, height; + unsigned num_components; + unsigned hsample[256], vsample[256], qtable[256]; + unsigned max_hsample, max_vsample; + unsigned stride[256]; + unsigned num_blocks_horizontal, num_blocks_vertical; + uint32_t qvalues[256][DCTSIZE2]; + void* idct_data[256]; + uint8_t* pixel_data[256]; + uint8_t* pixel_write_pointer[256]; +}; + +void read_jpeg(struct jpeg_image* jpeg, FILE *input); + +#endif /* !defined(_DRIVER_H) */ -- 2.39.2