使用 PVRTC 压缩格式创建纹理 Creating textures in the PVRTC compression format

简介: 转自:https://developer.apple.com/library/ios/qa/qa1611/_index.html Technical Q&A QA1611 Creating textures in the PVRTC compression format ...

转自:https://developer.apple.com/library/ios/qa/qa1611/_index.html

Technical Q&A QA1611

Creating textures in the PVRTC compression format

Q:  How do I create textures in the PVRTC compression format?

A: How do I create textures in the PVRTC compression format?

Important: This document has been superseded by the corresponding chapter Using Texturetool to Compress Textures in the OpenGL ES Programming Guide for iPhone. For updates and further information, please refer to that document.

The iPhone SDK includes a tool that allows you to create textures in the PVRTC compression format, aptly named texturetool. If you have Xcode installed with the iPhone OS 2.2 SDK in the default location (/Developer/Platforms/), then texturetool is located at: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool.

texturetool allows you to create four variants of PVRTC data, the primary difference being tradeoffs between quality and size. You will have to experiment with these variants to determine which setting is the best compromise for each individual texture image.

Important: If you are using PVRTexTool, then you must create textures that are square and a power of two in length. The results of using non-square or non-power-of-two PVRTC texture data on iPhone OS are undefined.

The parameters that may be passed to texturetool and their function is presented in the rest of this document.

Note: The encoders, formats and options available with texturetool are subject to change. This document describes those options available as of iPhone OS 2.2. Options not compatible with previous versions of iPhone OS are noted.

Note: The -p option indicates that it requires the -e option. It also requires the -o option.

Listing 1  Encoding Options.

user$ texturetool -l  Encoders:  PVRTC  --channel-weighting-linear  --channel-weighting-perceptual  --bits-per-pixel-2  --bits-per-pixel-4  Formats:  Raw PVR

The texturetool will default to --bits-per-pixel-4--channel-weighting-linear, and -f Raw if no other options are provided.

The --bits-per-pixel-2 and --bits-per-pixel-4 options create PVRTC data that encodes source pixels into 2 or 4 bits per pixel. These options represent a fixed 16:1 and 8:1 compression ratio over the uncompressed 32-bit RGBA image data. There is a minimum data size of 32 bytes; the compressor will never produce files smaller than this, and at least that many bytes are expected when uploading compressed texture data.

When compressing specifying --channel-weighting-linear will spread compression error equally across all channels. By contrast specifying --channel-weighting-perceptual attempts to reduce error in the green channel compared to the linear option. In general, PVRTC compression does better with photographic images than with line art.

The -m option allows you to automatically generate mipmap levels for the source image. This levels are provided as additional image data in the archive created. If you use the Raw image format, then each level of image data will be appended one after another to the archive. If you use the PVR archive format, then each mipmap image will be provided as a separate image in the archive.

Warning: Valid PVRTC data is at least 32 bytes in size. This means that images that are 8x8 or smaller will be padded to 32 bytes total before being written to the archive. For example, compressing a 4x4 image consumes 32 bytes, even though it only requires 8 bytes of storage. If you are using the mipmap option with Raw data files, ensure that you take this into consideration as you are reading them.

With iPhone OS 2.2, the texturetool now additional supports a format (-f) parameter that allows you to control the format of its output file. While this parameter is not available with iPhone OS 2.1 or earlier, the data files produced are compatible with those versions if iPhone OS.

The default format is Raw, which is equivalent to the format that texturetool produced under iPhone SDK 2.0 and 2.1. This format is raw compressed texture data, either for a single texture level (without the -m option) or for each texture level concatenated together (with the -m option). Each texture level stored in the file will be at least 32 bytes in size, and must be uploaded to the GPU in its entirety.

The PVR format is the same format that the PVRTexTool from the Imagination Technologies PowerVR SDK produces, and requires parsing to obtain the actual texture data. See the PVRTextureLoader sample for an example of working with texture data in this format.

Important: Source images for the encoder must satisfy these requirements:

  • Height and Width must be a power of 2.

  • Must be square (height==width).

  • Source images must be in a format that Image IO accepts. This includes PNG, JPG, TIFF and others.

Listing 2  Encoding images into the PVRTC compression format.

Encode Image.png into PVRTC using linear weights and 4 bpp, and saving as ImageL4.pvrtc
user$ texturetool -e PVRTC --channel-weighting-linear --bits-per-pixel-4 -o ImageL4.pvrtc Image.png

Encode Image.png into PVRTC using perceptual weights and 4 bpp, and saving as ImageP4.pvrtc
user$ texturetool -e PVRTC --channel-weighting-perceptual --bits-per-pixel-4 -o ImageP4.pvrtc Image.png

Encode Image.png into PVRTC using linear weights and 2 bpp, and saving as ImageL2.pvrtc
user$ texturetool -e PVRTC --channel-weighting-linear --bits-per-pixel-2 -o ImageL2.pvrtc Image.png

Encode Image.png into PVRTC using perceptual weights and 2 bpp, and saving as ImageP2.pvrtc
user$ texturetool -e PVRTC --channel-weighting-perceptual --bits-per-pixel-2 -o ImageP2.pvrtc Image.png

Listing 3  Encoding images into the PVRTC compression format while creating a preview.

Encode Image.png into PVRTC using linear weights and 4 bpp, and saving the output as ImageL4.pvrtc and a PNG preview as ImageL4.png
user$ texturetool -e PVRTC --channel-weighting-linear --bits-per-pixel-4 -o ImageL4.pvrtc -p ImageL4.png Image.png

