X-Git-Url: https://sfsrealm.hopto.org/projects/?a=blobdiff_plain;f=grpapi%2Fgrpapi.cpp;h=6c96c561290fac94dfba899aa2deb14a2561daef;hb=b54e4e4936096a8e3b1b25b435ac9aaac7c3660d;hp=7cc25b00af60bda9bbfeba4d14403f030706c5ea;hpb=03269fee39ef66bca887d4be10b93ab6995a12a4;p=grpapi.git diff --git a/grpapi/grpapi.cpp b/grpapi/grpapi.cpp index 7cc25b0..6c96c56 100644 --- a/grpapi/grpapi.cpp +++ b/grpapi/grpapi.cpp @@ -79,6 +79,23 @@ void GRPAPI WINAPI FreeGrpApi() { } +/* +HANDLE hProcessHeap = NULL; + +void * SFAlloc(size_t nSize) +{ + if (!hProcessHeap) hProcessHeap = GetProcessHeap(); + if (hProcessHeap) return HeapAlloc(hProcessHeap, 0, nSize); + else return NULL; +} + +void SFFree(void *lpMem) +{ + if (!hProcessHeap) hProcessHeap = GetProcessHeap(); + if (hProcessHeap) HeapFree(hProcessHeap, 0, lpMem); +} +*/ + BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName) { if (LoadStorm((char *)lpDllFileName)) return TRUE; @@ -455,6 +472,7 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa GrpHeader.wMaxHeight = wMaxHeight; lpFrameHeaders = (FRAMEHEADER *)malloc(nFrames * sizeof(FRAMEHEADER)); lpFrameData = (FRAMEDATA *)malloc(nFrames * sizeof(FRAMEDATA)); + nLastOffset = sizeof(GRPHEADER) + nFrames * sizeof(FRAMEHEADER); for (i = 0; i < nFrames; i++) { // Search for duplicate frames @@ -491,10 +509,16 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa } } } + x2 = x2 - x1 + 1; + y2 = y2 - y1 + 1; + if ((WORD)x1 > 255) x1 = 255; + if ((WORD)y1 > 255) y1 = 255; + if ((WORD)x2 > 255) x2 = 255; + if ((WORD)y2 > 255) y2 = 255; lpFrameHeaders[i].Left = x1; lpFrameHeaders[i].Top = y1; - lpFrameHeaders[i].Width = x2 - x1 + 1; - lpFrameHeaders[i].Height = y2 - y1 + 1; + lpFrameHeaders[i].Width = x2; + lpFrameHeaders[i].Height = y2; if (!bNoCompress) { EncodeFrameData(lpImageData, i, &GrpHeader, &lpFrameHeaders[i], &lpFrameData[i]); @@ -539,7 +563,7 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa for (y = 0; y < lpFrameHeaders[i].Height; y++) { for (x = 0; x < lpFrameHeaders[i].Width; x++) { lpGrpData[lpFrameHeaders[i].Offset + y * lpFrameHeaders[i].Width + x] = - lpImageData[i * wMaxWidth * wMaxHeight + (lpFrameHeaders[i].Top + y) * wMaxWidth + lpFrameHeaders[i].Left + x]; + (BYTE)lpImageData[i * wMaxWidth * wMaxHeight + (lpFrameHeaders[i].Top + y) * wMaxWidth + lpFrameHeaders[i].Left + x]; } } } @@ -555,7 +579,7 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHeader, FRAMEHEADER *lpFrameHeader, FRAMEDATA *lpFrameData) { - int x, y, i, j, nBufPos, nRepeat; + int x, y, i, nBufPos, nRepeat; LPBYTE lpRowBuf; WORD nLastOffset; @@ -563,6 +587,7 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea lpFrameData->lpRowSizes = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD)); lpFrameData->lpRowData = (LPBYTE *)malloc(lpFrameHeader->Height * sizeof(LPBYTE)); lpRowBuf = (LPBYTE)malloc(lpFrameHeader->Width * 2); + nLastOffset = lpFrameHeader->Height * sizeof(WORD); for (y = 0; y < lpFrameHeader->Height; y++) { i = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + y) * lpGrpHeader->wMaxWidth; @@ -602,7 +627,8 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea lpRowBuf[nBufPos]++; } x--; - nBufPos++; + if (nLastOffset + nBufPos + 1 <= 0xFFFF) + nBufPos++; continue; } @@ -613,7 +639,8 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea lpRowBuf[nBufPos] = 0x41 + nRepeat; lpRowBuf[nBufPos+1] = (BYTE)lpImageData[i+x]; x += nRepeat; - nBufPos += 2; + if (nLastOffset + nBufPos + 2 <= 0xFFFF) + nBufPos += 2; } else { lpRowBuf[nBufPos] = 0; @@ -630,18 +657,21 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea lpRowBuf[nBufPos+lpRowBuf[nBufPos]] = (BYTE)lpImageData[i+x]; } x--; - nBufPos += 1 + lpRowBuf[nBufPos]; + if (nLastOffset + nBufPos + 1 + lpRowBuf[nBufPos] <= 0xFFFF) + nBufPos += 1 + lpRowBuf[nBufPos]; } } else { if (lpImageData[i+x] < 0) { lpRowBuf[nBufPos] = 0x81; - nBufPos++; + if (nLastOffset + nBufPos + 1 <= 0xFFFF) + nBufPos++; } else { lpRowBuf[nBufPos] = 1; lpRowBuf[nBufPos+1] = (BYTE)lpImageData[i+x]; - nBufPos += 2; + if (nLastOffset + nBufPos + 2 <= 0xFFFF) + nBufPos += 2; } } }