PVR图像文件格式初探

来源:互联网 发布:052d 知乎 编辑:程序博客网 时间:2024/05/12 03:30
ios上图片当然是用pvr(pvrtc2/pvrtc4)格式,推荐pvr.ccz的rgb565/rgba4444格式

一.PVR格式优点:
1. cpu上,解压速度快,读取后不用解析直接交给显卡,不需要转换为ARGB形式就可以提交给显卡使用。
2. 内存和显存上,读取后直接提交给显卡,不用开辟临时内存来读取像素数据,避免了内存的申请释放消耗和内存的飙升。
3.文件大小上,pvr.ccz是压缩后的pvr格式,将大量的文件压缩为pvr.ccz可以有效的减少文件大小。

二.PVR文件格式:
PVRTC2PVRTC4是两种pvr压缩的图像格式,他们都是pvr文件。这两种图像格式比普通图像有更快的加载速度和更小的内存占用。
PVRTC4: Compressed format, 4 bits per pixel, ok image quality
PVRTC2: Compressed format, 2 bits per pixel, poor image quality
一般pvr格式文件的图像格式有:
RGBA8888: 32-bit texture with alpha channel, best image quality
RGBA4444: 16-bit texture with alpha channel, good image quality
RGB565: 16-bit texture without alpha channel, good image quality but no alpha (transparency)
PVR文件格式内容:
参见:http://imgtec.eetrend.com/download/1595
Header(52Byte) + Meta Data(0 + Bytes) + Texture Data(0 + Bytes)
包含了表面和层级mipmap,cubemap,volumemap信息,nFlag加表面特性信息,这都是提交给显卡直接需要的特性,类似PC下的dds贴图格式。
1.Name Size(bytes) Data Format
// The exact value of ‘Version’ will be one of the following depending upon the endianess of the file
1)Version 4 Unsigned 32bit Integer
/*
0x03525650, if endianess does not match
· 0x50565203, if endianess does match
*/
2)Flags 4 Unsigned 32bit Integer
/*
No Flag 0 No flag has been set.
Pre-multiplied 0x02 When this flag is set, colour values within the texture have been pre-multiplied by the alpha
values.
*/
3)Pixel Format 8 Unsigned 64bit Integer
/*
PVRTC 2bpp RGB 0
PVRTC 2bpp RGBA 1
PVRTC 4bpp RGB 2
PVRTC 4bpp RGBA 3
PVRTC-II 2bpp 4
PVRTC-II 4bpp 5
ETC1 6
DXT1 7
DXT2 8
DXT3 9
DXT4 10
DXT5 11
BC1 7
BC2 9
BC3 11
BC4 12
BC5 13
BC6 14
BC7 15
UYVY 16
YUY2 17
BW1bpp 18
R9G9B9E5 Shared Exponent 19
RGBG8888 20
GRGB8888 21
ETC2 RGB 22
ETC2 RGBA 23
ETC2 RGB A1 24
EAC R11 Unsigned 25
EAC R11 Signed 26
EAC RG11 Unsigned 27
EAC RG11 Signed 28
*/
4)Colour Space 4 Unsigned 32bit Integer
/*Linear RGB 0 Texture data is in the Linear RGB colour space
sRGB 1 Texture data is in the Standard RGB colour space
*/
5)Channel Type 4 Unsigned 32bit Integer
/*Unsigned Byte Normalised 0
Signed Byte Normalised 1
Unsigned Byte 2
Signed Byte 3
Unsigned Short Normalised 4
Signed Short Normalised 5
Unsigned Short 6
Signed Short 7
Unsigned Integer Normalised 8
Signed Integer Normalised 9
Unsigned Integer 10
Signed Integer 11
Float 12
*/
6)Height 4 Unsigned 32bit Integer // 高度的像素个数
7)Width 4 Unsigned 32bit Integer // 宽度的像素个数
8)Depth 4 Unsigned 32bit Integer // 深度的像素个数(也就是所有的深度数)
9)Num. Surfaces 4 Unsigned 32bit Integer // 纹理数组的表面面数
10)Num. Faces 4 Unsigned 32bit Integer // CubeMap纹理的面数
11)MIP-Map Count 4 Unsigned 32bit Integer // mipmap的 levels渐进层级数,如果是1只有一个纹理
12)Meta Data Size 4 Unsigned 32bit Integer // meta data大小

