Browse Source

Clean up SBmpLoadImage

pull/25/head
Anders Jenbo 7 years ago
parent
commit
da032c92cc
  1. 2
      3rdParty/Storm/Source/storm.h
  2. 141
      Stub/DiabloUI/sdlrender.cpp
  3. 108
      Stub/storm.cpp

2
3rdParty/Storm/Source/storm.h vendored

@ -607,7 +607,7 @@ STORMAPI
SBmpLoadImage(
const char *pszFileName,
PALETTEENTRY *pPalette ,
void *pBuffer,
BYTE *pBuffer,
DWORD dwBuffersize,
DWORD *pdwWidth,
DWORD *pdwHeight,

141
Stub/DiabloUI/sdlrender.cpp

@ -68,7 +68,7 @@ bool LoadArtImage(char *pszFile, void **pBuffer, int frames, DWORD *data, PALETT
if (!SBmpLoadImage(pszFile, 0, 0, 0, &width, &height, 0))
return 0;
*pBuffer = SMemAlloc(height * width, "U:\\DiabloUI\\Ui\\local.cpp", 88, 0);
*pBuffer = malloc(height * width);
if (!SBmpLoadImage(pszFile, pPalette, *pBuffer, height * width, 0, 0, 0))
return 0;
if (pBuffer && data) {
@ -79,145 +79,6 @@ bool LoadArtImage(char *pszFile, void **pBuffer, int frames, DWORD *data, PALETT
return 1;
}
BOOL __stdcall SBmpLoadImage(const char *pszFileName, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *dwHeight, DWORD *pdwBpp)
{
char *v7; // ebx
unsigned char *v8; // edi
PALETTEENTRY *v9; // esi
int v10; // esi
signed int v11; // ebx
int v12; // ebp
size_t v13; // ebp
unsigned char *v14; // eax
unsigned char *v15; // edx
int v16; // ebp
unsigned char v17; // cl
unsigned char v18; // al
int v19; // ecx
bool v20; // zf
bool v21; // sf
unsigned char(*v22)[3]; // eax
BYTE v23; // cl
unsigned char *Memory; // [esp+14h] [ebp-38Ch]
HANDLE hFile; // [esp+18h] [ebp-388h] MAPDST
DWORD v28; // [esp+1Ch] [ebp-384h]
PCXHeader pcxhdr; // [esp+20h] [ebp-380h]
unsigned char paldata[256][3]; // [esp+A0h] [ebp-300h]
int z;
if (pdwWidth)
*pdwWidth = 0;
if (dwHeight)
*dwHeight = 0;
if (pdwBpp)
*pdwBpp = 0;
v7 = (char *)pszFileName;
if (pszFileName) {
if (*pszFileName) {
v8 = (unsigned char *)pBuffer;
if (!pBuffer || dwBuffersize) {
v9 = pPalette;
if (pPalette || pBuffer || pdwWidth || dwHeight) {
if (SFileOpenFile(pszFileName, &hFile)) {
if (strchr(pszFileName, 92)) {
do
v7 = strchr(v7, 92) + 1;
while (strchr(v7, 92));
}
for (; strchr(v7 + 1, 46); v7 = strchr(v7, 46))
;
if (!v7 || _strcmpi(v7, ".pcx")) // omit all types except PCX
{
return 0;
//v10 = sub_15001C70(hFile, pPalette, pBuffer, dwBuffersize, pdwWidth, dwHeight, pdwBpp);
//goto LABEL_51;
}
if (!SFileReadFile(hFile, &pcxhdr, 128u, 0, 0)) {
v10 = 0;
LABEL_51:
SFileCloseFile(hFile);
return v10;
}
*(_DWORD *)&paldata[0][0] = pcxhdr.xmax - pcxhdr.xmin + 1;
v11 = pcxhdr.ymax - pcxhdr.ymin + 1;
v28 = pcxhdr.bitsPerPixel;
if (pdwWidth)
*pdwWidth = *(_DWORD *)&paldata[0][0];
if (dwHeight)
*dwHeight = v11;
if (pdwBpp)
*pdwBpp = v28;
if (!pBuffer) {
SFileSetFilePointer(hFile, 0, 0, 2);
goto LABEL_45;
}
v12 = SFileGetFileSize(hFile, 0);
v13 = v12 - SFileSetFilePointer(hFile, 0, 0, 1);
v14 = (unsigned char *)SMemAlloc(v13, "SBMP.CPP", 171, 0);
Memory = v14;
if (!v14) {
LABEL_45:
if (pPalette && v28 == 8) {
SFileSetFilePointer(hFile, -768, 0, 1);
SFileReadFile(hFile, paldata, 768u, 0, 0);
v22 = paldata;
for (z = 0; z < 256; z++) {
v23 = *(_BYTE *)v22;
++v9;
++v22;
v9[-1].peRed = v23;
v9[-1].peGreen = (*v22)[-2];
v9[-1].peBlue = (*v22)[-1];
v9[-1].peFlags = 0;
}
}
v10 = 1;
goto LABEL_51;
}
SFileReadFile(hFile, v14, v13, 0, 0);
v15 = Memory;
if (v11 <= 0)
goto LABEL_43;
LABEL_33:
v16 = *(_DWORD *)&paldata[0][0];
while (1) {
v17 = *v15++;
if (v17 < 0xC0u) {
*v8++ = v17;
--v16;
} else {
v18 = *v15;
v19 = v17 & 0x3F;
++v15;
for (; v19; --v16) {
v20 = v16 == 0;
v21 = v16 < 0;
if (!v16)
goto LABEL_41;
*v8++ = v18;
--v19;
}
}
v20 = v16 == 0;
v21 = v16 < 0;
LABEL_41:
if (v21 || v20) {
if (!--v11) {
LABEL_43:
SMemFree(Memory, "SBMP.CPP", 178, 0);
goto LABEL_45;
}
goto LABEL_33;
}
}
}
}
}
}
}
return 0;
}
void FreeMenuItems()
{
void *tmp;

108
Stub/storm.cpp

@ -109,6 +109,114 @@ BOOL STORMAPI SFileOpenFile(const char *filename, HANDLE *phFile)
// UNIMPLEMENTED();
// }
BOOL __stdcall SBmpLoadImage(const char *pszFileName, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *dwHeight, DWORD *pdwBpp)
{
HANDLE hFile;
size_t size;
PCXHeader pcxhdr;
BYTE paldata[256][3];
BYTE *dataPtr, *fileBuffer;
BYTE byte;
if (pdwWidth)
*pdwWidth = 0;
if (dwHeight)
*dwHeight = 0;
if (pdwBpp)
*pdwBpp = 0;
if (!pszFileName || !*pszFileName) {
return false;
}
if (pBuffer && !dwBuffersize) {
return false;
}
if (!pPalette && !pBuffer && !pdwWidth && !dwHeight) {
return false;
}
if (!SFileOpenFile(pszFileName, &hFile)) {
return false;
}
while (strchr(pszFileName, 92))
pszFileName = strchr(pszFileName, 92) + 1;
while (strchr(pszFileName + 1, 46))
pszFileName = strchr(pszFileName, 46);
// omit all types except PCX
if (!pszFileName || _strcmpi(pszFileName, ".pcx")) {
return false;
}
if (!SFileReadFile(hFile, &pcxhdr, 128, 0, 0)) {
SFileCloseFile(hFile);
return false;
}
int width = pcxhdr.xmax - pcxhdr.xmin + 1;
int height = pcxhdr.ymax - pcxhdr.ymin + 1;
if (pdwWidth)
*pdwWidth = width;
if (dwHeight)
*dwHeight = height;
if (pdwBpp)
*pdwBpp = pcxhdr.bitsPerPixel;
if (!pBuffer) {
SFileSetFilePointer(hFile, 0, 0, 2);
fileBuffer = NULL;
} else {
size = SFileGetFileSize(hFile, 0) - SFileSetFilePointer(hFile, 0, 0, 1);
fileBuffer = (BYTE *)malloc(size);
}
if (fileBuffer) {
SFileReadFile(hFile, fileBuffer, size, 0, 0);
dataPtr = fileBuffer;
for (int j = 0; j < height; j++) {
for (int x = 0; x < width; dataPtr++) {
byte = *dataPtr;
if (byte < 0xC0) {
*pBuffer = byte;
*pBuffer++;
x++;
continue;
}
dataPtr++;
for (int i = 0; i < (byte & 0x3F); i++) {
*pBuffer = *dataPtr;
*pBuffer++;
x++;
}
}
}
free(fileBuffer);
}
if (pPalette && pcxhdr.bitsPerPixel == 8) {
SFileSetFilePointer(hFile, -768, 0, 1);
SFileReadFile(hFile, paldata, 768, 0, 0);
for (int i = 0; i < 256; i++) {
pPalette[i].peRed = paldata[i][0];
pPalette[i].peGreen = paldata[i][1];
pPalette[i].peBlue = paldata[i][2];
pPalette[i].peFlags = 0;
}
}
SFileCloseFile(hFile);
return true;
}
// int __stdcall SFileSetFilePointer(HANDLE, int, HANDLE, int)
// {
// UNIMPLEMENTED();

Loading…
Cancel
Save