public BufferedImage()

in modules/awt/src/main/java/common/java/awt/image/BufferedImage.java [179:356]


    public BufferedImage(int width, int height, int imageType) {

        switch (imageType) {
        case TYPE_INT_RGB:
            cm = new DirectColorModel(24, RED_MASK, GREEN_MASK, BLUE_MASK);
            raster = cm.createCompatibleWritableRaster(width, height);
            break;

        case TYPE_INT_ARGB:
            cm = ColorModel.getRGBdefault();
            raster = cm.createCompatibleWritableRaster(width, height);
            break;

        case TYPE_INT_ARGB_PRE:
            cm = new DirectColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
                    32,
                    RED_MASK,
                    GREEN_MASK,
                    BLUE_MASK,
                    ALPHA_MASK,
                    true,
                    DataBuffer.TYPE_INT);

            raster = cm.createCompatibleWritableRaster(width, height);
            break;

        case TYPE_INT_BGR:
            cm = new DirectColorModel(24,
                    RED_BGR_MASK,
                    GREEN_BGR_MASK,
                    BLUE_BGR_MASK);

            raster = cm.createCompatibleWritableRaster(width, height);
            break;

        case TYPE_3BYTE_BGR: {
            int bits[] = { 8, 8, 8 };
            int bandOffsets[] = { 2, 1, 0 };
            cm = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
                    bits, 
                    false, 
                    false, 
                    Transparency.OPAQUE, 
                    DataBuffer.TYPE_BYTE);

            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                    width, height, width * 3, 3, bandOffsets, null);
            }
            break;

        case TYPE_4BYTE_ABGR: {
            int bits[] = { 8, 8, 8, 8 };
            int bandOffsets[] = { 3, 2, 1, 0 };
            cm = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
                    bits, 
                    true, 
                    false, 
                    Transparency.TRANSLUCENT, 
                    DataBuffer.TYPE_BYTE);

            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                    width, height, width * 4, 4, bandOffsets, null);
            }
            break;

        case TYPE_4BYTE_ABGR_PRE: {
            int bits[] = { 8, 8, 8, 8 };
            int bandOffsets[] = { 3, 2, 1, 0 };
            cm = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
                    bits, 
                    true, 
                    true, 
                    Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);

            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                    width, height, width * 4, 4, bandOffsets, null);
            }
            break;

        case TYPE_USHORT_565_RGB:
            cm = new DirectColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
                    16,
                    RED_565_MASK,
                    GREEN_565_MASK,
                    BLUE_565_MASK,
                    0,
                    false,
                    DataBuffer.TYPE_USHORT);

            raster = cm.createCompatibleWritableRaster(width, height);
            break;

        case TYPE_USHORT_555_RGB:
            cm = new DirectColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
                    15,
                    RED_555_MASK,
                    GREEN_555_MASK,
                    BLUE_555_MASK,
                    0,
                    false,
                    DataBuffer.TYPE_USHORT);

            raster = cm.createCompatibleWritableRaster(width, height);
            break;

        case TYPE_BYTE_GRAY: {
            int bits[] = { 8 };
            cm = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_GRAY),
                    bits, 
                    false, 
                    false, 
                    Transparency.OPAQUE, 
                    DataBuffer.TYPE_BYTE);

            raster = cm.createCompatibleWritableRaster(width, height);
            }
            break;

        case TYPE_USHORT_GRAY: {
            int bits[] = { 16 };
            cm = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_GRAY),
                    bits, 
                    false, 
                    false, 
                    Transparency.OPAQUE, 
                    DataBuffer.TYPE_USHORT);
            raster = cm.createCompatibleWritableRaster(width, height);
            }
            break;

        case TYPE_BYTE_BINARY: {
            int colorMap[] = { 0, 0xffffff };
            cm = new IndexColorModel(1, 2, colorMap, 0, false, -1,
                    DataBuffer.TYPE_BYTE);

            raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE, width,
                    height, 1, 1, null);
            }
            break;

        case TYPE_BYTE_INDEXED: {
            int colorMap[] = new int[256];
            int i = 0;
            for (int r = 0; r < 256; r += 51) {
                for (int g = 0; g < 256; g += 51) {
                    for (int b = 0; b < 256; b += 51) {
                        colorMap[i] = (r << 16) | (g << 8) | b;
                        i++;
                    }
                }
            }

            int gray = 0x12;
            for (; i < 256; i++, gray += 6) {
                colorMap[i] = (gray << 16) | (gray << 8) | gray;
            }
            cm = new IndexColorModel(8, 256, colorMap, 0, false, -1,
                    DataBuffer.TYPE_BYTE);
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                    width, height, 1, null);

            }
            break;
        default:
            // awt.224=Unknown image type
            throw new IllegalArgumentException(Messages.getString("awt.224")); //$NON-NLS-1$
        }
        this.imageType = imageType;
        imageSurf = createImageSurface(imageType);
    }