Encode Image.png into PVRTC using perceptual weights and 4 bpp, and saving the output as ImageP4.pvrtc and a PNG preview as ImageP4.png
user$ texturetool -e PVRTC --channel-weighting-perceptual --bits-per-pixel-4 -o ImageP4.pvrtc -p ImageP4.png Image.png

Encode Image.png into PVRTC using linear weights and 2 bpp, and saving the output as ImageL2.pvrtc and a PNG preview as ImageL2.png
user$ texturetool -e PVRTC --channel-weighting-linear --bits-per-pixel-2 -o ImageL2.pvrtc -p ImageL2.png Image.png

Encode Image.png into PVRTC using perceptual weights and 2 bpp, and saving the output as ImageP2.pvrtc and a PNG preview as ImageP2.png
user$ texturetool -e PVRTC --channel-weighting-perceptual --bits-per-pixel-2 -o ImageP2.pvrtc -p ImageP2.png Image.png

Note: It is not possible to create a preview without also specifying the -o parameter and a valid output file. Preview images are always in PNG format.

The sample images produced by these settings are shown below.

Table 1  Sample Images.

4bpp, Linear

Original

4bpp, Perceptual

Table 2  Sample Images.

2bpp, Linear

Original

2bpp, Perceptual

Listing 4 demonstrates how you can upload Raw PVRTC data to the GPU via the texImage2DPVRTC sample function. Typically on iPhone OS you would use NSBundle and NSData methods to load data from a file. For a complete example demonstrating how to upload texture data from a PVR formatted data file, see the PVRTextureLoader sample.

Listing 4  Example of uploading PVRTC data to the graphics chip.

void texImage2DPVRTC(GLint level, GLsizei bpp, GLboolean hasAlpha, GLsizei width, GLsizei height, void *pvrtcData)
{
    GLenum format;
    GLsizei size = width * height * bpp / 8;
    if(hasAlpha) {
        format = (bpp == 4) ? GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
    } else {
        format = (bpp == 4) ? GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
    }
    if(size < 32) {
        size = 32;
    }
    glCompressedTexImage2D(GL_TEXTURE_2D, level, format, width, height, 0, size, data);
}

For sample code see the PVRTextureLoader sample.



Document Revision History


Date Notes
2009-07-14

Revised to point to the OpenGL ES Programming Guide. Please refer to that documentation for further updates.

2009-01-27

Clarified non-square texture support (it isn't supported). Linked to the PVRTextureLoader sample.

2008-11-24

Changes for iPhone SDK 2.2, which include the new location for the texturetool and new options for its use.

2008-10-13

New document that describes how to create textures in the PVRTC compression format.





目录
相关文章
|
前端开发 API
图片或文件Blob、File、Base64之间的相互转换
在做前端项目的时候,遇到图片的上传或者下载时,不可避免的会遇到Blob、File、Base64三种类型的转换。那么今天就总结下,三者之间的相互转换。 首先我们看看base64 ,File 对象,Blob 对象长什么样的,怎么来的。
360 1
|
15天前
将图片(路径)转换为Base64 和 将base64转换为file类型
将图片(路径)转换为Base64 和 将base64转换为file类型
|
6月前
|
应用服务中间件 Perl
tomcat上传图片报错com.drew.imaging.jpeg.JpegProcessingException: JPEG data is expected to begin with 0xFFD
tomcat上传图片报错com.drew.imaging.jpeg.JpegProcessingException: JPEG data is expected to begin with 0xFFD
|
5月前
|
算法 Python
路径紧缩(Path Compression
路径紧缩(Path Compression)是用于优化Dijkstra算法的一种算法技巧,目的是减少搜索树中的路径数量,从而提高算法效率。在加权有向图中,路径紧缩可以有效地减少最短路径树的节点数量,使算法更快地找到最短路径。 路径紧缩的基本思想是:当发现一条路径比已有的最短路径更短时,将这条路径与原有路径进行合并,而不是将原有路径替换。这样,在搜索过程中,可以有效地减少树的节点数量,从而提高搜索速度。
36 3
|
7月前
|
存储 API 数据格式
读取HDF或者NetCDF格式的栅格数据
HDF是对HDF数据模型,数据格式以及HDF库API等一系列技术的总称. HDF的最新版本是HDF5. HDF数据模型基于组(groups)和数据集(datasets)概念:如果把HDF数据比作磁盘,那么组相当于文件夹,数据集相当于文件。组和数据集都有用户自定义的属性(attributes). MODIS影像,以及我国的风云卫星数据都适用HDF格式进行存储.
62 0
|
9月前
图片转base64 并根据格式加前缀
图片转base64 并根据格式加前缀
218 0
|
算法 开发者
关于 加载图片"Corrupt JPEG data: premature end of data segment" 的解决方法
关于 加载图片"Corrupt JPEG data: premature end of data segment" 的解决方法
关于 加载图片"Corrupt JPEG data: premature end of data segment" 的解决方法
Google Earth Engine(GEE)——export影像导出错误Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid
Google Earth Engine(GEE)——export影像导出错误Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid
550 0
Google Earth Engine(GEE)——export影像导出错误Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid
|
存储 测试技术 Apache
jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
161 0
jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
|
图形学 异构计算
Unity 之 纹理类型导入设置和压缩格式介绍
你知道纹理导入正确设置和各平台压缩格式吗?本文教你如何将纹理资源导入到Unity并为其设置为对应平台需要使用的压缩格式,一起来看看吧~
807 0
Unity 之 纹理类型导入设置和压缩格式介绍