Blame Scripts/Functions/Render/render_svg_convertPngToGrub.sh

4c79b5
#!/bin/bash
4c79b5
#
42db09
# render_svg_convertPngToGrub.sh -- This function provides
42db09
# post-rendition action used to produce GRUB images.
4c79b5
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
42db09
function render_svg_convertPngToGrub {
4c79b5
80d088
    # Define number of colors the images will be produced on.
33f612
    local COLORS='14'
f16762
15b1d2
    # Define options using those passed to actions from pre-rendition
f16762
    # configuration script. These options are applied to pnmremap when
f16762
    # doing color reduction, so any option available for pnmremap
f16762
    # command can be passed to renderSyslinux functionality.
ab1d67
    local OPTIONS=$(render_getConfigOption "$ACTION" '2-')
f16762
f16762
    # Check options passed to action. This is required in order to
f16762
    # aviod using options used already in this script. For example
f16762
    # -verbose and -mapfile options.
f16762
    for OPTION in $OPTIONS;do
f16762
        # Remove anything after equal sign inside option.
eb0e14
        OPTION=$(echo -n $OPTION | cut -d'=' -f1)
f16762
        if [[ "$OPTION" =~ "-(mapfile|verbose)" ]];then
0ff158
            cli_printMessage "`eval_gettext "The \\\"\\\$OPTION\\\" option is already used."`" --as-error-line
f16762
        fi
f16762
    done
4c79b5
80d088
    # Define file name prefix.
33f612
    local PREFIX="-${COLORS}c"
80d088
80d088
    # Redefine file name prefix using options as reference. This is
80d088
    # useful to differenciate final files produced using
80d088
    # Floyd-Steinberg dithering and files which are not.
80d088
    if [[ "$OPTIONS" =~ '-floyd' ]];then
80d088
        PREFIX="${PREFIX}-floyd"
80d088
    fi
80d088
80d088
    # Define absolute path to GPL palette.  This palettes should have
80d088
    # 14 colors only. For more information on this see the GRUB's
80d088
    # documentation.
33f612
    local PALETTE_GPL=${MOTIF_DIR}/Palettes/grub.gpl
33f612
33f612
    # Verify GPL palette existence. If it doesn't exist copy the one
33f612
    # provided by the design model and expand translation markers in
33f612
    # it.
33f612
    if [[ ! -f $PALETTE_GPL ]];then
33f612
        cp ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/grub.gpl ${PALETTE_GPL}
33f612
        cli_replaceTMarkers ${PALETTE_GPL}
33f612
    fi
80d088
80d088
    # Define absolute path to PPM palette. The PPM palette is built
80d088
    # from source palette (PALETTE_GPL) and provides the color
80d088
    # information understood by `ppmremap', the program used to
80d088
    # produce images in a specific amount of colors.
80d088
    local PALETTE_PPM=$(cli_getTemporalFile "grub.ppm")
80d088
80d088
    # Create image in Netpbm superformat (PNM). The PNM image file is
80d088
    # created from the PNG image rendered previously as centos-art
80d088
    # base-rendition output. The PNM image is an intermediate format
80d088
    # used to manipulate images through Netpbm tools.
0ff158
    cli_printMessage "${FILE}.pnm" --as-savedas-line
4c79b5
    pngtopnm -verbose \
9b4d7d
        < ${FILE}.png 2>${FILE}.log > ${FILE}.pnm
4c79b5
80d088
    # Print the path to GPL palette.
0ff158
    cli_printMessage "$PALETTE_GPL" --as-palette-line
80d088
80d088
    # Create PPM palette using GPL palette.
33f612
    render_svg_convertGplToPpm "$PALETTE_GPL" "$PALETTE_PPM" "$COLORS"
80d088
80d088
    # Reduce colors as specified in PPM palette.  Here we use the PPM
80d088
    # palette to enforce the color position in the image index and the
80d088
    # Floyd-Steinberg dithering in order to improve color reduction.
0ff158
    cli_printMessage "${FILE}${PREFIX}.ppm" --as-savedas-line
379ebf
    pnmremap -verbose -mapfile=$PALETTE_PPM $OPTIONS \
9b4d7d
        < ${FILE}.pnm 2>>${FILE}.log > ${FILE}${PREFIX}.ppm
4c79b5
80d088
    # Remove PPM palette. It is no longer needed.
80d088
    if [[ -f ${PALETTE_PPM} ]];then
80d088
        rm $PALETTE_PPM
80d088
    fi
80d088
f16762
    # Create the 14 colors xpm.gz file.
0ff158
    cli_printMessage "${FILE}${PREFIX}.xpm.gz" --as-savedas-line
4c79b5
    ppmtoxpm \
9b4d7d
        < ${FILE}${PREFIX}.ppm 2>>${FILE}.log > ${FILE}.xpm \
9b4d7d
        && gzip --force ${FILE}.xpm \
9b4d7d
        && mv ${FILE}.xpm.gz ${FILE}${PREFIX}.xpm.gz
743971
4c79b5
}