let webp of image can be rendered by cocos2d-x,make picture more smaller

WebP is a new image format that provides lossless and lossy compression for images on the web. WebP lossless images are 28 smaller in size compared to PNGs. WebP lossy images are 25-34 smaller in size compared to JPEG images at equivalent SSIM index. WebP supports losseless transparency (also known as alpha channel) with just 22 additional bytes. WebP also supports features such as animation, ICC color profile, XMP meta-data and tiling.
Webmasters and web developers can use the WebP image format to create smaller and richer images that can help make the web faster.

#include “HelloWorldScene.h”
#include “CCTexture2D.h”
#include “CCImage.h”
USING_NS_CC;

#include <WebP/decode.h>

@CCFileData tmpData(CCFileUtils::fullPathFromRelativePath("test0.webp"), "rb");
unsigned long  nSize = 0;
nSize = tmpData.getSize();
unsigned char\* pBuffer = NULL;
pBuffer =tmpData.getBuffer();

// Get the current version of the WebP decoder
int rc = WebPGetDecoderVersion();

printf("Version: d“, rc);

// Get the width and height of the selected WebP image
int width = 0;
int height = 0;
WebPGetInfo(pBuffer, nSize, &width, &height);
printf(”Image Width: d Image Height: d", width, height);

// Decode the WebP image data into a RGBA value array
uint8_t data = WebPDecodeRGBA;
CCImage
tmpImage = new CCImage();
bool isOk = tmpImage~~>initWithImageData,width,height,8);
if {
CCTexture2D * tmpText = new CCTexture2D;
tmpText~~>initWithImage(tmpImage);
CCSprite * tmpSprite = CCSprite::spriteWithTexture(tmpText);
tmpSprite~~>setPosition);
this~~>addChild(tmpSprite);
}@

you can copy the WebP.framework into your frameworks


WebP.framework.zip (308.6 KB)

Awesome.

integrate into Android platform method:

Download webp resource from:
http://code.google.com/intl/zh-CN/speed/webp/download.html

compile the src ,and get the libwebp.a

Modify: cocos2dx/Android.mk
Add: LOCAL_C_INCLUDES $(LOCAL_PATH)/platform/third_party/android/libwebp
Add: LOCAL_LDLIBS -lwebp

Copy webp src file into cocos2dx/platform/third_party/android/libwebp
Copy libwebp.a into cocos2dx/platform/third_party/android/libraries

Modify CCTextureCache.cpp and CCImage

decode method :

@
bool CCImage::*initWithWebpData
{
bool bRet = false;
do
{
int width = 0;
int height = 0;
WebPGetInfopData, nDatalen, &width, &height);
// Decode the WebP image data into a RGBA value array
uint8_t *data = WebPDecodeRGBApData, nDatalen, &width, &height);
bRet =*initWithRawData(data, nDatalen, width, height, 8);

free(data);

return bRet;

} while (0);

return bRet;
}

@