public int[] getPixel(final int x, final int y, int[] c) { if (this.frame == null) return this.grid.getPixel(x, y, c); int cell = (this.width * y + x) * 3; c[0] = this.frame[cell++] & 0xff; c[1] = this.frame[cell++] & 0xff; c[2] = this.frame[cell++] & 0xff; return c; }
private void generatePremultiplyAlpha(File out){ try { BufferedImage outImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); float[] color = new float[4]; WritableRaster raster = image.getRaster(); WritableRaster outRaster = outImage.getRaster(); for(int x =0, w = image.getWidth(); x< w; ++x) for(int y =0, h = image.getHeight(); y< h; ++y){ raster.getPixel(x, y, color); float alpha = color[3]/255f; for(int i=0;i < 3; ++i) color[i] *= alpha; outRaster.setPixel(x, y, color); } ImageIO.write(outImage, "png", out); } catch (IOException e) { e.printStackTrace(); } }
private void generatePremultiplyAlpha(File out){ try { BufferedImage outImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); float[] color = new float[4]; WritableRaster raster = image.getRaster(); WritableRaster outRaster = outImage.getRaster(); for(int x =0, w = image.getWidth(); x< w; ++x) for(int y =0, h = image.getHeight(); y< h; ++y){ raster.getPixel(x, y, color); float alpha = color[3]/255f; for(int i=0;i < 3; ++i) color[i] *= alpha; outRaster.setPixel(x, y, color); } ImageIO.write(outImage, "png", out); } catch (IOException e) { e.printStackTrace(); } }
/** Hunts for the start or end of a sequence of split pixels. Begins searching at (startX, startY) then follows along the x or * y axis (depending on value of xAxis) for the first non-transparent pixel if startPoint is true, or the first transparent * pixel if startPoint is false. Returns 0 if none found, as 0 is considered an invalid split point being in the outer border * which will be stripped. */ static private int getSplitPoint (WritableRaster raster, String name, int startX, int startY, boolean startPoint, boolean xAxis) { int[] rgba = new int[4]; int next = xAxis ? startX : startY; int end = xAxis ? raster.getWidth() : raster.getHeight(); int breakA = startPoint ? 255 : 0; int x = startX; int y = startY; while (next != end) { if (xAxis) x = next; else y = next; raster.getPixel(x, y, rgba); if (rgba[3] == breakA) return next; if (!startPoint && (rgba[0] != 0 || rgba[1] != 0 || rgba[2] != 0 || rgba[3] != 255)) splitError(x, y, rgba, name); next++; } return 0; }
/** Hunts for the start or end of a sequence of split pixels. Begins searching at (startX, startY) then follows along the x or * y axis (depending on value of xAxis) for the first non-transparent pixel if startPoint is true, or the first transparent * pixel if startPoint is false. Returns 0 if none found, as 0 is considered an invalid split point being in the outer border * which will be stripped. */ static private int getSplitPoint (WritableRaster raster, String name, int startX, int startY, boolean startPoint, boolean xAxis) { int[] rgba = new int[4]; int next = xAxis ? startX : startY; int end = xAxis ? raster.getWidth() : raster.getHeight(); int breakA = startPoint ? 255 : 0; int x = startX; int y = startY; while (next != end) { if (xAxis) x = next; else y = next; raster.getPixel(x, y, rgba); if (rgba[3] == breakA) return next; if (!startPoint && (rgba[0] != 0 || rgba[1] != 0 || rgba[2] != 0 || rgba[3] != 255)) splitError(x, y, rgba, name); next++; } return 0; }
for ( int y = 0; y < data.height; y++ ) { for ( int x = 0; x < data.width; x++ ) { raster.getPixel( x, y, pixelArray ); int pixel = palette.getPixel( new RGB( pixelArray[0], pixelArray[1], pixelArray[2] ) ); data.setPixel( x, y, pixel ); for ( int y = 0; y < data.height; y++ ) { for ( int x = 0; x < data.width; x++ ) { raster.getPixel( x, y, pixelArray ); data.setPixel( x, y, pixelArray[0] );
public boolean get(int x, int y) { raster.getPixel(x, y, pixel); return pixel[0] > 0; }
private int getIntensity(int x, int y, WritableRaster grey) { grey.getPixel(x, y, tmpIntensity); return tmpIntensity[0]; }
private int getIntensity(int x, int y, WritableRaster grey) { grey.getPixel(x, y, tmpIntensity); return tmpIntensity[0]; }
private int getIntensity(int x, int y, WritableRaster grey) { grey.getPixel(x, y, tmpIntensity); return tmpIntensity[0]; }
private int getIntensity(int x, int y, WritableRaster grey) { grey.getPixel(x, y, tmpIntensity); return tmpIntensity[0]; }
private int getIntensity(int x, int y, WritableRaster grey) { grey.getPixel(x, y, tmpIntensity); return tmpIntensity[0]; }
private int getIntensity(int x, int y, WritableRaster grey) { grey.getPixel(x, y, tmpIntensity); return tmpIntensity[0]; }
protected int[][][] getYUVImage(WritableRaster raster, int newWidth, int newHeight, int shift) { //TODO: rgb2yuv Conversion int[][][] yuvImage = new int[newWidth][newHeight][3]; int[] rgbPixel = new int[3]; for (int j = 0; j < newHeight; j++) { for (int i = 0; i < newWidth; i++) { raster.getPixel(i, j, rgbPixel); int r = rgbPixel[0]; int g = rgbPixel[1]; int b = rgbPixel[2]; // order: Y, U, V yuvImage[i][j][0] = (int) (0.299 * r + 0.587 * g + 0.114 * b) + shift; yuvImage[i][j][1] = (int) (128 - 0.1687 * r - 0.3313 * g + 0.5 * b) + shift; yuvImage[i][j][2] = (int) (128 + 0.5 * r - 0.4187 * g - 0.0813 * b) + shift; } } return yuvImage; }
private void getNeighbourhood(int x, int y, int[][] values, WritableRaster raster) { int k = 0; for (Iterator<Integer> integerIterator = randomNeighbourhood.iterator(); integerIterator.hasNext(); ) { int n = integerIterator.next(); raster.getPixel(x + possibleNeighbours[n][0], y + possibleNeighbours[n][1], values[k]); // convert to HSV: ColorConversion.rgb2hsv(values[k][0], values[k][1], values[k][2], values[k]); k++; } }
private void getNeighbourhood(int x, int y, int[][] values, WritableRaster raster) { int k = 0; for (Iterator<Integer> integerIterator = randomNeighbourhood.iterator(); integerIterator.hasNext(); ) { int n = integerIterator.next(); raster.getPixel(x + possibleNeighbours[n][0], y + possibleNeighbours[n][1], values[k]); // convert to HSV: ColorConversion.rgb2hsv(values[k][0], values[k][1], values[k][2], values[k]); k++; } }