cocos2d 像素格式

纹理的像素格式 的图像存储在GPU内存的方式。

可能的像素格式:

  • RGBA8888(32位)(kTexture2DPixelFormat_RGBA8888)
  • RGBA4444(16位)(kTexture2DPixelFormat_RGBA4444)
  • RGB5_A1(16位)(kTexture2DPixelFormat_RGB5A1)
  • RGB565(16位)(kTexture2DPixelFormat_RGB565)

RGBA8888:

  • 8位分配给红色通道, 绿色通道,8蓝色通道和8位alpha 通道8
  • 使用此像素格式,当您需要最大可能为您的图像质量
  • 但它会占用的内存比16位的纹理双。记忆是一种宝贵的资源,在iPhone上
  • 通常它是呈现也比较慢。
  • 有用:您介绍的场景的背景图像,并为大量的渐变颜色的图像

RGBA4444

  • 4位被分配到的红色通道, 绿色通道,蓝色通道44alpha通道4
  • 它可以让你在所有渠道,良好的速度,良好的内存消耗,质量好。
  • 有用的: 有不同的透明度值的精灵

RGB5A1

  • 5位被分配到的红色通道, 绿色通道,蓝色通道5只有1位alpha 通道5
  • 它可以让你在RGB通道的质量好,但质量差的一个通道。它还为您提供良好的速度和良好的内存消耗。
  • 有用的精灵 ,有透明的部分,但在透明度上或关闭

RGB565

  • 5位被分配到的红色通道, 绿色通道65蓝色通道。它有没有alpha通道支持
  • 它给你的16位最好的质量的纹理,但支持alpha通道。
  • 有用的:在游戏中的背景图像。

默认的像素格式 RGBA8888。

如何使用它:

/ /设置之前加载的图像的像素格式 / 8888 / RGBA的图像(32位 [的Texture2D setDefaultAlphaPixelForm  kTexture2DPixelFormat_RGBA8888 ] ; 雪碧* sprite1 [雪碧spriteWithFile ::“测试,rgba1.png的” ] ;   / /设置之前加载的图像的像素格式/ / RGBA的4444图像(16位)的Texture2D setDefaultAlphaPixelForm kTexture2DPixelFormat_RGBA4444 ] ; 雪碧* sprite2 [雪碧spriteWithFile “测试,rgba2.png的” ] ;   / /设置之前加载的图像的像素格式/ / RGB5A1图像(16位)的Texture2D setDefaultAlphaPixelForm kTexture2DPixelFormat_RGB5A1 ] ; 雪碧* sprite3 [雪碧spriteWithFile ::“测试,rgba3.png的” ] ;   / /设置之前加载的图像的像素格式/ / RGB565图像(16位)[的Texture2D setDefaultAlphaPixelForm  kTexture2DPixelFormat_RGB565 ] ; 雪碧* sprite4 [雪碧spriteWithFile “测试,rgba4.png的” ] ;   / /恢复默认的像素格式的Texture2D setDefaultAlphaPixelForm  kTexture2DPixelFormat_Default ] ;

常见问题:

  • 问:我可以使用这种技术PVRTC图像?
  • 答: 没有,PVRTC图像有自己的格式。PVRTC图像的速度更快,占用更少的内存,因为他们是2位或4位的纹理,但质量是没有很大的。
  • 问:如果我用16位的纹理,将我的游戏载入速度?
  • 答: 纹理像素格式有没有做你的游戏的加载时间。像素格式是如何在GPU内存中存储的图像。如果你想更快的加载时间,你应该减少你.PNG /的GIF / TIFF / TMP图像文件的大小。
  • 问:我应该使用RGB565图像压缩由Xcode吗?
  • 答: 当XCode的PNG图像压缩,这将创建一个压缩的PNG图像有它的RGB通道,预乘alpha通道。PNG格式是RGB565,但你不应该混淆纹理像素格式为PNG格式。据了解PNG图像Photoshop和cocos2d,但GPU知道关于PNG图像。PNG图像需要转换成纹理(GPU所理解的格式)。答案是:这取决于你想要什么。图像格式(PNG,GIF TIFF,BMP)的独立的纹理格式。
  • 问:如果我创建一个PNG / BMP / TIFF / GIF等图像没有alpha通道,我可以改变纹理像素格式?
  • 答:如果您的PNG / BMP / TIFF / GIF等图像没有alpha通道(或不预乘),然后将纹理 ​​像素格式是RGB565。它不能被改变使用API,但你可以改变修改Texture2D.m文件
  • 问:我可以更改一次创建纹理的像素格式。
  • 答: 号 一旦创建纹理,你不能修改的像素格式。但是你可以同时使用不同的像素格式的图像创建新的纹理。只要记住从TextureMgr删除的形象!




