Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_1_Build_1016 / libraries / libjni-ecw / include / NCSJP2File.h @ 33925

History | View | Annotate | Download (45.8 KB)

1
/********************************************************
2
** Copyright 2002 Earth Resource Mapping Ltd.
3
** This document contains proprietary source code of
4
** Earth Resource Mapping Ltd, and can only be used under
5
** one of the three licenses as described in the 
6
** license.txt file supplied with this distribution. 
7
** See separate license.txt file for license details 
8
** and conditions.
9
**
10
** This software is covered by US patent #6,442,298,
11
** #6,102,897 and #6,633,688.  Rights to use these patents 
12
** is included in the license agreements.
13
**
14
** FILE:     $Archive: /NCS/Source/include/NCSJP2File.h $
15
** CREATED:  28/11/2002 3:27:34 PM
16
** AUTHOR:   Simon Cope
17
** PURPOSE:  CNCSJP2File class header
18
** EDITS:    [xx] ddMmmyy NAME COMMENTS
19
**                         [01] 03Aug04 tfl  Added integer member to NCSJP2PCSBox
20
**                         [02] 07Dec04 tfl  Moved GeodataUsage enum declaration to NCSECWClient.h
21
**                         [03] 17Dec04 tfl  Added static CNCSJP2File::Shutdown() function called by CNCSJP2FileView::Shutdown()
22
 *******************************************************/
23

    
24
#ifndef NCSJP2FILE_H
25
#define NCSJP2FILE_H
26

    
27
#ifndef NCSJP2DEFS_H
28
#include "NCSJPCDefs.h"
29
#endif // NCSJP2DEFS_H
30

    
31
#ifndef NCSECWCLIENT_H
32
#include "NCSECWClient.h"
33
#endif // NCSECWCLIENT_H
34

    
35
//#ifndef NCSECW_H
36
//#include "NCSEcw.h"
37
//#endif // NCSECW_H
38

    
39
// Our own 64bit IOSTREAM class
40
#ifndef NCSJPCFileIOSTREAM_H
41
#include "NCSJPCFileIOStream.h"
42
#endif // NCSJPCFileIOSTREAM_H
43

    
44
// JP2 Box class
45
#ifndef NCSJP2BOX_H
46
#include "NCSJP2Box.h"
47
#endif // NCSJP2BOX_H
48

    
49
// JP2 SuperBox class
50
#ifndef NCSJP2SUPERBOX_H
51
#include "NCSJP2SuperBox.h"
52
#endif // NCSJP2SUPERBOX_H
53

    
54
// JPC ComponentDepthType
55
#ifndef NCSJPCCOMPONENTDEPTHTYPE_H
56
#include "NCSJPCComponentDepthType.h"
57
#endif // NCSJPCCOMPONENTDEPTHTYPE_H
58

    
59
// JPC codestream classes
60
#ifndef NCSJPC_H
61
#include "NCSJPC.h"
62
#endif // NCSJPC_H
63

    
64
#define ECW_COMPRESS_SDK_LIMIT_MASK                        0xfe43218a
65

    
66
/**
67
 * CNCSJP2File class - the JP2 file class.
68
 * Note, the JP2File class is a superbox!
69
 * The JP2File is the base shared file object used by multiple CNCSJP2FileView classes to 
70
 * access a JP2 file.
71
 * 
72
 * @author       Simon Cope
73
 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
74
 */
