1 | /* Copyright (C) 2001-2019 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., 1305 Grant Avenue - Suite 200, Novato, |
13 | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | */ |
15 | |
16 | /* |
17 | jbig2dec |
18 | */ |
19 | |
20 | #ifdef __cplusplus |
21 | extern "C" |
22 | { |
23 | #endif |
24 | |
25 | #ifndef _JBIG2_H |
26 | #define _JBIG2_H |
27 | |
28 | #define JBIG2_VERSION_MAJOR (0) |
29 | #define JBIG2_VERSION_MINOR (16) |
30 | |
31 | /* warning levels */ |
32 | typedef enum { |
33 | JBIG2_SEVERITY_DEBUG, |
34 | JBIG2_SEVERITY_INFO, |
35 | JBIG2_SEVERITY_WARNING, |
36 | JBIG2_SEVERITY_FATAL |
37 | } Jbig2Severity; |
38 | |
39 | typedef enum { |
40 | JBIG2_OPTIONS_EMBEDDED = 1 |
41 | } Jbig2Options; |
42 | |
43 | /* forward public structure declarations */ |
44 | typedef struct _Jbig2Allocator Jbig2Allocator; |
45 | typedef struct _Jbig2Ctx Jbig2Ctx; |
46 | typedef struct _Jbig2GlobalCtx Jbig2GlobalCtx; |
47 | |
48 | /* |
49 | this is the general image structure used by the jbig2dec library |
50 | images are 1 bpp, packed into rows a byte at a time. stride gives |
51 | the byte offset to the next row, while width and height define |
52 | the size of the image area in pixels. |
53 | */ |
54 | typedef struct _Jbig2Image Jbig2Image; |
55 | struct _Jbig2Image { |
56 | uint32_t width; |
57 | uint32_t height; |
58 | uint32_t stride; |
59 | uint8_t *data; |
60 | int refcount; |
61 | }; |
62 | |
63 | /* errors are returned from the library via a callback. If no callback |
64 | is provided (a NULL argument is passed to jbig2_ctx_new) a default |
65 | handler is used which prints fatal errors to the stderr stream. */ |
66 | |
67 | /* error callback */ |
68 | typedef void (*Jbig2ErrorCallback)(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx); |
69 | |
70 | /* memory allocation is likewise done via a set of callbacks so that |
71 | clients can better control memory usage. If a NULL is passed for |
72 | this argument of jbig2_ctx_new, a default allocator based on malloc() |
73 | is used. */ |
74 | |
75 | /* dynamic memory callbacks */ |
76 | struct _Jbig2Allocator { |
77 | void *(*alloc)(Jbig2Allocator *allocator, size_t size); |
78 | void (*free)(Jbig2Allocator *allocator, void *p); |
79 | void *(*realloc)(Jbig2Allocator *allocator, void *p, size_t size); |
80 | }; |
81 | |
82 | /* decoder context */ |
83 | #define jbig2_ctx_new(allocator, options, global_ctx, error_callback, error_callback_data) jbig2_ctx_new_imp((allocator), (options), (global_ctx), (error_callback), (error_callback_data), JBIG2_VERSION_MAJOR, JBIG2_VERSION_MINOR) |
84 | Jbig2Ctx *jbig2_ctx_new_imp(Jbig2Allocator *allocator, |
85 | Jbig2Options options, |
86 | Jbig2GlobalCtx *global_ctx, |
87 | Jbig2ErrorCallback error_callback, |
88 | void *error_callback_data, |
89 | int jbig2_version_major, |
90 | int jbig2_version_minor); |
91 | Jbig2Allocator *jbig2_ctx_free(Jbig2Ctx *ctx); |
92 | |
93 | /* global context for embedded streams */ |
94 | Jbig2GlobalCtx *jbig2_make_global_ctx(Jbig2Ctx *ctx); |
95 | Jbig2Allocator *jbig2_global_ctx_free(Jbig2GlobalCtx *global_ctx); |
96 | |
97 | /* submit data to the decoder */ |
98 | int jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size); |
99 | |
100 | /* get the next available decoded page image. NULL means there isn't one. */ |
101 | Jbig2Image *jbig2_page_out(Jbig2Ctx *ctx); |
102 | /* mark a returned page image as no longer needed. */ |
103 | void jbig2_release_page(Jbig2Ctx *ctx, Jbig2Image *image); |
104 | /* mark the current page as complete, simulating an end-of-page segment (for broken streams) */ |
105 | int jbig2_complete_page(Jbig2Ctx *ctx); |
106 | |
107 | #endif /* _JBIG2_H */ |
108 | |
109 | #ifdef __cplusplus |
110 | } |
111 | #endif |
112 | |