PNG compression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Harrop

    #1

    PNG compression


    I just added save-to-PNG to our software and noticed that WPF generates
    enormous PNG files. Re-encoding them under Linux makes them 20x smaller.

    Is it possible to enable compression under .NET or is PNG not properly
    supported?

    --
    Dr Jon D Harrop, Flying Frog Consultancy Ltd.
    Business Das perfekte Beratungsgespräch: Tipps und Tricks Sabine Henschel4. Juli 2024 Business Mindset Coach: Ihr Schlüssel zu einem neuen Denken Sabine Henschel4. Juli 2024 Familie Kollegiale Beratung in der Pflege: Zusammen stark Sabine Henschel3. Juli 2024 Familie Was kostet eine Beratung beim Notar wegen Erbrecht: Ein Ratgeber Sabine Henschel2. Juli 2024 Business Was kostet eine

  • Peter Duniho

    #2
    Re: PNG compression

    On Sun, 12 Oct 2008 04:20:42 -0700, Jon Harrop <jon@ffconsulta ncy.com>
    wrote:
    I just added save-to-PNG to our software and noticed that WPF generates
    enormous PNG files. Re-encoding them under Linux makes them 20x smaller.
    >
    Is it possible to enable compression under .NET or is PNG not properly
    supported?
    PNG is always compressed. But there's a myriad of parameters that can be
    applied as part of the compression, and .NET doesn't offer any way to
    control them. You're stuck with the defaults.

    I'm intrigued that you have images that can be compressed 20x smaller.
    I've never seen .NET's PNG perform so poorly compared to other
    implementations . It sounds as though you are either a) using a utility on
    Linux that does a broad search of the different parameters, testing to
    find the best compression technique for the image, or b) you have an image
    that just happens to be able to be compressed optimally by whatever
    compression parameters are used on Linux (whether explicitly or as
    built-in defaults).

    I suppose a third possibility is that you are not actually saving the
    images as PNG files in .NET even though you think you are. That would
    certainly explain such a large disparity.

    In any case, unless you post more details, including the exact code you're
    using in .NET to save the PNG files, as well as a detailed description of
    how you compress them under Linux, it's not clear to me that anyone could
    offer any sort of specific advice.

    Pete

    Comment

    • Jon Harrop

      #3
      Re: PNG compression

      Peter Duniho wrote:
      On Sun, 12 Oct 2008 04:20:42 -0700, Jon Harrop <jon@ffconsulta ncy.com>
      wrote:
      >I just added save-to-PNG to our software and noticed that WPF generates
      >enormous PNG files. Re-encoding them under Linux makes them 20x smaller.
      >>
      >Is it possible to enable compression under .NET or is PNG not properly
      >supported?
      To answer my own question: PNG is not fully supported by .NET.
      PNG is always compressed.
      Here is an excerpt from the PNG specification about its support for
      uncompressed images:

      "It is possible to store uncompressed data by using only uncompressed
      deflate blocks (a feature normally used to guarantee that deflate does not
      make incompressible data much larger)." -
      http://www.w3.org/TR/PNG-Rationale.html

      For example, here is a concrete implementation in OCaml:


      But there's a myriad of parameters that can be applied as part of the
      compression, and .NET doesn't offer any way to control them. You're stuck
      with the defaults.
      Indeed.
      I'm intrigued that you have images that can be compressed 20x smaller.
      I've never seen .NET's PNG perform so poorly compared to other
      implementations . It sounds as though you are either a) using a utility on
      Linux that does a broad search of the different parameters, testing to
      find the best compression technique for the image,
      I am using image magick with its default settings.
      or b) you have an image
      that just happens to be able to be compressed optimally by whatever
      compression parameters are used on Linux (whether explicitly or as
      built-in defaults).
      That appears to be the case. I have tested with several other images and
      they are typically only 50% more bloated when generated by .NET but some
      are much worse.
      I suppose a third possibility is that you are not actually saving the
      images as PNG files in .NET even though you think you are.
      I have verified that these are genuine PNG images and that the binary result
      after decompression is always identical to the original.
      In any case, unless you post more details, including the exact code you're
      using in .NET to save the PNG files, as well as a detailed description of
      how you compress them under Linux, it's not clear to me that anyone could
      offer any sort of specific advice.
      I just wanted to confirm that .NET provides only very rudimentary support
      for PNG encoding.

      --
      Dr Jon D Harrop, Flying Frog Consultancy Ltd.
      Business Das perfekte Beratungsgespräch: Tipps und Tricks Sabine Henschel4. Juli 2024 Business Mindset Coach: Ihr Schlüssel zu einem neuen Denken Sabine Henschel4. Juli 2024 Familie Kollegiale Beratung in der Pflege: Zusammen stark Sabine Henschel3. Juli 2024 Familie Was kostet eine Beratung beim Notar wegen Erbrecht: Ein Ratgeber Sabine Henschel2. Juli 2024 Business Was kostet eine

      Comment

      • Peter Duniho

        #4
        Re: PNG compression

        On Mon, 13 Oct 2008 19:01:14 -0700, Jon Harrop <jon@ffconsulta ncy.com>
        wrote:
        [...]
        >PNG is always compressed.
        >
        Here is an excerpt from the PNG specification about its support for
        uncompressed images:
        I guess I should have been more specific. My point was that .NET always
        tries to compress PNGs by default. You'd have to intentionally disable
        compression, and off the top of my head, I don't recall any codec settings
        that you can use with PNG that would do that (there's an
        EncoderValue.Co mpressionNone enumeration value, but AFAIK you can only use
        that with TIFF files).
        "It is possible to store uncompressed data by using only uncompressed
        deflate blocks (a feature normally used to guarantee that deflate does
        not
        make incompressible data much larger)." -
        http://www.w3.org/TR/PNG-Rationale.html
        Sure, but .NET doesn't do that.

        Of course, that point does raise the question: have you compared an
        explicitly uncompressed PNG generated with software that _does_ give you
        that level of control with the output from .NET? For uncompressed images,
        the data in the file should be byte-for-byte identical (or nearly so, if
        there are some header differences or something minor like that).

        Or at the very least, compared the PNG output size from .NET to the
        nominal uncompressed size of your data? That would give you direct,
        reliable information about just how much, if at all, .NET is compressing
        your image.

        Since you haven't posted the code here, whatever I or anyone else might
        write about what .NET is doing in your case is pure speculation. Garbage
        in, garbage out.
        [...]
        I just wanted to confirm that .NET provides only very rudimentary support
        for PNG encoding.
        ..NET provides only very rudimentary support for PNG encoding.

        Pete

        Comment

        • Michael J. Ryan

          #5
          Re: PNG compression

          On 10/12/2008 4:20 AM, Jon Harrop wrote:
          I just added save-to-PNG to our software and noticed that WPF generates
          enormous PNG files. Re-encoding them under Linux makes them 20x smaller.
          >
          Is it possible to enable compression under .NET or is PNG not properly
          supported?
          use an external exe like pngcrush to compress the png, this will require you
          to launch an external process, and probably hide it from the user.. if this is
          a desktop application, it shouldn't be too bad... it would be a small-ish
          exe... it's also available cross-platform.

          --
          Michael J. Ryan - tracker1(at)the roughnecks(dot) net - www.theroughnecks.net
          icq: 4935386 - AIM/AOL: azTracker1 - Y!: azTracker1 - MSN/Win: (email)

          .... FRA #261: A wealthy man can afford anything except a conscience.

          Comment

          • Jon Harrop

            #6
            Re: PNG compression

            Michael J. Ryan wrote:
            On 10/12/2008 4:20 AM, Jon Harrop wrote:
            >I just added save-to-PNG to our software and noticed that WPF generates
            >enormous PNG files. Re-encoding them under Linux makes them 20x smaller.
            >>
            >Is it possible to enable compression under .NET or is PNG not properly
            >supported?
            >
            use an external exe like pngcrush to compress the png, this will require
            you to launch an external process, and probably hide it from the user.. if
            this is a desktop application, it shouldn't be too bad... it would be a
            small-ish exe... it's also available cross-platform.
            Yes. Would anyone be interested in a C# translation of a real PNG codec as a
            commercial product?

            --
            Dr Jon D Harrop, Flying Frog Consultancy Ltd.
            Business Das perfekte Beratungsgespräch: Tipps und Tricks Sabine Henschel4. Juli 2024 Business Mindset Coach: Ihr Schlüssel zu einem neuen Denken Sabine Henschel4. Juli 2024 Familie Kollegiale Beratung in der Pflege: Zusammen stark Sabine Henschel3. Juli 2024 Familie Was kostet eine Beratung beim Notar wegen Erbrecht: Ein Ratgeber Sabine Henschel2. Juli 2024 Business Was kostet eine

            Comment

            Working...