2 * Copyright 2009 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.opengl;
19 import java.nio.Buffer;
22 * Methods for encoding and decoding ETC1 textures.
24 * The standard for the ETC1 texture format can be found at
25 * http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
27 * The PKM file format is of a 16-byte header that describes the image bounds
28 * followed by the encoded ETC1 texture data.
35 * Size in bytes of an encoded block.
37 public static final int ENCODED_BLOCK_SIZE = 8;
40 * Size in bytes of a decoded block.
42 public static final int DECODED_BLOCK_SIZE = 48;
45 * Size of a PKM file header, in bytes.
47 public static final int ETC_PKM_HEADER_SIZE = 16;
50 * Accepted by the internalformat parameter of glCompressedTexImage2D.
52 public static final int ETC1_RGB8_OES = 0x8D64;
55 * Encode a block of pixels.
57 * @param in a native order direct buffer of size DECODED_BLOCK_SIZE that represent a
58 * 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R
59 * value of pixel (x, y).
61 * @param validPixelMask is a 16-bit mask where bit (1 << (x + y * 4)) indicates whether
62 * the corresponding (x,y) pixel is valid. Invalid pixel color values are ignored when compressing.
64 * @param out a native order direct buffer of size ENCODED_BLOCK_SIZE that receives the
65 * ETC1 compressed version of the data.
68 public static native void encodeBlock(Buffer in, int validPixelMask, Buffer out);
71 * Decode a block of pixels.
73 * @param in a native order direct buffer of size ENCODED_BLOCK_SIZE that contains the
74 * ETC1 compressed version of the data.
76 * @param out a native order direct buffer of size DECODED_BLOCK_SIZE that will receive
77 * the decoded data. The data represents a
78 * 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R
79 * value of pixel (x, y).
81 public static native void decodeBlock(Buffer in, Buffer out);
84 * Return the size of the encoded image data (does not include size of PKM header).
86 public static native int getEncodedDataSize(int width, int height);
89 * Encode an entire image.
90 * @param in a native order direct buffer of the image data. Formatted such that
91 * pixel (x,y) is at pIn + pixelSize * x + stride * y;
92 * @param out a native order direct buffer of the encoded data.
93 * Must be large enough to store entire encoded image.
94 * @param pixelSize must be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image,
95 * 3 is a GL_BYTE RGB image.
97 public static native void encodeImage(Buffer in, int width, int height,
98 int pixelSize, int stride, Buffer out);
101 * Decode an entire image.
102 * @param in native order direct buffer of the encoded data.
103 * @param out native order direct buffer of the image data. Will be written such that
104 * pixel (x,y) is at pIn + pixelSize * x + stride * y. Must be
105 * large enough to store entire image.
106 * @param pixelSize must be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image,
107 * 3 is a GL_BYTE RGB image.
109 public static native void decodeImage(Buffer in, Buffer out,
110 int width, int height, int pixelSize, int stride);
113 * Format a PKM header
114 * @param header native order direct buffer of the header.
115 * @param width the width of the image in pixels.
116 * @param height the height of the image in pixels.
118 public static native void formatHeader(Buffer header, int width, int height);
121 * Check if a PKM header is correctly formatted.
122 * @param header native order direct buffer of the header.
124 public static native boolean isValid(Buffer header);
127 * Read the image width from a PKM header
128 * @param header native order direct buffer of the header.
130 public static native int getWidth(Buffer header);
133 * Read the image height from a PKM header
134 * @param header native order direct buffer of the header.
136 public static native int getHeight(Buffer header);