#!/usr/bin/make -f

%:
	dh $@

create-icons:
	# requires inkscape and imagemagick to be installed
	@if [ ! -x /usr/bin/inkscape ]; then \
		echo "ERROR: inkscape not installed!" ; \
		false ; \
	fi
	
	for f in aptosid-icon aptosid aptosid2; do \
		[ -r  $(CURDIR)/calamares/branding/aptosid/$${f}.svg ] || false ; \
		inkscape --export-type="png" \
			 --export-filename="$(CURDIR)/calamares/branding/aptosid/$${f}.png" \
			$(CURDIR)/calamares/branding/aptosid/$${f}.svg ; \
	done

	# slideshow mascots (fred), rasterised larger than their small native
	# size so they stay crisp when scaled in the QML slideshow.
	# streaked-fred and unstreaked-fred share a canvas and are layered in
	# show.qml (sharp fred over motion streaks), so export both at the same
	# height to keep them pixel-aligned.
	inkscape --export-type="png" --export-height=480 \
		--export-filename="$(CURDIR)/calamares/branding/aptosid/streaked-fred.png" \
		$(CURDIR)/calamares/branding/aptosid/streaked-fred.svg
	inkscape --export-type="png" --export-height=480 \
		--export-filename="$(CURDIR)/calamares/branding/aptosid/unstreaked-fred.png" \
		$(CURDIR)/calamares/branding/aptosid/unstreaked-fred.svg
	# fred world map (thanatos sddm background), shrunk for slideshow slide 3;
	# rendered larger than displayed so the tiled freds stay legible
	inkscape --export-type="png" --export-height=480 \
		--export-filename="$(CURDIR)/calamares/branding/aptosid/fred-world.png" \
		$(CURDIR)/calamares/branding/aptosid/fred-world.svg
	# big fred (close-up) lunging from the corner on the sign-off slide;
	# rendered near native size so it stays crisp when shown large
	inkscape --export-type="png" --export-height=640 \
		--export-filename="$(CURDIR)/calamares/branding/aptosid/big-fred.png" \
		$(CURDIR)/calamares/branding/aptosid/big-fred.svg
	# feather his cropped top/right/bottom edges into transparency so they
	# blend with the dark slideshow backdrop instead of ending in a hard
	# line. The left edge is left crisp so his face stays sharp.
	set -e; d="$(CURDIR)/calamares/branding/aptosid"; \
		w=$$(magick identify -format '%w' "$$d/big-fred.png"); \
		h=$$(magick identify -format '%h' "$$d/big-fred.png"); f=90; \
		magick -size $${w}x$${h} xc:black -fill white \
			-draw "rectangle 0,$$f $$((w-f)),$$((h-f))" -blur 0x35 "$$d/_mask.png"; \
		magick "$$d/big-fred.png" -alpha extract "$$d/_a.png"; \
		magick "$$d/_a.png" "$$d/_mask.png" -compose multiply -composite "$$d/_na.png"; \
		magick "$$d/big-fred.png" "$$d/_na.png" -alpha off \
			-compose CopyOpacity -composite "$$d/big-fred.png"; \
		rm -f "$$d/_mask.png" "$$d/_a.png" "$$d/_na.png"
