-
Notifications
You must be signed in to change notification settings - Fork 4
/
gbcamtool.html
311 lines (244 loc) · 8.15 KB
/
gbcamtool.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
function resolve_color(color){
// return an array containing R, G and B values
if(color === 'transparent')// IE (6 and ?)
color = '#FFF';
var r,g,b;
var hex_color_pcre = new RegExp("^#[0-9a-f]{3}([0-9a-f]{3})?$",'gi');
var rgb_color_pcre = new RegExp("rgb\\(\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*\\)$",'gi');
var rgb_percent_color_pcre = new RegExp("rgb\\(\\s*((?:[0-1]?[0-9])?[0-9])%\\s*,\\s*((?:[0-1]?[0-9])?[0-9])%\\s*,\\s*((?:[0-1]?[0-9])?[0-9])%\\s*\\)$",'gi');
if(color.match(hex_color_pcre)){
if(color.length == 4){
r = color.charAt(1)+""+color.charAt(1);
g = color.charAt(2)+""+color.charAt(2);
b = color.charAt(3)+""+color.charAt(3);
}
else{
r = color.charAt(1)+""+color.charAt(2);
g = color.charAt(3)+""+color.charAt(4);
b = color.charAt(5)+""+color.charAt(6);
}
r = h2d(r);
g = h2d(g);
b = h2d(b);
}
else if(color.match(rgb_color_pcre)){
r = RegExp.$1;
g = RegExp.$2;
b = RegExp.$3;
}
else if(color.match(rgb_percent_color_pcre)){
r = parseInt((RegExp.$1)*2.55);
g = parseInt((RegExp.$2)*2.55);
b = parseInt((RegExp.$3)*2.55);
}
else
return false;
var returned =[];
returned['red'] = r;
returned['green'] = g;
returned['blue'] = b;
return returned;
}
function h2d(h) {
// hex to decimal
return parseInt(h,16);
}
function getTileIndex(base, tile_id)
{
return base + 16 * tile_id;
}
function photoToImageData(savedata, ctx, photo_index)
{
// First photo at 0x2000, 0x1000 per photo
var offset = 0x2000 + photo_index * 0x1000;
var x,y,i,p,X;
var w = 128;
var h = 112;
var w_tiles = w >> 3;
var h_tiles = h >> 3;
var imagedata = ctx.createImageData(w,h);
var val;
var tdata;
var palette = [];
for (i=0; i<4; i++) {
palette[i] = resolve_color(document.getElementById("color"+i).value);
}
for (y = 0; y<h_tiles*8; y++) {
for (x = 0; x < w_tiles; x++) {
tdata = getTileIndex(offset + 0, (y>>3) * 0x10 + x);
for (i=0; i<8; i++) {
p = tdata + ((y&7) * 2);
val = 0;
if ((savedata[p] & (0x80 >> i))!=0) {
val += 1;
}
if ((savedata[p+1] & (0x80 >> i))!=0) {
val += 2;
}
X = x * 8 + i;
imagedata.data[(y*w*4)+(X*4)+0] = palette[val]['red'];
imagedata.data[(y*w*4)+(X*4)+1] = palette[val]['green'];
imagedata.data[(y*w*4)+(X*4)+2] = palette[val]['blue'];
imagedata.data[(y*w*4)+(X*4)+3] = 0xff;
}
}
}
return imagedata;
}
function setPreset(id)
{
var colors = [ "#ffffff", "#cccccc", "#666666", "#000000" ];
var i;
switch(id)
{
case 1:
colors = [ "#9bbc0f", "#8bac0f", "#306230", "#0f380f" ];
break;
case 2:
colors = [ "#ffffff", "#ffc000", "#a06000", "#000000" ];
}
for (i=0; i<4; i++) {
document.getElementById('color'+i).value = colors[i];
}
loadSaveFile();
}
function displayContents(savedata)
{
var photo;
for (photo = 0; photo < 30; photo++) {
var canvas = document.getElementById("photo" + photo);
var ctx = canvas.getContext("2d");
imgdata = photoToImageData(new Uint8Array(savedata), ctx, photo);
ctx.putImageData(imgdata,0,0);
}
}
function loadSaveFile()
{
file = document.getElementById('savefile').files[0];
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
displayContents(contents)
};
reader.readAsArrayBuffer(file);
}
</script>
</head>
<body>
<h1>Pocket Camera image viewer</h1>
This is a simple html5 + javascript Gameboy Camera (also known as Pocket Camera) photo
viewer/extraction tool that runs in a web browser.
<h2>Load save file</h2>
<input type="file" id="savefile" onchange="loadSaveFile()">
<button onclick="loadSaveFile()">(re)Load</button>
<h2>Tweaks</h2>
<b>Intensity</b><Br>
Color 1: <input type="text" id="color0" value="#ffffff" onchange="loadSaveFile()"><br>
Color 2: <input type="text" id="color1" value="#cccccc" onchange="loadSaveFile()"><br>
Color 3: <input type="text" id="color2" value="#666666" onchange="loadSaveFile()"><br>
Color 4: <input type="text" id="color3" value="#000000" onchange="loadSaveFile()"><br>
<br>
<b>Presets</b>
<input type="button" onClick="setPreset(0)" value="Black and White">
<input type="button" onClick="setPreset(1)" value="Gameboy">
<input type="button" onClick="setPreset(2)" value="Gameboy player">
<h2>Photos</h2>
To save a particular photo, right-click and select Save Image As... (or equivalent)<br>
<br>
<canvas id="photo0" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo1" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo2" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo3" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo4" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo5" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo6" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo7" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo8" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo9" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo10" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo11" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo12" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo13" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo14" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo15" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo16" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo17" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo18" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo19" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo20" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo21" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo22" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo23" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo24" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo25" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo26" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo27" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo28" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
<canvas id="photo29" width="128" height="112">
Fallback content, in case the browser does not support Canvas.
</canvas>
</body>
</html>