原文:

Understanding pixel format in cocos2d v0.7.3

Published by  riq on  May 28, 2009 in  cocos2d and pixel format15 Comments

Since cocos2d v0.7.3, you can specify the texture’s pixel format of your PNG/TIFF/BMP/GIF images.
The texture’s pixel format is the way the image is stored in GPU memory.

Possible pixel formats:

  • RGBA8888 (32-bit) (kTexture2DPixelFormat_RGBA8888)
  • RGBA4444 (16-bit) (kTexture2DPixelFormat_RGBA4444)
  • RGB5_A1 (16-bit)(kTexture2DPixelFormat_RGB5A1)
  • RGB565 (16-bit) (kTexture2DPixelFormat_RGB565)

RGBA8888:

  • 8 bits are assigned to the red channel, 8 bits to the green channel, 8 bits to the bluechannel and 8 bits to the alpha channel.
  • Use this pixel format when you need the maximum possible quality for your image.
  • But it will consume the double of memory compared to 16-bit textures. Memory is a precious resource on the iPhone
  • Usually it is also slower to render.
  • Useful for: background image of your intro scene, and for images with lots of gradient colors

RGBA4444:

  • 4 bits are assigned to the red channel, 4 bits to the green channel, 4 bits to the bluechannel, and 4 bits to the alpha channel
  • It gives you good quality in all channels, good speed, good memory consumption.
  • Useful for: sprites that have different values of transparency

RGB5A1:

  • 5 bits are assigned to the red channel, 5 bits to the green channel, 5 bits to the bluechannel, and only 1 bit to the alpha channel
  • It gives you good quality in RGB channels but poor quality on the A channel. It also gives you good speed and good memory consumption.
  • Useful for: sprites that have transparent parts, but the transparency is either On or Off

RGB565:

  • 5 bits are assigned to the red channel, 6 bits to the green channel, and 5 bits to the bluechannel. It has no alpha channel support
  • It gives you the best possible quality for 16-bit textures, but without alpha channel support.
  • Useful for: background images in your game.

The default pixel format in v0.7.3 is RGBA8888.

How to use it:

// Set the pixel format before loading the image // RGBA 8888 image (32-bit [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888]; Sprite *sprite1 = [Sprite spriteWithFile:@"test-rgba1.png"];   // Set the pixel format before loading the image// RGBA 4444 image (16-bit) [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444]; Sprite *sprite2 = [Sprite spriteWithFile:@"test-rgba2.png"];   // Set the pixel format before loading the image // RGB5A1 image (16-bit) [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGB5A1]; Sprite*sprite3 = [Sprite spriteWithFile:@"test-rgba3.png"];   // Set the pixel format before loading the image // RGB565 image (16-bit) [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGB565]; Sprite *sprite4 = [Sprite spriteWithFile:@"test-rgba4.png"];   // restore the default pixel format [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_Default];

FAQ:

  • Q: Can I use this technique for PVRTC images ?
  • A: No, PVRTC images have their own format. PVRTC images are faster and they consume less memory since they are either 2-bit or 4-bit textures but the quality is not that great.
  • Q: If I use 16-bit textures, will my game load faster ?
  • A: The texture pixel format has nothing to do with the loading times of your game. The Pixel Format is how the image is stored in the GPU memory. If you want faster loading times you should reduce the size of your .PNG/GIF/TIFF/TMP image file.
  • Q: Should I use RGB565 for the images that are compressed by XCode ?
  • A: When XCode compresses the PNG images, it will create a compressed PNG image that has it’s alpha channel premultiplied in the RGB channels. The PNG format is RGB565, but you should NOT confuse a PNG format with a texture pixel format. A PNG image is understood by Photoshop and cocos2d, but the GPU knows nothing about PNG images. The PNG images need to be converted into a Texture (the format understood by the GPU). The answer is: it depends on what you want. The Image (PNG,GIF,TIFF,BMP) format is independent of the Texture format.
  • Q: If I create a PNG/BMP/TIFF/GIF image without alpha channel, can I change the texture pixel format ?
  • A: If your PNG/BMP/TIFF/GIF image has no alpha channel (premultiplied or not), then the pixel format that will be used for the texture is RGB565. It can’t be changed using the API but you can change by modifying the Texture2D.m file
  • Q: Can I change the pixel format once the texture was created.
  • A: No. Once the Texture was created you can’t modify the pixel format. But you can create new textures from the same image using different pixel formats. Just remember to remove the image from the TextureMgr!


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值