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 [Wed, 5 Dec 2007 05:33:36 +0000 (05:33 +0000)]
grpapi/grpapi.cpp

index f35e7f5..67726c4 100644 (file)
@@ -499,20 +499,6 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa
        nLastOffset = sizeof(GRPHEADER) + nFrames * sizeof(FRAMEHEADER);\r
 \r
        for (i = 0; i < nFrames; i++) {\r
-               // Search for duplicate frames\r
-               for (j = 0; j < i; j++) {\r
-                       if (memcmp(&lpImageData[i * wMaxWidth * wMaxHeight],\r
-                                  &lpImageData[j * wMaxWidth * wMaxHeight],\r
-                                          wMaxWidth * wMaxHeight * sizeof(short)) == 0)\r
-                               break;\r
-               }\r
-\r
-               if (j < i) {\r
-                       memcpy(&lpFrameHeaders[i], &lpFrameHeaders[j], sizeof(FRAMEHEADER));\r
-                       lpFrameData[i].lpRowOffsets = 0;\r
-                       continue;\r
-               }\r
-\r
                lpFrameHeaders[i].Offset = nLastOffset;\r
 \r
                // Scan frame to find dimensions of used part\r
@@ -540,6 +526,47 @@ HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMa
                lpFrameHeaders[i].Height = y2;\r
 \r
                EncodeFrameData(lpImageData, i, &GrpHeader, &lpFrameHeaders[i], &lpFrameData[i], bNoCompress);\r
+\r
+               // Search for duplicate frames\r
+               for (j = 0; j < i; j++) {\r
+                       if (lpFrameData[j].lpRowOffsets && lpFrameHeaders[i].Width == lpFrameHeaders[j].Width && lpFrameHeaders[i].Height == lpFrameHeaders[j].Height && lpFrameData[i].Size == lpFrameData[j].Size) {\r
+                               for (y = 0; y < lpFrameHeaders[i].Height; y++) {\r
+                                       if (!lpFrameData[i].lpRowData[y] && !lpFrameData[j].lpRowData[y])\r
+                                               continue;\r
+\r
+                                       if ((!lpFrameData[i].lpRowData[y] && lpFrameData[j].lpRowData[y]) || (lpFrameData[i].lpRowData[y] && !lpFrameData[j].lpRowData[y]) || lpFrameData[i].lpRowSizes[y] != lpFrameData[j].lpRowSizes[y])\r
+                                               break;\r
+\r
+                                       if (memcmp(lpFrameData[i].lpRowData[y], lpFrameData[j].lpRowData[y], lpFrameData[i].lpRowSizes[y]) != 0)\r
+                                               break;\r
+                               }\r
+\r
+                               if (y == lpFrameHeaders[i].Height) {\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (j < i) {\r
+                       // Duplicate frame found, free stored frame data and change offset\r
+                       for (y = 0; y < lpFrameHeaders[i].Height; y++) {\r
+                               if (lpFrameData[i].lpRowData[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
+                       lpFrameHeaders[i].Offset = lpFrameHeaders[j].Offset;\r
+                       lpFrameData[i].lpRowOffsets = 0;\r
+                       lpFrameData[i].lpRowSizes = 0;\r
+                       lpFrameData[i].lpRowData = 0;\r
+                       lpFrameData[i].Size = 0;\r
+                       continue;\r
+               }\r
+\r
                nLastOffset = lpFrameHeaders[i].Offset + lpFrameData[i].Size;\r
        }\r
 \r