added match_suffix() to input handlers.
This commit is contained in:
7
tumble.c
7
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 <eric@brouhaha.com>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -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 <eric@brouhaha.com>
|
||||
*
|
||||
* 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;
|
||||
|
||||
@@ -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 <eric@brouhaha.com>
|
||||
*
|
||||
* 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);
|
||||
|
||||
@@ -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 <eric@brouhaha.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <strings.h> /* strcasecmp() is a BSDism */
|
||||
#include <jpeglib.h>
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 <eric@brouhaha.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h> /* strcasecmp() is a BSDism */
|
||||
|
||||
#include <tiffio.h>
|
||||
#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,
|
||||
|
||||
Reference in New Issue
Block a user