Statistics
| Revision:

svn-gvsig-desktop / branches / v05 / libraries / libjni-ecw / include / NCSJP2FileView.h @ 34016

History | View | Annotate | Download (30.6 KB)

1
/********************************************************
2
** Copyright 2003 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/NCSJP2FileView.h $
15
** CREATED:  14/03/2003 3:27:34 PM
16
** AUTHOR:   Simon Cope
17
** PURPOSE:  CNCSJP2FileView class header
18
** EDITS:    [xx] ddMmmyy NAME COMMENTS
19
**                         [01] 07Sep04 tfl  Added support for configuring georeferencing use
20
**                         [02] 11Nov04 tfl  Added rotation member to ensure rotation data persists
21
 *******************************************************/
22

    
23
#ifndef NCSJP2FILEVIEW_H
24
#define NCSJP2FILEVIEW_H
25

    
26
#ifndef NCSJPCDEFS_H
27
#include "NCSJPCDefs.h"
28
#endif // NCSJPCDEFS_H
29

    
30
#ifdef NCSJPC_ECW_SUPPORT
31
#ifndef NCSECWCLIENT_H
32
#include "NCSECWClient.h"
33
#endif // NCSECWCLIENT_H
34
#endif // NCSJPC_ECW_SUPPORT
35

    
36
#ifndef NCSMUTEX_H
37
#include "NCSMutex.h"
38
#endif // NCSMUTEX_H
39
#ifndef NCSJPCBUFFER_H
40
#include "NCSJPCBuffer.h"
41
#endif // NCSJPCBUFFER_H
42
#ifndef NCSJPCEVENT_H
43
#include "NCSJPCEvent.h"
44
#endif // NCSJPCEVENT_H
45
#ifndef NCSJP2BOX_H
46
#include "NCSJP2Box.h"
47
#endif // NCSJP2BOX_H
48

    
49
/**
50
 * CNCSJP2FileView class - the JP2 file view class.
51
 * 
52
 * @author       Simon Cope
53
 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
54
 */
