rawdataset.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #ifndef GDAL_FRMTS_RAW_RAWDATASET_H_INCLUDED
  32. #define GDAL_FRMTS_RAW_RAWDATASET_H_INCLUDED
  33. #include "gdal_pam.h"
  34. /************************************************************************/
  35. /* ==================================================================== */
  36. /* RawDataset */
  37. /* ==================================================================== */
  38. /************************************************************************/
  39. class RawRasterBand;
  40. /**
  41. * \brief Abstract Base Class dedicated to define new raw dataset types.
  42. */
  43. class CPL_DLL RawDataset : public GDALPamDataset
  44. {
  45. friend class RawRasterBand;
  46. protected:
  47. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  48. void *, int, int, GDALDataType,
  49. int, int *,
  50. GSpacing nPixelSpace, GSpacing nLineSpace,
  51. GSpacing nBandSpace,
  52. GDALRasterIOExtraArg* psExtraArg );
  53. public:
  54. RawDataset();
  55. ~RawDataset() = 0;
  56. };
  57. /************************************************************************/
  58. /* ==================================================================== */
  59. /* RawRasterBand */
  60. /* ==================================================================== */
  61. /************************************************************************/
  62. /**
  63. * \brief Abstract Base Class dedicated to define raw datasets.
  64. * \note It is not defined an Abstract Base Class, but it's advised to
  65. * consider it as such and not use it directly in client's code.
  66. */
  67. class CPL_DLL RawRasterBand : public GDALPamRasterBand
  68. {
  69. protected:
  70. friend class RawDataset;
  71. FILE *fpRaw;
  72. VSILFILE *fpRawL;
  73. int bIsVSIL;
  74. vsi_l_offset nImgOffset;
  75. int nPixelOffset;
  76. int nLineOffset;
  77. int nLineSize;
  78. int bNativeOrder;
  79. int nLoadedScanline;
  80. void *pLineBuffer;
  81. void *pLineStart;
  82. int bDirty;
  83. GDALColorTable *poCT;
  84. GDALColorInterp eInterp;
  85. char **papszCategoryNames;
  86. int bOwnsFP;
  87. int Seek( vsi_l_offset, int );
  88. size_t Read( void *, size_t, size_t );
  89. size_t Write( void *, size_t, size_t );
  90. CPLErr AccessBlock( vsi_l_offset nBlockOff, int nBlockSize,
  91. void * pData );
  92. int IsSignificantNumberOfLinesLoaded( int nLineOff, int nLines );
  93. void Initialize();
  94. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  95. void *, int, int, GDALDataType,
  96. GSpacing nPixelSpace, GSpacing nLineSpace,
  97. GDALRasterIOExtraArg* psExtraArg );
  98. int CanUseDirectIO(int nXOff, int nYOff, int nXSize, int nYSize,
  99. GDALDataType eBufType);
  100. public:
  101. RawRasterBand( GDALDataset *poDS, int nBand, void * fpRaw,
  102. vsi_l_offset nImgOffset, int nPixelOffset,
  103. int nLineOffset,
  104. GDALDataType eDataType, int bNativeOrder,
  105. int bIsVSIL = FALSE, int bOwnsFP = FALSE );
  106. RawRasterBand( void * fpRaw,
  107. vsi_l_offset nImgOffset, int nPixelOffset,
  108. int nLineOffset,
  109. GDALDataType eDataType, int bNativeOrder,
  110. int nXSize, int nYSize, int bIsVSIL = FALSE, int bOwnsFP = FALSE );
  111. ~RawRasterBand() /* = 0 */ ;
  112. // should override RasterIO eventually.
  113. virtual CPLErr IReadBlock( int, int, void * );
  114. virtual CPLErr IWriteBlock( int, int, void * );
  115. virtual GDALColorTable *GetColorTable();
  116. virtual GDALColorInterp GetColorInterpretation();
  117. virtual CPLErr SetColorTable( GDALColorTable * );
  118. virtual CPLErr SetColorInterpretation( GDALColorInterp );
  119. virtual char **GetCategoryNames();
  120. virtual CPLErr SetCategoryNames( char ** );
  121. virtual CPLErr FlushCache();
  122. virtual CPLVirtualMem *GetVirtualMemAuto( GDALRWFlag eRWFlag,
  123. int *pnPixelSpace,
  124. GIntBig *pnLineSpace,
  125. char **papszOptions );
  126. CPLErr AccessLine( int iLine );
  127. void SetAccess( GDALAccess eAccess );
  128. // this is deprecated.
  129. void StoreNoDataValue( double );
  130. // Query methods for internal data.
  131. vsi_l_offset GetImgOffset() { return nImgOffset; }
  132. int GetPixelOffset() { return nPixelOffset; }
  133. int GetLineOffset() { return nLineOffset; }
  134. int GetNativeOrder() { return bNativeOrder; }
  135. int GetIsVSIL() { return bIsVSIL; }
  136. FILE *GetFP() { return (bIsVSIL) ? (FILE*)fpRawL : fpRaw; }
  137. VSILFILE *GetFPL() { CPLAssert(bIsVSIL); return fpRawL; }
  138. int GetOwnsFP() { return bOwnsFP; }
  139. };
  140. #endif // GDAL_FRMTS_RAW_RAWDATASET_H_INCLUDED