MCPcopy Create free account
hub / github.com/DFHack/dfhack / deflateNoCompression

Function deflateNoCompression

depends/lodepng/lodepng.cpp:1744–1775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1742/* /////////////////////////////////////////////////////////////////////////// */
1743
1744static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize) {
1745 /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte,
1746 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
1747
1748 size_t i, numdeflateblocks = (datasize + 65534u) / 65535u;
1749 unsigned datapos = 0;
1750 for(i = 0; i != numdeflateblocks; ++i) {
1751 unsigned BFINAL, BTYPE, LEN, NLEN;
1752 unsigned char firstbyte;
1753 size_t pos = out->size;
1754
1755 BFINAL = (i == numdeflateblocks - 1);
1756 BTYPE = 0;
1757
1758 LEN = 65535;
1759 if(datasize - datapos < 65535u) LEN = (unsigned)datasize - datapos;
1760 NLEN = 65535 - LEN;
1761
1762 if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/
1763
1764 firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1u) << 1u) + ((BTYPE & 2u) << 1u));
1765 out->data[pos + 0] = firstbyte;
1766 out->data[pos + 1] = (unsigned char)(LEN & 255);
1767 out->data[pos + 2] = (unsigned char)(LEN >> 8u);
1768 out->data[pos + 3] = (unsigned char)(NLEN & 255);
1769 out->data[pos + 4] = (unsigned char)(NLEN >> 8u);
1770 lodepng_memcpy(out->data + pos + 5, data + datapos, LEN);
1771 datapos += LEN;
1772 }
1773
1774 return 0;
1775}
1776
1777/*
1778write the lz77-encoded data, which has lit, len and dist codes, to compressed stream using huffman trees.

Callers 1

lodepng_deflatevFunction · 0.85

Calls 2

ucvector_resizeFunction · 0.85
lodepng_memcpyFunction · 0.85

Tested by

no test coverage detected