Java Code Examples for java.awt.image.Raster#getDataElements()

The following examples show how to use java.awt.image.Raster#getDataElements() . 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: ShortInterleavedRaster.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        // Write inRaster (minX, minY) to (dstX, dstY)

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      REMIND: Do something faster!
//      if (inRaster instanceof ShortInterleavedRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY + startY, width, 1, tdata);
        }
    }
 
Example 2
Source File: ShortComponentRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        // Write inRaster (minX, minY) to (dstX, dstY)

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      // REMIND: Do something faster!
//      if (inRaster instanceof ShortComponentRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY + startY, width, 1, tdata);
        }
    }
 
Example 3
Source File: ByteBandedRaster.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      // REMIND: Do something faster!
//      if (inRaster instanceof ByteBandedRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY+startY, width, 1, tdata);
        }
    }
 
Example 4
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * <p>Returns an array of pixels, stored as integers, from a
 * <code>BufferedImage</code>. The pixels are grabbed from a rectangular
 * area defined by a location and two dimensions. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the source image
 * @param x the x location at which to start grabbing pixels
 * @param y the y location at which to start grabbing pixels
 * @param w the width of the rectangle of pixels to grab
 * @param h the height of the rectangle of pixels to grab
 * @param pixels a pre-allocated array of pixels of size w*h; can be null
 * @return <code>pixels</code> if non-null, a new array of integers
 *   otherwise
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static int[] getPixels(BufferedImage img,
                              int x, int y, int w, int h, int[] pixels) {
    if (w == 0 || h == 0) {
        return new int[0];
    }

    if (pixels == null) {
        pixels = new int[w * h];
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        Raster raster = img.getRaster();
        return (int[]) raster.getDataElements(x, y, w, h, pixels);
    }

    // Unmanages the image
    return img.getRGB(x, y, w, h, pixels, 0, w);
}
 
Example 5
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * <p>Returns an array of pixels, stored as integers, from a
 * <code>BufferedImage</code>. The pixels are grabbed from a rectangular
 * area defined by a location and two dimensions. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the source image
 * @param x the x location at which to start grabbing pixels
 * @param y the y location at which to start grabbing pixels
 * @param w the width of the rectangle of pixels to grab
 * @param h the height of the rectangle of pixels to grab
 * @param pixels a pre-allocated array of pixels of size w*h; can be null
 * @return <code>pixels</code> if non-null, a new array of integers
 *   otherwise
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static int[] getPixels(BufferedImage img,
                              int x, int y, int w, int h, int[] pixels) {
    if (w == 0 || h == 0) {
        return new int[0];
    }

    if (pixels == null) {
        pixels = new int[w * h];
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        Raster raster = img.getRaster();
        return (int[]) raster.getDataElements(x, y, w, h, pixels);
    }

    // Unmanages the image
    return img.getRGB(x, y, w, h, pixels, 0, w);
}
 
Example 6
Source File: ShortInterleavedRaster.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        // Write inRaster (minX, minY) to (dstX, dstY)

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      REMIND: Do something faster!
//      if (inRaster instanceof ShortInterleavedRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY + startY, width, 1, tdata);
        }
    }
 
Example 7
Source File: EffectUtils.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns an array of pixels, stored as integers, from a
 * <code>BufferedImage</code>. The pixels are grabbed from a rectangular
 * area defined by a location and two dimensions. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the source image
 * @param x the x location at which to start grabbing pixels
 * @param y the y location at which to start grabbing pixels
 * @param w the width of the rectangle of pixels to grab
 * @param h the height of the rectangle of pixels to grab
 * @param pixels a pre-allocated array of pixels of size w*h; can be null
 * @return <code>pixels</code> if non-null, a new array of integers
 *   otherwise
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static int[] getPixels(BufferedImage img,
                              int x, int y, int w, int h, int[] pixels) {
    if (w == 0 || h == 0) {
        return new int[0];
    }

    if (pixels == null) {
        pixels = new int[w * h];
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        Raster raster = img.getRaster();
        return (int[]) raster.getDataElements(x, y, w, h, pixels);
    }

    // Unmanages the image
    return img.getRGB(x, y, w, h, pixels, 0, w);
}
 
Example 8
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * <p>Returns an array of pixels, stored as integers, from a
 * <code>BufferedImage</code>. The pixels are grabbed from a rectangular
 * area defined by a location and two dimensions. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the source image
 * @param x the x location at which to start grabbing pixels
 * @param y the y location at which to start grabbing pixels
 * @param w the width of the rectangle of pixels to grab
 * @param h the height of the rectangle of pixels to grab
 * @param pixels a pre-allocated array of pixels of size w*h; can be null
 * @return <code>pixels</code> if non-null, a new array of integers
 *   otherwise
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static int[] getPixels(BufferedImage img,
                              int x, int y, int w, int h, int[] pixels) {
    if (w == 0 || h == 0) {
        return new int[0];
    }

    if (pixels == null) {
        pixels = new int[w * h];
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        Raster raster = img.getRaster();
        return (int[]) raster.getDataElements(x, y, w, h, pixels);
    }

    // Unmanages the image
    return img.getRGB(x, y, w, h, pixels, 0, w);
}
 
