本文整理汇总了Java中android.opengl.ETC1类的典型用法代码示例。如果您正苦于以下问题:Java ETC1类的具体用法?Java ETC1怎么用?Java ETC1使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ETC1类属于android.opengl包,在下文中一共展示了ETC1类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setResourceIds
import android.opengl.ETC1; //导入依赖的package包/类
public void setResourceIds(int[] resourceIds) {
ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length];
Resources resources = TextureManager.getInstance().getContext().getResources();
int mip_0_width = 1, mip_0_height = 1;
try {
for (int i = 0, length = resourceIds.length; i < length; i++) {
ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(resourceIds[i]));
mipmapChain[i] = texture.getData();
if (i == 0) {
mip_0_width = texture.getWidth();
mip_0_height = texture.getHeight();
}
}
setWidth(mip_0_width);
setHeight(mip_0_height);
setCompressionFormat(ETC1.ETC1_RGB8_OES);
} catch (IOException e) {
RajLog.e(e.getMessage());
e.printStackTrace();
}
mByteBuffers = mipmapChain;
}
示例2: setBitmap
import android.opengl.ETC1; //导入依赖的package包/类
public void setBitmap(Bitmap bitmap) {
mBitmap = bitmap;
int imageSize = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize);
bitmap.copyPixelsToBuffer(uncompressedBuffer);
uncompressedBuffer.position(0);
ByteBuffer compressedBuffer = ByteBuffer.allocateDirect(
ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder());
ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(),
compressedBuffer);
mByteBuffers = new ByteBuffer[]{compressedBuffer};
setWidth(bitmap.getWidth());
setHeight(bitmap.getHeight());
}
示例3: setBitmap
import android.opengl.ETC1; //导入依赖的package包/类
private void setBitmap(Bitmap bitmap) {
mBitmap = bitmap;
int imageSize = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize);
bitmap.copyPixelsToBuffer(uncompressedBuffer);
uncompressedBuffer.position(0);
ByteBuffer compressedBuffer = ByteBuffer.allocateDirect(
ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder());
ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(),
compressedBuffer);
setCompressionFormat(ETC1.ETC1_RGB8_OES);
mByteBuffers = new ByteBuffer[]{compressedBuffer};
setWidth(bitmap.getWidth());
setHeight(bitmap.getHeight());
}
示例4: ETC1Texture
import android.opengl.ETC1; //导入依赖的package包/类
public ETC1Texture(final TextureManager pTextureManager, final TextureOptions pTextureOptions, final ITextureStateListener pTextureStateListener) throws IOException {
super(pTextureManager, PixelFormat.RGB_565, pTextureOptions, pTextureStateListener);
InputStream inputStream = null;
try {
inputStream = this.getInputStream();
this.mETC1TextureHeader = new ETC1TextureHeader(StreamUtils.streamToBytes(inputStream, ETC1.ETC_PKM_HEADER_SIZE));
if (BuildConfig.DEBUG) {
if (!(MathUtils.isPowerOfTwo(this.mETC1TextureHeader.mWidth) && MathUtils.isPowerOfTwo(this.mETC1TextureHeader.mHeight))) {
Debug.w("ETC1 textures with NPOT sizes can cause a crash on PowerVR GPUs!");
}
}
} finally {
StreamUtils.close(inputStream);
}
}
示例5: ETC1TextureHeader
import android.opengl.ETC1; //导入依赖的package包/类
public ETC1TextureHeader(final byte[] pData) {
if (pData.length != ETC1.ETC_PKM_HEADER_SIZE) {
throw new IllegalArgumentException("Invalid " + this.getClass().getSimpleName() + "!");
}
this.mDataByteBuffer = ByteBuffer.allocateDirect(ETC1.ETC_PKM_HEADER_SIZE).order(ByteOrder.nativeOrder());
this.mDataByteBuffer.put(pData, 0, ETC1.ETC_PKM_HEADER_SIZE);
this.mDataByteBuffer.position(0);
if (!ETC1.isValid(this.mDataByteBuffer)) {
throw new IllegalArgumentException("Invalid " + this.getClass().getSimpleName() + "!");
}
this.mWidth = ETC1.getWidth(this.mDataByteBuffer);
this.mHeight = ETC1.getHeight(this.mDataByteBuffer);
}
示例6: ETC1TextureHeader
import android.opengl.ETC1; //导入依赖的package包/类
public ETC1TextureHeader(final byte[] pData) {
if(pData.length != ETC1.ETC_PKM_HEADER_SIZE) {
throw new IllegalArgumentException("Invalid " + this.getClass().getSimpleName() + "!");
}
this.mDataByteBuffer = ByteBuffer.allocateDirect(ETC1.ETC_PKM_HEADER_SIZE).order(ByteOrder.nativeOrder());
this.mDataByteBuffer.put(pData, 0, ETC1.ETC_PKM_HEADER_SIZE);
this.mDataByteBuffer.position(0);
if (!ETC1.isValid(this.mDataByteBuffer)) {
throw new IllegalArgumentException("Invalid " + this.getClass().getSimpleName() + "!");
}
this.mWidth = ETC1.getWidth(this.mDataByteBuffer);
this.mHeight = ETC1.getHeight(this.mDataByteBuffer);
}
示例7: addEtc1Texture
import android.opengl.ETC1; //导入依赖的package包/类
/**
* Add mipmap-chained ETC1 texture.
*/
public TextureInfo addEtc1Texture(int[] resourceIds, TextureType textureType, boolean isExistingTexture, WrapType wrapType, FilterType filterType) {
if (resourceIds == null) return null;
ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length];
int mip_0_width = 1, mip_0_height = 1;
try {
for (int i = 0, length = resourceIds.length; i < length; i++) {
ETC1Util.ETC1Texture texture = ETC1Util.createTexture(mContext.getResources().openRawResource(resourceIds[i]));
mipmapChain[i] = texture.getData();
if (i == 0) {
mip_0_width = texture.getWidth();
mip_0_height = texture.getHeight();
}
}
} catch (IOException e) {
RajLog.e(e.getMessage());
e.printStackTrace();
}
return addTexture(mipmapChain, null, mip_0_width, mip_0_height, textureType, null, true, false, isExistingTexture, wrapType, filterType, CompressionType.ETC1, ETC1.ETC1_RGB8_OES);
}
示例8: testSDKETC1BlockCompressor
import android.opengl.ETC1; //导入依赖的package包/类
public static byte[] testSDKETC1BlockCompressor() {
// Test android class block (reference)
byte[] in1 = { 6, 5, 7, 7, 6, 5, 9, 2, 1, 20, 5, 80, 75, 24, 96, 64,
27, 43, 45, 78, 21, 2, 85, 32, 9, 5, 7, 7, 6, 5, 9, 2, 1, 85,
5, 80, 75, 3, 96, 64, 4, 43, 45, 78, 21, 2, 7, 32 };
ByteBuffer inb = ByteBuffer.allocateDirect(48).order(
ByteOrder.nativeOrder());
inb.put(in1);
ByteBuffer out = ByteBuffer.allocateDirect(8).order(
ByteOrder.nativeOrder());
inb.rewind();
ETC1.encodeBlock(inb, mask, out);
inb.rewind();
byte[] arrayOut1 = new byte[8];
out.get(arrayOut1);
return arrayOut1;
}
示例9: testSDKETC1ImageCompressor
import android.opengl.ETC1; //导入依赖的package包/类
public static ETC1Texture testSDKETC1ImageCompressor() {
// RGB_565 is 2 bytes per pixel
ETC1.encodeImage(buffer, bitmap.getWidth(), bitmap.getHeight(), 2,
2 * bitmap.getWidth(), compressedImage);
ETC1Texture texture = new ETC1Texture(bitmap.getWidth(),
bitmap.getHeight(), compressedImage);
buffer.rewind();
// if (texture != null) {
// int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE
// + texture.getHeight() * texture.getWidth() / 2;
// File f = new
// File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm");
// f.delete();
// f.createNewFile();
// ETC1Util.writeTexture(texture, new FileOutputStream(f));
// System.out.println("Texture PKM created ");
// }
// System.out.println("Texture PKM creation failed ");
return texture;
}
示例10: writeTexture
import android.opengl.ETC1; //导入依赖的package包/类
/**
* Helper function that writes an ETC1Texture to an output stream formatted as a PKM file.
* @param texture the input texture.
* @param output the stream to write the formatted texture data to.
* @throws IOException
*/
public static void writeTexture(ETC1Texture texture, OutputStream output) throws IOException {
ByteBuffer dataBuffer = texture.getData();
dataBuffer.rewind();
System.out.println(dataBuffer.remaining());
int originalPosition = dataBuffer.position();
try {
int width = texture.getWidth();
int height = texture.getHeight();
ByteBuffer header = ByteBuffer.allocateDirect(ETC1.ETC_PKM_HEADER_SIZE).order(ByteOrder.nativeOrder());
ETC1.formatHeader(header, width, height);
header.position(0);
byte[] ioBuffer = new byte[4096];
header.get(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE);
output.write(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE);
while (dataBuffer.remaining()>0) {
int chunkSize = Math.min(ioBuffer.length, dataBuffer.remaining());
dataBuffer.get(ioBuffer, 0, chunkSize);
output.write(ioBuffer, 0, chunkSize);
}
} finally {
dataBuffer.position(originalPosition);
}
}
示例11: setResourceIds
import android.opengl.ETC1; //导入依赖的package包/类
public void setResourceIds(int[] resourceIds)
{
ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length];
Resources resources = TextureManager.getInstance().getContext().getResources();
int mip_0_width = 1, mip_0_height = 1;
try {
for (int i = 0, length = resourceIds.length; i < length; i++) {
ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(resourceIds[i]));
mipmapChain[i] = texture.getData();
if (i == 0) {
mip_0_width = texture.getWidth();
mip_0_height = texture.getHeight();
}
}
setWidth(mip_0_width);
setHeight(mip_0_height);
setCompressionFormat(ETC1.ETC1_RGB8_OES);
} catch (IOException e) {
RajLog.e(e.getMessage());
e.printStackTrace();
}
mByteBuffers = mipmapChain;
}
示例12: setBitmap
import android.opengl.ETC1; //导入依赖的package包/类
public void setBitmap(Bitmap bitmap)
{
mBitmap = bitmap;
int imageSize = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize);
bitmap.copyPixelsToBuffer(uncompressedBuffer);
uncompressedBuffer.position(0);
ByteBuffer compressedBuffer = ByteBuffer.allocateDirect(
ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder());
ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(),
compressedBuffer);
mByteBuffers = new ByteBuffer[] { compressedBuffer };
setWidth(bitmap.getWidth());
setHeight(bitmap.getHeight());
}
示例13: addEtc1Texture
import android.opengl.ETC1; //导入依赖的package包/类
/**
* Add mipmap-chained ETC1 texture.
* @param context
* @param resourceIds
* @return
*/
public TextureInfo addEtc1Texture(int[] resourceIds, TextureType textureType, boolean isExistingTexture, WrapType wrapType, FilterType filterType) {
if (resourceIds == null) return null;
ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length];
int mip_0_width = 1, mip_0_height = 1;
try {
for (int i = 0, length = resourceIds.length; i < length; i++) {
ETC1Util.ETC1Texture texture = ETC1Util.createTexture(mContext.getResources().openRawResource(resourceIds[i]));
mipmapChain[i] = texture.getData();
if (i == 0) {
mip_0_width = texture.getWidth();
mip_0_height = texture.getHeight();
}
}
} catch (IOException e) {
RajLog.e(e.getMessage());
e.printStackTrace();
}
return addTexture(mipmapChain, null, mip_0_width, mip_0_height, textureType, null, true, false, isExistingTexture, wrapType, filterType, CompressionType.ETC1, ETC1.ETC1_RGB8_OES);
}
示例14: createTexture
import android.opengl.ETC1; //导入依赖的package包/类
/**
* Create a new ETC2Texture from an input stream containing a PKM formatted compressed texture.
*
* @param input an input stream containing a PKM formatted compressed texture.
*
* @return an ETC2Texture read from the input stream.
* @throws IOException
*/
public static ETC2Texture createTexture(InputStream input) throws IOException {
int width = 0;
int height = 0;
int format = -1;
byte[] ioBuffer = new byte[4096];
// We can use the ETC1 header size as it is the same
if (input.read(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE) != ETC1.ETC_PKM_HEADER_SIZE) {
throw new IOException("Unable to read PKM file header.");
}
final ByteBuffer headerBuffer = ByteBuffer.allocateDirect(ETC1.ETC_PKM_HEADER_SIZE)
.order(ByteOrder.BIG_ENDIAN);
headerBuffer.put(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE).position(0);
if (!ETC2.isValid(headerBuffer)) {
throw new IOException("Not a PKM file.");
}
width = ETC2.getWidth(headerBuffer);
height = ETC2.getHeight(headerBuffer);
format = ETC2.getETC2CompressionType(headerBuffer);
final int encodedSize = ETC2.getEncodedDataSize(width, height);
final ByteBuffer dataBuffer = ByteBuffer.allocateDirect(encodedSize).order(ByteOrder.BIG_ENDIAN);
for (int i = 0; i < encodedSize; ) {
int chunkSize = Math.min(ioBuffer.length, encodedSize - i);
if (input.read(ioBuffer, 0, chunkSize) != chunkSize) {
throw new IOException("Unable to read PKM file data.");
}
dataBuffer.put(ioBuffer, 0, chunkSize);
i += chunkSize;
}
dataBuffer.position(0);
return new ETC2Texture(format, width, height, dataBuffer);
}
示例15: setResourceId
import android.opengl.ETC1; //导入依赖的package包/类
public void setResourceId(int resourceId) {
mResourceId = resourceId;
Resources resources = TextureManager.getInstance().getContext().getResources();
try {
ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(resourceId));
mByteBuffers = new ByteBuffer[]{texture.getData()};
setWidth(texture.getWidth());
setHeight(texture.getHeight());
setCompressionFormat(ETC1.ETC1_RGB8_OES);
} catch (IOException e) {
RajLog.e(e.getMessage());
e.printStackTrace();
}
}