MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / deflateNoCompression

Function deflateNoCompression

src/lodepng.cpp:1600–1635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1598/* /////////////////////////////////////////////////////////////////////////// */
1599
1600static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize)
1601{
1602 /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte,
1603 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
1604
1605 size_t i, j, numdeflateblocks = (datasize + 65534) / 65535;
1606 unsigned datapos = 0;
1607 for(i = 0; i < numdeflateblocks; i++)
1608 {
1609 unsigned BFINAL, BTYPE, LEN, NLEN;
1610 unsigned char firstbyte;
1611
1612 BFINAL = (i == numdeflateblocks - 1);
1613 BTYPE = 0;
1614
1615 firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1));
1616 ucvector_push_back(out, firstbyte);
1617
1618 LEN = 65535;
1619 if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos;
1620 NLEN = 65535 - LEN;
1621
1622 ucvector_push_back(out, (unsigned char)(LEN % 256));
1623 ucvector_push_back(out, (unsigned char)(LEN / 256));
1624 ucvector_push_back(out, (unsigned char)(NLEN % 256));
1625 ucvector_push_back(out, (unsigned char)(NLEN / 256));
1626
1627 /*Decompressed data*/
1628 for(j = 0; j < 65535 && datapos < datasize; j++)
1629 {
1630 ucvector_push_back(out, data[datapos++]);
1631 }
1632 }
1633
1634 return 0;
1635}
1636
1637/*
1638write 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