当前位置: 首页>>代码示例>>Java>>正文


Java ColorModel类代码示例

本文整理汇总了Java中java.awt.image.ColorModel的典型用法代码示例。如果您正苦于以下问题:Java ColorModel类的具体用法?Java ColorModel怎么用?Java ColorModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ColorModel类属于java.awt.image包,在下文中一共展示了ColorModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDataBP

import java.awt.image.ColorModel; //导入依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:BufImgSurfaceData.java

示例2: brightLut

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * Modifies the lookup table to display a bright image with gray values
 * in the range minGray ... 255. Does nothing if ip is of type
 * ColorProcessor.
 * 
 * @param ip The target image.
 * @param minGray Minimum gray value.
 */
public static void brightLut(ImageProcessor ip, int minGray) {
	if (minGray < 0 || minGray >= 255)
		return;
	ColorModel cm = ip.getColorModel();
	if (!(cm instanceof IndexColorModel))
		return;
	IndexColorModel icm = (IndexColorModel) cm;
	int mapSize = icm.getMapSize();
	byte[] reds = new byte[mapSize];
	byte[] grns = new byte[mapSize];
	byte[] blus = new byte[mapSize];
	float scale = (255 - minGray) / 255f;
	for (int i = 0; i < mapSize; i++) {
		byte g = (byte) (Math.round(minGray + scale * i) & 0xFF);
		reds[i] = g;
		grns[i] = g;
		blus[i] = g;
	}
	ip.setColorModel(new IndexColorModel(8, mapSize, reds, grns, blus));
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:29,代码来源:LookupTables.java

示例3: getCachedRaster

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * Took this cacheRaster code from GradientPaint. It appears to recycle
 * rasters for use by any other instance, as long as they are sufficiently
 * large.
 */
private static synchronized Raster getCachedRaster(ColorModel cm,
                                                   int w, int h)
{
    if (cm == cachedModel) {
        if (cached != null) {
            Raster ras = cached.get();
            if (ras != null &&
                ras.getWidth() >= w &&
                ras.getHeight() >= h)
            {
                cached = null;
                return ras;
            }
        }
    }
    return cm.createCompatibleWritableRaster(w, h);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:MultipleGradientPaintContext.java

示例4: setDimensions

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * The setDimensions method is part of the ImageConsumer API which
 * this class must implement to retrieve the pixels.
 * <p>
 * Note: This method is intended to be called by the ImageProducer
 * of the Image whose pixels are being grabbed.  Developers using
 * this class to retrieve pixels from an image should avoid calling
 * this method directly since that operation could result in problems
 * with retrieving the requested pixels.
 * @param width the width of the dimension
 * @param height the height of the dimension
 */
public void setDimensions(int width, int height) {
    if (dstW < 0) {
        dstW = width - dstX;
    }
    if (dstH < 0) {
        dstH = height - dstY;
    }
    if (dstW <= 0 || dstH <= 0) {
        imageComplete(STATICIMAGEDONE);
    } else if (intPixels == null &&
               imageModel == ColorModel.getRGBdefault()) {
        intPixels = new int[dstW * dstH];
        dstScan = dstW;
        dstOff = 0;
    }
    flags |= (ImageObserver.WIDTH | ImageObserver.HEIGHT);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:PixelGrabber.java

示例5: transformForType

import java.awt.image.ColorModel; //导入依赖的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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:JPEG.java

示例6: JFIFExtensionMarkerSegment

import java.awt.image.ColorModel; //导入依赖的package包/类
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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JFIFMarkerSegment.java

示例7: putCachedRaster

import java.awt.image.ColorModel; //导入依赖的package包/类
static synchronized void putCachedRaster(ColorModel cm, Raster ras) {
    if (cached != null) {
        Raster cras = cached.get();
        if (cras != null) {
            int cw = cras.getWidth();
            int ch = cras.getHeight();
            int iw = ras.getWidth();
            int ih = ras.getHeight();
            if (cw >= iw && ch >= ih) {
                return;
            }
            if (cw * ch >= iw * ih) {
                return;
            }
        }
    }
    cachedModel = cm;
    cached = new WeakReference<>(ras);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:GradientPaintContext.java

示例8: initAcceleratedSurface

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * Create a pixmap-based SurfaceData object
 */
protected SurfaceData initAcceleratedSurface() {
    SurfaceData sData;

    try {
        X11GraphicsConfig gc = (X11GraphicsConfig)vImg.getGraphicsConfig();
        ColorModel cm = gc.getColorModel();
        long drawable = 0;
        if (context instanceof Long) {
            drawable = ((Long)context).longValue();
        }
        sData = X11SurfaceData.createData(gc,
                                          vImg.getWidth(),
                                          vImg.getHeight(),
                                          cm, vImg, drawable,
                                          Transparency.OPAQUE);
    } catch (NullPointerException ex) {
        sData = null;
    } catch (OutOfMemoryError er) {
        sData = null;
    }

    return sData;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:X11VolatileSurfaceManager.java

示例9: xSetBackground

import java.awt.image.ColorModel; //导入依赖的package包/类
public final void xSetBackground(Color c) {
    XToolkit.awtLock();
    try {
        winBackground(c);
        // fix for 6558510: handle sun.awt.noerasebackground flag,
        // see doEraseBackground() and preInit() methods in XCanvasPeer
        if (!doEraseBackground()) {
            return;
        }
        // 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set
        // Note: When OGL is enabled, surfaceData.pixelFor() will not
        // return a pixel value appropriate for passing to
        // XSetWindowBackground().  Therefore, we will use the ColorModel
        // for this component in order to calculate a pixel value from
        // the given RGB value.
        ColorModel cm = getColorModel();
        int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm);
        XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel);
        XlibWrapper.XClearWindow(XToolkit.getDisplay(), getContentWindow());
    }
    finally {
        XToolkit.awtUnlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:XWindow.java

示例10: createComponentCM

import java.awt.image.ColorModel; //导入依赖的package包/类
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:ImageTypeSpecifier.java

示例11: getColorModel

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {

    if (model.getTransparency() == transparency) {
        return model;
    }
    switch (transparency) {
    case Transparency.OPAQUE:
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:BufferedImageGraphicsConfig.java

示例12: canEncodeImage

import java.awt.image.ColorModel; //导入依赖的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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:GIFImageWriterSpi.java

示例13: getCachedRaster

import java.awt.image.ColorModel; //导入依赖的package包/类
static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) {
    if (cm == cachedModel) {
        if (cached != null) {
            Raster ras = cached.get();
            if (ras != null &&
                ras.getWidth() >= w &&
                ras.getHeight() >= h)
            {
                cached = null;
                return ras;
            }
        }
    }
    return cm.createCompatibleWritableRaster(w, h);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:GradientPaintContext.java

示例14: createAcceleratedImage

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * Creates a new managed image of the given width and height
 * that is associated with the target Component.
 */
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Win32GraphicsConfig.java

示例15: setPixels

import java.awt.image.ColorModel; //导入依赖的package包/类
/**
 * Choose which rows and columns of the delivered int pixels are
 * needed for the destination scaled image and pass through just
 * those rows and columns that are needed, replicated as necessary.
 * <p>
 * Note: This method is intended to be called by the
 * {@code ImageProducer} of the {@code Image} whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, int pixels[], int off,
                      int scansize) {
    if (srcrows == null || srccols == null) {
        calculateMaps();
    }
    int sx, sy;
    int dx1 = (2 * x * destWidth + srcWidth - 1) / (2 * srcWidth);
    int dy1 = (2 * y * destHeight + srcHeight - 1) / (2 * srcHeight);
    int outpix[];
    if (outpixbuf != null && outpixbuf instanceof int[]) {
        outpix = (int[]) outpixbuf;
    } else {
        outpix = new int[destWidth];
        outpixbuf = outpix;
    }
    for (int dy = dy1; (sy = srcrows[dy]) < y + h; dy++) {
        int srcoff = off + scansize * (sy - y);
        int dx;
        for (dx = dx1; (sx = srccols[dx]) < x + w; dx++) {
            outpix[dx] = pixels[srcoff + sx - x];
        }
        if (dx > dx1) {
            consumer.setPixels(dx1, dy, dx - dx1, 1,
                               model, outpix, dx1, destWidth);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:ReplicateScaleFilter.java


注:本文中的java.awt.image.ColorModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。