#!/bin/sh

# Convert an image to LILO bootsplash format using ImageMagick's convert:
#   - BMP version 3 file format
#   - 16 colors indexed palette
#   - 640x480 size (will be stretched from original)
#
# Uses: sed, convert, identify.
# Author: Eric Hameleers <alien@slackware.com>

INPUT="$1"
if [ -z "$INPUT" ]; then
  echo "** Please provide image filename!"
  exit 1
fi
BASENAME=${INPUT##*/}
OUTPUT=${BASENAME%.*}.bmp

echo "-- Converting '${INPUT}' to './${OUTPUT}'"
convert "${INPUT}" -resize 640x480\! -colors 16 bmp3:${OUTPUT}

echo "-- LILO's 'bmp-colors' and 'bmp-timer' need to use these palette indices:" 
identify -verbose ${OUTPUT} |sed  '/ Colormap: /,/ Rendering /!d;//d'

