if (getDataFormat() != that.getDataFormat()) { return false; if (getDataType() != that.getDataType()) { return false; if (getWidth() != that.getWidth()) { return false; if (getHeight() != that.getHeight()) { return false; if (!this.getData().equals(that.getData())) { return false; if (getMipMapByteSizes() != null && !Arrays.equals(getMipMapByteSizes(), that.getMipMapByteSizes())) { return false; if (getMipMapByteSizes() == null && that.getMipMapByteSizes() != null) { return false;
public static Image makeArdor3dImage(final RenderedImage image, final boolean flipImage) { if (image == null) { return null; } final ColorModel colorModel = image.getColorModel(); final boolean hasAlpha = colorModel.hasAlpha(); final boolean grayscale = colorModel.getNumComponents() == 1; // Get a pointer to the image memory final byte data[] = asByteArray(image, grayscale, hasAlpha); final ByteBuffer scratch = createOnHeap ? BufferUtils.createByteBufferOnHeap(data.length) : BufferUtils .createByteBuffer(data.length); scratch.clear(); scratch.put(data); scratch.flip(); final Image ardorImage = new Image(); ardorImage.setDataFormat(grayscale ? ImageDataFormat.Red : hasAlpha ? ImageDataFormat.RGBA : ImageDataFormat.RGB); ardorImage.setDataType(PixelDataType.UnsignedByte); ardorImage.setWidth(image.getWidth()); ardorImage.setHeight(image.getHeight()); ardorImage.setData(scratch); return ardorImage; }
private static Image _RGB888_to_RGBA8888(final Image rgb888) { final int size = rgb888.getWidth() * rgb888.getHeight() * 4; final ByteBuffer rgb = rgb888.getData(0); final ByteBuffer rgba8888 = BufferUtils.createByteBuffer(size); rgb.rewind(); for (int j = 0; j < size; j++) { if ((j + 1) % 4 == 0) { rgba8888.put((byte) 0xFF); } else { rgba8888.put(rgb.get()); } } return new Image(ImageDataFormat.RGBA, PixelDataType.UnsignedByte, rgb888.getWidth(), rgb888.getHeight(), rgba8888, null); }
/** * Instantiates a MouseCursor. * * @param name * the name of this cursor, for debugging purposes. * @param image * the image that will be shown when this cursor is active. * @param hotspotX * the X coordinate of the clicking hotspot, 0 = left side * @param hotspotY * the Y coordinate of the clicking hotspot, 0 = bottom */ public MouseCursor(final String name, final Image image, final int hotspotX, final int hotspotY) { _name = name; _image = image; _hotspotX = hotspotX; _hotspotY = hotspotY; checkArgument(hotspotX >= 0 && hotspotX < image.getWidth(), "hotspot X is out of bounds: 0 <= %s < " + image.getWidth(), hotspotX); checkArgument(hotspotY >= 0 && hotspotY < image.getHeight(), "hotspot Y is out of bounds: 0 <= %s < " + image.getHeight(), hotspotY); }
final int actualWidth = image.getWidth(); final int actualHeight = image.getHeight(); && (!MathUtils.isPowerOfTwo(image.getWidth()) || !MathUtils.isPowerOfTwo(image.getHeight())); if (actualWidth > maxSize || actualHeight > maxSize || needsPowerOfTwo) { if (needsPowerOfTwo) { logger.warning("(card unsupported) Attempted to apply texture with size that is not power of 2: " + image.getWidth() + " x " + image.getHeight()); + maxSize + "]: " + image.getWidth() + " x " + image.getHeight()); final int pixFormat = LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()); final int pixDataType = LwjglTextureUtil.getGLPixelDataType(image.getDataType()); final int bpp = ImageUtils.getPixelByteSize(image.getDataFormat(), image.getDataType()); final ByteBuffer scaledImage = BufferUtils.createByteBuffer((w + 4) * h * bpp); final int error = MipMap.gluScaleImage(pixFormat, actualWidth, actualHeight, pixDataType, image.getData(0), w, h, pixDataType, scaledImage); if (error != 0) { Util.checkGLError(); image.setWidth(w); image.setHeight(h); image.setData(scaledImage); image.getData(0).rewind(); image.getWidth(), image.getHeight(), hasBorder ? 1 : 0, LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()), LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
final int actualWidth = image.getWidth(); final int actualHeight = image.getHeight(); logger.warning( "(card unsupported) Attempted to apply texture with size bigger than max texture size [" + maxSize + "]: " + image.getWidth() + " x " + image.getHeight()); return; image.getData(0).rewind(); image.getWidth(), image.getHeight(), hasBorder ? 1 : 0, Lwjgl3TextureUtils.getGLPixelFormat(image.getDataFormat()), Lwjgl3TextureUtils.getGLPixelDataType(image.getDataType()), image.getData(0)); break; case OneDimensional: image.getData(0).rewind(); image.getWidth(), hasBorder ? 1 : 0, Lwjgl3TextureUtils.getGLPixelFormat(image.getDataFormat()), Lwjgl3TextureUtils.getGLPixelDataType(image.getDataType()), image.getData(0)); break; case ThreeDimensional: int count = 0; ByteBuffer data = null; for (int x = 0; x < image.getData().size(); x++) { if (image.getData(x) != null) { data = image.getData(x);
public void setIcon(final Image[] iconImages) { final ByteBuffer[] iconData = new ByteBuffer[iconImages.length]; for (int i = 0; i < iconData.length; i++) { // Image.Format.RGBA8 is the format that LWJGL requires, so try to convert if it's not. if (iconImages[i].getDataType() != PixelDataType.UnsignedByte) { throw new Ardor3dException( "Your icon is in a format that could not be converted to UnsignedByte - RGBA"); } if (iconImages[i].getDataFormat() != ImageDataFormat.RGBA) { if (iconImages[i].getDataFormat() != ImageDataFormat.RGB) { throw new Ardor3dException( "Your icon is in a format that could not be converted to UnsignedByte - RGBA"); } iconImages[i] = _RGB888_to_RGBA8888(iconImages[i]); } iconData[i] = iconImages[i].getData(0); iconData[i].rewind(); } Display.setIcon(iconData); }
final PixelDataType type = image.getDataType(); final ImageDataFormat dataFormat = image.getDataFormat(); switch (dataFormat) { case BGRA:
image.setDataFormat(ImageDataFormat.PrecompressedDXT1A); logger.finest("DDS format: DXT3"); info.bpp = 8; image.setDataFormat(ImageDataFormat.PrecompressedDXT3); logger.finest("DDS format: DXT5"); info.bpp = 8; image.setDataFormat(ImageDataFormat.PrecompressedDXT5); logger.finest("DXGI format: BC4_UNORM"); info.bpp = 4; image.setDataFormat(ImageDataFormat.PrecompressedLATC_L); break; case DXGI_FORMAT_BC5_UNORM: logger.finest("DXGI format: BC5_UNORM"); info.bpp = 8; image.setDataFormat(ImageDataFormat.PrecompressedLATC_LA); break; default: image.setDataType(PixelDataType.UnsignedByte); if (alphaPixels) { logger.finest("DDS format: uncompressed rgba"); image.setDataFormat(ImageDataFormat.RGBA); } else { logger.finest("DDS format: uncompressed rgb "); image.setDataFormat(ImageDataFormat.RGB);
public int getWidth() { return _image.getWidth(); }
public int getHeight() { return _image.getHeight(); }
public Image load(final InputStream is, final boolean flipVertically) throws IOException { final LittleEndianDataInput in = new LittleEndianDataInput(is); // Read and check magic word... final int dwMagic = in.readInt(); if (dwMagic != getInt("DDS ")) { throw new Error("Not a dds file."); } logger.finest("Reading DDS file."); // Create our data store; final DdsImageInfo info = new DdsImageInfo(); info.flipVertically = flipVertically; // Read standard dds header info.header = DdsHeader.read(in); // if applicable, read DX10 header info.headerDX10 = info.header.ddpf.dwFourCC == getInt("DX10") ? DdsHeaderDX10.read(in) : null; // Create our new image final Image image = new Image(); image.setWidth(info.header.dwWidth); image.setHeight(info.header.dwHeight); // update depth based on flags / header updateDepth(image, info); // add our format and image data. populateImage(image, info, in); // return the loaded image return image; }
/** * Creates a one dimensional color image using each color given as a single pixel. * * @param useAlpha * if true, the image will have an alpha component (whose value will come from each supplied color.) * @param colors * one or more colors * @return a 1D image, width == colors.length */ public static Image create1DColorImage(final boolean useAlpha, final ReadOnlyColorRGBA... colors) { final ByteBuffer data = BufferUtils.createByteBuffer(colors.length * (useAlpha ? 4 : 3)); for (int i = 0; i < colors.length; i++) { final ReadOnlyColorRGBA color = colors[i]; data.put((byte) (color.getRed() * 255)); data.put((byte) (color.getGreen() * 255)); data.put((byte) (color.getBlue() * 255)); if (useAlpha) { data.put((byte) (color.getAlpha() * 255)); } } data.rewind(); final ImageDataFormat fmt = (useAlpha) ? ImageDataFormat.RGBA : ImageDataFormat.RGB; return new Image(fmt, PixelDataType.UnsignedByte, colors.length, 1, data, null); }
/** * Constructor instantiates a new <code>Image</code> object. The attributes of the image are defined during * construction. * * @param format * the data format of the image. Must not be null. * @param type * the data type of the image. Must not be null. * @param width * the width of the image. * @param height * the height of the image. * @param data * the image data. Must not be null. * @param mipMapSizes * the array of mipmap sizes, or null for no mipmaps. */ public Image(final ImageDataFormat format, final PixelDataType type, final int width, final int height, final List<ByteBuffer> data, int[] mipMapSizes) { if (mipMapSizes != null && mipMapSizes.length <= 1) { mipMapSizes = null; } setDataFormat(format); setDataType(type); setData(data); _width = width; _height = height; _depth = data.size(); _mipMapSizes = mipMapSizes; }
static final ByteBuffer readDXT(final LittleEndianDataInput in, final int totalSize, final DdsImageInfo info, final Image image) throws IOException { int mipWidth = info.header.dwWidth; int mipHeight = info.header.dwHeight; final ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); for (int mip = 0; mip < info.header.dwMipMapCount; mip++) { final byte[] data = new byte[info.mipmapByteSizes[mip]]; in.readFully(data); if (!info.flipVertically) { buffer.put(data); } else { final byte[] flipped = flipDXT(data, mipWidth, mipHeight, image.getDataFormat()); buffer.put(flipped); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } } buffer.rewind(); return buffer; }
return; final ImageDataFormat format = parameterObject.getTexture().getImage().getDataFormat(); if (format != ImageDataFormat.RGB && format != ImageDataFormat.RGBA) { TexturePacker.logger.warning( final ByteBuffer lightData = parameterObject.getTexture().getImage().getData(0);
private void buildMips(final Image map) { final int max = heightMapSizes.size(); int currentSize = heightMapSizes.get(max - 1); byte[] parentHeightMap = new byte[currentSize * currentSize * 3]; // populate parentHeightMap from image map.getData(0).get(parentHeightMap); maps.add(parentHeightMap); // populate mips for (int i = 1; i < max; i++) { currentSize = heightMapSizes.get(max - i - 1); final byte[] heightMapMip = new byte[currentSize * currentSize * 3]; for (int x = 0; x < currentSize; x++) { for (int z = 0; z < currentSize; z++) { heightMapMip[3 * (z * currentSize + x) + 0] = parentHeightMap[3 * (z * currentSize * 4 + x * 2) + 0]; heightMapMip[3 * (z * currentSize + x) + 1] = parentHeightMap[3 * (z * currentSize * 4 + x * 2) + 1]; heightMapMip[3 * (z * currentSize + x) + 2] = parentHeightMap[3 * (z * currentSize * 4 + x * 2) + 2]; } } parentHeightMap = heightMapMip; maps.add(parentHeightMap); } Collections.reverse(maps); }
final int actualWidth = image.getWidth(); final int actualHeight = image.getHeight(); && (!MathUtils.isPowerOfTwo(image.getWidth()) || !MathUtils.isPowerOfTwo(image.getHeight())); if (actualWidth > maxSize || actualHeight > maxSize || needsPowerOfTwo) { if (needsPowerOfTwo) { logger.warning("(card unsupported) Attempted to apply texture with size that is not power of 2: " + image.getWidth() + " x " + image.getHeight()); + maxSize + "]: " + image.getWidth() + " x " + image.getHeight()); final int pixFormat = JoglTextureUtil.getGLPixelFormat(image.getDataFormat()); final int pixDataType = JoglTextureUtil.getGLPixelDataType(image.getDataType()); final int bpp = ImageUtils.getPixelByteSize(image.getDataFormat(), image.getDataType()); final ByteBuffer scaledImage = BufferUtils.createByteBuffer((w + 4) * h * bpp); image.getData(0).rewind(); final int error = glu.gluScaleImage(pixFormat, actualWidth, actualHeight, pixDataType, image.getData(0), w, h, pixDataType, scaledImage); if (error != 0) { final int errorCode = gl.glGetError(); image.setWidth(w); image.setHeight(h); image.setData(scaledImage); image.getData(0).rewind(); JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(),
private static Image _RGB888_to_RGBA8888(final Image rgb888) { final int size = rgb888.getWidth() * rgb888.getHeight() * 4; final ByteBuffer rgb = rgb888.getData(0); final ByteBuffer rgba8888 = BufferUtils.createByteBuffer(size); rgb.rewind(); for (int j = 0; j < size; j++) { if ((j + 1) % 4 == 0) { rgba8888.put((byte) 0xFF); } else { rgba8888.put(rgb.get()); } } return new Image(ImageDataFormat.RGBA, PixelDataType.UnsignedByte, rgb888.getWidth(), rgb888.getHeight(), rgba8888, null); }
/** * Instantiates a MouseCursor. * * @param name * the name of this cursor, for debugging purposes. * @param image * the image that will be shown when this cursor is active. * @param hotspotX * the X coordinate of the clicking hotspot, 0 = left side * @param hotspotY * the Y coordinate of the clicking hotspot, 0 = bottom */ public MouseCursor(final String name, final Image image, final int hotspotX, final int hotspotY) { _name = name; _image = image; _hotspotX = hotspotX; _hotspotY = hotspotY; checkArgument(hotspotX >= 0 && hotspotX < image.getWidth(), "hotspot X is out of bounds: 0 <= %s < " + image.getWidth(), hotspotX); checkArgument(hotspotY >= 0 && hotspotY < image.getHeight(), "hotspot Y is out of bounds: 0 <= %s < " + image.getHeight(), hotspotY); }