Checks if the dimension of an image is power of 2 and hence a valid texture. - Java javax.microedition.lcdui

Java examples for javax.microedition.lcdui:Image

Description

Checks if the dimension of an image is power of 2 and hence a valid texture.

Demo Code


import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Main{
    /**/*from ww w. j ava 2  s .c  o  m*/
     * Checks if the dimension of an image is power of 2 and hence a
     * valid texture.
     * 
     * @param img image to evaluate
     * @param maxTexture max texture size allowed by platform
     * @return true if image dimension is power of 2, false otherwise
     */
    public static boolean validateTexture(Image img, int maxTexture) {
        if (null == img)
            return false;

        int imgWidth = img.getWidth();

        while (maxTexture > 0) {
            if (maxTexture == imgWidth)
                return true;
            maxTexture >>= 1;
        }

        return false;
    }
}

Related Tutorials