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

Function CompressZip

SampleFramework12/v1.00/TinyEXR.cpp:6868–6927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6866}
6867
6868void CompressZip(unsigned char *dst, unsigned long long &compressedSize,
6869 const unsigned char *src, unsigned long srcSize) {
6870
6871 std::vector<unsigned char> tmpBuf(srcSize);
6872
6873 //
6874 // Apply EXR-specific? postprocess. Grabbed from OpenEXR's
6875 // ImfZipCompressor.cpp
6876 //
6877
6878 //
6879 // Reorder the pixel data.
6880 //
6881
6882 {
6883 char *t1 = (char *)&tmpBuf.at(0);
6884 char *t2 = (char *)&tmpBuf.at(0) + (srcSize + 1) / 2;
6885 const char *stop = (const char *)src + srcSize;
6886
6887 while (true) {
6888 if ((const char *)src < stop)
6889 *(t1++) = *(src++);
6890 else
6891 break;
6892
6893 if ((const char *)src < stop)
6894 *(t2++) = *(src++);
6895 else
6896 break;
6897 }
6898 }
6899
6900 //
6901 // Predictor.
6902 //
6903
6904 {
6905 unsigned char *t = &tmpBuf.at(0) + 1;
6906 unsigned char *stop = &tmpBuf.at(0) + srcSize;
6907 int p = t[-1];
6908
6909 while (t < stop) {
6910 int d = int(t[0]) - p + (128 + 256);
6911 p = t[0];
6912 t[0] = d;
6913 ++t;
6914 }
6915 }
6916
6917 //
6918 // Compress the data using miniz
6919 //
6920
6921 miniz::mz_ulong outSize = miniz::mz_compressBound(srcSize);
6922 int ret = miniz::mz_compress(dst, &outSize,
6923 (const unsigned char *)&tmpBuf.at(0), srcSize);
6924 assert(ret == miniz::MZ_OK);
6925

Callers 2

SaveEXRFunction · 0.85
SaveMultiChannelEXRFunction · 0.85

Calls 2

mz_compressBoundFunction · 0.85
mz_compressFunction · 0.85

Tested by

no test coverage detected