Example 9
Source File: FastBlurFilter.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Returns an array of pixels, stored as integers, from a
 * <code>BufferedImage</code>. The pixels are grabbed from a rectangular
 * area defined by a location and two dimensions. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the source image
 * @param x the x location at which to start grabbing pixels
 * @param y the y location at which to start grabbing pixels
 * @param w the width of the rectangle of pixels to grab
 * @param h the height of the rectangle of pixels to grab
 * @param pixels a pre-allocated array of pixels of size w*h; can be null
 * @return <code>pixels</code> if non-null, a new array of integers
 *   otherwise
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
private static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) {
	if (w == 0 || h == 0) {
		return new int[0];
	}

	final int[] pix;
	if (pixels == null) {
		pix = new int[w * h];
	} else if (pixels.length < w * h) {
		throw new IllegalArgumentException("pixels array must have a length >= w*h");
	} else {
		pix = pixels;
	}

	final int imageType = img.getType();
	if (imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_RGB) {
		final Raster raster = img.getRaster();
		return (int[]) raster.getDataElements(x, y, w, h, pix);
	}

	// Unmanages the image
	return img.getRGB(x, y, w, h, pix, 0, w);
}
 
Example 10
Source File: ByteBandedRaster.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      // REMIND: Do something faster!
//      if (inRaster instanceof ByteBandedRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY+startY, width, 1, tdata);
        }
    }
 
Example 11
Source File: ShortComponentRaster.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        // Write inRaster (minX, minY) to (dstX, dstY)

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      // REMIND: Do something faster!
//      if (inRaster instanceof ShortComponentRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY + startY, width, 1, tdata);
        }
    }
 
Example 12
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * <p>Returns an array of pixels, stored as integers, from a
 * <code>BufferedImage</code>. The pixels are grabbed from a rectangular
 * area defined by a location and two dimensions. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the source image
 * @param x the x location at which to start grabbing pixels
 * @param y the y location at which to start grabbing pixels
 * @param w the width of the rectangle of pixels to grab
 * @param h the height of the rectangle of pixels to grab
 * @param pixels a pre-allocated array of pixels of size w*h; can be null
 * @return <code>pixels</code> if non-null, a new array of integers
 *   otherwise
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static int[] getPixels(BufferedImage img,
                              int x, int y, int w, int h, int[] pixels) {
    if (w == 0 || h == 0) {
        return new int[0];
    }

    if (pixels == null) {
        pixels = new int[w * h];
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        Raster raster = img.getRaster();
        return (int[]) raster.getDataElements(x, y, w, h, pixels);
    }

    // Unmanages the image
    return img.getRGB(x, y, w, h, pixels, 0, w);
}
 
Example 13
Source File: ShortInterleavedRaster.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Stores the Raster data at the specified location.
     * @param dstX The absolute X coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param dstY The absolute Y coordinate of the destination pixel
     * that will receive a copy of the upper-left pixel of the
     * inRaster
     * @param width      The number of pixels to store horizontally
     * @param height     The number of pixels to store vertically
     * @param inRaster   Raster of data to place at x,y location.
     */
    private void setDataElements(int dstX, int dstY,
                                 int width, int height,
                                 Raster inRaster) {
        // Assume bounds checking has been performed previously
        if (width <= 0 || height <= 0) {
            return;
        }

        // Write inRaster (minX, minY) to (dstX, dstY)

        int srcOffX = inRaster.getMinX();
        int srcOffY = inRaster.getMinY();
        Object tdata = null;

//      REMIND: Do something faster!
//      if (inRaster instanceof ShortInterleavedRaster) {
//      }

        for (int startY=0; startY < height; startY++) {
            // Grab one scanline at a time
            tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                             width, 1, tdata);
            setDataElements(dstX, dstY + startY, width, 1, tdata);
        }
    }
 
Example 14
Source File: PixelTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object context, int numReps) {
    Raster ras = ((Context) context).ras;
    Object elemdata = ((Context) context).elemdata;
    do {
        ras.getDataElements(numReps&7, 0, elemdata);
    } while (--numReps > 0);
}
 
