afImage.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:2k
源码类别:
其他游戏
开发平台:
Visual C++
- #include "afImage.h"
- #include "afLog.h"
- afImage::afImage() : data(NULL)
- {
- width = height = 0;
- format = UNKNOWN;
- }
- afImage::afImage(int nWidth, int nHeight, FORMAT nFormat, const afString& nName, unsigned char* nData, bool nCopy)
- {
- width = nWidth;
- height = nHeight;
- format = nFormat;
- name = nName;
- int size = width * height * getPixelSize();
- if(nData)
- {
- if(nCopy)
- {
- data = new unsigned char[size];
- memcpy(data, nData, size);
- }
- else
- data = nData;
- }
- else
- data = new unsigned char[size];
- }
- int
- afImage::getPixelSize() const
- {
- return getPixelSize(format);
- }
- int
- afImage::getPixelSize(FORMAT nFormat)
- {
- switch(nFormat)
- {
- default:
- case UNKNOWN:
- return 0;
- case A8:
- case P8:
- return 1;
- case RGB565:
- case XRGB1555:
- case ARGB1555:
- case ARGB4444:
- return 2;
- case RGB888:
- return 3;
- case ARGB8888:
- case XRGB8888:
- return 4;
- }
- }
- afString afImage::getFormatString(D3DFORMAT nFormat)
- {
- return getFormatString((FORMAT)nFormat);
- }
- afString afImage::getFormatString(FORMAT nFormat)
- {
- switch(nFormat)
- {
- default:
- case UNKNOWN:
- return "FORMAT-UNKNOWN";
- case A8:
- return "ALPHA-8";
- case P8:
- return "INDEXED-8";
- case RGB565:
- return "RGB-565";
- case XRGB1555:
- return "XRGB-1555";
- case ARGB1555:
- return "ARGB-1555";
- case ARGB4444:
- return "ARGB-4444";
- case RGB888:
- return "RGB-888";
- case ARGB8888:
- return "ARGB-8888";
- case XRGB8888:
- return "XRGB-8888";
- case DXT1:
- return "DXT1";
- case DXT2:
- return "DXT2";
- case DXT3:
- return "DXT3";
- case DXT4:
- return "DXT4";
- case DXT5:
- return "DXT5";
- case L8:
- return "LUMINANCE-8";
- }
- }
- bool afImage::isCompressed(FORMAT nFormat)
- {
- switch(nFormat)
- {
- case DXT1:
- case DXT2:
- case DXT3:
- case DXT4:
- case DXT5:
- return true;
- default:
- return false;
- }
- }
- bool afImage::hasAlpha(FORMAT nFormat)
- {
- switch(nFormat)
- {
- case ARGB8888:
- case ARGB1555:
- case ARGB4444:
- case A8:
- case DXT1:
- case DXT2:
- case DXT3:
- case DXT4:
- case DXT5:
- return true;
- default:
- return false;
- }
- }