FACT++  1.0
uint32_t zofits::compressHUFFMAN16 ( char *  dest,
const char *  src,
uint32_t  numRows,
uint32_t  sizeOfElems,
uint32_t  numRowElems 
)
inlineprotected

Do huffman encoding

Parameters
destthe buffer that will receive the compressed data
srcthe buffer hosting the transposed data
numRowsnumber of rows of data in the transposed buffer
sizeOfElemssize in bytes of one data elements
numRowElemsnumber of elements on each row
Returns
number of bytes written

Definition at line 900 of file zofits.h.

References ___err___, Huffman::Encode(), and gLog.

Referenced by factofits::WriteDrsOffsetsTable().

901  {
902  std::string huffmanOutput;
903  uint32_t previousHuffmanSize = 0;
904 
905  //if we have less than 2 elems to compress, Huffman encoder does not work (and has no point). Just return larger size than uncompressed to trigger the raw storage.
906  if (numRows < 2)
907  return numRows*sizeOfElems*numRowElems + 1000;
908 
909  if (sizeOfElems < 2 )
910  {
911 #ifdef __EXCEPTIONS
912  throw std::runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types");
913 #else
914  gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types" << std::endl;
915  return 0;
916 #endif
917  }
918 
919  uint32_t huffmanOffset = 0;
920  for (uint32_t j=0;j<numRowElems;j++)
921  {
922  Huffman::Encode(huffmanOutput,
923  reinterpret_cast<const uint16_t*>(&src[j*sizeOfElems*numRows]),
924  numRows*(sizeOfElems/2));
925  reinterpret_cast<uint32_t*>(&dest[huffmanOffset])[0] = huffmanOutput.size() - previousHuffmanSize;
926  huffmanOffset += sizeof(uint32_t);
927  previousHuffmanSize = huffmanOutput.size();
928  }
929 
930  const size_t totalSize = huffmanOutput.size() + huffmanOffset;
931 
932  //only copy if not larger than not-compressed size
933  if (totalSize < numRows*sizeOfElems*numRowElems)
934  memcpy(&dest[huffmanOffset], huffmanOutput.data(), huffmanOutput.size());
935 
936  return totalSize;
937  }
#define gLog
Definition: fits.h:36
#define ___err___
Definition: fits.h:37
bool Encode(std::string &bufout, const uint16_t *bufin, size_t bufinlen)
Definition: huffman.h:385
uint32_t numRows
Definition: FITS.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function: