MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / deflateNoCompression

Function deflateNoCompression

samples/shared/lodepng.cpp:1624–1659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1622/* /////////////////////////////////////////////////////////////////////////// */
1623
1624static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize)
1625{
1626 /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte,
1627 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
1628
1629 size_t i, j, numdeflateblocks = (datasize + 65534) / 65535;
1630 unsigned datapos = 0;
1631 for(i = 0; i < numdeflateblocks; i++)
1632 {
1633 unsigned BFINAL, BTYPE, LEN, NLEN;
1634 unsigned char firstbyte;
1635
1636 BFINAL = (i == numdeflateblocks - 1);
1637 BTYPE = 0;
1638
1639 firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1));
1640 ucvector_push_back(out, firstbyte);
1641
1642 LEN = 65535;
1643 if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos;
1644 NLEN = 65535 - LEN;
1645
1646 ucvector_push_back(out, (unsigned char)(LEN % 256));
1647 ucvector_push_back(out, (unsigned char)(LEN / 256));
1648 ucvector_push_back(out, (unsigned char)(NLEN % 256));
1649 ucvector_push_back(out, (unsigned char)(NLEN / 256));
1650
1651 /*Decompressed data*/
1652 for(j = 0; j < 65535 && datapos < datasize; j++)
1653 {
1654 ucvector_push_back(out, data[datapos++]);
1655 }
1656 }
1657
1658 return 0;
1659}
1660
1661/*
1662write 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