Java Code Examples for javax.imageio.ImageTypeSpecifier#getBufferedImageType()

The following examples show how to use javax.imageio.ImageTypeSpecifier#getBufferedImageType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BMPSubsamplingTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 2
Source File: BMPSubsamplingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 3
Source File: BMPSubsamplingTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 4
Source File: BMPSubsamplingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 5
Source File: BMPSubsamplingTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 6
Source File: BMPSubsamplingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 7
Source File: BMPImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 8
Source File: BMPImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 9
Source File: BMPImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 10
Source File: BMPImageWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 11
Source File: BMPImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 12
Source File: BMPImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 13
Source File: BMPImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 14
Source File: BMPImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 15
Source File: BMPImageWriter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 16
Source File: BMPImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 17
Source File: BMPImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
Example 18
Source File: BMPImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 19
Source File: BMPImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 20
Source File: BMPImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}