Sun's PNG decoders suck

Remember the problem we had with Sun’s ImageIO PNG decoder being unable to
correctly read transparency for PNGs with 8 bits per channel and color type 2?
I wrote a workaround for that which shunts those PNGs off to the Toolkit PNG
decoder, which can read them successfully.

Well, tonight somebody sent me an 8-bit type-2 PNG which causes the Toolkit’s
PNG decoder to throw an Exception which it swallows silently, so that you get
only a null back for the returned Image. I haven’t figured out what we need to
detect here in order to prevent this yet… Must be some feature of the PNG we
can spot beforehand. Of course, I’m not sure what we’re supposed to do if the
Toolkit chokes and ImageIO doesn’t render it properly.

Why can’t Sun provide a working PNG decoder?! It’s not that hard.

Thus spake “uckelman”:

This is Bug 2522301 for anyone keeping track.

I now know exaclty what the problem is and have solved it. What was wrong
was a combination of three things:

  1. There’s a program called SplitImage which some module designers use to
    slice countersheet images into individual counter images. This program writes
    broken PNGs. In particular, it writes 3-byte tRNS chunks for color type 2
    images, instead of 6-byte ones like it should according to the standard.

  2. We use Toolkit.createImage() to load color type 2 images instead of
    ImageIO.read() because the latter doesn’t handle tRNS chunks for those images
    correctly. The PNG decoder used by Toolkit.createImage() is less forgiving
    than the one used by ImageIO.read(), and returns a bogus Image with negative
    dimensions if you feed it a broken PNG (which is not documented, BTW).

  3. However, because it does return an Image (instead of null) and we never
    considered the possibility that it would return a junk Image, we end up
    converting it to a junk BufferedImage which has a null ColorModel—and that
    causes an NPE somewhere down the line.

So, I’ve added some additional code to ImageUtils.getImage() to check for
the case where Toolkit.createImage() fails, and in that case we log that
the PNG being loaded is broken and fallback to ImageIO.read() so that we
can display something which resembles the intended image.

Merge to trunk@4934, and 3.1@4935.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

This sounds like a utility we could/should include in VASSAL. It’s probably one of the most common things module designers do. It’s not terribly hard either.

This also begs the question: Why aren’t people using ImageMagick? Is it not available for Windows?

  • M.

Post generated using Mail2Forum (mail2forum.com)

Thus spake Michael Kiefte:

There are already several ways to do this:

  1. In the GIMP, you set guides where you want the cuts, and then select
    Image > Transform > Guillotine.

  2. This is pretty much trivial with ImageMagick, so long as you can specify
    the cuts in a regular way.

These are both freely available, and anyway are generally useful tools for
module designers. My feeling is that we will not be able to implement
something which does it better than either one of them, and so the effort
would be entirely wasted. We should instruct people on how to use the tools
which already exist rather than duplicating them badly ourselves.

Module creation tutorials need to mention these methods.

Raises the question, yes. (It doesn’t beg the question because you’re not
assuming the thing you’re trying to demonstrate. Sorry, that particular
misuse bugs me.)

I don’t know why people don’t use ImageMagick for this. I believe it is
available for Windows.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake Jeffrey Brent McBeth:

It would be a good thing to have a turorial which showed how to use
ImageMagick for module creation; also one which shows where the relevant
features are in the GIMP.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Because those of us with CS3 or Corel feel those programs are better perhaps? :slight_smile:

From: Michael Kiefte mkiefte@dal.ca
To: VASSAL Engine Forums Mailing List messages@forums.vassalengine.org
Sent: Wednesday, January 21, 2009 7:44:05 AM
Subject: Re: [Developers]Sun’s PNG decoders suck

This sounds like a utility we could/should include in VASSAL. It’s probably one of the most common things module designers do. It’s not terribly hard either.

This also begs the question: Why aren’t people using ImageMagick? Is it not available for Windows?

  • M.

Post generated using Mail2Forum (mail2forum.com)

What is CS3?

  • M.

