Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZopfliStream not working? #4

Open
ied206 opened this issue Jan 30, 2018 · 2 comments
Open

ZopfliStream not working? #4

ied206 opened this issue Jan 30, 2018 · 2 comments

Comments

@ied206
Copy link
Contributor

ied206 commented Jan 30, 2018

To fix issue #2 myself, I cloned this repositiory and executed unit tests.

By upgrading NUint to 3 and installing NUnit3Adapter nuget I was able to run IntegrationTests.cs, but the tests just stuck and never end. It is strange because tests reside on PNGCompressTests.cs works without a problem. It happens regardless of my patch (PR #3) to ZopfliStream.

@ied206
Copy link
Contributor Author

ied206 commented Jan 30, 2018

When I debug tests, the freeze comes from Zopfli.compress() funtion call.

@chylex
Copy link

chylex commented Apr 13, 2018

I experienced freezes when I used an "output sink" to disable verbose output, because the options didn't work. It turns out there's some critical error either in the way libzopfli-sharp passes ZopfliOptions to the native lib, or in the current build of the zopfli library itself - somehow it was passing a pointer to memory that was changing, and producing invalid data (like turning a 300 kB stream into 12 bytes).

I built my own version from source to work around it:
zopfli_lib.c

void ZopfliCompress(ZopfliOptions* options_unused, ZopfliFormat output_type,
                    const unsigned char* in, size_t insize,
                    unsigned char** out, size_t* outsize) {
  ZopfliOptions options;

  options.verbose = 0;
  options.verbose_more = 0;
  options.numiterations = 15;
  options.blocksplitting = 1;
  options.blocksplittinglast = 0;
  options.blocksplittingmax = 15;

  if (output_type == ZOPFLI_FORMAT_GZIP) {
    ZopfliGzipCompress(&options, in, insize, out, outsize);
  } else if (output_type == ZOPFLI_FORMAT_ZLIB) {
    ZopfliZlibCompress(&options, in, insize, out, outsize);
  } else if (output_type == ZOPFLI_FORMAT_DEFLATE) {
    unsigned char bp = 0;
    ZopfliDeflate(&options, 2 /* Dynamic block */, 1,
                  in, insize, &bp, out, outsize);
  } else {
    assert(0);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants