javax.imageio.ImageTypeSpecifier#getBufferedImageType ( )源码实例Demo

下面列出了javax.imageio.ImageTypeSpecifier#getBufferedImageType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8-source   文件: BMPSubsamplingTest.java
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;
}
 
源代码2 项目: dragonwell8_jdk   文件: BMPSubsamplingTest.java
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;
}
 
源代码3 项目: hottub   文件: BMPSubsamplingTest.java
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;
}
 
源代码4 项目: jdk8u-jdk   文件: BMPSubsamplingTest.java
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;
}
 
源代码5 项目: jdk8u-jdk   文件: BMPSubsamplingTest.java
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;
}
 
源代码6 项目: openjdk-8   文件: BMPSubsamplingTest.java
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;
}
 
源代码7 项目: jdk1.8-source-analysis   文件: BMPImageWriter.java
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
源代码8 项目: jdk1.8-source-analysis   文件: BMPImageWriter.java
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;
}
 
源代码9 项目: jdk8u-jdk   文件: BMPImageWriter.java
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
源代码10 项目: TencentKona-8   文件: BMPImageWriter.java
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
源代码11 项目: TencentKona-8   文件: BMPImageWriter.java
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;
}
 
源代码12 项目: jdk8u_jdk   文件: BMPImageWriter.java
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
源代码13 项目: jdk8u60   文件: BMPImageWriter.java
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;
}
 
源代码14 项目: openjdk-jdk9   文件: BMPImageWriter.java
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;
}
 
源代码15 项目: jdk8u-jdk   文件: BMPImageWriter.java
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;
}
 
源代码16 项目: jdk8u_jdk   文件: BMPImageWriter.java
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;
}
 
源代码17 项目: openjdk-jdk8u   文件: BMPImageWriter.java
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;
}
 
源代码18 项目: hottub   文件: BMPImageWriter.java
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;
}
 
源代码19 项目: openjdk-jdk9   文件: BMPImageWriter.java
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
源代码20 项目: Bytecoder   文件: BMPImageWriter.java
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}