75
class NCSJPC_EXPORT CNCSJP2File: public CNCSJP2SuperBox, public CNCSJPCNodeTiler {
76
public:
77
        
78
        /**
79
         * CNCSJP2FileVector class 
80
         * The JP2FileVector is a vector containing all the CNCSJP2File object instances.
81
         * There is only one instance of this class.
82
         * 
83
         * @author       Simon Cope
84
         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
85
         */
86
        class NCSJPC_EXPORT_ALL CNCSJP2FileVector: public std::vector<CNCSJP2File *> {
87
        public:
88
                        /** Default constructor, initialises ECW library */
89
                CNCSJP2FileVector() {
90
                        NCSecwInit();
91
                }
92
                        /** Virtual destructor, clean up */
93
                virtual ~CNCSJP2FileVector() { 
94
                        CloseAll(); 
95
                        NCSecwShutdown();
96
                };
97
                        /** 
98
                         * CloseAll() - closes all open CNCSJP2File instances
99
                         */
100
                void CloseAll(void);
101
                        /** 
102
                         * Lock() - Lock the vector
103
                         */
104
                void Lock(void) {
105
                        NCSecwGlobalLock();
106
                };
107
                        /** 
108
                         * UnLock() - Unlock the vector
109
                         */
110
                void UnLock(void) {
111
                        NCSecwGlobalUnLock();
112
                };
113
        };
114
                /**
115
                 * CNCSJP2SignatureBox class - the JP2 signature box.  This box is always present.
116
                 * 
117
                 * @author       Simon Cope
118
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
119
                 */        
120
        class NCSJPC_EXPORT_ALL CNCSJP2SignatureBox: public CNCSJP2Box {
121
        public:
122
                        /** Box type */ 
123
                static UINT32        sm_nTBox;
124
                        /** JP2 file signature */
125
                static UINT32        sm_JP2Signature;
126

    
127
                        /** Signature as read from file */
128
                UINT32                m_nSignature;
129

    
130
                        /** Default constructor, initialises members */
131
                CNCSJP2SignatureBox();
132
                        /** Virtual destructor */
133
                virtual ~CNCSJP2SignatureBox();
134
                        /** 
135
                         * Update the extended length of the box prior to writing
136
                         */
137
                virtual void UpdateXLBox(void);
138

    
139
                        /** 
140
                         * Parse the signature box from the JP2 file.
141
                         * @param                JP2File                JP2 file being parsed
142
                         * @param                Stream                IOStream to use to parse file.
143
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
144
                         */
145
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
146
                        /** 
147
                         * UnParse the signature box to the JP2 file.
148
                         * @param                JP2File                JP2 file being parsed
149
                         * @param                Stream                IOStream to use to parse file.
150
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
151
                         */
152
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
153
        };
154

    
155
                /**
156
                 * CNCSJP2FileTypeBox class - the JP2 file type box class.  This box is always present.
157
                 * 
158
                 * @author       Simon Cope
159
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
160
                 */        
161
        class NCSJPC_EXPORT_ALL CNCSJP2FileTypeBox: public CNCSJP2Box {
162
        public:
163
                        /** Compatibility list entry, 4 chars as UINT32 */
164
                typedef UINT32 CNCSJP2CLEntry;
165
                        /** Compatibility list */
166
                typedef std::list<CNCSJP2CLEntry> CNCSJP2CLList;
167

    
168
                        /** Box type */
169
                static UINT32        sm_nTBox;
170
                        /** JP2 Brand */
171
                static UINT32        sm_JP2Brand;
172

    
173
                        /** Brand as read from file */
174
                UINT32                        m_Brand;
175
                        /** Minor version */
176
                UINT32                        m_nMinV;
177
                        /** Compatibility list - other files may be readable as JP2, eg JPX files */
178
                CNCSJP2CLList        m_CLList;
179

    
180
                        /** Default constructor, initialises members */
181
                CNCSJP2FileTypeBox();
182
                        /** Virtual destructor */
183
                virtual ~CNCSJP2FileTypeBox();
184
                        /** 
185
                         * Update the extended length of the box prior to writing
186
                         */
187
                virtual void UpdateXLBox(void);
188

    
189
                        /** 
190
                         * Parse the file type box from the JP2 file.
191
                         * @param                JP2File                JP2 file being parsed
192
                         * @param                Stream                IOStream to use to parse file.
193
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
194
                         */
195
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
196
                        /** 
197
                         * UnParse the file type box to the JP2 file.
198
                         * @param                JP2File                JP2 file being parsed
199
                         * @param                Stream                IOStream to use to parse file.
200
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
201
                         */
202
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
203
        };
204
                /**
205
                 * CNCSJP2HeaderBox class - the JP2 file header box class.  This box is always present.
206
                 * 
207
                 * @author       Simon Cope
208
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
209
                 */        
210
        class NCSJPC_EXPORT_ALL CNCSJP2HeaderBox: public CNCSJP2SuperBox {
211
        public:
212
                        /**
213
                         * CNCSJP2ImageHeaderBox class - the JP2 file image header box class.  This box is always present.
214
                         * 
215
                         * @author       Simon Cope
216
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
217
                         */        
218
                class NCSJPC_EXPORT_ALL CNCSJP2ImageHeaderBox: public CNCSJP2Box, public CNCSJPCComponentDepthType {
219
                public:
220
                                /** Box type */
221
                        static UINT32        sm_nTBox;
222

    
223
                                /** Image Width */
224
                        UINT32                        m_nWidth;
225
                                /** Image Height */
226
                        UINT32                        m_nHeight;
227
                                /** Number of image components, eg RGB = 3 */
228
                        UINT16                        m_nComponents;
229
                                /** Compression type, for a JP2 == 7 */
230
                        UINT8                        m_nCompressionType;
231
                                /** Actual colorspace in image is known, 0 == known & ColourSpaceBox available, 1 == unkown */
232
                        UINT8                        m_nUnknownColorspace;
233
                                /** Intellectual property, 0 = none, 1 - IPRBox present */
234
                        UINT8                        m_nIPR;
235

    
236
                                /** Default constructor, initialises members */
237
                        CNCSJP2ImageHeaderBox();
238
                                /** Virtual destructor */
239
                        virtual ~CNCSJP2ImageHeaderBox();
240
                                /** 
241
                                 * Update the extended length of the box prior to writing
242
                                 */
243
                        virtual void UpdateXLBox(void);
244

    
245
                                /** 
246
                                 * Parse the image header box from the JP2 file.
247
                                 * @param                JP2File                JP2 file being parsed
248
                                 * @param                Stream                IOStream to use to parse file.
249
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
250
                                 */
251
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
252
                                /** 
253
                                 * UnParse the image header box to the JP2 file.
254
                                 * @param                JP2File                JP2 file being parsed
255
                                 * @param                Stream                IOStream to use to parse file.
256
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
257
                                 */
258
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
259
                };
260
                        /**
261
                         * CNCSJP2BitsPerComponentBox class - the JP2 file bits per component box class.
262
                         * This box is only present if m_nBitsPerComponent in the IMageHeaderBox is 255, indicating
263
                         * each component may be a different bit depth (eg, 5/6/6 RGB).
264
                         * 
265
                         * @author       Simon Cope
266
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
267
                         */        
268
                class NCSJPC_EXPORT_ALL CNCSJP2BitsPerComponentBox: public CNCSJP2Box {
269
                public:
270
                                /** Box type */
271
                        static UINT32        sm_nTBox;
272

    
273
                                /** Bit depth for each component */
274
                        std::vector<CNCSJPCComponentDepthType>        m_Bits;
275

    
276
                                /** Default constructor, initialised members */
277
                        CNCSJP2BitsPerComponentBox();
278
                                /** Virtual destructor */
279
                        virtual ~CNCSJP2BitsPerComponentBox();
280
                                /** 
281
                                 * Update the extended length of the box prior to writing
282
                                 */
283
                        virtual void UpdateXLBox(void);
284

    
285
                                /** 
286
                                 * Parse the bits per component box from the JP2 file.
287
                                 * @param                JP2File                JP2 file being parsed
288
                                 * @param                Stream                IOStream to use to parse file.
289
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
290
                                 */
291
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
292
                                /** 
293
                                 * UnParse the bits per component box to the JP2 file.
294
                                 * @param                JP2File                JP2 file being parsed
295
                                 * @param                Stream                IOStream to use to parse file.
296
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
297
                                 */
298
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
299
                };
300
                        /**
301
                         * CNCSJP2ColorSpecificationBox class - the JP2 file color specification box class.
302
                         * This box is only present when m_nUnknownColorspace in the ImageHeaderBox == 0, 
303
                         * indicating the colorspace of the image is known.
304
                         * 
305
                         * @author       Simon Cope
306
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
307
                         */        
308
                class NCSJPC_EXPORT_ALL CNCSJP2ColorSpecificationBox: public CNCSJP2Box {
309
                public:
310
                                /** Box type */
311
                        static UINT32        sm_nTBox;
312

    
313
                                /** ColorSpace type, may be predefined or an ICC mapping */
314
                        typedef enum {
315
                                        /** Either sRGB or GREYSCALE colorspace */
316
                                ENUMERATED_COLORSPACE                = 1,
317
                                        /** Rstricted ICC color profile is present */
318
                                RESTRICTED_ICC_PROFILE                = 2,
319
                                        /** Full ICC color profile is present */
320
                                ICC_PROFILE                = 3                        
321
                        } Type;
322
                                /** Enumerated colorspace types */
323
                        typedef enum {
324
                                        /** sRGB colorspace */
325
                                sRGB                                                = 16,
326
                                        /** GREYSCALE colorspace */
327
                                GREYSCALE                                        = 17,
328
                                        /** YCbCr colorspace */
329
                                YCbCr                                                = 18,
330
                                        /** sYCbCr colorspace */
331
                                sYCC                                                = 22
332
                        } EnumeratedType;
333

    
334
                                /** ColorSpace method, either ENUMERATED or ICC */
335
                        Type                m_eMethod;
336
                                /** Precedence, always = 0 & is ignored */
337
                        UINT8                m_nPrecedence;
338
                                /** Approximation, always = 0 & is ignored */
339
                        UINT8                m_nApproximation;
340
                                /** If m_nMethod == ENUMERATED, this specifies colorspace */
341
                        EnumeratedType                m_eEnumeratedColorspace;
342
                                /** If m_nMethod == ICC, this specifies ICC profile */
343
                        void                *m_pICCProfile;
344
                                /** Length in bytes of the in-memory ICC profile */
345
                        UINT32                m_nICCLen;
346

    
347
                                /** Default constructor, initialises members */
348
                        CNCSJP2ColorSpecificationBox();
349
                                /** Cirtual destructor */
350
                        virtual ~CNCSJP2ColorSpecificationBox();
351
                                /** 
352
                                 * Update the extended length of the box prior to writing
353
                                 */
354
                        virtual void UpdateXLBox(void);
355
                                /** 
356
                                 * Parse the color specification box from the JP2 file.
357
                                 * @param                JP2File                JP2 file being parsed
358
                                 * @param                Stream                IOStream to use to parse file.
359
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
360
                                 */
361
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
362
                                /** 
363
                                 * UnParse the color specification box to the JP2 file.
364
                                 * @param                JP2File                JP2 file being parsed
365
                                 * @param                Stream                IOStream to use to parse file.
366
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
367
                                 */
368
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
369
                };
370
                        /**
371
                         * CNCSJP2PaletteBox class - the JP2 file palette box class.
372
                         * This box is always present with a component mapping box.
373
                         * 
374
                         * @author       Simon Cope
375
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
376
                         */        
377
                class NCSJPC_EXPORT_ALL CNCSJP2PaletteBox: public CNCSJP2Box {
378
                public:
379
                        typedef std::vector<void*> PaletteEntry;
380
                                /** Box type */
381
                        static UINT32        sm_nTBox;
382

    
383
                                /** Number of entries in the palette, 1-1024 */
384
                        UINT16                m_nEntries;
385
                                /** Number of components generated by palette, eg RGB = 3 */
386
                        UINT8                m_nComponents;
387
                                /** Bit depth of each generated component, 1-38 bits, bit7 = sign */
388
                        std::vector<CNCSJPCComponentDepthType>        m_Bits;
389
                                /** Palette entries */
390
                        std::vector<PaletteEntry> m_Entries;
391

    
392
                                /** Default constructor, initialises members */
393
                        CNCSJP2PaletteBox();
394
                                /** Cirtual destructor */
395
                        virtual ~CNCSJP2PaletteBox();
396

    
397
                                /** 
398
                                 * Parse the palette box from the JP2 file.
399
                                 * @param                JP2File                JP2 file being parsed
400
                                 * @param                Stream                IOStream to use to parse file.
401
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
402
                                 */
403
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
404
#ifndef NCSJPC_LEAN_AND_MEAN
405
                                /** 
406
                                 * UnParse the palette box to the JP2 file.
407
                                 * @param                JP2File                JP2 file being parsed
408
                                 * @param                Stream                IOStream to use to parse file.
409
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
410
                                 */
411
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
412
#endif //!NCSJPC_LEAN_AND_MEAN
413
                };
414
                        /**
415
                         * CNCSJP2ComponentMappingBox class - the JP2 file component mapping box class.
416
                         * This box is always present with a palette box to define channel usage.
417
                         * 
418
                         * @author       Simon Cope
419
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
420
                         */        
421
                class NCSJPC_EXPORT_ALL CNCSJP2ComponentMappingBox: public CNCSJP2Box {
422
                public:
423
                                /** Type of component */
424
                        typedef enum {
425
                                        /** This is the direct component value, eg Red */
426
                                DIRECT                = 0,
427
                                        /** This component is a palette index */
428
                                PALETTE                = 1
429
                        } Type;
430

    
431
                                /** Component mapping information  */
432
                        typedef struct {
433
                                        /** 0-based index of the component this mapping is for */
434
                                UINT16        m_iComponent;
435
                                        /** Type of component */
436
                                Type        m_nType;
437
                                        /** Component "column" index into palette */
438
                                UINT8        m_iPalette;
439
                        } ComponentMapping;
440

    
441
                                /** Box type */
442
                        static UINT32        sm_nTBox;
443

    
444
                                /** Number of entries in the componentmapping */
445
                        UINT16                m_nEntries;
446

    
447
                                /** Component->Palette mappings */
448
                        std::vector<ComponentMapping>        m_Mapping;
449

    
450
                                /** Default constructor, initialises members */
451
                        CNCSJP2ComponentMappingBox();
452
                                /** Cirtual destructor */
453
                        virtual ~CNCSJP2ComponentMappingBox();
454

    
455
                                /** 
456
                                 * Parse the component mapping box from the JP2 file.
457
                                 * @param                JP2File                JP2 file being parsed
458
                                 * @param                Stream                IOStream to use to parse file.
459
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
460
                                 */
461
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
462
#ifndef NCSJPC_LEAN_AND_MEAN
463
                                /** 
464
                                 * UnParse the component mapping box to the JP2 file.
465
                                 * @param                JP2File                JP2 file being parsed
466
                                 * @param                Stream                IOStream to use to parse file.
467
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
468
                                 */
469
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
470
#endif //!NCSJPC_LEAN_AND_MEAN
471
                };
472
                        /**
473
                         * CNCSJP2ChannelDefinitionBox class - the JP2 file channel definition box class.
474
                         * This box is optional.
475
                         * 
476
                         * @author       Simon Cope
477
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
478
                         */        
479
                class NCSJPC_EXPORT_ALL CNCSJP2ChannelDefinitionBox: public CNCSJP2Box {
480
                public:
481
                                /** Channel type */
482
                        typedef enum {
483
                                        /** Color value */
484
                                COLOR                        = 0,
485
                                        /** Opacity value */
486
                                OPACITY                        = 1,
487
                                        /** Premultiplied opacity value */
488
                                PREMUL_OPACITY        = 2,
489
                                        /** Channel type is unknown */
490
                                UNKNOWN                        = 0xffff
491
                        } Type;
492

    
493
                                /** Color channel this channel is associated with */
494
                        typedef enum {
495
                                        /** The entire image, eg RGBA */
496
                                WHOLE_IMAGE                = 0,
497
                                        /** Red channel */
498
                                R                                = 1,
499
                                        /** Green channel */
500
                                G                                = 2,
501
                                        /** Blue channel */
502
                                B                                = 3,
503
                                        /** Luminance/Greyscale channel */
504
                                Y                                = 1,
505
                                        /** Cb channel */
506
                                Cb                                = 2,
507
                                        /** Cr channel */
508
                                Cr                                = 3,
509
                                        /** No channel associated */
510
                                NONE                        = 0xffff
511
                        } Association;
512

    
513
                                /** A channel definition */
514
                        typedef struct {
515
                                        /** 0-based index of channel this definition is for */
516
                                UINT16                m_iChannel;
517
                                        /** Channel type */
518
                                Type                m_eType;
519
                                        /** Channel color component association */
520
                                Association        m_eAssociation;
521
                        } ChannelDefinition;
522

    
523
                                /** Box type */
524
                        static UINT32        sm_nTBox;
525

    
526
                                /** Number of definitions */
527
                        UINT16                m_nEntries;
528

    
529
                                /** Channel Definitiona*/
530
                        std::vector<ChannelDefinition>        m_Definitions;
531

    
532
                                /** Default constructor, initialises members */
533
                        CNCSJP2ChannelDefinitionBox();
534
                                /** Cirtual destructor */
535
                        virtual ~CNCSJP2ChannelDefinitionBox();
536

    
537
                                /** 
538
                                 * Get the ChannelDefinition for the specified channel index.
539
                                 * @param                iChannel        Channel index
540
                                 * @return      const ChannelDefinition*        ChannelDefinition, or NULL on failure.
541
                                 */
542
                        virtual const ChannelDefinition *GetDefinitition(UINT16 iChannel);
543
                                /** 
544
                                 * Update the extended length of the box prior to writing
545
                                 */
546
                        virtual void UpdateXLBox(void);
547
                                /** 
548
                                 * Parse the channel definition box from the JP2 file.
549
                                 * @param                JP2File                JP2 file being parsed
550
                                 * @param                Stream                IOStream to use to parse file.
551
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
552
                                 */
553
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
554
                                /** 
555
                                 * UnParse the channel definition box to the JP2 file.
556
                                 * @param                JP2File                JP2 file being parsed
557
                                 * @param                Stream                IOStream to use to parse file.
558
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
559
                                 */
560
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
561
                };
562
                        /**
563
                         * CNCSJP2ResolutionBox class - the JP2 file resolution box class.
564
                         * This box is optional.
565
                         * 
566
                         * @author       Simon Cope
567
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
568
                         */        
569
                class NCSJPC_EXPORT_ALL CNCSJP2ResolutionBox: public CNCSJP2SuperBox {
570
                public:
571
                                /**
572
                                 * CNCSJP2CaptureResolutionBox class - the JP2 file capture resolution box class.
573
                                 * This box is optional.
574
                                 *
575
                                 * Actual resolution is in grid points per meter, calculated as:
576
                                 *
577
                                 * Rc = (RcN / RcD) * 10^RcE
578
                                 * 
579
                                 * @author       Simon Cope
580
                                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
581
                                 */        
582
                        class NCSJPC_EXPORT_ALL CNCSJP2CaptureResolutionBox: public CNCSJP2Box {
583
                        public:
584
                                        /** Box type */
585
                                static UINT32        sm_nTBox;
586

    
587
                                        /** Vertical grid resolution numerator */
588
                                UINT16                m_nVRcN;
589
                                        /** Vertical grid resolution denominator */
590
                                UINT16                m_nVRcD;
591
                                        /** Vertical grid resolution exponent, two's compliment */
592
                                INT8                m_nVRcE;
593
                                        /** Horizontal grid resolution numerator */
594
                                UINT16                m_nHRcN;
595
                                        /** Horizontal grid resolution denominator */
596
                                UINT16                m_nHRcD;
597
                                        /** Horizontal grid resolution exponent, two's compliment */
598
                                INT8                m_nHRcE;
599

    
600
                                /** Default constructor, initialises members */
601
                                CNCSJP2CaptureResolutionBox();
602
                                        /** Cirtual destructor */
603
                                virtual ~CNCSJP2CaptureResolutionBox();
604

    
605

    
606
                                        /** 
607
                                         * Parse the capture resolution box from the JP2 file.
608
                                         * @param                JP2File                JP2 file being parsed
609
                                         * @param                Stream                IOStream to use to parse file.
610
                                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
611
                                         */
612
                                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
613
                                        /** 
614
                                         * UnParse the capture resolution box to the JP2 file.
615
                                         * @param                JP2File                JP2 file being parsed
616
                                         * @param                Stream                IOStream to use to parse file.
617
                                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
618
                                         */
619
                                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
620
                        };
621
                                /**
622
                                 * CNCSJP2DefaultDisplayResolutionBox class - the JP2 file default display resolution box class.
623
                                 * This box is optional.
624
                                 *
625
                                 * Actual resolution is in grid points per meter, calculated as:
626
                                 *
627
                                 * Rc = (RcN / RcD) * 10^RcE
628
                                 * 
629
                                 * @author       Simon Cope
630
                                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
631
                                 */        
632
                        class NCSJPC_EXPORT_ALL CNCSJP2DefaultDisplayResolutionBox: public CNCSJP2CaptureResolutionBox {
633
                        public:
634
                                        /** Box type */
635
                                static UINT32        sm_nTBox;
636

    
637
                                /** Default constructor, initialises members */
638
                                CNCSJP2DefaultDisplayResolutionBox();
639
                                        /** Cirtual destructor */
640
                                virtual ~CNCSJP2DefaultDisplayResolutionBox();
641
                        };
642
                                /** Box Type */
643
                        static UINT32        sm_nTBox;
644

    
645
                                /** CaptureResolutionBox within ResolutionBox */
646
                        CNCSJP2CaptureResolutionBox m_Capture;
647
                                /** DefaultDisplayResolutionBox within ResolutionBox */
648
                        CNCSJP2DefaultDisplayResolutionBox m_DefaultDisplay;
649

    
650
                                /** Default constructor, initialises members */
651
                        CNCSJP2ResolutionBox();
652
                                /** Virtual destructor */
653
                        virtual ~CNCSJP2ResolutionBox();
654
                };
655

    
656
                        /** Box Type */
657
                static UINT32        sm_nTBox;
658

    
659
                        /** ImageHeaderBox within HeaderBox */
660
                CNCSJP2ImageHeaderBox m_ImageHeader;
661
                        /** Optional BitsPerComponentBox within HeaderBox */
662
                CNCSJP2BitsPerComponentBox m_BitsPerComponent;
663
                        /** Optional ColorSpecificationBox within HeaderBox */
664
                CNCSJP2ColorSpecificationBox m_ColorSpecification; 
665
                        /** Optional PaletteBox within HeaderBox */
666
                CNCSJP2PaletteBox m_Palette;
667
                        /** OPtional ComponentMappingBox within HeaderBox */
668
                CNCSJP2ComponentMappingBox m_ComponentMapping;
669
                        /** Optional ChannelDefinitionBox within HeaderBox */
670
                CNCSJP2ChannelDefinitionBox m_ChannelDefinition;
671
                        /** OPtional ResolutionBox within HeaderBox */
672
                CNCSJP2ResolutionBox m_Resolution;
673

    
674
                        /** Default contructor, initialises members */
675
                CNCSJP2HeaderBox();
676
                        /** Virtual destructor */
677
                virtual ~CNCSJP2HeaderBox();
678
        };
679
                /**
680
                 * CNCSJP2ContiguousCodestreamBox class - the JP2 codestream box.  This box is always present.
681
                 * 
682
                 * @author       Simon Cope
683
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
684
                 */        
685
        class NCSJPC_EXPORT_ALL CNCSJP2ContiguousCodestreamBox: public CNCSJP2Box, public CNCSJPC {
686
        public:
687
                        /** Box type */ 
688
                static UINT32        sm_nTBox;
689

    
690
                        /** Default constructor, initialises members */
691
                CNCSJP2ContiguousCodestreamBox();
692
                        /** Virtual destructor */
693
                virtual ~CNCSJP2ContiguousCodestreamBox();
694

    
695
                        /** 
696
                         * Parse the JPC box from the JP2 file.
697
                         * @param                JP2File                JP2 file being parsed
698
                         * @param                Stream                IOStream to use to parse file.
699
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
700
                         */
701
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
702
                        /** 
703
                         * UnParse the JPC box to the JP2 file.
704
                         * @param                JP2File                JP2 file being parsed
705
                         * @param                Stream                IOStream to use to parse file.
706
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
707
                         */
708
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
709
        };
710
                /**
711
                 * CNCSJP2IntellectualPropertyBox class - the JP2 IPR box.  This box is optional.
712
                 * 
713
                 * @author       Simon Cope
714
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
715
                 */        
716
        class NCSJPC_EXPORT_ALL CNCSJP2IntellectualPropertyBox: public CNCSJP2Box {
717
        public:
718
                        /** Box type */ 
719
                static UINT32        sm_nTBox;
720

    
721
                        /** Default constructor, initialises members */
722
                CNCSJP2IntellectualPropertyBox();
723
                        /** Virtual destructor */
724
                virtual ~CNCSJP2IntellectualPropertyBox();
725
        };
726
                /**
727
                 * CNCSJP2XMLBox class - the JP2 XML box.  This box is optional, and there may be more than one.
728
                 * 
729
                 * @author       Simon Cope
730
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
731
                 */        
732
        class NCSJPC_EXPORT_ALL CNCSJP2XMLBox: public CNCSJP2Box {
733
        public:
734
                        /** Box type */ 
735
                static UINT32        sm_nTBox;
736

    
737
                        /** Default constructor, initialises members */
738
                CNCSJP2XMLBox();
739
                        /** Virtual destructor */
740
                virtual ~CNCSJP2XMLBox();
741
                        /** 
742
                         * Parse the XML box from the JP2 file.
743
                         * @param                JP2File                JP2 file being parsed
744
                         * @param                Stream                IOStream to use to parse file.
745
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
746
                         */
747
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
748
                        /** 
749
                         * UnParse the XML box to the JP2 file.
750
                         * @param                JP2File                JP2 file being parsed
751
                         * @param                Stream                IOStream to use to parse file.
752
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
753
                         */
754
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
755
        };
756
                /**
757
                 * CNCSJP2UUIDBox class - the JP2 UUID box.  This box is optional, and there may be more than one.
758
                 * 
759
                 * @author       Simon Cope
760
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
761
                 */        
762
        class NCSJPC_EXPORT_ALL CNCSJP2UUIDBox: public CNCSJP2Box {
763
        public:
764
                        /** Box type */ 
765
                static UINT32        sm_nTBox;
766
                        /** UUID */
767
                NCSUUID        m_UUID;
768
                        /** UUID Box data */
769
                void *m_pData;
770
                        /** UUID Box data Length*/
771
                INT32 m_nLength;
772

    
773
                        /** Default constructor, initialises members */
774
                CNCSJP2UUIDBox();
775
                        /** Virtual destructor */
776
                virtual ~CNCSJP2UUIDBox();
777

    
778
                        /** 
779
                         * Parse the UUID box from the JP2 file.
780
                         * @param                JP2File                JP2 file being parsed
781
                         * @param                Stream                IOStream to use to parse file.
782
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
783
                         */
784
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
785
                        /** 
786
                         * UnParse the UUID box to the JP2 file.
787
                         * @param                JP2File                JP2 file being parsed
788
                         * @param                Stream                IOStream to use to parse file.
789
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
790
                         */
791
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
792
        };
793
                /**
794
                 * CNCSJP2UUIDInfoBox class - the JP2 UUIDInfo box.  This box is optional, and there may be more than one.
795
                 * 
796
                 * @author       Simon Cope
797
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
798
                 */        
799
        class NCSJPC_EXPORT_ALL CNCSJP2UUIDInfoBox: public CNCSJP2SuperBox {
800
        public:
801
                        /**
802
                         * CNCSJP2UUIDListBox class - the JP2 file UUIDList box class.
803
                         * This box is required within a UUIDInfo box.
804
                         * 
805
                         * @author       Simon Cope
806
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
807
                         */        
808
                class NCSJPC_EXPORT_ALL CNCSJP2UUIDListBox: public CNCSJP2Box {
809
                public:
810
                        
811
                                /** Box type */
812
                        static UINT32        sm_nTBox;
813
                                /** Number of entries */
814
                        UINT16                m_nEntries;
815
                                /** UUIDs */
816
                        std::vector<NCSUUID> m_UUIDs;
817
                        
818
                                /** Default constructor, initialises members */
819
                        CNCSJP2UUIDListBox();
820
                                /** Virtual destructor */
821
                        virtual ~CNCSJP2UUIDListBox();
822

    
823
                                /** 
824
                                 * Parse the UUID List box from the JP2 file.
825
                                 * @param                JP2File                JP2 file being parsed
826
                                 * @param                Stream                IOStream to use to parse file.
827
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
828
                                 */
829
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
830
                                /**
831
                                 * UnParse the UUID list box to the JP2 file.
832
                                 * @param                JP2File                JP2 file being parsed
833
                                 * @param                Stream                IOStream to use to parse file.
834
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
835
                                 */
836
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
837
                };
838
                        /**
839
                         * CNCSJP2DataEntryURLBox class - the JP2 file DateEntryURL box class.
840
                         * This box is required within a UUIDInfo box.
841
                         * 
842
                         * @author       Simon Cope
843
                         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
844
                         */        
845
                class NCSJPC_EXPORT_ALL CNCSJP2DataEntryURLBox: public CNCSJP2Box {
846
                public:
847
                        
848
                                /** Box type */
849
                        static UINT32        sm_nTBox;
850

    
851
                                /** Version */
852
                        UINT8                m_nVersion;
853
                                /** Flags */
854
                        UINT8                m_Flags[3];
855
                                /** Location URL */
856
                        UINT8                *m_pLocation;
857

    
858
                                /** Default constructor, initialises members */
859
                        CNCSJP2DataEntryURLBox();
860
                                /** Cirtual destructor */
861
                        virtual ~CNCSJP2DataEntryURLBox();
862

    
863
                                /** 
864
                                 * Parse the Data Entry URL box from the JP2 file.
865
                                 * @param                JP2File                JP2 file being parsed
866
                                 * @param                Stream                IOStream to use to parse file.
867
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
868
                                 */
869
                        virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
870
                                /**
871
                                 * UnParse the Data Entry URL box to the JP2 file.
872
                                 * @param                JP2File                JP2 file being parsed
873
                                 * @param                Stream                IOStream to use to parse file.
874
                                 * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
875
                                 */
876
                        virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
877
                };
878
                        /** Box Type */
879
                static UINT32        sm_nTBox;
880
                                /** UUIDListBox within UUIDInfo */
881
                CNCSJP2UUIDListBox m_List;
882
                                /** DataEntryURLBox within the UUIDInfo */
883
                CNCSJP2DataEntryURLBox m_DE;
884

    
885
                                /** Default constructor, initialises members */
886
                CNCSJP2UUIDInfoBox();
887
                        /** Virtual destructor */
888
                virtual ~CNCSJP2UUIDInfoBox();
889
        };
890
                /**
891
                 * CNCSJP2PCSBox class - the JP2 PCS GeoKey box.  This box is optional
892
                 * This implements a quick and dirty GeoTIFF tag parser rather than rely on a 3rd party 
893
                 * TIFF implementation such as TIFFlib.  Alternatively, an application can read the box contents 
894
                 * directly to implement more reobust/thorough parsing of the PCS tag values.
895
                 * 
896
                 * @author       Simon Cope & Tom Lynch
897
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
898
                 */        
899
        class NCSJPC_EXPORT_ALL CNCSJP2PCSBox: public CNCSJP2UUIDBox {
900
        public:
901
                        /** Relevent TIFF tag names */
902
                typedef enum {
903
                                /** Model Pixel Scale */
904
                        ModelPixelScale                = 0x830e,
905
                                /** Model Tie Point */
906
                        ModelTiePoint                = 0x8482,
907
                                /** Model Transformantion */
908
                        ModelTransformation = 0x85d8,
909
                                /** GetKey Directory */
910
                        GeoKeyDirectory                = 0x87af,
911
                                /** GeoKey Double Parameters */
912
                        GeoDoubleParams                = 0x87b0,
913
                                /** GetKey ASCII Parameters */
914
                        GeoASCIIParams                = 0x87b1,
915
                } TIFFTagNames;
916

    
917
                        /** TIFF Tag structure */
918
                typedef struct {
919
                                /** Tag value */
920
                        UINT16 Tag;
921
                                /** Tag type */
922
                        UINT16 Type;
923
                                /** Number of values */
924
                        UINT32 Count;
925
                                /** IFD offset to values */
926
                        UINT32 Offset;
927
                                /** Vector of the parsed double values */
928
                        std::vector<double>        Values;
929
                } TIFFTag;
930

    
931
                        /** GeoKey value union */
932
                typedef union {
933
                                /** An integer value - u16 */
934
                        UINT16                nValue;
935
                                /** A double value */
936
                        double                dValue;
937
                                /** A string value */
938
                        char                *pValue;
939
                } GeoKeyValue;
940

    
941
                        /** GetKey type enum = u16, double, ASCII */
942
                typedef enum {
943
                                /** An integer value */
944
                        GKT_SHORT        = 0,
945
                                /** A double value */
946
                        GKT_DOUBLE        = GeoDoubleParams,
947
                                /** A string value */
948
                        GKT_ASCII   = GeoASCIIParams
949
                } GeoKeyType;
950

    
951
                        /** An GeoKey value */
952
                typedef struct {
953
                                /** The Key ID */
954
                        UINT16 KeyID;
955
                                /** The Key Type */
956
                        GeoKeyType Type;
957
                                /** Number of values */
958
                        UINT16 Count;
959

    
960
                                /** The value */
961
                        GeoKeyValue v;
962
                } GeoKey;
963

    
964
                        /** UUID for the PCS box */
965
                static NCSUUID sm_UUID;
966

    
967
                        /** Default constructor, initialises members */
968
                CNCSJP2PCSBox();
969
                        /** Virtual destructor */
970
                virtual ~CNCSJP2PCSBox();
971

    
972
                        /** Update the extended length for the box before writing */
973
                virtual void UpdateXLBox(void);
974
                        /** 
975
                         * Parse the PCS GeoKey box from the JP2 file.
976
                         * @param                JP2File                JP2 file being parsed
977
                         * @param                Stream                IOStream to use to parse file.
978
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
979
                         */
980
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
981
                        /** 
982
                         * UnParse the PCS GeoKey box to the JP2 file.
983
                         * @param                JP2File                JP2 file being parsed
984
                         * @param                Stream                IOStream to use to parse file.
985
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
986
                         */
987
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
988
                        /** 
989
                         * get an NCSFileViewFileInfoEx structure equivalent of the parsed PCS box.
990
                         * @param                FileInfo        Info struct to fill in
991
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
992
                         */
993
                CNCSError GetFileInfo(NCSFileViewFileInfoEx &FileInfo);
994
                        /** 
995
                         * Setup the PCS box from an NCSFileViewFileInfoEx structure prior to writing out
996
                         * @param                FileInfo        Info struct to create PCS box from
997
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
998
                         */
999
                CNCSError SetFileInfo(NCSFileViewFileInfoEx &FileInfo);
1000
                        /**
1001
                         * Set the precision used in processing registration by the PCS box.
1002
                         * @param                fPrecision        The value below which to discard registration values
1003
                         */
1004
                static void SetPrecision(IEEE4 fPrecision);
1005
        private:
1006
                        /** 
1007
                         * get a tag from it's name 
1008
                         * @param                eTag                Tag name to get tag for
1009
                         * @return      TIFFTag*        TIFF Tag, or NULL on failure.
1010
                         */
1011
                TIFFTag *GetTag(TIFFTagNames eTag);
1012
                        /** 
1013
                         * get a GetKey from it's key name
1014
                         * @param                Key                        GetKey name to get
1015
                         * @return      GeoKey*                GeoKey, or NULL on failure.
1016
                         */
1017
                GeoKey *GetKey(UINT16 Key);
1018
                        /** 
1019
                         * Process the GeoTIFF Info 
1020
                         * @return      CNCSError        NCS_SUCCESS, or error on failure
1021
                         */
1022
                CNCSError ProcessGeoTIFFInfo();
1023
                        /** 
1024
                         * Format the GetTIFF Info
1025
                         * @param                pBuf                Info buffer
1026
                         * @return      CNCSError        NCS_SUCCESS, or error on failure\
1027
                         */
1028
                CNCSError FormatGeoTIFFInfo(UINT8 *pBuf);
1029

    
1030
                        /** PCSFileInfo */
1031
                NCSFileViewFileInfoEx m_PCSFileInfo;
1032
                        /** Vector of the TIFF Tags */
1033
                std::vector<TIFFTag> m_TIFFTags;
1034
                        /** Vector of the GeoKeys */
1035
                std::vector<GeoKey> m_GeoKeys;
1036
                        /** Actual GeoTIFF box length - FIXME is this required? */
1037
                UINT32 m_nGeoTIFFBoxLength;
1038
                        /** Geodata precision */
1039
                static IEEE4 sm_fGeodataPrecisionEpsilon;
1040
        };
1041
                /**
1042
                 * CNCSJP2PCSBox class - the JP2 GML box.  This box is optional
1043
                 * 
1044
                 * @author       Simon Cope
1045
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
1046
                 */        
1047
        class NCSJPC_EXPORT_ALL CNCSJP2GMLGeoLocationBox: public CNCSJP2XMLBox {
1048
        public:
1049
                        /** Default constructor, initialises members */
1050
                CNCSJP2GMLGeoLocationBox();
1051
                        /** Virtual destructor */
1052
                virtual ~CNCSJP2GMLGeoLocationBox();
1053

    
1054
                        /** Update the extended length of the box prior to writing */
1055
                virtual void UpdateXLBox(void);
1056
                        /** 
1057
                         * Parse the GML GeoLocation box from the JP2 file.
1058
                         * @param                JP2File                JP2 file being parsed
1059
                         * @param                Stream                IOStream to use to parse file.
1060
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
1061
                         */
1062
                virtual CNCSError Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
1063
                        /** 
1064
                         * UnParse the GML GeoLocation box to the JP2 file.
1065
                         * @param                JP2File                JP2 file being parsed
1066
                         * @param                Stream                IOStream to use to parse file.
1067
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
1068
                         */
1069
                virtual CNCSError UnParse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream);
1070

    
1071
                        /** 
1072
                         * get an NCSFileViewFileInfoEx structure equivalent of the parsed GML box.
1073
                         * @param                FileInfo        Info struct to fill in
1074
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
1075
                         */
1076
                CNCSError GetFileInfo(NCSFileViewFileInfoEx &FileInfo);
1077
                        /** 
1078
                         * Setup the GML box from an NCSFileViewFileInfoEx structure prior to writing out
1079
                         * @param                FileInfo        Info struct to create PCS box from
1080
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
1081
                         */
1082
                CNCSError SetFileInfo(NCSFileViewFileInfoEx &FileInfo);
1083
        private:
1084
                        /** GML FileInfo structure */
1085
                NCSFileViewFileInfoEx        m_GMLFileInfo;
1086
                        /** 
1087
                         * Setup the GML box prior to writing out
1088
                         * @param                pBuf                Buffer to format XMl into 
1089
                         * @param                nBufLen                Buffer length
1090
                         * @return      CNCSError        NCS_SUCCESS, or Error code on failure.
1091
                         */                        
1092
                CNCSError FormatXML(char *pBuf, UINT32 nBufLen);
1093
        };
1094
                /** ECW FileInfo Structure */
1095
        NCSFileViewFileInfoEx m_FileInfo;
1096
                /** Number of refs to this file */
1097
        INT32                                m_nRefs;
1098

    
1099
                /** SignatureBox within JP2File */
1100
        CNCSJP2SignatureBox                m_Signature;
1101
                /** FileTypeBox within JP2File */
1102
        CNCSJP2FileTypeBox                m_FileType;
1103
                /** HeaderBox within JP2File */
1104
        CNCSJP2HeaderBox                m_Header;
1105
                /** ContiguousCodestreamBox ie "JPC" within JP2File */
1106
        CNCSJP2ContiguousCodestreamBox        m_Codestream;
1107
                /** IntellectualPropertyBox within JP2File */
1108
        CNCSJP2IntellectualPropertyBox m_IPR;
1109
                /** GML geolocation box */
1110
        CNCSJP2GMLGeoLocationBox m_GML;
1111
                /** PCS Geokey box */
1112
        CNCSJP2PCSBox m_PCS;
1113

    
1114
                /** IOStream */
1115
        CNCSJPCIOStream *m_pStream;
1116
                /** Did we allocate the stream? */
1117
        bool        m_bOurStream;
1118

    
1119
                /** Component index for each output channel - 1:1 unless a palette is present */
