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