1 #ifndef MUPDF_FITZ_FILTER_H 2 #define MUPDF_FITZ_FILTER_H 3 4 #include "mupdf/fitz/system.h" 5 #include "mupdf/fitz/context.h" 6 #include "mupdf/fitz/buffer.h" 7 #include "mupdf/fitz/store.h" 8 #include "mupdf/fitz/stream.h" 9 10 typedef struct fz_jbig2_globals fz_jbig2_globals; 11 12 typedef struct 13 { 14 int64_t offset; 15 size_t length; 16 } fz_range; 17 18 /** 19 The null filter reads a specified amount of data from the 20 substream. 21 */ 22 fz_stream *fz_open_null_filter(fz_context *ctx, fz_stream *chain, int len, int64_t offset); 23 24 /** 25 The range filter copies data from specified ranges of the 26 chained stream. 27 */ 28 fz_stream *fz_open_range_filter(fz_context *ctx, fz_stream *chain, fz_range *ranges, int nranges); 29 30 /** 31 The endstream filter reads a PDF substream, and starts to look 32 for an 'endstream' token after the specified length. 33 */ 34 fz_stream *fz_open_endstream_filter(fz_context *ctx, fz_stream *chain, int len, int64_t offset); 35 36 /** 37 Concat filter concatenates several streams into one. 38 */ 39 fz_stream *fz_open_concat(fz_context *ctx, int max, int pad); 40 41 /** 42 Add a chained stream to the end of the concatenate filter. 43 44 Ownership of chain is passed in. 45 */ 46 void fz_concat_push_drop(fz_context *ctx, fz_stream *concat, fz_stream *chain); 47 48 /** 49 arc4 filter performs RC4 decoding of data read from the chained 50 filter using the supplied key. 51 */ 52 fz_stream *fz_open_arc4(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen); 53 54 /** 55 aesd filter performs AES decoding of data read from the chained 56 filter using the supplied key. 57 */ 58 fz_stream *fz_open_aesd(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen); 59 60 /** 61 a85d filter performs ASCII 85 Decoding of data read 62 from the chained filter. 63 */ 64 fz_stream *fz_open_a85d(fz_context *ctx, fz_stream *chain); 65 66 /** 67 ahxd filter performs ASCII Hex decoding of data read 68 from the chained filter. 69 */ 70 fz_stream *fz_open_ahxd(fz_context *ctx, fz_stream *chain); 71 72 /** 73 rld filter performs Run Length Decoding of data read 74 from the chained filter. 75 */ 76 fz_stream *fz_open_rld(fz_context *ctx, fz_stream *chain); 77 78 /** 79 dctd filter performs DCT (JPEG) decoding of data read 80 from the chained filter. 81 82 color_transform implements the PDF color_transform option; 83 use -1 (unset) as a default. 84 85 For subsampling on decode, set l2factor to the log2 of the 86 reduction required (therefore 0 = full size decode). 87 88 jpegtables is an optional stream from which the JPEG tables 89 can be read. Use NULL if not required. 90 */ 91 fz_stream *fz_open_dctd(fz_context *ctx, fz_stream *chain, int color_transform, int l2factor, fz_stream *jpegtables); 92 93 /** 94 faxd filter performs FAX decoding of data read from 95 the chained filter. 96 97 k: see fax specification (fax default is 0). 98 99 end_of_line: whether we expect end of line markers (fax default 100 is 0). 101 102 encoded_byte_align: whether we align to bytes after each line 103 (fax default is 0). 104 105 columns: how many columns in the image (fax default is 1728). 106 107 rows: 0 for unspecified or the number of rows of data to expect. 108 109 end_of_block: whether we expect end of block markers (fax 110 default is 1). 111 112 black_is_1: determines the polarity of the image (fax default is 113 0). 114 */ 115 fz_stream *fz_open_faxd(fz_context *ctx, fz_stream *chain, 116 int k, int end_of_line, int encoded_byte_align, 117 int columns, int rows, int end_of_block, int black_is_1); 118 119 /** 120 flated filter performs LZ77 decoding (inflating) of data read 121 from the chained filter. 122 123 window_bits: How large a decompression window to use. Typically 124 15. A negative number, -n, means to use n bits, but to expect 125 raw data with no header. 126 */ 127 fz_stream *fz_open_flated(fz_context *ctx, fz_stream *chain, int window_bits); 128 129 /** 130 lzwd filter performs LZW decoding of data read from the chained 131 filter. 132 133 early_change: (Default 1) specifies whether to change codes 1 134 bit early. 135 136 min_bits: (Default 9) specifies the minimum number of bits to 137 use. 138 139 reverse_bits: (Default 0) allows for compatibility with gif and 140 old style tiffs (1). 141 142 old_tiff: (Default 0) allows for different handling of the clear 143 code, as found in old style tiffs. 144 */ 145 fz_stream *fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits, int reverse_bits, int old_tiff); 146 147 /** 148 predict filter performs pixel prediction on data read from 149 the chained filter. 150 151 predictor: 1 = copy, 2 = tiff, other = inline PNG predictor 152 153 columns: width of image in pixels 154 155 colors: number of components. 156 157 bpc: bits per component (typically 8) 158 */ 159 fz_stream *fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, int colors, int bpc); 160 161 /** 162 Open a filter that performs jbig2 decompression on the chained 163 stream, using the optional globals record. 164 */ 165 fz_stream *fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals); 166 167 /** 168 Create a jbig2 globals record from a buffer. 169 170 Immutable once created. 171 */ 172 fz_jbig2_globals *fz_load_jbig2_globals(fz_context *ctx, fz_buffer *buf); 173 174 /** 175 Increment the reference count for a jbig2 globals record. 176 177 Never throws an exception. 178 */ 179 fz_jbig2_globals *fz_keep_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals); 180 181 /** 182 Decrement the reference count for a jbig2 globals record. 183 When the reference count hits zero, the record is freed. 184 185 Never throws an exception. 186 */ 187 void fz_drop_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals); 188 189 /** 190 Special jbig2 globals drop function for use in implementing 191 store support. 192 */ 193 void fz_drop_jbig2_globals_imp(fz_context *ctx, fz_storable *globals); 194 195 /* Extra filters for tiff */ 196 197 /** 198 SGI Log 16bit (greyscale) decode from the chained filter. 199 Decodes lines of w pixels to 8bpp greyscale. 200 */ 201 fz_stream *fz_open_sgilog16(fz_context *ctx, fz_stream *chain, int w); 202 203 /** 204 SGI Log 24bit (LUV) decode from the chained filter. 205 Decodes lines of w pixels to 8bpc rgb. 206 */ 207 fz_stream *fz_open_sgilog24(fz_context *ctx, fz_stream *chain, int w); 208 209 /** 210 SGI Log 32bit (LUV) decode from the chained filter. 211 Decodes lines of w pixels to 8bpc rgb. 212 */ 213 fz_stream *fz_open_sgilog32(fz_context *ctx, fz_stream *chain, int w); 214 215 /** 216 4bit greyscale Thunderscan decoding from the chained filter. 217 Decodes lines of w pixels to 8bpp greyscale. 218 */ 219 fz_stream *fz_open_thunder(fz_context *ctx, fz_stream *chain, int w); 220 221 #endif 222