public static BufferedImage convertImageData(ImageData data) { BufferedImage bimg = null; int height = data.getHeight(), width = data.getWidth(); Object pixels = data.getData(); if (pixels instanceof int[] && data.getElementWidth() == 1) { int[] arr = (int[]) pixels; byte[] barray = new byte[arr.length * 3]; int k = 0; for (int j = 0; j < arr.length; j++) { int l = arr[j]; barray[k++] = (byte) (l & 0xFF); barray[k++] = (byte) ((l >>> 8) & 0xFF); barray[k++] = (byte) ((l >>> 16) & 0xFF); } ColorModel ccm = new ComponentColorModel( ICC_ColorSpace.getInstance(ICC_ColorSpace.CS_sRGB), new int[] {8, 8, 8}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); DataBuffer bbuf = new DataBufferByte(barray, barray.length); SampleModel bmodel = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, width, height, 3, 3 * width, new int[] {2, 1, 0}); WritableRaster raster = Raster.createWritableRaster(bmodel, bbuf, new Point(0, 0)); bimg = new BufferedImage(ccm, raster, false, new Hashtable()); } else if (pixels instanceof byte[] && data.getElementWidth() == 1) { // Assume gray scale model? byte[] arr = (byte[]) pixels; byte[] barray = new byte[arr.length * 3]; int k = 0; for (int j = 0; j < arr.length; j++) { byte l = arr[j]; barray[k++] = l; barray[k++] = l; barray[k++] = l; } ColorModel ccm = new ComponentColorModel( ICC_ColorSpace.getInstance(ICC_ColorSpace.CS_sRGB), new int[] {8, 8, 8}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); DataBuffer bbuf = new DataBufferByte(barray, barray.length); SampleModel bmodel = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, width, height, 3, 3 * width, new int[] {2, 1, 0}); WritableRaster raster = Raster.createWritableRaster(bmodel, bbuf, new Point(0, 0)); bimg = new BufferedImage(ccm, raster, false, new Hashtable()); } else { throw new RuntimeException("Unexpected data."); } return bimg; }
public void updateVertex( final Dimension size, final Insets margin, final Insets border, final Insets padding) { this.m_entity.setVisible(true); this.m_entity3D.setVisible(true); this.m_particleEntity.setVisible(true); final int left = margin.left + border.left + padding.left; final int bottom = margin.bottom + border.bottom + padding.bottom; this.m_entity.getTransformer().setTranslation(0, this.m_x, this.m_y); if (this.m_modulationColor != null) { this.m_entity3D.setColor( this.m_modulationColor.getRed(), this.m_modulationColor.getGreen(), this.m_modulationColor.getBlue(), this.m_modulationColor.getAlpha()); for (int i = 0, isize = this.m_textDataList.size(); i < isize; ++i) { this.m_textDataList .get(i) .getParticle() .setGlobalColor( this.m_modulationColor.getRed() * this.m_modulationColor.getAlpha(), this.m_modulationColor.getGreen() * this.m_modulationColor.getAlpha(), this.m_modulationColor.getBlue() * this.m_modulationColor.getAlpha(), this.m_modulationColor.getAlpha()); } } else { this.m_entity3D.setColor(1.0f, 1.0f, 1.0f, 1.0f); for (int i = 0, isize = this.m_textDataList.size(); i < isize; ++i) { this.m_textDataList.get(i).getParticle().setGlobalColor(1.0f, 1.0f, 1.0f, 1.0f); } } for (int i = 0, listSize = this.m_imageDataList.size(); i < listSize; ++i) { final ImageData imageData = this.m_imageDataList.get(i); final int x = imageData.getX() * this.m_chunkWidth + left; final int y = imageData.getY() * this.m_chunkHeight + bottom + size.height; final GeometrySprite geometry = (GeometrySprite) this.m_entity3D.getGeometry(i); geometry.setTopLeft(y, x); } for (int i = 0, listSize = this.m_textDataList.size(); i < listSize; ++i) { final TextData textData = this.m_textDataList.get(i); final GeometryMesh geom = (GeometryMesh) this.m_entity3D.getGeometry(i + this.m_imageDataList.size()); this.setTextGeometryPosition(geom.getVertexBuffer(), textData); } }
private void addGeometry(final ImageData data) { final GeometrySprite geom = ((MemoryObject.ObjectFactory<GeometrySprite>) GLGeometrySprite.Factory).newPooledInstance(); final Pixmap pixmap = data.getPixmap(); geom.setTextureCoordinates( pixmap.getTop(), pixmap.getLeft(), pixmap.getBottom(), pixmap.getRight()); geom.setSize(pixmap.getWidth(), pixmap.getHeight()); this.m_entity3D.addTexturedGeometry(geom, pixmap.getTexture(), null); geom.removeReference(); }