cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Image Class Reference

#include <CCImage.h>

Inheritance diagram for Image:
Ref

Public Types

enum  Format {
  JPG, PNG, TIFF, WEBP,
  PVR, ETC, S3TC, ATITC,
  TGA, RAW_DATA, UNKOWN
}
 Supported formats for Image. More...
 

Public Member Functions

 Image ()
 ctor More...
 
virtual ~Image ()
 NA NA More...
 
bool initWithImageFile (const std::string &path)
 Load the image from the specified path. More...
 
bool initWithImageData (const unsigned char *data, ssize_t dataLen)
 Load image from stream buffer. More...
 
bool initWithRawData (const unsigned char *data, ssize_t dataLen, int width, int height, int bitsPerComponent, bool preMulti=false)
 
unsigned char * getData ()
 
ssize_t getDataLen ()
 
Format getFileType ()
 
Texture2D::PixelFormat getRenderFormat ()
 
int getWidth ()
 
int getHeight ()
 
int getNumberOfMipmaps ()
 
MipmapInfogetMipmaps ()
 
bool hasPremultipliedAlpha ()
 
bool isPremultipliedAlpha ()
 
int getBitPerPixel ()
 
bool hasAlpha ()
 
bool isCompressed ()
 
bool saveToFile (const std::string &filename, bool isToRGB=true)
 Save Image data to the specified file, with specified format. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 NA NA More...
 

Static Public Member Functions

static void setPVRImagesHavePremultipliedAlpha (bool haveAlphaPremultiplied)
 treats (or not) PVR files as if they have alpha premultiplied. More...
 

Protected Types

typedef struct sImageTGA tImageTGA
 

Protected Member Functions

bool initWithJpgData (const unsigned char *data, ssize_t dataLen)
 
bool initWithPngData (const unsigned char *data, ssize_t dataLen)
 
bool initWithTiffData (const unsigned char *data, ssize_t dataLen)
 
bool initWithWebpData (const unsigned char *data, ssize_t dataLen)
 
bool initWithPVRData (const unsigned char *data, ssize_t dataLen)
 
bool initWithPVRv2Data (const unsigned char *data, ssize_t dataLen)
 
bool initWithPVRv3Data (const unsigned char *data, ssize_t dataLen)
 
bool initWithETCData (const unsigned char *data, ssize_t dataLen)
 
bool initWithS3TCData (const unsigned char *data, ssize_t dataLen)
 
bool initWithATITCData (const unsigned char *data, ssize_t dataLen)
 
bool initWithTGAData (tImageTGA *tgaData)
 
bool saveImageToPNG (const std::string &filePath, bool isToRGB=true)
 
bool saveImageToJPG (const std::string &filePath)
 
void premultipliedAlpha ()
 
 Image (const Image &rImg)
 
Imageoperator= (const Image &)
 
bool initWithImageFileThreadSafe (const std::string &fullpath)
 
Format detectFormat (const unsigned char *data, ssize_t dataLen)
 
bool isPng (const unsigned char *data, ssize_t dataLen)
 
bool isJpg (const unsigned char *data, ssize_t dataLen)
 
bool isTiff (const unsigned char *data, ssize_t dataLen)
 
bool isWebp (const unsigned char *data, ssize_t dataLen)
 
bool isPvr (const unsigned char *data, ssize_t dataLen)
 
bool isEtc (const unsigned char *data, ssize_t dataLen)
 
bool isS3TC (const unsigned char *data, ssize_t dataLen)
 
bool isATITC (const unsigned char *data, ssize_t dataLen)
 
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

Protected Attributes

unsigned char * _data
 
ssize_t _dataLen
 
int _width
 
int _height
 
bool _unpack
 
Format _fileType
 
Texture2D::PixelFormat _renderFormat
 
MipmapInfo _mipmaps [MIPMAP_MAX]
 
int _numberOfMipmaps
 
bool _hasPremultipliedAlpha
 
