]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/mobile/jni/thirdparty/openjpeg/libopenjpeg/jp2.h
Add MuPDF native source codes
[hornmich/skoda-qr-demo.git] / QRScanner / mobile / jni / thirdparty / openjpeg / libopenjpeg / jp2.h
1 /*
2  * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3  * Copyright (c) 2002-2007, Professor Benoit Macq
4  * Copyright (c) 2002-2003, Yannick Verschueren
5  * Copyright (c) 2005, Herve Drolon, FreeImage Team
6  * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France 
7  * Copyright (c) 2012, CS Systemes d'Information, France
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 #ifndef __JP2_H
32 #define __JP2_H
33 /**
34 @file jp2.h
35 @brief The JPEG-2000 file format Reader/Writer (JP2)
36
37 */
38
39 /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
40 /*@{*/
41
42 /*#define JPIP_JPIP 0x6a706970*/
43
44 #define     JP2_JP   0x6a502020    /**< JPEG 2000 signature box */
45 #define     JP2_FTYP 0x66747970    /**< File type box */
46 #define     JP2_JP2H 0x6a703268    /**< JP2 header box (super-box) */
47 #define     JP2_IHDR 0x69686472    /**< Image header box */
48 #define     JP2_COLR 0x636f6c72    /**< Colour specification box */
49 #define     JP2_JP2C 0x6a703263    /**< Contiguous codestream box */
50 #define     JP2_URL  0x75726c20    /**< Data entry URL box */
51 #define     JP2_PCLR 0x70636c72    /**< Palette box */
52 #define     JP2_CMAP 0x636d6170    /**< Component Mapping box */
53 #define     JP2_CDEF 0x63646566    /**< Channel Definition box */
54 #define     JP2_DTBL 0x6474626c    /**< Data Reference box */
55 #define     JP2_BPCC 0x62706363    /**< Bits per component box */
56 #define     JP2_JP2  0x6a703220    /**< File type fields */
57
58 /* For the future */
59 /* #define JP2_RES 0x72657320 */  /**< Resolution box (super-box) */
60 /* #define JP2_JP2I 0x6a703269 */  /**< Intellectual property box */
61 /* #define JP2_XML  0x786d6c20 */  /**< XML box */
62 /* #define JP2_UUID 0x75756994 */  /**< UUID box */
63 /* #define JP2_UINF 0x75696e66 */  /**< UUID info box (super-box) */
64 /* #define JP2_ULST 0x756c7374 */  /**< UUID list box */
65
66 /* ----------------------------------------------------------------------- */
67
68 typedef enum
69 {
70   JP2_STATE_NONE            = 0x0,
71   JP2_STATE_SIGNATURE       = 0x1,
72   JP2_STATE_FILE_TYPE       = 0x2,
73   JP2_STATE_HEADER          = 0x4,
74   JP2_STATE_CODESTREAM      = 0x8,
75   JP2_STATE_END_CODESTREAM  = 0x10,
76   JP2_STATE_UNKNOWN         = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
77 }
78 JP2_STATE;
79
80 typedef enum
81 {
82   JP2_IMG_STATE_NONE        = 0x0,
83   JP2_IMG_STATE_UNKNOWN     = 0x7fffffff
84 }
85 JP2_IMG_STATE;
86
87 /** 
88 Channel description: channel index, type, assocation
89 */
90 typedef struct opj_jp2_cdef_info
91 {
92     OPJ_UINT16 cn, typ, asoc;
93 } opj_jp2_cdef_info_t;
94
95 /** 
96 Channel descriptions and number of descriptions
97 */
98 typedef struct opj_jp2_cdef
99 {
100     opj_jp2_cdef_info_t *info;
101     OPJ_UINT16 n;
102 } opj_jp2_cdef_t;
103
104 /** 
105 Component mappings: channel index, mapping type, palette index
106 */
107 typedef struct opj_jp2_cmap_comp
108 {
109     OPJ_UINT16 cmp;
110     OPJ_BYTE mtyp, pcol;
111 } opj_jp2_cmap_comp_t;
112
113 /** 
114 Palette data: table entries, palette columns
115 */
116 typedef struct opj_jp2_pclr
117 {
118     OPJ_UINT32 *entries;
119     OPJ_BYTE *channel_sign;
120     OPJ_BYTE *channel_size;
121     opj_jp2_cmap_comp_t *cmap;
122     OPJ_UINT16 nr_entries;
123     OPJ_BYTE nr_channels;
124 } opj_jp2_pclr_t;
125
126 /** 
127 Collector for ICC profile, palette, component mapping, channel description 
128 */
129 typedef struct opj_jp2_color
130 {
131     OPJ_BYTE *icc_profile_buf;
132     OPJ_UINT32 icc_profile_len;
133
134     opj_jp2_cdef_t *jp2_cdef;
135     opj_jp2_pclr_t *jp2_pclr;
136     OPJ_BYTE jp2_has_colr;
137 } opj_jp2_color_t;
138
139 /** 
140 JP2 component
141 */
142 typedef struct opj_jp2_comps {
143   OPJ_UINT32 depth;      
144   OPJ_UINT32 sgnd;       
145   OPJ_UINT32 bpcc;
146 } opj_jp2_comps_t;
147
148 /**
149 JPEG-2000 file format reader/writer
150 */
151 typedef struct opj_jp2
152 {
153   /** handle to the J2K codec  */
154   opj_j2k_t *j2k;
155   /** list of validation procedures */
156   struct opj_procedure_list * m_validation_list;
157   /** list of execution procedures */
158   struct opj_procedure_list * m_procedure_list;
159
160   /* width of image */
161   OPJ_UINT32 w;
162   /* height of image */
163   OPJ_UINT32 h;
164   /* number of components in the image */
165   OPJ_UINT32 numcomps;
166   OPJ_UINT32 bpc;
167   OPJ_UINT32 C;
168   OPJ_UINT32 UnkC;
169   OPJ_UINT32 IPR;
170   OPJ_UINT32 meth;
171   OPJ_UINT32 approx;
172   OPJ_UINT32 enumcs;
173   OPJ_UINT32 precedence;
174   OPJ_UINT32 brand;
175   OPJ_UINT32 minversion;
176   OPJ_UINT32 numcl;
177   OPJ_UINT32 *cl;
178   opj_jp2_comps_t *comps;
179   /* FIXME: The following two variables are used to save offset
180     as we write out a JP2 file to disk. This mecanism is not flexible
181     as codec writers will need to extand those fields as new part
182     of the standard are implemented.
183   */
184     OPJ_OFF_T j2k_codestream_offset;
185     OPJ_OFF_T jpip_iptr_offset;
186         OPJ_BOOL jpip_on;
187   OPJ_UINT32 jp2_state;
188   OPJ_UINT32 jp2_img_state;
189
190   opj_jp2_color_t color;
191     
192     OPJ_BOOL ignore_pclr_cmap_cdef;
193 }
194 opj_jp2_t;
195
196 /**
197 JP2 Box
198 */
199 typedef struct opj_jp2_box {
200     OPJ_UINT32 length;
201     OPJ_UINT32 type;
202     OPJ_INT32 init_pos;
203 } opj_jp2_box_t;
204
205 typedef struct opj_jp2_header_handler
206 {
207   /* marker value */
208   OPJ_UINT32 id;
209   /* action linked to the marker */
210   OPJ_BOOL (*handler) (     opj_jp2_t *jp2, 
211                             OPJ_BYTE *p_header_data, 
212                             OPJ_UINT32 p_header_size, 
213                             opj_event_mgr_t * p_manager);
214 }
215 opj_jp2_header_handler_t;
216
217
218 typedef struct opj_jp2_img_header_writer_handler 
219 {
220   /* action to perform */
221   OPJ_BYTE*   (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
222   /* result of the action : data */
223   OPJ_BYTE*   m_data;
224   /* size of data */
225   OPJ_UINT32  m_size;
226
227 opj_jp2_img_header_writer_handler_t;
228
229 /** @name Exported functions */
230 /*@{*/
231 /* ----------------------------------------------------------------------- */
232
233 /**
234  * Writes the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
235  *
236  * @param  jp2      the jpeg2000 file codec.
237  * @param  stream      the stream to write data to.
238  * @param  p_manager  user event manager.
239  *
240  * @return true if writing was successful.
241 */
242 OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
243                             opj_stream_private_t *stream,
244                             opj_event_mgr_t * p_manager );
245
246 /**
247 Setup the decoder decoding parameters using user parameters.
248 Decoding parameters are returned in jp2->j2k->cp.
249 @param jp2 JP2 decompressor handle
250 @param parameters decompression parameters
251 */
252 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
253
254 /**
255  * Decode an image from a JPEG-2000 file stream
256  * @param jp2 JP2 decompressor handle
257  * @param p_stream  FIXME DOC
258  * @param p_image   FIXME DOC
259  * @param p_manager FIXME DOC
260  *
261  * @return Returns a decoded image if successful, returns NULL otherwise
262 */
263 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
264                         opj_stream_private_t *p_stream,
265             opj_image_t* p_image,
266             opj_event_mgr_t * p_manager);
267
268 /**
269  * Setup the encoder parameters using the current image and using user parameters. 
270  * Coding parameters are returned in jp2->j2k->cp. 
271  *
272  * @param jp2 JP2 compressor handle
273  * @param parameters compression parameters
274  * @param image input filled image
275  * @param p_manager  FIXME DOC
276 */
277 void opj_jp2_setup_encoder(  opj_jp2_t *jp2, 
278                             opj_cparameters_t *parameters, 
279                             opj_image_t *image, 
280                             opj_event_mgr_t * p_manager);
281
282 /**
283 Encode an image into a JPEG-2000 file stream
284 @param jp2      JP2 compressor handle
285 @param stream    Output buffer stream
286 @param p_manager  event manager
287 @return Returns true if successful, returns false otherwise
288 */
289 OPJ_BOOL opj_jp2_encode(  opj_jp2_t *jp2, 
290               opj_stream_private_t *stream, 
291               opj_event_mgr_t * p_manager);
292
293
294 /**
295  * Starts a compression scheme, i.e. validates the codec parameters, writes the header.
296  *
297  * @param  jp2    the jpeg2000 file codec.
298  * @param  stream    the stream object.
299  * @param  p_image   FIXME DOC
300  * @param p_manager FIXME DOC
301  *
302  * @return true if the codec is valid.
303  */
304 OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
305                                 opj_stream_private_t *stream,
306                                 opj_image_t * p_image,
307                                 opj_event_mgr_t * p_manager);
308
309
310 /**
311  * Ends the compression procedures and possibiliy add data to be read after the
312  * codestream.
313  */
314 OPJ_BOOL opj_jp2_end_compress(  opj_jp2_t *jp2,
315                   opj_stream_private_t *cio,
316                   opj_event_mgr_t * p_manager);
317
318 /* ----------------------------------------------------------------------- */
319
320 /**
321  * Ends the decompression procedures and possibiliy add data to be read after the
322  * codestream.
323  */
324 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, 
325                                 opj_stream_private_t *cio,
326                                 opj_event_mgr_t * p_manager);
327
328 /**
329  * Reads a jpeg2000 file header structure.
330  *
331  * @param p_stream the stream to read data from.
332  * @param jp2 the jpeg2000 file header structure.
333  * @param p_image   FIXME DOC
334  * @param p_manager the user event manager.
335  *
336  * @return true if the box is valid.
337  */
338 OPJ_BOOL opj_jp2_read_header(  opj_stream_private_t *p_stream,
339                                 opj_jp2_t *jp2,
340                                 opj_image_t ** p_image,
341                                 opj_event_mgr_t * p_manager );
342
343 /**
344  * Reads a tile header.
345  * @param  p_jp2         the jpeg2000 codec.
346  * @param  p_tile_index  FIXME DOC
347  * @param  p_data_size   FIXME DOC
348  * @param  p_tile_x0     FIXME DOC
349  * @param  p_tile_y0     FIXME DOC
350  * @param  p_tile_x1     FIXME DOC
351  * @param  p_tile_y1     FIXME DOC
352  * @param  p_nb_comps    FIXME DOC
353  * @param  p_go_on       FIXME DOC
354  * @param  p_stream      the stream to write data to.
355  * @param  p_manager     the user event manager.
356  */
357 OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
358                                     OPJ_UINT32 * p_tile_index,
359                                     OPJ_UINT32 * p_data_size,
360                                     OPJ_INT32 * p_tile_x0,
361                                     OPJ_INT32 * p_tile_y0,
362                                     OPJ_INT32 * p_tile_x1,
363                                     OPJ_INT32 * p_tile_y1,
364                                     OPJ_UINT32 * p_nb_comps,
365                                     OPJ_BOOL * p_go_on,
366                                     opj_stream_private_t *p_stream,
367                                     opj_event_mgr_t * p_manager );
368
369 /**
370  * Writes a tile.
371  *
372  * @param  p_jp2    the jpeg2000 codec.
373  * @param p_tile_index  FIXME DOC
374  * @param p_data        FIXME DOC
375  * @param p_data_size   FIXME DOC
376  * @param  p_stream      the stream to write data to.
377  * @param  p_manager  the user event manager.
378  */
379 OPJ_BOOL opj_jp2_write_tile (  opj_jp2_t *p_jp2,
380                     OPJ_UINT32 p_tile_index,
381                     OPJ_BYTE * p_data,
382                     OPJ_UINT32 p_data_size,
383                     opj_stream_private_t *p_stream,
384                     opj_event_mgr_t * p_manager );
385
386 /**
387  * Decode tile data.
388  * @param  p_jp2    the jpeg2000 codec.
389  * @param  p_tile_index FIXME DOC
390  * @param  p_data       FIXME DOC
391  * @param  p_data_size  FIXME DOC
392  * @param  p_stream      the stream to write data to.
393  * @param  p_manager  the user event manager.
394  *
395  * @return FIXME DOC
396  */
397 OPJ_BOOL opj_jp2_decode_tile (  opj_jp2_t * p_jp2,
398                                 OPJ_UINT32 p_tile_index,
399                                 OPJ_BYTE * p_data,
400                                 OPJ_UINT32 p_data_size,
401                                 opj_stream_private_t *p_stream,
402                                 opj_event_mgr_t * p_manager );
403
404 /**
405  * Creates a jpeg2000 file decompressor.
406  *
407  * @return  an empty jpeg2000 file codec.
408  */
409 opj_jp2_t* opj_jp2_create (OPJ_BOOL p_is_decoder);
410
411 /**
412 Destroy a JP2 decompressor handle
413 @param jp2 JP2 decompressor handle to destroy
414 */
415 void opj_jp2_destroy(opj_jp2_t *jp2);
416
417
418 /**
419  * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
420  *
421  * @param  p_jp2      the jpeg2000 codec.
422  * @param  p_image     FIXME DOC
423  * @param  p_start_x   the left position of the rectangle to decode (in image coordinates).
424  * @param  p_start_y    the up position of the rectangle to decode (in image coordinates).
425  * @param  p_end_x      the right position of the rectangle to decode (in image coordinates).
426  * @param  p_end_y      the bottom position of the rectangle to decode (in image coordinates).
427  * @param  p_manager    the user event manager
428  *
429  * @return  true      if the area could be set.
430  */
431 OPJ_BOOL opj_jp2_set_decode_area(  opj_jp2_t *p_jp2,
432                     opj_image_t* p_image,
433                     OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
434                     OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
435                     opj_event_mgr_t * p_manager );
436
437  /**
438  * 
439  */
440 OPJ_BOOL opj_jp2_get_tile(  opj_jp2_t *p_jp2,
441                             opj_stream_private_t *p_stream,
442                             opj_image_t* p_image,
443                             opj_event_mgr_t * p_manager,
444                             OPJ_UINT32 tile_index );
445
446
447 /**
448  * 
449  */
450 OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, 
451                                                OPJ_UINT32 res_factor, 
452                                                opj_event_mgr_t * p_manager);
453
454
455 /* TODO MSD: clean these 3 functions */
456 /**
457  * Dump some elements from the JP2 decompression structure .
458  *
459  *@param p_jp2        the jp2 codec.
460  *@param flag        flag to describe what elments are dump.
461  *@param out_stream      output stream where dump the elements.
462  *
463 */
464 void jp2_dump (opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream);
465
466 /**
467  * Get the codestream info from a JPEG2000 codec.
468  *
469  *@param  p_jp2        jp2 codec.
470  *
471  *@return  the codestream information extract from the jpg2000 codec
472  */
473 opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2);
474
475 /**
476  * Get the codestream index from a JPEG2000 codec.
477  *
478  *@param  p_jp2        jp2 codec.
479  *
480  *@return  the codestream index extract from the jpg2000 codec
481  */
482 opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_t* p_jp2);
483
484
485 /*@}*/
486
487 /*@}*/
488
489 #endif /* __JP2_H */
490