-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJam.cpp
More file actions
executable file
·191 lines (151 loc) · 3.75 KB
/
Copy pathJam.cpp
File metadata and controls
executable file
·191 lines (151 loc) · 3.75 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
#include "stdafx.h"
#include "Jam.h"
#include "Pallette.h"
JAM::~JAM()
{
int size = getNumberOfImages();
//for(int i=0;i<size;i++)
//{
//delete &entry[i];
//}
delete[] entry;
if (jammemory) free(jammemory);
}
JAMEntry::~JAMEntry()
{
//if (info) free(info);
if (jamBmp)
{
delete (jamBmp);
jamBmp=NULL;
}
if (jamData) free(jamData);
}
unsigned char *JAM::getImagePtr(int img)
{
int offset=0;
//for(int i=0;i<img;i++)
//{
//offset+= entry[i].info->width*entry[i].info->height;
//offset+= 256*entry[i].info->height;
//}
//offset+=entry[img].info->x;
//int imageptr = entry[img].info->image_ptr;
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;
}
unsigned char * JAMEntry::AdjustImage(int image_total_size,unsigned char *imgo)
{
if (imageAdjusted) return jamData;
unsigned char *img = img_ptr;
int m_Width = info->width;
int m_Height = info->height;
int m_X = info->x;
int m_Y = info->y;
int m_ImagePal = info->palette_size_div4;
//unsigned char * m_PalPtrPal = info->imageptr;
//m_Width = 256;
jamData = (unsigned char*)malloc(m_Width*m_Height);
unsigned char * palptr = palette1;
//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;
for(int i=0;i<m_Height;i++)
{
for(int j=0;j<m_Width;j++)
{
int idx = ox+j+((oy+i)*256);
int idxD = (i*m_Width)+j;
jamData[idxD] = localPal[img[idx]];
}
}
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 (!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);
entry[index].jamBmp->SetPalette(pal);
//TRACE("w h %d %d\n",m_Width,m_Height);
entry[index].jamBmp->Create(m_Width,m_Height,newJamData);
free(pal);
}
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;
}
}