summaryrefslogtreecommitdiffstats
path: root/conversion/image.h
blob: 91213ed8aace2936635d0953bf0d2e57627a9635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/

#ifndef __RASNITF_IMAGE_H
#define __RASNITF_IMAGE_H

#include <fstream>
#include <iostream>

namespace RasNITF{

class image_band{
    
 public:

    char irepbandnn[2];
    char isubcatnn[6];
    char ifcnn[1];
    char imfltnn[3];
    char nlutsnn[1];
    char nelutnn[5];
    int numluts;
    int numlutentries;
    char* lutdnnm;

    image_band();
    ~image_band();
    
};

class image {

    /*********************************
     * image header fields
     ********************************/

    char m_im[2];
    char m_iid1[10];
    char m_idatim[14];
    char m_tgtid[17];
    char m_iid2[80];
    char m_isclas[1];
    char m_isclsy[2];
    char m_iscode[11];
    char m_isctlh[2];
    char m_isrel[20];
    char m_isdctp[2];
    char m_isdcdt[8];
    char m_isdcxm[4];
    char m_isdg[1];
    char m_isdgdt[8];
    char m_iscltx[43];
    char m_iscatp[1];
    char m_iscaut[40];
    char m_iscrsn[1];
    char m_issrdt[8];
    char m_isctln[15];
    char m_encryp[1];
    char m_isorce[42];
    char m_nrows[8];
    char m_ncols[8];
    char m_pvtype[3];
    char m_irep[8];
    char m_icat[8];
    char m_abpp[2];
    char m_pjust[1];
    char m_icords[1];
    char m_igeolo[60];    
    char m_nicom[1];
    char* m_icom;
    char m_ic[2];
    char m_comrat[4];
    char m_nbands[1];
    char m_xbands[5];  
    image_band* m_bands;
    char m_isync[1];
    char m_imode[1];
    char m_nbpr[4];
    char m_nbpc[4];
    char m_nppbh[4];
    char m_nppbv[4];
    char m_nbpp[2];
    char m_idlvl[3];
    char m_ialvl[3];
    char m_iloc[10];
    char m_imag[4];
    char m_udidl[5];
    char m_udofl[3];
    char* m_udid;
    char m_ixshdl[5];
    char m_ixsofl[3];
    char* m_ixshd;

    /*****************************
     *  image data mask table
     ****************************/

    /*      
    long imdataoff;
    unsigned short bmrlnth;
    unsigned short tmrlnth;
    unsigned short tpxcdlnth;
    long tpxcd;
    char* BMRnBNDm; 
    char* TMRnBNDm;
    */

    /*****************************
     * raw image data
     *****************************/
 
    char* m_data;

    /*****************************
     *  additional variables
     *****************************/

//    bool compressed;
    int n_nicom;
    int n_nbands;
    int n_xbands;
    int numbands; 
    int n_udidl;
    int n_ixshdl;
    long header_length;
    long data_length;
    char texthl[6];
    char textdl[10];
    int n_nbpr;                    
    int n_nbpc;                    
    int n_nppbh;                   
    int n_nppbv;                   

    /*****************************
     *  variables for data reordering
     *  populated by compute_data_reordering_variables()
     *****************************/
        
    int n_nrows;
    int n_ncols;
    int px_comp_size;
    int px_size;
    int numblocks;
    
    long block_size_bytes;
    long block_size_pixels;
    long block_row_size; //bytes
    long block_band_size; //bytes
    long block_band_size_px;
    long image_band_size;
  
 
    int copy_block_data(char* writeto, int hor_block_index, int ver_block_index );

    // functions for data reordering

    void compute_data_reordering_variables();

    int blpxseq2pxseq(char* src, char* dest);
    int pxseq2blpxseq(char*, char*);

    int imode_1band2ps();
    int imode_b2ps();
    int imode_r2ps();
    int imode_p2ps();
    int imode_s2ps();

    int imode_ps21band(char*);
    int imode_ps2b(char*);
    int imode_ps2r(char*);
    int imode_ps2p(char*);
    int imode_ps2s(char*);
   
 
 public:    

    image();
    ~image();

    int read_file(std::istream&, long, long, bool read_image_data);
    int write_file(std::ofstream& fs);

    std::string get_li() const;
    std::string get_lish() const;
    long get_size() const;
    int get_width() const;
    int get_height() const;

    int to_pixel_sequential();
    int to_block_pixel_sequential(char* src);

    std::string get_irep() const;
    std::string get_pvtype() const;

    int get_nbpp_bytes() const;

//    char* get_data_ptr();


};

}

#endif