-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogotype-153.html
273 lines (262 loc) · 6.89 KB
/
logotype-153.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
<html>
<head>
<title>Paguo-86PK logotype</title>
<script>
const reader = new FileReader();
//
var fileName;
var image;
var img;
var imData;
</script>
<script>
const binary = [
/*00*/ 0xE7, 0xF3, 0x00, 0x01, 0x00, 0x40, 0x01, 0xC0, 0x4D, 0xB3, 0x11, 0x53, 0x08, 0xE0, 0xFF, 0xFF,
/*10*/ 0x41, 0x4C, 0x49, 0x4B, 0x42, 0x45, 0x52, 0x4F, 0x56, 0x20, 0x32, 0x30, 0x32, 0x34, 0x00, 0xFF,
/*20*/ 0xE1, 0x7E, 0x23, 0xF9, 0xE1, 0xC1, 0xBE, 0x23, 0x03, 0xC2, 0x26, 0x00, 0xE1, 0x36, 0x00, 0x2B,
/*30*/ 0xD1, 0x73, 0x72, 0xD1, 0x73, 0x72, 0x23, 0x36, 0x23, 0x7E, 0x7E, 0xE6, 0x20, 0xCA, 0x3A, 0x00,
/*40*/ 0xEB, 0xE1, 0x36, 0x80, 0x2E, 0x04, 0x3A, 0x02, 0x00, 0x77, 0x3A, 0x03, 0x00, 0x77, 0x23, 0x71,
/*50*/ 0x70, 0x2E, 0x08, 0x36, 0xA4, 0xEB, 0x01, 0x23, 0xE0, 0x16, 0x22, 0x7E, 0xA2, 0xCA, 0x5B, 0x00,
/*60*/ 0xE6, 0x02, 0xCA, 0x5B, 0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE, 0x00, 0x70, 0x71, 0xC3, 0x5B, 0x00
];
class FILE86RK {
constructor() {
this.stream = [];
this.block = [];
}
saveFile(fileName) {
function base64ToArrayBuffer(base64) {
var binaryString = base64;
var binaryLen = binaryString.length;
var bytes = new Uint8Array(binaryLen);
for(var i = 0; i < binaryLen; ++ i)
bytes[i] = binaryString[i];
return bytes;
}
//
function saveByteArray(fileName, bytes) {
var blob = new Blob([bytes], {type: "application/octet-stream"});
var link = document.createElement("A");
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
}
//
let crc = this.getCRC();
let size = this.stream.length;
let end = size - 1;
this.stream.unshift(0x00, 0x00, end >> 8, end & 255);
this.stream.push(0x00, 0x00, 0xE6, crc >> 8, crc & 255);
saveByteArray(fileName, base64ToArrayBuffer(this.stream));
}
saveText(text) {
for(const chr of text.split(""))
this.block.push(chr.charCodeAt(0));
while(this.block.length < 128)
this.block.push(0);
}
saveByte(data) {
this.block.push(data);
}
saveBytes(data) {
this.block.push(...data);
}
saveBlock() {
while(this.block.length < 256)
this.block.push(0);
this.stream.splice(this.stream.length, 0, ...this.block.splice(0, 256));
}
saveData(data) {
this.stream.push(...data);
}
getCRC() {
let crc = 0;
let i = this.stream.length;
for(let code of this.stream) {
code &= 0xFF;
if(-- i)
crc += code * 0x0101;
else
crc = (crc & 0xFF00) + ((crc + code) & 0xFF);
crc &= 0xFFFF;
}
return crc;
}
}
var cnv;
var ctx;
function open_file(el) {
const offsetX = document.getElementById("OffsetX");
const offsetY = document.getElementById("OffsetY");
const offsetH = document.getElementById("OffsetH");
const file = el.files[0];
//
cnv = document.getElementById("Screen");
ctx = cnv.getContext("2d");
//
image = document.createElement("img");
image.src = URL.createObjectURL(file);
image.addEventListener("load", place);
//
fileName = file.name.replace(/\.GIF|\.PNG$/i, ".RKR");
//
document.querySelector("div").style.display = "block";
el.style.display = "none";
if("OffsetX" in window.localStorage)
offsetX.value = Number(window.localStorage.OffsetX);
if("OffsetY" in window.localStorage)
offsetY.value = Number(window.localStorage.OffsetY);
if("OffsetH" in window.localStorage)
offsetH.value = Number(window.localStorage.OffsetH);
}
function rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
let max = Math.max(r, g, b);
let min = Math.min(r, g, b);
let d = max - min;
let h;
if(d === 0)
h = 0;
else
if(max === r)
h = (g - b) / d % 6;
else
if(max === g)
h = (b - r) / d + 2;
else
if(max === b)
h = (r - g) / d + 4;
let l = (min + max) / 2;
let s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
return {
h:h * 60,
s:s,
l:l
}
}
function place() {
const offsetX = document.getElementById("OffsetX").value;
const offsetY = document.getElementById("OffsetY").value;
const offsetH = document.getElementById("OffsetH").value;
var i = 0;
//
if(cnv.width != image.width || cnv.height != image.height)
cnv.width = image.width,
cnv.height = image.height;
ctx.save();
ctx.clearRect(0, 0, cnv.width, cnv.height);
ctx.globalAlpha = 0.5;
ctx.drawImage(image, 0, 0);
ctx.globalAlpha = 1.0;
ctx.drawImage(image, offsetX, offsetY, 94, 153, offsetX, offsetY, 94, 153);
//
img = ctx.getImageData(offsetX, offsetY, 94, 153);
imData = img.data;
//
for(var y = 0; y < 153; ++ y) {
for(var x = 0; x < 94; ++ x) {
var b = imData[i];
var g = imData[i + 1];
var r = imData[i + 2];
var hsl = rgbToHsl(r, g, b);
var c;
if(offsetH < 0)
c = hsl.h;//Math.abs(hsl2.h - offsetH) > 30 ? 0 : 255;
else
c = g;
imData[i] = imData[i + 1] = imData[i + 2] = c;
i += 4;
}
}
ctx.putImageData(img, offsetX, offsetY);
ctx.restore();
}
function save_rk() {
const offsetX = document.getElementById("OffsetX").value;
const offsetY = document.getElementById("OffsetY").value;
const offsetH = document.getElementById("OffsetH").value;
const File = new FILE86RK();
//
window.localStorage.OffsetX = offsetX;
window.localStorage.OffsetY = offsetY;
window.localStorage.OffsetH = offsetH;
//
var i = 0;
var dmp = [];
var txt = [];
//
dmp.push(...binary);
//
if(window.location.href.match(/#apogey/i)) {
fileName = fileName(/RKR$/, "RKA");
dmp[7] = 0xEF;
dmp[13] = 0xF0;
}
//
while(dmp.length < 256)
dmp.push(0);
//
//
for(var y = 0; y < 153; ++ y) {
for(var x = 0; x < 47; ++ x) {
var b1 = imData[i ++];
var g1 = imData[i ++];
var r1 = imData[i ++];
i ++;
var b2 = imData[i ++];
var g2 = imData[i ++];
var r2 = imData[i ++];
i ++;
if(offsetH < 0) {
switch(((g1 & 0xC0) >> 2) | ((g2 & 0xC0) >> 6)) {
case 0x00: dmp.push(0x00); break;
case 0x01: dmp.push(0x4A); break;
case 0x02: dmp.push(0x2F); break;
case 0x03: dmp.push(0x02); break;
case 0x10: dmp.push(0x4C); break;
case 0x11: dmp.push(0x22); break;
case 0x12: dmp.push(0x1B); break;
case 0x13: dmp.push(0x5D); break;
case 0x20: dmp.push(0x01); break;
case 0x21: dmp.push(0x1B); break;
case 0x22: dmp.push(0x70); break;
case 0x23: dmp.push(0x25); break;
case 0x30: dmp.push(0x35); break;
case 0x31: dmp.push(0x5B); break;
case 0x32: dmp.push(0x01); break;
case 0x33: dmp.push(0x03); break;
}
} else {
dmp.push((g1 > offsetH ? 1 : 0) | (g2 > offsetH ? 2 : 0));
}
}
if(y % 51 != 50)
dmp.push(0xF1);
else
if(y != 152)
dmp.push(0x7F);
}
dmp.push(0xF3, 0);
//
File.saveData(dmp);
//
File.saveFile(fileName);
}
</script>
<style>
div {
display :none;
}
</style>
</head>
<body>
<input id=Picture type=file onchange='open_file(this)' />
<div>
<input id=OffsetX type=number min=0 max=640 value=92 onchange='place()' />,
<input id=OffsetY type=number min=0 max=480 value=56 onchange='place()' />/
<input id=OffsetH type=number min=-7 max=255 value=128 onchange='place()' />
<button onclick='save_rk()'>Save</button><br />
<canvas id=Screen width=94 height=153></canvas>
</div>
</body>