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




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