@Override public void renderPadPixel( final ImageMask imageMask, final DataBuffer data, final int pixelIndex) { if (imageMask.isPadPixel(data.getElem(pixelIndex))) { data.setElem(pixelIndex, 0x00000000); } }
/** * Sets all samples for a rectangle of pixels from an int array containing one sample per array * element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. * * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate of the upper left pixel location. * @param w The width of the pixel rectangle. * @param h The height of the pixel rectangle. * @param iArray The input samples in an int array. * @param data The DataBuffer containing the image data. * @see #getPixels(int, int, int, int, int[], DataBuffer) */ public void setPixels(int x, int y, int w, int h, int iArray[], DataBuffer data) { int x1 = x + w; int y1 = y + h; if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width || y < 0 || y >= height || h > height || y1 < 0 || y1 > height) { throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!"); } int lineOffset = y * scanlineStride + x; int srcOffset = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int value = data.getElem(lineOffset + j); for (int k = 0; k < numBands; k++) { value &= ~bitMasks[k]; int srcValue = iArray[srcOffset++]; value |= ((srcValue << bitOffsets[k]) & bitMasks[k]); } data.setElem(lineOffset + j, value); } lineOffset += scanlineStride; } }
/** * Sets the sample value for a band for the pixel at (x, y) in the specified data buffer. * * @param x the x-coordinate of the pixel. * @param y the y-coordinate of the pixel. * @param b the band (in the range <code>0</code> to <code>getNumBands() - 1</code>). * @param s the sample value. * @param data the data buffer (<code>null</code> not permitted). * @throws NullPointerException if <code>data</code> is <code>null</code>. */ public void setSample(int x, int y, int b, int s, DataBuffer data) { int offset = scanlineStride * y + x; int samples = data.getElem(offset); int bitMask = bitMasks[b]; samples &= ~bitMask; samples |= (s << bitOffsets[b]) & bitMask; data.setElem(offset, samples); }
public Object getDataElements(int[] components, int offset, Object obj) { DataBuffer buffer = Buffers.createBuffer(transferType, obj, getNumComponents()); int numComponents = getNumComponents(); for (int i = 0; i < numComponents; i++) buffer.setElem(i, components[offset++]); return Buffers.getData(buffer); }
/** * Sets the samples for the pixel at (x, y) in the specified data buffer to the specified values. * * @param x the x-coordinate of the pixel. * @param y the y-coordinate of the pixel. * @param iArray the sample values (<code>null</code> not permitted). * @param data the data buffer (<code>null</code> not permitted). * @throws NullPointerException if either <code>iArray</code> or <code>data</code> is <code>null * </code>. */ public void setPixel(int x, int y, int[] iArray, DataBuffer data) { int offset = scanlineStride * y + x; int samples = 0; for (int b = 0; b < numBands; b++) samples |= (iArray[b] << bitOffsets[b]) & bitMasks[b]; data.setElem(offset, samples); }
/** * Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using an * int for input. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in * bounds. * * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param b The band to set. * @param s The input sample as an int. * @param data The DataBuffer containing the image data. * @see #getSample(int, int, int, DataBuffer) */ public void setSample(int x, int y, int b, int s, DataBuffer data) { // Bounds check for 'b' will be performed automatically if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!"); } int value = data.getElem(y * scanlineStride + x); value &= ~bitMasks[b]; value |= (s << bitOffsets[b]) & bitMasks[b]; data.setElem(y * scanlineStride + x, value); }
/** * Sets a pixel in the DataBuffer using an int array of samples for input. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. * * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param iArray The input samples in an int array. * @param data The DataBuffer containing the image data. * @see #getPixel(int, int, int[], DataBuffer) */ public void setPixel(int x, int y, int iArray[], DataBuffer data) { if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!"); } int lineOffset = y * scanlineStride + x; int value = data.getElem(lineOffset); for (int i = 0; i < numBands; i++) { value &= ~bitMasks[i]; value |= ((iArray[i] << bitOffsets[i]) & bitMasks[i]); } data.setElem(lineOffset, value); }
public final void parseData(int data[][][], BufferedImage bi, ImageContents imageContents) { DataBuffer buffer = bi.getRaster().getDataBuffer(); PSDHeaderInfo header = imageContents.header; int width = header.Columns; int height = header.Rows; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { int rgb = getRGB(data, x, y, imageContents); buffer.setElem(y * width + x, rgb); } }
@Override public void renderPixelBand( final DataBuffer data, final int pixelIndex, final ImageInputStream imageInputStream, final int bandIndex) throws IOException { data.setElem( pixelIndex, ALPHA_MASK | data.getElem(pixelIndex) | (imageInputStream.read() << bandMapping.get(bandIndex))); }
/** * This method implements a more efficient way to set pixels than the default implementation of * the super class. It copies the pixel components directly from the input array instead of * creating a intermediate buffer. * * @param x The x-coordinate of the pixel rectangle in <code>obj</code>. * @param y The y-coordinate of the pixel rectangle in <code>obj</code>. * @param w The width of the pixel rectangle in <code>obj</code>. * @param h The height of the pixel rectangle in <code>obj</code>. * @param iArray The primitive array containing the pixels to set. * @param data The DataBuffer to store the pixels into. * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[], java.awt.image.DataBuffer) */ public void setPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data) { int inOffset = 0; for (int yy = y; yy < (y + h); yy++) { int offset = scanlineStride * yy + x; for (int xx = x; xx < (x + w); xx++) { int samples = 0; for (int b = 0; b < numBands; b++) samples |= (iArray[inOffset + b] << bitOffsets[b]) & bitMasks[b]; data.setElem(0, offset, samples); inOffset += numBands; offset += 1; } } }
public void setDataElements(int x, int y, Object obj, DataBuffer data) { int transferType = getTransferType(); switch (transferType) { case DataBuffer.TYPE_BYTE: { byte[] in = (byte[]) obj; data.setElem(y * scanlineStride + x, ((int) in[0]) & 0xff); } break; case DataBuffer.TYPE_USHORT: { short[] in = (short[]) obj; data.setElem(y * scanlineStride + x, ((int) in[0]) & 0xffff); } break; case DataBuffer.TYPE_INT: { int[] in = (int[]) obj; data.setElem(y * scanlineStride + x, in[0]); break; } } }
/** * Sets the data for a single pixel in the specified DataBuffer from a primitive array of type * TransferType. For a SinglePixelPackedSampleModel, only the first element of the array will hold * valid data, and the type of the array must be the same as the storage data type of the * SinglePixelPackedSampleModel. * * <p>The following code illustrates transferring data for one pixel from DataBuffer <code>db1 * </code>, whose storage layout is described by SinglePixelPackedSampleModel <code>sppsm1</code>, * to DataBuffer <code>db2</code>, whose storage layout is described by * SinglePixelPackedSampleModel <code>sppsm2</code>. The transfer will generally be more efficient * than using getPixel/setPixel. * * <pre> * SinglePixelPackedSampleModel sppsm1, sppsm2; * DataBufferInt db1, db2; * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, * db1), db2); * </pre> * * Using getDataElements/setDataElements to transfer between two DataBuffer/SampleModel pairs is * legitimate if the SampleModels have the same number of bands, corresponding bands have the same * number of bits per sample, and the TransferTypes are the same. * * <p>obj must be a primitive array of type TransferType. Otherwise, a ClassCastException is * thrown. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds, * or if obj is not large enough to hold the pixel data. * * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param obj A primitive array containing pixel data. * @param data The DataBuffer containing the image data. * @see #getDataElements(int, int, Object, DataBuffer) */ public void setDataElements(int x, int y, Object obj, DataBuffer data) { if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!"); } int type = getTransferType(); switch (type) { case DataBuffer.TYPE_BYTE: byte[] barray = (byte[]) obj; data.setElem(y * scanlineStride + x, ((int) barray[0]) & 0xff); break; case DataBuffer.TYPE_USHORT: short[] sarray = (short[]) obj; data.setElem(y * scanlineStride + x, ((int) sarray[0]) & 0xffff); break; case DataBuffer.TYPE_INT: int[] iarray = (int[]) obj; data.setElem(y * scanlineStride + x, iarray[0]); break; } }
/** * Sets the samples in the specified band for the specified rectangle of pixels from an int array * containing one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the * coordinates are not in bounds. * * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate of the upper left pixel location. * @param w The width of the pixel rectangle. * @param h The height of the pixel rectangle. * @param b The band to set. * @param iArray The input samples in an int array. * @param data The DataBuffer containing the image data. * @see #getSamples(int, int, int, int, int, int[], DataBuffer) */ public void setSamples(int x, int y, int w, int h, int b, int iArray[], DataBuffer data) { // Bounds check for 'b' will be performed automatically if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!"); } int lineOffset = y * scanlineStride + x; int srcOffset = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int value = data.getElem(lineOffset + j); value &= ~bitMasks[b]; int sample = iArray[srcOffset++]; value |= ((int) sample << bitOffsets[b]) & bitMasks[b]; data.setElem(lineOffset + j, value); } lineOffset += scanlineStride; } }
/** Sets player color to that of the plasma being shot and then draws it {@inheritdoc} */ public void draw(java.awt.image.DataBuffer buffer) { int color; if (luminence == -1) { color = (int) (Math.random() * 256 * 256 * 256); } else { int maxEnergy = Math.max(redEnergy, Math.max(greenEnergy, blueEnergy)); color = this.redEnergy * 255 / maxEnergy * luminence / maxLuminence * 256 * 256 + this.greenEnergy * 255 / maxEnergy * luminence / maxLuminence * 256 + this.blueEnergy * 255 / maxEnergy * luminence / maxLuminence; } for (int j = 0; j < 10; j++) { for (int i = 0; i < 10; i++) { int x = (int) (i + this.xLoc - 5f); int y = (int) (j + this.yLoc - 5f); if (!(x < 0 || x > 799 || y < 0 || y > 799)) { buffer.setElem(800 * y + x, color); } } } for (Projectile p : this.projectiles) { p.draw(buffer); } }
/** * Sets the requested data array element in the specified bank from the given double. The * implementation in this class is to cast val to an int and call {@link #setElem(int, int)}. * Subclasses can override this method if another implementation is needed. * * @param bank the specified bank * @param i the specified index * @param val the value to set the element in the specified bank at the specified index of the * data array * @see #getElemDouble(int) * @see #getElemDouble(int, int) */ public void setElemDouble(int bank, int i, double val) { setElem(bank, i, (int) val); }
/** * Sets the requested data array element in the first (default) bank from the given double. The * implementation in this class is to cast val to an int and call {@link #setElem(int, int)}. * Subclasses can override this method if another implementation is needed. * * @param i the specified index * @param val the value to set the element at the specified index in the data array * @see #getElemDouble(int) * @see #getElemDouble(int, int) */ public void setElemDouble(int i, double val) { setElem(i, (int) val); }
/** * Sets the requested data array element in the specified bank from the given float. The * implementation in this class is to cast val to an int and call {@link #setElem(int, int)}. * Subclasses can override this method if another implementation is needed. * * @param bank the specified bank * @param i the specified index * @param val the value to set the element in the specified bank at the specified index in the * data array * @see #getElemFloat(int) * @see #getElemFloat(int, int) */ public void setElemFloat(int bank, int i, float val) { setElem(bank, i, (int) val); }
/** * Sets the requested data array element in the first (default) bank from the given float. The * implementation in this class is to cast val to an int and call {@link #setElem(int, int)}. * Subclasses can override this method if another implementation is needed. * * @param i the specified index * @param val the value to set the element at the specified index in the data array * @see #getElemFloat(int) * @see #getElemFloat(int, int) */ public void setElemFloat(int i, float val) { setElem(i, (int) val); }
/** * Sets the requested data array element in the first (default) bank from the given integer. * * @param i the specified index into the data array * @param val the data to set the element at the specified index in the data array * @see #getElem(int) * @see #getElem(int, int) */ public void setElem(int i, int val) { setElem(0, i, val); }
public void runTest(Object context, int numReps) { DataBuffer db = ((Context) context).db; do { db.setElem(numReps & 7, 0); } while (--numReps > 0); }