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, 6 Sep 2006 22:00:53 +0000 (22:00 +0000)]
drawgrp/drawgrp.cpp
grpapi/grpapi.cpp
grpapi/grpapi.h
grpapi/grpapi_no-lib.h

index 4de2c4c..d342525 100644 (file)
@@ -82,11 +82,11 @@ int main(int argc, char* argv[])
                        BI.pBuffer[x] = 0xFFFFFFFF;\r
                for (j=0;j<32;j++) {\r
 //                     DrawGrp(hGrp,(HDC)&BI,i,0,i % (17*8),dwPalette,ALPHA_BLEND,0x401020);\r
-                       DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,0,0x401020);\r
+                       DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,USE_INDEX,0x401020);\r
                        for (x = 0; x < BI.nWidth; x++)\r
                                for (y = 0; y < BI.nHeight; y++) {\r
                                        clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r
-                                       if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, i + x, i + y, clrPixel);\r
+                                       if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, i + x, i + y, dwPalette[clrPixel]);\r
                                }\r
                }\r
                FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r
@@ -99,11 +99,11 @@ int main(int argc, char* argv[])
                        BI.pBuffer[x] = 0xFFFFFFFF;\r
                for (j=0;j<32;j++) {\r
 //                     DrawGrp(hGrp,(HDC)&BI,400-i,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|ALPHA_BLEND,0x401020);\r
-                       DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,HORIZONTAL_FLIP,0x401020);\r
+                       DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|USE_INDEX,0x401020);\r
                        for (x = 0; x < BI.nWidth; x++)\r
                                for (y = 0; y < BI.nHeight; y++) {\r
                                        clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r
-                                       if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400-i + x, 400-i + y, clrPixel);\r
+                                       if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400-i + x, 400-i + y, dwPalette[clrPixel]);\r
                                }\r
                }\r
                FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r
@@ -111,7 +111,7 @@ int main(int argc, char* argv[])
        for (i = 0; i < BI.nWidth; i++)\r
                for (j = 0; j < BI.nHeight; j++) {\r
                        clrPixel = BI.pBuffer[(j * BI.nWidth) + i];\r
-                       if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400 + i, 300 + j, clrPixel);\r
+                       if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400 + i, 300 + j, dwPalette[clrPixel]);\r
                }\r
        //}\r
        ReleaseDC(0,hDC);\r
index b286741..abe808a 100644 (file)
@@ -37,7 +37,7 @@ typedef struct {
 GETPIXELPROC MyGetPixel = GetPixel;\r
 SETPIXELPROC MySetPixel = (SETPIXELPROC)SetPixelV;\r
 \r
-void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DWORD dwAlpha);\r
+void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha);\r
 \r
 extern HINSTANCE hStorm;\r
 \r
@@ -226,14 +226,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                                        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
+                                                               SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+i],dwPalette,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
+                                                               SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha);\r
                                                                x++;\r
                                                        }\r
                                                        ofs+=2;\r
@@ -249,7 +249,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                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
+                                       SetPix(hdcDest,nXDest+x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
@@ -263,14 +263,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                                        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
+                                                               SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+i],dwPalette,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
+                                                               SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha);\r
                                                                x++;\r
                                                        }\r
                                                        ofs+=2;\r
@@ -286,7 +286,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                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
+                                       SetPix(hdcDest,Right-x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
@@ -300,14 +300,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                                        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
+                                                               SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+i],dwPalette,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
+                                                               SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha);\r
                                                                x++;\r
                                                        }\r
                                                        ofs+=2;\r
@@ -323,7 +323,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                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
+                                       SetPix(hdcDest,nXDest+x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
@@ -337,14 +337,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                                        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
+                                                               SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+i],dwPalette,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
+                                                               SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha);\r
                                                                x++;\r
                                                        }\r
                                                        ofs+=2;\r
@@ -360,7 +360,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
                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
+                                       SetPix(hdcDest,Right-x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha);\r
                                }\r
                        }\r
                }\r
@@ -385,37 +385,42 @@ void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc)
        MySetPixel = lpSetPixelProc;\r
 }\r
 \r
