/* Copyright (C) 2012 Brian P. Hinz
+ * Copyright (C) 2012 D. R. Commander. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
public void setPF(PixelFormat pf) {
super.setPF(pf);
- if (source != null)
- source.newPixels(data, cm, 0, width_);
}
public void updateColourMap() {
cm = new IndexColorModel(8, nColours, reds, greens, blues);
- if (source != null)
- source.newPixels(data, cm, 0, width_);
}
// resize() resizes the image, preserving the image data where possible.
image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
image.setAccelerationPriority(1);
image.createGraphics();
- data = new int[width() * height()];
- source = new MemoryImageSource(w, h, cm, data, 0, w);
- source.setAnimated(true);
- source.setFullBufferUpdates(false);
- source.newPixels(data, cm, 0, width_);
- sourceImage = tk.createImage(source);
+ WritableRaster wr = image.getRaster();
+ SinglePixelPackedSampleModel sm =
+ (SinglePixelPackedSampleModel)image.getSampleModel();
+ DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+ data = db.getData();
}
public void fillRect(int x, int y, int w, int h, int pix) {
} else {
for (int j = 0; j < h; j++)
System.arraycopy(pix, (w*j), data, width_ * (y + j) + x, w);
- source.newPixels(x, y, w, h, true);
- Graphics2D graphics = (Graphics2D)image.getGraphics();
- graphics.setClip(x, y, w, h);
- graphics.drawImage(sourceImage, 0, 0, null);
- graphics.setClip(0, 0, width(), height());
- graphics.dispose();
}
}
}
BufferedImage image;
- MemoryImageSource source;
- int[] data;
- Image sourceImage;
Rectangle clip;
static LogWriter vlog = new LogWriter("BIPixelBuffer");