java.awt.image.DataBufferInt Java Examples

The following examples show how to use java.awt.image.DataBufferInt. 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: IncorrectAlphaConversionBicubic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: IMGUtils.java    From icafe with Eclipse Public License 1.0 6 votes vote down vote up
public static void RGB2CMYK(ICC_ColorSpace cmykColorSpace, int[] rgb, float[][] C, float[][] M, float[][] Y, float[][] K, int imageWidth, int imageHeight) {
	DataBuffer db = new DataBufferInt(rgb, rgb.length);
	WritableRaster raster = Raster.createPackedRaster(db, imageWidth, imageHeight, imageWidth,  new int[] {0x00ff0000, 0x0000ff00, 0x000000ff}, null);
	ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);

	ColorConvertOp cco = new ColorConvertOp(sRGB, cmykColorSpace, null);
	
	BufferedImage rgbImage = new BufferedImage(new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff), raster, false, null);
	BufferedImage cmykImage = cco.filter(rgbImage, null);
	WritableRaster cmykRaster = cmykImage.getRaster();
	
	byte[] cmyk = (byte[])cmykRaster.getDataElements(0, 0, imageWidth, imageHeight, null);
	
	for(int i = 0, index = 0; i < imageHeight; i++) {
		for(int j = 0; j < imageWidth; j++) {
			C[i][j] = (cmyk[index++]&0xff) - 128.0f;
			M[i][j] = (cmyk[index++]&0xff) - 128.0f;
			Y[i][j] = (cmyk[index++]&0xff) - 128.0f;
			K[i][j] = (cmyk[index++]&0xff) - 128.0f;
		}
	}
}
 
Example #3
Source File: ShaderUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static final ByteBuffer getImageDataFromImage(BufferedImage bufferedImage) {
	WritableRaster wr;
	DataBuffer db;

	BufferedImage bi = new BufferedImage(128, 64, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	g.drawImage(bufferedImage, null, null);
	bufferedImage = bi;
	wr = bi.getRaster();
	db = wr.getDataBuffer();

	DataBufferInt dbi = (DataBufferInt) db;
	int[] data = dbi.getData();

	ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * 4);
	byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
	byteBuffer.asIntBuffer().put(data);
	byteBuffer.flip();

	return byteBuffer;
}
 
Example #4
Source File: IncorrectClipXorModeSW2Surface.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage getBufferedImage(int sw) {
    final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, sw, sw);
    g2d.dispose();

    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;
}
 
Example #5
Source File: ScreenGPU.java    From PengueeBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void grab(Rectangle rect) throws Exception {

	// ADD UPDATE CHECK, IT MAY FAIL SOMETIMES
	if (screenImage == null) {
		grab();
		return;
	}
	screenImage = robot.createScreenCapture(rect);
	final int pixels[] = ((DataBufferInt) screenImage.getData().getDataBuffer()).getData();
	long[] buffer_origin = new long[] { rect.x * Sizeof.cl_int, rect.y, 0 }; // setup initial offsets
	long[] host_origin = new long[] { 0, 0, 0 }; // screenshot data has no offsets
	long[] region = new long[] { rect.width * Sizeof.cl_int, rect.height, 1 }; // set rectangle bounds
	int result = clEnqueueWriteBufferRect(commandQueue, memObjects[0], CL_TRUE, buffer_origin, host_origin, region,
			(long) (screenRect.width * Sizeof.cl_int), (long) 0, (long) (rect.width * Sizeof.cl_int), (long) 0,
			Pointer.to(pixels), 0, null, null);
	if (result != CL_SUCCESS)
		throw new Exception(String.valueOf(result).concat(" screenshot update error occured"));
}
 
Example #6
Source File: UnmanagedDrawImagePerformance.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
    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;
}
 
Example #7
Source File: UnmanagedDrawImagePerformance.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
    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;
}
 
