add colorSwizzle when blit is no supported

ink-soul 2024-03-29 11:04:47 +08:00
parent 58749f5791
commit 4d4c55f0ac
5 changed files with 1788 additions and 24 deletions

View File

@ -13,6 +13,7 @@ include_directories(external/tinygltf)
include_directories(external/ktx/include)
include_directories(external/ktx/other_include)
include_directories(external/toml11)
include_directories(external/stb)
include_directories(base)
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)

View File

@ -119,7 +119,7 @@ public:
bool multiSampling = true; // 多重采样
bool rotateModel = true; // 模型自旋转(暂时失效)
bool headless = false; // 无头开关
bool outputPNGimage = true; // 输出图片序列格式为PNG四通道
bool enableSaveToImageSequeue = false; // 图片序列开关(暂时弃用)
uint32_t outputFrameCount = 75; // 图片序列结束帧
bool takeScreenShot = false; // 截屏(暂时弃用)

1724
external/stb/stb_image_write.h vendored 100644

File diff suppressed because it is too large Load Diff

View File

@ -1756,11 +1756,6 @@ 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
@ -1771,28 +1766,69 @@ PlumageRender::PlumageRender()
colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end());
}
// ppm binary pixel data
for (uint32_t y = 0; y < height; y++)
if (settings.outputPNGimage)
{
unsigned int* row = (unsigned int*)data;
for (uint32_t x = 0; x < width; x++)
if (colorSwizzle)
{
if (colorSwizzle)
uint8_t* pixels = new uint8_t[width * height * 4];
uint32_t index = 0;
for (uint32_t j = height - 1; j >= 0; j--)
{
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();
unsigned int* row = (unsigned int*)data;
for (int i = 0; i < width; ++i)
{
float r = (float)i / (float)width;
float g = (float)j / (float)height;
float b = 0.2f;
int ir = int(255.99 * r);
int ig = int(255.99 * g);
int ib = int(255.99 * b);
pixels[index++] = ir;
pixels[index++] = ig;
pixels[index++] = ib;
}
}
stbi_write_png(filePath.c_str(), width, height, 4, pixels, static_cast<int>(subResourceLayout.rowPitch));
}
else
{
stbi_write_png(filePath.c_str(), width, height, 4, data, static_cast<int>(subResourceLayout.rowPitch));
}
}
else
{
std::ofstream file(filePath, std::ios::out | std::ios::binary);
// ppm header
file << "P6\n" << width << "\n" << height << "\n" << 255 << "\n";
// 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();
}
std::cout << "Screenshot saved to " << filePath << std::endl;
// Clean up resources

View File

@ -24,6 +24,9 @@
#include "ui.hpp"
#include <VulkanUtils.hpp>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define ENABLE_VALIDATION false