2009/1/21 Timothy Mccarron <timothy.mccarron@sbcglobal.net (timothy.mccarron@sbcglobal.net)>

Post generated using Mail2Forum (mail2forum.com)

Probably Adobe CS3 suite: Photoshop & Illustrator being the most useful components for image and graphics work.

Gimp is similar to Photoshop. ImageMagick is a bit different, being fundamentally a command-line tool. And there’s also InkScape, which is more Illustrator like. All of these are free, whereas Adobe charges a fair amount for their (excellent) tools.

SplitImage is an excellent program that does nothing except cut up images, so it has a number of features that make it a much better choice than either GIMP or ImageMagick to do the actual cutting.

I use it all the time, but always transform the cut images afterwards by running them through ImageMagick via an auto-generated script to crop, scale and add a border. This fixes any problems in the images (lucky for me!). There is only a problem where people use the split images directly in a module.

This leaves you with a million new images that you must now individually name and save. This is extremely painful. The average counter sheet has some 200 counters. This is not a method I would recommend to my worst enemy. SplitImage names all of the split images for you using a user supplied prefix and a counter and saves them all to a folder.

Having processed close to 50 countersheets sourced direct from the artist over the last year or so, I have yet to find one where you could specify the cuts in a regular way.

SplitImage allows you to drag guidelines (similiar to the Gimp guides), or to specify a regular grid, that you can then modify manually for an exact fit.

SplitImage is far superior to any other tool, with the caveat that you must resave the images using another image program. I’m adding this caveat to the FAQ pages.

I’m with Michael a bit on this one though, I think it would be fairly easy to a write a tool for the module editor to do this, using SplitImage as the spec. Perhaps we could even provide a basic front-end to ImageMagick to allow cropping, scaling, bordering etc. and then pump the results into my new Mass Piece Loader to have the counters auto-magically generated?

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

If that’s your sole complaint about using GIMP for this job, then it’s easily
addressed. What you need is a Script-Fu script which will name and save all
of the resulting images for you. I haven’t looked for one, but I wouldn’t
be surprised at all if one existed already. If there isn’t one, then writing
one would be a better use of our efforts and far more efficient than creating
a custom program for chopping images—such a script wouldn’t run to more
than a few dozen lines.

Have you done a lot of games where there is a mix of counter sizes all on
one countersheet?


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake Joel Uckelman:

I did some looking around, and discovered that a Script-Fu scirpt isn’t
even necessary for this—it turns out that neither of us looked in the
right place in GIMP. Guillotine does give you all of the pieces as open
images. If you want them all saved with a given prefix instead, then you
want Filters > Web > Slice.

Slice does exactly what you requested. So, again: I contend that there
is no need for us to create such a thing ourselves. :slight_smile:


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

I have just installed the latest 2.6.4 Gimp and I have no Slice in my Web filters menu. Is this something you downloaded seperately?

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

No, none, but between gutters and artists not feeling the need to be pixel perfect, I rarely find a counter sheet that you can place a fixed grid over.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

I wasn’t talking about a uniform grid. It should be possible to specify
irregularly-spaced cuts with ImageMagick.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

I also have GIMP 2.6.4. Slice is not something I added myself, though it
does appear to be part of python-fu.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Yes, you may be able to do it in ImageMagick, but there is no comparison in ease of use.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

I agree. I think it’s probably going to be a lot easier to do in ImageMagick,
especially if you’re going to to several sheets with the same layout or if
you’re doing a bunch of other scripted processing after cutting the sheets.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Actually, my argument was that SplitImage wins the ease of use contest hands down, followed by Gimp/Slice (It is practically impossible for the average Windows user to install it), followed by ImageMagick running a long way last :slight_smile:

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

It appears that you need Python installed in order to activate the python-fu
scripts in GIMP. We could provide instructions for that.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

Would you like to find a way to contact the author of SplitImage, then, so
he can fix his bug? I’ve tried, but the only email address I found on his
site (which seems not to have been updated since 2005) bounces.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)