From: ShadowFlare Date: Wed, 6 Sep 2006 22:00:53 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://sfsrealm.hopto.org/projects/gitweb.cgi?a=commitdiff_plain;h=ff0247836fccf91e3aa28708f8a4cff04aa038e1;p=grpapi.git --- diff --git a/drawgrp/drawgrp.cpp b/drawgrp/drawgrp.cpp index 4de2c4c..d342525 100644 --- a/drawgrp/drawgrp.cpp +++ b/drawgrp/drawgrp.cpp @@ -82,11 +82,11 @@ int main(int argc, char* argv[]) BI.pBuffer[x] = 0xFFFFFFFF; for (j=0;j<32;j++) { // DrawGrp(hGrp,(HDC)&BI,i,0,i % (17*8),dwPalette,ALPHA_BLEND,0x401020); - DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,0,0x401020); + DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,USE_INDEX,0x401020); for (x = 0; x < BI.nWidth; x++) for (y = 0; y < BI.nHeight; y++) { clrPixel = BI.pBuffer[(y * BI.nWidth) + x]; - if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, i + x, i + y, clrPixel); + if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, i + x, i + y, dwPalette[clrPixel]); } } FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1)); @@ -99,11 +99,11 @@ int main(int argc, char* argv[]) BI.pBuffer[x] = 0xFFFFFFFF; for (j=0;j<32;j++) { // DrawGrp(hGrp,(HDC)&BI,400-i,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|ALPHA_BLEND,0x401020); - DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,HORIZONTAL_FLIP,0x401020); + DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|USE_INDEX,0x401020); for (x = 0; x < BI.nWidth; x++) for (y = 0; y < BI.nHeight; y++) { clrPixel = BI.pBuffer[(y * BI.nWidth) + x]; - if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400-i + x, 400-i + y, clrPixel); + if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400-i + x, 400-i + y, dwPalette[clrPixel]); } } FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1)); @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) for (i = 0; i < BI.nWidth; i++) for (j = 0; j < BI.nHeight; j++) { clrPixel = BI.pBuffer[(j * BI.nWidth) + i]; - if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400 + i, 300 + j, clrPixel); + if (clrPixel != 0xFFFFFFFF) SetPixelV(hDC, 400 + i, 300 + j, dwPalette[clrPixel]); } //} ReleaseDC(0,hDC); diff --git a/grpapi/grpapi.cpp b/grpapi/grpapi.cpp index b286741..abe808a 100644 --- a/grpapi/grpapi.cpp +++ b/grpapi/grpapi.cpp @@ -37,7 +37,7 @@ typedef struct { GETPIXELPROC MyGetPixel = GetPixel; SETPIXELPROC MySetPixel = (SETPIXELPROC)SetPixelV; -void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DWORD dwAlpha); +void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); extern HINSTANCE hStorm; @@ -226,14 +226,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR if (!(RowData[ofs] & 0x80)) { if (!(RowData[ofs] & 0x40)) { for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha); + SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); x++; } ofs+=RowData[ofs]+1; } else { for (i=0;iWidth;i++) { - SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha); + SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); x++; } ofs+=2; @@ -249,7 +249,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR else { for (y=0;yHeight;y++) { for (x=0;xWidth;x++) { - SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha); + SetPix(hdcDest,nXDest+x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); } } } @@ -263,14 +263,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR if (!(RowData[ofs] & 0x80)) { if (!(RowData[ofs] & 0x40)) { for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha); + SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); x++; } ofs+=RowData[ofs]+1; } else { for (i=0;iWidth;i++) { - SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha); + SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); x++; } ofs+=2; @@ -286,7 +286,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR else { for (y=0;yHeight;y++) { for (x=0;xWidth;x++) { - SetPix(hdcDest,Right-x,nYDest+y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha); + SetPix(hdcDest,Right-x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); } } } @@ -300,14 +300,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR if (!(RowData[ofs] & 0x80)) { if (!(RowData[ofs] & 0x40)) { for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha); + SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); x++; } ofs+=RowData[ofs]+1; } else { for (i=0;iWidth;i++) { - SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha); + SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); x++; } ofs+=2; @@ -323,7 +323,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR else { for (y=0;yHeight;y++) { for (x=0;xWidth;x++) { - SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha); + SetPix(hdcDest,nXDest+x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); } } } @@ -337,14 +337,14 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR if (!(RowData[ofs] & 0x80)) { if (!(RowData[ofs] & 0x40)) { for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha); + SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); x++; } ofs+=RowData[ofs]+1; } else { for (i=0;iWidth;i++) { - SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha); + SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); x++; } ofs+=2; @@ -360,7 +360,7 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR else { for (y=0;yHeight;y++) { for (x=0;xWidth;x++) { - SetPix(hdcDest,Right-x,Bottom-y,dwPalette[GrpRaw[y * GrpFrame->Width + x]],dwFlags,dwAlpha); + SetPix(hdcDest,Right-x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); } } } @@ -385,37 +385,42 @@ void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc) MySetPixel = lpSetPixelProc; } -void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DWORD dwAlpha) +void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha) { - if (dwFlags&SHADOW_COLOR) { - clrColor = (dwFlags >> 8) & 0x00FFFFFF; - } - if (dwFlags&ALPHA_BLEND) { - DWORD dwColor = MyGetPixel(hDC,X,Y); + if (!(dwFlags&USE_INDEX)) { + if (dwFlags&SHADOW_COLOR) { + clrColor = (dwFlags >> 8) & 0x00FFFFFF; + } + else { + clrColor = dwPalette[clrColor]; + } + if (dwFlags&ALPHA_BLEND) { + DWORD dwColor = MyGetPixel(hDC,X,Y); - // Old alpha - /*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256); - ((BYTE *)&dwColor)[1]*=1-((float)((BYTE *)&dwAlpha)[1]/256); - ((BYTE *)&dwColor)[2]*=1-((float)((BYTE *)&dwAlpha)[2]/256); - ((BYTE *)&clrColor)[0]*=(float)((BYTE *)&dwAlpha)[0]/256; - ((BYTE *)&clrColor)[1]*=(float)((BYTE *)&dwAlpha)[1]/256; - ((BYTE *)&clrColor)[2]*=(float)((BYTE *)&dwAlpha)[2]/256; - ((BYTE *)&clrColor)[0]+=((BYTE *)&dwColor)[0]; - ((BYTE *)&clrColor)[1]+=((BYTE *)&dwColor)[1]; - ((BYTE *)&clrColor)[2]+=((BYTE *)&dwColor)[2];*/ + // Old alpha + /*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256); + ((BYTE *)&dwColor)[1]*=1-((float)((BYTE *)&dwAlpha)[1]/256); + ((BYTE *)&dwColor)[2]*=1-((float)((BYTE *)&dwAlpha)[2]/256); + ((BYTE *)&clrColor)[0]*=(float)((BYTE *)&dwAlpha)[0]/256; + ((BYTE *)&clrColor)[1]*=(float)((BYTE *)&dwAlpha)[1]/256; + ((BYTE *)&clrColor)[2]*=(float)((BYTE *)&dwAlpha)[2]/256; + ((BYTE *)&clrColor)[0]+=((BYTE *)&dwColor)[0]; + ((BYTE *)&clrColor)[1]+=((BYTE *)&dwColor)[1]; + ((BYTE *)&clrColor)[2]+=((BYTE *)&dwColor)[2];*/ - /* blendedcolor = - ( ( forecolor * ( 1 - alpha ) ) >> 8 ) - + ( ( backcolor * ( 256 - alpha ) ) >> 8 ) */ - ((BYTE *)&clrColor)[0] = - ( ( ((BYTE *)&clrColor)[0] * ( ((BYTE *)&dwAlpha)[0] + 1 ) ) >> 8 ) - + ( ( ((BYTE *)&dwColor)[0] * ( 256 - ((BYTE *)&dwAlpha)[0] ) ) >> 8 ); - ((BYTE *)&clrColor)[1] = - ( ( ((BYTE *)&clrColor)[1] * ( ((BYTE *)&dwAlpha)[1] + 1 ) ) >> 8 ) - + ( ( ((BYTE *)&dwColor)[1] * ( 256 - ((BYTE *)&dwAlpha)[1] ) ) >> 8 ); - ((BYTE *)&clrColor)[2] = - ( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 ) - + ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 ); + /* blendedcolor = + ( ( forecolor * ( 1 - alpha ) ) >> 8 ) + + ( ( backcolor * ( 256 - alpha ) ) >> 8 ) */ + ((BYTE *)&clrColor)[0] = + ( ( ((BYTE *)&clrColor)[0] * ( ((BYTE *)&dwAlpha)[0] + 1 ) ) >> 8 ) + + ( ( ((BYTE *)&dwColor)[0] * ( 256 - ((BYTE *)&dwAlpha)[0] ) ) >> 8 ); + ((BYTE *)&clrColor)[1] = + ( ( ((BYTE *)&clrColor)[1] * ( ((BYTE *)&dwAlpha)[1] + 1 ) ) >> 8 ) + + ( ( ((BYTE *)&dwColor)[1] * ( 256 - ((BYTE *)&dwAlpha)[1] ) ) >> 8 ); + ((BYTE *)&clrColor)[2] = + ( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 ) + + ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 ); + } } MySetPixel(hDC,X,Y,clrColor); } diff --git a/grpapi/grpapi.h b/grpapi/grpapi.h index 501253d..8a61f43 100644 --- a/grpapi/grpapi.h +++ b/grpapi/grpapi.h @@ -81,7 +81,7 @@ typedef void (WINAPI* SETPIXELPROC)( // Call these to have DrawGrp use custom functions for reading and drawing pixels // so that you can have it read from and write to a buffer, for example. -void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc); +void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc); // Only used with ALPHA_BLEND void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc); // Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). diff --git a/grpapi/grpapi_no-lib.h b/grpapi/grpapi_no-lib.h index 8ce9772..ac1b3d6 100644 --- a/grpapi/grpapi_no-lib.h +++ b/grpapi/grpapi_no-lib.h @@ -86,7 +86,7 @@ typedef void (WINAPI* SETPIXELPROC)( // so that you can have it read from and write to a buffer, for example. typedef void (WINAPI* funcSetFunctionGetPixel)(GETPIXELPROC lpGetPixelProc); typedef void (WINAPI* funcSetFunctionSetPixel)(SETPIXELPROC lpSetPixelProc); -extern funcSetFunctionGetPixel SetFunctionGetPixel; +extern funcSetFunctionGetPixel SetFunctionGetPixel; // Only used with ALPHA_BLEND extern funcSetFunctionSetPixel SetFunctionSetPixel; // Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ).