/* * public: * * dng_lossless_encoder(const uint16* srcData, * uint32 srcRows, * uint32 srcCols, * uint32 srcChannels, * uint32 srcBitDepth, * int32 srcRowStep, * int32 srcColStep, * dng_stream &stream); * * void Encode(); * * private: * * void EmitByte(uint8 value); * * void EmitBits(int code, int size); * * void FlushBits(); * * void CountOneDiff(int diff, uint32* countTable); * * void EncodeOneDiff(int diff, HuffmanTable* dctbl); * * void FreqCountSet(); * * void HuffEncode(); * * void GenHuffCoding(HuffmanTable* htbl, uint32* freq); * * void HuffOptimize(); * * void EmitMarker(JpegMarker mark); * * void Emit2bytes(int value); * * void EmitDht(int index); * * void EmitSof(JpegMarker code); * * void EmitSos(); * * void WriteFileHeader(); * * void WriteScanHeader(); * * void WriteFileTrailer(); * * }; * * /*****************************************************************************/ public DNGLosslessEncoder(uint16[] srcData, uint32 srcRows, uint32 srcCols, uint32 srcChannels, uint32 srcBitDepth, int32 srcRowStep, int32 srcColStep, dng_stream stream) { fSrcData = srcData; fSrcRows = srcRows; fSrcCols = srcCols; fSrcChannels = srcChannels; fSrcBitDepth = srcBitDepth; fSrcRowStep = srcRowStep; fSrcColStep = srcColStep; fStream = stream; huffPutBuffer = 0; huffPutBits = 0; // Initialize number of bits lookup table. numBitsTable[0] = 0; for (int i = 1; i < 256; i++) { int temp = i; int nbits = 1; while ((temp >>= 1) != 0) { nbits++; } numBitsTable[i] = nbits; } }
/*****************************************************************************/ static public void EncodeLosslessJPEG(uint16[] srcData, uint32 srcRows, uint32 srcCols, uint32 srcChannels, uint32 srcBitDepth, int32 srcRowStep, int32 srcColStep, dng_stream stream) { DNGLosslessEncoder encoder = new DNGLosslessEncoder(srcData, srcRows, srcCols, srcChannels, srcBitDepth, srcRowStep, srcColStep, stream); encoder.Encode(); }