Example #8
Source File: DistanceTable.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public BufferedImage getImage (int maxDistance)
{
    final BufferedImage img = new BufferedImage(
            getWidth(),
            getHeight(),
            BufferedImage.TYPE_INT_ARGB);

    // Built a LUT (biased one cell to make room for VALUE_UNKNOWN)
    final int rawDistMax = maxDistance * normalizer;
    final int[] lut = getLut(rawDistMax);

    // Process image data, pixel by pixel
    final int[] data = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
    Arrays.fill(data, Color.WHITE.getRGB()); // All white by default

    for (int i = (getWidth() * getHeight()) - 1; i >= 0; i--) {
        final int val = getValue(i);

        if (val < rawDistMax) {
            data[i] = lut[1 + val]; // LUT is biased
        }
    }

    return img;
}
 
Example #9
Source File: ImageTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: UnmanagedDrawImagePerformance.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
    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;
}
 
Example #11
Source File: IncorrectAlphaConversionBicubic.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: JLightweightFrame.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
    content.paintLock();
    try {
        int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
        if (reset) {
            copyBuffer = new int[srcBuffer.length];
        }
        int linestride = bbImage.getWidth();

        x *= scale;
        y *= scale;
        w *= scale;
        h *= scale;

        for (int i=0; i<h; i++) {
            int from = (y + i) * linestride + x;
            System.arraycopy(srcBuffer, from, copyBuffer, from, w);
        }
    } finally {
        content.paintUnlock();
    }
}
 
Example #13
Source File: PnmImageParserTest.java    From commons-imaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteImageRaw_happyCase() throws ImageWriteException,
                                                 ImageReadException, IOException {
    final BufferedImage srcImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
    final Map<String, Object> params = new HashMap<>();
    params.put(PnmImageParser.PARAM_KEY_PNM_RAWBITS, PnmImageParser.PARAM_VALUE_PNM_RAWBITS_YES);

    final byte[] dstBytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNM, params);
    final BufferedImage dstImage = Imaging.getBufferedImage(dstBytes);

    assertTrue(srcImage.getWidth() == dstImage.getWidth());
    assertTrue(srcImage.getHeight() == dstImage.getHeight());

    final DataBufferInt srcData = (DataBufferInt) srcImage.getRaster().getDataBuffer();
    final DataBufferInt dstData = (DataBufferInt) dstImage.getRaster().getDataBuffer();

    for (int bank = 0; bank < srcData.getNumBanks(); bank++) {
        final int[] actual = srcData.getData(bank);
        final int[] expected = dstData.getData(bank);

        assertArrayEquals(actual, expected);
    }
}
 
Example #14
Source File: ColorLUT.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Renders an image with all possible colors. The image can be used to
 * display the color look-up table.
 *
 * @param width Width of the image
 * @param height Height of the image
 * @return The new image.
 */
@Override
public BufferedImage getDiagramImage(int width, int height) {
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    int[] imageBuffer = ((DataBufferInt) (img.getRaster().getDataBuffer())).getData();
    for (int r = 0; r < height; r++) {
        for (int c = 0; c < width; c++) {
            double x = c / (width - 1d);
            double y = 1d - r / (height - 1d);
            int lutCol = (int) Math.round(x * (ColorLUT.LUT_SIZE - 1));
            int lutRow = (int) Math.round(y * (ColorLUT.LUT_SIZE - 1));
            imageBuffer[r * width + c] = lut[lutRow][lutCol];
        }
    }
    return img;
}
 
Example #15
Source File: IMGUtils.java    From icafe with Eclipse Public License 1.0 6 votes vote down vote up
public static void RGB2YCCK_Inverted(ICC_ColorSpace cmykColorSpace, int[] rgb, float[][] Y, float[][] Cb, float[][] Cr, float[][] K, int imageWidth, int imageHeight) {
	DataBuffer db = new DataBufferInt(rgb, rgb.length);
	WritableRaster raster = Raster.createPackedRaster(db, imageWidth, imageHeight, imageWidth,  new int[] {0x00ff0000, 0x0000ff00, 0x000000ff}, null);
	ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);

	ColorConvertOp cco = new ColorConvertOp(sRGB, cmykColorSpace, null);
	
	BufferedImage rgbImage = new BufferedImage(new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff), raster, false, null);
	BufferedImage cmykImage = cco.filter(rgbImage, null);
	WritableRaster cmykRaster = cmykImage.getRaster();
	
	byte[] cmyk = (byte[])cmykRaster.getDataElements(0, 0, imageWidth, imageHeight, null);		
	float c, m, y;
	for(int i = 0, index = 0; i < imageHeight; i++) {
		for(int j = 0; j < imageWidth; j++) {
			c = 255.0f - (cmyk[index++]&0xff); // Red
			m = 255.0f - (cmyk[index++]&0xff); // Green
			y = 255.0f - (cmyk[index++]&0xff); // Blue							
			Y[i][j] = 128.0f - (c*0.299f + m*0.587f + y*0.114f);
			Cb[i][j] = 0.16874f*c + 0.33126f*m - 0.5f*y;
			Cr[i][j] = - 0.5f*c + 0.41869f*m + 0.08131f*y;
			K[i][j] = 128.0f - (cmyk[index++]&0xff);
		}
	}
}
 
Example #16
Source File: Renderer.java    From minicraft-plus-revived with GNU General Public License v3.0 6 votes vote down vote up
static void initScreen() {
	if(!HAS_GUI) return;
	
	image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
	pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

	try {
		// This sets up the screens, and loads the different spritesheets.
		initSpriteSheets();
	} catch (IOException e) {
		e.printStackTrace();
	}
	screen.pixels = pixels;
	
	if(HAS_GUI) {
		canvas.createBufferStrategy(3);
		canvas.requestFocus();
	}
}
 
Example #17
Source File: IncorrectUnmanagedImageRotatedClip.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #18
Source File: IncorrectUnmanagedImageRotatedClip.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #19
Source File: UnmanagedDrawImagePerformance.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
    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;
}
 
Example #20
Source File: IncorrectUnmanagedImageRotatedClip.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #21
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates an RGB image from the given raw byte array, performing any
 * necessary type conversions.
 *
 * @param data Array containing image data.
 * @param c Nuber of channels. NB: Channels over 4 will be discarded.
 * @param h Height of image plane.
 * @param w Width of image plane.
 * @param interleaved If set, the channels are assumed to be interleaved;
 *          otherwise they are assumed to be sequential. For example, for RGB
 *          data, the pattern "RGBRGBRGB..." is interleaved, while
 *          "RRR...GGG...BBB..." is sequential.
 */
public static BufferedImage makeRGBImage(final byte[] data, final int c,
	final int w, final int h, final boolean interleaved)
{
	final int cc = Math.min(c, 4); // throw away channels beyond 4
	final int[] buf = new int[data.length / c];
	final int nBits = (cc - 1) * 8;

	for (int i = 0; i < buf.length; i++) {
		for (int q = 0; q < cc; q++) {
			if (interleaved) {
				buf[i] |= ((data[i * c + q] & 0xff) << (nBits - q * 8));
			}
			else {
				buf[i] |= ((data[q * buf.length + i] & 0xff) << (nBits - q * 8));
			}
		}
	}

	final DataBuffer buffer = new DataBufferInt(buf, buf.length);
	return constructImage(cc, DataBuffer.TYPE_INT, w, h, false, false, buffer);
}
 
Example #22
Source File: IncorrectUnmanagedImageSourceOffset.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage bi = new BufferedImage(511, 255, type);
    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;
}
 
