You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.0 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//////////////////////////////////////////////////////////////////////////////
//文件 Texture.h
//主要功能:
//
//程序编写: 2005-12-07
/////////////////////////////////////////////////////////////////////////////
//********************************************
// class CTexture
//********************************************
// This object stores a bitmap image used as
// an Coin3D texture.
// Depth are currently 8 16 24 or 32 bits,
// Modes are : L(Lighteness), LA, RGB, RGBA (Alpha layer).
//********************************************
#ifndef _TEXTURE_
#define _TEXTURE_
#include "DrawImage\ImageBase.h"
namespace NCube
{
class AFX_EXT_CLASS CTexture : public CObject
{
public :
// Construction / destruction
CTexture();
virtual ~CTexture();
// Memory
int Create(int width, int height, int bpp);
int CreateFrom(CImageBase& img);
//输出图像
int ToImageBase(CImageBase& img);
//绑定指针后,内部将自动删除该指针,绑定之前,内部将自动清空已有数据
int AttachBuffer(unsigned char *buffer, int width, int height, int bpp);
//在Coin3D中使用该函数设置材质时需要设置拷贝方式为SoSFImage::NO_COPY_AND_DELETE
//以便让Coin3D使用delete函数释放内存
unsigned char* Detach(void);
//在Coin3D中使用该函数设置材质时需要设置拷贝方式为SoSFImage::COPY
unsigned char* GetData(void) { return m_pData; }
void Free(void);
// File reading, writing
void Serialize(CArchive& ar);
int ReadImage(char *filename);
int SaveImage(char *filename);
void operator=(CTexture& ir);
// Datas (explicit inline functions)
unsigned char* GetData(int i, int j){ return m_pData + m_lineWidthBytes*j + i*m_nBpp/8; }
int GetDataBytes() { return m_lineWidthBytes*m_nHeight; }
int GetWidth(void) { return m_nWidth; }
int GetHeight(void) { return m_nHeight;}
int GetBPP(void) { return m_nBpp; }
int GetBytesPerPixel() { return m_nBpp/8; }
void SetPixel(int i, int j, RGBQUAD rgba);
void SetPixel(int i, int j, COLORREF color);
RGBQUAD GetPixel(int i, int j);
// Misc
int IsValid();
int BGRtoRGB(void);
// Alpha0为完全透明255为不透明
int HasAlpha() { return (m_nBpp == 32 || m_nBpp == 16); }
int AddAlphaLayer(unsigned char alpha);
int SetAlphaLayer(unsigned char alpha);
void SetAlpha(int i, int j, unsigned char alpha); //设置指定像素点的透明度
void SetColorAlpha(COLORREF color, unsigned char alpha);//设置指定颜色的透明度
int MirrorX(void);
int MirrorY(void);
// Members datas
protected:
//可包含4种长度的纹理数据
//单通道1个字节只包含亮度数据0-255
//双通道2个字节包含亮度和透明度(alpha)数据,各占一个字节
//三通道3个字节包含红、绿、蓝三种颜色数据各占一个字节
//四通道4个字节包含红、绿、蓝及透明度数据各占一个字节
//提示:通常使用单、双通道纹理,因其需要比较少的计算量,快于三、四通道纹理
// 各个像素是按行连续存放共width*height个像素
unsigned char* m_pData; // datas
int m_nWidth; // width (pixels)
int m_nHeight; // height (pixels)
int m_nBpp; // bits per pixel该类仅支持8、16、24、32四种
int m_lineWidthBytes; // width (in bytes, 一行像素的字节个数没有进行32位对齐)
};
};
using namespace NCube;
#endif // _TEXTURE_