Example 15
Source File: ByteComponentRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Stores the Raster data at the specified location.
 * @param dstX The absolute X coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param dstY The absolute Y coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param width      The number of pixels to store horizontally
 * @param height     The number of pixels to store vertically
 * @param inRaster   Raster of data to place at x,y location.
 */
private void setDataElements(int dstX, int dstY,
                             int width, int height,
                             Raster inRaster) {
    // Assume bounds checking has been performed previously
    if (width <= 0 || height <= 0) {
        return;
    }

    int srcOffX = inRaster.getMinX();
    int srcOffY = inRaster.getMinY();
    Object tdata = null;

    if (inRaster instanceof ByteComponentRaster) {
        ByteComponentRaster bct = (ByteComponentRaster) inRaster;
        byte[] bdata = bct.getDataStorage();
        // REMIND: Do something faster!
        if (numDataElements == 1) {
            int toff = bct.getDataOffset(0);
            int tss  = bct.getScanlineStride();

            int srcOffset = toff;
            int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
                                           (dstX-minX);


            if (pixelStride == bct.getPixelStride()) {
                width *= pixelStride;
                for (int tmpY=0; tmpY < height; tmpY++) {
                    System.arraycopy(bdata, srcOffset,
                                     data, dstOffset, width);
                    srcOffset += tss;
                    dstOffset += scanlineStride;
                }
                markDirty();
                return;
            }
        }
    }

    for (int startY=0; startY < height; startY++) {
        // Grab one scanline at a time
        tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                         width, 1, tdata);
        setDataElements(dstX, dstY+startY, width, 1, tdata);
    }
}
 
Example 16
Source File: LwjglTextureUtils.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static int createTexture(BufferedImage imageData, TextureFilter filterMode)
{
	imageData = convertToGlFormat(imageData);
	
	IntBuffer buff = BufferUtils.createIntBuffer(16);
	buff.limit(1);
	GL11.glGenTextures(buff);
	
	int textureId = buff.get();
	
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
	if (filterMode == TextureFilter.NEAREST)
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
	}
	else
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	}
	
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	
	ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight());

	Raster raster = imageData.getRaster();
	byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null);
	scratch.clear();
	scratch.put(data);
	scratch.rewind();
	
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,					// Mip level & Internal format
						imageData.getWidth(), imageData.getHeight(), 0,		// width, height, border
						GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,				// pixel data format
						scratch);											// pixel data
	
	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
			0, 0,
			imageData.getWidth(), imageData.getHeight(),
			GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,			// format, type
			scratch);
	
	return textureId;
}
 
Example 17
Source File: IntegerInterleavedRaster.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Stores the Raster data at the specified location.
 * @param dstX The absolute X coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param dstY The absolute Y coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param width      The number of pixels to store horizontally
 * @param height     The number of pixels to store vertically
 * @param inRaster   Raster of data to place at x,y location.
 */
private void setDataElements(int dstX, int dstY,
                             int width, int height,
                             Raster inRaster) {
    // Assume bounds checking has been performed previously
    if (width <= 0 || height <= 0) {
        return;
    }

    // Write inRaster (minX, minY) to (dstX, dstY)

    int srcOffX = inRaster.getMinX();
    int srcOffY = inRaster.getMinY();
    int tdata[] = null;

    if (inRaster instanceof IntegerInterleavedRaster) {
        IntegerInterleavedRaster ict = (IntegerInterleavedRaster) inRaster;

        // Extract the raster parameters
        tdata    = ict.getDataStorage();
        int tss  = ict.getScanlineStride();
        int toff = ict.getDataOffset(0);

        int srcOffset = toff;
        int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
                                       (dstX-minX);


        // Fastest case.  We can copy scanlines
        // Loop through all of the scanlines and copy the data
        for (int startY=0; startY < height; startY++) {
            System.arraycopy(tdata, srcOffset, data, dstOffset, width);
            srcOffset += tss;
            dstOffset += scanlineStride;
        }
        markDirty();
        return;
    }

    Object odata = null;
    for (int startY=0; startY < height; startY++) {
        // Grab one scanline at a time
        odata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                         width, 1, odata);
        setDataElements(dstX, dstY+startY, width, 1, odata);
    }
}
 
Example 18
Source File: ByteComponentRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Stores the Raster data at the specified location.
 * @param dstX The absolute X coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param dstY The absolute Y coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param width      The number of pixels to store horizontally
 * @param height     The number of pixels to store vertically
 * @param inRaster   Raster of data to place at x,y location.
 */
