public static void convert(BufferedImage image, Format format, ByteBuffer buf) {
        DecodeParams p = params.get(format);
        if (p == null)
            throw new UnsupportedOperationException("Image format " + format + " is not supported");

        int width = image.getWidth();
        int height = image.getHeight();

        boolean alpha = true;
        boolean luminance = false;

        int reductionA = 8 - Integer.bitCount(p.am);
        int reductionR = 8 - Integer.bitCount(p.rm);
        int reductionG = 8 - Integer.bitCount(p.gm);
        int reductionB = 8 - Integer.bitCount(p.bm);

        int initialPos = buf.position();
        for (int y = 0; y < height; y++){
            for (int x = 0; x < width; x++){
                // Get ARGB
                int argb = image.getRGB(x, y);

                // Extract color components
                int a = (argb & 0xff000000) >> 24;
                int r = (argb & 0x00ff0000) >> 16;
                int g = (argb & 0x0000ff00) >> 8;
                int b = (argb & 0x000000ff);

                // Remove anything after 8 bits
                a = a & 0xff;
                r = r & 0xff;
                g = g & 0xff;
                b = b & 0xff;

                // Set full alpha if target image has no alpha
                if (!alpha)
                    a = 0xff;

                // Convert color to luminance if target
                // image is in luminance format
                if (luminance){
                    // convert RGB to luminance
                }

                // Do bit reduction, assumes proper rounding has already been
                // done.
                a = a >> reductionA;
                r = r >> reductionR;
                g = g >> reductionG;
                b = b >> reductionB;
                
                // Put components into appropriate positions
                a = (a << p.as) & p.am;
                r = (r << p.rs) & p.rm;
                g = (g << p.gs) & p.gm;
                b = (b << p.bs) & p.bm;

                int outputPixel = ((a | r | g | b) << p.is) & p.im;
                int i = initialPos + (Ix(x,y,width) * p.bpp);
                writePixel(buf, i, outputPixel, p.bpp);
            }
        }
    }
Convert an AWT image to jME image. XXX not implemented yet!

@param image the input image (not null, unaffected)
@param format the data format
@param buf the output buffer (not null, modified)
jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java