1
/******************************************************************************
2
* $Id: vsiiostream.h 20919 2010-10-21 02:00:35Z warmerdam $
5
* Purpose: ECW Driver: virtualized io stream declaration.
6
* Author: Frank Warmerdam, warmerdam@pobox.com
8
******************************************************************************
9
* Copyright (c) 2004, Frank Warmerdam <warmerdam@pobox.com>
11
* Permission is hereby granted, free of charge, to any person obtaining a
12
* copy of this software and associated documentation files (the "Software"),
13
* to deal in the Software without restriction, including without limitation
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
* and/or sell copies of the Software, and to permit persons to whom the
16
* Software is furnished to do so, subject to the following conditions:
18
* The above copyright notice and this permission notice shall be included
19
* in all copies or substantial portions of the Software.
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
* DEALINGS IN THE SOFTWARE.
28
****************************************************************************/
30
#ifndef VSIIOSTREAM_H_INCLUDED
31
#define VSIIOSTREAM_H_INCLUDED
34
#include "gdal_priv.h"
35
#include "gdal_frmts.h"
39
/* -------------------------------------------------------------------- */
40
/* These definitions aren't really specific to the VSIIOStream, */
41
/* but are shared amoung the ECW driver modules. */
42
/* -------------------------------------------------------------------- */
43
#include <NCSECWClient.h>
44
#include <NCSECWCompressClient.h>
45
#include <NCSErrors.h>
47
#include <NCSJP2FileView.h>
49
/* By default, assume 3.3 SDK Version. */
51
#if !defined(ECWSDK_VERSION)
52
# define ECWSDK_VERSION 33
55
#if ECWSDK_VERSION < 40
56
# include <NCSJP2File.h>
58
# include <ECWJP2BuildNumber.h>
62
/* As of July 2002 only uncompress support is available on Unix */
63
#if !defined(NO_COMPRESS)
64
# define HAVE_COMPRESS
69
ECWCreateCopyECW( const char * pszFilename, GDALDataset *poSrcDS,
70
int bStrict, char ** papszOptions,
71
GDALProgressFunc pfnProgress, void * pProgressData );
73
ECWCreateCopyJPEG2000( const char * pszFilename, GDALDataset *poSrcDS,
74
int bStrict, char ** papszOptions,
75
GDALProgressFunc pfnProgress, void * pProgressData );
78
ECWCreateECW( const char * pszFilename, int nXSize, int nYSize, int nBands,
79
GDALDataType eType, char **papszOptions );
81
ECWCreateJPEG2000(const char *pszFilename, int nXSize, int nYSize, int nBands,
82
GDALDataType eType, char **papszOptions );
85
/************************************************************************/
86
/* ==================================================================== */
88
/* ==================================================================== */
89
/************************************************************************/
91
class VSIIOStream : public CNCSJPCIOStream
109
virtual ~VSIIOStream() {
113
VSIFCloseL( fpVSIL );
117
#if ECWSDK_VERSION >= 40
118
virtual NCS::CIOStream *Clone() { return NULL; }
119
#endif /* ECWSDK_VERSION >= 4 */
121
virtual CNCSError Access( FILE *fpVSILIn, BOOLEAN bWrite,
122
const char *pszFilename,
123
INT64 start, INT64 size = -1) {
126
startOfJPData = start;
127
lengthOfJPData = size;
129
VSIFSeekL(fpVSIL, startOfJPData, SEEK_SET);
131
return(CNCSJPCIOStream::Open((char *)pszFilename, (bool) bWrite));
134
virtual bool NCS_FASTCALL Seek() {
138
virtual bool NCS_FASTCALL Seek(INT64 offset, Origin origin = CURRENT) {
141
return(0 == VSIFSeekL(fpVSIL, offset+startOfJPData, SEEK_SET));
144
return(0 == VSIFSeekL(fpVSIL, offset, SEEK_CUR));
147
return(0 == VSIFSeekL(fpVSIL, offset, SEEK_END));
153
virtual INT64 NCS_FASTCALL Tell() {
154
return VSIFTellL( fpVSIL ) - startOfJPData;
157
virtual INT64 NCS_FASTCALL Size() {
158
if( lengthOfJPData != -1 )
159
return lengthOfJPData;
162
INT64 curPos = Tell(), size;
166
Seek( curPos, START );
172
virtual bool NCS_FASTCALL Read(void* buffer, UINT32 count) {
176
// return(1 == VSIFReadL( buffer, count, 1, fpVSIL ) );
178
// The following is a hack
179
if( VSIFReadL( buffer, count, 1, fpVSIL ) != 1 )
181
CPLDebug( "VSIIOSTREAM",
182
"Read(%d) failed @ %d, ignoring failure.",
183
count, (int) (VSIFTellL( fpVSIL ) - startOfJPData) );
189
virtual bool NCS_FASTCALL Write(void* buffer, UINT32 count) {
192
return(1 == VSIFWriteL(buffer, count, 1, fpVSIL));
196
#endif /* def FRMT_ecw */
198
#endif /* ndef VSIIOSTREAM_H_INCLUDED */