1120
        std::vector<UINT16>        m_ChannelComponentIndex;
1121

    
1122
                /** Default constructor, initialises members */
1123
        CNCSJP2File();
1124
                /** Virtual Destructor */
1125
        virtual ~CNCSJP2File();
1126

    
1127
#if defined(_WCHAR_T_DEFINED)||defined(_WCHAR_T)
1128
                /** 
1129
                 * Open the JP2 file for Parsing/UnParsing.
1130
                 * @param                pFileName        Full path name of JP2 file to open
1131
                 * @param                bWrite                If true, opens for writing.
1132
                 * @return      CNCSError        NCS_SUCCESS or error code on failuer.
1133
                 */
1134
        virtual CNCSError Open(wchar_t *pFileName, bool bWrite = false);
1135
#endif
1136
                /** 
1137
                 * Open the JP2 file for Parsing/UnParsing.
1138
                 * @param                pFileName        Full path name of JP2 file to open
1139
                 * @param                bWrite                If true, opens for writing.
1140
                 * @return      CNCSError        NCS_SUCCESS or error code on failuer.
1141
                 */
1142
        virtual CNCSError Open(char *pFileName, bool bWrite = false);
1143
                /** 
1144
                 * Open the JP2 file from the specified stream.
1145
                 * @param                Stream                Stream of JP2 file to open
1146
                 * @return      CNCSError        NCS_SUCCESS or error code on failuer.
1147
                 */
