/** * Inverts image color. * * @param image input image * @return an inverted-color image */ public static BufferedImage invertImageColor(BufferedImage image) { BufferedImage tmp = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); BufferedImageOp invertOp = new LookupOp(new ShortLookupTable(0, invertTable), null); return invertOp.filter(image, tmp); }
@Override public void paint(Graphics g) { if (g == null) throw new NullPointerException(); for (int x = 0; x < widthInCharacters; x++) { for (int y = 0; y < heightInCharacters; y++) { if (oldBackgroundColors[x][y] == backgroundColors[x][y] && oldForegroundColors[x][y] == foregroundColors[x][y] && oldChars[x][y] == chars[x][y]) continue; Color bg = backgroundColors[x][y]; Color fg = foregroundColors[x][y]; LookupOp op = setColors(bg, fg); BufferedImage img = op.filter(glyphs[chars[x][y]], null); offscreenGraphics.drawImage(img, x * charWidth, y * charHeight, null); oldBackgroundColors[x][y] = backgroundColors[x][y]; oldForegroundColors[x][y] = foregroundColors[x][y]; oldChars[x][y] = chars[x][y]; } } g.drawImage(offscreenBuffer,0,0,this); }
LookupTable lookupTable = lookupOp.getTable(); int nComponents = lookupTable.getNumComponents();
public WritableRaster copyData(WritableRaster wr){ CachableRed src = (CachableRed)getSources().get(0); wr = src.copyData(wr); GraphicsUtil.coerceData(wr, src.getColorModel(), false); WritableRaster srcWR = wr.createWritableTranslatedChild(0,0); operation.filter(srcWR, srcWR); return wr; } }
LookupTable lookupTable = lookupOp.getTable(); int nComponents = lookupTable.getNumComponents();
private void createFilters() { this.grayscaleOp = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); short[] invert = new short[256]; short[] straight = new short[256]; for (int i = 0; i < 256; i++) { invert[i] = (short) (255 - i); straight[i] = (short) i; } this.invertOp = new LookupOp(new ShortLookupTable(0, invert), null); this.invertOp4 = new LookupOp(new ShortLookupTable(0, new short[][]{invert, invert, invert, straight}), null); }
/** * For testing lookup tables */ public static Image toInverseVideo(Image source) { // BufferedImage src = new BufferedImage(source.getWidth(null), source .getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = src.getGraphics(); g.drawImage(source, 0, 0, null); // short[][] lookup = new short[4][256]; for (int c = 0; c < 4; c++) { for (short b = 0; b < 256; b++) { if (c == 3) lookup[c][b] = b; else lookup[c][b] = (short)(255 - b); } } LookupTable table = new ShortLookupTable(0, lookup); LookupOp op = new LookupOp (table, null); return op.filter(src, null); }
public WritableRaster copyData(WritableRaster wr){ CachableRed src = (CachableRed)getSources().get(0); wr = src.copyData(wr); GraphicsUtil.coerceData(wr, src.getColorModel(), false); WritableRaster srcWR = wr.createWritableTranslatedChild(0,0); operation.filter(srcWR, srcWR); return wr; } }
Color from = Color.decode("#ff00ff"); Color to = new Color(0, true); BufferedImageOp lookup = new LookupOp(new ColorMapper(from, to), null); BufferedImage convertedImage = lookup.filter(image, null);
public WritableRaster copyData(WritableRaster wr){ CachableRed src = (CachableRed)getSources().get(0); wr = src.copyData(wr); GraphicsUtil.coerceData(wr, src.getColorModel(), false); WritableRaster srcWR = wr.createWritableTranslatedChild(0,0); operation.filter(srcWR, srcWR); return wr; } }
/** * Inverts image color. * * @param image input image * @return an inverted-color image */ public static BufferedImage invertImageColor(BufferedImage image) { BufferedImage tmp = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); BufferedImageOp invertOp = new LookupOp(new ShortLookupTable(0, invertTable), null); return invertOp.filter(image, tmp); }
}; java.awt.Graphics2D g2 = retVal.createGraphics(); g2.drawImage(srcImage, new java.awt.image.LookupOp(conversion, null), 0, 0); g2.dispose(); g2 = null;
private void createFilters() { this.grayscaleOp = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); short[] invert = new short[256]; short[] straight = new short[256]; for (int i = 0; i < 256; i++) { invert[i] = (short) (255 - i); straight[i] = (short) i; } this.invertOp = new LookupOp(new ShortLookupTable(0, invert), null); this.invertOp4 = new LookupOp(new ShortLookupTable(0, new short[][]{invert, invert, invert, straight}), null); }
return new LookupOp(new ShortLookupTable(0, table), null);
public FilterPanelSeparator(int group) { this.group = group; jPanel = new JPanel(); GroupLayout layout = new GroupLayout(jPanel); jPanel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(false); BufferedImageOp lookup = new LookupOp(new ColorMapper(Color.WHITE, getColor("nimbusBlueGrey", "Separator.foreground")), null); BufferedImage convertedImage = lookup.filter((BufferedImage)Images.MISC_AND.getImage(), null); JLabel jIcon = new JLabel(new ImageIcon(convertedImage)); layout.setHorizontalGroup( layout.createSequentialGroup() .addGap(30) .addComponent(jIcon, 12, 12, 12) ); layout.setVerticalGroup( layout.createSequentialGroup() .addGap(1) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(jIcon, 4, 4, 4) ) .addGap(1) ); }
static void thresholding(BufferedImage bi) { // TODO Optimize short[] threshold = new short[256]; for (short i = 0; i < 36; i++) { threshold[i] = 0; } for (short i = 36; i < 256; i++) { threshold[i] = i; } BufferedImageOp thresholdOp = new LookupOp(new ShortLookupTable(0, threshold), null); thresholdOp.filter(bi, bi); }
BufferedImageOp lookupOp = new LookupOp(lut, null); lookupOp.filter(src, dst);