Fri, 21 Feb 2003 09:25:47 +0000
implemented ImageMask fill color arguments to pdf_write_g4_fax_image().
eric@53 | 1 | /* |
eric@53 | 2 | * t2p: Create a PDF file from the contents of one or more TIFF |
eric@53 | 3 | * bilevel image files. The images in the resulting PDF file |
eric@53 | 4 | * will be compressed using ITU-T T.6 (G4) fax encoding. |
eric@53 | 5 | * |
eric@53 | 6 | * bitblt routines |
eric@57 | 7 | * $Id: bitblt.h,v 1.11 2003/02/20 04:11:06 eric Exp $ |
eric@53 | 8 | * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> |
eric@53 | 9 | * |
eric@53 | 10 | * This program is free software; you can redistribute it and/or modify |
eric@53 | 11 | * it under the terms of the GNU General Public License version 2 as |
eric@53 | 12 | * published by the Free Software Foundation. Note that permission is |
eric@53 | 13 | * not granted to redistribute this program under the terms of any |
eric@53 | 14 | * other version of the General Public License. |
eric@53 | 15 | * |
eric@53 | 16 | * This program is distributed in the hope that it will be useful, |
eric@53 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
eric@53 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eric@53 | 19 | * GNU General Public License for more details. |
eric@53 | 20 | * |
eric@53 | 21 | * You should have received a copy of the GNU General Public License |
eric@53 | 22 | * along with this program; if not, write to the Free Software |
eric@53 | 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA |
eric@53 | 24 | */ |
eric@53 | 25 | |
eric@53 | 26 | |
eric@2 | 27 | typedef struct Point |
eric@2 | 28 | { |
eric@48 | 29 | int32_t x; |
eric@48 | 30 | int32_t y; |
eric@2 | 31 | } Point; |
eric@2 | 32 | |
eric@2 | 33 | typedef struct Rect |
eric@2 | 34 | { |
eric@42 | 35 | Point min; |
eric@42 | 36 | Point max; |
eric@2 | 37 | } Rect; |
eric@2 | 38 | |
eric@48 | 39 | static inline int32_t rect_width (Rect *r) |
eric@42 | 40 | { |
eric@42 | 41 | return (r->max.x - r->min.x); |
eric@42 | 42 | } |
eric@42 | 43 | |
eric@48 | 44 | static inline int32_t rect_height (Rect *r) |
eric@42 | 45 | { |
eric@42 | 46 | return (r->max.y - r->min.y); |
eric@42 | 47 | } |
eric@42 | 48 | |
eric@47 | 49 | |
eric@48 | 50 | typedef uint32_t word_type; |
eric@47 | 51 | #define BITS_PER_WORD (8 * sizeof (word_type)) |
eric@47 | 52 | #define ALL_ONES (~ 0U) |
eric@47 | 53 | |
eric@43 | 54 | |
eric@2 | 55 | typedef struct Bitmap |
eric@2 | 56 | { |
eric@43 | 57 | word_type *bits; |
eric@42 | 58 | Rect rect; |
eric@48 | 59 | uint32_t row_words; |
eric@2 | 60 | } Bitmap; |
eric@2 | 61 | |
eric@2 | 62 | |
eric@2 | 63 | #define TF_SRC 0xc |
eric@2 | 64 | #define TF_AND 0x8 |
eric@2 | 65 | #define TF_OR 0xe |
eric@2 | 66 | #define TF_XOR 0x6 |
eric@2 | 67 | |
eric@2 | 68 | |
eric@53 | 69 | void bitblt_init (void); |
eric@53 | 70 | |
eric@53 | 71 | |
eric@42 | 72 | Bitmap *create_bitmap (Rect *rect); |
eric@42 | 73 | void free_bitmap (Bitmap *bitmap); |
eric@3 | 74 | |
eric@48 | 75 | bool get_pixel (Bitmap *bitmap, Point coord); |
eric@48 | 76 | void set_pixel (Bitmap *bitmap, Point coord, bool value); |
eric@2 | 77 | |
eric@42 | 78 | |
eric@2 | 79 | Bitmap *bitblt (Bitmap *src_bitmap, |
eric@42 | 80 | Rect *src_rect, |
eric@2 | 81 | Bitmap *dest_bitmap, |
eric@42 | 82 | Point *dest_min, |
eric@43 | 83 | int tfn, |
eric@43 | 84 | int background); |
eric@42 | 85 | |
eric@42 | 86 | |
eric@42 | 87 | /* in-place transformations */ |
eric@42 | 88 | void flip_h (Bitmap *src); |
eric@42 | 89 | void flip_v (Bitmap *src); |
eric@42 | 90 | |
eric@42 | 91 | void rot_180 (Bitmap *src); /* combination of flip_h and flip_v */ |
eric@42 | 92 | |
eric@42 | 93 | /* "in-place" transformations - will allocate new memory and free old */ |
eric@42 | 94 | void transpose (Bitmap *src); |
eric@42 | 95 | |
eric@42 | 96 | void rot_90 (Bitmap *src); /* transpose + flip_h */ |
eric@42 | 97 | void rot_270 (Bitmap *src); /* transpose + flip_v */ |
eric@47 | 98 | |
eric@47 | 99 | |
eric@48 | 100 | void reverse_bits (uint8_t *p, int byte_count); |
eric@57 | 101 | |
eric@57 | 102 | |
eric@57 | 103 | /* |
eric@57 | 104 | * get_row_run_lengths counts the runs of 0 and 1 bits in row |
eric@57 | 105 | * y of a bitmap, from min_x through max_x inclusive. The run lengths |
eric@57 | 106 | * will be stored in the run_length array. The first entry will be |
eric@57 | 107 | * the length of a zero run (which length may be zero, if the first |
eric@57 | 108 | * bit is a one). The next entry will the be the length of a run of |
eric@57 | 109 | * ones, and they will alternate from there, with even entries representing |
eric@57 | 110 | * runs of zeros, and odd entries representing runs of ones. |
eric@57 | 111 | * |
eric@57 | 112 | * max_runs should be set to the maximum number of run lengths that |
eric@57 | 113 | * can be stored in the run_length array. |
eric@57 | 114 | * |
eric@57 | 115 | * Returns the actual number of runs counted, or -max_runs if there |
eric@57 | 116 | * was not enough room in the array. |
eric@57 | 117 | */ |
eric@57 | 118 | int32_t get_row_run_lengths (Bitmap *src, |
eric@57 | 119 | int32_t y, |
eric@57 | 120 | int32_t min_x, int32_t max_x, |
eric@57 | 121 | int32_t max_runs, |
eric@57 | 122 | uint32_t *run_length); |