⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 surface.h

📁 这个是symbian下的一个蛮庞大的3D游戏源代码!对于学习3D开发的人有很大的帮助!
💻 H
字号:
#ifndef _IMG_SURFACE_H
#define _IMG_SURFACE_H


#include <gr/SurfaceFormat.h>
#include "stdint.h"
#include "Fix.h"
#include <assert.h>
#include "ImageResample.h"


namespace io {
	class InputStream;
	class OutputStream;}


/**
 * Handle to A4R4G4B4 surface pixel data.
 */
class Surface
{
public:
	enum BlendType
	{
		BLEND_COPY,
		BLEND_ALPHA,
		BLEND_ALPHA1B,
		BLEND_ADD,
	};

	enum Flags
	{
		FLAG_DEFAULT	= 0,
		FLAG_MIRROR		= 1,
		FLAG_END_STOP	= 2,
	};

	Surface();
	Surface( void* data, int pitch, int width, int height );
	Surface( const Surface& other, int flags );

	void		destroy();
	void 		blt( int dstx, int dsty, const Surface* src, BlendType blend=BLEND_COPY );
	void 		blt( int dstx, int dsty, const Surface& src, BlendType blend=BLEND_COPY );
	void		fill( int x, int y, int w, int h, int argb4444, BlendType blend=BLEND_COPY );
	void		load( const char* fname, ImageResample* imageResamplingEngine = 0, bool halfResolution = false );
	void		setPixel( int x, int y, int rgba4444 );
	void		setViewport( int x0, int y0 );
	void		setViewportPixel( int x, int y, int rgba4444 );

	void		loadCustom( const char* in, ImageResample* imageResamplingEngine = 0, bool halfResolution = false );
	void		saveCustom( const char* out );

	void		setFrames( int x );
	void		setFramerate( int x );
	void		setFrameWidth( int x );
	void		setFrameHeight( int x );
	void		setOffset( int x, int y );
	void		setFrameRateModifier( Fix frameRateModifier )	{m_frameRateModifier = ( frameRateModifier >= Fixf(0) ) ? frameRateModifier : Fixf(0);}
	void		setReversed( bool reversed)						{m_reversed = reversed;}
	void		setEndBehaviorStop()							{m_flags |= FLAG_END_STOP;}
	
	void		calculateEndTime();

	Surface		clipFrame( int i ) const;
	Surface		clip( int x0, int y0, int x1, int y1 ) const;
	bool		isRowEmpty( int y ) const;
	bool		isColumnEmpty( int x ) const;
	int			viewportX() const					{return m_viewportx0;}
	int			viewportY() const					{return m_viewporty0;}

	bool		mirror() const						{return m_flags & FLAG_MIRROR;}
	uint16_t	keyColor() const					{return reinterpret_cast<const uint16_t*>(m_data)[0];}
	int			frames() const						{return m_frames;}
	int			framerate() const					{return m_framerate;}
	int			frameWidth() const					{return m_framew;}
	int			frameHeight() const					{return m_frameh;}
	int			offsetX() const						{return m_offx;}
	int			offsetY() const						{return m_offy;}

	int			getPixel( int x, int y ) const;
	uint8_t*	data() const 						{return m_data;}
	int			pitch() const						{return m_pitch;}
	int			width() const						{return m_width;}
	int			height() const						{return m_height;}
	bool		isValid( const void* p ) const;
	Fix			endTime() const						{return m_endTime;}
	int			getFrame( Fix time ) const;
	Fix			frameRateModifier() const			{return m_frameRateModifier;}
	bool		reversed() const					{return m_reversed;}

private:
	uint8_t*		m_data;
	uint16_t		m_pitch;
	uint16_t		m_width;
	uint16_t		m_height;

	uint16_t		m_frames;
	uint16_t		m_framerate;
	uint16_t		m_framew;
	uint16_t		m_frameh;
	int16_t			m_offx;
	int16_t			m_offy;

	int				m_viewportx0;
	int				m_viewporty0;

	int				m_flags;

	Fix				m_endTime;
	Fix				m_frameRateModifier;
	bool			m_reversed;
};


inline int Surface::getPixel( int x, int y ) const
{
#ifdef WIN32
	assert( x >= 0 && x < (int)m_width );
	assert( y >= 0 && y < (int)m_height );
#endif
	return reinterpret_cast<uint16_t*>(m_data+m_pitch*y)[x];
}

inline void Surface::setPixel( int x, int y, int rgba4444 )
{
#ifdef WIN32
	assert( x >= 0 && x < (int)m_width );
	assert( y >= 0 && y < (int)m_height );
	assert( rgba4444 >= 0 && rgba4444 < 0x10000 );
#endif
	reinterpret_cast<uint16_t*>(m_data+m_pitch*y)[x] = (uint16_t)rgba4444;
}


#endif // _IMG_SURFACE_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -