Correct BMP creation on Linux (PR #1014)

Enable BMP Header packing on all compilers.
Add virtual function to FrameBase to select where to save screenshots.
This commit is contained in:
Andrea 2022-01-03 14:41:03 +00:00 committed by GitHub
parent a243efc74b
commit d63e406573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 17 deletions

View File

@ -121,9 +121,9 @@ void FrameBase::Video_SaveScreenShot(const Video::VideoScreenShot_e ScreenShotTy
void FrameBase::Util_MakeScreenShotFileName(TCHAR* pFinalFileName_, DWORD chars) void FrameBase::Util_MakeScreenShotFileName(TCHAR* pFinalFileName_, DWORD chars)
{ {
const std::string sPrefixScreenShotFileName = "AppleWin_ScreenShot"; const std::string sPrefixScreenShotFileName = "AppleWin_ScreenShot";
// TODO: g_sScreenshotDir
const std::string pPrefixFileName = !g_pLastDiskImageName.empty() ? g_pLastDiskImageName : sPrefixScreenShotFileName; const std::string pPrefixFileName = !g_pLastDiskImageName.empty() ? g_pLastDiskImageName : sPrefixScreenShotFileName;
StringCbPrintf(pFinalFileName_, chars, TEXT("%s_%09d.bmp"), pPrefixFileName.c_str(), g_nLastScreenShot); const std::string folder = Video_GetScreenShotFolder();
StringCbPrintf(pFinalFileName_, chars, TEXT("%s%s_%09d.bmp"), folder.c_str(), pPrefixFileName.c_str(), g_nLastScreenShot);
} }
// Returns TRUE if file exists, else FALSE // Returns TRUE if file exists, else FALSE

View File

@ -56,6 +56,7 @@ public:
void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame); void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame);
void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename); void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename);
virtual std::string Video_GetScreenShotFolder() = 0;
void Video_TakeScreenShot(const Video::VideoScreenShot_e ScreenShotType); void Video_TakeScreenShot(const Video::VideoScreenShot_e ScreenShotType);
void Video_SaveScreenShot(const Video::VideoScreenShot_e ScreenShotType, const TCHAR* pScreenShotFileName); void Video_SaveScreenShot(const Video::VideoScreenShot_e ScreenShotType, const TCHAR* pScreenShotFileName);
void SetDisplayPrintScreenFileName(bool state) { g_bDisplayPrintScreenFileName = state; } void SetDisplayPrintScreenFileName(bool state) { g_bDisplayPrintScreenFileName = state; }

View File

@ -509,7 +509,7 @@ void Video::Video_SetBitmapHeader(WinBmpHeader_t *pBmp, int nWidth, int nHeight,
void Video::Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShotType) void Video::Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShotType)
{ {
WinBmpHeader_t *pBmp = &g_tBmpHeader; WinBmpHeader_t bmp, *pBmp = &bmp;
Video_SetBitmapHeader( Video_SetBitmapHeader(
pBmp, pBmp,
@ -518,8 +518,13 @@ void Video::Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShot
32 32
); );
char sIfSizeZeroOrUnknown_BadWinBmpHeaderPackingSize54[ sizeof( WinBmpHeader_t ) == (14 + 40) ]; #define EXPECTED_BMP_HEADER_SIZE (14 + 40)
#ifdef _MSC_VER
char sIfSizeZeroOrUnknown_BadWinBmpHeaderPackingSize54[ sizeof( WinBmpHeader_t ) == EXPECTED_BMP_HEADER_SIZE];
/**/ sIfSizeZeroOrUnknown_BadWinBmpHeaderPackingSize54[0]=0; /**/ sIfSizeZeroOrUnknown_BadWinBmpHeaderPackingSize54[0]=0;
#else
static_assert(sizeof( WinBmpHeader_t ) == EXPECTED_BMP_HEADER_SIZE, "BadWinBmpHeaderPackingSize");
#endif
// Write Header // Write Header
fwrite( pBmp, sizeof( WinBmpHeader_t ), 1, pFile ); fwrite( pBmp, sizeof( WinBmpHeader_t ), 1, pFile );
@ -575,6 +580,11 @@ void Video::Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShot
pSrc += GetFrameBufferWidth(); pSrc += GetFrameBufferWidth();
} }
} }
// re-write the Header to include the file size (otherwise "file" does not recognise it)
pBmp->nSizeFile = ftell(pFile);
rewind(pFile);
fwrite( pBmp, sizeof( WinBmpHeader_t ), 1, pFile );
} }
//=========================================================================== //===========================================================================

View File

@ -82,13 +82,9 @@ enum AppleFont_e
APPLE_FONT_Y_APPLE_40COL = 512, // ][ APPLE_FONT_Y_APPLE_40COL = 512, // ][
}; };
#ifdef _MSC_VER
// turn of MSVC struct member padding // turn on struct member padding
#pragma pack(push,1) #pragma pack(push,1)
#define PACKED
#else
#define PACKED // TODO: FIXME: gcc/clang __attribute__
#endif
// TODO: Replace with WinGDI.h / RGBQUAD // TODO: Replace with WinGDI.h / RGBQUAD
struct bgra_t struct bgra_t
@ -174,10 +170,7 @@ struct WinBmpHeader4_t
uint32_t nBlueGamma ; // 0x76 0x04 uint32_t nBlueGamma ; // 0x76 0x04
}; };
#ifdef _MSC_VER #pragma pack(pop)
#pragma pack(pop)
#endif
// //
class Video class Video
@ -298,8 +291,6 @@ private:
COLORREF g_nMonochromeRGB; // saved to Registry COLORREF g_nMonochromeRGB; // saved to Registry
bool m_hasVidHD; bool m_hasVidHD;
WinBmpHeader_t g_tBmpHeader;
static const int kVDisplayableScanLines = 192; // max displayable scanlines static const int kVDisplayableScanLines = 192; // max displayable scanlines
static const UINT kVideoRomSize8K = kVideoRomSize4K*2; static const UINT kVideoRomSize8K = kVideoRomSize4K*2;

View File

@ -620,3 +620,9 @@ BYTE* Win32Frame::GetResource(WORD id, LPCSTR lpType, DWORD dwExpectedSize)
return pResource; return pResource;
} }
std::string Win32Frame::Video_GetScreenShotFolder()
{
// save in current folder
return "";
}

View File

@ -55,6 +55,8 @@ public:
virtual BYTE* GetResource(WORD id, LPCSTR lpType, DWORD expectedSize); virtual BYTE* GetResource(WORD id, LPCSTR lpType, DWORD expectedSize);
virtual void Restart(); virtual void Restart();
virtual std::string Video_GetScreenShotFolder();
bool GetFullScreenShowSubunitStatus(void); bool GetFullScreenShowSubunitStatus(void);
int GetFullScreenOffsetX(void); int GetFullScreenOffsetX(void);
int GetFullScreenOffsetY(void); int GetFullScreenOffsetY(void);