Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




ShadowFlare [Sun, 10 Sep 2006 03:41:46 +0000 (03:41 +0000)]
grpapi/grpapi.cpp

index fcb1c27..6c1e737 100644 (file)
@@ -467,6 +467,7 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa
 \r
                if (j < i) {\r
                        memcpy(&lpFrameHeaders[i], &lpFrameHeaders[j], sizeof(FRAMEHEADER));\r
+                       lpFrameData[i].lpRowOffsets = 0;\r
                        continue;\r
                }\r
 \r
@@ -514,22 +515,19 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa
        memcpy(lpGrpData + sizeof(GRPHEADER), lpFrameHeaders, nFrames * sizeof(FRAMEHEADER));\r
 \r
        for (i = 0; i < nFrames; i++) {\r
-               if (lpFrameHeaders[i].Offset) {\r
+               if (lpFrameData[i].lpRowOffsets) {\r
                        memcpy(lpGrpData + lpFrameHeaders[i].Offset, lpFrameData[i].lpRowOffsets, lpFrameHeaders[i].Height * sizeof(WORD));\r
 \r
                        for (y = 0; y < lpFrameHeaders[i].Height; y++) {\r
-                               memcpy(lpGrpData + lpFrameHeaders[i].Offset + lpFrameData[i].lpRowOffsets[y], lpFrameData[i].lpRowData[y], lpFrameData[i].lpRowSizes[y]);\r
-                               free(lpFrameData[i].lpRowData[y]);\r
+                               if (lpFrameData[i].lpRowData[y]) {\r
+                                       memcpy(lpGrpData + lpFrameHeaders[i].Offset + lpFrameData[i].lpRowOffsets[y], lpFrameData[i].lpRowData[y], lpFrameData[i].lpRowSizes[y]);\r
+                                       free(lpFrameData[i].lpRowData[y]);\r
+                               }\r
                        }\r
 \r
                        free(lpFrameData[i].lpRowOffsets);\r
                        free(lpFrameData[i].lpRowSizes);\r
                        free(lpFrameData[i].lpRowData);\r
-\r
-                       for (j = i + 1; j < nFrames; j++) {\r
-                               if (lpFrameHeaders[i].Offset == lpFrameHeaders[j].Offset)\r
-                                       lpFrameHeaders[j].Offset = 0;\r
-                       }\r
                }\r
        }\r
 \r
@@ -542,8 +540,9 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa
 \r
 void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHeader, FRAMEHEADER *lpFrameHeader, FRAMEDATA *lpFrameData)\r
 {\r
-       int x, y, i, nBufPos, nRepeat;\r
+       int x, y, i, j, nBufPos, nRepeat;\r
        LPBYTE lpRowBuf;\r
+       WORD nLastOffset;\r
 \r
        lpFrameData->lpRowOffsets = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD));\r
        lpFrameData->lpRowSizes = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD));\r
@@ -552,6 +551,32 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea
 \r
        for (y = 0; y < lpFrameHeader->Height; y++) {\r
                i = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + y) * lpGrpHeader->wMaxWidth;\r
+\r
+               /* Fails verification when using this.  Bug in encoder or decoder?  Doesn't provide much benefit.\r
+               // Search for duplicate rows\r
+               for (x = 0; x < y; x++) {\r
+                       j = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + x) * lpGrpHeader->wMaxWidth;\r
+                       if (memcmp(&lpImageData[i+lpFrameHeader->Left],\r
+                                  &lpImageData[j+lpFrameHeader->Left],\r
+                                  lpGrpHeader->wMaxWidth * sizeof(short)) == 0)\r
+                               break;\r
+               }\r
+\r
+               if (x < y) {\r
+                       lpFrameData->lpRowOffsets[y] = lpFrameData->lpRowOffsets[x];\r
+                       lpFrameData->lpRowSizes[y] = 0;\r
+                       lpFrameData->lpRowData[y] = 0;\r
+\r
+#ifdef _DEBUG\r
+                       if (!VerifyRow(&lpImageData[i+lpFrameHeader->Left], lpFrameHeader->Width, lpFrameData->lpRowData[x], lpFrameData->lpRowSizes[x])) {\r
+                               nBufPos = nBufPos;\r
+                       }\r
+#endif\r
+\r
+                       continue;\r
+               }\r
+               */\r
+\r
                nBufPos = 0;\r
                if (lpFrameHeader->Width > 0) {\r
                        for (x = lpFrameHeader->Left; x < lpFrameHeader->Left + lpFrameHeader->Width; x++) {\r
@@ -617,9 +642,11 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea
                        lpFrameData->lpRowOffsets[y] = lpFrameHeader->Height * sizeof(WORD);\r
                }\r
                else {\r
-                       lpFrameData->lpRowOffsets[y] = lpFrameData->lpRowOffsets[y-1] + lpFrameData->lpRowSizes[y-1];\r
+                       lpFrameData->lpRowOffsets[y] = nLastOffset;\r
                }\r
 \r
+               nLastOffset = lpFrameData->lpRowOffsets[y] + nBufPos;\r
+\r
                lpFrameData->lpRowSizes[y] = nBufPos;\r
                lpFrameData->lpRowData[y] = (LPBYTE)malloc(nBufPos);\r
                memcpy(lpFrameData->lpRowData[y], lpRowBuf, nBufPos);\r