Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 2 ■ an IntroduCtIon to Content CreatIon: 2d new MedIa asset FundaMentals


Also, notice that you can set the percentage of dithering used. I often select either the 0 percent or 100
percent setting; however, you can fine-tune the dithering effect anywhere in between these two extreme
values to fine-tune your resulting file size because these dithering dot patterns introduce more data to
compress and increase file size.
You can also choose between dithering algorithms because, as you probably have surmised already,
these different dithering effects are created mathematically by using dithering algorithms that are ultimately
compatible with (supported by) indexed file format compression, which uses a palette to hold the color
values used for the pixels.
I use diffusion dithering, which gives a smooth effect along irregularly shaped gradients, as is seen in
the car fender. You can also use a noise option, which is more randomized, or a pattern option, which is
less randomized. The diffusion option usually gives the best results, which is why I use it when I am using
indexed color (which is not often).
Dithering, as you might imagine, adds data patterns into your images. These are more difficult to
compress. This is because smooth areas in an image, such as gradients or fill areas, will generally be easier
for these compression algorithms to compress, whereas sharp transitions (anti-aliased edges), or random
pixel patterns usually generated by dithering, or possibly by “noise” from a camera with a substandard CCD,
for instance.
Therefore, applying the dithering option will always increase the data footprint by a few percentage
points. Be sure to check the resulting file size with and without dithering applied (selected in an export
dialog) to see whether this is worth the improved visual result that it affords. Notice that there is also a
transparency option check box for indexed color PNG images but that an alpha channel used in PNG8
images is only 1-bit (on/off ), not 8-bit like with PNG32.
The final concept that we have learned about so far that can increase the data footprint of your image is
adding the alpha channel to define transparency for compositing. This is because adding the alpha channel
will add in another 8-bit color channel (more accurately, a transparency or alpha channel) to the image
being compressed. If you need an alpha channel to define transparency for the image, most likely to support
future compositing requirements such as using the image as a game sprite, there’s not a whole lot of choice
in the matter, so include the alpha channel.
If your alpha channel contains all zeros (that is, uses an all-black fill color, which would define your
imagery as being completely transparent) or if your alpha channel contains all FF values (or uses an
all-white fill color, defining your image as being completely opaque or a background plate), you would
essentially (in practical use) be defining an alpha channel that does not contain any useful alpha data values.


Figure 2-5. Setting dithering to the Diffusion algorithm and 32 colors (5-bit color) with 100 percent dithering
for PNG5 output

Free download pdf