1
0
mirror of synced 2026-01-12 00:02:50 +00:00

now use C99 stdint.h and stdbool.h

This commit is contained in:
Eric Smith 2002-08-26 06:03:55 +00:00
parent e1ff187bde
commit be4804020a
13 changed files with 124 additions and 124 deletions

View File

@ -1,6 +1,6 @@
# t2p: build a PDF file out of one or more TIFF Class F Group 4 files
# Makefile
# $Id: Makefile,v 1.9 2002/01/30 00:55:53 eric Exp $
# $Id: Makefile,v 1.10 2002/08/25 22:03:55 eric Exp $
# Copyright 2001 Eric Smith <eric@brouhaha.com>
#
# This program is free software; you can redistribute it and/or modify
@ -25,7 +25,7 @@ YACC = bison
YFLAGS = -d -v
SRCS = bitblt.c bitblt_test.c t2p.c semantics.c
HDRS = type.h bitblt.h t2p.h semantics.h
HDRS = bitblt.h t2p.h semantics.h
MISC = Makefile scanner.l parser.y
TARGETS = t2p bitblt_test

View File

@ -1,16 +1,17 @@
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "type.h"
#include "bitblt.h"
#define DIV_ROUND_UP(count,pow2) (((count) - 1) / (pow2) + 1)
static const u8 bit_reverse_byte [0x100] =
static const uint8_t bit_reverse_byte [0x100] =
{
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
@ -47,7 +48,7 @@ static const u8 bit_reverse_byte [0x100] =
};
void reverse_bits (u8 *p, int byte_count)
void reverse_bits (uint8_t *p, int byte_count)
{
while (byte_count--)
{
@ -69,7 +70,7 @@ static word_type bit_reverse_word (word_type d)
static word_type *temp_buffer;
static word_type temp_buffer_size;
static void realloc_temp_buffer (u32 size)
static void realloc_temp_buffer (uint32_t size)
{
if (size <= temp_buffer_size)
return;
@ -121,8 +122,8 @@ static inline word_type pixel_range_mask (int left, int right)
Bitmap *create_bitmap (Rect *rect)
{
Bitmap *bitmap;
u32 width = rect_width (rect);
u32 height = rect_height (rect);
uint32_t width = rect_width (rect);
uint32_t height = rect_height (rect);
if ((width <= 0) || (height <= 0))
return (NULL);
@ -147,7 +148,7 @@ void free_bitmap (Bitmap *bitmap)
free (bitmap);
}
boolean get_pixel (Bitmap *bitmap, Point coord)
bool get_pixel (Bitmap *bitmap, Point coord)
{
word_type *p;
int w,b;
@ -165,7 +166,7 @@ boolean get_pixel (Bitmap *bitmap, Point coord)
return (((*p) & pixel_mask (b)) != 0);
}
void set_pixel (Bitmap *bitmap, Point coord, boolean value)
void set_pixel (Bitmap *bitmap, Point coord, bool value)
{
word_type *p;
int w,b;
@ -189,7 +190,7 @@ void set_pixel (Bitmap *bitmap, Point coord, boolean value)
/* modifies rect1 to be the intersection of rect1 and rect2;
returns true if intersection is non-null */
static boolean clip_rect (Rect *rect1, Rect *rect2)
static bool clip_rect (Rect *rect1, Rect *rect2)
{
if (rect1->min.y > rect2->max.y)
goto empty;
@ -223,12 +224,12 @@ static boolean clip_rect (Rect *rect1, Rect *rect2)
static void blt_background (Bitmap *dest_bitmap,
Rect dest_rect)
{
u32 y;
uint32_t y;
word_type *rp;
u32 left_bit, left_word;
u32 right_bit, right_word;
uint32_t left_bit, left_word;
uint32_t right_bit, right_word;
word_type left_mask, right_mask;
s32 word_count;
int32_t word_count;
/* This function requires a non-null dest rect */
assert (dest_rect.min.x < dest_rect.max.x);
@ -289,7 +290,7 @@ static void blt_background (Bitmap *dest_bitmap,
/* use Duff's Device for the full words */
if (word_count)
{
s32 i = word_count;
int32_t i = word_count;
switch (i % 8)
{
while (i > 0)
@ -323,7 +324,7 @@ static void blt (Bitmap *src_bitmap,
Bitmap *dest_bitmap,
Rect *dest_rect)
{
s32 y;
int32_t y;
word_type *rp;
/* This function requires a non-null src rect */
@ -402,18 +403,18 @@ Bitmap *bitblt (Bitmap *src_bitmap,
{
Rect sr, dr; /* src and dest rects, clipped to visible portion of
dest rect */
u32 drw, drh; /* dest rect width, height - gets adjusted */
uint32_t drw, drh; /* dest rect width, height - gets adjusted */
Point src_point, dest_point;
/* dest coordinates: */
u32 x0, x1, x2, x3;
u32 y0, y1, y2, y3;
uint32_t x0, x1, x2, x3;
uint32_t y0, y1, y2, y3;
{
sr = * src_rect;
u32 srw = rect_width (& sr);
u32 srh = rect_height (& sr);
uint32_t srw = rect_width (& sr);
uint32_t srh = rect_height (& sr);
if ((srw < 0) || (srh < 0))
goto done; /* the source rect is empty! */
@ -595,7 +596,7 @@ Bitmap *bitblt (Bitmap *src_bitmap,
src_point.x < src_rect->max.x;
src_point.x++)
{
boolean a;
bool a;
dest_point.x = dest_min->x + src_point.x - src_rect->min.x;
@ -616,7 +617,7 @@ Bitmap *bitblt (Bitmap *src_bitmap,
src_point.x < src_rect->max.x;
src_point.x++)
{
boolean a, b, c;
bool a, b, c;
dest_point.x = dest_min->x + src_point.x - src_rect->min.x;
@ -639,7 +640,7 @@ void flip_h (Bitmap *src)
word_type *rp; /* row pointer */
word_type *p1; /* work src ptr */
word_type *p2; /* work dest ptr */
s32 y;
int32_t y;
int shift1, shift2;
realloc_temp_buffer ((src->row_words + 1) * sizeof (word_type));
@ -713,7 +714,7 @@ void rot_180 (Bitmap *src) /* combination of flip_h and flip_v */
/* "in-place" transformations - will allocate new memory and free old */
void transpose (Bitmap *src)
{
u32 new_row_words = DIV_ROUND_UP (rect_height (& src->rect), 32);
uint32_t new_row_words = DIV_ROUND_UP (rect_height (& src->rect), 32);
word_type *new_bits;
new_bits = calloc (1, new_row_words * rect_width (& src->rect) * sizeof (word_type));

View File

@ -1,7 +1,7 @@
typedef struct Point
{
s32 x;
s32 y;
int32_t x;
int32_t y;
} Point;
typedef struct Rect
@ -10,18 +10,18 @@ typedef struct Rect
Point max;
} Rect;
static inline s32 rect_width (Rect *r)
static inline int32_t rect_width (Rect *r)
{
return (r->max.x - r->min.x);
}
static inline s32 rect_height (Rect *r)
static inline int32_t rect_height (Rect *r)
{
return (r->max.y - r->min.y);
}
typedef u32 word_type;
typedef uint32_t word_type;
#define BITS_PER_WORD (8 * sizeof (word_type))
#define ALL_ONES (~ 0U)
@ -30,7 +30,7 @@ typedef struct Bitmap
{
word_type *bits;
Rect rect;
u32 row_words;
uint32_t row_words;
} Bitmap;
@ -43,8 +43,8 @@ typedef struct Bitmap
Bitmap *create_bitmap (Rect *rect);
void free_bitmap (Bitmap *bitmap);
boolean get_pixel (Bitmap *bitmap, Point coord);
void set_pixel (Bitmap *bitmap, Point coord, boolean value);
bool get_pixel (Bitmap *bitmap, Point coord);
void set_pixel (Bitmap *bitmap, Point coord, bool value);
Bitmap *bitblt (Bitmap *src_bitmap,
@ -68,4 +68,4 @@ void rot_90 (Bitmap *src); /* transpose + flip_h */
void rot_270 (Bitmap *src); /* transpose + flip_v */
void reverse_bits (u8 *p, int byte_count);
void reverse_bits (uint8_t *p, int byte_count);

View File

@ -1,7 +1,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "type.h"
#include "bitblt.h"

View File

@ -1,6 +1,7 @@
%{
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "type.h"
#include "semantics.h"
%}
@ -186,7 +187,7 @@ pdf_file_attributes:
output_file_clause:
FILE_KEYWORD STRING { output_set_file ($2); }
pdf_file_attributes ';'
pdf_file_attributes ';' ;
label_clause:
LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }

View File

@ -1,14 +1,15 @@
/*
$Id: scanner.l,v 1.15 2002/01/02 02:17:24 eric Exp $
$Id: scanner.l,v 1.16 2002/08/25 22:02:31 eric Exp $
*/
%option case-insensitive
%option noyywrap
%{
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "type.h"
#include "semantics.h"
#include "parser.tab.h"

View File

@ -1,8 +1,9 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "type.h"
#include "semantics.h"
#include "parser.tab.h"
#include "t2p.h"
@ -10,13 +11,13 @@
typedef struct
{
boolean has_page_size;
bool has_page_size;
page_size_t page_size;
boolean has_rotation;
bool has_rotation;
int rotation;
boolean has_crop;
bool has_crop;
crop_t crop;
} input_modifiers_t;
@ -57,7 +58,7 @@ typedef struct output_context_t
bookmark_t *first_bookmark;
bookmark_t *last_bookmark;
boolean has_page_label;
bool has_page_label;
page_label_t page_label;
} output_context_t;
@ -432,9 +433,9 @@ static char *get_input_file (input_context_t *context)
exit (2);
}
static boolean get_input_rotation (input_context_t *context,
input_modifier_type_t type,
int *rotation)
static bool get_input_rotation (input_context_t *context,
input_modifier_type_t type,
int *rotation)
{
for (; context; context = context->parent)
{
@ -452,9 +453,9 @@ static boolean get_input_rotation (input_context_t *context,
return (0); /* default */
}
static boolean get_input_page_size (input_context_t *context,
input_modifier_type_t type,
page_size_t *page_size)
static bool get_input_page_size (input_context_t *context,
input_modifier_type_t type,
page_size_t *page_size)
{
for (; context; context = context->parent)
{
@ -510,7 +511,7 @@ void dump_input_tree (void)
for (i = image->range.first; i <= image->range.last; i++)
{
input_modifier_type_t parity = (i % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
boolean has_rotation, has_page_size;
bool has_rotation, has_page_size;
int rotation;
page_size_t page_size;
@ -571,9 +572,9 @@ static inline int range_count (range_t range)
}
boolean parse_spec_file (char *fn)
bool parse_spec_file (char *fn)
{
boolean result = 0;
bool result = 0;
yyin = fopen (fn, "r");
if (! yyin)
@ -617,7 +618,7 @@ boolean parse_spec_file (char *fn)
}
boolean process_specs (void)
bool process_specs (void)
{
input_image_t *image = NULL;
output_page_t *page = NULL;

View File

@ -72,5 +72,5 @@ void output_pages (range_t range);
/* functions to be called from main program: */
boolean parse_spec_file (char *fn);
boolean process_specs (void);
bool parse_spec_file (char *fn);
bool process_specs (void);

39
t2p.c
View File

@ -4,7 +4,7 @@
* will be compressed using ITU-T T.6 (G4) fax encoding.
*
* Main program
* $Id: t2p.c,v 1.18 2002/08/25 21:43:49 eric Exp $
* $Id: t2p.c,v 1.19 2002/08/25 22:02:31 eric Exp $
* Copyright 2001 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -23,6 +23,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -33,7 +35,6 @@
#include <panda/functions.h>
#include <panda/constants.h>
#include "type.h"
#include "bitblt.h"
#include "semantics.h"
#include "parser.tab.h"
@ -62,7 +63,7 @@ output_file_t *out;
/* panda_pdf *out; */
boolean close_tiff_input_file (void)
bool close_tiff_input_file (void)
{
if (in)
{
@ -74,7 +75,7 @@ boolean close_tiff_input_file (void)
return (1);
}
boolean open_tiff_input_file (char *name)
bool open_tiff_input_file (char *name)
{
if (in)
{
@ -99,7 +100,7 @@ boolean open_tiff_input_file (char *name)
}
boolean close_pdf_output_files (void)
bool close_pdf_output_files (void)
{
output_file_t *o, *n;
@ -115,8 +116,8 @@ boolean close_pdf_output_files (void)
return (1);
}
boolean open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes)
bool open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes)
{
output_file_t *o;
@ -225,23 +226,23 @@ static void rotate_bitmap (Bitmap *src,
#define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0)
boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
bool process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
{
int result = 0;
u32 image_length, image_width;
u32 dest_image_length, dest_image_width;
uint32_t image_length, image_width;
uint32_t dest_image_length, dest_image_width;
#ifdef CHECK_DEPTH
u32 image_depth;
uint32_t image_depth;
#endif
u16 samples_per_pixel;
u16 bits_per_sample;
u16 planar_config;
uint16_t samples_per_pixel;
uint16_t bits_per_sample;
uint16_t planar_config;
u16 resolution_unit;
uint16_t resolution_unit;
float x_resolution, y_resolution;
float dest_x_resolution, dest_y_resolution;
@ -381,7 +382,7 @@ boolean process_page (int image, /* range 1 .. n */
}
#ifdef TIFF_REVERSE_BITS
reverse_bits ((u8 *) bitmap->bits,
reverse_bits ((uint8_t *) bitmap->bits,
image_length * bitmap->row_words * sizeof (word_type));
#endif /* TIFF_REVERSE_BITS */
@ -424,7 +425,7 @@ boolean process_page (int image, /* range 1 .. n */
TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
#ifdef TIFF_REVERSE_BITS
reverse_bits ((u8 *) bitmap->bits,
reverse_bits ((uint8_t *) bitmap->bits,
image_length * bitmap->row_words * sizeof (word_type));
#endif /* TIFF_REVERSE_BITS */

22
t2p.h
View File

@ -1,21 +1,21 @@
typedef struct
{
boolean has_resolution;
bool has_resolution;
double x_resolution;
double y_resolution;
boolean has_page_size;
bool has_page_size;
page_size_t page_size;
boolean has_rotation;
bool has_rotation;
int rotation;
boolean has_crop;
bool has_crop;
crop_t crop;
} input_attributes_t;
boolean open_tiff_input_file (char *name);
boolean close_tiff_input_file (void);
bool open_tiff_input_file (char *name);
bool close_tiff_input_file (void);
typedef struct
@ -27,8 +27,8 @@ typedef struct
char *keywords;
} pdf_file_attributes_t;
boolean open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes);
bool open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes);
void process_page_numbers (int page_index,
@ -36,6 +36,6 @@ void process_page_numbers (int page_index,
int base,
page_label_t *page_label);
boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks);
bool process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks);

View File

@ -4,7 +4,7 @@
* will be compressed using ITU-T T.6 (G4) fax encoding.
*
* Main program
* $Id: tumble.c,v 1.18 2002/08/25 21:43:49 eric Exp $
* $Id: tumble.c,v 1.19 2002/08/25 22:02:31 eric Exp $
* Copyright 2001 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -23,6 +23,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -33,7 +35,6 @@
#include <panda/functions.h>
#include <panda/constants.h>
#include "type.h"
#include "bitblt.h"
#include "semantics.h"
#include "parser.tab.h"
@ -62,7 +63,7 @@ output_file_t *out;
/* panda_pdf *out; */
boolean close_tiff_input_file (void)
bool close_tiff_input_file (void)
{
if (in)
{
@ -74,7 +75,7 @@ boolean close_tiff_input_file (void)
return (1);
}
boolean open_tiff_input_file (char *name)
bool open_tiff_input_file (char *name)
{
if (in)
{
@ -99,7 +100,7 @@ boolean open_tiff_input_file (char *name)
}
boolean close_pdf_output_files (void)
bool close_pdf_output_files (void)
{
output_file_t *o, *n;
@ -115,8 +116,8 @@ boolean close_pdf_output_files (void)
return (1);
}
boolean open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes)
bool open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes)
{
output_file_t *o;
@ -225,23 +226,23 @@ static void rotate_bitmap (Bitmap *src,
#define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0)
boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
bool process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
{
int result = 0;
u32 image_length, image_width;
u32 dest_image_length, dest_image_width;
uint32_t image_length, image_width;
uint32_t dest_image_length, dest_image_width;
#ifdef CHECK_DEPTH
u32 image_depth;
uint32_t image_depth;
#endif
u16 samples_per_pixel;
u16 bits_per_sample;
u16 planar_config;
uint16_t samples_per_pixel;
uint16_t bits_per_sample;
uint16_t planar_config;
u16 resolution_unit;
uint16_t resolution_unit;
float x_resolution, y_resolution;
float dest_x_resolution, dest_y_resolution;
@ -381,7 +382,7 @@ boolean process_page (int image, /* range 1 .. n */
}
#ifdef TIFF_REVERSE_BITS
reverse_bits ((u8 *) bitmap->bits,
reverse_bits ((uint8_t *) bitmap->bits,
image_length * bitmap->row_words * sizeof (word_type));
#endif /* TIFF_REVERSE_BITS */
@ -424,7 +425,7 @@ boolean process_page (int image, /* range 1 .. n */
TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
#ifdef TIFF_REVERSE_BITS
reverse_bits ((u8 *) bitmap->bits,
reverse_bits ((uint8_t *) bitmap->bits,
image_length * bitmap->row_words * sizeof (word_type));
#endif /* TIFF_REVERSE_BITS */

View File

@ -1,21 +1,21 @@
typedef struct
{
boolean has_resolution;
bool has_resolution;
double x_resolution;
double y_resolution;
boolean has_page_size;
bool has_page_size;
page_size_t page_size;
boolean has_rotation;
bool has_rotation;
int rotation;
boolean has_crop;
bool has_crop;
crop_t crop;
} input_attributes_t;
boolean open_tiff_input_file (char *name);
boolean close_tiff_input_file (void);
bool open_tiff_input_file (char *name);
bool close_tiff_input_file (void);
typedef struct
@ -27,8 +27,8 @@ typedef struct
char *keywords;
} pdf_file_attributes_t;
boolean open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes);
bool open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes);
void process_page_numbers (int page_index,
@ -36,6 +36,6 @@ void process_page_numbers (int page_index,
int base,
page_label_t *page_label);
boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks);
bool process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks);

7
type.h
View File

@ -1,7 +0,0 @@
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef int s32;
typedef int boolean;