Changeset 13586
- Timestamp:
- 01/24/08 12:20:57 (5 months ago)
- Files:
-
- trunk/gdal/frmts/rmf/rmfdataset.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gdal/frmts/rmf/rmfdataset.cpp
r13518 r13586 100 100 GUInt32 i, nCurBlockYSize; 101 101 102 CPLAssert( poGDS != NULL 103 && nBlockXOff >= 0 104 && nBlockYOff >= 0 105 && pImage != NULL ); 106 102 107 memset( pImage, 0, nBlockBytes ); 103 108 … … 201 206 /* -------------------------------------------------------------------- */ 202 207 GUInt32 nRawBytes; 203 if ( nLastTileXBytes && (GUInt32) nBlockXOff == poGDS->nXTiles - 1 )208 if ( nLastTileXBytes && (GUInt32)nBlockXOff == poGDS->nXTiles - 1 ) 204 209 { 205 210 nRawBytes = nLastTileXBytes; 206 if ( nLastTileHeight && (GUInt32) nBlockYOff == poGDS->nYTiles - 1)211 if ( nLastTileHeight && (GUInt32)nBlockYOff == poGDS->nYTiles - 1 ) 207 212 nRawBytes *= nLastTileHeight; 208 213 else … … 212 217 { 213 218 nRawBytes = poGDS->nBands * nBlockXSize * nDataSize; 214 if ( nLastTileHeight && (GUInt32) nBlockYOff == poGDS->nYTiles - 1)219 if ( nLastTileHeight && (GUInt32)nBlockYOff == poGDS->nYTiles - 1 ) 215 220 nRawBytes *= nLastTileHeight; 216 221 else … … 218 223 } 219 224 220 if ( poGDS->Decompress && nRawBytes > nTileBytes)221 { 222 GByte *pszRawBuf = (GByte *)CPLMalloc( nRawBytes);223 224 (*poGDS->Decompress)( pabyTile, nTileBytes, pszRawBuf, nRawBytes);225 CPLFree( pabyTile);225 if ( poGDS->Decompress && nRawBytes > nTileBytes ) 226 { 227 GByte *pszRawBuf = (GByte *)CPLMalloc( nRawBytes ); 228 229 (*poGDS->Decompress)( pabyTile, nTileBytes, pszRawBuf, nRawBytes ); 230 CPLFree( pabyTile ); 226 231 pabyTile = pszRawBuf; 227 232 nTileBytes = nRawBytes; … … 818 823 819 824 /* -------------------------------------------------------------------- */ 820 /* Write out the block table. */ 821 /* -------------------------------------------------------------------- */ 825 /* Write out the block table, swapped if needed. */ 826 /* -------------------------------------------------------------------- */ 827 #ifdef CPL_MSB 828 GUInt32 i; 829 GUInt32 *paiTilesSwapped = (GUInt32 *)CPLMalloc( sHeader.nTileTblSize ); 830 831 if ( !paiTilesSwapped ) 832 return CE_Failure; 833 834 memcpy( paiTilesSwapped, paiTiles, sHeader.nTileTblSize ); 835 for ( i = 0; i < sHeader.nTileTblSize / sizeof(GUInt32); i++ ) 836 CPL_SWAP32PTR( paiTilesSwapped + i ); 837 VSIFWriteL( paiTilesSwapped, 1, sHeader.nTileTblSize, fp ); 838 839 CPLFree( paiTilesSwapped ); 840 #else 822 841 VSIFWriteL( paiTiles, 1, sHeader.nTileTblSize, fp ); 842 #endif 823 843 824 844 bHeaderDirty = FALSE; … … 845 865 if ( eRMFType == RMFT_MTW ) 846 866 { 847 GDALComputeRasterMinMax( GetRasterBand(1), FALSE, 848 sHeader.adfElevMinMax ); 849 bHeaderDirty = TRUE; 867 GDALRasterBand *poBand = GetRasterBand(1); 868 869 if ( poBand ) 870 { 871 poBand->ComputeRasterMinMax( FALSE, sHeader.adfElevMinMax ); 872 bHeaderDirty = TRUE; 873 } 850 874 } 851 875 WriteHeader(); … … 958 982 959 983 #ifdef DEBUG 984 960 985 CPLDebug( "RMF", "%s image has width %d, height %d, bit depth %d, " 961 986 "compression scheme %d", … … 1002 1027 } 1003 1028 1029 #ifdef CPL_MSB 1030 for ( i = 0; i < poDS->sHeader.nTileTblSize / sizeof(GUInt32); i++ ) 1031 CPL_SWAP32PTR( poDS->paiTiles + i ); 1032 #endif 1033 1004 1034 #if DEBUG 1005 1035 CPLDebug( "RMF", "List of block offsets/sizes:" ); 1006 1036 1007 for ( i = 0; i < poDS->sHeader.nTileTblSize / 4; i += 2 ) 1037 for ( i = 0; i < poDS->sHeader.nTileTblSize / sizeof(GUInt32); i += 2 ) 1038 { 1008 1039 CPLDebug( "RMF", " %d / %d", 1009 1040 poDS->paiTiles[i], poDS->paiTiles[i + 1] ); 1041 } 1010 1042 #endif 1011 1043 … … 1220 1252 poDS = new RMFDataset(); 1221 1253 1222 poDS->fp = VSIFOpenL( pszFilename, "w b+" );1254 poDS->fp = VSIFOpenL( pszFilename, "w+b" ); 1223 1255 if( poDS->fp == NULL ) 1224 1256 {
