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

📄 ddsreader.h

📁 DDS格式二次开发插件
💻 H
字号:
/*************************************************************************/
/*	File : DDSReader.h													 */
/*																		 */	
/*	DDSReader class declaration  										 */	
/*																		 */	
/*	A sample Direct Draw Surface Load/Saver using D3DX toolkit 			 */	
/*	for Directx 8														 */	
/*																		 */	
/*	Virtools SDK 														 */	 
/*	Copyright (c) Virtools 2000, All Rights Reserved.					 */	
/*************************************************************************/
#include "CKAll.h"
#include "CKBitmapReader.h"
#include "d3d8.h"


#define DDS_READER_VERSION		0x0000001
#define DDS_READER_GUID			CKGUID(0x338a39dd,0x5d0d31b5)

/****************************************************
 For this reader we add (as an option) a pixel format
 to use when saving to a file...
****************************************************/
struct DDSBitmapProperties : public CKBitmapProperties
{
	// Ctor
	DDSBitmapProperties() {
		m_Size = sizeof(DDSBitmapProperties);
		m_PixelFormat  = D3DFMT_A8R8G8B8;
	}
	// Members
	D3DFORMAT	m_PixelFormat; //
};

/***************************************************

***************************************************/
class DDSReader : public CKBitmapReader
{
public:
	// Ctor
	DDSReader();
	// Dtor
	~DDSReader();
	// Release
	void Release();
	// Reader Info
	CKPluginInfo* GetReaderInfo();

//------------------------------------------
// Our DDS Reader can Read/Save from file or memory 
// we must give these flags in case a feature is not supported
	virtual CK_DATAREADER_FLAGS GetFlags() {return (CK_DATAREADER_FLAGS) (CK_DATAREADER_FILELOAD|CK_DATAREADER_FILESAVE|CK_DATAREADER_MEMORYLOAD|CK_DATAREADER_MEMORYSAVE);}

///------------------------------------------
// Options (In our case, we can give the pixel format
// for the file being saved....)
	// Get Options Count
	int GetOptionsCount();
	// Get Options Description
	CKSTRING GetOptionDescription(int i);


///------------------------------------------
// Bitmap Properties 
	// Default Properties
	void GetBitmapDefaultProperties(CKBitmapProperties**);
	// Default Properties
	void SetBitmapDefaultProperties(CKBitmapProperties*);
	// If alpha is saved in a given format...	
	CKBOOL IsAlphaSaved(CKBitmapProperties* bp);
	
///------------------------------------------------
// Loading Functions
	
	// Synchronous Reading from file or URL
	int ReadFile(char* name,CKBitmapProperties**);
	// Synchronous Reading from memory
	int ReadMemory(void* memory,int size,CKBitmapProperties**);

// ASynchronous Reading from file or URL is not supported...
	int ReadASynchronousFile(char* name,CKBitmapProperties**) { return 0; }

///-------------------------------------------------
// Saving Functions

	// Synchronous writing to file
	int SaveFile(char* name,CKBitmapProperties*);
	// Synchronous Reading from memory, return number of bytes written
	int SaveMemory(void** memory,CKBitmapProperties*);

// Release the memory allocated by SaveMemory
	void ReleaseMemory(void* memory);

protected:
	// Default Bitmap Properties
	DDSBitmapProperties		m_Properties;

};



