BUILD: remove the last of the imagemagick stuff

The only remaining thing depending on imagemagick are the dist scripts
This commit is contained in:
Nick Zatkovich 2017-07-30 23:26:52 -07:00
parent 6724ef5aba
commit 215b7c644e
13 changed files with 149 additions and 182 deletions

View file

@ -16,8 +16,7 @@ OBJS=$(FREEDM) $(FREEDOOM1) $(FREEDOOM2)
all: $(OBJS) all: $(OBJS)
subdirs: subdirs:
$(MAKE) -C graphics/text $(MAKE) VERSION=$(VERSION) -C graphics/text
$(MAKE) VERSION=$(VERSION) -C graphics/titlepic
$(MAKE) -C lumps/playpal $(MAKE) -C lumps/playpal
$(MAKE) -C lumps/colormap $(MAKE) -C lumps/colormap
$(MAKE) -C lumps/genmidi $(MAKE) -C lumps/genmidi
@ -111,7 +110,6 @@ clean:
$(MAKE) -C dist clean $(MAKE) -C dist clean
$(MAKE) -C graphics/text clean $(MAKE) -C graphics/text clean
$(MAKE) -C graphics/titlepic clean
$(MAKE) -C lumps/playpal clean $(MAKE) -C lumps/playpal clean
$(MAKE) -C lumps/colormap clean $(MAKE) -C lumps/colormap clean
$(MAKE) -C lumps/genmidi clean $(MAKE) -C lumps/genmidi clean

View file

@ -16,3 +16,5 @@ credtext*.png
freettl.png freettl.png
helptext*.png helptext*.png
wikilrs_horiz.png wikilrs_horiz.png
fd?title.png
m_*.png

View file