1148
        virtual CNCSError Open(CNCSJPCIOStream &Stream);
1149
                /** 
1150
                 * Close the JP2 file.
1151
                 * @param                bFreeCache        Free the cache & delete file object if last close
1152
                 * @return      CNCSError        NCS_SUCCESS or error code on failuer.
1153
                 */
1154
        virtual CNCSError Close(bool bFreeCache = false);
1155

    
1156
                /** 
1157
                 * Get X0 of this node.
1158
                 * @return      INT32                Coordinate value.
1159
                 */
1160
        virtual INT32 GetX0();
1161
                /** 
1162
                 * Get Y0 of this node.
1163
                 * @return      INT32                Coordinate value.
1164
                 */
1165
        virtual INT32 GetY0();
1166
                /** 
1167
                 * Get X1 of this node.
1168
                 * @return      INT32                Coordinate value.
1169
                 */
1170
        virtual INT32 GetX1();
1171
                /** 
1172
                 * Get Y1 of this node.
1173
                 * @return      INT32                Coordinate value.
1174
                 */
1175
        virtual INT32 GetY1();
1176

    
1177
                /** 
1178
                 * Get the memory image of the file.
1179
                 * @param                pLength                Returned length of image
1180
                 * @return      void *                NCSMalloc()'d pointer to image.
1181
                 */
