Giter VIP home page Giter VIP logo

Comments (3)

lvandeve avatar lvandeve commented on July 23, 2024

An example of using a custom codec is here:
https://github.com/google/zopfli/blob/master/src/zopflipng/zopflipng_lib.cc#L171
It's an encoder there, but it's simimar to set a decoder.

An example of using zlib (deflate) with unknown size is here:
https://github.com/madler/zlib/blob/master/test/example.c#L258

What you suggest could be interesting: Normally you do not know the decompressed size of a zlib stream beforehand, but in the case of PNG you can of course compute it given width, height, color model etc... It's of course not a trivial computation (with various subtleties about how to end sub-byte pixels at scanlines etc...) but possible. Of course a bad PNG file could contain a zlib stream in it that has a larger size anyway for some reason, so it would never be guaranteed. This may be a possible optimization in the future. For now, it's with unknown size though.

from lodepng.

powof2 avatar powof2 commented on July 23, 2024

I said so because there are already 'predict' bytes memory allocated to scanlines, its size is 'predict and expecting decoded size is 'predict' too.

  // here predict bytes memory are allocated (reserved) to scanlines
  if(!state->error && !ucvector_reserve(&scanlines, predict)) state->error = 83; /*alloc fail*/
  if(!state->error)
  {
    state->error = zlib_decompress(&scanlines.data, &scanlines.size, idat.data,
                                   idat.size, &state->decoder.zlibsettings);
    if(!state->error && scanlines.size != predict) state->error = 91; /*decompressed size doesn't match prediction*/
  }

but it does not matter since it is possible to decode with unknown size, thank you for the link.

from lodepng.

zpul avatar zpul commented on July 23, 2024

do you have some examples of using standard zlib with lodepng ?

from lodepng.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.