@ -52,20 +52,20 @@ TEXTGEN_GRAPHIC_LUMPS = \
TEXTGEN_GRAPHICS = $(TEXTGEN_GRAPHIC_LUMPS) \ TEXTGEN_GRAPHICS = $(TEXTGEN_GRAPHIC_LUMPS) \
helpttl.png freettl.png helpttl.png freettl.png
all: textgen.mk help.png credit.png wikilrs.png wivctms.png all: text_strings help.png credit.png wikilrs.png wivctms.png titlepic
# Generate the menu and level strings # Generate the menu and level strings
textgen.mk: config.py fontchars ../../lumps/dehacked.lmp text_strings: config.py fontchars ../../lumps/dehacked.lmp
./textgen $@ python textgen.py
cp $(TEXTGEN_GRAPHIC_LUMPS) ../ cp $(TEXTGEN_GRAPHIC_LUMPS) ../
# Background for the help screen is a color shifted version of INTERPIC: # Background for the help screen is a color shifted version of INTERPIC:
helpbg.png: ../interpic.png helpbg.png: ../interpic.png
python tint.py ../interpic.png '#5599ff' helpbg.png python tint.py ../interpic.png '#57b9b0' helpbg.png
# Generate transparent image containing text for the HELP screen: # Generate transparent image containing text for the HELP screen:
help.png: helpttl.png helpbg.png help.png: text_strings helpbg.png
python smtextgen help.png 320x200 \ python smtextgen.py help.png 320x200 \
-background "helpbg.png" \ -background "helpbg.png" \
150,5 "file:helpttl.png" \ 150,5 "file:helpttl.png" \
10,25 "Weapons" \ 10,25 "Weapons" \
@ -97,8 +97,8 @@ help.png: helpttl.png helpbg.png
128,107 "file:../../sprites/pstra0.png" \ 128,107 "file:../../sprites/pstra0.png" \
170,115 "Armor" \ 170,115 "Armor" \
220,113 "file:../../sprites/bon2a0.png" \ 220,113 "file:../../sprites/bon2a0.png" \
240,105 "file:../../sprites/arm1b0.png" \ 240,113 "file:../../sprites/arm1b0.png" \
280,105 "file:../../sprites/arm2b0.png" \ 280,110 "file:../../sprites/arm2b0.png" \
145,140 "Map" \ 145,140 "Map" \
175,130 "file:../../sprites/pmapa0.png" \ 175,130 "file:../../sprites/pmapa0.png" \
10,140 "Overdrive" \ 10,140 "Overdrive" \
@ -122,30 +122,47 @@ help.png: helpttl.png helpbg.png
cp $@ ../ cp $@ ../
credit.png: freettl.png helpbg.png credit.txt credit.png: text_strings helpbg.png credit.txt
python smtextgen credit.png 320x200 \ python smtextgen.py credit.png 320x200 \
-background "helpbg.png" \ -background "helpbg.png" \
120,5 "file:freettl.png" \ 120,5 "file:freettl.png" \
10,30 "include:credit.txt" 10,30 "include:credit.txt"
cp $@ ../
wikilrs_horiz.png: wikilrs_horiz.png:
python smtextgen $@ 49x7 \ python smtextgen.py $@ 49x7 \
0,0 killers 0,0 killers
wikilrs.png: wikilrs_horiz.png wikilrs.png: wikilrs_horiz.png
python rotate.py wikilrs_horiz.png 90 $@ python rotate.py wikilrs_horiz.png -90 $@
cp $@ ../ cp $@ ../
wivctms.png: wivctms.png:
python smtextgen $@ 54x7 \ python smtextgen.py $@ 54x7 \
0,0 victims 0,0 victims
cp $@ ../ cp $@ ../
titlepic: fd1title.png fd2title.png fdmtitle.png
fd1title.png: text_strings ../titlepic/titlepic.png ../m_doom.png ../t_phase1.png
python create_caption.py ../titlepic/titlepic.png ../m_doom.png ../t_phase1.png $@
cp $@ ../
fd2title.png: text_strings ../titlepic/titlepic.png ../m_doom.png ../t_phase2.png
python create_caption.py ../titlepic/titlepic.png ../m_doom.png ../t_phase2.png $@
cp $@ ../
fdmtitle.png: ../titlepic/freedm_titlepic.png
python create_caption.py $< $@
cp $@ ../
clean: clean:
rm -f $(TEXTGEN_GRAPHICS) helpbg.png help.png helptext.png \ rm -f $(TEXTGEN_GRAPHICS) helpbg.png help.png \
helptext2.png graphics.stamp *.pyc credtext.png \ graphics.stamp *.pyc credtext.png \
credtext.png credit.png dmwilv*.png wikilrs.png \ credtext.png credit.png dmwilv*.png wikilrs.png \
wivctms.png wikilrs_horiz.png ../credit.png ../help.png \ wivctms.png wikilrs_horiz.png ../credit.png ../help.png \
../wikilrs.png ../wivctms.png ../wikilrs.png ../wivctms.png \
fd1title.png fd2title.png fdmtitle.png \
../fd1title.png ../fd2title.png ../fdmtitle.png
for graphic in $(TEXTGEN_GRAPHICS); do rm -f ../$$graphic; done for graphic in $(TEXTGEN_GRAPHICS); do rm -f ../$$graphic; done
rm -fr __pycache__ rm -fr __pycache__

View file

@ -1,46 +0,0 @@
# SPDX-License-Identifier: BSD-3-Clause
import re
import subprocess
import sys
from PIL import Image
# Output from 'identify' looks like this:
# fontchars/font033.png GIF 9x16 9x16+0+0 8-bit sRGB 32c 194B 0.000u 0:00.000
IDENTIFY_OUTPUT_RE = re.compile(r'(\S+)\s(\S+)\s(\d+)x(\d+)(\+\d+\+\d+)?\s')
# Regexp to identify strings that are all lowercase (can use shorter height)
LOWERCASE_RE = re.compile(r'^[a-z\!\. ]*$')
def get_image_dimensions(filename):
"""Get image dimensions w x h
Args:
filename: filename of the image
"""
with Image.open(filename) as img:
width, height = img.size
return (width, height)
def invoke_command(command):
"""Invoke a command, printing the command to stdout.
Args:
command: Command and arguments as a list.
"""
for arg in command:
if arg.startswith('-'):
sys.stdout.write("\\\n ")
if ' ' in arg or '#' in arg:
sys.stdout.write(repr(arg))
else:
sys.stdout.write(arg)
sys.stdout.write(' ')
sys.stdout.write('\n')
return subprocess.call(command)