VX_PIXELFORMAT D3DFormatToVxPixelFormat(D3DFORMAT ddpf)
{
    switch(ddpf) {
#ifdef _XBOX
    case D3DFMT_LIN_A8R8G8B8: return _32_ARGB8888; break;
    case D3DFMT_LIN_X8R8G8B8: return _32_RGB888; break;  
    case D3DFMT_LIN_A1R5G5B5: return _16_ARGB1555; break;  
    case D3DFMT_LIN_A4R4G4B4:return _16_ARGB4444; break; 
    case D3DFMT_LIN_R5G6B5	:return _16_RGB565; break;  		
    case D3DFMT_LIN_X1R5G5B5:return _16_RGB555; break;    
#endif
#ifdef D3DFMT_R8G8B8
		case D3DFMT_R8G8B8   : return _24_RGB888; break;  
#endif
		case D3DFMT_A8R8G8B8 : return _32_ARGB8888; break;
		case D3DFMT_X8R8G8B8 : return _32_RGB888; break;  
		case D3DFMT_R5G6B5   : return _16_RGB565; break;  
		case D3DFMT_X1R5G5B5 : return _16_RGB555; break;  
		case D3DFMT_A1R5G5B5 : return _16_ARGB1555; break;  
		case D3DFMT_A4R4G4B4 : return _16_ARGB4444; break;  
#ifdef D3DFMT_R3G3B2		
		case D3DFMT_R3G3B2   : return _8_RGB332; break;  
#endif
#ifdef D3DFMT_X4R4G4B4
		case D3DFMT_X4R4G4B4 : return _16_ARGB4444; break;  
#endif
		case D3DFMT_DXT1     : return _DXT1; break;  
#ifndef _XBOX
		case D3DFMT_DXT2     : return _DXT2; break;  
#endif
		case D3DFMT_DXT3     : return _DXT3; break;  
#ifndef _XBOX
		case D3DFMT_DXT4     : return _DXT4; break;  
#endif
		case D3DFMT_DXT5     : return _DXT5; break;

		case D3DFMT_V8U8   : return _16_V8U8; break;  
		case D3DFMT_V16U16 : return _32_V16U16; break;  
		case D3DFMT_L6V5U5 : return _16_L6V5U5; break;  
#ifndef _XBOX
		case D3DFMT_X8L8V8U8 : return _32_X8L8V8U8; break;  			
#endif
	}
	return UNKNOWN_PF;
}

D3DFORMAT VxPixelFormatToD3DFormat(VX_PIXELFORMAT pf)
{
    switch(pf) {
#ifdef D3DFMT_R8G8B8
		case _24_RGB888		: return D3DFMT_R8G8B8    	; break  ;
#else
		case _24_RGB888		: return D3DFMT_X8R8G8B8   	; break  ;
#endif 
		case _32_ARGB8888	: return D3DFMT_A8R8G8B8  	; break;
		case _32_RGB888		: return D3DFMT_X8R8G8B8  	; break  ;
		case _16_RGB565		: return D3DFMT_R5G6B5    	; break  ;
		case _16_RGB555		: return D3DFMT_X1R5G5B5  	; break  ;
		case _16_ARGB1555	: return D3DFMT_A1R5G5B5  	; break  ;
		case _16_ARGB4444	: return D3DFMT_A4R4G4B4  	; break  ;
#ifdef _8_RGB332
		case _8_RGB332		: return D3DFMT_R3G3B2    	; break  ;
#else
		case _8_RGB332		: return D3DFMT_A4R4G4B4   	; break  ;
		case _8_ARGB2222	: return D3DFMT_A4R4G4B4   	; break  ;

#endif
		case _DXT1			: return D3DFMT_DXT1      	; break  ;
		case _DXT2			: return D3DFMT_DXT2      	; break  ;
		case _DXT3			: return D3DFMT_DXT3      	; break  ;
		case _DXT4			: return D3DFMT_DXT4      	; break  ;
		case _DXT5			: return D3DFMT_DXT5      	; break;

		case _16_V8U8		: return D3DFMT_V8U8;		break;  
		case _32_V16U16		: return D3DFMT_V16U16;		break;  
		case _16_L6V5U5		: return D3DFMT_L6V5U5;		break;  
		case _32_X8L8V8U8	: return D3DFMT_X8L8V8U8;	break;  	
	}
	return D3DFMT_UNKNOWN;
}

⌨️ 快捷键说明

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