原文連結:http://blog.csdn.net/yang3wei/article/details/7484222
發現一個問題,夥計交過來的pvr圖檔,我沒法确切的知道他到底使用了哪種像素格式。
想到一個辦法,可以在程式加載的時候列印出一些資訊來得到這些資訊。
主要修改 CCTexturePVR.m 這個檔案,先看看pvr支援那些像素格式:
[cpp] view plain copy
- #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);
[java] view plain copy
- 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
如上控制台輸出表示加載了3張pvr圖檔
第一張是 PVRTC4,第二、三張是 RGBA4444。