原文链接:http://blog.csdn.net/yang3wei/article/details/7484222
发现一个问题,伙计交过来的pvr图片,我没法确切的知道他到底使用了哪种像素格式。
想到一个办法,可以在程序加载的时候打印出一些信息来得到这些信息。
主要修改 CCTexturePVR.m 这个文件,先看看pvr支持那些像素格式:
- #import <Availability.h>
- #import <zlib.h>
- #import "CCTexturePVR.h"
- #import "ccMacros.h"
- #import "CCConfiguration.h"
- #import "Support/ccUtils.h"
- #import "Support/CCFileUtils.h"
- #import "Support/ZipUtils.h"
- #import "Support/OpenGL_Internal.h"
- #pragma mark -
- #pragma mark CCTexturePVR
- #define PVR_TEXTURE_FLAG_TYPE_MASK 0xff
- #define PVR_TEXTURE_FLAG_FLIPPED_MASK 0x10000
- static char gPVRTexIdentifier[4] = "PVR!";
- enum
- {
- kPVRTextureFlagTypeRGBA_4444= 0x10,
- kPVRTextureFlagTypeRGBA_5551,
- kPVRTextureFlagTypeRGBA_8888,
- kPVRTextureFlagTypeRGB_565,
- kPVRTextureFlagTypeRGB_555, // unsupported
- kPVRTextureFlagTypeRGB_888, // unsupported
- kPVRTextureFlagTypeI_8,
- kPVRTextureFlagTypeAI_88,
- kPVRTextureFlagTypePVRTC_2,
- kPVRTextureFlagTypePVRTC_4,
- kPVRTextureFlagTypeBGRA_8888,
- kPVRTextureFlagTypeA_8,
- };
RGBA_8888 没像素占用4字节内存,还原度最高,纹理质量最高。
RGBA_4444 每像素占用2字节内存,背景图采用此类型较优
RGBA_5551 每像素占用2字节内存,如上
RGBA_565 每像素占用2字节内存,如上(4444,5551,565依据对透明度的不同要求做不同选择)~
RGBA_888 每像素占用3字节,不包含透明度的图片用这种像素格式是最优的。
PVRTC_4,PVRTC_2 每像素占4bit,2bit,效果还是相当不错的,不过占用的内存将为8888的16分之1。
不过,耗用如此低,对像素质量也不要报太高期望了。
解题,主要修改 CCTexturePVR.m 的 -unpackPVRData:PVRLen: 方法:
在方法末 return success;这句代码之前添加如下代码:
NSLog(@"width=%d, height=%d, formatFlags=0x%2x", width_, height_, formatFlags);
- GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Fri Sep 16 06:56:50 UTC 2011)
- Copyright 2004 Free Software Foundation, Inc.
- GDB is free software, covered by the GNU General Public License, and you are
- welcome to change it and/or distribute copies of it under certain conditions.
- Type "show copying" to see the conditions.
- There is absolutely no warranty for GDB. Type "show warranty" for details.
- This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys000
- target remote-mobile /tmp/.XcodeGDBRemote-280-57
- Switching to remote-macosx protocol
- mem 0x1000 0x3fffffff cache
- mem 0x40000000 0xffffffff none
- mem 0x00000000 0x0fff none
- [Switching to process 7171 thread 0x1c03]
- [Switching to process 7171 thread 0x1c03]
- sharedlibrary apply-load-rules all
- 2012-04-21 14:18:12.659 GameSceneEx[78875:707] width=1024, height=1024, formatFlags=0x19
- 2012-04-21 14:18:12.706 GameSceneEx[78875:707] width=512, height=1024, formatFlags=0x10
- 2012-04-21 14:18:12.863 GameSceneEx[78875:707] width=512, height=1024, formatFlags=0x10
第一张是 PVRTC4,第二、三张是 RGBA4444。