Changeset 13586

Show
Ignore:
Timestamp:
01/24/08 12:20:57 (5 months ago)
Author:
dron
Message:

Do not forget to swap block size/offset table on big-endian archs.
As per bug #2169.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/rmf/rmfdataset.cpp

    r13518 r13586  
    100100    GUInt32     i, nCurBlockYSize; 
    101101 
     102    CPLAssert( poGDS != NULL 
     103               && nBlockXOff >= 0 
     104               && nBlockYOff >= 0 
     105               && pImage != NULL ); 
     106 
    102107    memset( pImage, 0, nBlockBytes ); 
    103108 
     
    201206/* -------------------------------------------------------------------- */ 
    202207        GUInt32 nRawBytes; 
    203         if ( nLastTileXBytes && (GUInt32) nBlockXOff == poGDS->nXTiles - 1 ) 
     208        if ( nLastTileXBytes && (GUInt32)nBlockXOff == poGDS->nXTiles - 1 ) 
    204209        { 
    205210            nRawBytes = nLastTileXBytes; 
    206             if (nLastTileHeight && (GUInt32) nBlockYOff == poGDS->nYTiles - 1
     211            if ( nLastTileHeight && (GUInt32)nBlockYOff == poGDS->nYTiles - 1
    207212                nRawBytes *= nLastTileHeight; 
    208213            else 
     
    212217        { 
    213218            nRawBytes = poGDS->nBands * nBlockXSize * nDataSize; 
    214             if (nLastTileHeight && (GUInt32) nBlockYOff == poGDS->nYTiles - 1
     219            if ( nLastTileHeight && (GUInt32)nBlockYOff == poGDS->nYTiles - 1
    215220                nRawBytes *= nLastTileHeight; 
    216221            else 
     
    218223        } 
    219224 
    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 ); 
    226231            pabyTile = pszRawBuf; 
    227232            nTileBytes = nRawBytes; 
     
    818823 
    819824/* -------------------------------------------------------------------- */ 
    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 
    822841    VSIFWriteL( paiTiles, 1, sHeader.nTileTblSize, fp ); 
     842#endif 
    823843 
    824844    bHeaderDirty = FALSE; 
     
    845865    if ( eRMFType == RMFT_MTW ) 
    846866    { 
    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        } 
    850874    } 
    851875    WriteHeader(); 
     
    958982 
    959983#ifdef DEBUG 
     984 
    960985    CPLDebug( "RMF", "%s image has width %d, height %d, bit depth %d, " 
    961986              "compression scheme %d", 
     
    10021027    } 
    10031028 
     1029#ifdef CPL_MSB 
     1030    for ( i = 0; i < poDS->sHeader.nTileTblSize / sizeof(GUInt32); i++ ) 
     1031        CPL_SWAP32PTR( poDS->paiTiles + i ); 
     1032#endif 
     1033 
    10041034#if DEBUG 
    10051035    CPLDebug( "RMF", "List of block offsets/sizes:" ); 
    10061036 
    1007     for ( i = 0; i < poDS->sHeader.nTileTblSize / 4; i += 2 ) 
     1037    for ( i = 0; i < poDS->sHeader.nTileTblSize / sizeof(GUInt32); i += 2 ) 
     1038    { 
    10081039        CPLDebug( "RMF", "    %d / %d", 
    10091040                  poDS->paiTiles[i], poDS->paiTiles[i + 1] ); 
     1041    } 
    10101042#endif 
    10111043 
     
    12201252    poDS = new RMFDataset(); 
    12211253 
    1222     poDS->fp = VSIFOpenL( pszFilename, "wb+" ); 
     1254    poDS->fp = VSIFOpenL( pszFilename, "w+b" ); 
    12231255    if( poDS->fp == NULL ) 
    12241256    {