~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to frmts/ecw/vsiiostream.h

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 * $Id: vsiiostream.h 20919 2010-10-21 02:00:35Z warmerdam $
3
 
 *
4
 
 * Project:  GDAL 
5
 
 * Purpose:  ECW Driver: virtualized io stream declaration.
6
 
 * Author:   Frank Warmerdam, warmerdam@pobox.com
7
 
 *
8
 
 ******************************************************************************
9
 
 * Copyright (c) 2004, Frank Warmerdam <warmerdam@pobox.com>
10
 
 *
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:
17
 
 *
18
 
 * The above copyright notice and this permission notice shall be included
19
 
 * in all copies or substantial portions of the Software.
20
 
 *
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
 
 ****************************************************************************/
29
 
 
30
 
#ifndef VSIIOSTREAM_H_INCLUDED
31
 
#define VSIIOSTREAM_H_INCLUDED
32
 
 
33
 
#include "cpl_vsi.h"
34
 
#include "gdal_priv.h"
35
 
#include "gdal_frmts.h"
36
 
 
37
 
#ifdef FRMT_ecw
38
 
 
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>
46
 
#include <NCSFile.h>
47
 
#include <NCSJP2FileView.h>
48
 
 
49
 
/* By default, assume 3.3 SDK Version. */
50
 
 
51
 
#if !defined(ECWSDK_VERSION)
52
 
#  define ECWSDK_VERSION 33
53
 
#endif
54
 
 
55
 
#if ECWSDK_VERSION < 40
56
 
#  include <NCSJP2File.h>
57
 
#else
58
 
#  include <ECWJP2BuildNumber.h>
59
 
#  define NCS_FASTCALL
60
 
#endif
61
 
 
62
 
/* As of July 2002 only uncompress support is available on Unix */
63
 
#if !defined(NO_COMPRESS)
64
 
#  define HAVE_COMPRESS
65
 
#endif
66
 
 
67
 
#ifdef HAVE_COMPRESS
68
 
GDALDataset *
69
 
ECWCreateCopyECW( const char * pszFilename, GDALDataset *poSrcDS, 
70
 
                 int bStrict, char ** papszOptions, 
71
 
                 GDALProgressFunc pfnProgress, void * pProgressData );
72
 
GDALDataset *
73
 
ECWCreateCopyJPEG2000( const char * pszFilename, GDALDataset *poSrcDS, 
74
 
                 int bStrict, char ** papszOptions, 
75
 
                 GDALProgressFunc pfnProgress, void * pProgressData );
76
 
 
77
 
GDALDataset *
78
 
ECWCreateECW( const char * pszFilename, int nXSize, int nYSize, int nBands, 
79
 
              GDALDataType eType, char **papszOptions );
80
 
GDALDataset *
81
 
ECWCreateJPEG2000(const char *pszFilename, int nXSize, int nYSize, int nBands, 
82
 
                  GDALDataType eType, char **papszOptions );
83
 
#endif
84
 
 
85
 
/************************************************************************/
86
 
/* ==================================================================== */
87
 
/*                             VSIIOStream                              */
88
 
/* ==================================================================== */
89
 
/************************************************************************/
90
 
 
91
 
class VSIIOStream : public CNCSJPCIOStream
92
 
 
93
 
{
94
 
  public:
95
 
    
96
 
    INT64    startOfJPData;
97
 
    INT64    lengthOfJPData;
98
 
    FILE    *fpVSIL;
99
 
    int      bWritable;
100
 
        int      nFileViewCount;
101
 
    char     *pszFilename;
102
 
 
103
 
    VSIIOStream() {
104
 
        nFileViewCount = 0;
105
 
        startOfJPData = 0;
106
 
        lengthOfJPData = -1;
107
 
        fpVSIL = NULL;
108
 
    }
109
 
    virtual ~VSIIOStream() {
110
 
        Close();
111
 
        if( fpVSIL != NULL )
112
 
        {
113
 
            VSIFCloseL( fpVSIL );
114
 
            fpVSIL = NULL;
115
 
        }
116
 
    }
117
 
#if ECWSDK_VERSION >= 40
118
 
    virtual NCS::CIOStream *Clone() { return NULL; }
119
 
#endif /* ECWSDK_VERSION >= 4 */
120
 
 
121
 
    virtual CNCSError Access( FILE *fpVSILIn, BOOLEAN bWrite,
122
 
                              const char *pszFilename, 
123
 
                              INT64 start, INT64 size = -1) {
124
 
 
125
 
        fpVSIL = fpVSILIn;
126
 
        startOfJPData = start;
127
 
        lengthOfJPData = size;
128
 
        bWritable = bWrite;
129
 
        VSIFSeekL(fpVSIL, startOfJPData, SEEK_SET);
130
 
 
131
 
        return(CNCSJPCIOStream::Open((char *)pszFilename, (bool) bWrite));
132
 
    }
133
 
 
134
 
    virtual bool NCS_FASTCALL Seek() {
135
 
        return(true);
136
 
    }
137
 
    
138
 
    virtual bool NCS_FASTCALL Seek(INT64 offset, Origin origin = CURRENT) {
139
 
        switch(origin) {
140
 
            case START:
141
 
                return(0 == VSIFSeekL(fpVSIL, offset+startOfJPData, SEEK_SET));
142
 
 
143
 
            case CURRENT:
144
 
                return(0 == VSIFSeekL(fpVSIL, offset, SEEK_CUR));
145
 
                
146
 
            case END:
147
 
                return(0 == VSIFSeekL(fpVSIL, offset, SEEK_END));
148
 
        }
149
 
        
150
 
        return(false);
151
 
    }
152
 
 
153
 
    virtual INT64 NCS_FASTCALL Tell() {
154
 
        return VSIFTellL( fpVSIL ) - startOfJPData;
155
 
    }
156
 
 
157
 
    virtual INT64 NCS_FASTCALL Size() {
158
 
        if( lengthOfJPData != -1 )
159
 
            return lengthOfJPData;
160
 
        else
161
 
        {
162
 
            INT64 curPos = Tell(), size;
163
 
 
164
 
            Seek( 0, END );
165
 
            size = Tell();
166
 
            Seek( curPos, START );
167
 
 
168
 
            return size;
169
 
        }
170
 
    }
171
 
 
172
 
    virtual bool NCS_FASTCALL Read(void* buffer, UINT32 count) {
173
 
        if( count == 0 )
174
 
            return true;
175
 
 
176
 
//        return(1 == VSIFReadL( buffer, count, 1, fpVSIL ) );
177
 
 
178
 
        // The following is a hack 
179
 
        if( VSIFReadL( buffer, count, 1, fpVSIL ) != 1 )
180
 
        {
181
 
            CPLDebug( "VSIIOSTREAM",
182
 
                      "Read(%d) failed @ %d, ignoring failure.",
183
 
                      count, (int) (VSIFTellL( fpVSIL ) - startOfJPData) );
184
 
        }
185
 
        
186
 
        return true;
187
 
    }
188
 
 
189
 
    virtual bool NCS_FASTCALL Write(void* buffer, UINT32 count) {
190
 
        if( count == 0 )
191
 
            return true;
192
 
        return(1 == VSIFWriteL(buffer, count, 1, fpVSIL));
193
 
    }
194
 
};
195
 
 
196
 
#endif /* def FRMT_ecw */
197
 
 
198
 
#endif /* ndef VSIIOSTREAM_H_INCLUDED */
199