MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / deflateNoCompression

Function deflateNoCompression

dependency/densecrf/examples/lodepng.cpp:1653–1688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1651/* /////////////////////////////////////////////////////////////////////////// */
1652
1653static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize)
1654{
1655 /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte,
1656 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
1657
1658 size_t i, j, numdeflateblocks = (datasize + 65534) / 65535;
1659 unsigned datapos = 0;
1660 for(i = 0; i != numdeflateblocks; ++i)
1661 {
1662 unsigned BFINAL, BTYPE, LEN, NLEN;
1663 unsigned char firstbyte;
1664
1665 BFINAL = (i == numdeflateblocks - 1);
1666 BTYPE = 0;
1667
1668 firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1));
1669 ucvector_push_back(out, firstbyte);
1670
1671 LEN = 65535;
1672 if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos;
1673 NLEN = 65535 - LEN;
1674
1675 ucvector_push_back(out, (unsigned char)(LEN & 255));
1676 ucvector_push_back(out, (unsigned char)(LEN >> 8));
1677 ucvector_push_back(out, (unsigned char)(NLEN & 255));
1678 ucvector_push_back(out, (unsigned char)(NLEN >> 8));
1679
1680 /*Decompressed data*/
1681 for(j = 0; j < 65535 && datapos < datasize; ++j)
1682 {
1683 ucvector_push_back(out, data[datapos++]);
1684 }
1685 }
1686
1687 return 0;
1688}
1689
1690/*
1691 write the lz77-encoded data, which has lit, len and dist codes, to compressed stream using huffman trees.

Callers 1

lodepng_deflatevFunction · 0.85

Calls 1

ucvector_push_backFunction · 0.85

Tested by

no test coverage detected