Java 类java.awt.image.DataBuffer 实例源码

项目:openjdk-jdk10    文件:IndexColorModelEqualsTest.java   
private static void testSizeEquality() {
    // test with different size for cmap.
    IndexColorModel model1 = new IndexColorModel(8, 4,
            new int[] {1, 2, 3, 4},
            0, true, -1, DataBuffer.TYPE_BYTE);
    IndexColorModel model2 = new IndexColorModel(8, 3,
            new int[] {1, 2, 3},
            0, true, -1, DataBuffer.TYPE_BYTE);
    if (model1.equals(model2)) {
        throw new RuntimeException("equals() method is determining"
                + " Map size equality improperly");
    }
    if (model2.equals(model1)) {
        throw new RuntimeException("equals() method is determining"
                + " Map size equality improperly");
    }
}
项目:OpenJSharp    文件:ImageTests.java   
public Image makeImage(TestEnvironment env, int w, int h) {
    BufferedImage img = new BufferedImage(w, h, type);
    if (unmanaged) {
        DataBuffer db = img.getRaster().getDataBuffer();
        if (db instanceof DataBufferInt) {
            ((DataBufferInt)db).getData();
        } else if (db instanceof DataBufferShort) {
            ((DataBufferShort)db).getData();
        } else if (db instanceof DataBufferByte) {
            ((DataBufferByte)db).getData();
        } else {
            try {
                img.setAccelerationPriority(0.0f);
            } catch (Throwable e) {}
        }
    }
    return img;
}
项目:jdk8u-jdk    文件:IncorrectAlphaConversionBicubic.java   
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
                                             int type) {
    BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(RGB);
    g2d.fillRect(0, 0, SIZE, SIZE);
    g2d.dispose();
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
项目:openjdk-jdk10    文件:ColConvTest.java   
static String getDTName(int dType) {
    switch(dType) {
        case DataBuffer.TYPE_BYTE:
            return "TYPE_BYTE";
        case DataBuffer.TYPE_DOUBLE:
            return "TYPE_DOUBLE";
        case DataBuffer.TYPE_FLOAT:
            return "TYPE_FLOAT";
        case DataBuffer.TYPE_INT:
            return "TYPE_INT";
        case DataBuffer.TYPE_SHORT:
            return "TYPE_SHORT";
        case DataBuffer.TYPE_USHORT:
            return "TYPE_USHORT";
        case DataBuffer.TYPE_UNDEFINED:
            return "TYPE_UNDEFINED";
    }
    return "UNKNOWN";
}
项目:openjdk-jdk10    文件:D3DGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:jdk8u-jdk    文件:WGLGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:openjdk-jdk10    文件:GetDataElementsTest.java   
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
项目:OpenJSharp    文件:ImageUtil.java   
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
项目:jdk8u-jdk    文件:D3DGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:jdk8u-jdk    文件:ImageUtil.java   
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
项目:OpenJSharp    文件:WGLGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:jdk8u-jdk    文件:IncorrectUnmanagedImageRotatedClip.java   
private static BufferedImage makeUnmanagedBI() {
    final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:openjdk-jdk10    文件:ImageUtil.java   
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
项目:openjdk-jdk10    文件:IndexColorModelEqualsTest.java   
private static void testValidPixelsEquality() {
    // test with different valid pixels.
    /*
     * In setRGBs() function of IndexColorModel we override
     * transparent_index value to map to pixel value if alpha is 0x00
     * so we should have atleast minimum alpha value to verify
     * equality of validBits thats why we have color value as
     * 16777216(2 ^ 24).
     */
    int color = 16777216;
    IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("2"));
    if (model1.equals(model2)) {
        throw new RuntimeException("equals() method is determining"
                + " Valid pixels equality improperly");
    }
    if (model2.equals(model1)) {
        throw new RuntimeException("equals() method is determining"
                + " Valid pixels equality improperly");
    }
}
项目:openjdk-jdk10    文件:IncorrectAlphaConversionBicubic.java   
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
                                             int type) {
    BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(RGB);
    g2d.fillRect(0, 0, SIZE, SIZE);
    g2d.dispose();
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
项目:OpenJSharp    文件:Buffers.java   
/**
  * Create a data buffer of a particular type.
  *
  * @param dataType the desired data type of the buffer.
  * @param size the size of the data buffer bank
  * @param numBanks the number of banks the buffer should have
  */
 public static DataBuffer createBuffer(int dataType, int size, int numBanks)
 {
   switch (dataType)
     {
     case DataBuffer.TYPE_BYTE:
return new DataBufferByte(size, numBanks);
     case DataBuffer.TYPE_SHORT:
return new DataBufferShort(size, numBanks);
     case DataBuffer.TYPE_USHORT:
return new DataBufferUShort(size, numBanks);
     case DataBuffer.TYPE_INT:
return new DataBufferInt(size, numBanks);
     case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat(size, numBanks);
     case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble(size, numBanks);
     default:
throw new UnsupportedOperationException();
     }
 }
项目:openjdk-jdk10    文件:IndexColorModelEqualsTest.java   
private static void testConstructor7() {
    /*
     * verify equality with constructor
     * IndexColorModel(int bits, int size, int[] cmap, int start,
     * int transferType, BigInteger validBits)
     */
    /*
     * In setRGBs() function of IndexColorModel we override
     * transparent_index value to map to pixel value if alpha is 0x00
     * so we should have atleast minimum alpha value to keep
     * both model1 and model2 same.
     */
    int color = 16777216;
    IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    verifyEquals(model1, model2);
}
项目:etomica    文件:Image.java   
/**
 * @param windowWidth
 * @param windowHeight
 * @param pBuffer
 * @param windowSize
 * @param backgroundTransparent
 * @return an Image
 */
static Object allocateRgbImage(int windowWidth, int windowHeight,
                               int[] pBuffer, int windowSize,
                               boolean backgroundTransparent) {
  //backgroundTransparent not working with antialiasDisplay. I have no idea why. BH 9/24/08
  /* DEAD CODE   if (false && backgroundTransparent)
        return new BufferedImage(
            rgbColorModelT,
            Raster.createWritableRaster(
                new SinglePixelPackedSampleModel(
                    DataBuffer.TYPE_INT,
                    windowWidth,
                    windowHeight,
                    sampleModelBitMasksT), 
                new DataBufferInt(pBuffer, windowSize),
                null),
            false, 
            null);
  */
  return new BufferedImage(rgbColorModel, Raster.createWritableRaster(
      new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, windowWidth,
          windowHeight, sampleModelBitMasks), new DataBufferInt(pBuffer,
          windowSize), null), false, null);
}
项目:jdk8u-jdk    文件:ImageTests.java   
public Image makeImage(TestEnvironment env, int w, int h) {
    BufferedImage img = new BufferedImage(w, h, type);
    if (unmanaged) {
        DataBuffer db = img.getRaster().getDataBuffer();
        if (db instanceof DataBufferInt) {
            ((DataBufferInt)db).getData();
        } else if (db instanceof DataBufferShort) {
            ((DataBufferShort)db).getData();
        } else if (db instanceof DataBufferByte) {
            ((DataBufferByte)db).getData();
        } else {
            try {
                img.setAccelerationPriority(0.0f);
            } catch (Throwable e) {}
        }
    }
    return img;
}
项目:openjdk-jdk10    文件:GLXGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:incubator-netbeans    文件:CSampleModel.java   
/** Creates a new instance of CSampleModel */
public CSampleModel(int width, int height) {
    super (DataBuffer.TYPE_INT, width, height, MASKS);
    this.buf = buf;
    this.width = width;
    this.height = height;
}
项目:incubator-netbeans    文件:ImageBuilder.java   
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int size = fa.getInt(instance, "size");                        // NOI18N
    int[] offsets = fa.getIntArray(instance, "offsets", false);      // NOI18N
    //int[] data = fa.getIntArray(instance, "data", false);     // NOI18N
    int[][] bankdata = fa.getIntArray2(instance, "bankdata", false); // NOI18N
    return new DataBufferInt(bankdata, size, offsets);
}
项目:incubator-netbeans    文件:ImageBuilder.java   
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int size = fa.getInt(instance, "size");                        // NOI18N
    int[] offsets = fa.getIntArray(instance, "offsets", false);      // NOI18N
    byte[][] bankdata = fa.getByteArray2(instance, "bankdata", false); // NOI18N
    return new DataBufferByte(bankdata, size, offsets);
}
项目:incubator-netbeans    文件:ImageBuilder.java   
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int size = fa.getInt(instance, "size");                        // NOI18N
    int[] offsets = fa.getIntArray(instance, "offsets", false);      // NOI18N
    short[][] bankdata = fa.getShortArray2(instance, "bankdata", false); // NOI18N
    return new DataBufferUShort(bankdata, size, offsets);
}
项目:rapidminer    文件:ToolbarHandlerBuffer.java   
private void createImage() {
    if (this.gc != null) {
        this.image = this.gc.createCompatibleImage(IMAGE_SIZE, IMAGE_SIZE, Transparency.BITMASK);
    } else {
        int cmap[] = { this.topColor.getRGB(), this.shadowColor.getRGB() };
        IndexColorModel icm = new IndexColorModel(8, 3, cmap, 0, false, -1, DataBuffer.TYPE_BYTE);
        this.image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_BYTE_INDEXED, icm);
    }
}
项目:sumo    文件:KmlIO.java   
private static URL createOverview(GeoImageReader gir, boolean toFlip) throws IOException {
    File f = File.createTempFile("kmloverview", ".png");
    // generate a suitable size image
    double ratio = Math.max(((double) gir.getWidth()) / 1024., ((double) gir.getHeight()) / 1024.);
    // generate overview image
    BufferedImage temp = new BufferedImage((int) (gir.getWidth() * (1.0 / ratio)), (int) (gir.getHeight() * (1.0 / ratio)), gir.getType(true));
    // get a handle on the raster data
    WritableRaster raster = temp.getRaster();
    int[] data = gir.readAndDecimateTile(0, 0, gir.getWidth(), gir.getHeight(), 1.0 / ratio, true,0);
    raster.setSamples(0, 0, temp.getWidth(), temp.getHeight(), 0, data);

    float average = 0;
    for (int i = 0; i < data.length; i++) {
        average = average + data[i];
    }
    average = average / data.length;
    RescaleOp rescale = new RescaleOp(((1 << (8 * gir.getNumberOfBytes())) / 5f / average), 0, null);
    rescale.filter(temp, temp);

    ColorConvertOp bop = new ColorConvertOp(null);
    BufferedImage out = bop.createCompatibleDestImage(temp, new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE));
    out = bop.filter(temp, out);

    //flip the image if necessary
    if (toFlip) {
        int w = out.getWidth();
        int h = out.getHeight();
        BufferedImage dimg = new BufferedImage(w, h, out.getType());
        Graphics2D g = dimg.createGraphics();
        g.drawImage(out, 0, 0, w, h, w, 0, 0, h, null);
        g.dispose();
        ImageIO.write(dimg, "png", f);
    } else {
        ImageIO.write(out, "png", f);
    }
    return f.toURI().toURL();

}
项目:openjdk-jdk10    文件:IndexColorModelEqualsTest.java   
private static void testConstructor6() {
    /*
     * verify equality with constructor
     * IndexColorModel(int bits, int size, int[] cmap, int start,
     * boolean hasalpha, int trans, int transferType)
     */
    IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {1, 2, 3},
            0, true, -1, DataBuffer.TYPE_BYTE);
    IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {1, 2, 3},
            0, true, -1, DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
