Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/jbig2dec/jbig2_priv.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* Copyright (C) 2001-2023 Artifex Software, Inc. | |
| 2 All Rights Reserved. | |
| 3 | |
| 4 This software is provided AS-IS with no warranty, either express or | |
| 5 implied. | |
| 6 | |
| 7 This software is distributed under license and may not be copied, | |
| 8 modified or distributed except as expressly authorized under the terms | |
| 9 of the license contained in the file LICENSE in this distribution. | |
| 10 | |
| 11 Refer to licensing information at http://www.artifex.com or contact | |
| 12 Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, | |
| 13 CA 94129, USA, for further information. | |
| 14 */ | |
| 15 | |
| 16 /* | |
| 17 jbig2dec | |
| 18 */ | |
| 19 | |
| 20 #ifndef _JBIG2_PRIV_H | |
| 21 #define _JBIG2_PRIV_H | |
| 22 | |
| 23 /* To enable Memento predefine MEMENTO while building by setting | |
| 24 CFLAGS=-DMEMENTO. */ | |
| 25 | |
| 26 /* If we are being compiled as part of a larger project that includes | |
| 27 * Memento, that project should define JBIG_EXTERNAL_MEMENTO_H to point | |
| 28 * to the include file to use. | |
| 29 */ | |
| 30 #ifdef JBIG_EXTERNAL_MEMENTO_H | |
| 31 #include JBIG_EXTERNAL_MEMENTO_H | |
| 32 #else | |
| 33 #include "memento.h" | |
| 34 #endif | |
| 35 | |
| 36 /* library internals */ | |
| 37 | |
| 38 /* If we don't have a definition for inline, make it nothing so the code will compile */ | |
| 39 #ifndef inline | |
| 40 #define inline | |
| 41 #endif | |
| 42 | |
| 43 typedef uint8_t byte; | |
| 44 | |
| 45 #define bool int | |
| 46 | |
| 47 #ifdef __cplusplus | |
| 48 #define template template_C | |
| 49 #define new new_C | |
| 50 #endif | |
| 51 | |
| 52 #ifndef TRUE | |
| 53 #define TRUE 1 | |
| 54 #endif | |
| 55 #ifndef FALSE | |
| 56 #define FALSE 0 | |
| 57 #endif | |
| 58 | |
| 59 #ifndef NULL | |
| 60 #define NULL ((void*)0) | |
| 61 #endif | |
| 62 | |
| 63 #if !defined (INT32_MIN) | |
| 64 #define INT32_MIN (-0x7fffffff - 1) | |
| 65 #endif | |
| 66 #if !defined (INT32_MAX) | |
| 67 #define INT32_MAX 0x7fffffff | |
| 68 #endif | |
| 69 #if !defined (UINT32_MAX) | |
| 70 #define UINT32_MAX 0xffffffffu | |
| 71 #endif | |
| 72 | |
| 73 typedef struct _Jbig2Page Jbig2Page; | |
| 74 typedef struct _Jbig2Segment Jbig2Segment; | |
| 75 | |
| 76 typedef enum { | |
| 77 JBIG2_FILE_HEADER, | |
| 78 JBIG2_FILE_SEQUENTIAL_HEADER, | |
| 79 JBIG2_FILE_SEQUENTIAL_BODY, | |
| 80 JBIG2_FILE_RANDOM_HEADERS, | |
| 81 JBIG2_FILE_RANDOM_BODIES, | |
| 82 JBIG2_FILE_EOF | |
| 83 } Jbig2FileState; | |
| 84 | |
| 85 struct _Jbig2Ctx { | |
| 86 Jbig2Allocator *allocator; | |
| 87 Jbig2Options options; | |
| 88 const Jbig2Ctx *global_ctx; | |
| 89 Jbig2ErrorCallback error_callback; | |
| 90 void *error_callback_data; | |
| 91 | |
| 92 byte *buf; | |
| 93 size_t buf_size; | |
| 94 size_t buf_rd_ix; | |
| 95 size_t buf_wr_ix; | |
| 96 | |
| 97 Jbig2FileState state; | |
| 98 | |
| 99 uint8_t file_header_flags; | |
| 100 uint32_t n_pages; | |
| 101 | |
| 102 uint32_t n_segments_max; | |
| 103 Jbig2Segment **segments; | |
| 104 uint32_t n_segments; /* index of last segment header parsed */ | |
| 105 uint32_t segment_index; /* index of last segment body parsed */ | |
| 106 | |
| 107 /* list of decoded pages, including the one in progress, | |
| 108 currently stored as a contiguous, 0-indexed array. */ | |
| 109 uint32_t current_page; | |
| 110 uint32_t max_page_index; | |
| 111 Jbig2Page *pages; | |
| 112 }; | |
| 113 | |
| 114 uint32_t jbig2_get_uint32(const byte *bptr); | |
| 115 | |
| 116 int32_t jbig2_get_int32(const byte *buf); | |
| 117 | |
| 118 uint16_t jbig2_get_uint16(const byte *bptr); | |
| 119 | |
| 120 int16_t jbig2_get_int16(const byte *buf); | |
| 121 | |
| 122 /* dynamic memory management */ | |
| 123 void *jbig2_alloc(Jbig2Allocator *allocator, size_t size, size_t num); | |
| 124 | |
| 125 void jbig2_free(Jbig2Allocator *allocator, void *p); | |
| 126 | |
| 127 void *jbig2_realloc(Jbig2Allocator *allocator, void *p, size_t size, size_t num); | |
| 128 | |
| 129 #define jbig2_new(ctx, t, size) ((t *)jbig2_alloc(ctx->allocator, size, sizeof(t))) | |
| 130 | |
| 131 #define jbig2_renew(ctx, p, t, size) ((t *)jbig2_realloc(ctx->allocator, (p), size, sizeof(t))) | |
| 132 | |
| 133 int jbig2_error(Jbig2Ctx *ctx, Jbig2Severity severity, uint32_t seg_idx, const char *fmt, ...) | |
| 134 #ifdef __GNUC__ | |
| 135 __attribute__ ((format (__printf__, 4, 5))) | |
| 136 #endif | |
| 137 ; | |
| 138 | |
| 139 /* The word stream design is a compromise between simplicity and | |
| 140 trying to amortize the number of method calls. Each ::get_next_word | |
| 141 invocation pulls 4 bytes from the stream, packed big-endian into a | |
| 142 32 bit word. The offset argument is provided as a convenience. It | |
| 143 begins at 0 and increments by 4 for each successive invocation. */ | |
| 144 typedef struct _Jbig2WordStream Jbig2WordStream; | |
| 145 | |
| 146 struct _Jbig2WordStream { | |
| 147 int (*get_next_word)(Jbig2Ctx *ctx, Jbig2WordStream *self, size_t offset, uint32_t *word); | |
| 148 }; | |
| 149 | |
| 150 Jbig2WordStream *jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size); | |
| 151 | |
| 152 void jbig2_word_stream_buf_free(Jbig2Ctx *ctx, Jbig2WordStream *ws); | |
| 153 | |
| 154 /* restrict is standard in C99, but not in all C++ compilers. */ | |
| 155 #if defined (__STDC_VERSION_) && (__STDC_VERSION__ >= 199901L) /* C99 */ | |
| 156 #define JBIG2_RESTRICT restrict | |
| 157 #elif defined(_MSC_VER) && (_MSC_VER >= 1600) /* MSVC 10 or newer */ | |
| 158 #define JBIG2_RESTRICT __restrict | |
| 159 #elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC 3 or newer */ | |
| 160 #define JBIG2_RESTRICT __restrict | |
| 161 #else /* Unknown or ancient */ | |
| 162 #define JBIG2_RESTRICT | |
| 163 #endif | |
| 164 | |
| 165 #endif /* _JBIG2_PRIV_H */ |
