473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.
http://www.ffconsultancy.com/?u
Oct 12 '08 #1
5 6246
On Sun, 12 Oct 2008 04:20:42 -0700, Jon Harrop <jo*@ffconsultancy.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
Oct 12 '08 #2
Peter Duniho wrote:
On Sun, 12 Oct 2008 04:20:42 -0700, Jon Harrop <jo*@ffconsultancy.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:

http://code.google.com/p/aihiot/sour...p/ocaml/png.ml
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.
http://www.ffconsultancy.com/?u
Oct 14 '08 #3
On Mon, 13 Oct 2008 19:01:14 -0700, Jon Harrop <jo*@ffconsultancy.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.CompressionNone 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
Oct 14 '08 #4
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)theroughnecks(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.
Oct 16 '08 #5
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.
http://www.ffconsultancy.com/?u
Oct 17 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim Hubbard | last post by:
I went to the compression newsgroups, but all I saw was spam. So, I thought I'd post his question here to get the best info I could from other programmers. Which compression algorithm offers...
1
by: Maurice Mertens | last post by:
Hello, I'm having troubles with saving a tiff-file with a certain compression and colordepth. This is the code I use: ----------------------------------------------------------------------...
8
by: Anurag | last post by:
Hi, I am told that Oracle has this "data compression" feature that allows you to store online data ina compressed format. This is different from archived data - you compress only that data which...
2
by: deko | last post by:
Is it best practice to set Unicode Compression to "No" for memo fields in a table? What about text fields? According to the VB help entry: "Data in a Memo field is not compressed unless it...
17
by: dunric | last post by:
After writing the computing urban legend "The Helsinki Code", I spent several nights thinking up how in the world Gustav Larsson, the Finnish PDP-8 computer programmer, could have managed to...
1
by: chris.atlee | last post by:
I'm writing a program in python that creates tar files of a certain maximum size (to fit onto CD/DVD). One of the problems I'm running into is that when using compression, it's pretty much...
3
by: Benny Ng | last post by:
Dear All, Now I met some performance problems in my application. Because according to our business. The size of some web forms are larger than 1xxx MB. So it takes a long time for user opening a...
20
by: chance | last post by:
Hello, I want to add compression to a memory stream and save it in an Oracle database. This is the code I have so far: //save the Word document to a binary field, MemoryStream dataStream = new...
21
by: =?Utf-8?B?VkJB?= | last post by:
I compressed a file with GZipStream class and is larger than the original file.... how can this be?, the original file is 737 KB and the "compressed" file is 1.1 MB. Did i miss something or is...
3
by: GiJeet | last post by:
Hello, we have an app that scans documents into TIFF format and we need to transfer them over the internet. If anyone knows of a SDK we can use that can compress TIFFs on the fly or even if it can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.