本文整理汇总了Java中javax.imageio.ImageTypeSpecifier.getColorModel方法的典型用法代码示例。如果您正苦于以下问题:Java ImageTypeSpecifier.getColorModel方法的具体用法?Java ImageTypeSpecifier.getColorModel怎么用?Java ImageTypeSpecifier.getColorModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageTypeSpecifier
的用法示例。
在下文中一共展示了ImageTypeSpecifier.getColorModel方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformForType
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
/**
* Given an image type, return the Adobe transform corresponding to
* that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
* with an Adobe marker segment. If <code>input</code> is true, then
* the image type is considered before colorspace conversion.
*/
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
int retval = ADOBE_IMPOSSIBLE;
ColorModel cm = imageType.getColorModel();
switch (cm.getColorSpace().getType()) {
case ColorSpace.TYPE_GRAY:
retval = ADOBE_UNKNOWN;
break;
case ColorSpace.TYPE_RGB:
retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
break;
case ColorSpace.TYPE_YCbCr:
retval = ADOBE_YCC;
break;
case ColorSpace.TYPE_CMYK:
retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
}
return retval;
}
示例2: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
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);
}
}
示例3: transformForType
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
/**
* Given an image type, return the Adobe transform corresponding to
* that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
* with an Adobe marker segment. If {@code input} is true, then
* the image type is considered before colorspace conversion.
*/
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
int retval = ADOBE_IMPOSSIBLE;
ColorModel cm = imageType.getColorModel();
switch (cm.getColorSpace().getType()) {
case ColorSpace.TYPE_GRAY:
retval = ADOBE_UNKNOWN;
break;
case ColorSpace.TYPE_RGB:
retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
break;
case ColorSpace.TYPE_YCbCr:
retval = ADOBE_YCC;
break;
case ColorSpace.TYPE_CMYK:
retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
}
return retval;
}
示例4: prepareInsertEmpty
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
public void prepareInsertEmpty(int imageIndex,
ImageTypeSpecifier imageType,
int width,
int height,
IIOMetadata imageMetadata,
List<? extends BufferedImage> thumbnails,
ImageWriteParam param) throws IOException {
checkParamsEmpty(imageType, width, height, thumbnails);
this.isInsertingEmpty = true;
SampleModel emptySM = imageType.getSampleModel();
RenderedImage emptyImage =
new EmptyImage(0, 0, width, height,
0, 0, emptySM.getWidth(), emptySM.getHeight(),
emptySM, imageType.getColorModel());
insert(imageIndex, new IIOImage(emptyImage, null, imageMetadata),
param, false);
}
示例5: isJFIFcompliant
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the given imageType can be used
* in a JFIF file. If <code>input</code> is true, then the
* image type is considered before colorspace conversion.
*/
static boolean isJFIFcompliant(ImageTypeSpecifier imageType,
boolean input) {
ColorModel cm = imageType.getColorModel();
// Can't have alpha
if (cm.hasAlpha()) {
return false;
}
// Gray is OK, always
int numComponents = imageType.getNumComponents();
if (numComponents == 1) {
return true;
}
// If it isn't gray, it must have 3 channels
if (numComponents != 3) {
return false;
}
if (input) {
// Must be RGB
if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
return true;
}
} else {
// Must be YCbCr
if (cm.getColorSpace().getType() == ColorSpace.TYPE_YCbCr) {
return true;
}
}
return false;
}
示例6: getDestCSType
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
retval = JPEG.JCS_GRAYSCALE;
break;
case ColorSpace.TYPE_RGB:
if (alpha) {
retval = JPEG.JCS_RGBA;
} else {
retval = JPEG.JCS_RGB;
}
break;
case ColorSpace.TYPE_YCbCr:
if (alpha) {
retval = JPEG.JCS_YCbCrA;
} else {
retval = JPEG.JCS_YCbCr;
}
break;
case ColorSpace.TYPE_3CLR:
if (cs == JPEG.JCS.getYCC()) {
if (alpha) {
retval = JPEG.JCS_YCCA;
} else {
retval = JPEG.JCS_YCC;
}
}
case ColorSpace.TYPE_CMYK:
retval = JPEG.JCS_CMYK;
break;
}
return retval;
}
示例7: isJFIFcompliant
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
/**
* Returns {@code true} if the given imageType can be used
* in a JFIF file. If {@code input} is true, then the
* image type is considered before colorspace conversion.
*/
static boolean isJFIFcompliant(ImageTypeSpecifier imageType,
boolean input) {
ColorModel cm = imageType.getColorModel();
// Can't have alpha
if (cm.hasAlpha()) {
return false;
}
// Gray is OK, always
int numComponents = imageType.getNumComponents();
if (numComponents == 1) {
return true;
}
// If it isn't gray, it must have 3 channels
if (numComponents != 3) {
return false;
}
if (input) {
// Must be RGB
if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
return true;
}
} else {
// Must be YCbCr
if (cm.getColorSpace().getType() == ColorSpace.TYPE_YCbCr) {
return true;
}
}
return false;
}
示例8: getDestCSType
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
retval = JPEG.JCS_GRAYSCALE;
break;
case ColorSpace.TYPE_RGB:
if (alpha) {
retval = JPEG.JCS_RGBA;
} else {
retval = JPEG.JCS_RGB;
}
break;
case ColorSpace.TYPE_YCbCr:
if (alpha) {
retval = JPEG.JCS_YCbCrA;
} else {
retval = JPEG.JCS_YCbCr;
}
break;
case ColorSpace.TYPE_3CLR:
if (cs == JPEG.JCS.getYCC()) {
if (alpha) {
retval = JPEG.JCS_YCCA;
} else {
retval = JPEG.JCS_YCC;
}
}
break;
case ColorSpace.TYPE_CMYK:
retval = JPEG.JCS_CMYK;
break;
}
return retval;
}
示例9: prepareWriteEmpty
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
public void prepareWriteEmpty(IIOMetadata streamMetadata,
ImageTypeSpecifier imageType,
int width,
int height,
IIOMetadata imageMetadata,
List<? extends BufferedImage> thumbnails,
ImageWriteParam param) throws IOException {
if (stream == null) {
throw new IllegalStateException("output == null!");
}
checkParamsEmpty(imageType, width, height, thumbnails);
this.isWritingEmpty = true;
SampleModel emptySM = imageType.getSampleModel();
RenderedImage emptyImage =
new EmptyImage(0, 0, width, height,
0, 0, emptySM.getWidth(), emptySM.getHeight(),
emptySM, imageType.getColorModel());
markPositions();
write(streamMetadata, new IIOImage(emptyImage, null, imageMetadata),
param, true, false);
if (abortRequested()) {
resetPositions();
}
}
示例10: getDefaultImageMetadata
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
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;
}
示例11: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
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;
}