base/common/src/main/com/thesett/common/swing/surface/Surface.java
private BufferedImage createSGISurface(int w, int h, int pixelBits)
    {
        int rMask32 = 0xFF000000;
        int rMask16 = 0xF800;
        int gMask32 = 0x00FF0000;
        int gMask16 = 0x07C0;
        int bMask32 = 0x0000FF00;
        int bMask16 = 0x003E;
        DirectColorModel dcm = null;
        DataBuffer db = null;
        WritableRaster wr = null;

        switch (pixelBits)
        {
        case 16:
        {
            short[] imageDataUShort = new short[w * h];
            dcm = new DirectColorModel(16, rMask16, gMask16, bMask16);
            db = new DataBufferUShort(imageDataUShort, imageDataUShort.length);
            wr = Raster.createPackedRaster(db, w, h, w, new int[] { rMask16, gMask16, bMask16 }, null);

            break;
        }

        case 32:
        {
            int[] imageDataInt = new int[w * h];
            dcm = new DirectColorModel(32, rMask32, gMask32, bMask32);
            db = new DataBufferInt(imageDataInt, imageDataInt.length);
            wr = Raster.createPackedRaster(db, w, h, w, new int[] { rMask32, gMask32, bMask32 }, null);

            break;
        }

        default:
        {
            new Exception("Invalid # of bit per pixel").printStackTrace();
        }

        }

        return new BufferedImage(dcm, wr, false, null);
    }
private BufferedImage createSGISurface(int w, int h, int pixelBits)
    {
        int rMask32 = 0xFF000000;
        int rMask16 = 0xF800;
        int gMask32 = 0x00FF0000;
        int gMask16 = 0x07C0;
        int bMask32 = 0x0000FF00;
        int bMask16 = 0x003E;
        DirectColorModel dcm = null;
        DataBuffer db = null;
        WritableRaster wr = null;

        switch (pixelBits)
        {
        case 16:
        {
            short[] imageDataUShort = new short[w * h];
            dcm = new DirectColorModel(16, rMask16, gMask16, bMask16);
            db = new DataBufferUShort(imageDataUShort, imageDataUShort.length);
            wr = Raster.createPackedRaster(db, w, h, w, new int[] { rMask16, gMask16, bMask16 }, null);

            break;
        }

        case 32:
        {
            int[] imageDataInt = new int[w * h];
            dcm = new DirectColorModel(32, rMask32, gMask32, bMask32);
            db = new DataBufferInt(imageDataInt, imageDataInt.length);
            wr = Raster.createPackedRaster(db, w, h, w, new int[] { rMask32, gMask32, bMask32 }, null);

            break;
        }

        default:
        {
            new Exception("Invalid # of bit per pixel").printStackTrace();
        }

        }

        return new BufferedImage(dcm, wr, false, null);
    }
Creates a custom colour image format.

@param  w         The image width.
@param  h         The image height.
@param  pixelBits The number of bits-per-pixel to use. Must be 16 or 32.

@return A buffered image of the specifed size and type.