public Image makeImage(TestEnvironment env, int w, int h) { BufferedImage img = new BufferedImage(w, h, type); if (unmanaged) { DataBuffer db = img.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt)db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort)db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte)db).getData(); } else { try { img.setAccelerationPriority(0.0f); } catch (Throwable e) {} } } return img; }
/** * Create a data buffer of a particular type. * * @param dataType the desired data type of the buffer. * @param size the size of the data buffer bank * @param numBanks the number of banks the buffer should have */ public static DataBuffer createBuffer(int dataType, int size, int numBanks) { switch (dataType) { case DataBuffer.TYPE_BYTE: return new DataBufferByte(size, numBanks); case DataBuffer.TYPE_SHORT: return new DataBufferShort(size, numBanks); case DataBuffer.TYPE_USHORT: return new DataBufferUShort(size, numBanks); case DataBuffer.TYPE_INT: return new DataBufferInt(size, numBanks); case DataBuffer.TYPE_FLOAT: return new DataBufferFloat(size, numBanks); case DataBuffer.TYPE_DOUBLE: return new DataBufferDouble(size, numBanks); default: throw new UnsupportedOperationException(); } }
/** * Create a data buffer of a particular type. * * @param dataType the desired data type of the buffer * @param data an array containing the data * @param size the size of the data buffer bank */ public static DataBuffer createBufferFromData(int dataType, Object data, int size) { switch (dataType) { case DataBuffer.TYPE_BYTE: return new DataBufferByte((byte[]) data, size); case DataBuffer.TYPE_SHORT: return new DataBufferShort((short[]) data, size); case DataBuffer.TYPE_USHORT: return new DataBufferUShort((short[]) data, size); case DataBuffer.TYPE_INT: return new DataBufferInt((int[]) data, size); case DataBuffer.TYPE_FLOAT: return new DataBufferFloat((float[]) data, size); case DataBuffer.TYPE_DOUBLE: return new DataBufferDouble((double[]) data, size); default: throw new UnsupportedOperationException(); } }
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc, int type) { BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type); Graphics2D g2d = img.createGraphics(); g2d.setColor(RGB); g2d.fillRect(0, 0, SIZE, SIZE); g2d.dispose(); final DataBuffer db = img.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt) db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort) db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte) db).getData(); } else { try { img.setAccelerationPriority(0.0f); } catch (final Throwable ignored) { } } return img; }
private static BufferedImage makeUnmanagedBI(final int type) { final BufferedImage img = new BufferedImage(SIZE, SIZE, type); final DataBuffer db = img.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt) db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort) db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte) db).getData(); } else { try { img.setAccelerationPriority(0.0f); } catch (final Throwable ignored) { } } return img; }
private static BufferedImage getBufferedImage(int sw) { final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bi.createGraphics(); g2d.setColor(Color.RED); g2d.fillRect(0, 0, sw, sw); g2d.dispose(); final DataBuffer db = bi.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt) db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort) db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte) db).getData(); } else { try { bi.setAccelerationPriority(0.0f); } catch (final Throwable ignored) { } } return bi; }
private static BufferedImage makeUnmanagedBI() { final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB); final DataBuffer db = bi.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt) db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort) db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte) db).getData(); } else { try { bi.setAccelerationPriority(0.0f); } catch (final Throwable ignored) { } } return bi; }
private static BufferedImage makeUnmanagedBI(final int type) { final BufferedImage bi = new BufferedImage(511, 255, type); final DataBuffer db = bi.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt) db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort) db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte) db).getData(); } else { try { bi.setAccelerationPriority(0.0f); } catch (final Throwable ignored) { } } return bi; }