1182
        void *GetMemImage(UINT32 &nLength);
1183
                /** 
1184
                 * Get length of a packet in the file.
1185
                 * @param                nPacket                Absolute Packet number to determine length for
1186
                 * @return      UINT32                Packet length or 0 on failure.
1187
                 */
1188
        UINT32 GetPacketLength(NCSBlockId nPacket);
1189
                /** 
1190
                 * Read a packet from the file.
1191
                 * @param                nPacket                Absolute Packet number to determine length for
1192
                 * @param                pLength                Returned length of packet (header+data)
1193
                 * @return      void *                NCSMalloc()'d pointer to read packet (header+data).
1194
                 */
1195
        void *GetPacket(NCSBlockId nPacket, UINT32 &nLength);
1196
                /** 
1197
                 * Get number of a packet in the file.
1198
                 * @return      UINT32                Number of Packets or 0 on failure.
1199
                 */
1200
        UINT32 GetNrPackets();
1201

    
1202
                /** 
1203
                 * Get a pointer to a UUID box bsed on the specified UUID.  Iterate via the pLast paramter.
1204
                 * @param                uuid                UUID to find UUID box for
1205
                 * @param                pLast                Pointer to last returned UUID box (or NULL on first call), used to iterate through multiple UUID boxes with the same UUID
1206
                 * @return      CNCSJP2UUIDBox*                Pointer to UUID Box.
1207
                 */