项目:omr-dataset-tools    文件:SubImages.java   
/**
 * Build the sub-image that corresponds to the provided row of features.
 *
 * @param row the flat row of pixel values
 * @return the bufferedImage
 */
public static BufferedImage buildSubImage (INDArray row)
{
    // Build a gray image with vector values
    BufferedImage grayImg = new BufferedImage(
            CONTEXT_WIDTH,
            CONTEXT_HEIGHT,
            BufferedImage.TYPE_BYTE_GRAY);
    WritableRaster raster = grayImg.getRaster();
    DataBuffer buffer = raster.getDataBuffer();
    DataBufferByte byteBuffer = (DataBufferByte) buffer;

    for (int r = 0; r < CONTEXT_HEIGHT; r++) {
        int offset = r * CONTEXT_WIDTH;

        for (int c = 0; c < CONTEXT_WIDTH; c++) {
            int i = offset + c;
            int val = (int) Math.rint(row.getDouble(i));
            val = 255 - val; // Inversion
            byteBuffer.setElem(i, val);
        }
    }

    // Draw colored reference lines on top of image
    BufferedImage colorImg = new BufferedImage(
            CONTEXT_WIDTH,
            CONTEXT_HEIGHT,
            BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = colorImg.createGraphics();
    g.drawImage(grayImg, null, null);
    g.setColor(CROSS_COLOR);
    g.drawLine(CONTEXT_WIDTH / 2, 0, CONTEXT_WIDTH / 2, CONTEXT_HEIGHT);
    g.drawLine(0, CONTEXT_HEIGHT / 2, CONTEXT_WIDTH, CONTEXT_HEIGHT / 2);
    g.dispose();

    return colorImg;
}
项目:openjdk-jdk10    文件:SunToolkit.java   
public static DataBufferInt getScaledIconData(java.util.List<Image> imageList, int width, int height) {
    BufferedImage bimage = getScaledIconImage(imageList, width, height);
    if (bimage == null) {
        return null;
    }
    Raster raster = bimage.getRaster();
    DataBuffer buffer = raster.getDataBuffer();
    return (DataBufferInt)buffer;
}
项目:OpenJSharp    文件:GeneralRenderer.java   
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
项目:openjdk-jdk10    文件:ImageFactory.java   
public static void fillDCM(DataBuffer data, SampleModel sm, int csType,
                           int c1Bits, int c2Bits, int c3Bits)
{
    int [] pixel;
    pixel = new int[4];
    for (int i = 0; i < WIDTH; i++) {
        for (int j = 0; j < HEIGHT; j++) {
            pixel[0] = i >> (8 - c1Bits);
            pixel[1] = j >> (8 - c2Bits);
            pixel[2] = ((i + j)>>1) >> (8 - c3Bits);
            pixel[3] = 0xFF;
            sm.setPixel(i, j, pixel, data);
        }
    }
}
项目:OpenJSharp    文件:ByteComponentRaster.java   
/**
 * Constructs a ByteComponentRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same size as the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferByte compatible with SampleModel.
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or ComponentSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ByteComponentRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
项目:OpenJSharp    文件:ShortComponentRaster.java   
/**
 * Constructs a ShortComponentRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same sizes the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferUShort compatible with SampleModel.
 * SampleModel must be of type ComponentSampleModel or
 * SinglePixelPackedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ShortComponentRaster(SampleModel sampleModel,
                               DataBuffer dataBuffer,
                               Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
项目:jdk8u-jdk    文件:RenderToCustomBufferTest.java   
private static BufferedImage createCustomBuffer() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(cs, false, false,
            Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    WritableRaster wr = cm.createCompatibleWritableRaster(width, height);

    return new BufferedImage(cm, wr, false, null);
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same sizes the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferInt compatible with SampleModel.
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
项目:OpenJSharp    文件:PixelConverter.java   
public int rgbToPixel(int rgb, ColorModel cm) {
    Object obj = cm.getDataElements(rgb, null);
    switch (cm.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        byte[] bytearr = (byte[]) obj;
        int pix = 0;

        switch(bytearr.length) {
        default: // bytearr.length >= 4
            pix = bytearr[3] << 24;
            // FALLSTHROUGH
        case 3:
            pix |= (bytearr[2] & 0xff) << 16;
            // FALLSTHROUGH
        case 2:
            pix |= (bytearr[1] & 0xff) << 8;
            // FALLSTHROUGH
        case 1:
            pix |= (bytearr[0] & 0xff);
        }

        return pix;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        short[] shortarr = (short[]) obj;

        return (((shortarr.length > 1) ? shortarr[1] << 16 : 0) |
                shortarr[0] & 0xffff);
    case DataBuffer.TYPE_INT:
        return ((int[]) obj)[0];
    default:
        return rgb;
    }
}
项目:jdk8u-jdk    文件:BufImgSurfaceData.java   
public BufImgSurfaceData(DataBuffer db,
                         BufferedImage bufImg, SurfaceType sType)
{
    super(SunWritableRaster.stealTrackable(db),
          sType, bufImg.getColorModel());
    this.bufImg = bufImg;
}
项目:jdk8u-jdk    文件:PixelConverter.java   
public int rgbToPixel(int rgb, ColorModel cm) {
    Object obj = cm.getDataElements(rgb, null);
    switch (cm.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        byte[] bytearr = (byte[]) obj;
        int pix = 0;

        switch(bytearr.length) {
        default: // bytearr.length >= 4
            pix = bytearr[3] << 24;
            // FALLSTHROUGH
        case 3:
            pix |= (bytearr[2] & 0xff) << 16;
            // FALLSTHROUGH
        case 2:
            pix |= (bytearr[1] & 0xff) << 8;
            // FALLSTHROUGH
        case 1:
            pix |= (bytearr[0] & 0xff);
        }

        return pix;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        short[] shortarr = (short[]) obj;

        return (((shortarr.length > 1) ? shortarr[1] << 16 : 0) |
                shortarr[0] & 0xffff);
    case DataBuffer.TYPE_INT:
        return ((int[]) obj)[0];
    default:
        return rgb;
    }
}
项目:OpenJSharp    文件:SunWritableRaster.java   
public SunWritableRaster(SampleModel sampleModel,
                         DataBuffer dataBuffer,
                         Rectangle aRegion,
                         Point sampleModelTranslate,
                         WritableRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent);
    theTrackable = stealTrackable(dataBuffer);
}