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 [Fri, 21 Apr 2006 21:50:53 +0000 (21:50 +0000)]
grpapi/grpapi.cpp

index b5fb2ce..b286741 100644 (file)
@@ -187,124 +187,180 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
        GRPHEADER *GrpFile = (GRPHEADER *)hGrp;\r
        nFrame %= GrpFile->nFrames;\r
        FRAMEHEADER *GrpFrame = &((FRAMEHEADER *)(((char *)GrpFile)+6))[nFrame];\r
+       FRAMEHEADER *GrpFrames = &((FRAMEHEADER *)(((char *)GrpFile)+6))[0];\r
+       int FrameSize = 0xFFFFFF;\r
        DWORD Right,Bottom;\r
        if (dwFlags&HORIZONTAL_FLIP) Right = nXDest+GrpFile->wMaxWidth-1-GrpFrame->Left;\r
        if (dwFlags&VERTICAL_FLIP) Bottom = nYDest+GrpFile->wMaxHeight-1-GrpFrame->Top;\r
        nXDest += GrpFrame->Left;\r
        nYDest += GrpFrame->Top;\r
        WORD *GrpOffsets = ((WORD *)(((char *)GrpFile)+GrpFrame->Offset));\r
+       BYTE *GrpRaw = (BYTE *)GrpOffsets;\r
        BYTE *RowData;\r
        WORD x,ofs;\r
        DWORD y;\r
        WORD i;\r
