Archive for November, 2003

Simplifying Hand-Drawn Curves

Saturday, November 22nd, 2003

I have just published a new tutorial on KevLinDev that discusses a method for simplifying hand-drawn curves. The algorithm allows you to specify a tolerance so you can control the quality of the final curve as visually compared to the original curve. The tutorial ends with an example showing the algorithm in action. I hope you’ll enjoy the tutorial and gain something useful from it.

JavaScript PNG Generator - Utilities

Tuesday, November 18th, 2003

This is just a quick note. The JS_PNG generator object suite and example code make use of a 32-bit CRC and a Base64 encoder. I thought that perchance these would be useful to others standalone, so I have moved those two JavaScript objects to the Utilities page.

JavaScript PNG Generator - Continued

Monday, November 17th, 2003

I’ve continued work on my JS_PNG generator to include support for:

  • Greyscale Images
  • Greyscale Images with Transparency
  • Greyscale Images with an Alpha Channel
  • True Color Images
  • True Color Images with Transparency
  • True Color Images with an Alpha Channel

And, of course, the Indexed and Indexed with Transparency modes are still available. Examples of each supported image type can be seen at the URL above.

I ran into an interesting bug with ASV3 and ASV6 during the implementation of the new image formats. It appears that these viewers do not support transparency with greyscale and true color images. Even worse, greyscale images with transparency do not render and surprisingly prevent all following PNG images from rendering too. You can see a demonstration of the problem when viewing the examples mentioned above.

I found that if I create what I believe is a slightly invalid greyscale with transparency image, the ASV viewers will render it and the following PNGs. However, the transparency effect does not appear, and these “invalid” images will not display correctly in CSV 2.1, but do display fine in Batik 1.5.

There is a noticable difference in how greyscale PNGs are displayed in ASV versus CVS and Batik. I haven’t tested this yet, but it looks as if the greyscale image in ASV has a different gamma. I have seen this same difference with RGB images. Setting image-rendering to linearRGB appears to improve the match between viewers. I’m guessing the same issue is occurring with greyscale images since, if I remember correctly, the SVG specifications require that single channel greyscale images be converted to RGBA before being rendered, used as masks, or used in filter effects.

The other thing I noticed is that CSV displays greyscale images with an alpha channel differently than ASV and Batik. CSV’s version appears to add white to the content behind it. Instead of trying to describe the effect here, it’s probably best to view the example images on the JS_PNG page with each viewer.

I’m a bit surprised to see how much difference exists between these viewers. Perhaps since SVG is a “vector” technology, emphasis has not been placed on the “raster” aspects of the language. These problems will sure make for challenges for those who rely on the accurate display of color in raster images on the web: photographers, designers, advertisers, etc. Maybe it’s time that I start getting more intimate with ICC. That very well could make all of these problems moot.

Next, I intend to improve palette support with indexed images. Right now the code always generates a palette with 256 entries. I could save some processing time by reducing the palette to a smaller power of 2. Also, I may implement support for compression, but I’ll have to be feeling really crazy to that :-)