From 18f02cb7d30808ec75e06187ac719e146f91418f Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 23 Jul 2017 20:41:30 -0500 Subject: [PATCH] winport - fix screenshot, aviout bugs due to 888 colorspace change --- desmume/src/frontend/modules/ImageOut.cpp | 10 ++++++++-- desmume/src/frontend/modules/ImageOut.h | 6 +++++- desmume/src/frontend/windows/aviout.cpp | 14 +++++++------- desmume/src/frontend/windows/hotkey.cpp | 13 ++++++++++--- desmume/src/frontend/windows/main.cpp | 16 ++++++++++------ 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/desmume/src/frontend/modules/ImageOut.cpp b/desmume/src/frontend/modules/ImageOut.cpp index 77d4aa294..f7c5e56df 100644 --- a/desmume/src/frontend/modules/ImageOut.cpp +++ b/desmume/src/frontend/modules/ImageOut.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2008-2015 DeSmuME team + Copyright (C) 2008-2017 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -56,8 +56,14 @@ int NDS_WriteBMP_15bpp(int width, int height, const u16 *data, const char *filen return ok?1:0; } +int NDS_WritePNG_32bppBuffer(int width, int height, const void* buf, const char *filename) +{ + bool ok = rpng_save_image_argb(filename, (const uint32_t*)buf, width, height, width * 4); + return ok ? 1 : 0; +} + int NDS_WriteBMP_32bppBuffer(int width, int height, const void* buf, const char *filename) { - bool ok = rbmp_save_image(filename,buf,width,height,width*4,RBMP_SOURCE_TYPE_ARGB8888); + bool ok = rbmp_save_image(filename,buf,width,height,width*4,(rbmp_source_type)(RBMP_SOURCE_TYPE_ARGB8888 | RBMP_SOURCE_TYPE_YFLIPPED)); return ok?1:0; } \ No newline at end of file diff --git a/desmume/src/frontend/modules/ImageOut.h b/desmume/src/frontend/modules/ImageOut.h index 3bdafd0ba..206a16155 100644 --- a/desmume/src/frontend/modules/ImageOut.h +++ b/desmume/src/frontend/modules/ImageOut.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 DeSmuME team + Copyright (C) 2015-2017 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,8 +20,12 @@ #include "types.h" +u8* Convert15To24(const u16* src, int width, int height); +u8* Convert32To32SwapRB(const void* src, int width, int height); + int NDS_WritePNG_15bpp(int width, int height, const u16 *data, const char *fname); int NDS_WriteBMP_15bpp(int width, int height, const u16 *data, const char *filename); +int NDS_WritePNG_32bppBuffer(int width, int height, const void* buf, const char *filename); int NDS_WriteBMP_32bppBuffer(int width, int height, const void* buf, const char *filename); #endif \ No newline at end of file diff --git a/desmume/src/frontend/windows/aviout.cpp b/desmume/src/frontend/windows/aviout.cpp index d15d1d6e2..9d70f9977 100644 --- a/desmume/src/frontend/windows/aviout.cpp +++ b/desmume/src/frontend/windows/aviout.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2006-2015 DeSmuME team + Copyright (C) 2006-2017 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -310,8 +310,8 @@ static int avi_open(const char* filename, const BITMAPINFOHEADER* pbmih, const W return result; } -//converts 16bpp to 24bpp and flips -static void do_video_conversion(AVIFile* avi, const u16* buffer) +//converts 32bpp to 24bpp and flips +static void do_video_conversion(AVIFile* avi, const u32* buffer) { int width = avi->prescaleLevel*256; int height = avi->prescaleLevel*384; @@ -321,10 +321,10 @@ static void do_video_conversion(AVIFile* avi, const u16* buffer) { for (int x = 0; x < width; x++) { - u32 dst = ColorspaceConvert555To8888Opaque(*buffer++); - *outbuf++ = dst & 0xFF; - *outbuf++ = (dst >> 8) & 0xFF; + u32 dst = *buffer++; *outbuf++ = (dst >> 16) & 0xFF; + *outbuf++ = (dst >> 8) & 0xFF; + *outbuf++ = dst & 0xFF; } outbuf -= width*3*2; @@ -418,7 +418,7 @@ void DRV_AviVideoUpdate() return; const NDSDisplayInfo& dispInfo = GPU->GetDisplayInfo(); - const u16* buffer = (const u16 *)dispInfo.masterCustomBuffer; + const u32* buffer = (const u32 *)dispInfo.masterCustomBuffer; //dont do anything if prescale has changed, it's just going to be garbage if(video.prescaleHD != avi_file->prescaleLevel) diff --git a/desmume/src/frontend/windows/hotkey.cpp b/desmume/src/frontend/windows/hotkey.cpp index 49a42ae30..c295a5de1 100644 --- a/desmume/src/frontend/windows/hotkey.cpp +++ b/desmume/src/frontend/windows/hotkey.cpp @@ -164,15 +164,22 @@ void HK_QuickScreenShot(int param, bool justPressed) switch(path.imageformat()) { case path.PNG: - { + { strcat(fname, ".png"); - NDS_WritePNG_15bpp(dispInfo.customWidth, dispInfo.customHeight*2, (const u16*)dispInfo.masterCustomBuffer, fname); + u32* swapbuf = (u32*)malloc_alignedCacheLine(dispInfo.customWidth * dispInfo.customHeight * 2 * 4); + ColorspaceConvertBuffer888XTo8888Opaque((const u32*)dispInfo.masterCustomBuffer, swapbuf, dispInfo.customWidth * dispInfo.customHeight * 2); + free_aligned(swapbuf); + NDS_WritePNG_32bppBuffer(dispInfo.customWidth, dispInfo.customHeight*2, swapbuf, fname); + free_aligned(swapbuf); } break; case path.BMP: { strcat(fname, ".bmp"); - NDS_WriteBMP_15bpp(dispInfo.customWidth, dispInfo.customHeight *2, (const u16*)dispInfo.masterCustomBuffer, fname); + u32* swapbuf = (u32*)malloc_alignedCacheLine(dispInfo.customWidth * dispInfo.customHeight * 2 * 4); + ColorspaceConvertBuffer888XTo8888Opaque((const u32*)dispInfo.masterCustomBuffer, swapbuf, dispInfo.customWidth * dispInfo.customHeight * 2); + NDS_WriteBMP_32bppBuffer(dispInfo.customWidth, dispInfo.customHeight *2, swapbuf, fname); + free_aligned(swapbuf); } break; } diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 4e17c9a0f..ba982da1d 100644 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -88,6 +88,7 @@ #include "frontend/modules/osd/agg/agg_osd.h" #include "frontend/modules/osd/agg/aggdraw.h" #include "frontend/modules/osd/agg/agg2d.h" +#include "frontend/modules/ImageOut.h" #include "winutil.h" #include "ogl.h" @@ -4224,16 +4225,19 @@ void ScreenshotToClipboard(bool extraInfo) memset(&bmi, 0, sizeof(bmi)); bmi.bV4Size = sizeof(bmi); bmi.bV4Planes = 1; - bmi.bV4BitCount = 16; - bmi.bV4V4Compression = BI_RGB | BI_BITFIELDS; - bmi.bV4RedMask = 0x001F; - bmi.bV4GreenMask = 0x03E0; - bmi.bV4BlueMask = 0x7C00; + bmi.bV4BitCount = 32; + bmi.bV4V4Compression = BI_RGB; bmi.bV4Width = width; bmi.bV4Height = -height; + + u32* swapbuf = (u32*)malloc_alignedCacheLine(width*height*4); + ColorspaceConvertBuffer888XTo8888Opaque((const u32*)dispInfo.masterCustomBuffer, swapbuf, width * height); + FillRect(hMemDC, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH)); - SetDIBitsToDevice(hMemDC, 0, 0, width, height, 0, 0, 0, height, dispInfo.masterCustomBuffer, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + SetDIBitsToDevice(hMemDC, 0, 0, width, height, 0, 0, 0, height, swapbuf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + + free_aligned(swapbuf); //center-justify the extra text int xo = (width - 256)/2;