开发视界翻译-图像载入和色彩剪裁
出处:开发视界-http://www.sf.org.cn
这是一个用程序实现如何高效率处理一般图形图象数据的小例子:
用Series 60 图像格式转换加载文件中(jpg/png/gif 三种格式为例) 的图像
从外部同步化进程,以便你得到一个图像加载的阻断方法
以12位元彩色的256色调色板执行简单色彩剪裁把图像转换成一个带有索引的位图。
注意: 此例子使用嵌套调度。 (嵌套 CActiveScheduler::Start(),CActiveScheduler::Stop())
这种方法如果误用可能是危险的, 但谨慎地用,它是简单高效的。
以下是 CImageLoader 和 CTexture 这两个类的源文件; CTexture 是一个承载数据,
调色板和画面高度/宽度的图像类,但是因为我在3D texture mapper中直接使用了此代码,它叫做:texture。
程序中写了注释,读起来应该很好理解。当然希望大家从中真正地学到知识,而不是直接拷贝。
并且程序是受版权保护的。
Happy hacking!
--------------------------------------------------------------------------------
texture.h:
#ifndef __TEXTURE_H
#define __TEXTURE_H
#include <e32base.h>
/**
* Represents a texture used by the texture mapping routines.
*/
class CTexture : public CBase
{
public:
/*!
@函数NewL
@讨论建立CTexture的一个对象
@param aWidth texture宽度 (须在2的3次幂到2的10次幂之间,从而使宽度在8-1024的范围内)
@param aHeight texture高度
@param aWidthShift==log2(aWidth)
@param aPalette调色板信息,这个被复制到本地缓冲器中
@param aData 指向调色板指针的索引texture数据,它不被拷贝到本地缓冲器,所
以起始缓冲器在销毁这个对象之前不可以被释放 */
static CTexture * NewL(TInt aWidth, TInt aHeight, TInt aWidthShift, TUint16 *aPalette, TUint8 *aData);
~CTexture();
TInt GetWidth() { return iWidth; }
TInt GetHeight() { return iHeight; }
TInt GetWidthShift() { return iWidthShift; }
TUint16 * GetPalette() { return iPalette; }
TUint8 * GetData() { return iData; }
private:
CTexture();
void ConstructL(TInt aWidth, TInt aHeight, TInt aWidthShift, TUint16 *aPalette, TUint8 *aData);
TInt iWidth;
TInt iHeight;
TInt iWidthShift;
TUint16 *iPalette;
TUint8 *iData;
};
#endif
--------------------------------------------------------------------------------
texture.cpp:
#include "texture.h"
CTexture * CTexture::NewL(TInt aWidth, TInt aHeight, TInt aWidthShift, TUint16 *aPalette, TUint8 *aData)
{
CTexture *texture = new (ELeave) CTexture();
CleanupStack::PushL(texture);
texture->ConstructL(aWidth, aHeight, aWidthShift,
aPalette, aData);
CleanupStack::Pop(); // texture
return texture;
}
void CTexture::ConstructL(TInt aWidth, TInt aHeight, TInt aWidthShift,
TUint16 *aPalette, TUint8 *aData)
{
iWidth = aWidth;
iHeight = aHeight;
iWidthShift = aWidthShift;
iData = aData;
// 创建一个调色板并复制它到本地指针
iPalette = (TUint16 *)User::AllocL(256 * sizeof(TUint16));
Mem::Copy(iPalette, aPalette, 256 * sizeof(TUint16));
}
CTexture::CTexture()
{
}
CTexture::~CTexture()
{
User::Free(iData);
User::Free(iPalette);
}
贴子一次不能发太长剩余请到这里查看
http://www.sf.org.cn/Article/symbiandev/200603/17219.html