# websrc/pictools/MakeResources # This is an 'include' makefile for # augmenting an .../images/... directory # with files made from soures # in a .../resources/... directory # The only clever bits are those that know how to convert files # to transparent backgrounds while eliminating the "halo" effect. # See TRANSPARENTSURROUND and TRANSPARENTBACKGROUND, below. # The Makefile has this form: # # include $(PICTOOLS)/MakeResources # # $(PICTOOLS)/MakeVars is included below, # so the facilitites defined therein are available. # In particular, this Makefile supports SUBDIRS # and the targets build and buildall. Upload is # supported in that it causes build to happen. #/---------------------------------------------------------\ #| Applicable Variables #| The following variables are, or may be, defined: #| #| IMAGESDIR - defined herein as the directory #| into which files are built or copied. #| The invoking Makefile may set this variable itself #| to choose another directory as the destination. #| #| IMAGEDIRFILES - Names -- without directory - of files #| to be built or copied into IMAGESDIR. #| The default is to copy a file. (Although usually #| such files can simply reside directly in .../images/...) #| If the file needs to be built, a rule to build it must be #| written. It should have the form: #| $(IMAGESDIR)/file: source file(s) #| commands to make the sources into $@ #| #| BUILDFILES #| Additional files to be created for the 'build' target. #| There must also be rules for building these files. #| #| TRANSPARENTBACKGROUND #| TRANSPARENTSURROUND #| When an image is placed on a background, dithering #| usually leak colors between the background into the image. #| Then when the image background is made transparent and #| the image is placed on a background of another color, #| a halo appears around it. Similar artifacts occur when #| anti-aliasing is applied to soften jagged lines. # #| This Makefile tool provides two halo reduction tricks. #| Each makes the background transparent and the halo pixels #| semi-transparent. When the image is laid over a new #| background its pixels will glimmer through. #| The first trick, TRANSPARENTBACKGROUND, makes transparent #| all instances of the background color. #| The second, TRANSPARENTSURROUND, makes transparent #| only those background color pixels which form the edge #| and adjacent pixels. #| #| The algorithm works best if the original background #| is light, or even white. #| #| The commands nobg and nosur are used. By default they #| treat all pixels within 5% (the default fuzzpct) of the #| transparent color as also being that color. #\--------------------------------------------------------/ include $(PICTOOLS)/MakeVars # get parallel directory ../.../images/... ifndef IMAGESDIR IMAGESDIR = $(subst /resources/,/images/,$(CURDIR)/.) endif _DESTFILES = $(IMAGEDIRFILES:%=$(IMAGESDIR)/%)\ _NOBGF = $(foreach name,$(TRANSPARENTBACKGROUND), \ $(IMAGESDIR)/$(basename $(name)).png) _NOSURF = $(foreach name,$(TRANSPARENTSURROUND), \ $(IMAGESDIR)/$(basename $(name)).png) build: $(IMAGESDIR) transbuild $(_DESTFILES) $(BUILDFILES) buildall: build subdirs upload: build subdirs: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir $(MAKECMDGOALS); \ done $(IMAGESDIR): mkdir -p $(IMAGESDIR) # to get the dependencies we want, we build `tmake' and $(MAKE) it # (perhaps this could be done with .SECONDEXPANSION) transbuild: @tmak=Tmake.$$$$; \ echo transbuild: $(_NOBGF) $(_NOSURF) > $$tmak; \ for name in $(TRANSPARENTBACKGROUND); \ do \ echo $(IMAGESDIR)/$${name%.*}.png: $$name >>$$tmak; \ echo ' sh $(PICTOOLS)/nobg $$< $$@' >>$$tmak; \ done; \ for name in $(TRANSPARENTSURROUND); \ do \ echo $(IMAGESDIR)/$${name%.*}.png: $$name >>$$tmak; \ echo ' sh $(PICTOOLS)/nosur $$< $$@' >>$$tmak; \ done; \ $(MAKE) -f $$tmak transbuild; \ rm $$tmak $(IMAGESDIR)/%: % cp $< $@ #################################### # clean .PHONY: clean clean: rm -rf $(JUNKFILES) @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir clean; \ done