Changeset 14749

Show
Ignore:
Timestamp:
06/21/08 20:17:46 (5 months ago)
Author:
warmerdam
Message:

add support for writing 1, 2 and 4 bit data (#2436)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/gdal/frmts/hfa/hfacompress.cpp

    r10645 r14749  
    3939  m_nDataTypeNumBits    = HFAGetDataTypeBits( m_nDataType ); 
    4040  m_nBlockSize  = nBlockSize; 
    41   m_nBlockCount = nBlockSize / ( m_nDataTypeNumBits / 8 )
     41  m_nBlockCount = (nBlockSize * 8) / m_nDataTypeNumBits
    4242 
    4343  /* Allocate some memory for the count and values - probably too big */ 
    4444  /* About right for worst case scenario tho */ 
    45   m_pCounts     = (GByte*)CPLMalloc( m_nBlockSize + sizeof(GUInt32) ); 
     45  m_pCounts     = (GByte*)CPLMalloc( m_nBlockCount + sizeof(GUInt32) ); 
    4646  m_nSizeCounts = 0; 
    4747   
    48   m_pValues     = (GByte*)CPLMalloc( m_nBlockSize + sizeof(GUInt32) ); 
     48  m_pValues     = (GByte*)CPLMalloc( m_nBlockCount + sizeof(GUInt32) ); 
    4949  m_nSizeValues = 0; 
    5050   
     
    7979 
    8080/* Gets the value from the uncompressed block as a GUInt32 no matter the data type */ 
    81 GUInt32 HFACompress::valueAsUInt32( GUInt32 index
    82 { 
    83 GUInt32 val = 0; 
     81GUInt32 HFACompress::valueAsUInt32( GUInt32 iPixel
     82{ 
     83  GUInt32 val = 0; 
    8484 
    8585  if( m_nDataTypeNumBits == 8 ) 
    8686  { 
    87     val = ((GByte*)m_pData)[index]; 
     87    val = ((GByte*)m_pData)[iPixel]; 
    8888  } 
    8989  else if( m_nDataTypeNumBits == 16 ) 
    9090  { 
    91     val = ((GUInt16*)m_pData)[index]; 
     91    val = ((GUInt16*)m_pData)[iPixel]; 
    9292  } 
    9393  else if( m_nDataTypeNumBits == 32 ) 
    9494  { 
    95     val = ((GUInt32*)m_pData)[index];  
     95    val = ((GUInt32*)m_pData)[iPixel];  
     96  } 
     97  else if( m_nDataTypeNumBits == 4 ) 
     98  { 
     99      if( iPixel % 2 == 0 ) 
     100          val = ((GByte*)m_pData)[iPixel/2] & 0x0f;   
     101      else 
     102          val = (((GByte*)m_pData)[iPixel/2] & 0xf0) >> 4; 
     103  } 
     104  else if( m_nDataTypeNumBits == 2 ) 
     105  { 
     106      if( iPixel % 2 == 0 ) 
     107          val = ((GByte*)m_pData)[iPixel/4] & 0x03;   
     108      else if( iPixel % 2 == 1 ) 
     109          val = (((GByte*)m_pData)[iPixel/4] & 0x0c) >> 2;   
     110      else if( iPixel % 2 == 2 ) 
     111          val = (((GByte*)m_pData)[iPixel/4] & 0x30) >> 4;   
     112      else  
     113          val = (((GByte*)m_pData)[iPixel/4] & 0xc0) >> 6;   
     114  } 
     115  else if( m_nDataTypeNumBits == 1 ) 
     116  { 
     117      if( ((GByte*)m_pData)[iPixel >> 3] & (0x1 << (iPixel & 0x07)) ) 
     118          val = 1; 
     119      else 
     120          val = 0; 
    96121  } 
    97122  else 
     
    272297  int nBits = HFAGetDataTypeBits( nHFADataType ); 
    273298   
    274   return ( nBits == 8 ) || ( nBits == 16 ) || ( nBits == 32 ); 
    275 
    276  
     299  return ( nBits == 8 ) || ( nBits == 16 ) || ( nBits == 32 ) || (nBits == 4) 
     300      || (nBits == 2) || (nBits == 1); 
     301
     302