Changeset 14477 for branches

Show
Ignore:
Timestamp:
05/16/08 16:17:25 (3 months ago)
Author:
rouault
Message:

Fix wrong data type used to read the source band AAIGCreateCopy (#2369)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/gdal/frmts/aaigrid/aaigriddataset.cpp

    r13865 r14477  
    767767/*      Loop over image, copying image data.                            */ 
    768768/* -------------------------------------------------------------------- */ 
    769     double      *padfScanline; 
     769    int         *panScanline = NULL; 
     770    double      *padfScanline = NULL; 
     771    int         bReadAsInt; 
    770772    int         iLine, iPixel; 
    771773    CPLErr      eErr = CE_None; 
    772774     
     775    bReadAsInt = ( poBand->GetRasterDataType() == GDT_Byte  
     776                || poBand->GetRasterDataType() == GDT_Int16 
     777                || poBand->GetRasterDataType() == GDT_UInt16 
     778                || poBand->GetRasterDataType() == GDT_Int32 ); 
     779 
    773780    // Write scanlines to output file 
    774     padfScanline = (double *) CPLMalloc( nXSize * 
    775                                 GDALGetDataTypeSize(GDT_CFloat64) / 8 ); 
     781    if (bReadAsInt) 
     782        panScanline = (int *) CPLMalloc( nXSize * 
     783                                GDALGetDataTypeSize(GDT_Int32) / 8 ); 
     784    else 
     785        padfScanline = (double *) CPLMalloc( nXSize * 
     786                                    GDALGetDataTypeSize(GDT_Float64) / 8 ); 
     787 
    776788    for( iLine = 0; eErr == CE_None && iLine < nYSize; iLine++ ) 
    777789    { 
    778790        eErr = poBand->RasterIO( GF_Read, 0, iLine, nXSize, 1,  
    779                               padfScanline, nXSize, 1, GDT_CFloat64, 
    780                               sizeof(double), sizeof(double) * nXSize ); 
    781  
    782         if( poBand->GetRasterDataType() == GDT_Byte  
    783             || poBand->GetRasterDataType() == GDT_Int16 
    784             || poBand->GetRasterDataType() == GDT_UInt16 
    785             || poBand->GetRasterDataType() == GDT_Int32 ) 
     791                                 (bReadAsInt) ? (void*)panScanline : (void*)padfScanline, 
     792                                 nXSize, 1, (bReadAsInt) ? GDT_Int32 : GDT_Float64, 
     793                                 0, 0 ); 
     794 
     795        if( bReadAsInt ) 
    786796        { 
    787797            for ( iPixel = 0; iPixel < nXSize; iPixel++ ) 
    788798            { 
    789                 sprintf( szHeader, " %d", (int) padfScanline[iPixel] ); 
     799                sprintf( szHeader, " %d", panScanline[iPixel] ); 
    790800                if( VSIFWriteL( szHeader, strlen(szHeader), 1, fpImage ) != 1 ) 
    791801                { 
     
    822832    } 
    823833 
     834    CPLFree( panScanline ); 
    824835    CPLFree( padfScanline ); 
    825836    VSIFCloseL( fpImage );