Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4760 right-hear 1
/*
2
    jbig2dec
3
 
4
    Copyright (C) 2002-2005 Artifex Software, Inc.
5
 
6
    This software is distributed under license and may not
7
    be copied, modified or distributed except as expressly
8
    authorized under the terms of the license contained in
9
    the file LICENSE in this distribution.
10
 
11
    For further licensing information refer to http://artifex.com/ or
12
    contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
13
    San Rafael, CA  94903, U.S.A., +1(415)492-9861.
14
*/
15
 
16
#ifdef __cplusplus
17
extern "C" {
18
#endif
19
 
20
#ifndef _JBIG2_H
21
#define _JBIG2_H
22
 
23
/* warning levels */
24
typedef enum {
25
  JBIG2_SEVERITY_DEBUG,
26
  JBIG2_SEVERITY_INFO,
27
  JBIG2_SEVERITY_WARNING,
28
  JBIG2_SEVERITY_FATAL
29
} Jbig2Severity;
30
 
31
typedef enum {
32
  JBIG2_OPTIONS_EMBEDDED = 1
33
} Jbig2Options;
34
 
35
/* forward public structure declarations */
36
typedef struct _Jbig2Allocator Jbig2Allocator;
37
typedef struct _Jbig2Ctx Jbig2Ctx;
38
typedef struct _Jbig2GlobalCtx Jbig2GlobalCtx;
39
typedef struct _Jbig2Segment Jbig2Segment;
40
typedef struct _Jbig2Image Jbig2Image;
41
 
42
/* private structures */
43
typedef struct _Jbig2Page Jbig2Page;
44
typedef struct _Jbig2SymbolDictionary Jbig2SymbolDictionary;
45
 
46
/*
47
   this is the general image structure used by the jbig2dec library
48
   images are 1 bpp, packed into rows a byte at a time. stride gives
49
   the byte offset to the next row, while width and height define
50
   the size of the image area in pixels.
51
*/
52
 
53
struct _Jbig2Image {
54
        int             width, height, stride;
55
        uint8_t        *data;
56
	int		refcount;
57
};
58
 
59
Jbig2Image*     jbig2_image_new(Jbig2Ctx *ctx, int width, int height);
60
Jbig2Image*	jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
61
void		jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
62
void            jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
63
void		jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value);
64
Jbig2Image	*jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image,
65
                                int width, int height);
66
 
67
/* errors are returned from the library via a callback. If no callback
68
   is provided (a NULL argument is passed ot jbig2_ctx_new) a default
69
   handler is used which prints fatal errors to the stderr stream. */
70
 
71
/* error callback */
72
typedef int (*Jbig2ErrorCallback) (void *data,
73
				  const char *msg, Jbig2Severity severity,
74
				  int32_t seg_idx);
75
 
76
/* memory allocation is likewise done via a set of callbacks so that
77
   clients can better control memory usage. If a NULL is passed for
78
   this argumennt of jbig2_ctx_new, a default allocator based on malloc()
79
   is used. */
80
 
81
/* dynamic memory callbacks */
82
struct _Jbig2Allocator {
83
  void *(*alloc) (Jbig2Allocator *allocator, size_t size);
84
  void (*free) (Jbig2Allocator *allocator, void *p);
85
  void *(*realloc) (Jbig2Allocator *allocator, void *p, size_t size);
86
};
87
 
88
/* decoder context */
89
Jbig2Ctx *jbig2_ctx_new (Jbig2Allocator *allocator,
90
			 Jbig2Options options,
91
			 Jbig2GlobalCtx *global_ctx,
92
			 Jbig2ErrorCallback error_callback,
93
			 void *error_callback_data);
94
void jbig2_ctx_free (Jbig2Ctx *ctx);
95
 
96
/* global context for embedded streams */
97
Jbig2GlobalCtx *jbig2_make_global_ctx (Jbig2Ctx *ctx);
98
void jbig2_global_ctx_free (Jbig2GlobalCtx *global_ctx);
99
 
100
/* submit data to the decoder */
101
int jbig2_data_in (Jbig2Ctx *ctx, const unsigned char *data, size_t size);
102
 
103
/* get the next available decoded page image. NULL means there isn't one. */
104
Jbig2Image *jbig2_page_out (Jbig2Ctx *ctx);
105
/* mark a returned page image as no longer needed. */
106
int jbig2_release_page (Jbig2Ctx *ctx, Jbig2Image *image);
107
/* mark the current page as complete, simulating an end-of-page segment (for broken streams) */
108
int jbig2_complete_page (Jbig2Ctx *ctx);
109
 
110
 
111
/* segment header routines */
112
 
113
struct _Jbig2Segment {
114
  uint32_t number;
115
  uint8_t flags;
116
  uint32_t page_association;
117
  size_t data_length;
118
  int referred_to_segment_count;
119
  uint32_t *referred_to_segments;
120
  void *result;
121
};
122
 
123
Jbig2Segment *jbig2_parse_segment_header (Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size,
124
			    size_t *p_header_size);
125
int jbig2_parse_segment (Jbig2Ctx *ctx, Jbig2Segment *segment,
126
			 const uint8_t *segment_data);
127
void jbig2_free_segment (Jbig2Ctx *ctx, Jbig2Segment *segment);
128
 
129
Jbig2Segment *jbig2_find_segment(Jbig2Ctx *ctx, uint32_t number);
130
 
131
#endif /* _JBIG2_H */
132
 
133
#ifdef __cplusplus
134
}
135
#endif