From d7d4fa0632d3ae7dec56f5aa903e5be475c1dfe5 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Thu, 20 Mar 2003 14:55:28 +0000 Subject: [PATCH] added match_suffix() to input handlers. --- tumble.c | 7 ++----- tumble_input.c | 11 ++++++++++- tumble_input.h | 4 +++- tumble_jpeg.c | 30 +++++++++++++++++++----------- tumble_tiff.c | 32 ++++++++++++++++++++------------ 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/tumble.c b/tumble.c index 78a0906..7c69b36 100644 --- a/tumble.c +++ b/tumble.c @@ -2,7 +2,7 @@ * tumble: build a PDF file from image files * * Main program - * $Id: tumble.c,v 1.39 2003/03/20 00:26:18 eric Exp $ + * $Id: tumble.c,v 1.40 2003/03/20 06:55:27 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -224,10 +224,7 @@ static int filename_length_without_suffix (char *in_fn) int len = strlen (in_fn); p = strrchr (in_fn, '.'); - if (p && ((strcasecmp (p, ".tif") == 0) || - (strcasecmp (p, ".tiff") == 0) || - (strcasecmp (p, ".jpg") == 0) || - (strcasecmp (p, ".jpeg") == 0))) + if (p && match_input_suffix (p)) return (p - in_fn); return (len); } diff --git a/tumble_input.c b/tumble_input.c index 5f18b58..a4bdbab 100644 --- a/tumble_input.c +++ b/tumble_input.c @@ -2,7 +2,7 @@ * tumble: build a PDF file from image files * * Input handler dispatch - * $Id: tumble_input.c,v 1.2 2003/03/19 23:02:28 eric Exp $ + * $Id: tumble_input.c,v 1.3 2003/03/20 06:55:27 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -57,6 +57,15 @@ void install_input_handler (input_handler_t *handler) } +bool match_input_suffix (char *suffix) +{ + int i; + for (i = 0; i < input_handler_count; i++) + if (input_handlers [i]->match_suffix (suffix)) + return (1); + return (0); +} + bool open_input_file (char *name) { int i; diff --git a/tumble_input.h b/tumble_input.h index 8a82259..6bb2844 100644 --- a/tumble_input.h +++ b/tumble_input.h @@ -1,7 +1,7 @@ /* * tumble: build a PDF file from image files * - * $Id: tumble_input.h,v 1.1 2003/03/19 22:54:08 eric Exp $ + * $Id: tumble_input.h,v 1.2 2003/03/20 06:55:27 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -32,6 +32,7 @@ typedef struct typedef struct { + bool (*match_suffix) (char *suffix); bool (*open_input_file) (FILE *f, char *name); bool (*close_input_file) (void); bool (*last_input_page) (void); @@ -48,6 +49,7 @@ typedef struct void install_input_handler (input_handler_t *handler); +bool match_input_suffix (char *suffix); bool open_input_file (char *name); bool close_input_file (void); bool last_input_page (void); diff --git a/tumble_jpeg.c b/tumble_jpeg.c index 81c3659..aa737c3 100644 --- a/tumble_jpeg.c +++ b/tumble_jpeg.c @@ -1,7 +1,7 @@ /* * tumble: build a PDF file from image files * - * $Id: tumble_jpeg.c,v 1.3 2003/03/20 00:32:16 eric Exp $ + * $Id: tumble_jpeg.c,v 1.4 2003/03/20 06:55:27 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include #include #include +#include /* strcasecmp() is a BSDism */ #include @@ -40,13 +41,19 @@ static struct jpeg_decompress_struct cinfo; static struct jpeg_error_mgr jerr; -bool close_jpeg_input_file (void) +static bool match_jpeg_suffix (char *suffix) +{ + return ((strcasecmp (suffix, ".jpg") == 0) || + (strcasecmp (suffix, ".jpeg") == 0)); +} + +static bool close_jpeg_input_file (void) { return (1); } -bool open_jpeg_input_file (FILE *f, char *name) +static bool open_jpeg_input_file (FILE *f, char *name) { uint8_t buf [2]; size_t l; @@ -75,15 +82,15 @@ bool open_jpeg_input_file (FILE *f, char *name) } -bool last_jpeg_input_page (void) +static bool last_jpeg_input_page (void) { return (1); } -bool get_jpeg_image_info (int image, - input_attributes_t input_attributes, - image_info_t *image_info) +static bool get_jpeg_image_info (int image, + input_attributes_t input_attributes, + image_info_t *image_info) { double unit; @@ -155,10 +162,10 @@ bool get_jpeg_image_info (int image, } -bool process_jpeg_image (int image, /* range 1 .. n */ - input_attributes_t input_attributes, - image_info_t *image_info, - pdf_page_handle page) +static bool process_jpeg_image (int image, /* range 1 .. n */ + input_attributes_t input_attributes, + image_info_t *image_info, + pdf_page_handle page) { pdf_write_jpeg_image (page, 0, 0, /* x, y */ @@ -175,6 +182,7 @@ bool process_jpeg_image (int image, /* range 1 .. n */ input_handler_t jpeg_handler = { + match_jpeg_suffix, open_jpeg_input_file, close_jpeg_input_file, last_jpeg_input_page, diff --git a/tumble_tiff.c b/tumble_tiff.c index 7ae3914..0d5b2c1 100644 --- a/tumble_tiff.c +++ b/tumble_tiff.c @@ -1,7 +1,7 @@ /* * tumble: build a PDF file from image files * - * $Id: tumble_tiff.c,v 1.3 2003/03/20 00:20:52 eric Exp $ + * $Id: tumble_tiff.c,v 1.4 2003/03/20 06:55:28 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -25,7 +25,7 @@ #include #include #include -#include +#include /* strcasecmp() is a BSDism */ #include #define TIFF_REVERSE_BITS @@ -44,14 +44,21 @@ TIFF *tiff_in; #define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0) -bool close_tiff_input_file (void) +static bool match_tiff_suffix (char *suffix) +{ + return ((strcasecmp (suffix, ".tif") == 0) || + (strcasecmp (suffix, ".tiff") == 0)); +} + + +static bool close_tiff_input_file (void) { TIFFClose (tiff_in); return (1); } -bool open_tiff_input_file (FILE *f, char *name) +static bool open_tiff_input_file (FILE *f, char *name) { uint8_t buf [2]; size_t l; @@ -75,15 +82,15 @@ bool open_tiff_input_file (FILE *f, char *name) } -bool last_tiff_input_page (void) +static bool last_tiff_input_page (void) { return (TIFFLastDirectory (tiff_in)); } -bool get_tiff_image_info (int image, - input_attributes_t input_attributes, - image_info_t *image_info) +static bool get_tiff_image_info (int image, + input_attributes_t input_attributes, + image_info_t *image_info) { uint32_t image_height, image_width; uint16_t samples_per_pixel; @@ -250,10 +257,10 @@ static void rotate_bitmap (Bitmap *src, } -bool process_tiff_image (int image, /* range 1 .. n */ - input_attributes_t input_attributes, - image_info_t *image_info, - pdf_page_handle page) +static bool process_tiff_image (int image, /* range 1 .. n */ + input_attributes_t input_attributes, + image_info_t *image_info, + pdf_page_handle page) { bool result = 0; Rect rect; @@ -333,6 +340,7 @@ bool process_tiff_image (int image, /* range 1 .. n */ input_handler_t tiff_handler = { + match_tiff_suffix, open_tiff_input_file, close_tiff_input_file, last_tiff_input_page,