1208
        CNCSJP2UUIDBox *GetUUIDBox(NCSUUID uuid, CNCSJP2UUIDBox *pLast = NULL);
1209
                /** 
1210
                 * Get a pointer to an XML box.  Iterate via the pLast paramter.
1211
                 * @param                pLast                Pointer to last returned XML box (or NULL on first call), used to iterate through multiple XML boxes
1212
                 * @return      CNCSJP2XMLBox*                Pointer to XML Box.
1213
                 */
1214
        CNCSJP2XMLBox *GetXMLBox(CNCSJP2XMLBox *pLast = NULL);
1215

    
1216
                /** 
1217
                 * Set the compression parameters (dimensions, registration, bitdepth etc).
1218
                 * @param                Info                FileInfo structure
1219
                 * @return      CNCSError        NCS_SUCCESS, or error on failure 
1220
                 */
1221
        CNCSError SetCompress(NCSFileViewFileInfoEx &Info);
1222
                /** 
1223
                 * Write the next line in BIL format into the file.
1224
                 * @param                nCtx                                Unique Context ID
1225
                 * @param                pSrc                                Source buffer
1226
                 * @param                iComponent                        Component index
1227
                 * @return      bool                                true on success, else false.
1228
                 */
1229
        bool WriteLine(ContextID nCtx, CNCSJPCBuffer *pSrc, UINT16 iComponent);
1230
                /** 
1231
                 * Get normal Node Width.
1232
                 * @return      INT32                Un-clipped Width of codeblocks.
1233
                 */
1234
        virtual UINT32 GetNodeWidth(UINT16 iComponent = 0);
1235
                /** 
1236
                 * Get normal Node Height.
1237
                 * @return      INT32                Un-clipped height of codeblocks.
1238
                 */
1239
        virtual UINT32 GetNodeHeight(UINT16 iComponent = 0);
1240
                /** 
1241
                 * Get number of nodes wide.
1242
                 * @return      INT32                Nr of codeblocks across.
1243
                 */
1244
        virtual UINT32 GetNumNodesWide(UINT16 iComponent = 0);
1245
                /** 
1246
                 * Get number of nodes high.
1247
                 * @return      INT32                Nr of codeblocks high.
1248
                 */
1249
        virtual UINT32 GetNumNodesHigh(UINT16 iComponent = 0);
1250
                /** 
1251
                 * Get pointer to specific node.
1252
                 * @param                UINT32                Node nr
1253
                 * @return      CNCSJPCNode * Ptr to node.
1254
                 */
