图片及优化---png的Xcode优化

来源:互联网 发布:淘宝亲密付退款退到哪 编辑:程序博客网 时间:2024/04/30 03:57

开始做iOS应用就有一个“公理”,图片素材要使用png格式,至于公理是怎么形成的完全不知道,只是听说在官方文档里提到过一句:苹果会对png进行优化。

为什么优化?谁优化的?什么时候优化的?怎么优化的?

原因是iPhone的显存。iPhone的vRAM在存放单个像素的颜色的时候,并不是按照传统的“红-绿-蓝”这样的顺序排列的,而是“蓝-绿-红”,即我们常说的RGB,在iPhone的显存里是BGR。并且,没有alpha通道。

另一边,png格式按照“红-绿-蓝”的顺序描述颜色,并且支持alpha通道的半透明,RGBA四个通道各占1个字节。

(1)为什么优化?
因为一边RGB一边BGR,一边有alpha一边没有alpha。
(2)谁优化的?
Xcode优化的,通过pngcrash优化。
(3)什么时候优化的?
Xcode在编译时,会对png资源进行优化。
(4)怎么优化的? 优化做了两件事:
把png里所有的RGB颜色转成BGR顺序
把png里所有的alpha通道先和RGB三通道先乘好(比如R:1 G:1 B:1 A:0.5的颜色直接转成 R:0.5 G:0.5 B:0.5)
这样最终设备在运行时渲染这些颜色的时候,不需要任何处理,一个汇编语句就把数据丢尽显存里了。

苹果官方
Q: When I build my iOS application, Xcode optimizes the PNG files within my application’s bundle, meaning that Preview can’t display them. How can I view these optimized files?
A: This optimization is done by the pngcrush tool, which you can find inside Xcode. The pngcrush tool supports a command line option, -revert-iphone-optimizations, that undoes the optimizations done during the Xcode build process. So, to view an optimized PNG file, you should first undo the optimization and then open it with Preview.
a Listing 1/a shows how you can use the pngcrush tool to convert an iOS-optimized PNG file (Local.png) to a standard PNG file (Local-standard.png). It uses xcrun to run the tool from within your currently selected Xcode (as determined by xcode-select).
PS: 这里还有一个手动转换,和还原的办法

via: http://iphonedevelopment.blogspot.jp/2008/10/iphone-optimized-pngs.html

0 0
原创粉丝点击