Combining Sprites in an Image Strip

The interactive Adobe Flash pixel art illustration is divided into 72 regular shaped rectangles. Per rectangle a compressed image strip is calculated, based on the compression technique previously described.
This results in 72 image strips containing a certain amount - depending on a predefined minimum amount of different pixels - of rectangles with different dimensions.

combining sprites

The next, fairly difficult, problem is how to combine the separate images of an image strip in order to get an image strip with the lowest possible surface, which means an image strip with a minimum amount of redundant space.
If an image strip has e.g. 32 rectangles with different sizes, the possible options are astronomical. Even with a very fast computer, it's impossible to calculate them all.

To calculate a good option - not necessarily the best one if the numbers of rectangles are relative high - I start with the first rectangle, and position this rectangle on position 0,0. The next rectangle is positioned on the right side of this rectangle, or at the bottom left.
This process is repeated until all rectangles are positioned.
The first time the last rectangle is positioned the overall surface is calculated and used as the minimum surface. The next step is to reposition the last rectangle to a new available position. This is one of the positions on the right side or bottom left side of previous rectangles. The new overall surface is calculated and compared with the minimum surface.
If all possible positions are calculated, the rectangle, before the last rectangle, is repositioned and the whole process is repeated again... etc., etc.

By adding some extra checks to bypass solutions that are not relevant, the calculation of a reasonably good solution is do-able.

The next example illustrates the process. The example image strip contains four different-sized rectangles.
A few possible options are drawn; option 18, 19 and 20 are the most efficient solutions, which means they have a minimum amount of redundant space.

sprite combinations

 

Adobe flash can't cope internally with images bigger than 2800 pixels to reconstruct the original images. To bypass this restriction, I use several image strips to rebuild all 72 image strips.

The next image show two image strips used for the detail animations.
The black areas are redundant space.

image strip examples

 

the complete page is available in the commercial version of this tutorial.