Home Software Imaging Astronomy Gallery Blog
www.chrfr.de

Geometric transformations of images in MIDP 1.0

MIDP 1.0 neither provides low-level access to the pixel data of an Image object, nor any other means to even query the color of a specific pixel. However, it is still possible to rotate, mirror and scale images, or to transform them in any other way which only involves copying individual pixels to new locations. This can be achieved simply by calling drawImage once for each destination pixel,setting the clipping rectangle and drawing coordinates appriopriately each time.

Why would you want to do this at all?

The approach outlined above works perfectly, albeit with the following drawbacks: The performance can be increased for many transformations by exploiting their specific properties. For example, to mirror an image you can "draw-copy" entire rows or columns instead of individual pixels. The same holds if you scale an image along a single axis only. A rotation about 180 degrees can be expressed by two mirrors, and scaling along both axes can be decomposed by scaling one axis first. Cutting a tile out of a tileset image involves only a single draw operation. Even so, you will usually apply these transformations only once during application initialization.

The lack of interpolation is not relevant for many practical transformations. Of the transformations mentioned above, only the scaling would benefit from it. The lack of transparency is more serious, as it prevents using the above technique for game foreground objects usually referred to as sprites. Unfortunately, MIDP 1.0 (and unbelievably, also MIDP 2.0) does not provide the means to create a mutable image with a transparent background (like, e.g., the Nokia UI extension does).

And now for something completely different

In theory, there is yet another approach for working with images in MIDP, and that is to load the image data from the resources into an array yourself. Since you are probably not willing to write and package a fully fledged PNG decoder, this would mean to define a rather simple custom image format with some basic compression suitable for your type of graphics. Since you have the image data in an array, you can then apply any transformation your heart desires. Finally, you need to create images from your arrays.

Back to MIDP page


[an error occurred while processing this directive]
Copyright (C) 2006-2013 by Christian Fröschlin. Please note the legal disclaimer. If you experience problems with this page, contact webmaster@chrfr.de.