mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
screenshots in .bmp format without libpng
This commit is contained in:
parent
4814054df5
commit
4fe2bf7c99
@ -36,9 +36,7 @@ void mouse_lock();
|
||||
void mouse_unlock();
|
||||
|
||||
/* from screenshot.c */
|
||||
#ifdef HAVE_LIBPNG
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||
#endif
|
||||
|
||||
IDirectDrawImpl *ddraw = NULL;
|
||||
|
||||
@ -761,7 +759,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
if(wParam == VK_CONTROL || wParam == ddraw->screenshotKey)
|
||||
{
|
||||
if(GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(ddraw->screenshotKey) & 0x8000)
|
||||
@ -770,16 +768,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
#ifdef HAVE_LIBPNG
|
||||
case WM_KEYUP:
|
||||
if (wParam == VK_SNAPSHOT)
|
||||
screenshot(ddraw->primary);
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
/* button up messages reactivate cursor lock */
|
||||
|
@ -13,9 +13,6 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
@ -24,6 +21,102 @@
|
||||
#include "palette.h"
|
||||
#include "surface.h"
|
||||
|
||||
#ifndef HAVE_LIBPNG
|
||||
|
||||
//https://docs.microsoft.com/en-us/windows/desktop/gdi/storing-an-image
|
||||
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *src)
|
||||
{
|
||||
HANDLE hf; // file handle
|
||||
BITMAPFILEHEADER hdr; // bitmap file-header
|
||||
PBITMAPINFOHEADER pbih; // bitmap info-header
|
||||
LPBYTE lpBits; // memory pointer
|
||||
DWORD dwTotal; // total count of bytes
|
||||
DWORD cb; // incremental count of bytes
|
||||
BYTE *hp; // byte pointer
|
||||
DWORD dwTmp;
|
||||
int i;
|
||||
char title[128];
|
||||
char filename[128];
|
||||
char str_time[64];
|
||||
time_t t = time(NULL);
|
||||
BOOL result = TRUE;
|
||||
|
||||
strncpy(title, ddraw->title, sizeof(ddraw->title));
|
||||
|
||||
for (i = 0; i<strlen(title); i++) {
|
||||
if (title[i] == ' ')
|
||||
{
|
||||
title[i] = '_';
|
||||
}
|
||||
else
|
||||
{
|
||||
title[i] = tolower(title[i]);
|
||||
}
|
||||
}
|
||||
|
||||
strftime(str_time, 64, "%Y-%m-%d-%H_%M_%S", localtime(&t));
|
||||
_snprintf(filename, 128, "%s-%s.bmp", title, str_time);
|
||||
|
||||
pbih = (PBITMAPINFOHEADER)src->bmi;
|
||||
lpBits = (LPBYTE)src->surface;
|
||||
|
||||
if (!lpBits)
|
||||
return FALSE;
|
||||
|
||||
// Create the .BMP file.
|
||||
hf = CreateFile(filename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
(DWORD)0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
(HANDLE)NULL);
|
||||
|
||||
if (hf == INVALID_HANDLE_VALUE)
|
||||
return FALSE;
|
||||
|
||||
hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
|
||||
// Compute the size of the entire file.
|
||||
hdr.bfSize = (DWORD)(sizeof(BITMAPFILEHEADER) +
|
||||
pbih->biSize + pbih->biClrUsed
|
||||
* sizeof(RGBQUAD) + pbih->biSizeImage);
|
||||
hdr.bfReserved1 = 0;
|
||||
hdr.bfReserved2 = 0;
|
||||
|
||||
// Compute the offset to the array of color indices.
|
||||
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
|
||||
pbih->biSize + pbih->biClrUsed
|
||||
* sizeof(RGBQUAD);
|
||||
|
||||
// Copy the BITMAPFILEHEADER into the .BMP file.
|
||||
if (!WriteFile(hf, (LPVOID)&hdr, sizeof(BITMAPFILEHEADER),
|
||||
(LPDWORD)&dwTmp, NULL))
|
||||
{
|
||||
result = FALSE;
|
||||
}
|
||||
|
||||
// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
|
||||
if (!WriteFile(hf, (LPVOID)pbih, sizeof(BITMAPINFOHEADER)
|
||||
+ pbih->biClrUsed * sizeof(RGBQUAD),
|
||||
(LPDWORD)&dwTmp, (NULL)))
|
||||
result = FALSE;
|
||||
|
||||
// Copy the array of color indices into the .BMP file.
|
||||
dwTotal = cb = pbih->biSizeImage;
|
||||
hp = lpBits;
|
||||
if (!WriteFile(hf, (LPSTR)hp, (int)cb, (LPDWORD)&dwTmp, NULL))
|
||||
result = FALSE;
|
||||
|
||||
// Close the .BMP file.
|
||||
if (!CloseHandle(hf))
|
||||
result = FALSE;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <png.h>
|
||||
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *src)
|
||||
|
@ -560,6 +560,12 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
|
||||
Surface->bmi->bmiHeader.biBitCount = Surface->bpp;
|
||||
Surface->bmi->bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
WORD cClrBits = (WORD)(Surface->bmi->bmiHeader.biPlanes * Surface->bmi->bmiHeader.biBitCount);
|
||||
if (cClrBits < 24)
|
||||
Surface->bmi->bmiHeader.biClrUsed = (1 << cClrBits);
|
||||
|
||||
Surface->bmi->bmiHeader.biSizeImage = ((Surface->width * cClrBits + 31) & ~31) / 8 * Surface->height;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user