1 #ifndef MUPDF_FITZ_COMPRESSED_BUFFER_H 2 #define MUPDF_FITZ_COMPRESSED_BUFFER_H 3 4 #include "mupdf/fitz/system.h" 5 #include "mupdf/fitz/context.h" 6 #include "mupdf/fitz/buffer.h" 7 #include "mupdf/fitz/stream.h" 8 #include "mupdf/fitz/filter.h" 9 10 /** 11 Compression parameters used for buffers of compressed data; 12 typically for the source data for images. 13 */ 14 typedef struct 15 { 16 int type; 17 union { 18 struct { 19 int color_transform; /* Use -1 for unset */ 20 } jpeg; 21 struct { 22 int smask_in_data; 23 } jpx; 24 struct { 25 fz_jbig2_globals *globals; 26 } jbig2; 27 struct { 28 int columns; 29 int rows; 30 int k; 31 int end_of_line; 32 int encoded_byte_align; 33 int end_of_block; 34 int black_is_1; 35 int damaged_rows_before_error; 36 } fax; 37 struct 38 { 39 int columns; 40 int colors; 41 int predictor; 42 int bpc; 43 } 44 flate; 45 struct 46 { 47 int columns; 48 int colors; 49 int predictor; 50 int bpc; 51 int early_change; 52 } lzw; 53 } u; 54 } fz_compression_params; 55 56 /** 57 Buffers of compressed data; typically for the source data 58 for images. 59 */ 60 typedef struct 61 { 62 fz_compression_params params; 63 fz_buffer *buffer; 64 } fz_compressed_buffer; 65 66 /** 67 Return the storage size used for a buffer and its data. 68 Used in implementing store handling. 69 70 Never throws exceptions. 71 */ 72 size_t fz_compressed_buffer_size(fz_compressed_buffer *buffer); 73 74 /** 75 Open a stream to read the decompressed version of a buffer. 76 */ 77 fz_stream *fz_open_compressed_buffer(fz_context *ctx, fz_compressed_buffer *); 78 79 /** 80 Open a stream to read the decompressed version of a buffer, 81 with optional log2 subsampling. 82 83 l2factor = NULL for no subsampling, or a pointer to an integer 84 containing the maximum log2 subsample factor acceptable (0 = 85 none, 1 = halve dimensions, 2 = quarter dimensions etc). If 86 non-NULL, then *l2factor will be updated on exit with the actual 87 log2 subsample factor achieved. 88 */ 89 fz_stream *fz_open_image_decomp_stream_from_buffer(fz_context *ctx, fz_compressed_buffer *, int *l2factor); 90 91 /** 92 Open a stream to read the decompressed version of another stream 93 with optional log2 subsampling. 94 */ 95 fz_stream *fz_open_image_decomp_stream(fz_context *ctx, fz_stream *, fz_compression_params *, int *l2factor); 96 97 /** 98 Recognise image format strings in the first 8 bytes from image 99 data. 100 */ 101 int fz_recognize_image_format(fz_context *ctx, unsigned char p[8]); 102 103 enum 104 { 105 FZ_IMAGE_UNKNOWN = 0, 106 107 /* Uncompressed samples */ 108 FZ_IMAGE_RAW, 109 110 /* Compressed samples */ 111 FZ_IMAGE_FAX, 112 FZ_IMAGE_FLATE, 113 FZ_IMAGE_LZW, 114 FZ_IMAGE_RLD, 115 116 /* Full image formats */ 117 FZ_IMAGE_BMP, 118 FZ_IMAGE_GIF, 119 FZ_IMAGE_JBIG2, 120 FZ_IMAGE_JPEG, 121 FZ_IMAGE_JPX, 122 FZ_IMAGE_JXR, 123 FZ_IMAGE_PNG, 124 FZ_IMAGE_PNM, 125 FZ_IMAGE_TIFF, 126 }; 127 128 /** 129 Drop a reference to a compressed buffer. Destroys the buffer 130 and frees any storage/other references held by it. 131 132 Never throws exceptions. 133 */ 134 void fz_drop_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf); 135 136 #endif 137