public void setPixel(final int x, final int y, int[] c) { if (this.frame == null) { this.grid.setPixel(x, y, c); return; } int cell = (this.width * y + x) * 3; this.frame[cell++] = (byte) c[0]; this.frame[cell++] = (byte) c[1]; this.frame[cell++] = (byte) c[2]; }
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(); } }
public BufferedImage getDebugImageUBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int u; u = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.U, ((x/2)%8)/4, ((y/2)%8)/4).getDest()[(x/2)%4][(y/2)%4]; c[0] = u; c[1] = u; c[2] = u; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageVPredBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int v; v = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.V, ((x/2)%8)/4, ((y/2)%8)/4).getPredict()[(x/2)%4][(y/2)%4]; c[0] = v; c[1] = v; c[2] = v; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageYPredBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int yy; yy = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.Y1, (x%16)/4, (y%16)/4).getPredict()[x%4][y%4]; c[0] = yy; c[1] = yy; c[2] = yy; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageVBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int v; v = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.V, ((x/2)%8)/4, ((y/2)%8)/4).getDest()[(x/2)%4][(y/2)%4]; c[0] = v; c[1] = v; c[2] = v; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageYBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int yy; yy = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.Y1, (x%16)/4, (y%16)/4).getDest()[x%4][y%4]; c[0] = yy; c[1] = yy; c[2] = yy; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageVDiffBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int v; v = 127+this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.V, ((x/2)%8)/4, ((y/2)%8)/4).getDiff()[(x/2)%4][(y/2)%4]; c[0] = v; c[1] = v; c[2] = v; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; } public BufferedImage getDebugImageVPredBuffer() {
public BufferedImage getDebugImageYDiffBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int yy; yy = 127+this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.Y1, (x%16)/4, (y%16)/4).getDiff()[x%4][y%4]; c[0] = yy; c[1] = yy; c[2] = yy; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageUDiffBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int u; u = 127+this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.U, ((x/2)%8)/4, ((y/2)%8)/4).getDiff()[(x/2)%4][(y/2)%4]; c[0] = u; c[1] = u; c[2] = u; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImageUPredBuffer() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int u; u = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.U, ((x/2)%8)/4, ((y/2)%8)/4).getPredict()[(x/2)%4][(y/2)%4]; c[0] = u; c[1] = u; c[2] = u; for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
/** * Distinguishes between weak and strong edge points based on the thresholds given. * @param x * @param y * @param gray * @param v */ private void setPixel(int x, int y, BufferedImage gray, double v) { if (v > thresholdLow) gray.getRaster().setPixel(x, y, tmp000); else if (v > thresholdHigh) gray.getRaster().setPixel(x, y, tmp128); else gray.getRaster().setPixel(x, y, tmp255); }
/** * Distinguishes between weak and strong edge points based on the thresholds given. * @param x * @param y * @param gray * @param v */ private void setPixel(int x, int y, BufferedImage gray, double v) { if (v > thresholdLow) gray.getRaster().setPixel(x, y, tmp000); else if (v > thresholdHigh) gray.getRaster().setPixel(x, y, tmp128); else gray.getRaster().setPixel(x, y, tmp255); }
public BufferedImage getDebugImageDiff() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int yy, u, v; yy = 127+this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.Y1, (x%16)/4, (y%16)/4).getDiff()[x%4][y%4]; u = 127+this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.U, ((x/2)%8)/4, ((y/2)%8)/4).getDiff()[(x/2)%4][(y/2)%4]; v = 127+this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.V, ((x/2)%8)/4, ((y/2)%8)/4).getDiff()[(x/2)%4][(y/2)%4]; c[0] = (int)( 1.164*(yy-16)+1.596*(v-128) ); c[1] = (int)( 1.164*(yy-16)-0.813*(v-128)-0.391*(u-128) ); c[2] = (int)( 1.164*(yy-16)+2.018*(u-128) ); for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public BufferedImage getDebugImagePredict() { BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster imRas = bi.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int yy, u, v; yy = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.Y1, (x%16)/4, (y%16)/4).getPredict()[x%4][y%4]; u = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.U, ((x/2)%8)/4, ((y/2)%8)/4).getPredict()[(x/2)%4][(y/2)%4]; v = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.V, ((x/2)%8)/4, ((y/2)%8)/4).getPredict()[(x/2)%4][(y/2)%4]; c[0] = (int)( 1.164*(yy-16)+1.596*(v-128) ); c[1] = (int)( 1.164*(yy-16)-0.813*(v-128)-0.391*(u-128) ); c[2] = (int)( 1.164*(yy-16)+2.018*(u-128) ); for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } bufferCount++; return bi; }
public void useBufferedImage(BufferedImage dst) { WritableRaster imRas = dst.getWritableTile(0, 0); for(int x = 0; x< getWidth(); x++) { for(int y = 0; y< getHeight(); y++) { int c[] = new int[3]; int yy, u, v; yy = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.Y1, (x%16)/4, (y%16)/4).getDest()[x%4][y%4]; u = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.U, ((x/2)%8)/4, ((y/2)%8)/4).getDest()[(x/2)%4][(y/2)%4]; v = this.getMacroBlock(x/16, y/16).getSubBlock(SubBlock.PLANE.V, ((x/2)%8)/4, ((y/2)%8)/4).getDest()[(x/2)%4][(y/2)%4]; c[0] = (int)( 1.164*(yy-16)+1.596*(v-128) ); c[1] = (int)( 1.164*(yy-16)-0.813*(v-128)-0.391*(u-128) ); c[2] = (int)( 1.164*(yy-16)+2.018*(u-128) ); for(int z=0; z<3; z++) { if(c[z]<0) c[z]=0; if(c[z]>255) c[z]=255; } imRas.setPixel(x, y, c); } fireRGBProgressUpdate(100.0F*x/getWidth()); } } public void setFrame(ImageInputStream frame) {