width = 106
height = `perl -e 'print int($(width) * 0.50)'`
threshold1 = 0.54
threshold2 = 0.90

target = kurumi.txt

all: $(target)

$(target): layer1.txt layer2.txt merge_layers.rb trim_space.pl freq.pl
	ruby merge_layers.rb layer1.txt layer2.txt | perl trim_space.pl > $@
	perl freq.pl $@

layer1.txt: kurumi.png Makefile pgmtotxt.pl
	pngtopnm $< | pamscale -xsize=$(width) -ysize=$(height) | pamthreshold -simple -threshold=$(threshold1) | pamtopnm | ppmtopgm | perl pgmtotxt.pl > layer1.txt

layer2.txt: kurumi.png Makefile pgmtotxt.pl alpha_shift_diagonal.pl
	pngtopnm $< | pamscale -xsize=$(width) -ysize=$(height) | pamthreshold -simple -threshold=$(threshold2) | pamtopnm | ppmtopgm | perl pgmtotxt.pl | sed -e 's/X/a/g' | perl alpha_shift_diagonal.pl > layer2.txt

clean:
	-rm -f $(target) layer{1,2}.txt
