Initial revision
[openjpeg.git] / libopenjpeg / tcd.h
1 /*
2  * Copyright (c) 2001-2002, David Janssens 
3  * Copyright (c) 2002-2003, Yannick Verschueren
4  * Copyright (c) 2002-2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #ifndef __TCD_H
30 #define __TCD_H
31
32 #include "j2k.h"
33 #include "tgt.h"
34
35 typedef struct {
36         int numpasses;
37         int len;
38         unsigned char *data;
39         int maxpasses;
40         int numnewpasses;
41         int newlen;
42 } tcd_seg_t;
43
44 typedef struct {
45         int rate;
46         double distortiondec;
47         int term, len;
48 } tcd_pass_t;
49
50 typedef struct {
51         int numpasses;
52         int len;
53         double disto;                                                                   /* add for index (Cfr. Marcela) */
54         unsigned char *data;
55 } tcd_layer_t;
56
57 typedef struct {
58         int x0, y0, x1, y1;
59         int numbps;
60         int numlenbits;
61         int len;
62         int numpasses;
63         int numnewpasses;
64         int numsegs;
65         tcd_seg_t segs[100];
66         unsigned char data[8192];
67         int numpassesinlayers;
68         tcd_layer_t layers[100];
69         int totalpasses;
70         tcd_pass_t passes[100];
71 } tcd_cblk_t;
72
73 typedef struct {
74         int x0, y0, x1, y1;
75         int cw, ch;
76         tcd_cblk_t *cblks;
77         tgt_tree_t *incltree;
78         tgt_tree_t *imsbtree;
79 } tcd_precinct_t;
80
81 typedef struct {
82         int x0, y0, x1, y1;
83         int bandno;
84         tcd_precinct_t *precincts;
85         int numbps;
86         int stepsize;
87 } tcd_band_t;
88
89 typedef struct {
90         int x0, y0, x1, y1;
91         int previous_x0, previous_y0, previous_x1, previous_y1; /* usefull for the DWT */
92         int cas_col, cas_row;                                   /* usefull for the DWT */
93         int pw, ph;                                                                             /* , old_pw,old_ph, old_pw_max,old_ph_max; */
94         int numbands;
95         tcd_band_t bands[3];
96 } tcd_resolution_t;
97
98 typedef struct {
99         int x0, y0, x1, y1;
100         int previous_row, previous_col; /* usefull for the DWT */
101         int numresolutions;
102         tcd_resolution_t *resolutions;
103         int *data;
104 } tcd_tilecomp_t;
105
106 typedef struct {
107         int x0, y0, x1, y1;
108         int numcomps;
109         /* int PPT; */
110         /* int len_ppt; */
111         tcd_tilecomp_t *comps;
112 } tcd_tile_t;
113
114 typedef struct {
115         int tw, th;
116         tcd_tile_t *tiles;
117 } tcd_image_t;
118
119 /*
120  * Initialize the tile coder/decoder
121  * img: raw image
122  * cp: coding parameters
123  * info_IM: creation of index file
124  */
125 void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno);
126
127 void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno);
128
129 void tcd_init(j2k_image_t * img, j2k_cp_t * cp);
130
131 void tcd_free_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno);
132
133 /*
134  * Encode a tile from the raw image into a buffer, format pnm, pgm or ppm
135  * tileno: number that identifies one of the tiles to be encoded
136  * dest: destination buffer
137  * len: length of destination buffer
138  */
139 int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
140                                                                                                 info_image * info_IM);
141
142 /*
143  * Encode a tile from the raw image into a buffer, format pgx
144  * tileno: number that identifies one of the tiles to be encoded
145  * dest: destination buffer
146  * len: length of destination buffer
147  */
148 int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
149                                                                                                 info_image * info_IM);
150
151 /*
152  * Decode a tile from a buffer into a raw image
153  * src: source buffer
154  * len: length of the source buffer
155  * tileno: number that identifies the tile that will be decoded
156  */
157 int tcd_decode_tile(unsigned char *src, int len, int tileno);
158
159 #endif