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

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

public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // 4450894: Ensure bitDepth is between 1 and 8
    if (bitDepth < 1 || bitDepth > 8) {
        return false;
    }

    return true;
}
 
源代码2 项目: dragonwell8_jdk   文件: JPEGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // 4450894: Ensure bitDepth is between 1 and 8
    if (bitDepth < 1 || bitDepth > 8) {
        return false;
    }

    return true;
}
 
源代码3 项目: dragonwell8_jdk   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码4 项目: openjdk-8-source   文件: JPEGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // 4450894: Ensure bitDepth is between 1 and 8
    if (bitDepth < 1 || bitDepth > 8) {
        return false;
    }

    return true;
}
 
源代码5 项目: jdk8u-jdk   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码6 项目: Bytecoder   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码8 项目: jdk8u60   文件: WBMPImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sm = type.getSampleModel();
    if (!(sm instanceof MultiPixelPackedSampleModel))
        return false;
    if (sm.getSampleSize(0) != 1)
        return false;

    return true;
}
 
源代码9 项目: jdk8u_jdk   文件: WBMPImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sm = type.getSampleModel();
    if (!(sm instanceof MultiPixelPackedSampleModel))
        return false;
    if (sm.getSampleSize(0) != 1)
        return false;

    return true;
}
 
源代码10 项目: j-webp   文件: WebPImageWriterSpi.java
@Override
public boolean canEncodeImage( ImageTypeSpecifier type ) {
  ColorModel colorModel = type.getColorModel();
  SampleModel sampleModel = type.getSampleModel();
  int transferType = sampleModel.getTransferType();

  if ( colorModel instanceof ComponentColorModel ) {
    if ( !( sampleModel instanceof ComponentSampleModel ) ) {
      return false;
    }

    if ( transferType != DataBuffer.TYPE_BYTE && transferType != DataBuffer.TYPE_INT ) {
      return false;
    }
  }
  else if ( colorModel instanceof DirectColorModel ) {
    if ( !( sampleModel instanceof SinglePixelPackedSampleModel ) ) {
      return false;
    }

    if ( transferType != DataBuffer.TYPE_INT ) {
      return false;
    }
  }

  ColorSpace colorSpace = colorModel.getColorSpace();
  if ( !( colorSpace.isCS_sRGB() ) ) {
    return false;
  }

  int[] sampleSize = sampleModel.getSampleSize();
  for ( int i = 0; i < sampleSize.length; i++ ) {
    if ( sampleSize[ i ] > 8 ) {
      return false;
    }
  }


  return true;
}
 
源代码11 项目: openjdk-jdk9   文件: WBMPImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sm = type.getSampleModel();
    if (!(sm instanceof MultiPixelPackedSampleModel))
        return false;
    if (sm.getSampleSize(0) != 1)
        return false;

    return true;
}
 
源代码12 项目: TencentKona-8   文件: WBMPImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sm = type.getSampleModel();
    if (!(sm instanceof MultiPixelPackedSampleModel))
        return false;
    if (sm.getSampleSize(0) != 1)
        return false;

    return true;
}
 
源代码13 项目: openjdk-8-source   文件: 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 项目: 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;
}
 
源代码15 项目: openjdk-8   文件: GIFImageWriter.java
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    GIFWritableImageMetadata imageMetadata =
        new GIFWritableImageMetadata();

    // Image dimensions

    SampleModel sampleModel = imageType.getSampleModel();

    Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
                                           sampleModel.getHeight());
    Dimension destSize = new Dimension();
    computeRegions(sourceBounds, destSize, param);

    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Interlacing

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
        imageMetadata.interlaceFlag = false;
    } else {
        imageMetadata.interlaceFlag = true;
    }

    // Local color table

    ColorModel colorModel = imageType.getColorModel();

    imageMetadata.localColorTable =
        createColorTable(colorModel, sampleModel);

    // Transparency

    if (colorModel instanceof IndexColorModel) {
        int transparentIndex =
            ((IndexColorModel)colorModel).getTransparentPixel();
        if (transparentIndex != -1) {
            imageMetadata.transparentColorFlag = true;
            imageMetadata.transparentColorIndex = transparentIndex;
        }
    }

    return imageMetadata;
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: 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 项目: jdk8u-jdk   文件: PNGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();
    ColorModel colorModel = type.getColorModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // Ensure bitDepth is between 1 and 16
    if (bitDepth < 1 || bitDepth > 16) {
        return false;
    }

    // Check number of bands, alpha
    int numBands = sampleModel.getNumBands();
    if (numBands < 1 || numBands > 4) {
        return false;
    }

    boolean hasAlpha = colorModel.hasAlpha();
    // Fix 4464413: PNGTransparency reg-test was failing
    // because for IndexColorModels that have alpha,
    // numBands == 1 && hasAlpha == true, thus causing
    // the check below to fail and return false.
    if (colorModel instanceof IndexColorModel) {
        return true;
    }
    if ((numBands == 1 || numBands == 3) && hasAlpha) {
        return false;
    }
    if ((numBands == 2 || numBands == 4) && !hasAlpha) {
        return false;
    }

    return true;
}
 
源代码18 项目: openjdk-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;
}
 
源代码19 项目: 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;
}
 
源代码20 项目: TencentKona-8   文件: GIFImageWriter.java
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    GIFWritableImageMetadata imageMetadata =
        new GIFWritableImageMetadata();

    // Image dimensions

    SampleModel sampleModel = imageType.getSampleModel();

    Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
                                           sampleModel.getHeight());
    Dimension destSize = new Dimension();
    computeRegions(sourceBounds, destSize, param);

    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Interlacing

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
        imageMetadata.interlaceFlag = false;
    } else {
        imageMetadata.interlaceFlag = true;
    }

    // Local color table

    ColorModel colorModel = imageType.getColorModel();

    imageMetadata.localColorTable =
        createColorTable(colorModel, sampleModel);

    // Transparency

    if (colorModel instanceof IndexColorModel) {
        int transparentIndex =
            ((IndexColorModel)colorModel).getTransparentPixel();
        if (transparentIndex != -1) {
            imageMetadata.transparentColorFlag = true;
            imageMetadata.transparentColorIndex = transparentIndex;
        }
    }

    return imageMetadata;
}