2010-07-23 14:36:16 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_UPHONE_UIIMAGE_H__
|
|
|
|
#define __PLATFORM_UPHONE_UIIMAGE_H__
|
|
|
|
|
|
|
|
#include <string>
|
2010-08-06 09:29:18 +08:00
|
|
|
#include "ccxCommon.h"
|
2010-09-26 10:09:05 +08:00
|
|
|
#include "CCRenderTexture.h"
|
2010-07-23 14:36:16 +08:00
|
|
|
|
2010-07-23 15:13:47 +08:00
|
|
|
class TBitmap;
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-23 15:13:47 +08:00
|
|
|
|
2010-09-26 10:09:05 +08:00
|
|
|
// typedef enum {
|
|
|
|
// kImageTypePNG = 0,
|
|
|
|
// kImageTypeJPG = 1,
|
|
|
|
// } CCXImageType;
|
|
|
|
|
|
|
|
typedef struct
|
2010-09-18 14:14:51 +08:00
|
|
|
{
|
|
|
|
unsigned int height;
|
|
|
|
unsigned int width;
|
|
|
|
int bitsPerComponent;
|
|
|
|
bool hasAlpha;
|
|
|
|
bool isPremultipliedAlpha;
|
|
|
|
unsigned char *data;
|
|
|
|
} tImageInfo;
|
|
|
|
|
2010-08-06 09:29:18 +08:00
|
|
|
class CCX_DLL UIImage
|
2010-07-23 14:36:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
UIImage(void);
|
2010-09-09 17:24:55 +08:00
|
|
|
UIImage(TBitmap *bitmap);
|
|
|
|
|
2010-07-26 18:18:46 +08:00
|
|
|
UIImage(int nX, int nY, void *buffer);
|
2010-07-23 14:36:16 +08:00
|
|
|
~UIImage(void);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** load the image from the specified path
|
|
|
|
@imageType: the type of image, now only support tow types
|
|
|
|
kImageFormatPNG -> png
|
|
|
|
kImageFormatJPG -> jpeg
|
|
|
|
*/
|
2010-09-26 10:09:05 +08:00
|
|
|
bool initWithContentsOfFile(const std::string &strPath, tImageFormat imageType = kImageFormatPNG);
|
2010-08-26 13:47:47 +08:00
|
|
|
bool initWithData(unsigned char *pBuffer, int nLength);
|
|
|
|
bool initWithBuffer(int tx, int ty, unsigned char *pBuffer);
|
2010-07-23 14:36:16 +08:00
|
|
|
|
2010-07-26 18:18:46 +08:00
|
|
|
bool save(const std::string &strFileName, int nFormat);
|
2010-07-23 14:36:16 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** get the image width */
|
2010-08-02 10:58:00 +08:00
|
|
|
unsigned int width(void);
|
2010-09-28 16:18:05 +08:00
|
|
|
/** get the image height */
|
2010-08-02 10:58:00 +08:00
|
|
|
unsigned int height(void);
|
2010-07-23 14:36:16 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** whether or not the image has alpha channel */
|
2010-07-23 14:36:16 +08:00
|
|
|
bool isAlphaPixelFormat(void);
|
2010-09-28 16:18:05 +08:00
|
|
|
/** whether or not the r, g, b channels are premultiplied by alpha channel */
|
2010-08-04 14:38:11 +08:00
|
|
|
bool isPremultipliedAlpha(void);
|
2010-07-23 14:36:16 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** get the bit depth of each color channel */
|
2010-07-26 18:18:46 +08:00
|
|
|
int CGImageGetBitsPerComponent(void);
|
2010-09-28 16:18:05 +08:00
|
|
|
/** the source color space for the image, or 0 if the image is an image mask */
|
2010-07-26 18:18:46 +08:00
|
|
|
int CGImageGetColorSpace(void);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** get the image data */
|
2010-09-26 10:09:05 +08:00
|
|
|
unsigned char* getData(void);
|
2010-08-12 14:46:58 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool loadPng(const char* strFileName);
|
2010-08-26 12:04:22 +08:00
|
|
|
bool loadPngFromStream(unsigned char *data, int nLength);
|
2010-09-26 10:09:05 +08:00
|
|
|
bool loadJpg(const char *strFileName);
|
2010-08-12 14:46:58 +08:00
|
|
|
|
2010-07-23 14:36:16 +08:00
|
|
|
private:
|
|
|
|
TBitmap *m_pBitmap;
|
2010-09-18 14:14:51 +08:00
|
|
|
tImageInfo m_imageInfo;
|
2010-07-23 14:36:16 +08:00
|
|
|
};
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|
2010-07-23 14:36:16 +08:00
|
|
|
|
|
|
|
#endif // __PLATFORM_UPHONE_UIIMAGE_H__
|