添加输出图片为png格式的支持
							parent
							
								
									aff5dee7d4
								
							
						
					
					
						commit
						6e34140783
					
				| 
						 | 
				
			
			@ -9,6 +9,7 @@ include_directories(external)
 | 
			
		|||
include_directories(external/glm)
 | 
			
		||||
include_directories(external/gli)
 | 
			
		||||
include_directories(external/imgui)
 | 
			
		||||
include_directories(external/stb)
 | 
			
		||||
include_directories(external/tinygltf)
 | 
			
		||||
include_directories(external/ktx/include)
 | 
			
		||||
include_directories(external/ktx/other_include)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -119,7 +119,7 @@ public:
 | 
			
		|||
		bool multiSampling = true; // 多重采样
 | 
			
		||||
		bool rotateModel = true; // 模型自旋转(暂时失效)
 | 
			
		||||
		bool headless = false; // 无头开关
 | 
			
		||||
 | 
			
		||||
		bool outputPNGimage = true;
 | 
			
		||||
		bool enableSaveToImageSequeue = false; // 图片序列开关(暂时弃用)
 | 
			
		||||
		uint32_t outputFrameCount = 75; // 图片序列结束帧
 | 
			
		||||
		bool takeScreenShot = false; // 截屏(暂时弃用)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -1755,42 +1755,55 @@ PlumageRender::PlumageRender()
 | 
			
		|||
		vkMapMemory(device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (void**)&data);
 | 
			
		||||
		data += subResourceLayout.offset;
 | 
			
		||||
 | 
			
		||||
		std::ofstream file(filePath, std::ios::out | std::ios::binary);
 | 
			
		||||
 | 
			
		||||
		// ppm header
 | 
			
		||||
		file << "P6\n" << width << "\n" << height << "\n" << 255 << "\n";
 | 
			
		||||
 | 
			
		||||
		// If source is BGR (destination is always RGB) and we can't use blit (which does automatic conversion), we'll have to manually swizzle color components
 | 
			
		||||
		bool colorSwizzle = false;
 | 
			
		||||
		// Check if source is BGR
 | 
			
		||||
		// Note: Not complete, only contains most common and basic BGR surface formats for demonstration purposes
 | 
			
		||||
		if (!supportsBlit)
 | 
			
		||||
		if (settings.outputPNGimage)
 | 
			
		||||
		{
 | 
			
		||||
			std::vector<VkFormat> formatsBGR = { VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_SNORM };
 | 
			
		||||
			colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end());
 | 
			
		||||
			stbi_write_png(filePath.c_str(), width, height, 4, data, static_cast<int>(subResourceLayout.rowPitch));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// ppm binary pixel data
 | 
			
		||||
		for (uint32_t y = 0; y < height; y++)
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			unsigned int* row = (unsigned int*)data;
 | 
			
		||||
			for (uint32_t x = 0; x < width; x++)
 | 
			
		||||
 | 
			
		||||
			std::ofstream file(filePath, std::ios::out | std::ios::binary);
 | 
			
		||||
 | 
			
		||||
			// ppm header
 | 
			
		||||
			file << "P6\n" << width << "\n" << height << "\n" << 255 << "\n";
 | 
			
		||||
 | 
			
		||||
			// If source is BGR (destination is always RGB) and we can't use blit (which does automatic conversion), we'll have to manually swizzle color components
 | 
			
		||||
			bool colorSwizzle = false;
 | 
			
		||||
			// Check if source is BGR
 | 
			
		||||
			// Note: Not complete, only contains most common and basic BGR surface formats for demonstration purposes
 | 
			
		||||
			if (!supportsBlit)
 | 
			
		||||
			{
 | 
			
		||||
				if (colorSwizzle)
 | 
			
		||||
				{
 | 
			
		||||
					file.write((char*)row + 2, 1);
 | 
			
		||||
					file.write((char*)row + 1, 1);
 | 
			
		||||
					file.write((char*)row, 1);
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					file.write((char*)row, 3);
 | 
			
		||||
				}
 | 
			
		||||
				row++;
 | 
			
		||||
				std::vector<VkFormat> formatsBGR = { VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_SNORM };
 | 
			
		||||
				colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end());
 | 
			
		||||
			}
 | 
			
		||||
			data += subResourceLayout.rowPitch;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
			// ppm binary pixel data
 | 
			
		||||
			for (uint32_t y = 0; y < height; y++)
 | 
			
		||||
			{
 | 
			
		||||
				unsigned int* row = (unsigned int*)data;
 | 
			
		||||
				for (uint32_t x = 0; x < width; x++)
 | 
			
		||||
				{
 | 
			
		||||
					if (colorSwizzle)
 | 
			
		||||
					{
 | 
			
		||||
						file.write((char*)row + 2, 1);
 | 
			
		||||
						file.write((char*)row + 1, 1);
 | 
			
		||||
						file.write((char*)row, 1);
 | 
			
		||||
					}
 | 
			
		||||
					else
 | 
			
		||||
					{
 | 
			
		||||
						file.write((char*)row, 3);
 | 
			
		||||
					}
 | 
			
		||||
					row++;
 | 
			
		||||
				}
 | 
			
		||||
				data += subResourceLayout.rowPitch;
 | 
			
		||||
			}
 | 
			
		||||
			file.close();
 | 
			
		||||
		}
 | 
			
		||||
		file.close();
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
		std::cout << "Screenshot saved to " << filePath << std::endl;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1821,7 +1834,18 @@ PlumageRender::PlumageRender()
 | 
			
		|||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			signal.imageSequenceOutputComplete = true;
 | 
			
		||||
			std::string fileName = "/%dresult.ppm";
 | 
			
		||||
 | 
			
		||||
			std::string fileName;
 | 
			
		||||
 | 
			
		||||
			if (settings.outputPNGimage)
 | 
			
		||||
			{
 | 
			
		||||
				fileName = "/%dresult.png";
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				fileName = "/%dresult.ppm";
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			filePath.totalImageOutputPath = filePath.deviceSpecFilePath + fileName;
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -1829,7 +1853,16 @@ PlumageRender::PlumageRender()
 | 
			
		|||
		{
 | 
			
		||||
			std::filesystem::create_directories(filePath.deviceSpecFilePath.c_str());
 | 
			
		||||
		}
 | 
			
		||||
		std::string fileName ="/" + std::to_string(savedFrameCounter) + "result.ppm";
 | 
			
		||||
		std::string fileNameSuffix;
 | 
			
		||||
		if (settings.outputPNGimage)
 | 
			
		||||
		{
 | 
			
		||||
			fileNameSuffix = "result.png";
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			fileNameSuffix = "dresult.ppm";
 | 
			
		||||
		}
 | 
			
		||||
		std::string fileName ="/" + std::to_string(savedFrameCounter) + fileNameSuffix;
 | 
			
		||||
		filePath.totalImageOutputPath = filePath.deviceSpecFilePath + fileName;
 | 
			
		||||
		//std::cout << outputPath << std::endl;
 | 
			
		||||
		writeImageToFile(filePath.totalImageOutputPath.c_str());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,9 @@
 | 
			
		|||
#include<dirent.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
 | 
			
		||||
#include "stb/stb_image_write.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue