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

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

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

有关该篇官方文档的相关信息,可以看到很久一直保持应用着,下面具体来看一下 PVRTC 是否能解决纹理加载过程中的延迟大的问题,以便能使其它方法处理结果速度有所提升。

针对于跨平台的 OpenGLES 应用,尚不知这种压缩后的纹理是否能正常工作,有待进一步证实。

技术问答
QA1611

Technical Q&A QA1611

使用 PVRTC 压缩格式创建纹理

Creating textures in the PVRTC compression format

Q:  我如何使用 PVRTC 压缩格式创建纹理?

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

A: 我如何使用 PVRTC 压缩格式创建纹理?

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.


Copyright ? 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy
Policy
 | Updated: 2009-07-14

使用 PVRTC 压缩格式创建纹理(Creating textures in the PVRTC compression format),布布扣,bubuko.com

时间: 2024-10-01 05:16:18

使用 PVRTC 压缩格式创建纹理(Creating textures in the PVRTC compression format)的相关文章

常用纹理和纹理压缩格式

转载至: http://blog.csdn.net/ynnmnm/article/details/44983545 by 夜风 简单纹理格式 RGBA8888 每个像素4字节,RGBA通道各占用8位 RGBA4444 每个像素2字节,RGBA通道各占用4位 RGB888 每个像素3字节,RGB通道各占用8位,无透明通道 RGB565 每个像素2字节,RGB通道各占用5/6/5位,无透明通道 RGBA5551 每个像素2字节,RGB通道各占用5位,透明通道1位,所以要么完全透明要么不透明 DXT纹

Unity3d纹理压缩格式表

将Texure Type设置为Advanced时纹理的格式列表 格式 详解 Automatic Compressed 压缩RGB纹理,默认选项,常用的漫反射纹理格式.4位/像素(32KB, 256x256) RGB Compressed DXT1 压缩的RGB纹理.常用的漫反射纹理格式.4位/像素(32KB, 256x256) RGBA Compressed DXT5 压缩的RGBA纹理.是漫反射和高光控制纹理的主要格式.1字节/像素(64KB, 256x256) RGB Compressed

移动平台纹理压缩格式选择

1)移动平台纹理压缩格式选择2)Unity 2018是否在Mali GPU上支持Alpha 8格式3)如何在Unity自带的Navmesh上获取地面高度4)ParticleSystem无法重新播放5)UI开发中按界面的打开顺序返回到上级面板的问题 Texture Q:在这之前了解过纹理压缩的相关知识和UWA的一些推荐方式.但还是有一点小的疑问,所以在这里再次提出来,希望得到解答. 在纹理压缩格式的选择上,如果Android选用ETC,iOS选用PVRTC,因为有2的次方(ETC1和PVRTC)长

创建GZIP压缩格式的HIVE表

[Author]:  kwu GZIP为Linux系统中最常用的压缩格式,创建GZIP压缩格式的HIVE表具体步骤如下. 1.以 STORED AS TEXTFILE 为存储格式创建HIVE表 CREATE TABLE TRACKLOG (DATEDAY STRING COMMENT "日期",IP STRING COMMENT "IP",COOKIEID STRING COMMENT "用户COOKIE",USERID STRING COMME

Linux XZ压缩格式学习

XZ的介绍   今天升级Python的时候,下载的Python-2.7.8.tar.xz安装包为xz格式,好吧,我又孤陋寡闻了,居然第一次遇见xz格式的压缩文件.搜索了一下资料,下面是xz的一些介绍: xz是一个使用 LZMA压缩算法的无损数据压缩文件格式.和gzip与bzip2一样,同样支持多文件压缩,但是约定不能将多于一个的目标文件压缩进同一个档案文件.相反,xz通常作为一种归档文件自身的压缩格式,例如使用tar或cpioUnix程序创建的归档.xz 在GNU coreutils(版本 7.

常见压缩格式比对,及 Linux 下的压缩相关指令

可先浏览加粗部分 一.常见压缩档 *.zip | zip 程序压缩打包的档案: (很常见,但是因为不包含文档名编码信息,跨平台可能会乱码) *.rar | winrar 进程压缩打包的档案:(在windows上很常见,但是是商业软件.) *.gz | gzip 程序压缩的档案: (linux目前使用最广泛的压缩格式) *.bz2 | bzip2 程序压缩的档案: *.xz | xz 程序压缩的档案: *.tar | tar 程序打包的资料,并没有压缩过: *.tar.gz | tar 程序打包的

使用django + Pillow进行图片上传压缩格式保存时出错的处理

安装Pillow之前先安装好python-dev libzip-dev libjpeg8-dev libfreetype6-dev libpng12-dev 否则在用PIL(Pillow)进行上传图片压缩格式保存时会出错: encoder jpeg not available decoder zip not available sudo apt-get install python-dev libzip-dev libjpeg8-dev libfreetype6-dev libpng12-dev

c#生成AVI自动设置压缩格式,不调用AVISaveOptions

工作中遇到生成AVI视频的项目,代码中会调用AVISaveOptions来设置压缩格式,针对单个文件还好说,但是批量生成视频的时候,每一个都要设置格式, 体验不是很好,经过查询资料问题得到解决 最开始的代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS(); opts.fccType = _fccType; opts.fccHandler = 0;

统计电视机顶盒中无效用户数据,并以压缩格式输出

前面我们学习了如何使用MapReduce计数器,那么我们通过下面这个项目巩固我们所学 1.介绍 本项目我们使用电视机顶盒数据,统计出无效用户数据记录,并解析出有效的用户数据以压缩格式输出 2.数据集 数据来源于“hadoop小文件合并”处理后的结果 3.分析 基于需求,我们通过以下几步完成: 1.首先使用Jsoup,解析出html格式的机顶盒数据 2.编写Mapper类,自定义计数器统计无效的机顶盒数据,并将有效的机顶盒数据以压缩格式输出 4.实现 1.首先定义一个ParseTVData类,解析