MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / mz_deflate

Function mz_deflate

SampleFramework12/v1.00/TinyEXR.cpp:1539–1592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1537}
1538
1539int mz_deflate(mz_streamp pStream, int flush) {
1540 size_t in_bytes, out_bytes;
1541 mz_ulong orig_total_in, orig_total_out;
1542 int mz_status = MZ_OK;
1543
1544 if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) ||
1545 (!pStream->next_out))
1546 return MZ_STREAM_ERROR;
1547 if (!pStream->avail_out)
1548 return MZ_BUF_ERROR;
1549
1550 if (flush == MZ_PARTIAL_FLUSH)
1551 flush = MZ_SYNC_FLUSH;
1552
1553 if (((tdefl_compressor *)pStream->state)->m_prev_return_status ==
1554 TDEFL_STATUS_DONE)
1555 return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR;
1556
1557 orig_total_in = pStream->total_in;
1558 orig_total_out = pStream->total_out;
1559 for (;;) {
1560 tdefl_status defl_status;
1561 in_bytes = pStream->avail_in;
1562 out_bytes = pStream->avail_out;
1563
1564 defl_status = tdefl_compress((tdefl_compressor *)pStream->state,
1565 pStream->next_in, &in_bytes, pStream->next_out,
1566 &out_bytes, (tdefl_flush)flush);
1567 pStream->next_in += (mz_uint)in_bytes;
1568 pStream->avail_in -= (mz_uint)in_bytes;
1569 pStream->total_in += (mz_uint)in_bytes;
1570 pStream->adler = tdefl_get_adler32((tdefl_compressor *)pStream->state);
1571
1572 pStream->next_out += (mz_uint)out_bytes;
1573 pStream->avail_out -= (mz_uint)out_bytes;
1574 pStream->total_out += (mz_uint)out_bytes;
1575
1576 if (defl_status < 0) {
1577 mz_status = MZ_STREAM_ERROR;
1578 break;
1579 } else if (defl_status == TDEFL_STATUS_DONE) {
1580 mz_status = MZ_STREAM_END;
1581 break;
1582 } else if (!pStream->avail_out)
1583 break;
1584 else if ((!pStream->avail_in) && (flush != MZ_FINISH)) {
1585 if ((flush) || (pStream->total_in != orig_total_in) ||
1586 (pStream->total_out != orig_total_out))
1587 break;
1588 return MZ_BUF_ERROR; // Can't make forward progress without some input.
1589 }
1590 }
1591 return mz_status;
1592}
1593
1594int mz_deflateEnd(mz_streamp pStream) {
1595 if (!pStream)

Callers 1

mz_compress2Function · 0.85

Calls 2

tdefl_compressFunction · 0.85
tdefl_get_adler32Function · 0.85

Tested by

no test coverage detected