天天看點

Cocos2d 檢視 pvr 圖檔的詳細格式

原文連結:http://blog.csdn.net/yang3wei/article/details/7484222

發現一個問題,夥計交過來的pvr圖檔,我沒法确切的知道他到底使用了哪種像素格式。

想到一個辦法,可以在程式加載的時候列印出一些資訊來得到這些資訊。

主要修改 CCTexturePVR.m 這個檔案,先看看pvr支援那些像素格式:

[cpp]  view plain copy

  1. #import <Availability.h>  
  2. #import <zlib.h>  
  3. #import "CCTexturePVR.h"  
  4. #import "ccMacros.h"  
  5. #import "CCConfiguration.h"  
  6. #import "Support/ccUtils.h"  
  7. #import "Support/CCFileUtils.h"  
  8. #import "Support/ZipUtils.h"  
  9. #import "Support/OpenGL_Internal.h"  
  10. #pragma mark -  
  11. #pragma mark CCTexturePVR  
  12. #define PVR_TEXTURE_FLAG_TYPE_MASK  0xff  
  13. #define PVR_TEXTURE_FLAG_FLIPPED_MASK 0x10000  
  14. static char gPVRTexIdentifier[4] = "PVR!";  
  15. enum  
  16. {  
  17.     kPVRTextureFlagTypeRGBA_4444= 0x10,  
  18.     kPVRTextureFlagTypeRGBA_5551,  
  19.     kPVRTextureFlagTypeRGBA_8888,  
  20.     kPVRTextureFlagTypeRGB_565,  
  21.     kPVRTextureFlagTypeRGB_555,             // unsupported  
  22.     kPVRTextureFlagTypeRGB_888,             // unsupported  
  23.     kPVRTextureFlagTypeI_8,  
  24.     kPVRTextureFlagTypeAI_88,  
  25.     kPVRTextureFlagTypePVRTC_2,  
  26.     kPVRTextureFlagTypePVRTC_4,   
  27.     kPVRTextureFlagTypeBGRA_8888,  
  28.     kPVRTextureFlagTypeA_8,  
  29. };  

簡要介紹一下,比較常用的格式有:

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

  1. GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Fri Sep 16 06:56:50 UTC 2011)  
  2. Copyright 2004 Free Software Foundation, Inc.  
  3. GDB is free software, covered by the GNU General Public License, and you are  
  4. welcome to change it and/or distribute copies of it under certain conditions.  
  5. Type "show copying" to see the conditions.  
  6. There is absolutely no warranty for GDB.  Type "show warranty" for details.  
  7. This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys000  
  8. target remote-mobile /tmp/.XcodeGDBRemote-280-57  
  9. Switching to remote-macosx protocol  
  10. mem 0x1000 0x3fffffff cache  
  11. mem 0x40000000 0xffffffff none  
  12. mem 0x00000000 0x0fff none  
  13. [Switching to process 7171 thread 0x1c03]  
  14. [Switching to process 7171 thread 0x1c03]  
  15. sharedlibrary apply-load-rules all  
  16. 2012-04-21 14:18:12.659 GameSceneEx[78875:707] width=1024, height=1024, formatFlags=0x19  
  17. 2012-04-21 14:18:12.706 GameSceneEx[78875:707] width=512, height=1024, formatFlags=0x10  
  18. 2012-04-21 14:18:12.863 GameSceneEx[78875:707] width=512, height=1024, formatFlags=0x10  

如上控制台輸出表示加載了3張pvr圖檔

第一張是 PVRTC4,第二、三張是 RGBA4444。