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-10-11 15:28:58 +08:00
|
|
|
class TBitmap;
|
2010-09-29 17:39:45 +08:00
|
|
|
namespace cocos2d {
|
2010-10-11 10:58:27 +08:00
|
|
|
class CCXBitmapDC;
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/// @cond
|
2010-09-26 10:09:05 +08:00
|
|
|
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-09-29 17:39:45 +08:00
|
|
|
/// @endcond
|
2010-09-18 14:14:51 +08:00
|
|
|
|
2010-09-28 18:00:38 +08:00
|
|
|
/**
|
|
|
|
@brief image toolkits
|
|
|
|
*/
|
2010-08-06 09:29:18 +08:00
|
|
|
class CCX_DLL UIImage
|
2010-07-23 14:36:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
UIImage(void);
|
2010-10-11 10:58:27 +08:00
|
|
|
UIImage(CCXBitmapDC * pBmpDC);
|
2010-09-09 17:24:55 +08:00
|
|
|
|
2010-07-23 14:36:16 +08:00
|
|
|
~UIImage(void);
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/**
|
|
|
|
Load the image from the specified path.
|
|
|
|
@param strPath the absolute file path
|
|
|
|
@param imageType the type of image, now only support tow types:
|
|
|
|
- kImageFormatPNG -> png
|
|
|
|
- kImageFormatJPG -> jpeg
|
|
|
|
@return true if load correctly
|
2010-09-28 16:18:05 +08:00
|
|
|
*/
|
2010-12-25 15:09:42 +08:00
|
|
|
bool initWithContentsOfFile(const std::string &strPath, eImageFormat imageType = kCCImageFormatPNG);
|
2010-09-29 17:39:45 +08:00
|
|
|
/**
|
|
|
|
Load image from stream buffer.
|
|
|
|
@param pBuffer stream buffer that hold the image data
|
|
|
|
@param nLength the length of data(managed in byte)
|
|
|
|
@return true if load correctly
|
|
|
|
*/
|
2010-08-26 13:47:47 +08:00
|
|
|
bool initWithData(unsigned char *pBuffer, int nLength);
|
2010-07-23 14:36:16 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/// @cond
|
2010-10-11 15:28:58 +08:00
|
|
|
bool initWithBitmap(const TBitmap* pBmp);
|
2010-09-29 17:39:45 +08:00
|
|
|
bool initWithBuffer(int tx, int ty, unsigned char *pBuffer);
|
2010-07-26 18:18:46 +08:00
|
|
|
bool save(const std::string &strFileName, int nFormat);
|
2010-09-29 17:39:45 +08:00
|
|
|
/// @endcond
|
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:
|
2010-08-26 12:04:22 +08:00
|
|
|
bool loadPngFromStream(unsigned char *data, int nLength);
|
2010-11-29 10:49:43 +08:00
|
|
|
bool loadJpgFromStream(unsigned char *data, unsigned long nSize);
|
2010-08-12 14:46:58 +08:00
|
|
|
|
2010-07-23 14:36:16 +08:00
|
|
|
private:
|
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__
|