std::string _filePath
 
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 

Static Protected Attributes

static const int MIPMAP_MAX = 16
 Determine how many mipmaps can we have. More...
 

Friends

class TextureCache
 

Member Typedef Documentation

typedef struct sImageTGA tImageTGA
protected

Member Enumeration Documentation

enum Format
strong

Supported formats for Image.

Enumerator
JPG 

JPEG.

PNG 

PNG.

TIFF 

TIFF.

WEBP 

WebP.

PVR 

PVR.

ETC 

ETC.

S3TC 

S3TC.

ATITC 

ATITC.

TGA 

TGA.

RAW_DATA 

Raw Data.

UNKOWN 

Unknown format.

Constructor & Destructor Documentation

Image ( )

ctor

virtual ~Image ( )
virtual

NA NA

Image ( const Image rImg)
protected

Member Function Documentation

Format detectFormat ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
int getBitPerPixel ( )
unsigned char* getData ( )
inline
ssize_t getDataLen ( )
inline
Format getFileType ( )
inline
int getHeight ( )
inline
MipmapInfo* getMipmaps ( )
inline
int getNumberOfMipmaps ( )
inline
Texture2D::PixelFormat getRenderFormat ( )
inline
int getWidth ( )
inline
bool hasAlpha ( )
bool hasPremultipliedAlpha ( )
inline
bool initWithATITCData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithETCData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithImageData ( const unsigned char *  data,
ssize_t  dataLen 
)

Load image from stream buffer.

Parameters
datastream buffer which holds the image data.
dataLendata length expressed in (number of) bytes.
Returns
true if loaded correctly. NA NA
bool initWithImageFile ( const std::string &  path)

Load the image from the specified path.

Parameters
paththe absolute file path.
Returns
true if loaded correctly.
bool initWithImageFileThreadSafe ( const std::string &  fullpath)
protected
bool initWithJpgData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithPngData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithPVRData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithPVRv2Data ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithPVRv3Data ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithRawData ( const unsigned char *  data,
ssize_t  dataLen,
int  width,
int  height,
int  bitsPerComponent,
bool  preMulti = false 
)
bool initWithS3TCData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithTGAData ( tImageTGA tgaData)
protected
bool initWithTiffData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool initWithWebpData ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isATITC ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isCompressed ( )
bool isEtc ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isJpg ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isPng ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isPremultipliedAlpha ( )
inline
bool isPvr ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isS3TC ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isTiff ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
bool isWebp ( const unsigned char *  data,
ssize_t  dataLen 
)
protected
Image& operator= ( const Image )
protected
void premultipliedAlpha ( )
protected
bool saveImageToJPG ( const std::string &  filePath)
protected
bool saveImageToPNG ( const std::string &  filePath,
bool  isToRGB = true 
)
protected
bool saveToFile ( const std::string &  filename,
bool  isToRGB = true 
)

Save Image data to the specified file, with specified format.

Parameters
filePaththe file's absolute path, including file suffix.
isToRGBwhether the image is saved as RGB format.
static void setPVRImagesHavePremultipliedAlpha ( bool  haveAlphaPremultiplied)
static

treats (or not) PVR files as if they have alpha premultiplied.

Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is possible load them as if they have (or not) the alpha channel premultiplied.

By default it is disabled.

Friends And Related Function Documentation

friend class TextureCache
friend

Member Data Documentation

unsigned char* _data
protected
ssize_t _dataLen
protected
std::string _filePath
protected
Format _fileType
protected
bool _hasPremultipliedAlpha
protected
int _height
protected
MipmapInfo _mipmaps[MIPMAP_MAX]
protected
int _numberOfMipmaps
protected
Texture2D::PixelFormat _renderFormat
protected
bool _unpack
protected
int _width
protected
const int MIPMAP_MAX = 16
staticprotected

Determine how many mipmaps can we have.

Its same as define but it respects namespaces


The documentation for this class was generated from the following file: