int SDTSRasterReader::GetMinMax( double * pdfMin, double * pdfMax,
                                 double dfNoData )

{
    void	*pBuffer;
    int		bFirst = TRUE;
    int		b32Bit = GetRasterType() == SDTS_RT_FLOAT32;

    CPLAssert( GetBlockXSize() == GetXSize() && GetBlockYSize() == 1 );
    
    pBuffer = CPLMalloc(sizeof(float) * GetXSize());

    for( int iLine = 0; iLine < GetYSize(); iLine++ )
    {
        if( !GetBlock( 0, iLine, pBuffer ) )
        {
            CPLFree( pBuffer );
            return FALSE;
        }

        for( int iPixel = 0; iPixel < GetXSize(); iPixel++ )
        {
            double	dfValue;
            
            if( b32Bit )
                dfValue = ((float *) pBuffer)[iPixel];
            else
                dfValue = ((short *) pBuffer)[iPixel];

            if( dfValue != dfNoData )
            {
                if( bFirst )
                {
                    *pdfMin = *pdfMax = dfValue;
                    bFirst = FALSE;
                }
                else
                {
                    *pdfMin = MIN(*pdfMin,dfValue);
                    *pdfMax = MAX(*pdfMax,dfValue);
                }
            }
        }
    }

    CPLFree( pBuffer );
    
    return !bFirst;
}
Beispiel #2
0
int SDTSRasterReader::GetMinMax( double * pdfMin, double * pdfMax,
                                 double dfNoData )

{
    CPLAssert( GetBlockXSize() == GetXSize() && GetBlockYSize() == 1 );

    bool bFirst = true;
    const bool b32Bit = GetRasterType() == SDTS_RT_FLOAT32;
    void *pBuffer = CPLMalloc(sizeof(float) * GetXSize());

    for( int iLine = 0; iLine < GetYSize(); iLine++ )
    {
        if( !GetBlock( 0, iLine, pBuffer ) )
        {
            CPLFree( pBuffer );
            return FALSE;
        }

        for( int iPixel = 0; iPixel < GetXSize(); iPixel++ )
        {
            double dfValue;

            if( b32Bit )
                dfValue = reinterpret_cast<float *>( pBuffer )[iPixel];
            else
                dfValue = reinterpret_cast<short *>( pBuffer )[iPixel];

            if( dfValue != dfNoData )
            {
                if( bFirst )
                {
                    *pdfMin = dfValue;
                    *pdfMax = dfValue;
                    bFirst = false;
                }
                else
                {
                    *pdfMin = std::min( *pdfMin, dfValue );
                    *pdfMax = std::max( *pdfMax, dfValue );
                }
            }
        }
    }

    CPLFree( pBuffer );

    return !bFirst;
}