java.awt.image.BufferedImage#getColorModel()源码实例Demo

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

源代码1 项目: pentaho-kettle   文件: SwingGC.java
private void drawImage( SwingUniversalImage image, int centerX, int centerY, double angle, int imageSize ) {
  if ( isDrawingPixelatedImages() && image.isBitmap() ) {
    BufferedImage img =  image.getAsBitmapForSize( imageSize, imageSize, angle );
    ColorModel cm = img.getColorModel();
    Raster raster = img.getRaster();

    int offx = centerX + xOffset - img.getWidth() / 2;
    int offy = centerY + yOffset - img.getHeight() / 2;
    for ( int x = 0; x < img.getWidth( observer ); x++ ) {
      for ( int y = 0; y < img.getHeight( observer ); y++ ) {
        Object pix = raster.getDataElements( x, y, null );
        gc.setColor( new Color( cm.getRed( pix ), cm.getGreen( pix ), cm.getBlue( pix ), cm.getAlpha( pix ) ) );
        gc.setStroke( new BasicStroke( 1.0f ) );
        gc.drawLine(
            offx + x,
            offy + y,
            offx + x + 1,
            offy + y + 1 );
      }
    }
  } else {
    image.drawToGraphics( gc, centerX, centerY, imageSize, imageSize, angle );
  }
}
 
源代码2 项目: openjdk-jdk8u-backup   文件: ShortHistogramTest.java
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
源代码3 项目: jdk8u-dev-jdk   文件: BufImgSurfaceData.java
public static SurfaceData createDataBP(BufferedImage bImg,
                                       SurfaceType sType) {
    BytePackedRaster bpRaster =
        (BytePackedRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bpRaster.getDataStorage(),
                    bpRaster.getDataBitOffset() / 8,
                    bpRaster.getDataBitOffset() & 7,
                    bpRaster.getWidth(),
                    bpRaster.getHeight(),
                    0,
                    bpRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
源代码4 项目: openjdk-jdk8u   文件: JFIFMarkerSegment.java
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();
    }
}
 
源代码5 项目: TencentKona-8   文件: BufImgSurfaceData.java
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank) {
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
源代码6 项目: TencentKona-8   文件: GIFImageReader.java
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
源代码7 项目: hottub   文件: ShortHistogramTest.java
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
源代码8 项目: hottub   文件: BufferedBufImgOps.java
/**************************** RescaleOp support *****************************/

    public static boolean isRescaleOpValid(RescaleOp rop,
                                           BufferedImage srcImg)
    {
        int numFactors = rop.getNumFactors();
        ColorModel srcCM = srcImg.getColorModel();

        if (srcCM instanceof IndexColorModel) {
            throw new
                IllegalArgumentException("Rescaling cannot be "+
                                         "performed on an indexed image");
        }
        if (numFactors != 1 &&
            numFactors != srcCM.getNumColorComponents() &&
            numFactors != srcCM.getNumComponents())
        {
            throw new IllegalArgumentException("Number of scaling constants "+
                                               "does not equal the number of"+
                                               " of color or color/alpha "+
                                               " components");
        }

        int csType = srcCM.getColorSpace().getType();
        if (csType != ColorSpace.TYPE_RGB &&
            csType != ColorSpace.TYPE_GRAY)
        {
            // Not prepared to deal with other color spaces
            return false;
        }

        if (numFactors == 2 || numFactors > 4) {
            // Not really prepared to handle this at the native level, so...
            return false;
        }

        return true;
    }
 
源代码9 项目: TencentKona-8   文件: TexturePaintContext.java
public static PaintContext getContext(BufferedImage bufImg,
                                      AffineTransform xform,
                                      RenderingHints hints,
                                      Rectangle devBounds) {
    WritableRaster raster = bufImg.getRaster();
    ColorModel cm = bufImg.getColorModel();
    int maxw = devBounds.width;
    Object val = hints.get(RenderingHints.KEY_INTERPOLATION);
    boolean filter =
        (val == null
         ? (hints.get(RenderingHints.KEY_RENDERING) == RenderingHints.VALUE_RENDER_QUALITY)
         : (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
    if (raster instanceof IntegerInterleavedRaster &&
        (!filter || isFilterableDCM(cm)))
    {
        IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
        if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
            return new Int(iir, cm, xform, maxw, filter);
        }
    } else if (raster instanceof ByteInterleavedRaster) {
        ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
        if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
            if (filter) {
                if (isFilterableICM(cm)) {
                    return new ByteFilter(bir, cm, xform, maxw);
                }
            } else {
                return new Byte(bir, cm, xform, maxw);
            }
        }
    }
    return new Any(raster, cm, xform, maxw, filter);
}
 
源代码10 项目: Bytecoder   文件: PrinterGraphicsConfig.java
/**
 * Returns the color model associated with this configuration.
 */
@Override
public ColorModel getColorModel() {
    if (theModel == null) {
        BufferedImage bufImg =
            new BufferedImage(1,1, BufferedImage.TYPE_3BYTE_BGR);
        theModel = bufImg.getColorModel();
    }

    return theModel;
}
 
源代码11 项目: MeteoInfo   文件: GraphicsUtilities.java
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null);
}
 
源代码12 项目: dragonwell8_jdk   文件: PathGraphics.java
protected boolean isBitmaskTransparency(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    return (colorModel != null &&
            colorModel.getTransparency() == ColorModel.BITMASK);
}
 
源代码13 项目: jdk8u60   文件: PathGraphics.java
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
源代码14 项目: jdk8u-dev-jdk   文件: PathGraphics.java
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
源代码15 项目: filthy-rich-clients   文件: GraphicsUtilities.java
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
源代码16 项目: filthy-rich-clients   文件: GraphicsUtilities.java
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
源代码17 项目: openjdk-jdk8u   文件: EffectUtils.java
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
源代码18 项目: openjdk-8   文件: EffectUtils.java
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
源代码19 项目: hottub   文件: EffectUtils.java
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
源代码20 项目: dragonwell8_jdk   文件: EffectUtils.java
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}