private void setDataElements(int dstX, int dstY,
                             int width, int height,
                             Raster inRaster) {
    // Assume bounds checking has been performed previously
    if (width <= 0 || height <= 0) {
        return;
    }

    int srcOffX = inRaster.getMinX();
    int srcOffY = inRaster.getMinY();
    Object tdata = null;

    if (inRaster instanceof ByteComponentRaster) {
        ByteComponentRaster bct = (ByteComponentRaster) inRaster;
        byte[] bdata = bct.getDataStorage();
        // REMIND: Do something faster!
        if (numDataElements == 1) {
            int toff = bct.getDataOffset(0);
            int tss  = bct.getScanlineStride();

            int srcOffset = toff;
            int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
                                           (dstX-minX);


            if (pixelStride == bct.getPixelStride()) {
                width *= pixelStride;
                for (int tmpY=0; tmpY < height; tmpY++) {
                    System.arraycopy(bdata, srcOffset,
                                     data, dstOffset, width);
                    srcOffset += tss;
                    dstOffset += scanlineStride;
                }
                markDirty();
                return;
            }
        }
    }

    for (int startY=0; startY < height; startY++) {
        // Grab one scanline at a time
        tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                         width, 1, tdata);
        setDataElements(dstX, dstY+startY, width, 1, tdata);
    }
}
 
Example 19
Source File: IntegerInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Stores the Raster data at the specified location.
 * @param dstX The absolute X coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param dstY The absolute Y coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param width      The number of pixels to store horizontally
 * @param height     The number of pixels to store vertically
 * @param inRaster   Raster of data to place at x,y location.
 */
private void setDataElements(int dstX, int dstY,
                             int width, int height,
                             Raster inRaster) {
    // Assume bounds checking has been performed previously
    if (width <= 0 || height <= 0) {
        return;
    }

    // Write inRaster (minX, minY) to (dstX, dstY)

    int srcOffX = inRaster.getMinX();
    int srcOffY = inRaster.getMinY();
    int tdata[] = null;

    if (inRaster instanceof IntegerInterleavedRaster) {
        IntegerInterleavedRaster ict = (IntegerInterleavedRaster) inRaster;

        // Extract the raster parameters
        tdata    = ict.getDataStorage();
        int tss  = ict.getScanlineStride();
        int toff = ict.getDataOffset(0);

        int srcOffset = toff;
        int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
                                       (dstX-minX);


        // Fastest case.  We can copy scanlines
        // Loop through all of the scanlines and copy the data
        for (int startY=0; startY < height; startY++) {
            System.arraycopy(tdata, srcOffset, data, dstOffset, width);
            srcOffset += tss;
            dstOffset += scanlineStride;
        }
        markDirty();
        return;
    }

    Object odata = null;
    for (int startY=0; startY < height; startY++) {
        // Grab one scanline at a time
        odata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                         width, 1, odata);
        setDataElements(dstX, dstY+startY, width, 1, odata);
    }
}
 
Example 20
Source File: IntegerComponentRaster.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Stores the Raster data at the specified location.
 * @param dstX The absolute X coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param dstY The absolute Y coordinate of the destination pixel
 * that will receive a copy of the upper-left pixel of the
 * inRaster
 * @param width      The number of pixels to store horizontally
 * @param height     The number of pixels to store vertically
 * @param inRaster   Raster of data to place at x,y location.
 */
private void setDataElements(int dstX, int dstY,
                             int width, int height,
                             Raster inRaster) {
    // Assume bounds checking has been performed previously
    if (width <= 0 || height <= 0) {
        return;
    }

    // Write inRaster (minX, minY) to (dstX, dstY)

    int srcOffX = inRaster.getMinX();
    int srcOffY = inRaster.getMinY();
    int tdata[] = null;

    if (inRaster instanceof IntegerComponentRaster &&
        (pixelStride == 1) && (numDataElements == 1)) {
        IntegerComponentRaster ict = (IntegerComponentRaster) inRaster;
        if (ict.getNumDataElements() != 1) {
            throw new ArrayIndexOutOfBoundsException("Number of bands"+
                                                     " does not match");
        }

        // Extract the raster parameters
        tdata    = ict.getDataStorage();
        int tss  = ict.getScanlineStride();
        int toff = ict.getDataOffset(0);

        int srcOffset = toff;

        int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
                                       (dstX-minX);


        // Fastest case.  We can copy scanlines
        if (ict.getPixelStride() == pixelStride) {
            width *= pixelStride;

            // Loop through all of the scanlines and copy the data
            for (int startY=0; startY < height; startY++) {
                System.arraycopy(tdata, srcOffset, data, dstOffset, width);
                srcOffset += tss;
                dstOffset += scanlineStride;
            }
            markDirty();
            return;
        }
    }

    Object odata = null;
    for (int startY=0; startY < height; startY++) {
        odata = inRaster.getDataElements(srcOffX, srcOffY+startY,
                                         width, 1, odata);
        setDataElements(dstX, dstY+startY,
                        width, 1, odata);
    }
}