55
class NCSJPC_EXPORT_ALL CNCSJP2FileView: private CNCSThread {
56
public:
57
                /** Statistics enum */
58
        typedef enum {
59
                        /** Global T1 Decoder US total */
60
                ST_CODEBLOCK_DECODER_US                        = 0,        
61
                        /** Global T1 Decoder samples total */
62
                ST_CODEBLOCK_DECODER_SAMPLES        = 1,        
63
                        /** Global Codeblock read US total */
64
                ST_CODEBLOCK_READ_US                        = 2,        
65
                        /** Global Codeblock read samples total */
66
                ST_CODEBLOCK_READ_SAMPLES                = 3,
67
                        /** DC Shift US total */
68
                ST_DCSHIFT_US                                        = 10,
69
                        /** MCT US total */
70
                ST_MCT_US                                                = 20,
71
                        /** DWT ROW US total */
72
                ST_DWT_ROW_US                                        = 30,
73
                        /** DWT COL US total */
74
                ST_DWT_COL_US                                        = 31,
75
                        /** DWT Samples total */
76
                ST_DWT_SAMPLES                                        = 32,
77
                        /** SetView US total */
78
                ST_VIEW_SETVIEW_US                                = 40,
79
                        /** ReadLine US total */
80
                ST_VIEW_READLINE_US                                = 41,
81
                        /** Resample US total */
82
                ST_VIEW_RESAMPLE_US                                = 42,
83
                        /** Raw IO Read US total */
84
                ST_IO_READ_US                                        = 50,
85
                        /** Raw IO Write US total */
86
                ST_IO_WRITE_US                                        = 51,
87
                        /** Raw IO Seek US total */
88
                ST_IO_SEEK_US                                        = 52,
89
                        /** Global Buffer Alloc US total */
90
                ST_BUF_ALLOC_US                                        = 60,        
91
                        /** Global Buffer Free US total */
92
                ST_BUF_FREE_US                                        = 61,        
93
                        /** Global Buffer bytes allocated total */
94
                ST_BUF_ALLOC_BYTES                                = 62,        
95
                        /** Global Buffer Copy US total */
96
                ST_BUF_COPY_US                                        = 63,        
97
                        /** Global Buffer bytes copied total */
98
                ST_BUF_COPY_BYTES                                = 64,        
99
                        /** Global Buffer Clear US total */
100
                ST_BUF_CLEAR_US                                        = 65,        
101
                        /** Global Buffer bytes cleared total */
102
                ST_BUF_CLEAR_BYTES                                = 66,        
103
                        /** File Compression Total MS */
104
                ST_COMPRESS_TOTAL_MS                        = 80,        
105
                        /** File Compression output size bytes total */
106
                ST_COMPRESS_OUTPUT_SIZE                        = 81        
107
        } Statistic;
108

    
109
                /** JP2FileView parameters */
110
        typedef enum {
111
                        /** Default, Baseline Profile 0 */
112
                JP2_COMPRESS_PROFILE_BASELINE_0                = 0, 
113
                        /** Baseline Profile 1 */
114
                JP2_COMPRESS_PROFILE_BASELINE_1                = 1, 
115
                        /** Profile 2 (unrestricted) */
116
                JP2_COMPRESS_PROFILE_BASELINE_2                = 2, 
117
                        /** NITF NSIF BIIF NPJE Profile */
118
                JP2_COMPRESS_PROFILE_NITF_BIIF_NPJE = 3, 
119
                        /** NITF NSIF BIIF EPJE Profile */
120
                JP2_COMPRESS_PROFILE_NITF_BIIF_EPJE = 4, 
121

    
122
                        /** Resolution Levels.  UINT32 - Calculated so r=0 <= 64x64 */
123
                JP2_COMPRESS_LEVELS                                        = 20, 
124
                        /** Quality Layers.  UINT32 - Default 1 */
125
                JP2_COMPRESS_LAYERS                                        = 21, 
126
                        /** Precinct Width.  UINT32 - Default 64 or larger depending on file size */
127
                JP2_COMPRESS_PRECINCT_WIDTH                        = 22, 
128
                        /** Precinct Height.  UINT32 - Default 64 or larger depending on file size */
129
                JP2_COMPRESS_PRECINCT_HEIGHT                = 23, 
130
                        /** Tile Width.  UINT32 - Default to image width given in SetFileInfo() */
131
                JP2_COMPRESS_TILE_WIDTH                                = 24, 
132
                        /** Tile Height.  UINT32 - Default to image height given in SetFileInfo() */
133
                JP2_COMPRESS_TILE_HEIGHT                        = 25, 
134
                        /** Output SOP.  bool - Default false */
135
                JP2_COMPRESS_INCLUDE_SOP                        = 26, 
136
                        /** Output EPH.  bool - Default true */
137
                JP2_COMPRESS_INCLUDE_EPH                        = 27, 
138
                        /** bool - Only write JPC codestream, no JP2 file wrapper */
139
                JP2_COMPRESS_CODESTREAM_ONLY                = 28, 
140
                        /** bool - Enable/disable compression threaded read - Default true */
141
                JP2_COMPRESS_MT_READ                                = 29, 
142

    
143
                        /** LRCP progression */
144
                JP2_COMPRESS_PROGRESSION_LRCP                = 30, 
145
                        /** RLCP progression */
146
                JP2_COMPRESS_PROGRESSION_RLCP                = 31, 
147
                        /** v3.1 SDK Default: RPCL progression */
148
                JP2_COMPRESS_PROGRESSION_RPCL                = 32, 
149

    
150
                        /** Control the precedence of georeferencing metadata from world files and embedded GML XML boxes and PCS UUID boxes */
151
                JP2_GEODATA_USAGE                                        = 40, 
152
                        /** Control the precision employed by registration info (rounding errors can cause ridiculous values) */
153
                JP2_GEODATA_PRECISION_EPSILON       = 41,
154
                        /** UINT32 - Defaults to all */
155
                JP2_DECOMPRESS_LAYERS                                = 100, 
156
                        /** IEEE4 - defaults to 0.0, range 0.0 <= r < 1.0 */
157
                JPC_DECOMPRESS_RECONSTRUCTION_PARAMETER = 101        
158
        } Parameter;
159
                /**
160
                 * CNCSJP2FileViewVector class - vector of current JP2FileView instances.
161
                 * Also deals with progressive mode.
162
                 * 
163
                 * @author       Simon Cope
164
                 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
165
                 */
166
        class NCSJPC_EXPORT_ALL CNCSJP2FileViewVector: public std::vector<CNCSJP2FileView *>, public CNCSThread {
167
        public:
168
                        /** Default constructor */
169
                virtual ~CNCSJP2FileViewVector();
170
                        /** Event - fired when something happens */
171
                CNCSJPCEvent        m_Event;
172
                        /** Progressive Mode Thread worker function */
173
                virtual void Work(void *pData);
174
        };
175

    
176
                /** The number of cells across the dataset */
177
        INT32 m_nWidth;                                
178
                /** The number of lines down the dataset */
179
        INT32 m_nHeight;                        
180
                /** The number of bands in the dataset */
181
        INT32 m_nNumberOfBands;        
182
                /** The actual compression ratio */        
183
        IEEE8 m_dCompressionRate;        
184
                /** The target compression ratio */
185
        IEEE8 m_dTargetCompressionRate;
186
                /** The X cell size in m_CellSizeUnits */
187
        IEEE8 m_dCellIncrementX;        
188
                /** The Y cell size in m_CellSizeUnits */
189
        IEEE8 m_dCellIncrementY;        
190
                /** The top left X origin of the dataset (world) */
191
        IEEE8 m_dOriginX;                        
192
                /** The top left Y origin of the dataset (world) */
193
        IEEE8 m_dOriginY;                        
194

    
195
                /** The GDT datum of the dataset */
196
        char *m_pDatum;                                
197
                /** The GDT projection of the dataset */
198
        char *m_pProjection;                
199
                /** A pointer to the currently open filename */
200
        char *m_pFilename;                        
201
                /** Cell units, meters, degrees or feet */
202
        CellSizeUnits m_CellSizeUnits;
203
                /** Cell type image should be read as */
204
        NCSEcwCellType m_eCellType;                
205
                /** ColorSpace of image */
206
        NCSFileColorSpace m_eColorSpace;                
207
                /** BandInfo for each band */
208
        std::vector<NCSFileBandInfo> m_Bands;
209
                /** The clockwise rotation of the image in degrees [02] */
210
        IEEE8 m_dCWRotationDegrees; 
211

    
212
                /** The number of bands in the current view */
213
        INT32 m_nSetViewNrBands;                
214
                /** A pointer to the band list for the current view */
215
        INT32 *m_pnSetViewBandList;                
216
                /** The current view width */
217
        INT32 m_nSetViewWidth;                        
218
                /** The current view height */
219
        INT32 m_nSetViewHeight;                        
220
                /** The current view world top left X */
221
        IEEE8 m_dSetViewWorldTLX;                
222
                /** The current view world top left Y */
223
        IEEE8 m_dSetViewWorldTLY;                
224
                /** The current view world bottom right X */
225
        IEEE8 m_dSetViewWorldBRX;                
226
                /** The current view world bottom right Y */
227
        IEEE8 m_dSetViewWorldBRY;                
228
                /** The current view dataset top left X */
229
        INT32 m_nSetViewDatasetTLX;                
230
                /** The current view dataset top left Y */
231
        INT32 m_nSetViewDatasetTLY;                
232
                /** The current view dataset bottom right X */
233
        INT32 m_nSetViewDatasetBRX;                
234
                /** The current view dataset bottom right Y */
235
        INT32 m_nSetViewDatasetBRY;                
236

    
237
                /** Default constructor, initialises members */
238
        CNCSJP2FileView();
239
                /** Virtual Destructor */
240
        virtual ~CNCSJP2FileView();
241
#if defined(_WCHAR_T_DEFINED)||defined(_WCHAR_T)
242
                /** 
243
                 * Open the JP2 file for Parsing/UnParsing.
244
                 * @param                pURLPath        Full path name of JP2 file to open
245
                 * @param                bProgressiveDisplay                Open for preogressive reading.
246
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
247
                 */
248
        virtual CNCSError Open(wchar_t *pURLPath, bool bProgressiveDisplay = false, bool bWrite = false);
249
#endif
250
                /** 
251
                 * Open the JP2 file for Parsing/UnParsing.
252
                 * @param                pURLPath        Full path name of JP2 file to open
253
                 * @param                bProgressiveDisplay                Open for preogressive reading.
254
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
255
                 */
256
        virtual CNCSError Open(char *pURLPath, bool bProgressiveDisplay = false, bool bWrite = false);
257
                /** 
258
                 * Open the JP2 file for Parsing/UnParsing on the specified stream.
259
                 * @param                pURLPath        Full path name of JP2 file to open
260
                 * @param                bProgressiveDisplay                Open for preogressive reading.
261
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
262
                 */
263
        virtual CNCSError Open(CNCSJPCIOStream *pStream, bool bProgressiveDisplay = false);
264
                /** 
265
                 * Close the JP2 file
266
                 * @param                bFreeCache        Free the cached JP2 file data.
267
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
268
                 */
269
        virtual CNCSError Close ( bool bFreeCache = false );
270

    
271
                /** 
272
                 * Set a view into the JP2 file for reading.
273
                 * @param                nBands                        Number of bands in pBandList to read
274
                 * @param                pBandList                Array of band indices to read.
275
                 * @param                nWidth                        Width of the view in pixels
276
                 * @param                nHeight                        Height of the view in pixels
277
                 * @param                nDatasetTLX                Top left X dataset coordinate of view
278
                 * @param                nDatasetTLY                Top left Y dataset coordinate of view
279
                 * @param                nDatasetBRX                Bottom right X dataset coordinate of view
280
                 * @param                nDatasetBRY                Bottom right Y dataset voordinate of view
281
                 * @param                dWorldTLX                Top left X world coordinate of view (informative only)
282
                 * @param                dWorldTLY                Top left Y world coordinate of view (informative only)
283
                 * @param                dWorldBRX                Bottom right X world coordinate of view (informative only)
284
                 * @param                dWorldBRY                Bottom right Y world coordinate of view (informative only)
285
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
286
                 */
287
        virtual CNCSError SetView(UINT32 nBands, UINT32 *pBandList, 
288
                                                             UINT32 nDatasetTLX, UINT32 nDatasetTLY,
289
                                                          UINT32 nDatasetBRX, UINT32 nDatasetBRY,
290
                                                          UINT32 nWidth, UINT32 nHeight,
291
                                                          IEEE8 dWorldTLX = 0.0, IEEE8 dWorldTLY = 0.0,
292
                                                          IEEE8 dWorldBRX = 0.0, IEEE8 dWorldBRY = 0.0);
293

    
294
                /** 
295
                 * Read the next line in BIL format from the current view into the file.
296
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
297
                 * @return      NCSEcwReadStatus        Read status code
298
                 */
299
        virtual NCSEcwReadStatus ReadLineBIL(UINT8 **ppOutputLine);
300
                /** 
301
                 * Read the next line in BIL format from the current view into the file.
302
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
303
                 * @return      NCSEcwReadStatus        Read status code
304
                 */
305
        virtual NCSEcwReadStatus ReadLineBIL(UINT16 **ppOutputLine);
306
                /** 
307
                 * Read the next line in BIL format from the current view into the file.
308
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
309
                 * @return      NCSEcwReadStatus        Read status code
310
                 */
311
        virtual NCSEcwReadStatus ReadLineBIL(UINT32 **ppOutputLine);
312
                /** 
313
                 * Read the next line in BIL format from the current view into the file.
314
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
315
                 * @return      NCSEcwReadStatus        Read status code
316
                 */
317
        virtual NCSEcwReadStatus ReadLineBIL(UINT64 **ppOutputLine);
318
                /** 
319
                 * Read the next line in BIL format from the current view into the file.
320
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
321
                 * @return      NCSEcwReadStatus        Read status code
322
                 */
323
        virtual NCSEcwReadStatus ReadLineBIL(INT8 **ppOutputLine);
324
                /** 
325
                 * Read the next line in BIL format from the current view into the file.
326
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
327
                 * @return      NCSEcwReadStatus        Read status code
328
                 */
329
        virtual NCSEcwReadStatus ReadLineBIL(INT16 **ppOutputLine);
330
                /** 
331
                 * Read the next line in BIL format from the current view into the file.
332
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
333
                 * @return      NCSEcwReadStatus        Read status code
334
                 */
335
        virtual NCSEcwReadStatus ReadLineBIL(INT32 **ppOutputLine);
336
                /** 
337
                 * Read the next line in BIL format from the current view into the file.
338
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
339
                 * @return      NCSEcwReadStatus        Read status code
340
                 */
341
        virtual NCSEcwReadStatus ReadLineBIL(INT64 **ppOutputLine);
342
                /** 
343
                 * Read the next line in BIL format from the current view into the file.
344
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
345
                 * @return      NCSEcwReadStatus        Read status code
346
                 */
347
        virtual NCSEcwReadStatus ReadLineBIL(IEEE4 **ppOutputLine);
348
                /** 
349
                 * Read the next line in BIL format from the current view into the file.
350
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
351
                 * @return      NCSEcwReadStatus        Read status code
352
                 */
353
        virtual NCSEcwReadStatus ReadLineBIL(IEEE8 **ppOutputLine);
354
                /** 
355
                 * Read the next line in RGB UINT8 triplet format from the current view into the file.
356
                 * @param                pRGBTripler                        Pointer to UINT8 buffer to receive RGB data
357
                 * @return      NCSEcwReadStatus        Read status code
358
                 */
359
        virtual NCSEcwReadStatus ReadLineRGB(UINT8 *pRGBTriplet);
360
                /** 
361
                 * Read the next line in BGR UINT8 triplet format from the current view into the file.
362
                 * @param                pBGRTripler                        Pointer to UINT8 buffer to receive BGR data
363
                 * @return      NCSEcwReadStatus        Read status code
364
                 */
365
        virtual NCSEcwReadStatus ReadLineBGR(UINT8 *pBGRTriplet);
366
                /** 
367
                 * Read the next line in RGBA UINT32 format from the current view into the file.
368
                 * @param                pRGBA                                Pointer to UINT32 buffer to receive RGBA data
369
                 * @return      NCSEcwReadStatus        Read status code
370
                 */
371
        virtual NCSEcwReadStatus ReadLineRGBA(UINT32 *pRGBA);
372
                /** 
373
                 * Read the next line in BGRA UINT32 format from the current view into the file.
374
                 * @param                pBGRA                                Pointer to UINT32 buffer to receive BGRA data
375
                 * @return      NCSEcwReadStatus        Read status code
376
                 */
377
        virtual NCSEcwReadStatus ReadLineBGRA(UINT32 *pBGRA);
378
                /** 
379
                 * Read the next line in ARGB UINT32 format from the current view into the file.
380
                 * @param                pARGB                                Pointer to UINT32 buffer to receive ARGB data
381
                 * @return      NCSEcwReadStatus        Read status code
382
                 */
383
        virtual NCSEcwReadStatus ReadLineARGB(UINT32 *pARGB);
384
                /** 
385
                 * Read the next line in ABGR UINT32 format from the current view into the file.
386
                 * @param                pABGR                                Pointer to UINT32 buffer to receive ABGR data
387
                 * @return      NCSEcwReadStatus        Read status code
388
                 */
389
        virtual NCSEcwReadStatus ReadLineABGR(UINT32 *pABGR);
390
                /** 
391
                 * Read the next line in BIL format from the current view into the file.
392
                 * @param                eType                                Output buffer type
393
                 * @param                nBands                                Number of output bands
394
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
395
                 * @param                pLineSteps                        Line steps, in CELLS.
396
                 * @return      NCSEcwReadStatus        Read status code
397
                 */
398
        virtual NCSEcwReadStatus ReadLineBIL(NCSEcwCellType eType, UINT16 nBands, void **ppOutputLine, UINT32 *pLineSteps = NULL);
399

    
400
                /** 
401
                 * Write the next line in BIL format into the JP2 file.
402
                 * @param                eType                                Output buffer type
403
                 * @param                nBands                                Number of output bands
404
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
405
                 * @param                pLineSteps                        Line steps, in CELLS.
406
                 * @return      CNCSError                        Write status code
407
                 */
408
        virtual CNCSError WriteLineBIL(NCSEcwCellType eType, UINT16 nBands, void **ppOutputLine, UINT32 *pLineSteps = NULL);
409

    
410
                /** 
411
                 * More data is available and a refresh update should be done.
412
                 * @param                pSetViewInfo                Pointer to SetViewInfo containing details on view the update is for
413
                 * @return      NCSEcwReadStatus        Return the Read status code from the ReadLine*() call.
414
                 */
415
        virtual NCSEcwReadStatus RefreshUpdateEx(NCSFileViewSetInfo *pViewSetInfo);
416

    
417
                /** 
418
                 * Start the compression.
419
                 * In progressive (pull) mode scanlines will be sequentially
420
                 * read by the overloaded WriteReadLine() method
421
                 * @param                eType                                Output buffer type
422
                 * @param                nBands                                Number of output bands
423
                 * @param                ppOutputLine                Array of buffer pointers, one buffer for each band
424
                 * @param                pLineSteps                        Line steps, in CELLS.
425
                 * @return      CNCSError                        Write status code
426
                 */
427
        virtual CNCSError Write();        
428
                /** 
429
                 * Read input line for compression.
430
                 * In progressive (pull) mode scanlines will be sequentially
431
                 * read by the overloaded WriteReadLine() method
432
                 * @param                nNextLine                        Next input line to read
433
                 * @param                ppInputArray                Array of buffer pointers, one buffer for each band
434
                 * @return      CNCSError                        Write status code
435
                 */
436
        virtual CNCSError WriteReadLine(UINT32 nNextLine, void **ppInputArray);        
437
                /** 
438
                 * Compression status callback.
439
                 * you overload this if you want a status callback to show progress during compression
440
                 * @param                nCurrentLine                Current input line processed
441
                 */
442
        virtual void WriteStatus(UINT32 nCurrentLine);
443
                /** 
444
                 * Compression cancel callback.
445
                 * you overload this if you want to be able to cancel during compression
446
                 * @return      bool                                Return true to cancel, else false to continue
447
                 */
448
        virtual bool        WriteCancel(void);
449

    
450
                /** 
451
                 * Get current ViewSetinfo structure.
452
                 * @return      NCSFileViewSetInfo*        Return pointer to the current SetViewInfo.
453
                 */
454
        virtual /*const*/ NCSFileViewSetInfo *GetFileViewSetInfo();
455
                /** 
456
                 * Get FileInfo structure.
457
                 * @return      NCSFileViewFileInfo*        Return pointer to the FileInfo.
458
                 */
459
        virtual /*const*/ NCSFileViewFileInfoEx *GetFileInfo();
460
                /** 
461
                 * Set FileInfo structure.
462
                 * @param                Info                New fileinfo - used to specify file info for compression
463
                 * @return      CNCSError        Return pointer to the FileInfo.
464
                 */
465
        virtual CNCSError SetFileInfo(NCSFileViewFileInfoEx &Info);
466

    
467
                /**
468
                  * Get the next UUID box with the specified UUID from the file.
469
                  * @param                uuid                        UUID of UUID box to find.
470
                  * @param                pLast                        Last UUID box found, else NULL for first
471
                  * @return                CNCSJP2Box*                Pointer to box if found, else NULL;
472
                  */
473
        virtual CNCSJP2Box *GetUUIDBox(NCSUUID uuid, CNCSJP2Box *pLast = NULL);
474
                /**
475
                  * Get the next XML box from the file.
476
                  * @param                pLast                        Last XML box found, else NULL for first
477
                  * @return                CNCSJP2Box*                Pointer to box if found, else NULL;
478
                  */
479
        virtual CNCSJP2Box *GetXMLBox(CNCSJP2Box *pLast = NULL);
480
                /**
481
                  * Get the next box of the specified type from the file.
482
                  * @param                nTBox                        Box type to find
483
                  * @param                pLast                        Last box found, else NULL for first
484
                  * @return                CNCSJP2Box*                Pointer to box if found, else NULL;
485
                  */
486
        virtual CNCSJP2Box *GetBox(UINT32 nTBox, CNCSJP2Box *pLast = NULL);
487
                /**
488
                  * Add a box to be written to the file on compression.
489
                  * The specified box's UnParse() method will be called to write the box into the file
490
                  * @param                pBox                        Box to be written to file
491
                  * @return                CNCSError                returned error or NCS_SUCCESS;
492
                  */
493
        virtual CNCSError AddBox(CNCSJP2Box *pBox);
494

    
495

    
496
        /**
497
                  * Get a GDT (ER Mapper) Projection/Datum pair for the given EPSG code, if available
498
                  * @param                nEPSGCode                EPSG Code to find projection/datum for
499
                  * @param                ppProjection        Returned GDT Projection name - free with NCSFree()
500
                  * @param                ppDatum                        Returned GDT Datum name - free with NCSFree()
501
                  * @return                CNCSError                Error code;
502
                  */
503
        static CNCSError GetProjectionAndDatum(const INT32 nEPSGCode, char **ppProjection, char **ppDatum);
504
                /**
505
                  * Get an EPSG code from the given GDT (ER Mapper) Projection/Datum pair if available
506
                  * @param                pProjection                GDT Projection name
507
                  * @param                pDatum                        GDT Datum name
508
                  * @param                nEPSGCode                Returned EPSG Code or 0 on error
509
                  * @return                CNCSError                Error code;
510
                  */
511
        static CNCSError GetEPSGCode(char *pProjection, char *pDatum, INT32 *nEPSGCode);
512
                /**
513
                  * Get the custom GDT data path (for EPSG<-->ER Mapper projection/datum mapping)
514
                  * @return the custom path being used, or NULL
515
                  */
516
        static char *GetGDTPath();
517
                /**
518
                  * Set the custom GDT data path (for EPSG<-->ER Mapper projection/datum mapping)
519
                  * @param szPath the new GDT data path
520
                  */
521
        static void SetGDTPath(const char *szPath);
522
                /**
523
                  * Refresh the custom GDT data path, doing a search and validity check on 
524
                  * the current path value and several common GDT data locations
525
                  */
526
        static void DetectGDTPath();
527

    
528
                /** 
529
                  * Set refresh callback funnction 
530
                  * @param                pCallback                Refresh callback function to use
531
                  * @return                CNCSError                Error code;
532
                  */
533
        CNCSError SetRefreshCallback(NCSEcwReadStatus (*pCallback)(NCSFileView*));
534

    
535
                /**
536
                  * Set Compress Client - Internal func for "C" API support only
537
                  * @param                pCompressClient        ECW Compress Client struct
538
                  * @return                CNCSError                Error code;
539
                  */                 
540
        CNCSError SetCompressClient(struct NCSEcwCompressClient *pCompressClient);
541

    
542
                /** 
543
                 * Get underlying CNCSJP2File pointer.
544
                 * @return      CNCSJP2File*        Return pointer to the CNCSJP2File instance.
545
                 */
546
        class CNCSJP2File *GetFile();
547
#ifdef NCSJPC_ECW_SUPPORT
548
                /** 
549
                 * Get underlying NCSFileView pointer, where it exists.
550
                 * @return      NCSFileView*        Return pointer to the NCSFileView instance.
551
                 */
552
        NCSFileView *GetNCSFileView();
553
#endif
554

    
555
                /** 
556
                 * Get a pointer to the underlying CNCSJPCIOStream.
557
                 * This can be used to read specific JP2 UUID/XML boxes etc.
558
                 * @return      CNCSJPCIOStream*        Return pointer to the CNCSJPCIOStream, else NULL.
559
                 */
560
        CNCSJPCIOStream *GetStream();
561

    
562
                /**
563
                  * Find the CNCSJP2FileVIew instance pointer for a given NCSFileView structure
564
                  * @param                pNCSFileView                NCSFileView to find
565
                  * @return                CNCSJP2FileView*        CNCSJP2FileView instance if found, else NULL
566
                  */                 
567
        static CNCSJP2FileView *FindJP2FileView(NCSFileView *pNCSFileView);
568

    
569
                /**
570
                  * Get a statistic of NCSTimeStampMs type
571
                  * @param                eType                                Statistic to find
572
                  * @param                Val                                        Statistic value
573
                  */                 
574
        void GetStatistic(Statistic eType, NCSTimeStampMs &Val);
575
                /**
576
                  * Get a statistic of UINT64 type
577
                  * @param                eType                                Statistic to find
578
                  * @param                Val                                        Statistic value
579
                  */                 
580
        void GetStatistic(Statistic eType, UINT64 &Val);
581
                /**
582
                  * Reset the specified statistic to the default value
583
                  * @param                eType                                Statistic to reset
584
                  */                 
585
        void ResetStatistic(Statistic eType);
586
                /**
587
                  * Reset all statistics to their default values
588
                  */                 
589
        void ResetStatistics();
590

    
591
                /**
592
                  * Set a parameter on the view.  These over-ride default settings, such as compression output profile,
593
                  * progression order, tiling etc
594
                  * @param                eType                        Parameter type to set.
595
                  */
596
        void SetParameter(Parameter eType);
597
                /**
598
                  * Set a parameter on the view.  These over-ride default settings, such as compression output profile,
599
                  * progression order, tiling etc
600
                  * @param                eType                        Parameter type to set.
601
                  * @param                bBool                        Boolean parameter true/false
602
                  */
603
        void SetParameter(Parameter eType, bool bBool);
604
                /**
605
                  * Set a parameter on the view.  These over-ride default settings, such as compression output profile,
606
                  * progression order, tiling etc
607
                  * @param                eType                        Parameter type to set.
608
                  * @param                nValue                        UINT32 parameter value to set
609
                  */
610
        void SetParameter(Parameter eType, UINT32 nValue);
611
                /**
612
                  * Set a parameter on the view.  These over-ride default settings, such as compression output profile,
613
                  * progression order, tiling etc
614
                  * @param                eType                        Parameter type to set.
615
                  * @param                fValue                        IEEE4 parameter value to set
616
                  */
617
        void SetParameter(Parameter eType, IEEE4 fValue);
618

    
619
                /**
620
                  * Get the percent complete (from time of setview == 0%)
621
                  * @return                INT32                        Returned Percent complete
622
                  */                 
623
        INT32 GetPercentComplete();
624

    
625
                /**
626
                  * Get the percent complete as a percentage of total blocks in the current view.
627
                  * @return                INT32                        Returned Percent complete
628
                  */                 
629
        INT32 GetPercentCompleteTotalBlocksInView();
630

    
631
                /**
632
                  * Get the EPSG code associated with this view's projection and datum, if any.
633
                  * @return                INT32                        EPSG code, or 0 if none applies.
634
                  */
635
        INT32 GetEPSGCode();
636

    
637
                /**
638
                  * Internal shutdown function.
639
                  */                 
640
        static void Shutdown();
641

    
642
                /**
643
                  * Call this function to enable unlimited compression.
644
                  * NOTE: Verify you are in compliance with the appropriate license agreements.
645
                  * Calling this function signifies you accept the terms of the appropriate license.
646
                  */                 
647
        static void SetKeySize(void);
648

    
649
                /**
650
                  * Get the type of the currently open file
651
                  * @return                NCSFileType                        The file type.
652
                  */
653
        NCSFileType GetFileType();
654

    
655
                /**
656
                  * Get the Mime type of the currently open file
657
                  * @return                The Mime Type string or NULL if error.
658
                  */
659
        char *GetFileMimeType();
660
        
661
                /**
662
                  * Return the Mime type of a file given the file type.
663
                  * @param                NCSFileType                        The file type.
664
                  * @return                The Mime Type string or NULL if error.
665
                  */
666
        static char *GetFileMimeType(NCSFileType fileType);
667

    
668
protected:
669
                /** Timestamp representing lat time a blocking read was called */
670
        NCSTimeStampMs        m_tsLastBlockTime;
671
                /** Next line in view to read */
672
        UINT32                m_nNextLine;
673
        
674
                /**
675
                  * Fire a refresh update,
676
                  * @param                _Lock                                Global lock to release during call.
677
                  * @return                NCSEcwReadStatus        RefreshUpdate Read status
678
                  */
679
        NCSEcwReadStatus FireRefreshUpdate(CNCSJPCGlobalLock &_Lock);
680
                /** 
681
                 * Open the JP2 file for Parsing/UnParsing.
682
                 * @param                pURLPath        Full path name of JP2 file to open
683
                 * @param                pStream                IO Stream to open on
684
                 * @param                bProgressiveDisplay                Open for preogressive reading.
685
                 * @return      CNCSError                NCS_SUCCESS or error code on failure.
686
                 */
687
        virtual CNCSError OpenForWrite(char *pURLPath, CNCSJPCIOStream *pStream, bool bProgressiveDisplay = false);
688
        
689
friend class CNCSJPCResample;
690
                /** Add a dynamically allocated node to the dynamic node list so it is released */
691
        void AddDynamicNode(class CNCSJPCNode *pNode) { m_DynamicNodes.push_back(pNode); };
692

    
693
protected:
694
friend class CNCSJP2FileViewVector;
695
                /** Display update is progressive for this view */
696
        bool m_bIsProgressive;
697
                /** SetView is valid */
698
        bool m_bHaveValidSetView;
699
                /** Set view mode is world? */
700
        bool m_bSetViewModeIsWorld;
701
                /** File is open */
702
        bool m_bIsOpen;
703
                /** File is open */
704
        bool m_bIsWrite;
705

    
706
                /** CNCSJP2File */
707
        CNCSJP2File *m_pFile;
708
                /** ECW SetViewInfo Structure */
709
        NCSFileViewSetInfo m_CurrentView;
710
                /** Do we have a pending setview */
711
        bool        m_bPendingView;
712
                /** Progressive pending View */
713
        NCSFileViewSetInfo m_PendingView;
714
                /** JP2 Compression Output node */
715
        class CNCSJPCNode *m_pOutputNode;
716

    
717
private:
718
        /**
719
         * ParameterValuePair class - holds compression parameters prior to CNCSJP2File instance being created on the Open()
720
         * 
721
         * @author       Simon Cope
722
         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
723
         */
724
        class NCSJPC_EXPORT_ALL ParameterValuePair {
725
        public:
726
                        /** Parameter name */
727
                Parameter m_eParam;
728
                        /** Parameter value */
729
                void        *m_pValue;
730

    
731
                        /** Default constructor */
732
                ParameterValuePair();
733
                        /** Copy constructor */
734
                ParameterValuePair(const ParameterValuePair &Src);
735
                        /** No-parameter constructor */
736
                ParameterValuePair(Parameter eParam);
737
                        /** bool-parameter constructor */
738
                ParameterValuePair(Parameter eParam, bool bValue);
739
                        /** UINT32-paramater constructor */
740
                ParameterValuePair(Parameter eParam, UINT32 nValue);
741
                        /** IEEE4-parameter constructor */
742
                ParameterValuePair(Parameter eParam, IEEE4 fValue);
743
                        /** Virtual destructor */
744
                virtual ~ParameterValuePair();
745
        };
746

    
747
                /** Number of blocks in cache at the last SetView() */
748
        UINT32        m_nBlocksAtLastRefreshUpdate;
749
                /** Current in RefreshUpdate() callback */
750
        bool        m_bInRefreshUpdate;
751
                /** Cancel the read */
752
        bool        m_bCancelRead;
753
                /** Performing low-memory JP2 compression */
754
        bool        m_bLowMemCompress;
755

    
756
                /** parameters held until open() */
757
        std::vector<ParameterValuePair> m_Parameters;
758
                /** Copy the parameters from the m_Parameters vector to the CNCSJP2File instance */
759
        void SetFileParameters();
760
                /** List of other JP2 box(es) to be included in the output file */
761
        CNCSJP2Box::CNCSJP2BoxList m_OtherBoxes;        
762

    
763
                /** Used when SetView is >4000 in either dimension - too large to cache */
764
        bool        m_bTiledView;
765
                /** Tiled views when view > 4K x 4K */
766
        std::vector<CNCSJP2FileView *> m_TiledViews;
767
                /** Set the tiled views */
768
        CNCSError SetTiledView(NCSFileViewSetInfo &View, UINT32 nReadLine);
769

    
770
                /** Static list of file views */
771
        static CNCSJP2FileViewVector sm_Views;
772
                /** Dynamic Nodes to free */
773
        CNCSJPCNodeVector m_DynamicNodes;
774

    
775
                // The following private members are here to support the "C" API only.
776
                /** Progressive read callback for ECW decompression */
777
        NCSEcwReadStatus (*m_pRefreshCallback)(NCSFileView *pNCSFileView);
778
                /** ECW Compress Client for "C" compression API */
779
        struct NCSEcwCompressClient *m_pCompressClient;
780

    
781
                /** Compression Start timestamp */
782
        NCSTimeStampMs        m_tsCompressStart;
783
                /** Compression End timestamp */
784
        NCSTimeStampMs        m_tsCompressEnd;
785

    
786
                /** JP2 compression progressive buffer queue */
787
        std::vector<CNCSJPCBufferVector*> m_CompressReadQueue;
788
                /** Read event */
789
        CNCSJPCEvent        m_CompressReadEvent;
790
                /** Compression free buffer queue */
791
        std::vector<CNCSJPCBufferVector*> m_CompressFreeQueue;
792
                /** Compression free event */
793
        CNCSJPCEvent        m_CompressFreeEvent;
794
                /** Compression queue mutex */
795
        CNCSMutex                m_CompressQueueMutex;
796
                /** Compression Error status */
797
        CNCSError                m_CompressError;
798
                /** Multi-thread compression */
799
        bool                        m_bCompressMTRead;
800
#ifdef NCSJPC_ECW_SUPPORT
801
                /** ECW File reading struct instance */
802
        NCSFileView        *m_pECWFileView;
803
                /** Static RefreshUpdate callback hook */
804
        static NCSEcwReadStatus sRefreshCallback(NCSFileView *pNCSFileView);
805

    
806
                /** ECW File writing struct instance */
807
        struct EcwCompressionTask *m_pECWCompressionTask;
808

    
809
                /** Static Compression read thread function hook */
810
        static void sECWCompressThreadReadFunc(void *pData);
811
                /** Static Compression read callback hook */
812
        static NCSError        sECWCompressRead(void *pClient, UINT32 nNextLine, IEEE4 **ppInputArray);        
813
                /** Static Compression status callback hook */
814
        static void sECWCompressStatus(void *pClient, UINT32 nCurrentLine);
815
                /** Statuc Compression Cancel callback hook */
816
        static BOOLEAN        sECWCompressCancel(void *pClient);
817
#endif // NCSJPC_ECW_SUPPORT
818

    
819
                /** JP2 resampler */
820
        CNCSJPCResample        *m_pResampler;
821

    
822
                /** Scanline input buffer */
823
        CNCSJPCBuffer m_InputBuf;
824

    
825
                /** Update the public file & view members */
826
        bool UpdateFileViewInfo(void);
827

    
828
                /** Delete all dynamic nodes */
829
        void DeleteDynamicNodes(void);
830

    
831
                /** Update the view statistics */
832
        void UpdateViewStats();
833

    
834
                /** Thread Work func for JP2 progressive compression */
835
        void Work(void *pDate);
836
};
837

    
838
#endif // !NCSJP2FILEVIEW_H