-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixelart.html
More file actions
858 lines (723 loc) · 44.2 KB
/
pixelart.html
File metadata and controls
858 lines (723 loc) · 44.2 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
<!--
This webpage uses culori (https://github.com/Evercoder/culori),
portion of rebane's MapartCraft's (https://github.com/rebane2001/mapartcraft) ported version of redstonehelper's Mapconverter (https://github.com/redstonehelper/MapConverter),
Prismarine NBT (https://github.com/PrismarineJS/prismarine-nbt)
and pako (https://github.com/nodeca/pako)
culori is licensed as:
MIT License
Copyright (c) 2018 Dan Burzo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MapartCraft is licensed as GPLv3.0:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Pako is licensed as:
The MIT License
Copyright (C) 2014-2017 by Vitaly Puzrin and Andrei Tuputcyn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Image to Pixel Art</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="./culori.min.js"></script>
<script src="./pnbt.js"></script>
<script>
const nbt = require('prismarine-nbt');
</script>
<script src="./pako.min.js"></script>
<style>
.hidden {
display: none;
}
#progress {
position: fixed;
z-index: 1;
left: 50%;
top: 50%;
padding: 0;
margin: 0;
}
#dropzone {
position: fixed;
top: 0;
left: 0;
z-index: 999;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
transition: visibility 175ms, opacity 175ms;
}
.inline-table {
display: inline-table;
}
.img-inline {
padding: 0 0.5em;
vertical-align: text-top;
}
.canvas-scroll {
overflow: scroll;
max-width: 100%;
}
</style>
</head>
<body>
<div id="dropzone" style="visibility:hidden; opacity:0"></div>
<div id="main">
<header class="w3-container w3-dark-grey">
<h2>Image to Pixel Art (for in-game and world map)</h2>
</header>
<div class="w3-panel w3-pale-yellow">
Images resized to above 1000x1000 pixels may not load for now.
</div>
<div class="w3-container">
<h3>Session</h3>
Load: <select class="w3-container w3-cell" id="session_load"><option value=""></option></select>
<button id="session_save">Save</button>
<button id="session_delete" disabled="disabled">Delete</button>
</div>
<div class="w3-container w3-cell">
<h3>Palette</h3>
<div class="w3-container">
<input type="checkbox" id="palette_all">
<label for="palette_all">All</label>
</div>
<div class="w3-container w3-cell" id="palette1"></div>
<div class="w3-container w3-cell" id="palette2"></div>
<div class="w3-container w3-cell" id="palette3"></div>
</div>
<div class="w3-container w3-cell">
<h3>Glasses</h3>
<small><i>Adds glass layer</i></small>
<div class="w3-container w3-cell" id="glasses"></div>
</div>
<div class="w3-container w3-cell">
<h3>Options</h3>
<div class="w3-container">
Orientation:
<select id="orientation">
<option value="0" selected="selected">↕ Vertical</option>
<option value="1">↔ Horizontal</option>
</select>
</div>
<div class="w3-container">
Max width:
<input type="number" id="max_width" style="max-width: 4.5em;"><br>
Max height:
<input type="number" id="max_height" style="max-width: 4.5em;">
</div>
<div class="w3-container">
Dithering:
<select id="dither">
<option value="0">None</option>
<option value="1">Floyd-Steinberg</option>
<option value="2" selected="selected">Atkinson</option>
</select>
</div>
<div class="w3-container">
Color comparison:
<select id="color_diff">
<option value="0">Cie76</option>
<option value="1" selected="selected">Ciede2000</option>
<option value="C">MapartCraft Custom</option>
</select>
</div>
<div class="w3-container">
Background color:
<input type="color" id="bg_color" value="#FFFFFF">
</div>
<div class="w3-container">
<input type="checkbox" id="transparent_color_enabled">
Air color</small>:
<input type="color" id="transparent_color" value="#000000" disabled="disabled">
</div>
</div>
<form class="w3-container w3-cell">
<h3>Upload image file</h3>
<input accept="image/*" type="file" id="image_input" class="w3-input">
<div class="w3-container" id="canvas_orig_container">
<span id="canvas_orig_dimensions"></span><br>
<canvas id="canvas_orig"></canvas>
</div>
</form>
<div class="w3-container">
<div class="w3-container w3-cell" id="palette4"></div>
<div class="w3-container w3-cell" id="palette5"></div>
</div>
<div id="progress" class="w3-panel w3-center hidden">
<i id="spinner" class="fa fa-spinner w3-spin" style="font-size: 48px"></i><br>
<span id="progress_text"></span>
</div>
<div id="results" class="w3-container hidden">
<h3>Result</h3>
<div class="w3-row-padding">
<div class="w3-col m4 l3">
<button id="download"><i class="fa fa-download"></i> Download as .schem - <span id="schematic_dimensions"></span></button>
<br><br>
<div id="material_list"><i class="fa-regular fa-copy"></i> Materials <span id="material_list_copy" class="w3-tag w3-teal w3-round hidden">Copied!</span></div>
<textarea id="material_list_count" class="w3-input w3-monospace" readonly="readonly"></textarea>
</div>
<div class="w3-col m8 l9">
<label for="result_zoom">Zoom</label>
<input type="range" id="result_zoom" value="15" min="0" max="30">
<div class="canvas-scroll">
<canvas id="canvas_result"></canvas>
</div>
</div>
</div>
</div>
</div>
<script src="/js/pixelart/session.js"></script>
<script type="module">
import { xyzToKey, convertToSchem} from './js/schematics.js';
const worker = new Worker('./jsworker/pixelartworker.js');
const ORIENTATION_VERTICAL = "0";
const ORIENTATION_HORIZONTAL = "1";
//This can be used to compare with mapartcraft
/*
const palette = [
{name: 'White Wool', file: 'white_wool.png', id: 'white_wool', color: 'rgb(220, 220, 220)'},
{name: 'Light Gray Wool', file: 'light_gray_wool.png', id: 'light_gray_wool', color: 'rgb(132, 132, 132)'},
{name: 'Gray Wool', file: 'gray_wool.png', id: 'gray_wool', color: 'rgb(65, 65, 65)'},
{name: 'Black Wool', file: 'black_wool.png', id: 'black_wool', color: 'rgb(21, 21, 21)'},
{name: 'Brown Wool', file: 'brown_wool.png', id: 'brown_wool', color: 'rgb(88, 65, 44)'},
{name: 'Red Wool', file: 'red_wool.png', id: 'red_wool', color: 'rgb(132, 44, 44)'},
{name: 'Orange Wool', file: 'orange_wool.png', id: 'orange_wool', color: 'rgb(186, 109, 44)'},
{name: 'Yellow Wool', file: 'yellow_wool.png', id: 'yellow_wool', color: 'rgb(197, 197, 44)'},
{name: 'Lime Wool', file: 'lime_wool.png', id: 'lime_wool', color: 'rgb(109, 176, 21)'},
{name: 'Green Wool', file: 'green_wool.png', id: 'green_wool', color: 'rgb(88, 109, 44)'},
{name: 'Cyan Wool', file: 'cyan_wool.png', id: 'cyan_wool', color: 'rgb(65, 109, 132)'},
{name: 'Light Blue Wool', file: 'light_blue_wool.png', id: 'light_blue_wool', color: 'rgb(88, 132, 186)'},
{name: 'Blue Wool', file: 'blue_wool.png', id: 'blue_wool', color: 'rgb(44, 65, 153)'},
{name: 'Purple Wool', file: 'purple_wool.png', id: 'purple_wool', color: 'rgb(109, 54, 153)'},
{name: 'Magenta Wool', file: 'magenta_wool.png', id: 'magenta_wool', color: 'rgb(153, 65, 186)'},
{name: 'Pink Wool', file: 'pink_wool.png', id: 'pink_wool', color: 'rgb(208, 109, 142)'},
];
*/
//The colors are obtained doing average calculation of all pixels of a texture
//This can be done with img2color.html
const palette1 = [
{name: 'White Wool', file: 'white_wool.png', id: 'white_wool', color: '#eaeded', block: 'minecraft:white_wool'},
{name: 'Light Gray Wool', file: 'light_gray_wool.png', id: 'light_gray_wool', color: '#8e8e86', block: 'minecraft:light_gray_wool'},
{name: 'Gray Wool', file: 'gray_wool.png', id: 'gray_wool', color: '#3f4447', block: 'minecraft:gray_wool'},
{name: 'Black Wool', file: 'black_wool.png', id: 'black_wool', color: '#141519', block: 'minecraft:black_wool'},
{name: 'Brown Wool', file: 'brown_wool.png', id: 'brown_wool', color: '#724828', block: 'minecraft:brown_wool'},
{name: 'Red Wool', file: 'red_wool.png', id: 'red_wool', color: '#a12722', block: 'minecraft:red_wool'},
{name: 'Orange Wool', file: 'orange_wool.png', id: 'orange_wool', color: '#f17613', block: 'minecraft:orange_wool'},
{name: 'Yellow Wool', file: 'yellow_wool.png', id: 'yellow_wool', color: '#f9c627', block: 'minecraft:yellow_wool'},
{name: 'Lime Wool', file: 'lime_wool.png', id: 'lime_wool', color: '#70b91a', block: 'minecraft:lime_wool'},
{name: 'Green Wool', file: 'green_wool.png', id: 'green_wool', color: '#556d1b', block: 'minecraft:green_wool'},
{name: 'Cyan Wool', file: 'cyan_wool.png', id: 'cyan_wool', color: '#158a91', block: 'minecraft:cyan_wool'},
{name: 'Light Blue Wool', file: 'light_blue_wool.png', id: 'light_blue_wool', color: '#3aafd9', block: 'minecraft:light_blue_wool'},
{name: 'Blue Wool', file: 'blue_wool.png', id: 'blue_wool', color: '#35399e', block: 'minecraft:blue_wool'},
{name: 'Purple Wool', file: 'purple_wool.png', id: 'purple_wool', color: '#7a2aad', block: 'minecraft:purple_wool'},
{name: 'Magenta Wool', file: 'magenta_wool.png', id: 'magenta_wool', color: '#be45b4', block: 'minecraft:magenta_wool'},
{name: 'Pink Wool', file: 'pink_wool.png', id: 'pink_wool', color: '#ee8dac', block: 'minecraft:pink_wool'},
];
addPalette(palette1, document.getElementById("palette1"), 'All Wool', 'palette_all_wool');
const palette2 = [
{name: 'White Concrete', file: 'white_concrete.png', id: 'white_concrete', color: '#cfd5d6', block: 'minecraft:white_concrete'},
{name: 'Light Gray Concrete', file: 'light_gray_concrete.png', id: 'light_gray_concrete', color: '#7d7d73', block: 'minecraft:light_gray_concrete'},
{name: 'Gray Concrete', file: 'gray_concrete.png', id: 'gray_concrete', color: '#36393d', block: 'minecraft:gray_concrete'},
{name: 'Black Concrete', file: 'black_concrete.png', id: 'black_concrete', color: '#080a0f', block: 'minecraft:black_concrete'},
{name: 'Brown Concrete', file: 'brown_concrete.png', id: 'brown_concrete', color: '#613c20', block: 'minecraft:brown_concrete'},
{name: 'Red Concrete', file: 'red_concrete.png', id: 'red_concrete', color: '#8f2121', block: 'minecraft:red_concrete'},
{name: 'Orange Concrete', file: 'orange_concrete.png', id: 'orange_concrete', color: '#e06101', block: 'minecraft:orange_concrete'},
{name: 'Yellow Concrete', file: 'yellow_concrete.png', id: 'yellow_concrete', color: '#f1b015', block: 'minecraft:yellow_concrete'},
{name: 'Lime Concrete', file: 'lime_concrete.png', id: 'lime_concrete', color: '#5ea918', block: 'minecraft:lime_concrete'},
{name: 'Green Concrete', file: 'green_concrete.png', id: 'green_concrete', color: '#495b24', block: 'minecraft:green_concrete'},
{name: 'Cyan Concrete', file: 'cyan_concrete.png', id: 'cyan_concrete', color: '#157788', block: 'minecraft:cyan_concrete'},
{name: 'Light Blue Concrete', file: 'light_blue_concrete.png', id: 'light_blue_concrete', color: '#2389c7', block: 'minecraft:light_blue_concrete'},
{name: 'Blue Concrete', file: 'blue_concrete.png', id: 'blue_concrete', color: '#2c2e8f', block: 'minecraft:blue_concrete'},
{name: 'Purple Concrete', file: 'purple_concrete.png', id: 'purple_concrete', color: '#65209d', block: 'minecraft:purple_concrete'},
{name: 'Magenta Concrete', file: 'magenta_concrete.png', id: 'magenta_concrete', color: '#a9309f', block: 'minecraft:magenta_concrete'},
{name: 'Pink Concrete', file: 'pink_concrete.png', id: 'pink_concrete', color: '#d6658f', block: 'minecraft:pink_concrete'},
];
addPalette(palette2, document.getElementById("palette2"), 'All Concrete', 'palette_all_concrete');
const palette3 = [
{name: 'White Terracotta', file: 'white_terracotta.png', id: 'white_terracotta', color: '#d2b2a1', block: 'minecraft:white_terracotta'},
{name: 'Light Gray Terracotta', file: 'light_gray_terracotta.png', id: 'light_gray_terracotta', color: '#876b62', block: 'minecraft:light_gray_terracotta'},
{name: 'Gray Terracotta', file: 'gray_terracotta.png', id: 'gray_terracotta', color: '#3a2a24', block: 'minecraft:gray_terracotta'},
{name: 'Black Terracotta', file: 'black_terracotta.png', id: 'black_terracotta', color: '#251710', block: 'minecraft:black_terracotta'},
{name: 'Brown Terracotta', file: 'brown_terracotta.png', id: 'brown_terracotta', color: '#4d3324', block: 'minecraft:brown_terracotta'},
{name: 'Red Terracotta', file: 'red_terracotta.png', id: 'red_terracotta', color: '#8f3d2f', block: 'minecraft:red_terracotta'},
{name: 'Orange Terracotta', file: 'orange_terracotta.png', id: 'orange_terracotta', color: '#a25426', block: 'minecraft:orange_terracotta'},
{name: 'Yellow Terracotta', file: 'yellow_terracotta.png', id: 'yellow_terracotta', color: '#ba8523', block: 'minecraft:yellow_terracotta'},
{name: 'Lime Terracotta', file: 'lime_terracotta.png', id: 'lime_terracotta', color: '#687635', block: 'minecraft:lime_terracotta'},
{name: 'Green Terracotta', file: 'green_terracotta.png', id: 'green_terracotta', color: '#4c532a', block: 'minecraft:green_terracotta'},
{name: 'Cyan Terracotta', file: 'cyan_terracotta.png', id: 'cyan_terracotta', color: '#575b5b', block: 'minecraft:cyan_terracotta'},
{name: 'Light Blue Terracotta', file: 'light_blue_terracotta.png', id: 'light_blue_terracotta', color: '#716d8a', block: 'minecraft:light_blue_terracotta'},
{name: 'Blue Terracotta', file: 'blue_terracotta.png', id: 'blue_terracotta', color: '#4a3c5b', block: 'minecraft:blue_terracotta'},
{name: 'Purple Terracotta', file: 'purple_terracotta.png', id: 'purple_terracotta', color: '#764656', block: 'minecraft:purple_terracotta'},
{name: 'Magenta Terracotta', file: 'magenta_terracotta.png', id: 'magenta_terracotta', color: '#96586d', block: 'minecraft:magenta_terracotta'},
{name: 'Pink Terracotta', file: 'pink_terracotta.png', id: 'pink_terracotta', color: '#a24e4f', block: 'minecraft:pink_terracotta'},
{name: 'Terracotta', file: 'terracotta.png', id: 'terracotta', color: '#985e44', block: 'minecraft:terracotta'},
];
addPalette(palette3, document.getElementById("palette3"), 'All Terracotta', 'palette_all_terracotta');
const palette4 = [
{name: 'Birch Planks', file: 'birch_planks.png', id: 'birch_planks', color: '#c1af79', block: 'minecraft:birch_planks'},
{name: 'Bamboo Planks', file: 'bamboo_planks.png', id: 'bamboo_planks', color: '#c1ad51', block: 'minecraft:bamboo_planks'},
{name: 'Oak Planks', file: 'oak_planks.png', id: 'oak_planks', color: '#a2834e', block: 'minecraft:oak_planks'},
{name: 'Jungle Planks', file: 'jungle_planks.png', id: 'jungle_planks', color: '#a17351', block: 'minecraft:jungle_planks'},
{name: 'Acacia Planks', file: 'acacia_planks.png', id: 'acacia_planks', color: '#a95a32', block: 'minecraft:acacia_planks'},
{name: 'Spruce Planks', file: 'spruce_planks.png', id: 'spruce_planks', color: '#735531', block: 'minecraft:spruce_planks'},
{name: 'Warped Planks', file: 'warped_planks.png', id: 'warped_planks', color: '#2b6963', block: 'minecraft:warped_planks'},
{name: 'Dark Oak Planks', file: 'dark_oak_planks.png', id: 'dark_oak_planks', color: '#432b15', block: 'minecraft:dark_oak_planks'},
{name: 'Mangrove Planks', file: 'mangrove_planks.png', id: 'mangrove_planks', color: '#753631', block: 'minecraft:mangrove_planks'},
{name: 'Crimson Planks', file: 'crimson_planks.png', id: 'crimson_planks', color: '#663147', block: 'minecraft:crimson_planks'},
{name: 'Cherry Planks', file: 'cherry_planks.png', id: 'cherry_planks', color: '#e2b2ad', block: 'minecraft:cherry_planks'},
];
addPalette(palette4, document.getElementById("palette4"), 'All Planks', 'palette_all_planks');
const palette5 = [
{name: 'Birch Log', file: ['birch_log.png', 'birch_log_top.png'], id: 'birch_log', color: ['#d9d7d2', '#c1b387'], block: 'minecraft:birch_log[axis=y]'},
{name: 'Birch Log (top)', file: ['birch_log_top.png', 'birch_log.png'], id: 'birch_log_top', color: ['#c1b387', '#d9d7d2'], block: 'minecraft:birch_log[axis=z]'},
{name: 'Bamboo Block', file: ['bamboo_block.png', 'bamboo_block_top.png'], id: 'bamboo_block', color: ['#8b8e3e', '#7f903a'], block: 'minecraft:bamboo_block[axis=y]'},
{name: 'Bamboo Block (top)', file: ['bamboo_block_top.png', 'bamboo_block.png'], id: 'bamboo_block_top', color: ['#7f903a', '#8b8e3e'], block: 'minecraft:bamboo_block[axis=z]'},
{name: 'Oak Log', file: ['oak_log.png', 'oak_log_top.png'], id: 'oak_log', color: ['#6e5533', '#977a48'], block: 'minecraft:oak_log[axis=y]'},
{name: 'Oak Log (top)', file: ['oak_log_top.png', 'oak_log.png'], id: 'oak_log_top', color: ['#977a48', '#6e5533'], block: 'minecraft:oak_log[axis=z]'},
{name: 'Jungle Log', file: ['jungle_log.png', 'jungle_log_top.png'], id: 'jungle_log', color: ['#554419', '#966d47'], block: 'minecraft:jungle_log[axis=y]'},
{name: 'Jungle Log (top)', file: ['jungle_log_top.png', 'jungle_log.png'], id: 'jungle_log_top', color: ['#966d47', '#554419'], block: 'minecraft:jungle_log[axis=z]'},
{name: 'Acacia Log', file: ['acacia_log.png', 'acacia_log_top.png'], id: 'acacia_log', color: ['#676057', '#975937'], block: 'minecraft:acacia_log[axis=y]'},
{name: 'Acacia Log (top)', file: ['acacia_log_top.png', 'acacia_log.png'], id: 'acacia_log_top', color: ['#975937', '#676057'], block: 'minecraft:acacia_log[axis=z]'},
{name: 'Spruce Log', file: ['spruce_log.png', 'spruce_log_top.png'], id: 'spruce_log', color: ['#3b2611', '#6d512f'], block: 'minecraft:spruce_log[axis=y]'},
{name: 'Spruce Log (top)', file: ['spruce_log_top.png', 'spruce_log.png'], id: 'spruce_log_top', color: ['#6d512f', '#3b2611'], block: 'minecraft:spruce_log[axis=z]'},
{name: 'Warped Stem', file: ['warped_stem.png', 'warped_stem_top.png'], id: 'warped_stem', color: ['#3a3b4e', '#356e6e'], block: 'minecraft:warped_stem[axis=y]'},
{name: 'Warped Stem (top)', file: ['warped_stem_top.png', 'warped_stem.png'], id: 'warped_stem_top', color: ['#356e6e', '#3a3b4e'], block: 'minecraft:warped_stem[axis=z]'},
{name: 'Dark Oak Log', file: ['dark_oak_log.png', 'dark_oak_log_top.png'], id: 'dark_oak_log', color: ['#3c2f1a', '#432d16'], block: 'minecraft:dark_oak_log[axis=y]'},
{name: 'Dark Oak Log (top)', file: ['dark_oak_log_top.png', 'dark_oak_log.png'], id: 'dark_oak_log_top', color: ['#432d16', '#3c2f1a'], block: 'minecraft:dark_oak_log[axis=z]'},
{name: 'Mangrove Log', file: ['mangrove_log.png', 'mangrove_log_top.png'], id: 'mangrove_log', color: ['#544229', '#67312b'], block: 'minecraft:mangrove_log[axis=y]'},
{name: 'Mangrove Log (top)', file: ['mangrove_log_top.png', 'mangrove_log.png'], id: 'mangrove_log_top', color: ['#67312b', '#544229'], block: 'minecraft:mangrove_log[axis=z]'},
{name: 'Crimson Stem', file: ['crimson_stem.png', 'crimson_stem_top.png'], id: 'crimson_stem', color: ['#5e1a1e', '#713246'], block: 'minecraft:crimson_stem[axis=y]'},
{name: 'Crimson Stem (top)', file: ['crimson_stem_top.png', 'crimson_stem.png'], id: 'crimson_stem_top', color: ['#713246', '#5e1a1e'], block: 'minecraft:crimson_stem[axis=z]'},
{name: 'Cherry Log', file: ['cherry_log.png', 'cherry_log_top.png'], id: 'cherry_log', color: ['#37212c', '#b98d89'], block: 'minecraft:cherry_log[axis=y]'},
{name: 'Cherry Log (top)', file: ['cherry_log_top.png', 'cherry_log.png'], id: 'cherry_log_top', color: ['#b98d89', '#37212c'], block: 'minecraft:cherry_log[axis=z]'},
];
addPalette(palette5, document.getElementById("palette5"), 'All Logs', 'palette_all_logs');
const glasses = [
{name: 'White Stained Glass', file: 'white_stained_glass.png', id: 'white_stained_glass', color: '#ffffff75', block: 'minecraft:white_stained_glass'},
{name: 'Light Gray Stained Glass', file: 'light_gray_stained_glass.png', id: 'light_gray_stained_glass', color: '#98989875', block: 'minecraft:light_gray_stained_glass'},
{name: 'Gray Stained Glass', file: 'gray_stained_glass.png', id: 'gray_stained_glass', color: '#4b4b4b75', block: 'minecraft:gray_stained_glass'},
{name: 'Black Stained Glass', file: 'black_stained_glass.png', id: 'black_stained_glass', color: '#19191975', block: 'minecraft:black_stained_glass'},
{name: 'Brown Stained Glass', file: 'brown_stained_glass.png', id: 'brown_stained_glass', color: '#664b3275', block: 'minecraft:brown_stained_glass'},
{name: 'Red Stained Glass', file: 'red_stained_glass.png', id: 'red_stained_glass', color: '#98323275', block: 'minecraft:red_stained_glass'},
{name: 'Orange Stained Glass', file: 'orange_stained_glass.png', id: 'orange_stained_glass', color: '#d7803275', block: 'minecraft:orange_stained_glass'},
{name: 'Yellow Stained Glass', file: 'yellow_stained_glass.png', id: 'yellow_stained_glass', color: '#e6e63275', block: 'minecraft:yellow_stained_glass'},
{name: 'Lime Stained Glass', file: 'lime_stained_glass.png', id: 'lime_stained_glass', color: '#80cd1975', block: 'minecraft:lime_stained_glass'},
{name: 'Green Stained Glass', file: 'green_stained_glass.png', id: 'green_stained_glass', color: '#66803275', block: 'minecraft:green_stained_glass'},
{name: 'Cyan Stained Glass', file: 'cyan_stained_glass.png', id: 'cyan_stained_glass', color: '#4b809875', block: 'minecraft:cyan_stained_glass'},
{name: 'Light Blue Stained Glass', file: 'light_blue_stained_glass.png', id: 'light_blue_stained_glass', color: '#6698d775', block: 'minecraft:light_blue_stained_glass'},
{name: 'Blue Stained Glass', file: 'blue_stained_glass.png', id: 'blue_stained_glass', color: '#324bb275', block: 'minecraft:blue_stained_glass'},
{name: 'Purple Stained Glass', file: 'purple_stained_glass.png', id: 'purple_stained_glass', color: '#803eb275', block: 'minecraft:purple_stained_glass'},
{name: 'Magenta Stained Glass', file: 'magenta_stained_glass.png', id: 'magenta_stained_glass', color: '#b24bd775', block: 'minecraft:magenta_stained_glass'},
{name: 'Pink Stained Glass', file: 'pink_stained_glass.png', id: 'pink_stained_glass', color: '#f280a575', block: 'minecraft:pink_stained_glass'},
{name: 'Tinted Glass', file: 'tinted_glass.png', id: 'tinted_glass', color: '#2c272d83', block: 'minecraft:tinted_glass'},
];
addPalette(glasses, document.getElementById('glasses'), 'All Glasses', 'palette_all_glasses', {unchecked: true});
function addPalette(palette, domContainer, allText, id, args) {
const checked = (args == undefined || !args.unchecked);
if (allText) {
const domCheckbox = document.createElement("input");
domCheckbox.type = "checkbox";
domCheckbox.setAttribute("id", id);
domCheckbox.checked = checked;
domCheckbox.addEventListener("input", togglePalette);
domContainer.appendChild(domCheckbox);
const domLabel = document.createElement("label");
domLabel.htmlFor = id;
domLabel.innerHTML = " " + allText;
domContainer.appendChild(domLabel);
const domBr = document.createElement("br");
domContainer.appendChild(domBr);
}
for (const pal of palette) {
const actualId = 'palette_' + pal.id;
const domCheckbox = document.createElement("input");
domCheckbox.type = "checkbox";
domCheckbox.classList.add("toggle-with-" + id);
domCheckbox.setAttribute("id", actualId);
domCheckbox.checked = checked;
domCheckbox.addEventListener("input", runResult);
domContainer.appendChild(domCheckbox);
const domLabel = document.createElement("label");
domLabel.htmlFor = actualId;
if (typeof pal.file === 'string')
{
const domImg = document.createElement("img");
domImg.src = './textures/' + pal.file;
domImg.classList.add("img-inline");
domImg.onload = function() {
createImageBitmap(this).then((value) => pal.img = value);
};
domLabel.appendChild(domImg);
}
else {
for (let i = 0; i < pal.file.length; i++) {
pal.img = [];
const domImg = document.createElement("img");
domImg.src = './textures/' + pal.file[i];
domImg.classList.add("img-inline");
domImg.classList.add("img-orientation" + i);
domImg.onload = function() {
createImageBitmap(this).then((value) => pal.img[i] = value);
};
domLabel.appendChild(domImg);
}
}
const domContent = document.createTextNode(pal.name);
domLabel.appendChild(domContent);
domContainer.appendChild(domLabel);
const domBr = document.createElement("br");
domContainer.appendChild(domBr);
}
}
const palettes = [palette1, palette2, palette3, palette4, palette5];
const domImageInput = document.getElementById("image_input");
const domCanvasOrigContainer = document.getElementById("canvas_orig_container");
const domCanvasOrigDimensions = document.getElementById("canvas_orig_dimensions");
const domCanvasOrig = document.getElementById("canvas_orig");
const canvasOrigCtx = domCanvasOrig.getContext("2d", { willReadFrequently: true });
const domCanvasResult = document.getElementById("canvas_result");
const canvasResultCtx = domCanvasResult.getContext("bitmaprenderer");
const domMaxWidth = document.getElementById('max_width');
const domMaxHeight = document.getElementById('max_height');
const domOrientation = document.getElementById("orientation");
const domDither = document.getElementById("dither");
const domColorDiff = document.getElementById("color_diff")
const domBackgroundColor = document.getElementById("bg_color");
const domTransparentColor = document.getElementById("transparent_color")
const domTransparentColorEnabled = document.getElementById("transparent_color_enabled");
const domMaterialList = document.getElementById('material_list');
const domMaterialListCopy = document.getElementById('material_list_copy');
const domMaterialListCount = document.getElementById('material_list_count');
const domDownload = document.getElementById("download");
const domResultZoom = document.getElementById("result_zoom");
const results = document.getElementById("results");
const domProgress = document.getElementById("progress");
const domProgressText = document.getElementById("progress_text");
const spinner = document.getElementById("spinner");
const dropzone = document.getElementById("dropzone");
var lastTarget = null; //cache for drag and drop events
var lastFile = null; //cache for refreshing when an option is changed
let fileLoaded = false;
let schematic;
let width, height;
document.getElementById('palette_all').addEventListener("input", function() {
const inputs = document.getElementsByTagName('input');
for (const input of inputs) {
if (input.type !== 'checkbox') continue;
if (input.parentElement && input.parentElement.id.startsWith("palette"))
input.checked = this.checked;
}
runResult();
});
function togglePalette() {
const checkboxes = document.getElementsByClassName('toggle-with-' + this.id);
for (const checkbox of checkboxes) {
checkbox.checked = this.checked;
}
runResult();
}
document.addEventListener("dragover", event => {
event.preventDefault(); // prevent default to allow drop
});
document.addEventListener("dragenter", function (e) {
lastTarget = e.target; // cache the last target here
// unhide our dropzone overlay
dropzone.style.visibility = "";
dropzone.style.opacity = 1;
});
document.addEventListener("dragleave", function (e) {
// this is the magic part. when leaving the window,
// e.target happens to be exactly what we want: what we cached
// at the start, the dropzone we dragged into.
// so..if dragleave target matches our cache, we hide the dropzone.
// `e.target === document` is a workaround for Firefox 57
if (e.target === lastTarget || e.target === document) {
dropzone.style.visibility = "hidden";
dropzone.style.opacity = 0;
}
});
document.addEventListener("drop", function (e) {
e.preventDefault(); // prevent dragged file from being opened
dropzone.style.visibility = "hidden";
dropzone.style.opacity = 0;
if (e.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
for (let i = 0; i < e.dataTransfer.items.length; i++) {
// If dropped items aren't files, reject them
if (e.dataTransfer.items[i].kind === 'file') {
const file = e.dataTransfer.items[i].getAsFile();
handleInput(file);
break;
}
}
}
else {
// Use DataTransfer interface to access the file(s)
if (e.dataTransfer.files.length > 0) {
handleInput(e.dataTransfer.files[0]);
}
}
});
domImageInput.addEventListener("change", function (event) {
const fileList = this.files;
if (fileList.length > 0) {
handleInput(fileList[0]);
}
}, false);
function handleInput(file) {
domProgress.classList.remove("hidden");
domProgressText.innerText = '';
results.classList.add("hidden");
lastFile = null;
schematic = null;
const img = new Image();
img.onload = onImageLoad;
img.src = URL.createObjectURL(file);
lastFile = file;
}
function onImageLoad() {
domCanvasOrigDimensions.innerText = `Dimensions: ${this.naturalWidth}x${this.naturalHeight}`;
const maxWidth = domCanvasOrigContainer.clientWidth;
if (this.naturalWidth <= maxWidth) {
domCanvasOrig.width = this.naturalWidth;
domCanvasOrig.height = this.naturalHeight;
}
else {
domCanvasOrig.width = maxWidth;
domCanvasOrig.height = this.naturalHeight * maxWidth / this.naturalWidth;
}
canvasOrigCtx.drawImage(this, 0, 0, domCanvasOrig.width, domCanvasOrig.height);
fileLoaded = true;
runResult();
}
function runResult() {
if (!fileLoaded) return;
domProgress.classList.remove("hidden");
domProgressText.innerText = '';
//Can't copy DOM elements to workers, so fetches the checked value now
for (const palette of palettes) {
for (const pal of palette) {
pal.checked = document.getElementById('palette_' + pal.id).checked;
}
}
for (const pal of glasses) {
pal.checked = document.getElementById('palette_' + pal.id).checked;
}
worker.postMessage({
orientation: domOrientation.value,
maxWidth: domMaxWidth.value,
maxHeight: domMaxHeight.value,
palettes: palettes,
glasses: glasses,
colorDiff: domColorDiff.value,
dither: domDither.value,
bgColor: domBackgroundColor.value,
transparentColor: domTransparentColorEnabled.checked ? domTransparentColor.value : undefined,
imageData: canvasOrigCtx.getImageData(0, 0, domCanvasOrig.width, domCanvasOrig.height),
});
}
worker.onmessage = function(e) {
if (!e.data) {
// Happens if all palettes are disabled
schematic = null;
results.classList.remove("hidden");
domProgress.classList.add("hidden");
return;
}
if (e.data.progress) {
// In progress
domProgressText.innerText = e.data.progress;
return;
}
if (e.data.schematic) {
// Pixel Art Complete
schematic = e.data.schematic;
const imageBitmap = e.data.imageBitmap;
width = e.data.width;
height = e.data.height;
document.getElementById('schematic_dimensions').innerText = `Dimensions: ${width / 16}x${height / 16}`;
const zoom = getZoom();
domCanvasResult.width = width * zoom;
domCanvasResult.height = height * zoom;
canvasResultCtx.transferFromImageBitmap(imageBitmap);
results.classList.remove("hidden");
domProgress.classList.add("hidden");
// Material List
insertMaterialList(domMaterialListCount, e.data.sortedByCount);
results.scrollIntoView({ behavior: "smooth"});
}
}
const NBSP = String.fromCharCode(160); //non-breaking space
const CRLF = String.fromCharCode(13, 10); //new line
function insertMaterialList(dom, materialList) {
let html = ["```"];
//calculate paddings
let nameMaxLength = 0;
let amountMaxLength = 0;
for (const [key, val] of materialList) {
if (nameMaxLength < key.length)
nameMaxLength = key.length;
const text = convertToBoxStack(key, val);
if (amountMaxLength < text.length)
amountMaxLength = text.length;
}
//insert each entry
for (const [key, val] of materialList) {
html.push(key.padEnd(nameMaxLength, NBSP) + NBSP + convertToBoxStack(key, val).padStart(amountMaxLength, NBSP) + " = " + val);
}
html.push("```");
dom.setAttribute('rows', html.length);
dom.innerHTML = html.join(CRLF);
}
domMaterialList.addEventListener('click', function() {
//for mobile devices
domMaterialListCount.select();
domMaterialListCount.setSelectionRange(0, 99999);
navigator.clipboard.writeText(domMaterialListCount.value);
domMaterialListCopy.classList.remove("hidden");
setTimeout(function () {
domMaterialListCopy.classList.add("hidden");
}, 2000);
});
function convertToBoxStack(item, amount) {
let array = [];
const maxCount = 64;
const boxes = Math.floor(amount / (27 * maxCount));
let remainder = amount % (27 * maxCount);
let stacks = 0;
if (maxCount > 1) {
stacks = Math.floor(remainder / maxCount);
remainder %= maxCount;
}
if (boxes > 0) {
array.push(boxes + " B");
}
if (stacks > 0) {
array.push(("" + stacks).padStart(2) + " S");
}
else {
array.push(NBSP.repeat(4));
}
if (remainder > 0) {
array.push(("" + remainder).padStart(2) + " I");
}
else {
array.push(NBSP.repeat(4));
}
return array.join(NBSP);
}
domMaxWidth.addEventListener("change", runResult);
domMaxHeight.addEventListener("change", runResult);
domDither.addEventListener("input", runResult);
domColorDiff.addEventListener("input", runResult);
domBackgroundColor.addEventListener("input", runResult);
domTransparentColor.addEventListener("input", runResult);
domTransparentColorEnabled.addEventListener("input", function() {
domTransparentColor.disabled = !domTransparentColor.disabled;
runResult();
});
domDownload.addEventListener("click", function(event) {
if (schematic) {
let filename = lastFile.name;
filename = filename.substring(0, filename.lastIndexOf('.'));
if (domOrientation.value === ORIENTATION_VERTICAL)
filename += "_vertical.schem";
else
filename += "_horizontal.schem";
const buffer = convertToSchem(schematic);
download(filename, buffer);
}
});
function download(filename, uint8array) {
const element = document.createElement("a");
const blob = new Blob([uint8array], {type: "application/octet-stream"});
element.setAttribute('href', window.URL.createObjectURL(blob));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
domResultZoom.addEventListener("input", function() {
if (width && height) {
const zoom = getZoom();
domCanvasResult.width = width * zoom;
domCanvasResult.height = height * zoom;
}
});
function getZoom() {
//each step zooms by +/- 25%
return Math.pow(1.25, +domResultZoom.value - domResultZoom.defaultValue);
}
function hideOtherOrientation() {
for (const el of document.getElementsByClassName('img-orientation0')) {
if (domOrientation.value === ORIENTATION_VERTICAL)
el.classList.remove("hidden");
else
el.classList.add("hidden");
}
for (const el of document.getElementsByClassName('img-orientation1')) {
if (domOrientation.value === ORIENTATION_HORIZONTAL)
el.classList.remove("hidden");
else
el.classList.add("hidden");
}
}
domOrientation.addEventListener("input", function() {
hideOtherOrientation();
runResult();
});
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", onDOMLoad);
}
else {
onDOMLoad();
}
function onDOMLoad() {
loadSessionNames();
hideOtherOrientation();
}
setOnSessionLoad(runResult);
</script>
</body>
</html>