Browse Source

C declaration (#498)

* Convert player.cpp functions to C
* Convert capture.cpp functions to C
pull/25/head
Anders Jenbo 7 years ago committed by GitHub
parent
commit
7dee72d446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      Source/capture.cpp
  2. 417
      Source/player.cpp

28
Source/capture.cpp

@ -4,17 +4,19 @@
void __cdecl CaptureScreen() void __cdecl CaptureScreen()
{ {
HANDLE hObject;
PALETTEENTRY palette[256]; PALETTEENTRY palette[256];
char FileName[MAX_PATH]; char FileName[MAX_PATH];
BOOL success;
HANDLE hObject = CaptureFile(FileName); hObject = CaptureFile(FileName);
if (hObject != INVALID_HANDLE_VALUE) { if (hObject != INVALID_HANDLE_VALUE) {
DrawAndBlit(); DrawAndBlit();
lpDDPalette->GetEntries(0, 0, 256, palette); lpDDPalette->GetEntries(0, 0, 256, palette);
RedPalette(palette); RedPalette(palette);
j_lock_buf_priv(2); j_lock_buf_priv(2);
BOOL success = CaptureHdr(hObject, 640, 480); success = CaptureHdr(hObject, 640, 480);
if (success) { if (success) {
success = CapturePix(hObject, 640, 480, 768, (BYTE *)gpBuffer->row[0].pixels); success = CapturePix(hObject, 640, 480, 768, (BYTE *)gpBuffer->row[0].pixels);
if (success) { if (success) {
@ -34,9 +36,10 @@ void __cdecl CaptureScreen()
BOOL __fastcall CaptureHdr(HANDLE hFile, short width, short height) BOOL __fastcall CaptureHdr(HANDLE hFile, short width, short height)
{ {
DWORD lpNumBytes;
PCXHeader Buffer; PCXHeader Buffer;
memset(&Buffer, 0, sizeof(Buffer)); memset(&Buffer, 0, sizeof(Buffer));
Buffer.manufacturer = 10; Buffer.manufacturer = 10;
Buffer.version = 5; Buffer.version = 5;
Buffer.encoding = 1; Buffer.encoding = 1;
@ -48,7 +51,6 @@ BOOL __fastcall CaptureHdr(HANDLE hFile, short width, short height)
Buffer.numColorPlanes = 1; Buffer.numColorPlanes = 1;
Buffer.bytesPerScanLine = width; Buffer.bytesPerScanLine = width;
DWORD lpNumBytes;
return WriteFile(hFile, &Buffer, sizeof(Buffer), &lpNumBytes, NULL) && lpNumBytes == sizeof(Buffer); return WriteFile(hFile, &Buffer, sizeof(Buffer), &lpNumBytes, NULL) && lpNumBytes == sizeof(Buffer);
} }
@ -56,10 +58,12 @@ BOOL __fastcall CapturePal(HANDLE hFile, PALETTEENTRY *palette)
{ {
char *v3; char *v3;
char Buffer[769]; char Buffer[769];
int i;
DWORD lpNumBytes;
Buffer[0] = 12; Buffer[0] = 12;
v3 = &Buffer[1]; v3 = &Buffer[1];
for (int i = 256; i != 0; --i) { for (i = 256; i != 0; --i) {
v3[0] = palette->peRed; v3[0] = palette->peRed;
v3[1] = palette->peGreen; v3[1] = palette->peGreen;
v3[2] = palette->peBlue; v3[2] = palette->peBlue;
@ -68,7 +72,6 @@ BOOL __fastcall CapturePal(HANDLE hFile, PALETTEENTRY *palette)
v3 += 3; v3 += 3;
} }
DWORD lpNumBytes;
return WriteFile(hFile, Buffer, sizeof(Buffer), &lpNumBytes, NULL) && lpNumBytes == sizeof(Buffer); return WriteFile(hFile, Buffer, sizeof(Buffer), &lpNumBytes, NULL) && lpNumBytes == sizeof(Buffer);
} }
@ -76,15 +79,16 @@ BOOL __fastcall CapturePix(HANDLE hFile, WORD width, WORD height, WORD stride, B
{ {
int writeSize; int writeSize;
DWORD lpNumBytes; DWORD lpNumBytes;
BYTE *pBuffer, *pBufferEnd;
BYTE *pBuffer = (BYTE *)DiabloAllocPtr(2 * width); pBuffer = (BYTE *)DiabloAllocPtr(2 * width);
do { do {
if (!height) { if (!height) {
mem_free_dbg(pBuffer); mem_free_dbg(pBuffer);
return TRUE; return TRUE;
} }
height--; height--;
BYTE *pBufferEnd = CaptureEnc(pixels, pBuffer, width); pBufferEnd = CaptureEnc(pixels, pBuffer, width);
pixels += stride; pixels += stride;
writeSize = pBufferEnd - pBuffer; writeSize = pBufferEnd - pBuffer;
} while (WriteFile(hFile, pBuffer, writeSize, &lpNumBytes, 0) && lpNumBytes == writeSize); } while (WriteFile(hFile, pBuffer, writeSize, &lpNumBytes, 0) && lpNumBytes == writeSize);
@ -94,10 +98,12 @@ BOOL __fastcall CapturePix(HANDLE hFile, WORD width, WORD height, WORD stride, B
BYTE *__fastcall CaptureEnc(BYTE *src, BYTE *dst, int width) BYTE *__fastcall CaptureEnc(BYTE *src, BYTE *dst, int width)
{ {
int rleLength;
do { do {
BYTE rlePixel = *src; BYTE rlePixel = *src;
*src++; *src++;
int rleLength = 1; rleLength = 1;
width--; width--;
@ -127,11 +133,11 @@ BYTE *__fastcall CaptureEnc(BYTE *src, BYTE *dst, int width)
HANDLE __fastcall CaptureFile(char *dst_path) HANDLE __fastcall CaptureFile(char *dst_path)
{ {
BOOLEAN num_used[100]; BOOLEAN num_used[100];
int free_num; int free_num, hFind;
_finddata_t finder; _finddata_t finder;
memset(num_used, FALSE, sizeof(num_used)); memset(num_used, FALSE, sizeof(num_used));
int hFind = _findfirst("screen??.PCX", &finder); hFind = _findfirst("screen??.PCX", &finder);
if (hFind != -1) { if (hFind != -1) {
do { do {
if (isdigit(finder.name[6]) && isdigit(finder.name[7])) { if (isdigit(finder.name[6]) && isdigit(finder.name[7])) {

417
Source/player.cpp

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save