Changeset 14709

Show
Ignore:
Timestamp:
06/14/08 19:41:14 (6 months ago)
Author:
rouault
Message:

Fix HFA EPT_f32 readuced precision (#1000)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/hfa/hfaband.cpp

    r13515 r14709  
    485485 
    486486/* -------------------------------------------------------------------- */ 
    487 /*      For floating point output, the saved 16-bit value will be       */ 
    488 /*      based on the minimum value for the tile. Note that the there    */ 
    489 /*      still seems to be some problems selecting the correct factor    */ 
    490 /*      right near a power of 2 boundary (like 512). I have not been    */ 
    491 /*      able to determine how the switchover occurs at power of 2       */ 
    492 /*      boundaries for the minimum value. (#1000)                       */ 
    493 /* -------------------------------------------------------------------- */ 
    494         float fMultFactor = 1.0; 
    495         float fMinValue = 0.0; 
    496         if ( nDataType == EPT_f32 ) 
    497         { 
    498             fMinValue = *((float *) &nDataMin); 
    499  
    500             int nDataMin = ( fMinValue > 0.0 ) ? (int)fMinValue : (int)-fMinValue; 
    501             int nDivShift = -9; 
    502  
    503             for ( ; ( nDataMin > 0 ); nDivShift++, nDataMin >>= 1 ) {} 
    504             if ( nDivShift < 0 ) 
    505             { 
    506                 nDivShift = -nDivShift; 
    507                 fMultFactor = 1.0 / ( 1 << nDivShift ); 
    508             } 
    509             else 
    510             { 
    511                 fMultFactor = ( 1 << nDivShift ); 
    512             } 
    513         } 
    514  
    515 /* -------------------------------------------------------------------- */ 
    516487/*      Loop over block pixels.                                         */ 
    517488/* -------------------------------------------------------------------- */ 
     
    623594                ((GUInt32 *) pabyDest)[nPixelsOutput] = nDataValue; 
    624595            } 
    625 /* -------------------------------------------------------------------- */ 
    626 /*      Note, floating point values are handled somewhat                */ 
    627 /*      differently, and I've only been able to test f32 with a         */ 
    628 /*      16bit offset value (see bug #1000 and                           */ 
    629 /*      data/imagine/bug1000/float.img)                                 */ 
    630 /* -------------------------------------------------------------------- */ 
    631596            else if( nDataType == EPT_f32 ) 
    632597            { 
    633                 float fValue; 
    634  
    635                 if( nNumBits == 16 ) 
    636                     fValue = fMinValue + fMultFactor * (nRawValue / 32768.0); 
    637                 else 
    638                     CPLAssert( FALSE ); 
    639                  
    640                 ((float *) pabyDest)[nPixelsOutput] = fValue; 
     598/* -------------------------------------------------------------------- */ 
     599/*      Note, floating point values are handled as if they were signed  */ 
     600/*      32-bit integers (bug #1000).                                    */ 
     601/* -------------------------------------------------------------------- */ 
     602                ((float *) pabyDest)[nPixelsOutput] = *((float*)( &nDataValue )); 
    641603            } 
    642604            else