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

Function CompressZip

SampleFramework11/v1.02/TinyEXR.cpp:6867–6926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

SaveEXRFunction · 0.85
SaveMultiChannelEXRFunction · 0.85

Calls 3

mz_compressBoundFunction · 0.85
mz_compressFunction · 0.85
atMethod · 0.80

Tested by

no test coverage detected