View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
# coding=utf-8
from PIL import Image, ImageFont, ImageDraw
import sys
import os
#create_caption.py <background_image> <title?> <phase?> <outfile>
try:
font = ImageFont.truetype("DejaVuSansCondensed-Bold.ttf", 11)
except IOError:
font = ImageFont.load_default()
txt1= u"© 2001-2017"
txt2= os.environ['VERSION']
background_image = Image.open(sys.argv[1])
background_image.load()
background_image = background_image.convert("RGBA")
image = Image.new("RGBA", background_image.size, (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
txt1_size = draw.textsize(txt1, font=font)
txt2_size = draw.textsize(txt2, font=font)
draw.text((5, (image.height - txt1_size[1] - 5)), txt1, font=font, fill=(255,165,0,255))
draw.text(((image.width - txt2_size[0] - 10), (image.height - txt2_size[1] - 5)), txt2, font=font, fill=(255,165,0,255))
if len(sys.argv) > 3:
#paste the other stuff onto the thing.
logo = Image.open(sys.argv[2])
logo.load()
phase = Image.open(sys.argv[3])
phase.load()
image.paste(logo, ((image.width/2 - logo.width/2), 18))
image.paste(phase, ((image.width/2 - phase.width/2), (image.height - logo.height - 10)))
outfile_name = sys.argv[4]
else:
outfile_name = sys.argv[2]
image = Image.alpha_composite(background_image, image)
image.save(outfile_name)

View file

@ -0,0 +1,23 @@
# SPDX-License-Identifier: BSD-3-Clause
import re
from PIL import Image
def get_image_dimensions(filename):
"""Get image dimensions w x h
Args:
filename: filename of the image
"""
with Image.open(filename) as img:
width, height = img.size
return (width, height)
if __name__ == '__main__':
import sys
x,y = get_image_dimensions(sys.argv[1])
string = "%i %i" % (x, y)
sys.stdout.write(string)

View file

@ -9,7 +9,7 @@ from glob import glob
import sys import sys
import re import re
from common import * from image_dimensions import *
from tint import image_tint from tint import image_tint
# Background color for output files. # Background color for output files.
@ -108,41 +108,42 @@ def parse_command_line(args):
return result return result
if __name__ == '__main__':
args = parse_command_line(sys.argv[1:]) args = parse_command_line(sys.argv[1:])
if not args: if not args:
print("Usage: smtextgen <filename> <size> [...text commands...]") print("Usage: smtextgen <filename> <size> [...text commands...]")
print("Where each text command looks like:") print("Where each text command looks like:")
print(" [x,y] [text]") print(" [x,y] [text]")
sys.exit(0) sys.exit(0)
smallfont = Font() smallfont = Font()
if args['background'] is not None: if args['background'] is not None:
background_image = Image.open(args['background']) background_image = Image.open(args['background'])
background_image.load() background_image.load()
background_image = background_image.convert("RGBA") background_image = background_image.convert("RGBA")
image = Image.new("RGBA", args['dimensions'],(0,0,0,0)) image = Image.new("RGBA", args['dimensions'],(0,0,0,0))
for xy, string in args['strings']: for xy, string in args['strings']:
# Allow contents of a file to be included with special prefix: # Allow contents of a file to be included with special prefix:
if string.startswith(':'): if string.startswith('include:'):
with open(string[8:]) as f: with open(string[8:]) as f:
string = f.read() string = f.read()
# Allow special notation to indicate an image file to just draw # Allow special notation to indicate an image file to just draw
# rather than rendering a string. # rather than rendering a string.
if string.startswith('file:'): if string.startswith('file:'):
src_image = Image.open(string[5:]) src_image = Image.open(string[5:])
src_image.load() src_image.load()
image.paste(src_image, (xy[0], xy[1])) image.paste(src_image, (xy[0], xy[1]))
else: else:
smallfont.draw_for_text(image, string, xy[0], xy[1]) smallfont.draw_for_text(image, string, xy[0], xy[1])
if args['background'] is not None: if args['background'] is not None:
image = Image.alpha_composite(background_image, image) image = Image.alpha_composite(background_image, image)
image.save(args['filename']) image.save(args['filename'])

View file

@ -11,10 +11,10 @@ import re
import sys import sys
from config import * from config import *
from common import * from image_dimensions import *
from tint import image_tint from tint import image_tint
# ImageMagick -colorize parameters for colorizing text: # Tinting parameters for colorizing text:
COLOR_BLUE = "#000001" COLOR_BLUE = "#000001"
COLOR_RED = "#010000" COLOR_RED = "#010000"
COLOR_WHITE = None COLOR_WHITE = None
@ -31,6 +31,7 @@ UPPERCASE_FONT = False
# Width of a space character in pixels. # Width of a space character in pixels.
SPACE_WIDTH = 7 SPACE_WIDTH = 7
LOWERCASE_RE = re.compile(r'^[a-z\!\. ]*$')
class Font(object): class Font(object):
@ -109,8 +110,7 @@ class Font(object):
if c is None: if c is None:
return x return x
def generate_graphic(self, text, output_filename, def generate_graphic(self, text, color=COLOR_WHITE):
color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR):
"""Get command to render text to a file """Get command to render text to a file
with the given background color. with the given background color.
""" """
@ -136,15 +136,15 @@ class Font(object):
txt_image.paste(char_image, (x, height - FONT_HEIGHT)) txt_image.paste(char_image, (x, height - FONT_HEIGHT))
txt_image = image_tint(txt_image, color) txt_image = image_tint(txt_image, color)
txt_image.save(output_filename) return txt_image
def generate_graphics(graphics, color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR): def generate_graphics(graphics, color=COLOR_WHITE):
for name, text in sorted(graphics.items()): for name, text in sorted(graphics.items()):
# write a makefile fragment # write a makefile fragment
target = '%s.png' % name target = '%s.png' % name
font.generate_graphic(text, target, image = font.generate_graphic(text, color=color)
color=color, bgcolor=bgcolor) image.save(target)
def generate_kerning_test(): def generate_kerning_test():
@ -158,12 +158,9 @@ def generate_kerning_test():
cmd = font.generate_graphic(" ".join(pairs), "kerning.png") cmd = font.generate_graphic(" ".join(pairs), "kerning.png")
if __name__ == '__main__':
font = Font('fontchars', kerning_table=FONT_KERNING_RULES) font = Font('fontchars', kerning_table=FONT_KERNING_RULES)
generate_graphics(red_graphics, color=COLOR_RED)
# Enable to generate test image file for tweaking kerning values: generate_graphics(blue_graphics, color=COLOR_BLUE)
#generate_kerning_test() generate_graphics(white_graphics, color=COLOR_WHITE)
generate_graphics(red_graphics, color=COLOR_RED)
generate_graphics(blue_graphics, color=COLOR_BLUE)
generate_graphics(white_graphics, color=COLOR_WHITE)

View file

@ -1,12 +1,10 @@
#/usr/bin/env python #/usr/bin/env python
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# Copyright (c) 2017 Martin Miller # Copyright (c) 2017 Martin Miller, Nick Zatkovich
# https://stackoverflow.com/questions/12251896/colorize-image-while-preserving-transparency-with-pil # https://stackoverflow.com/questions/12251896/colorize-image-while-preserving-transparency-with-pil
from PIL import Image from PIL import Image, ImageColor, ImageOps
from ImageColor import getcolor, getrgb
from ImageOps import grayscale
def image_tint(image, tint=None): def image_tint(image, tint=None):
if tint is None: if tint is None:
@ -14,8 +12,8 @@ def image_tint(image, tint=None):
if image.mode not in ['RGB', 'RGBA']: if image.mode not in ['RGB', 'RGBA']:
image = image.convert('RGBA') image = image.convert('RGBA')
tr, tg, tb = getrgb(tint) tr, tg, tb = ImageColor.getrgb(tint)
tl = getcolor(tint, "L") # tint color's overall luminosity tl = ImageColor.getcolor(tint, "L") # tint color's overall luminosity
if not tl: if not tl:
tl = 1 # avoid division by zero tl = 1 # avoid division by zero
tl = float(tl) # compute luminosity preserving tint factors tl = float(tl) # compute luminosity preserving tint factors
@ -27,7 +25,7 @@ def image_tint(image, tint=None):
luts = (map(lambda lr: int(lr * sr + 0.5), range(256)) + luts = (map(lambda lr: int(lr * sr + 0.5), range(256)) +
map(lambda lg: int(lg * sg + 0.5), range(256)) + map(lambda lg: int(lg * sg + 0.5), range(256)) +
map(lambda lb: int(lb * sb + 0.5), range(256))) map(lambda lb: int(lb * sb + 0.5), range(256)))
l = grayscale(image) # 8-bit luminosity version of whole image l = ImageOps.grayscale(image) # 8-bit luminosity version of whole image
if Image.getmodebands(image.mode) < 4: if Image.getmodebands(image.mode) < 4:
merge_args = (image.mode, (l, l, l)) # for RGB verion of grayscale merge_args = (image.mode, (l, l, l)) # for RGB verion of grayscale
else: # include copy of image's alpha layer else: # include copy of image's alpha layer

View file

@ -1,2 +0,0 @@
fd?title.png
m_*.png

View file

@ -1,19 +0,0 @@
titlepic: fd1title.png fd2title.png fdmtitle.png
fd1title.png: titlepic.png ../m_doom.png ../t_phase1.png
./create_caption titlepic.png ../m_doom.png ../t_phase1.png $@
cp $@ ../
fd2title.png: titlepic.png ../m_doom.png ../t_phase2.png
./create_caption titlepic.png ../m_doom.png ../t_phase2.png $@
cp $@ ../
fdmtitle.png: freedm_titlepic.png
./create_caption $< $@
cp $@ ../
clean:
rm -f fd1title.png fd2title.png fdmtitle.png \
../fd1title.png ../fd2title.png ../fdmtitle.png
.PHONY: clean

View file

@ -1,4 +1,2 @@
This directory contains a shell script that uses ImageMagick to layer This directory contains template images for generating the title screen
some text information about the build version onto the game's title for Freedoom Phase 1, Phase 2, and FreeDM
screen. The same is performed for each of the three IWADs.

View file

@ -1,40 +0,0 @@
#!/bin/sh
find_font() {
local font fontlist
fontlist=$(convert -list font | awk '$1=="Font:" { print $2 }')
for font in "$@" ; do
if echo $fontlist | grep -q $font ; then
echo $font
return
fi
done
}
font=$(find_font Helvetica-Bold Liberation-Sans-Bold DejaVu-Sans-Condensed-Bold)
if [ -z "$font" ] ; then echo "Cannot find any fonts" ; exit 1 ; fi
draw_with_footer() {
input_file=$1;
output_file=$2;
shift; shift
convert $input_file -fill orange -font "$font" +dither \
-pointsize 11 \
-gravity southwest \
-draw "text 5,5 '© 2001-2017'" \
-gravity southeast \
-draw "text 10,5 '$VERSION'" \
"$@" \
$output_file
}
if [ $# = 4 ]; then
draw_with_footer "$1" "$4" \
-gravity north \
-draw "image over 0,18 0,0 '$2'" \
-gravity south \
-draw "image over 0,30 0,0 '$3'"
else
draw_with_footer "$1" "$2"
fi