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 Small banner for links to this site: |
1 // drawgrp.cpp : Defines the entry point for the console application.\r
2 //\r
3 \r
4 #define _CRT_RAND_S\r
5 #include <stdlib.h>\r
6 #include "stdafx.h"\r
7 \r
8 \r
9 /*int qmain(int argc, char* argv[]);\r
10 \r
11 int main(int argc, char* argv[])\r
12 {\r
13 HINSTANCE hStorm = LoadStorm("Storm.dll");\r
14 if (SFileDestroy!=0) SFileDestroy();\r
15 LoadGrpApi();\r
16 int RetVal = qmain(argc,argv);\r
17 FreeGrpApi();\r
18 if (hStorm!=0) FreeLibrary(hStorm);\r
19 return RetVal;\r
20 }*/\r
21 \r
22 struct BufferInfo {\r
23 WORD nWidth;\r
24 WORD nHeight;\r
25 signed short *pBuffer;\r
26 WORD nFrame;\r
27 };\r
28 \r
29 COLORREF WINAPI ReadPixelFromBuffer(BufferInfo *pBI, int X, int Y)\r
30 {\r
31 if (pBI->nFrame == 0xFFFF)\r
32 return pBI->pBuffer[(Y * pBI->nWidth) + X];\r
33 else\r
34 return pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X];\r
35 }\r
36 \r
37 void WINAPI WritePixelToBuffer(BufferInfo *pBI, int X, int Y, COLORREF clrColor)\r
38 {\r
39 if (pBI->nFrame == 0xFFFF)\r
40 pBI->pBuffer[(Y * pBI->nWidth) + X] = (signed short)clrColor;\r
41 else\r
42 pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)clrColor;\r
43 }\r
44 \r
45 int main(int argc, char* argv[])\r
46 {\r
47 HANDLE hMPQ=0,hMPQ2=0,hMPQ3=0;\r
48 DWORD *dwPalette = (DWORD *)_alloca(1024);\r
49 memset(dwPalette,0,1024);\r
50 LoadStorm("SFMpq.dll");\r
51 SetMpqDll("SFMpq.dll");\r
52 if (SFileOpenArchive!=0) {\r
53 char *buffer = (char *)_alloca(13);\r
54 memcpy(buffer,"StarDat.mpq",12);\r
55 if (SFileOpenArchive(buffer,1000,0,&hMPQ)==0) return 0;\r
56 memcpy(buffer,"BrooDat.mpq",12);\r
57 SFileOpenArchive(buffer,2000,0,&hMPQ2);\r
58 memcpy(buffer,"Patch_rt.mpq",13);\r
59 SFileOpenArchive(buffer,3000,0,&hMPQ3);\r
60 }\r
61 BufferInfo BI;\r
62 LoadPalette("tileset\\Jungle.wpe",dwPalette);\r
63 HANDLE hGrp, hGrp2;\r
64 if (argc>1)\r
65 hGrp = LoadGrp(argv[1]);\r
66 else\r
67 hGrp = LoadGrp("unit\\zerg\\ultra.grp");\r
68 HDC hDC = GetDC(0);\r
69 GRPHEADER GrpInfo;\r
70 if (GetGrpInfo(hGrp,&GrpInfo)==0) {GrpInfo.nFrames=0;GrpInfo.wMaxWidth=0;GrpInfo.wMaxHeight=0;}\r
71 BI.nWidth = GrpInfo.wMaxWidth;\r
72 BI.nHeight = GrpInfo.wMaxHeight;\r
73 BI.pBuffer = (signed short *)malloc(GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short));\r
74 WORD i,x,y;\r
75 DWORD j, nGrpSize;\r
76 unsigned int u,v;\r
77 memset(BI.pBuffer, 0xFF, GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short));\r
78 //for (DWORD j=0;j<16;j++){\r
79 /*for (WORD i=0;i<GrpInfo.nFrames;i++) {\r
80 DrawGrp(hGrp,hDC,0,0,i,dwPalette,ALPHA_BLEND,0x401020);\r
81 }*/\r
82 signed short clrPixel;\r
83 RECT rect;\r
84 for (i=0;i<GrpInfo.nFrames;i++) {\r
85 for (j=0;j<8;j++)\r
86 {\r
87 rand_s(&u);\r
88 rand_s(&v);\r
89 u = u % 800;\r
90 v = v % 600;\r
91 //DrawGrp(hGrp,hDC,u,v,i,dwPalette,ALPHA_BLEND,0x404040);\r
92 }\r
93 }\r
94 SetFunctionGetPixel((GETPIXELPROC)ReadPixelFromBuffer);\r
95 SetFunctionSetPixel((SETPIXELPROC)WritePixelToBuffer);\r
96 for (i=0;i<GrpInfo.nFrames;i++) {\r
97 BI.nFrame = i;\r
98 DrawGrp(hGrp,(HDC)&BI,0,0,i,0,USE_INDEX,0);\r
99 }\r
100 hGrp2 = hGrp;\r
101 hGrp = CreateGrp(BI.pBuffer, GrpInfo.nFrames, GrpInfo.wMaxWidth, GrpInfo.wMaxHeight, &nGrpSize);\r
102 BI.nFrame = 0xFFFF;\r
103 for (i=13;i<14;i+=17) {\r
104 rect.left = rect.top = i;\r
105 rect.right = rect.left + BI.nWidth;\r
106 rect.bottom = rect.top + BI.nHeight;\r
107 for (x = 0; x < BI.nWidth * BI.nHeight; x++)\r
108 BI.pBuffer[x] = -1;\r
109 for (j=0;j<(32 * 25);j++) {\r
110 // DrawGrp(hGrp,(HDC)&BI,i,0,i % (17*8),dwPalette,ALPHA_BLEND,0x401020);\r
111 DrawGrp(hGrp2,(HDC)&BI,0,0,i % (17*8),0,USE_INDEX,0x401020);\r
112 u = memcmp(BI.pBuffer, &BI.pBuffer[(i % (17*8)) * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short));\r
113 DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),0,USE_INDEX,0x401020);\r
114 u = memcmp(BI.pBuffer, &BI.pBuffer[(i % (17*8)) * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short));\r
115 for (x = 0; x < BI.nWidth; x++)\r
116 for (y = 0; y < BI.nHeight; y++) {\r
117 clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r
118 if (clrPixel != -1) SetPixelV(hDC, i + x, i + y, dwPalette[clrPixel]);\r
119 }\r
120 }\r
121 if (u) {\r
122 MessageBox(0, "Output of re-encoded graphic does not match original!", 0, 0);\r
123 break;\r
124 }\r
125 FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r
126 }\r
127 for (i=4;i<400;i+=17) {\r
128 rect.left = rect.top = 400-i;\r
129 rect.right = rect.left + BI.nWidth;\r
130 rect.bottom = rect.top + BI.nHeight;\r
131 for (x = 0; x < BI.nWidth * BI.nHeight; x++)\r
132 BI.pBuffer[x] = -1;\r
133 for (j=0;j<32;j++) {\r
134 // DrawGrp(hGrp,(HDC)&BI,400-i,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|ALPHA_BLEND,0x401020);\r
135 DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),0,HORIZONTAL_FLIP|USE_INDEX,0x401020);\r
136 for (x = 0; x < BI.nWidth; x++)\r
137 for (y = 0; y < BI.nHeight; y++) {\r
138 clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r
139 if (clrPixel != -1) SetPixelV(hDC, 400-i + x, 400-i + y, dwPalette[clrPixel]);\r
140 }\r
141 }\r
142 FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r
143 }\r
144 for (i = 0; i < BI.nWidth; i++)\r
145 for (j = 0; j < BI.nHeight; j++) {\r
146 clrPixel = BI.pBuffer[(j * BI.nWidth) + i];\r
147 if (clrPixel != -1) SetPixelV(hDC, 400 + i, 300 + j, dwPalette[clrPixel]);\r
148 }\r
149 //}\r
150 ReleaseDC(0,hDC);\r
151 free(BI.pBuffer);\r
152 DestroyGrp(hGrp);\r
153 DestroyGrp(hGrp2);\r
154 if (SFileCloseArchive!=0) {\r
155 if (hMPQ3!=0) SFileCloseArchive(hMPQ3);\r
156 if (hMPQ2!=0) SFileCloseArchive(hMPQ2);\r
157 if (hMPQ!=0) SFileCloseArchive(hMPQ);\r
158 }\r
159 return 0;\r
160 }\r
161 \r
|