1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

GLideNUI-wtl: Generate Screen shot

This commit is contained in:
zilmar 2020-04-13 11:39:54 +09:30 committed by Sergey Lipskiy
parent 02fcbf9b88
commit 6c4b18266e
4 changed files with 116 additions and 12 deletions

Binary file not shown.

View File

@ -1,6 +1,122 @@
#include "GLideNUI.h"
#include "../Config.h"
#include "util.h"
#include <Windows.h>
#include "../GLideNHQ/inc/png.h"
void write_png_file(const wchar_t * file_name, int width, int height, const uint8_t *buffer)
{
#pragma warning(disable: 4996)
FILE *fp = _wfopen(file_name, L"wb");
#pragma warning(default: 4996)
if (!fp) return;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(fp);
return;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(fp);
return;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return;
}
png_init_io(png_ptr, fp);
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return;
}
png_byte bit_depth = 8;
png_byte color_type = PNG_COLOR_TYPE_RGB;
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return;
}
int pixel_size = 3;
int p = 0;
png_bytep * row_pointers = (png_bytep*)malloc(sizeof(png_bytep)* height);
for (int y = height - 1; y >= 0; y--) {
row_pointers[y] = (png_byte*)malloc(width*pixel_size);
for (int x = 0; x < width; x++) {
row_pointers[y][x*pixel_size + 0] = buffer[p++];
row_pointers[y][x*pixel_size + 1] = buffer[p++];
row_pointers[y][x*pixel_size + 2] = buffer[p++];
}
}
png_write_image(png_ptr, row_pointers);
for (int y = 0; y < height; y++) {
free(row_pointers[y]);
}
free(row_pointers);
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return;
}
png_write_end(png_ptr, NULL);
fclose(fp);
}
EXPORT void CALL SaveScreenshot(const wchar_t * _folder, const char * _name, int _width, int _height, const unsigned char * _data)
{
const wchar_t * fileExt = L"png";
std::wstring folder = _folder;
if (folder.size() > 1 && folder[folder.size() - 1] == L'\\') folder.resize(folder.size() - 1);
WIN32_FIND_DATA FindData = { 0 };
HANDLE hFindFile = FindFirstFile(folder.c_str(), &FindData); // Find anything
if (hFindFile == INVALID_HANDLE_VALUE) {
::CreateDirectory(folder.c_str(), NULL);
hFindFile = FindFirstFile(folder.c_str(), &FindData);
}
if (hFindFile != INVALID_HANDLE_VALUE)
FindClose(hFindFile);
if ((FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
return;
std::wstring romName = ToUTF16(_name);
for (size_t i = 0, n = romName.size(); i < n; i++) {
if (romName[i] == L' ') romName[i] = L'_';
if (romName[i] == L':') romName[i] = L';';
}
wchar_t fileName[MAX_PATH];
int i;
for (i = 0; i < 1000; ++i) {
#pragma warning(disable: 4996)
swprintf(fileName, L"%ls\\GLideN64_%ls_%03i.%s", folder.c_str(), romName.c_str(), i, fileExt);
#pragma warning(default: 4996)
hFindFile = FindFirstFile(fileName, &FindData);
if (hFindFile == INVALID_HANDLE_VALUE)
{
break;
}
FindClose(hFindFile);
}
if (i == 1000)
return;
write_png_file(fileName, _width, _height, _data);
}

View File

@ -247,9 +247,6 @@ void CVideoTab::LoadSettings(bool /*blockCustomSettings*/)
CButton(GetDlgItem(IDC_BILINEAR_3POINT)).SetCheck(config.texture.bilinearMode == BILINEAR_3POINT ? BST_CHECKED : BST_UNCHECKED);
CButton(GetDlgItem(IDC_BILINEAR_STANDARD)).SetCheck(config.texture.bilinearMode == BILINEAR_STANDARD ? BST_CHECKED : BST_UNCHECKED);
CButton(GetDlgItem(IDC_SCREENSHOT_PNG)).SetCheck(config.texture.screenShotFormat == 0 ? BST_CHECKED : BST_UNCHECKED);
CButton(GetDlgItem(IDC_SCREENSHOT_JPEG)).SetCheck(config.texture.screenShotFormat == 1 ? BST_CHECKED : BST_UNCHECKED);
CComboBox aspectComboBox(GetDlgItem(IDC_CMB_ASPECT_RATIO));
switch (config.frameBufferEmulation.aspect)
{
@ -335,15 +332,6 @@ void CVideoTab::SaveSettings()
config.texture.bilinearMode = BILINEAR_STANDARD;
}
if (CButton(GetDlgItem(IDC_SCREENSHOT_PNG)).GetCheck() == BST_CHECKED)
{
config.texture.screenShotFormat = 0;
}
else if (CButton(GetDlgItem(IDC_SCREENSHOT_JPEG)).GetCheck() == BST_CHECKED)
{
config.texture.screenShotFormat = 1;
}
config.generalEmulation.rdramImageDitheringMode = CComboBox(GetDlgItem(IDC_CMB_PATTERN)).GetCurSel();
config.generalEmulation.enableDitheringPattern = CButton(GetDlgItem(IDC_CHK_APPLY_TO_OUTPUT)).GetCheck() == BST_CHECKED ? 1 : 0;
config.generalEmulation.enableDitheringQuantization = CButton(GetDlgItem(IDC_CHK_5BIT_QUANTIZATION)).GetCheck() == BST_CHECKED ? 1 : 0;

Binary file not shown.