1 /******************************************************************************
2  * $Id: rawdataset.h 28053 2014-12-04 09:31:07Z rouault $
3  *
4  * Project:  Raw Translator
5  * Purpose:  Implementation of RawDataset class.  Intented to be subclassed
6  *           by other raw formats.
7  * Author:   Frank Warmerdam, warmerdam@pobox.com
8  *
9  ******************************************************************************
10  * Copyright (c) 1999, Frank Warmerdam
11  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef GDAL_FRMTS_RAW_RAWDATASET_H_INCLUDED
33 #define GDAL_FRMTS_RAW_RAWDATASET_H_INCLUDED
34 
35 #include "gdal_pam.h"
36 
37 /************************************************************************/
38 /* ==================================================================== */
39 /*				RawDataset				*/
40 /* ==================================================================== */
41 /************************************************************************/
42 
43 class RawRasterBand;
44 
45 /**
46  * \brief Abstract Base Class dedicated to define new raw dataset types.
47  */
48 class CPL_DLL RawDataset : public GDALPamDataset
49 {
50     friend class RawRasterBand;
51 
52   protected:
53     virtual CPLErr      IRasterIO( GDALRWFlag, int, int, int, int,
54                                    void *, int, int, GDALDataType,
55                                    int, int *,
56                                    GSpacing nPixelSpace, GSpacing nLineSpace,
57                                    GSpacing nBandSpace,
58                                    GDALRasterIOExtraArg* psExtraArg );
59   public:
60                  RawDataset();
61                  ~RawDataset() = 0;
62 
63 };
64 
65 /************************************************************************/
66 /* ==================================================================== */
67 /*                            RawRasterBand                             */
68 /* ==================================================================== */
69 /************************************************************************/
70 
71 /**
72  * \brief Abstract Base Class dedicated to define raw datasets.
73  * \note It is not defined an Abstract Base Class, but it's advised to
74  * consider it as such and not use it directly in client's code.
75  */
76 class CPL_DLL RawRasterBand : public GDALPamRasterBand
77 {
78 protected:
79     friend class RawDataset;
80 
81     FILE       *fpRaw;
82     VSILFILE   *fpRawL;
83     int         bIsVSIL;
84 
85     vsi_l_offset nImgOffset;
86     int		nPixelOffset;
87     int		nLineOffset;
88     int         nLineSize;
89     int		bNativeOrder;
90 
91     int		nLoadedScanline;
92     void	*pLineBuffer;
93     void        *pLineStart;
94     int         bDirty;
95 
96     GDALColorTable *poCT;
97     GDALColorInterp eInterp;
98 
99     char           **papszCategoryNames;
100 
101     int         bOwnsFP;
102 
103     int         Seek( vsi_l_offset, int );
104     size_t      Read( void *, size_t, size_t );
105     size_t      Write( void *, size_t, size_t );
106 
107     CPLErr      AccessBlock( vsi_l_offset nBlockOff, int nBlockSize,
108                              void * pData );
109     int         IsSignificantNumberOfLinesLoaded( int nLineOff, int nLines );
110     void        Initialize();
111 
112     virtual CPLErr  IRasterIO( GDALRWFlag, int, int, int, int,
113                               void *, int, int, GDALDataType,
114                               GSpacing nPixelSpace, GSpacing nLineSpace,
115                               GDALRasterIOExtraArg* psExtraArg );
116 
117     int         CanUseDirectIO(int nXOff, int nYOff, int nXSize, int nYSize,
118                                GDALDataType eBufType);
119 
120 public:
121 
122                  RawRasterBand( GDALDataset *poDS, int nBand, void * fpRaw,
123                                 vsi_l_offset nImgOffset, int nPixelOffset,
124                                 int nLineOffset,
125                                 GDALDataType eDataType, int bNativeOrder,
126                                 int bIsVSIL = FALSE, int bOwnsFP = FALSE );
127 
128                  RawRasterBand( void * fpRaw,
129                                 vsi_l_offset nImgOffset, int nPixelOffset,
130                                 int nLineOffset,
131                                 GDALDataType eDataType, int bNativeOrder,
132                                 int nXSize, int nYSize, int bIsVSIL = FALSE, int bOwnsFP = FALSE );
133 
134                  ~RawRasterBand() /* = 0 */ ;
135 
136     // should override RasterIO eventually.
137 
138     virtual CPLErr  IReadBlock( int, int, void * );
139     virtual CPLErr  IWriteBlock( int, int, void * );
140 
141     virtual GDALColorTable *GetColorTable();
142     virtual GDALColorInterp GetColorInterpretation();
143     virtual CPLErr SetColorTable( GDALColorTable * );
144     virtual CPLErr SetColorInterpretation( GDALColorInterp );
145 
146     virtual char **GetCategoryNames();
147     virtual CPLErr SetCategoryNames( char ** );
148 
149     virtual CPLErr  FlushCache();
150 
151     virtual CPLVirtualMem  *GetVirtualMemAuto( GDALRWFlag eRWFlag,
152                                                int *pnPixelSpace,
153                                                GIntBig *pnLineSpace,
154                                                char **papszOptions );
155 
156     CPLErr          AccessLine( int iLine );
157 
158     void            SetAccess( GDALAccess eAccess );
159 
160     // this is deprecated.
161     void	 StoreNoDataValue( double );
162 
163     // Query methods for internal data.
GetImgOffset()164     vsi_l_offset GetImgOffset() { return nImgOffset; }
GetPixelOffset()165     int          GetPixelOffset() { return nPixelOffset; }
GetLineOffset()166     int          GetLineOffset() { return nLineOffset; }
GetNativeOrder()167     int          GetNativeOrder() { return bNativeOrder; }
GetIsVSIL()168     int          GetIsVSIL() { return bIsVSIL; }
GetFP()169     FILE        *GetFP() { return (bIsVSIL) ? (FILE*)fpRawL : fpRaw; }
GetFPL()170     VSILFILE    *GetFPL() { CPLAssert(bIsVSIL); return fpRawL; }
GetOwnsFP()171     int          GetOwnsFP() { return bOwnsFP; }
172 };
173 
174 #endif // GDAL_FRMTS_RAW_RAWDATASET_H_INCLUDED
175