-void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DWORD dwAlpha)\r
+void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha)\r
 {\r
-       if (dwFlags&SHADOW_COLOR) {\r
-               clrColor = (dwFlags >> 8) & 0x00FFFFFF;\r
-       }\r
-       if (dwFlags&ALPHA_BLEND) {\r
-               DWORD dwColor = MyGetPixel(hDC,X,Y);\r
+       if (!(dwFlags&USE_INDEX)) {\r
+               if (dwFlags&SHADOW_COLOR) {\r
+                       clrColor = (dwFlags >> 8) & 0x00FFFFFF;\r
+               }\r
+               else {\r
+                       clrColor = dwPalette[clrColor];\r
+               }\r
+               if (dwFlags&ALPHA_BLEND) {\r
+                       DWORD dwColor = MyGetPixel(hDC,X,Y);\r
 \r
-               // Old alpha\r
-               /*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256);\r
-               ((BYTE *)&dwColor)[1]*=1-((float)((BYTE *)&dwAlpha)[1]/256);\r
-               ((BYTE *)&dwColor)[2]*=1-((float)((BYTE *)&dwAlpha)[2]/256);\r
-               ((BYTE *)&clrColor)[0]*=(float)((BYTE *)&dwAlpha)[0]/256;\r
-               ((BYTE *)&clrColor)[1]*=(float)((BYTE *)&dwAlpha)[1]/256;\r
-               ((BYTE *)&clrColor)[2]*=(float)((BYTE *)&dwAlpha)[2]/256;\r
-               ((BYTE *)&clrColor)[0]+=((BYTE *)&dwColor)[0];\r
-               ((BYTE *)&clrColor)[1]+=((BYTE *)&dwColor)[1];\r
-               ((BYTE *)&clrColor)[2]+=((BYTE *)&dwColor)[2];*/\r
+                       // Old alpha\r
+                       /*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256);\r
+                       ((BYTE *)&dwColor)[1]*=1-((float)((BYTE *)&dwAlpha)[1]/256);\r
+                       ((BYTE *)&dwColor)[2]*=1-((float)((BYTE *)&dwAlpha)[2]/256);\r
+                       ((BYTE *)&clrColor)[0]*=(float)((BYTE *)&dwAlpha)[0]/256;\r
+                       ((BYTE *)&clrColor)[1]*=(float)((BYTE *)&dwAlpha)[1]/256;\r
+                       ((BYTE *)&clrColor)[2]*=(float)((BYTE *)&dwAlpha)[2]/256;\r
+                       ((BYTE *)&clrColor)[0]+=((BYTE *)&dwColor)[0];\r
+                       ((BYTE *)&clrColor)[1]+=((BYTE *)&dwColor)[1];\r
+                       ((BYTE *)&clrColor)[2]+=((BYTE *)&dwColor)[2];*/\r
 \r
-               /* blendedcolor =\r
-                    ( ( forecolor * ( 1 - alpha ) ) >> 8 )\r
-                  + ( ( backcolor * ( 256 - alpha ) ) >> 8 ) */\r
-               ((BYTE *)&clrColor)[0] =\r
-                       ( ( ((BYTE *)&clrColor)[0] * ( ((BYTE *)&dwAlpha)[0] + 1 ) ) >> 8 )\r
-                       + ( ( ((BYTE *)&dwColor)[0] * ( 256 - ((BYTE *)&dwAlpha)[0] ) ) >> 8 );\r
-               ((BYTE *)&clrColor)[1] =\r
-                       ( ( ((BYTE *)&clrColor)[1] * ( ((BYTE *)&dwAlpha)[1] + 1 ) ) >> 8 )\r
-                       + ( ( ((BYTE *)&dwColor)[1] * ( 256 - ((BYTE *)&dwAlpha)[1] ) ) >> 8 );\r
-               ((BYTE *)&clrColor)[2] =\r
-                       ( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 )\r
-                       + ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 );\r
+                       /* blendedcolor =\r
+                                ( ( forecolor * ( 1 - alpha ) ) >> 8 )\r
+                          + ( ( backcolor * ( 256 - alpha ) ) >> 8 ) */\r
+                       ((BYTE *)&clrColor)[0] =\r
+                               ( ( ((BYTE *)&clrColor)[0] * ( ((BYTE *)&dwAlpha)[0] + 1 ) ) >> 8 )\r
+                               + ( ( ((BYTE *)&dwColor)[0] * ( 256 - ((BYTE *)&dwAlpha)[0] ) ) >> 8 );\r
+                       ((BYTE *)&clrColor)[1] =\r
+                               ( ( ((BYTE *)&clrColor)[1] * ( ((BYTE *)&dwAlpha)[1] + 1 ) ) >> 8 )\r
+                               + ( ( ((BYTE *)&dwColor)[1] * ( 256 - ((BYTE *)&dwAlpha)[1] ) ) >> 8 );\r
+                       ((BYTE *)&clrColor)[2] =\r
+                               ( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 )\r
+                               + ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 );\r
+               }\r
        }\r
        MySetPixel(hDC,X,Y,clrColor);\r
 }\r
index 501253d..8a61f43 100644 (file)
@@ -81,7 +81,7 @@ typedef void (WINAPI* SETPIXELPROC)(
 \r
 // Call these to have DrawGrp use custom functions for reading and drawing pixels\r
 // so that you can have it read from and write to a buffer, for example.\r
-void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc);\r
+void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc); // Only used with ALPHA_BLEND\r
 void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc);\r
 \r
 // Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ).\r
index 8ce9772..ac1b3d6 100644 (file)
@@ -86,7 +86,7 @@ typedef void (WINAPI* SETPIXELPROC)(
 // so that you can have it read from and write to a buffer, for example.\r
 typedef void (WINAPI* funcSetFunctionGetPixel)(GETPIXELPROC lpGetPixelProc);\r
 typedef void (WINAPI* funcSetFunctionSetPixel)(SETPIXELPROC lpSetPixelProc);\r
-extern funcSetFunctionGetPixel SetFunctionGetPixel;\r
+extern funcSetFunctionGetPixel SetFunctionGetPixel; // Only used with ALPHA_BLEND\r
 extern funcSetFunctionSetPixel SetFunctionSetPixel;\r
 \r
 // Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ).\r