GE Debugger: Copy images optionally with alpha.

Although, lots of apps don't support this.
This commit is contained in:
Unknown W. Brackets committed 2022-09-24 11:43:52 -07:00
1 parent f3722faef4
commit 3cc628beb4
8 files changed
+158 -45

No files matched your search

+28 -2
View File
@@ -406,8 +406,7 @@ bool Save888RGBScreenshot(const Path &filename, ScreenshotFormat fmt, const u8 *
}
bool Save8888RGBAScreenshot(const Path &filename, const u8 *buffer, int w, int h) {
png_image png;
memset(&png, 0, sizeof(png));
png_image png{};
png.version = PNG_IMAGE_VERSION;
png.format = PNG_FORMAT_RGBA;
png.width = w;
@@ -421,3 +420,30 @@ bool Save8888RGBAScreenshot(const Path &filename, const u8 *buffer, int w, int h
}
return success;
}
bool Save8888RGBAScreenshot(std::vector<uint8_t> &bufferPNG, const u8 *bufferRGBA8888, int w, int h) {
png_image png{};
png.version = PNG_IMAGE_VERSION;
png.format = PNG_FORMAT_RGBA;
png.width = w;
png.height = h;
png_alloc_size_t allocSize = bufferPNG.size();
int result = png_image_write_to_memory(&png, allocSize == 0 ? nullptr : bufferPNG.data(), &allocSize, 0, bufferRGBA8888, w * 4, nullptr);
bool success = result != 0 && png.warning_or_error <= 1;
if (!success && allocSize != bufferPNG.size()) {
bufferPNG.resize(allocSize);
png.warning_or_error = 0;
result = png_image_write_to_memory(&png, bufferPNG.data(), &allocSize, 0, bufferRGBA8888, w * 4, nullptr);
success = result != 0 && png.warning_or_error <= 1;
}
if (success)
bufferPNG.resize(allocSize);
png_image_free(&png);
if (!success) {
ERROR_LOG(IO, "Buffering screenshot to PNG produced errors.");
bufferPNG.clear();
}
return success;
}