Java Code Examples for java.awt.image.ColorModel#hasAlpha()

The following examples show how to use java.awt.image.ColorModel#hasAlpha() . 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: JFIFMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
Example 2
Source File: JFIFMarkerSegment.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
Example 3
Source File: JPEG.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: JPEG.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: JPEGImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private int getDefaultDestCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            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_YCCK;
            break;
        }
    }
    return retval;
}
 
Example 6
Source File: JPEG.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: BlitBg.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void BlitBg(SurfaceData srcData,
                   SurfaceData dstData,
                   Composite comp,
                   Region clip,
                   int bgArgb,
                   int srcx, int srcy,
                   int dstx, int dsty,
                   int width, int height)
{
    ColorModel dstModel = dstData.getColorModel();
    boolean bgHasAlpha = (bgArgb >>> 24) != 0xff;
    if (!dstModel.hasAlpha() && bgHasAlpha) {
        dstModel = ColorModel.getRGBdefault();
    }
    WritableRaster wr =
        dstModel.createCompatibleWritableRaster(width, height);
    boolean isPremult = dstModel.isAlphaPremultiplied();
    BufferedImage bimg =
        new BufferedImage(dstModel, wr, isPremult, null);
    SurfaceData tmpData = BufImgSurfaceData.createData(bimg);
    Color bgColor = new Color(bgArgb, bgHasAlpha);
    SunGraphics2D sg2d = new SunGraphics2D(tmpData, bgColor, bgColor,
                                           defaultFont);
    FillRect fillop = FillRect.locate(SurfaceType.AnyColor,
                                      CompositeType.SrcNoEa,
                                      tmpData.getSurfaceType());
    Blit combineop = Blit.getFromCache(srcData.getSurfaceType(),
                                       CompositeType.SrcOverNoEa,
                                       tmpData.getSurfaceType());
    Blit blitop = Blit.getFromCache(tmpData.getSurfaceType(), compositeType,
                                    dstData.getSurfaceType());
    fillop.FillRect(sg2d, tmpData, 0, 0, width, height);
    combineop.Blit(srcData, tmpData, AlphaComposite.SrcOver, null,
                   srcx, srcy, 0, 0, width, height);
    blitop.Blit(tmpData, dstData, comp, clip,
                0, 0, dstx, dsty, width, height);
}
 
Example 8
Source File: BlitBg.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void BlitBg(SurfaceData srcData,
                   SurfaceData dstData,
                   Composite comp,
                   Region clip,
                   int bgArgb,
                   int srcx, int srcy,
                   int dstx, int dsty,
                   int width, int height)
{
    ColorModel dstModel = dstData.getColorModel();
    boolean bgHasAlpha = (bgArgb >>> 24) != 0xff;
    if (!dstModel.hasAlpha() && bgHasAlpha) {
        dstModel = ColorModel.getRGBdefault();
    }
    WritableRaster wr =
        dstModel.createCompatibleWritableRaster(width, height);
    boolean isPremult = dstModel.isAlphaPremultiplied();
    BufferedImage bimg =
        new BufferedImage(dstModel, wr, isPremult, null);
    SurfaceData tmpData = BufImgSurfaceData.createData(bimg);
    Color bgColor = new Color(bgArgb, bgHasAlpha);
    SunGraphics2D sg2d = new SunGraphics2D(tmpData, bgColor, bgColor,
                                           defaultFont);
    FillRect fillop = FillRect.locate(SurfaceType.AnyColor,
                                      CompositeType.SrcNoEa,
                                      tmpData.getSurfaceType());
    Blit combineop = Blit.getFromCache(srcData.getSurfaceType(),
                                       CompositeType.SrcOverNoEa,
                                       tmpData.getSurfaceType());
    Blit blitop = Blit.getFromCache(tmpData.getSurfaceType(), compositeType,
                                    dstData.getSurfaceType());
    fillop.FillRect(sg2d, tmpData, 0, 0, width, height);
    combineop.Blit(srcData, tmpData, AlphaComposite.SrcOver, null,
                   srcx, srcy, 0, 0, width, height);
    blitop.Blit(tmpData, dstData, comp, clip,
                0, 0, dstx, dsty, width, height);
}
 
Example 9
Source File: JPEGImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private int getDefaultDestCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            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_YCCK;
            break;
        }
    }
    return retval;
}
 
Example 10
Source File: JPEGImageWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private int getDefaultDestCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            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_YCCK;
            break;
        }
    }
    return retval;
}
 
Example 11
Source File: JPEGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private int getSrcCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        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;
}
 
Example 12
Source File: JPEGImageWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private int getSrcCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        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;
}
 
Example 13
Source File: JPEG.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: JPEGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 15
Source File: ColorYCbCrComposite.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public CompositeContext createContext( ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints )
{
	final Composer c;
	if ( srcColorModel.getNumColorComponents() > 1 )
	{
		if ( srcColorModel.hasAlpha() )
			c = new ARGB2ARGB();
		else
			c = new RGB2ARGB();
	}
	else
		c = new Gray2ARGB();
	
	return new CompositeContext()
	{
		private Composer composer = c;
		public void compose( Raster src, Raster dstIn, WritableRaster dstOut )
		{
			final int[] srcPixel = new int[ 4 ];
			final int[] dstInPixel = new int[ 4 ];
			
			for ( int x = 0; x < dstOut.getWidth(); x++ )
			{
				for ( int y = 0; y < dstOut.getHeight(); y++ )
				{
					src.getPixel( x, y, srcPixel );
					dstIn.getPixel( x, y, dstInPixel );
					
					composer.compose( srcPixel, dstInPixel, alpha );
					
					dstOut.setPixel( x, y, dstInPixel );
				}
			}
		}

		public void dispose()
		{}
	};
}
 
Example 16
Source File: ImageType.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves the image type info to use for the given color model.
 * May return null.
 */
public ImageTypeInfo getImageTypeInfoFor(Integer targetPixelType, ColorModel colorModel) {
    Integer resultPixelType = null;
    ColorModel resultColorModel = null; // TODO: DEV NOTE: this must NOT be the colorModel parameter!!!

    if (targetPixelType != null) resultPixelType = typeMappings.get(targetPixelType);
    if (resultPixelType == null && (colorModel != null && !colorModel.hasAlpha())) resultPixelType = getPixelTypeNoAlpha();
    if (resultPixelType == null) resultPixelType = getPixelTypeDefault();

    return new ImageTypeInfo(resultPixelType, resultColorModel);
}
 
Example 17
Source File: PNGImageWriterSpi.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: PNGImageWriterSpi.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: PNGImageWriterSpi.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: PNGImageWriterSpi.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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;
}