Example #23
Source File: IncorrectAlphaConversionBicubic.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: ImageTests.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #25
Source File: IncorrectUnmanagedImageRotatedClip.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #26
Source File: MultipleGradientPaintContext.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public final Raster getRaster(int x, int y, int w, int h) {
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    Raster raster = saved;
    if (raster == null ||
        raster.getWidth() < w || raster.getHeight() < h)
    {
        raster = getCachedRaster(model, w, h);
        saved = raster;
    }

    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    // These calls make the DataBuffer non-acceleratable, but the
    // Raster is never Stable long enough to accelerate anyway...
    DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer();
    int[] pixels = rasterDB.getData(0);
    int off = rasterDB.getOffset();
    int scanlineStride = ((SinglePixelPackedSampleModel)
                          raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;

    fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass

    return raster;
}
 
Example #27
Source File: BiomeExporter.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Raster getData(Rectangle rect) {
	DataBufferInt buffer = new DataBufferInt(Math.multiplyExact(rect.width, rect.height));
	
	int[] pixelArray = buffer.getData();
	
	short[][] dataArray;
	
	dataArray = new short[rect.width][rect.height];
	biomeDataOracle.populateArray(new CoordinatesInWorld((long) worldX + rect.x * resolutionFactor, (long) worldY + rect.y * resolutionFactor), dataArray, useQuarterResolution);

	try {
		for (int imgY = 0; imgY < rect.height; imgY++) {
			for (int imgX = 0; imgX < rect.width; imgX++) {
				int imgidx = (rect.height - imgY - 1) * rect.width + imgX;
				pixelArray[imgidx] = biomeProfileSelection.getBiomeColor(dataArray[imgX][imgY]).getRGB();
			}
		}
	} catch (Exception e) {
		AmidstLogger.error(e);
	}
	
	dataArray = null;
	
	Raster r = Raster.createPackedRaster(buffer, rect.width, rect.height, rect.width, BITMASKS, new Point(rect.x, rect.y));
	
	progressReporter.report(entry(PROGRESS, rect.y));
	
	return r;
}
 
Example #28
Source File: ImageService.java    From jlineup with Apache License 2.0 5 votes vote down vote up
public static boolean bufferedImagesEqualQuick(BufferedImage image1, BufferedImage image2) {
    DataBuffer dataBuffer1 = image1.getRaster().getDataBuffer();
    DataBuffer dataBuffer2 = image2.getRaster().getDataBuffer();
    if (dataBuffer1 instanceof DataBufferByte && dataBuffer2 instanceof DataBufferByte) {
        DataBufferByte dataBufferBytes1 = (DataBufferByte) dataBuffer1;
        DataBufferByte dataBufferBytes2 = (DataBufferByte) dataBuffer2;
        for (int bank = 0; bank < dataBufferBytes1.getNumBanks(); bank++) {
            byte[] bytes1 = dataBufferBytes1.getData(bank);
            byte[] bytes2 = dataBufferBytes2.getData(bank);
            if (!Arrays.equals(bytes1, bytes2)) {
                return false;
            }
        }
    } else if (dataBuffer1 instanceof DataBufferInt && dataBuffer2 instanceof DataBufferInt) {
        DataBufferInt dataBufferInt1 = (DataBufferInt) dataBuffer1;
        DataBufferInt dataBufferInt2 = (DataBufferInt) dataBuffer2;
        for (int bank = 0; bank < dataBufferInt1.getNumBanks(); bank++) {
            int[] ints1 = dataBufferInt1.getData(bank);
            int[] ints2 = dataBufferInt2.getData(bank);
            if (!Arrays.equals(ints1, ints2)) {
                return false;
            }
        }
    } else {
        return false;
    }
    return true;
}
 
Example #29
Source File: SoftwareGraphicsSystem.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
public DataBuffer newBuffer(DoomScreen screen) {
    final V buffer = screens.get(screen);
    if (buffer.getClass() == int[].class) {
        return new DataBufferInt((int[]) buffer, ((int[]) buffer).length);
    } else if (buffer.getClass() == short[].class) {
        return new DataBufferUShort((short[]) buffer, ((short[]) buffer).length);
    } else if (buffer.getClass() == byte[].class) {
        return new DataBufferByte((byte[]) buffer, ((byte[]) buffer).length);
    }
    
    throw new UnsupportedOperationException(String.format("SoftwareVideoRenderer does not support %s buffers", buffer.getClass()));
}
 
Example #30
Source File: OpaqueImageToSurfaceBlitTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
        vi.validate(gc);

        BufferedImage bi =
            new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
        int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
        data[0] = 0x0000007f;
        data[1] = 0x0000007f;
        data[2] = 0xff00007f;
        data[3] = 0xff00007f;
        Graphics2D g = vi.createGraphics();
        g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
        g.drawImage(bi, 0, 0, null);

        bi = vi.getSnapshot();
        if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
            throw new RuntimeException("Test FAILED: color at 0x0 ="+
                Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
                Integer.toHexString(bi.getRGB(1,1)));
        }

        System.out.println("Test PASSED.");
    }