Blame Scripts/Bash/Functions/Render/Svg/svg_convertPngToGrub.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# svg_convertPngToGrub.sh -- This function provides post-rendition
878a2b
# action used to produce GRUB images.
878a2b
#
878a2b
# Initially, the color information is defined with GIMP (The GNU Image
878a2b
# Manipulation Program) as a `.gpl' palette of color. This palette of
878a2b
# colors contains 14 colors only and is saved in a file named
878a2b
# `grub.gpl.  The `grub.gpl' file is used to build the `grub.ppm' file
878a2b
# which provide the color information needed to reduce the full color
878a2b
# PNG image, produced as result of SVG base-rendition, to the amount
878a2b
# of colors specified (i.e., 14 colors). Later, with the 14 color PNG
878a2b
# image already created, the `grub.ppm' file is used to build the
878a2b
# `splash.xpm.gz' file.
878a2b
#
878a2b
# In order for this function to work, the `grub.gpl' file should have
878a2b
# a format similar to the following:
878a2b
#
878a2b
# GIMP Palette
878a2b
# Name: CentOS-TreeFlower-4-Syslinux
878a2b
# Columns: 14
878a2b
# #
878a2b
# 32  76 141	204c8d
878a2b
# 36  82 146	245292
878a2b
# 52  93 152	345d98
878a2b
# 72 108 162	486ca2
878a2b
# 102 131 176	6683b0
878a2b
# 126 153 190	7e99be
878a2b
# 146 170 200	92aac8
878a2b
# 161 182 209	a1b6d1
878a2b
# 182 199 219	b6c7db
878a2b
# 202 214 228	cad6e4
878a2b
# 221 230 238	dde6ee
878a2b
# 235 241 245	ebf1f5
878a2b
# 246 251 254	f6fbfe
878a2b
# 254 255 252	fefffc
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function svg_convertPngToGrub {
878a2b
878a2b
    # Define number of colors the images will be produced on.
878a2b
    local COLORS='14'
878a2b
878a2b
    # Define options using those passed to actions from pre-rendition
878a2b
    # configuration script. These options are applied to pnmremap when
878a2b
    # doing color reduction, so any option available for pnmremap
878a2b
    # command can be passed to renderSyslinux functionality.
878a2b
    local OPTIONS=$(render_getConfigOption "$ACTION" '2-')
878a2b
878a2b
    # Check options passed to action. This is required in order to
878a2b
    # aviod using options used already in this script. For example
878a2b
    # -verbose and -mapfile options.
878a2b
    for OPTION in $OPTIONS;do
878a2b
        # Remove anything after equal sign inside option.
878a2b
        OPTION=$(echo -n $OPTION | cut -d'=' -f1)
878a2b
        if [[ "$OPTION" =~ "-(mapfile|verbose)" ]];then
878a2b
            cli_printMessage "`eval_gettext "The \\\"\\\$OPTION\\\" option is already used."`" --as-error-line
878a2b
        fi
878a2b
    done
878a2b
878a2b
    # Define file name prefix.
878a2b
    local PREFIX="-${COLORS}c"
878a2b
878a2b
    # Redefine file name prefix using options as reference. This is
878a2b
    # useful to differenciate final files produced using
878a2b
    # Floyd-Steinberg dithering and files which are not.
878a2b
    if [[ "$OPTIONS" =~ '-floyd' ]];then
878a2b
        PREFIX="${PREFIX}-floyd"
878a2b
    fi
878a2b
684e48
    # Define logs' file. Log files are stored in the same place of
684e48
    # images and are used to store output information produced by
684e48
    # programs when the image files are built up.
684e48
    local LOGS=${FILE}${PREFIX}.log
684e48
878a2b
    # Define absolute path to GPL palette.  This palettes should have
878a2b
    # 14 colors only. For more information on this see the GRUB's
878a2b
    # documentation.
878a2b
    local PALETTE_GPL=${MOTIF_DIR}/Palettes/grub.gpl
878a2b
878a2b
    # Verify GPL palette existence. If it doesn't exist copy the one
878a2b
    # provided by the design model through subversion (to keep track
878a2b
    # of the change) and expand translation markers in the copied
878a2b
    # instance.
878a2b
    if [[ ! -f $PALETTE_GPL ]];then
878a2b
        svn cp ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/grub.gpl ${PALETTE_GPL}
878a2b
        cli_expandTMarkers ${PALETTE_GPL}
878a2b
    fi
878a2b
878a2b
    # Define absolute path to PPM palette. The PPM palette is built
878a2b
    # from source palette (PALETTE_GPL) and provides the color
878a2b
    # information understood by `ppmremap', the program used to
878a2b
    # produce images in a specific amount of colors.
878a2b
    local PALETTE_PPM=$(cli_getTemporalFile "grub.ppm")
878a2b
878a2b
    # Create image in Netpbm superformat (PNM). The PNM image file is
878a2b
    # created from the PNG image rendered previously as centos-art
878a2b
    # base-rendition output. The PNM image is an intermediate format
878a2b
    # used to manipulate images through Netpbm tools.
878a2b
    cli_printMessage "${FILE}.pnm" --as-savedas-line
878a2b
    pngtopnm -verbose \
684e48
        < ${FILE}.png 2>${LOGS} > ${FILE}.pnm
878a2b
878a2b
    # Print the path to GPL palette.
878a2b
    cli_printMessage "$PALETTE_GPL" --as-palette-line
878a2b
878a2b
    # Create PPM palette using GPL palette.
878a2b
    svg_convertGplToPpm "$PALETTE_GPL" "$PALETTE_PPM" "$COLORS"
878a2b
878a2b
    # Reduce colors as specified in PPM palette.  Here we use the PPM
878a2b
    # palette to enforce the color position in the image index and the
878a2b
    # Floyd-Steinberg dithering in order to improve color reduction.
878a2b
    cli_printMessage "${FILE}${PREFIX}.ppm" --as-savedas-line
878a2b
    pnmremap -verbose -mapfile=$PALETTE_PPM $OPTIONS \
684e48
        < ${FILE}.pnm 2>>${LOGS} > ${FILE}${PREFIX}.ppm
878a2b
878a2b
    # Remove PPM palette. It is no longer needed.
878a2b
    if [[ -f ${PALETTE_PPM} ]];then
878a2b
        rm $PALETTE_PPM
878a2b
    fi
878a2b
878a2b
    # Create the 14 colors xpm.gz file.
878a2b
    cli_printMessage "${FILE}${PREFIX}.xpm.gz" --as-savedas-line
878a2b
    ppmtoxpm \
684e48
        < ${FILE}${PREFIX}.ppm 2>>${LOGS} > ${FILE}.xpm \
878a2b
        && gzip --force ${FILE}.xpm \
878a2b
        && mv ${FILE}.xpm.gz ${FILE}${PREFIX}.xpm.gz
878a2b
878a2b
}