+       int j;\r
+       if (nFrame + 1 < GrpFile->nFrames) {\r
+               for (i = 0; i + 1 < GrpFile->nFrames; i++) {\r
+                       j = GrpFrames[i].Offset - GrpFrame->Offset;\r
+                       if (j > 0 && j < FrameSize)\r
+                               FrameSize = j;\r
+               }\r
+       }\r
+       if (FrameSize == 0xFFFFFF) {\r
+               for (i = 0; i + 1 < GrpFile->nFrames; i++) {\r
+                       j = GrpFrames[i].Offset - GrpFrames[0].Offset;\r
+                       if (j > 0 && j < FrameSize)\r
+                               FrameSize = j;\r
+               }\r
+               if (FrameSize == GrpFrames[0].Width * GrpFrames[0].Height)\r
+                       FrameSize = GrpFrame->Width * GrpFrame->Height;\r
+       }\r
        if (!(dwFlags&HORIZONTAL_FLIP) && !(dwFlags&VERTICAL_FLIP)) {\r
-               for (y=0;y<GrpFrame->Height;y++) {\r
-                       RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
-                       x=0; ofs=0;\r
-                       while (x<GrpFrame->Width) {\r
-                               if (!(RowData[ofs] & 0x80)) {\r
-                                       if (!(RowData[ofs] & 0x40)) {\r
-                                               for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
-                                                       x++;\r
+               if (FrameSize != GrpFrame->Width * GrpFrame->Height) {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+                               x=0; ofs=0;\r
+                               while (x<GrpFrame->Width) {\r
+                                       if (!(RowData[ofs] & 0x80)) {\r
+                                               if (!(RowData[ofs] & 0x40)) {\r
+                                                       for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=RowData[ofs]+1;\r
+                                               }\r
+                                               else {\r
+                                                       for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=2;\r
                                                }\r
-                                               ofs+=RowData[ofs]+1;\r
                                        }\r
                                        else {\r
-                                               for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
-                                                       x++;\r
-                                               }\r
-                                               ofs+=2;\r
+                                               x+=RowData[ofs]-128;\r
+                                               ofs++;\r
                                        }\r
                                }\r
-                               else {\r
-                                       x+=RowData[ofs]-128;\r
-                                       ofs++;\r
+                       }\r
+               }\r
+               else {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               for (x=0;x<GrpFrame->Width;x++) {\r
+                                       SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
        }\r
        else if (dwFlags&HORIZONTAL_FLIP && !(dwFlags&VERTICAL_FLIP)) {\r
-               for (y=0;y<GrpFrame->Height;y++) {\r
-                       RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
-                       x=0; ofs=0;\r
-                       while (x<GrpFrame->Width) {\r
-                               if (!(RowData[ofs] & 0x80)) {\r
-                                       if (!(RowData[ofs] & 0x40)) {\r
-                                               for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
-                                                       x++;\r
+               if (FrameSize != GrpFrame->Width * GrpFrame->Height) {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+                               x=0; ofs=0;\r
+                               while (x<GrpFrame->Width) {\r
+                                       if (!(RowData[ofs] & 0x80)) {\r
+                                               if (!(RowData[ofs] & 0x40)) {\r
+                                                       for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=RowData[ofs]+1;\r
+                                               }\r
+                                               else {\r
+                                                       for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=2;\r
                                                }\r
-                                               ofs+=RowData[ofs]+1;\r
                                        }\r
                                        else {\r
-                                               for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
-                                                       x++;\r
-                                               }\r
-                                               ofs+=2;\r
+                                               x+=RowData[ofs]-128;\r
+                                               ofs++;\r
                                        }\r
                                }\r
-                               else {\r
-                                       x+=RowData[ofs]-128;\r
-                                       ofs++;\r
+                       }\r
+               }\r
+               else {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               for (x=0;x<GrpFrame->Width;x++) {\r
+                                       SetPix(hdcDest,Right-x,nYDest+y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
        }\r
        else if (!(dwFlags&HORIZONTAL_FLIP) && dwFlags&VERTICAL_FLIP) {\r
-               for (y=0;y<GrpFrame->Height;y++) {\r
-                       RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
-                       x=0; ofs=0;\r
-                       while (x<GrpFrame->Width) {\r
-                               if (!(RowData[ofs] & 0x80)) {\r
-                                       if (!(RowData[ofs] & 0x40)) {\r
-                                               for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
-                                                       x++;\r
+               if (FrameSize != GrpFrame->Width * GrpFrame->Height) {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+                               x=0; ofs=0;\r
+                               while (x<GrpFrame->Width) {\r
+                                       if (!(RowData[ofs] & 0x80)) {\r
+                                               if (!(RowData[ofs] & 0x40)) {\r
+                                                       for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=RowData[ofs]+1;\r
+                                               }\r
+                                               else {\r
+                                                       for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=2;\r
                                                }\r
-                                               ofs+=RowData[ofs]+1;\r
                                        }\r
                                        else {\r
-                                               for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
-                                                       x++;\r
-                                               }\r
-                                               ofs+=2;\r
+                                               x+=RowData[ofs]-128;\r
+                                               ofs++;\r
                                        }\r
                                }\r
-                               else {\r
-                                       x+=RowData[ofs]-128;\r
-                                       ofs++;\r
+                       }\r
+               }\r
+               else {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               for (x=0;x<GrpFrame->Width;x++) {\r
+                                       SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
        }\r
        else {\r
-               for (y=0;y<GrpFrame->Height;y++) {\r
-                       RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
-                       x=0; ofs=0;\r
-                       while (x<GrpFrame->Width) {\r
-                               if (!(RowData[ofs] & 0x80)) {\r
-                                       if (!(RowData[ofs] & 0x40)) {\r
-                                               for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
-                                                       x++;\r
+               if (FrameSize != GrpFrame->Width * GrpFrame->Height) {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+                               x=0; ofs=0;\r
+                               while (x<GrpFrame->Width) {\r
+                                       if (!(RowData[ofs] & 0x80)) {\r
+                                               if (!(RowData[ofs] & 0x40)) {\r
+                                                       for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=RowData[ofs]+1;\r
+                                               }\r
+                                               else {\r
+                                                       for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+                                                               SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+                                                               x++;\r
+                                                       }\r
+                                                       ofs+=2;\r
                                                }\r
-                                               ofs+=RowData[ofs]+1;\r
                                        }\r
                                        else {\r
-                                               for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
-                                                       SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
-                                                       x++;\r
-                                               }\r
-                                               ofs+=2;\r
+                                               x+=RowData[ofs]-128;\r
+                                               ofs++;\r
                                        }\r
                                }\r
-                               else {\r
-                                       x+=RowData[ofs]-128;\r
-                                       ofs++;\r
+                       }\r
+               }\r
+               else {\r
+                       for (y=0;y<GrpFrame->Height;y++) {\r
+                               for (x=0;x<GrpFrame->Width;x++) {\r
+                                       SetPix(hdcDest,Right-x,Bottom-y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r