📄 image.java
字号:
/*
* Copyright (c) 2003-2009 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme.image;
import java.io.IOException;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
/**
* <code>Image</code> defines a data format for a graphical image. The image
* is defined by a format, a height and width, and the image data. The width and
* height must be greater than 0. The data is contained in a byte buffer, and
* should be packed before creation of the image object.
*
* @author Mark Powell
* @author Joshua Slack
* @version $Id: Image.java,v 1.16 2007/03/06 15:07:50 nca Exp $
*/
public class Image implements Serializable, Savable {
private static final long serialVersionUID = 2L;
public enum Format {
/**
* When used in texture loading, this indicates to let jME guess the
* format. jME will use S3TC compression, if available.
*/
Guess,
/**
* When used in texture loading, this indicates to let jME guess the
* format, but not to use S3TC compression, even if available.
*/
GuessNoCompression,
/**
* 4 bit alpha only format - usually forced to 8bit by the card
*/
Alpha4,
/**
* 8 bit alpha only format
*/
Alpha8,
/**
* 12 bit alpha only format - often forced to 8bit or 16bit by the card
*/
Alpha12,
/**
* 16 bit alpha only format - older cards will often use 8bit instead.
*/
Alpha16,
/**
* 4 bit luminance only format - usually forced to 8bit by the card
*/
Luminance4,
/**
* 8 bit luminance only format
*/
Luminance8,
/**
* 12 bit luminance only format - often forced to 8bit or 16bit by the
* card
*/
Luminance12,
/**
* 16 bit luminance only format - older cards will often use 8bit
* instead.
*/
Luminance16,
/**
* 4 bit luminance, 4 bit alpha format
*/
Luminance4Alpha4,
/**
* 6 bit luminance, 2 bit alpha format
*/
Luminance6Alpha2,
/**
* 8 bit luminance, 8 bit alpha format
*/
Luminance8Alpha8,
/**
* 12 bit luminance, 4 bit alpha format
*/
Luminance12Alpha4,
/**
* 12 bit luminance, 12 bit alpha format
*/
Luminance12Alpha12,
/**
* 16 bit luminance, 16 bit alpha format
*/
Luminance16Alpha16,
/**
* 4 bit intensity only format - usually forced to 8bit by the card
*/
Intensity4,
/**
* 8 bit intensity only format
*/
Intensity8,
/**
* 12 bit intensity only format - often forced to 8bit or 16bit by the
* card
*/
Intensity12,
/**
* 16 bit intensity only format - older cards will often use 8bit
* instead.
*/
Intensity16,
/**
* 3 bit red, 3 bit green, 3 bit blue - often forced to 16 bit by the
* card
*/
R3G3B2,
/**
* 4 bits per red, green and blue
*/
RGB4,
/**
* 5 bits per red, green and blue
*/
RGB5,
/**
* 8 bits per red, green and blue
*/
RGB8,
/**
* 10 bits per red, green and blue - usually falls back to 8 bits on the
* card
*/
RGB10,
/**
* 12 bits per red, green and blue - usually falls back to 8 bits on the
* card
*/
RGB12,
/**
* 16 bits per red, green and blue - usually falls back to 8 bits on the
* card
*/
RGB16,
/**
* 2 bits per red, green, blue and alpha - often forced to RGBA4 by the
* card
*/
RGBA2,
/**
* 4 bits per red, green, blue and alpha
*/
RGBA4,
/**
* 5 bits per red, green and blue. 1 bit of alpha
*/
RGB5A1,
/**
* 8 bits per red, green, blue and alpha
*/
RGBA8,
/**
* 10 bits per red, green and blue. 2 bits of alpha - often forced to
* RGBA8 by the card
*/
RGB10A2,
/**
* 12 bits per red, green, blue and alpha - often forced to RGBA8 by the
* card
*/
RGBA12,
/**
* 16 bits per red, green, blue and alpha - often forced to RGBA8 by the
* card
*/
RGBA16,
/**
* 8 bits per red, green and blue. Compressed and stored by the card in
* DXT1 format.
*/
RGB_TO_DXT1,
/**
* 8 bits per red, green, blue and alpha. Compressed and stored by the
* card in DXT1 format.
*/
RGBA_TO_DXT1,
/**
* 8 bits per red, green, blue and alpha. Compressed and stored by the
* card in DXT3 format.
*/
RGBA_TO_DXT3,
/**
* 8 bits per red, green, blue and alpha. Compressed and stored by the
* card in DXT5 format.
*/
RGBA_TO_DXT5,
/**
* Image data already in DXT1 format.
*/
NativeDXT1,
/**
* Image data already in DXT1 (with Alpha) format.
*/
NativeDXT1A,
/**
* Image data already in DXT3 format.
*/
NativeDXT3,
/**
* Image data already in DXT5 format.
*/
NativeDXT5,
/**
* 16 bit depth component format
*/
Depth16,
/**
* 24 bit depth component format
*/
Depth24,
/**
* 32 bit depth component format - often stored in Depth24 format by the
* card.
*/
Depth32,
/**
* 16 bit float per red, green and blue
*/
RGB16F,
/**
* 32 bit float per red, green and blue
*/
RGB32F,
/**
* 16 bit float per red, green, blue and alpha
*/
RGBA16F,
/**
* 32 bit float per red, green, blue and alpha
*/
RGBA32F,
/**
* 16 bit float, alpha only format
*/
Alpha16F,
/**
* 16 bit float, alpha only format
*/
Alpha32F,
/**
* 16 bit float, luminance only format
*/
Luminance16F,
/**
* 32 bit float, luminance only format
*/
Luminance32F,
/**
* 16 bit float per luminance and alpha
*/
LuminanceAlpha16F,
/**
* 32 bit float per luminance and alpha
*/
LuminanceAlpha32F,
/**
* 16 bit float, intensity only format
*/
Intensity16F,
/**
* 32 bit float, intensity only format
*/
Intensity32F;
}
// image attributes
protected Format format;
protected int width, height, depth;
protected int[] mipMapSizes;
protected transient ArrayList<ByteBuffer> data;
/**
* Constructor instantiates a new <code>Image</code> object. All values
* are undefined.
*/
public Image() {
data = new ArrayList<ByteBuffer>(1);
}
/**
* 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.
* @param width
* the width of the image.
* @param height
* the height of the image.
* @param data
* the image data.
* @param mipMapSizes
* the array of mipmap sizes, or null for no mipmaps.
*/
public Image(Format format, int width, int height, int depth, ArrayList<ByteBuffer> data,
int[] mipMapSizes) {
if (mipMapSizes != null && mipMapSizes.length <= 1) {
mipMapSizes = null;
}
setFormat(format);
this.width = width;
this.height = height;
this.data = data;
this.depth = depth;
this.mipMapSizes = mipMapSizes;
}
/**
* 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.
* @param width
* the width of the image.
* @param height
* the height of the image.
* @param data
* the image data.
* @param mipMapSizes
* the array of mipmap sizes, or null for no mipmaps.
*/
public Image(Format format, int width, int height, ByteBuffer data,
int[] mipMapSizes) {
if (mipMapSizes != null && mipMapSizes.length <= 1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -