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

📄 pfs.cpp

📁 光滑质点无网格法SPH并行计算程序
💻 CPP
字号:
//      ___                       ___           ___           ___       ___     //     /\__\          ___        /\__\         /\  \         /\__\     /\  \.    //    /::|  |        /\  \      /::|  |       /::\  \       /:/  /    /::\  \.   //   /:|:|  |        \:\  \    /:|:|  |      /:/\:\  \     /:/  /    /:/\:\  \.  //  /:/|:|__|__      /::\__\  /:/|:|  |__   /:/  \:\  \   /:/  /    /::\~\:\  \. // /:/ |::::\__\  __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/    /:/\:\ \:\__\.// \/__/~~/:/  / /\/:/  /    \/__|:|/:/  / \:\  /\ \/__/ \:\  \    \:\~\:\ \/__///       /:/  /  \::/__/         |:/:/  /   \:\ \:\__\    \:\  \    \:\ \:\__\.  //      /:/  /    \:\__\         |::/  /     \:\/:/  /     \:\  \    \:\ \/__/  //     /:/  /      \/__/         /:/  /       \::/  /       \:\__\    \:\__\.    //     \/__/                     \/__/         \/__/         \/__/     \/__/    // // =============================================================================//                       Minimalist OpenGL Environment// =============================================================================//// This file is part of Minimalist OpenGL Environment (MinGLE)//// Version: 0.2.0// Author: Balazs Domonkos// Filename: src/misc-formats/src/pfs.cpp// Creation Date: December 12th 2007// Revision Date: December 12th 2007////// The Minimalist OpenGL Environment is free software: you can// redistribute it and/or modify it under the terms of the GNU// General Public License as published by the Free Software// Foundation, either version 3 of the License, or (at your// option) any later version.//// The Minimalist OpenGL Environment is distributed in the hope// that it will be useful, but WITHOUT ANY WARRANTY; without// even the implied warranty of MERCHANTABILITY or FITNESS FOR// A PARTICULAR PURPOSE. See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License// along with Minimalist OpenGL Environment.  If not, see // <http://www.gnu.org/licenses/>. See the COPYING file included // with this distribution file for license details.///// @file pfs.cpp/// PFS high dynamic range image format support for Devil Image library// Header that contains the declaration#include <misc-formats/include/pfs.h>// MinGLE headers#include <Exception.h>#if MINGLE_PFS_SUPPORT == 1// System headers#include <list>#include <utility>#include <string>namespace MinGLE {	static unsigned getNumberOfChannels() {		// Note: ilGetInteger(IL_IMAGE_CHANNELS) is buggy:		//ILint channels = ilGetInteger(IL_IMAGE_CHANNELS);		ILint format = ilGetInteger(IL_IMAGE_FORMAT);		switch(format) {			case IL_COLOR_INDEX:			Except("getNumberOfChannels", "Indexed images are not supported");			case IL_LUMINANCE:			return 1;			case IL_LUMINANCE_ALPHA:			return 2;			case IL_RGB: case IL_BGR:			return 3;			case IL_RGBA: case IL_BGRA:			return 4;			break;			default:			Except("getNumberOfChannels", "Invalid image format");		}		return 0;	}	static void writeData(FILE *fp, float *data, float *tmpData, const unsigned sizeofChannel, const unsigned channels) {		float *pend = data + channels*sizeofChannel;		for(unsigned i=0; i<channels; i++) {			// Collect the specified channel from the interleaved data to continous memory area 			float *p = data+i;			for(float *ptmp=tmpData; p<pend; p+=channels, ptmp++)			*ptmp = *p;			// Write channel			fwrite(tmpData, sizeofChannel, sizeof(float), fp);		}	}	ILenum loadPFS(const ILstring filename) {		Except("loadPFS", "TODO: implement");		return true;	}	ILenum savePFS(const ILstring filename) {		// Open the file		FILE *fp = fopen(filename, "wb");		Assert(fp, "savePFS");		// Get image info		ILinfo ilInfo;		iluGetImageInfo(&ilInfo);		unsigned channels = getNumberOfChannels();		// Image is needed to be flipped		iluFlipImage();		// Convert image to floating point type		if(ilInfo.Type != IL_FLOAT)		ilConvertImage(ilInfo.Format, IL_FLOAT);		// Write header		fprintf(fp, "PFS1\n");		fprintf(fp, "%d %d\n", ilInfo.Width, ilInfo.Height);		fprintf(fp, "%d\n", channels);		fprintf(fp, "1\n"); // frameTagCount		fprintf(fp, "LUMINANCE=RELATIVE\n"); // Uncalibrated luminance		const char channelNames[] = "XYZA";		for(unsigned i=0; i<channels; i++) {			fprintf(fp, "%c\n", channelNames[i]);			fprintf(fp, "0\n");		}		fprintf(fp, "ENDH");		// Create temporary memory for one channel		size_t channelSize = ilInfo.Width*ilInfo.Height;		float *tmpData = (float *) malloc(channelSize * sizeof(float));		// Write data		writeData(fp, (float *) ilGetData(), tmpData, channelSize, channels);		// Close the file		fclose(fp);		// Deallocate temporary memory		free(tmpData);		return true;	}} // namespace MinGLE#endif // MINGLE_PFS_SUPPORT == 1

⌨️ 快捷键说明

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