How PNG Works

Portable Network Graphics (PNG) format is a lossless image format that uses a GZIP style compressor to make its data smaller. Since the image format is lossless, the compressed image quality will be identical to your source image. This is great since you can get high quality while still getting some compression, but not nearly as much as with lossy formats.

One of the biggest attractions of PNG is that it supports transparency. In addition to the red, green, and blue channels, it supports an alpha channel that defines which pixels to alpha-blend during rendering. This transparency support makes PNG quite attractive to the web, and to applications where you may want an image on screen that isn’t exactly rectangular.
1

I grabbed a copy of Icebreaker the other day. Great game really. But when I opened up the APK to take a look at some of their artwork in higher detail, I found the game’s asset sizes were larger than they should be.

I’ve always been a fan of the artistic style and design quality of Nitrome games. Like most of their content, there’s lots of hand-optimized transparent sprites that are used. But I was appalled when I saw that that 20% of their asset footprint came from 32bpp PNG files.
7

I’ve been seeing some weird CPU performance weirdness while working on a new Android project, and after digging around a bit, realized that the perf issue wasn’t in my code at all; the CPU was being throttled by the hardware, automatically

You see, pretty much all modern mobile CPUs have a process known as frequency scaling.  That is, in order to conserve battery, most mobile hardware will reduce the amount of voltage supplied to the CPU depending on the workload that’s provided to it.
4

I’ve talked about a quantization of performance solutions before, and even a more accurate way to look at algorithm complexity. But it’s time to get into specifics for Android Games.

We have a game. We want to know whether it is limited by CPU or GPU performance.
3

In my travels, I’ve started seeing more texture atlases that waste hordes of texture space. The dominant waste comes from alpha textures being interspersed with opaque textures, effectively keeping around an extra channel of pixels for an image that isn’t needed.. Most games seem to dump all the textures into a single atlas in order to reduce the number texture swaps on the CPU. Sadly, they are wasting space by pushing all those blank pixels into memory.
3

For most Android game developers, PNGs are a simple, easy to use texture format that offers ‘good enough’ compression alongside alpha support, which is important since the dominant form of game in the mobile market is 2D based. But the truth is that while PNGs may help with distribution, they don’t help you when it comes to GPU residency; they are still full, fat textures eating up your available memory. But, it doesn’t have to be that way.
1

As I mentioned in my previous post, PNGs on android can be pretty gnarly, and a large portion of the asset footprint, for example, over 180 APKs, here was the breakdown between texture formats:

From the graph above, you can see that PNG files make up 78% of the total texture footprint.

To some, it may seem that I’m on a holy campaign to convince developers to avoid using PNGs; That’s because I am.
10

Lately, I’ve been seeing a lot more extended-content apps showing up in my Android game playing habits.That is, games which boast a 1.2mb download, and then require me to wait an extra 20 minutes while it brings down a brand new 1gb file after launching the game.
9

GZIP and Deflate, for the time being, are the only supported compression formats for serving web content. As I've shown before, it's less than ideal as a format, and has quite a bit of bloat. Thankfully, there's ways out there to serve smaller, more compact versions of GZIP files.
5

Compressing javascript source code is a tricky undertaking. To my knowledge, the only domain specific javascript compressor I’ve found is JSZap, which is a hefty undertaking in terms of tree-teardowns. There’s also the proposals for Javascript Diffing, which would save tons of bandwidth every day for GMAIL, but that’s a very generic algorithm.
8
Subscribe
Subscribe
Loading