Update 'palette-gen.js'

This commit is contained in:
sora 2023-06-17 02:42:25 +02:00 committed by soraefir
parent 1563bb0815
commit 5af7dcbbe7
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
24 changed files with 37 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
palette.in
palette.out

24
Makefile Normal file
View File

@ -0,0 +1,24 @@
SRCDIR:= img
DSTDIR:= build
SOURCES := $(wildcard $(SRCDIR)/*)
FILES := $(patsubst $(SRCDIR)/%,$(DSTDIR)/%,$(SOURCES))
all: $(FILES)
@echo $(SOURCES)
@echo $(FILES)
palette.out: palette.in
node palette-gen.js < palette.in > palette.out
builddir:
@mkdir -p build
build/%.jpg: img/%.jpg builddir palette.out
repalette $@< $@ -p $$(cat palette.out) --dither $$DITHER
build/%.png: img/%.png builddir palette.out
repalette $< $@ -p $$(cat palette.out) --dither $$DITHER
clean:
@rm -rf palette.in palette.out build

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

Before

Width:  |  Height:  |  Size: 2.5 MiB

After

Width:  |  Height:  |  Size: 2.5 MiB

View File

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

Before

Width:  |  Height:  |  Size: 959 KiB

After

Width:  |  Height:  |  Size: 959 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View File

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

Before

Width:  |  Height:  |  Size: 2.9 MiB

After

Width:  |  Height:  |  Size: 2.9 MiB

View File

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -1,7 +1,7 @@
#!/bin/nodejs
const componentToHex = (c) => ("0" + c.toString(16)).slice(-2);
const rgbToHex = (c) => "#" + componentToHex(c.r) + componentToHex(c.g) + componentToHex(c.b);
const rgbToHex = (c) => componentToHex(c.r) + componentToHex(c.g) + componentToHex(c.b);
const hexToRgb = (hex) => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
@ -31,5 +31,12 @@ const rl = readline.createInterface({
});
rl.on('line', (line) => {
console.log(parseScheme(line).map(e=>genPalette(e).map(c=>rgbToHex(c))));
console.log(
parseScheme(line)
.map(e=>
genPalette(e)
.map(c=>
rgbToHex(c)
)).join(",")
);
});