Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 2 ■ an IntroduCtIon to Content CreatIon: 2d new MedIa asset FundaMentals

these together. Since digital audio also involves the fourth dimension of time, I will finish up with digital
audio concepts; finally, we will take a quick look at digital content optimization so that your pro Java games
and IoT projects are compact and download quickly.


Digital Imaging Concepts: Resolution, Color Depth, Alpha,


Layers


JavaFX supports the most popular digital imaging file (data) formats, which gives us game designers a ton
of flexibility. Since the JavaFX 8 API is now part of Java 8 and 9, this means Java also supports these image
formats. Some of these digital image formats have been around for decades, like the CompuServe Graphics
Information Format (GIF) or the widely used Joint Photographic Experts Group (JPEG) format. Some
of the JavaFX digital image formats are more modern; for instance, the Portable Network Graphics (PNG,
pronounced “ping”) is the file format that we will be using for our games because it yields the highest quality
level and supports image compositing, which we will be learning about soon. All of these mainstream digital
image file formats supported in Java are also supported in HTML5 browsers, and since Java apps can be used
inside HTML apps or web sites, this is a very logical synergy indeed! You can also use a third-party digital
image library called ImageJ, if you need a wider range of digital image file format support.
The oldest format is a lossless digital image file format called CompuServe GIF. It is termed lossless
because it does not throw away (lose) any source image data to achieve its compression result. The GIF
compression algorithm is not as refined (not as powerful) as the PNG format, and GIF only supports
indexed color, which is how it obtains its compression (smaller file size). We will be learning about color
depth (indexed color versus true color) in detail later in this section. If all your game image assets are
already created using the GIF format, you’ll be able to use them in your Java game with no problems, rather
than less efficient image compression and limited image compositing capabilities.
The most popular digital image format that Java supports via JavaFX is JPEG. JPEG uses a “true color”
color depth, instead of an indexed color depth. We’ll be covering color theory and color depth a bit later.
JPEG uses what is termed lossy digital image compression. This is because the compression algorithm
“throws away” image data so that it can achieve a smaller file size. This image data is lost forever, unless you
are smart and save the original raw image!
If you magnify a JPEG image after compression, you will see discolored or dirty areas, which clearly
weren’t present in your original image. The degraded area or areas in an image are termed compression
artifacts in the digital imaging industry. This will only occur in lossy image compression and is common
with JPEG (and MPEG) compression.
The digital imaging format that I recommend you use for your pro Java games is the Portable Network
Graphic file format. PNG has two true-color file versions; one is called PNG24 and can’t be used in image
compositing, and the other is called PNG32 and carries an alpha channel used to define transparency,
which we will be covering a bit later. There is also an indexed (a maximum of 256; can be fewer) color
version of the PNG format, called PNG8.
The reason I recommend PNG for your games is because it has a decent image compression algorithm
and because it is a lossless image format. This means that PNG has great image quality as well as reasonable
levels of data compression efficiency, which will make your game distribution file smaller. The real power of
the PNG32 format comes in its ability to composite with other game imagery using transparency and anti-
aliasing (via its alpha channel).

Free download pdf