int rmask = pf.redMax << pf.redShift;
int gmask = pf.greenMax << pf.greenShift;
int bmask = pf.blueMax << pf.blueShift;
- cm = new DirectColorModel(8, rmask, gmask, bmask);
- if (!pf.trueColour)
+ if (pf.trueColour)
+ cm = new DirectColorModel(8, rmask, gmask, bmask);
+ else
cm = new IndexColorModel(8, 256, new byte[256], new byte[256], new byte[256]);
break;
case 16:
public void setPF(PixelFormat pf) {
super.setPF(pf);
+ createImage(width(), height());
}
public void updateColourMap() {
cm = new IndexColorModel(8, nColours, reds, greens, blues);
+ createImage(width_, height_);
}
// resize() resizes the image, preserving the image data where possible.
public void resize(int w, int h) {
- if (w == width() && h == height()) return;
+ if (w == width() && h == height())
+ return;
width_ = w;
height_ = h;
- GraphicsEnvironment ge =
- GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice gd = ge.getDefaultScreenDevice();
- GraphicsConfiguration gc = gd.getDefaultConfiguration();
- image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
- image.setAccelerationPriority(1);
- image.createGraphics();
- WritableRaster wr = image.getRaster();
- SinglePixelPackedSampleModel sm =
- (SinglePixelPackedSampleModel)image.getSampleModel();
- DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
- data = db.getData();
+ createImage(w, h);
+ }
+
+ private void createImage(int w, int h) {
+ if (w == 0 || h == 0) return;
+ WritableRaster wr;
+ if (cm instanceof IndexColorModel)
+ wr = ((IndexColorModel)cm).createCompatibleWritableRaster(w, h);
+ else
+ wr = ((DirectColorModel)cm).createCompatibleWritableRaster(w, h);
+ image = new BufferedImage(cm, wr, true, null);
+ db = wr.getDataBuffer();
}
public void fillRect(int x, int y, int w, int h, int pix) {
clip = null;
img.flush();
} else {
- for (int j = 0; j < h; j++)
- System.arraycopy(pix, (w*j), data, width_ * (y + j) + x, w);
+ if (image.getSampleModel().getTransferType() == DataBuffer.TYPE_BYTE) {
+ byte[] bytes = new byte[((int[])pix).length];
+ for (int i = 0; i < bytes.length; i++)
+ bytes[i] = (byte)((int[])pix)[i];
+ pix = bytes;
+ }
+ image.getSampleModel().setDataElements(x, y, w, h, pix, db);
}
}
}
BufferedImage image;
+ DataBuffer db;
Rectangle clip;
static LogWriter vlog = new LogWriter("BIPixelBuffer");
(newFullColour ? "enabled" : "disabled"));
fullColour = newFullColour;
formatChange = true;
+ forceNonincremental = true;
}
}
if (forceNonincremental || !continuousUpdates) {
pendingUpdate = true;
writer().writeFramebufferUpdateRequest(new Rect(0,0,cp.width,cp.height),
- !formatChange && !forceNonincremental);
+ !forceNonincremental);
}
forceNonincremental = false;
public void getOptions() {
autoSelect = options.autoSelect.isSelected();
- if (fullColour != options.fullColour.isSelected())
+ if (fullColour != options.fullColour.isSelected()) {
formatChange = true;
+ forceNonincremental = true;
+ }
fullColour = options.fullColour.isSelected();
if (!fullColour) {
int newLowColourLevel = (options.veryLowColour.isSelected() ? 0 :
if (newLowColourLevel != lowColourLevel) {
lowColourLevel = newLowColourLevel;
formatChange = true;
+ forceNonincremental = true;
}
}
int newEncoding = (options.zrle.isSelected() ? Encodings.encodingZRLE :