2.Meta Data Format
Meta data allows for the creator of a PVR to store custom information within the PVR file relating to
the storage
2.1)FourCC 4 Four Byte Array
2.2)Key 4 Unsigned 32bit Integer
2.3)Data Size 4 Unsigned 32bit Integer
2.4)Data Variable Variable

3.Texture Data
The remainder of the file, after the header and meta data, is texture data. The format and size of this
texture data can be found in the header (see Section 2.1 Header Format).
The texture data is laid out as follows:
for each MIP-Map Level in MIP-Map Count // 纹理层级数
for each Surface in Num. Surfaces // 表面数(一个表面可以有6个面数)
for each Face in Num. Faces // 面数
for each Slice in Depth // 片(一个面可能有多个片三角形)
for each Row in Height // 行
for each Pixel in Width // 像素
Byte data[Size_Based_On_PixelFormat]
end
end
end
end
end
end

三.PVR文件生成工具:
1)PVRTexTool:
高效压缩格式纹理: pvr, 必须是正方形且边长为2的幂次方,使用PvrTexTool生成.
PvrTexTool支持命令行调用,调用方法和参数请参考纹理工具命令行调用范例
苹果设备限制标准官方文档

3D模型光效贴图,不按这种方式(PVRTC 4BPP)出3D贴图会导致模型贴图闪烁
1.PVRTC4BPP像素格式的PVR贴图必须是正方形且边长为2的幂次方
2.文字型的光效贴图使用-m参数会导致文字显示模糊。
3.Android版本下可以选择RGBA 4444像素格式的PVR贴图以兼容所有Android手机机型,且没有2的次方限制。

2)TexturePacker:
TP让你可以创建PVR格式的纹理。除了PVR纹理支持NPOT外,它们不仅可以不是2的幂,而且还可以不是方形的(但方形2的幂次方的pvr格式效率更高)
PVR 是最灵活的纹理文件格式。除了支持标准的未压缩的RGB图片格式外,支持有损压缩的pvrtc格式。另外,未压缩的pvr格式的纹理的内存消耗非常地低。 不像png图片那样要消耗2倍于本身内存占用大小的内存,pvr格式只需要消耗纹理本身内存大小再加上一点点处理该图片格式的内存大小。
pvr格式的一个缺点就是,你不能在Mac上面打开查看。但是,如果你安装了TP的话,就可以使用TP自带的pvr图片浏览器来浏览pvr格式的图片了。
用脚本调用TP批量转化:
1、新建一个 bat文件 如:PVR转PNG.bat
2、输入内容如下:


   1:  @echo off
   2:   
   3:  path %path%;"C:\Program Files (x86)\CodeAndWeb\TexturePacker\bin"
   4:   
   5:  for /f "usebackq tokens=*" %%d in (`dir /s /b *.pvr *.pvr.ccz *.pvr.gz`) do (
   6:  TexturePacker.exe "%%d" --sheet "%%~dpnd.png" --data "%%~dpnd.plist" --opt RGBA8888 --allow-free-size --algorithm Basic --no-trim --dither-fs
   7:  )
   8:   
   9:  pause


可以将第6行的 %%~dpnd.png 改成 %%~dpnd.jpg,就可以转成jpg


PNG转PVR.bat


   1:  @echo off
   2:   
   3:  path %path%;"C:\Program Files (x86)\CodeAndWeb\TexturePacker\bin"
   4:   
   5:  for /f "usebackq tokens=*" %%d in (`dir /s /b *.png`) do (
   6:  TexturePacker.exe "%%d" --sheet "%%~dpnd.pvr" --data "%%~dpnd.plist" --opt PVRTC4 --allow-free-size --algorithm Basic --no-trim --dither-fs
   7:  )
   8:   
   9:  pause
参考文章:
http://www.cnblogs.com/luming1979/archive/2013/02/04/2891421.html
http://www.cnblogs.com/optimus/archive/2012/06/27/2565860.html
http://wiki.c3.99.com/index.php?title=%E6%89%8B%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%BA%B9%E7%90%86%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E
http://blog.csdn.net/kaitiren/article/details/8054856
http://www.cnblogs.com/zhaoqingqing/p/3921833.html
http://blog.csdn.net/peng_weida/article/details/40116169
http://imgtec.eetrend.com/download/1595




0 0
原创粉丝点击