-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJam.cpp
More file actions
executable file
·415 lines (340 loc) · 9.54 KB
/
Copy pathJam.cpp
File metadata and controls
executable file
·415 lines (340 loc) · 9.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#include "stdafx.h"
#include "Jam.h"
#include "Pallette.h"
JAM::~JAM()
{
int size = getNumberOfImages();
delete[] entry;
if (jammemory) free(jammemory);
}
JAMEntry::~JAMEntry()
{
// if (info) free(info);
if (jamBmp) {
delete (jamBmp);
jamBmp = NULL;
}
}
unsigned char *
JAM::getImagePtr(int img)
{
int offset = 0;
int imageptr = offset;
unsigned char *ptr = jamimagememory;
ptr += imageptr;
entry[img].img_ptr = ptr;
return ptr;
}
BOOL
JAM::LoadBMPImage(CBitmap &bitmap, int m_Width, int m_Height)
{
int size = getNumberOfImages();
int width = getMaxX();
int height = getMinX();
for (int i = 0; i < size; i++) {
LoadSingleBMPImage(bitmap, 0, 0, i);
}
return TRUE;
}
BOOL
JAM::DrawAllJams(CDC *pDC, double currentScale, BOOL drawRcr, BOOL drawOutlines)
{
if (!valid) {
OpenToRead(FALSE);
}
if (valid) {
// LoadSingleBMPImage(bmp,256,getMaxY(),0);
for (int i = 0; i < getNumberOfImages(); i++)
// for(int i=0;i<7;i++)
{
CBitmap bmp, *poldbmp;
LoadSingleBMPImage(bmp, getImageWidth(i), getImageHeight(i), i);
CDC memdc;
// Create a compatible memory DC
memdc.CreateCompatibleDC(pDC);
// Select the bitmap into the DC
poldbmp = memdc.SelectObject(&bmp);
int nWidth = getImageWidth(i);
int nHeight = getImageHeight(i);
if (currentScale != 1.0) {
int dwidth = (int)(nWidth * currentScale);
int dheight = (int)(nHeight * currentScale);
int dx = (int)(getImageX(i) * currentScale);
int dy = (int)(getImageY(i) * currentScale);
if (drawRcr) {
dx *= 2;
dy *= 2;
}
pDC->StretchBlt(dx, dy, dwidth, dheight, &memdc, 0, 0, nWidth, nHeight,
SRCCOPY);
}
else {
int x = (int)(getImageX(i) * currentScale);
int y = (int)(getImageY(i) * currentScale);
pDC->BitBlt(x, y, 2 * nWidth, nHeight, &memdc, 0, 0, SRCCOPY);
}
memdc.SelectObject(&poldbmp);
}
CPen *yellowPen = new CPen(PS_SOLID, 1, RGB(0, 0, 0));
pDC->SelectObject(yellowPen);
// pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0, 0, 0));
if (drawOutlines) {
for (int i = 0; i < getNumberOfImages(); i++) {
int x = (int)(currentScale * getImageX(i));
int y = (int)(currentScale * getImageY(i));
if (drawRcr) {
/*
if (i>0)
{
int py = (int)(currentScale*getImageY(i-1));
if (y-py == 1)
{
x=256+x;
y = py;
}
}
y=y/2;
*/
x = 0;
y = i * 30;
}
int w = (int)(currentScale * getImageWidth(i));
int h = (int)(currentScale * getImageHeight(i));
if (drawRcr) {
w *= 2;
}
pDC->MoveTo(x, y);
pDC->LineTo(x + w, y);
pDC->LineTo(x + w, y + h);
pDC->LineTo(x, y + h);
pDC->LineTo(x, y);
char label[10];
int id = getImageId(i);
wsprintf(label, "#%d(%x)", id, id);
pDC->TextOut((x + (x + w)) / 2 - 10, (y + (y + h)) / 2 - 10, label);
}
}
delete yellowPen;
}
else {
AfxMessageBox(
"Trouble Loading JAM File perhaps I don't know GP2 Location or Jam "
"Does not exist/corrupt");
}
return TRUE;
}
unsigned char *
JAMEntry::AdjustImage(int image_total_size, unsigned char *imgo, BOOL rcr)
{
if (imageAdjusted) return jamData;
unsigned char *img = img_ptr;
// int m_Width = (rcr) ? 2*info->width : info->width;
int m_Width = (rcr) ? 1024 : info->width;
int m_Height = (rcr) ? image_total_size / 2 : info->height;
// int m_Height = info->height;
int m_X = (rcr) ? 0 : info->x;
int m_Y = (rcr) ? 0 : info->y;
int m_ImagePal = (rcr) ? 0 : info->palette_size_div4;
jamData = (unsigned char *)malloc(m_Width * m_Height);
unsigned char *palptr = palette1;
memset(jamData, 0, (m_Width * m_Height));
TRACE("%x %d %d\n", img_ptr, m_Width, m_Height);
unsigned char localPal[256];
if (m_ImagePal > 0) {
for (int i = 0; i < m_ImagePal; i++) {
unsigned char idx = palptr[i];
localPal[i] = idx;
}
}
else {
for (int i = 0; i < 256; i++) {
localPal[i] = i;
}
}
int ox = m_X;
int oy = m_Y;
int step = (rcr) ? 2 : 1;
for (int i = 0; i < m_Height; i++) {
for (int j = 0; j < (m_Width); j++) {
int idx = 0;
if (rcr)
idx = ox + j + ((oy + i) * 512);
else
idx = ox + j + ((oy + i) * 256);
int idxD = (i * m_Width) + j;
int da = img[idx];
int palcol = localPal[da];
jamData[idxD] = palcol;
// jamData[idxD] = da;
}
}
imageAdjusted = TRUE;
return jamData;
}
BOOL
JAM::LoadSingleBMPImage(CBitmap &bitmap, int m_Width, int m_Height, int index)
{
if (entry[index].jamBmp == NULL) {
entry[index].jamBmp = new BMP();
}
if (rcr) m_Width *= 2;
if (!valid) {
OpenToRead(FALSE);
}
unsigned char *img = getImagePtr(index);
unsigned char *palptr = getPalletePtr(index);
int m_ImagePal = getPalleteSize(index);
RGBQUAD *pal = (RGBQUAD *)malloc(256 * sizeof(RGBQUAD));
int palleteSize = sizeof(palette) / sizeof(palette[0]);
for (int i = 0; i < palleteSize; i++) {
pal[i].rgbRed = palette[i + 1].r;
pal[i].rgbGreen = palette[i + 1].g;
pal[i].rgbBlue = palette[i + 1].b;
pal[i].rgbReserved = 0;
}
unsigned char *newJamData =
entry[index].AdjustImage(header->image_total_size, img, rcr);
/*
int count=0;
int ypos=0;
for( i=0;i<256;i++)
{
newJamData[((ypos*256)+count)] = i;
count++;
if (count>15)
{
count = 0;
ypos++;
}
}
*/
entry[index].jamBmp->SetPalette(pal);
// TRACE("w h %d %d\n",m_Width,m_Height);
entry[index].jamBmp->Create(m_Width, m_Height, newJamData);
entry[index].jamBmp->CreateDIB(bitmap);
return TRUE;
}
void
JAM::UnJam(void *ptr, unsigned int len)
{
unsigned long x;
unsigned int n;
unsigned char *pc;
unsigned long *pl;
x = 0xb082f164UL;
n = len / 4;
x |= 1;
pl = (unsigned long *)ptr;
while (n--) {
*pl ^= x;
++pl;
x = x + (x * 4);
}
n = len & (4 - 1);
if (n != 0) {
pc = (unsigned char *)pl;
*pc ^= x & 0xff;
++pc;
x >>= 8;
}
}
int
JAM::GetPoint(int x, int y)
{
unsigned char *img = getImagePtr(0);
img += (y * 256);
img += x;
return *img;
}
BOOL
JAM::DrawSingleJams(CDC *pDC, double currentScale, CBitmap ¤tJam,
BOOL rcr)
{
if (!valid) {
OpenToRead(FALSE);
}
if (valid) {
CBitmap bmp, *poldbmp, *decaloldbmp;
int nWidth, nHeight;
if (rcr) {
nWidth = 512;
nHeight = header->image_total_size / 2;
}
else {
nWidth = 256;
nHeight = header->image_total_size;
}
LoadSingleBMPImage(bmp, nWidth, nHeight, 0);
CDC memdc;
// Create a compatible memory DC
memdc.CreateCompatibleDC(pDC);
// Select the bitmap into the DC
poldbmp = memdc.SelectObject(&bmp);
if (currentScale != 1.0) {
int dwidth = (int)(nWidth * currentScale);
int dheight = (int)(nHeight * currentScale);
int dx = 0;
int dy = 0;
pDC->StretchBlt(dx, dy, dwidth, dheight, &memdc, 0, 0, nWidth, nHeight,
SRCCOPY);
}
else {
int x = 0;
int y = 0;
pDC->BitBlt(x, y, nWidth, nHeight, &memdc, 0, 0, SRCCOPY);
}
memdc.SelectObject(&poldbmp);
CPen *yellowPen = new CPen(PS_SOLID, 1, RGB(255, 255, 0));
pDC->SelectObject(yellowPen);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255, 255, 0));
if (TRUE) {
for (int i = 0; i < getNumberOfImages(); i++) {
int x = (int)(currentScale * getImageX(i));
int y = (int)(currentScale * getImageY(i));
int w = (int)(currentScale * getImageWidth(i));
int h = (int)(currentScale * getImageHeight(i));
if (y % 2) {
x += 256;
y = y - 1;
}
w = w * 2;
y = y / 2;
pDC->MoveTo(x, y);
pDC->LineTo(x + w, y);
pDC->LineTo(x + w, y + h);
pDC->LineTo(x, y + h);
pDC->LineTo(x, y);
char label[10];
int id = getImageId(i);
wsprintf(label, "#%d(%x)", id, id);
pDC->TextOut((x + (x + w)) / 2 - 10, (y + (y + h)) / 2 - 10, label);
}
}
delete yellowPen;
CBitmap img;
img.CreateCompatibleBitmap(pDC, (nWidth / 2), nHeight);
poldbmp = memdc.SelectObject(&img);
if (rcr) {
CDC memdcDecal;
memdcDecal.CreateCompatibleDC(pDC);
decaloldbmp = memdcDecal.SelectObject(¤tJam);
unsigned char *ptr = getImagePtr(0);
int SmallWidth = nWidth / 2;
for (int j = 0; j < nHeight; j++) {
for (int i = 0; i < SmallWidth; i++) {
int valX = *ptr;
ptr++;
int valY = *ptr;
ptr++;
memdc.SetPixel(i, j, memdcDecal.GetPixel(valX, valY));
}
}
pDC->BitBlt(0, nHeight, SmallWidth, nHeight, &memdc, 0, 0, SRCCOPY);
memdc.SelectObject(&poldbmp);
memdcDecal.SelectObject(&decaloldbmp);
}
}
return TRUE;
}