1255
        virtual CNCSJPCNode *GetNodePtr(UINT32 nNode, UINT16 iComponent = 0);
1256

    
1257
                /** 
1258
                 * Enable unlimited compression - NOTE YOU MUST COMPLY WITH THE EULA.
1259
                 */
1260
        static void SetKeySize(void);
1261
                /** 
1262
                 * Purge any unused buffers, codeblocks etc if memory useage exceeds acceptable limites
1263
                 */
1264
        static void Purge();
1265
private:
1266
        friend class CNCSJP2FileView;
1267
        friend class CNCSJPCGlobalLock;
1268

    
1269
                /** Static list of files */
1270
        static CNCSJP2FileVector sm_Files;
1271
                /** 
1272
                 * Close the JP2 file
1273
                 * @param                bFreeCache                Free the cached JP2 file data.
1274
                 * @param                bFromDestructor        Being called from destructor.
1275
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
1276
                 */
1277
        virtual CNCSError Close ( bool bFreeCache, bool bFromDestructor);
1278
        //[03]
1279
                /**
1280
                 * Shutdown the resources associated with CNCSJP2File objects.
1281
                 * Called only by CNCSJP2FileView::Shutdown().
1282
                 */
1283
        static void Shutdown();
1284

    
1285
#if defined(_WCHAR_T_DEFINED)||defined(_WCHAR_T)
1286
                /** 
1287
                 * Static Open method - returns existing instance if already open
1288
                 * @param                ppFile                        Returned CNCSJP2File instance pointer.
1289
                 * @param                pURLPath                Local/remote path/URL.
1290
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
1291
                 */
1292
        static CNCSError sOpen(CNCSJP2File **ppFile, wchar_t *pURLPath);
1293
#else
1294
                /** 
1295
                 * Static Open method - returns existing instance if already open
1296
                 * @param                ppFile                        Returned CNCSJP2File instance pointer.
1297
                 * @param                pURLPath                Local/remote path/URL.
1298
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
1299
                 */
1300
        static CNCSError sOpen(CNCSJP2File **ppFile, char *pURLPath);
1301
#endif
1302
                /** 
1303
                 * Static Open method - returns existing instance if already open
1304
                 * @param                ppFile                        Returned CNCSJP2File instance pointer.
1305
                 * @param                pStream                        Stream to open file from.
1306
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
1307
                 */
1308
        static CNCSError sOpen(CNCSJP2File **ppFile, CNCSJPCIOStream *pStream);
1309

    
1310
                /** 
1311
                 * Add a JP2 file box to a memory image
1312
                 * @param                pImage                        Existing memory image to append box to.
1313
                 * @param                pLength                        Current/returned length of memory image.
1314
                 * @param                pBox                        JP2 Box to append to memory image.
1315
                 * @return      void*                        Memory image with appended box, else NULL on error.
1316
                 */
1317
        void *GetMemImage_AddBox(void *pImage, UINT32 *pLength, CNCSJP2Box *pBox);
1318
                /** 
1319
                 * Add a JPC codestream marker to a memory image
1320
                 * @param                pImage                        Existing memory image to append box to.
1321
                 * @param                pLength                        Current/returned length of memory image.
1322
                 * @param                pMarker                        JPC codestream marker to append to memory image.
1323
                 * @return      void*                        Memory image with appended box, else NULL on error.
1324
                 */
1325
        void *GetMemImage_AddMarker(void *pImage, UINT32 *pLength, CNCSJPCMarker *pMarker);
1326
                /** 
1327
                 * Add the JPC codestream to a memory image (excluding packets)
1328
                 * @param                pImage                        Existing memory image to append box to.
1329
                 * @param                pLength                        Current/returned length of memory image.
1330
                 * @return      void*                        Memory image with appended box, else NULL on error.
1331
                 */
1332
        void *GetMemImage_AddCodestream(void *pImage, UINT32 *pLength);
1333
                /** 
1334
                 * Is the JP2 SDK currently over it's memory budget
1335
                 * @return      bool                        true if over budget, else false 
1336
                 */
1337
        static bool OverBudget();
1338

    
1339
                /** Next line to read/write */
1340
        INT32 m_nNextLine;
1341

    
1342
                /** Compression profile on writing */
1343
        CNCSJPC::Profile        m_eCompressionProfile;
1344
                /** Compression resolution levels on writing */
1345
        UINT8                                m_nCompressionLevels;
1346
                /** Compression quality layers on writing */
1347
        UINT16                                m_nCompressionLayers;
1348
                /** Compression precinct width on writing */
1349
        UINT32                                m_nCompressionPrecinctWidth;
1350
                /** Compression precinct height on writing */
1351
        UINT32                                m_nCompressionPrecinctHeight;
1352
                /** Compression tile width on writing */
1353
        UINT32                                m_nCompressionTileWidth;
1354
                /** Compression tile height on writing */
1355
        UINT32                                m_nCompressionTileHeight;
1356
                /** Compression output SOP on writing */
1357
        bool                                m_bCompressionIncludeSOP;
1358
                /** Compression output EPH on writing */
1359
        bool                                m_bCompressionIncludeEPH;
1360
                /** Compression output JPC only on writing (no JP2 wrapper output) */
1361
        bool                                m_bCodestreamOnly;
1362
                /** Compression progression order on writing (LRCP, RLCP, RPCL only) */
1363
        CNCSJPCProgressionOrderType::Type        m_eCompressionOrder;
1364
                /** # of layers to decompress on reading - FIXME unimplemented */
1365
        UINT16                                m_nDecompressionLayers;
1366
                /** GeoData usage priority */
1367
        static UINT32                sm_nGeodataUsage;
1368
                /** Unlimited compression key - see SetKeySize() */
1369
        static UINT32                sm_nKeySize;
1370
};
1371

    
1372
        /** 
1373
         * Initialiase a FileInfo structure
1374
         * @param                pDst                        File info to initialise.
1375
         */
1376
extern "C" void NCSInitFileInfoEx(NCSFileViewFileInfoEx *pDst);
1377
        /** 
1378
         * Free a FileInfo structure
1379
         * @param                pDst                        File info to free.
1380
         */
1381
extern "C" void NCSFreeFileInfoEx(NCSFileViewFileInfoEx *pDst);
1382
        /** 
1383
         * Copy a FileInfo structure
1384
         * @param                pDst                        File info to copy to.
1385
         * @param                pSrc                        File info to copy from.
1386
         */
1387
extern "C" void NCSCopyFileInfoEx(NCSFileViewFileInfoEx *pDst, NCSFileViewFileInfoEx *pSrc);
1388
        /** 
1389
         * check if a FileInfo structure is georeferenced
1390
         * @param                pInfo                        File info to test.
1391
         * @return                BOOLEAN                        TRUE if FileInfo is georeferences (Non RAW/RAW).
1392
         */
1393
extern "C" BOOLEAN NCSIsFileInfoExGeoreferenced(NCSFileViewFileInfoEx *pInfo);
1394
        /** 
1395
         * Standardize a FileInfo structure
1396
         * @param                pInfo                        File info to standardize.
1397
         */
1398
extern "C" void        NCSStandardizeFileInfoEx(NCSFileViewFileInfoEx *pInfo);
1399
        /** 
1400
         * Set the GDT library path (EPSG<>PCS mapping)
1401
         * @param                szPath                        File path to GDT library DAt files
1402
         */
1403

    
1404
#endif // !NCSJP2FILE_H