MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / deflateNoCompression

Function deflateNoCompression

external/lodepng/lodepng.cpp:1740–1771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1738/* /////////////////////////////////////////////////////////////////////////// */
1739
1740static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize) {
1741 /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte,
1742 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
1743
1744 size_t i, numdeflateblocks = (datasize + 65534u) / 65535u;
1745 size_t datapos = 0;
1746 for(i = 0; i != numdeflateblocks; ++i) {
1747 unsigned BFINAL, BTYPE, LEN, NLEN;
1748 unsigned char firstbyte;
1749 size_t pos = out->size;
1750
1751 BFINAL = (i == numdeflateblocks - 1);
1752 BTYPE = 0;
1753
1754 LEN = 65535;
1755 if(datasize - datapos < 65535u) LEN = (unsigned)datasize - (unsigned)datapos;
1756 NLEN = 65535 - LEN;
1757
1758 if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/
1759
1760 firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1u) << 1u) + ((BTYPE & 2u) << 1u));
1761 out->data[pos + 0] = firstbyte;
1762 out->data[pos + 1] = (unsigned char)(LEN & 255);
1763 out->data[pos + 2] = (unsigned char)(LEN >> 8u);
1764 out->data[pos + 3] = (unsigned char)(NLEN & 255);
1765 out->data[pos + 4] = (unsigned char)(NLEN >> 8u);
1766 lodepng_memcpy(out->data + pos + 5, data + datapos, LEN);
1767 datapos += LEN;
1768 }
1769
1770 return 0;
1771}
1772
1773/*
1774write 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