void ZopfliBlockSplit(const ZopfliOptions* options, const unsigned char* in, size_t instart, size_t inend, size_t maxblocks, size_t** splitpoints, size_t* npoints) { size_t pos = 0; size_t i; ZopfliBlockState s; size_t* lz77splitpoints = 0; size_t nlz77points = 0; ZopfliLZ77Store store; ZopfliHash hash; ZopfliHash* h = &hash; ZopfliInitLZ77Store(in, &store); ZopfliInitBlockState(options, instart, inend, 0, &s); ZopfliAllocHash(ZOPFLI_WINDOW_SIZE, h); *npoints = 0; *splitpoints = 0; /* Unintuitively, Using a simple LZ77 method here instead of ZopfliLZ77Optimal results in better blocks. */ ZopfliLZ77Greedy(&s, in, instart, inend, &store, h); ZopfliBlockSplitLZ77(options, &store, maxblocks, &lz77splitpoints, &nlz77points); /* Convert LZ77 positions to positions in the uncompressed input. */ pos = instart; if (nlz77points > 0) { for (i = 0; i < store.size; i++) { size_t length = store.dists[i] == 0 ? 1 : store.litlens[i]; if (lz77splitpoints[*npoints] == i) { ZOPFLI_APPEND_DATA(pos, splitpoints, npoints); if (*npoints == nlz77points) break; } pos += length; } } assert(*npoints == nlz77points); free(lz77splitpoints); ZopfliCleanBlockState(&s); ZopfliCleanLZ77Store(&store); ZopfliCleanHash(h); }
void ZopfliBlockSplit(const ZopfliOptions* options, const unsigned char* in, size_t instart, size_t inend, size_t maxblocks, size_t** splitpoints, size_t* npoints, size_t* startnpoints) { size_t pos = 0; size_t i; ZopfliBlockState s; size_t* lz77splitpoints = 0; size_t nlz77points = 0; ZopfliLZ77Store store; ZopfliInitLZ77Store(&store); s.options = options; s.blockstart = instart; s.blockend = inend; #ifdef ZOPFLI_LONGEST_MATCH_CACHE s.lmc = 0; #endif *npoints = 0; *splitpoints = 0; /* Unintuitively, Using a simple LZ77 method here instead of ZopfliLZ77Optimal results in better blocks. */ ZopfliLZ77Greedy(&s, in, instart, inend, &store, options); ZopfliBlockSplitLZ77(options, store.litlens, store.dists, store.size, maxblocks, &lz77splitpoints, &nlz77points, *startnpoints); /* Convert LZ77 positions to positions in the uncompressed input. */ pos = instart; if (nlz77points > 0) { for (i = 0; i < store.size; i++) { size_t length = store.dists[i] == 0 ? 1 : store.litlens[i]; if (lz77splitpoints[*npoints] == i) { ZOPFLI_APPEND_DATA(pos, splitpoints, npoints); if (*npoints == nlz77points) break; } pos += length; } } assert(*npoints == nlz77points); free(lz77splitpoints); ZopfliCleanLZ77Store(&store); }