Blame Scripts/CentOS-Art/Functions/Render/Svg/svg_convertPngToGrub.sh

4c79b5
#!/bin/bash
4c79b5
#
6b44b6
# svg_convertPngToGrub.sh -- This function provides post-rendition
6b44b6
# action used to produce GRUB images.
6b44b6
#
6b44b6
# Initially, the color information is defined with GIMP (The GNU Image
6b44b6
# Manipulation Program) as a `.gpl' palette of color. This palette of
6b44b6
# colors contains 14 colors only and is saved in a file named
6b44b6
# `grub.gpl.  The `grub.gpl' file is used to build the `grub.ppm' file
6b44b6
# which provide the color information needed to reduce the full color
6b44b6
# PNG image, produced as result of SVG base-rendition, to the amount
6b44b6
# of colors specified (i.e., 14 colors). Later, with the 14 color PNG
6b44b6
# image already created, the `grub.ppm' file is used to build the
6b44b6
# `splash.xpm.gz' file.
6b44b6
#
6b44b6
# In order for this function to work, the `grub.gpl' file should have
6b44b6
# a format similar to the following:
6b44b6
#
2fe9b7
# GIMP Palette
2fe9b7
# Name: CentOS-TreeFlower-4-Syslinux
2fe9b7
# Columns: 14
2fe9b7
# #
2fe9b7
# 32  76 141	204c8d
2fe9b7
# 36  82 146	245292
2fe9b7
# 52  93 152	345d98
2fe9b7
# 72 108 162	486ca2
2fe9b7
# 102 131 176	6683b0
2fe9b7
# 126 153 190	7e99be
2fe9b7
# 146 170 200	92aac8
2fe9b7
# 161 182 209	a1b6d1
2fe9b7
# 182 199 219	b6c7db
2fe9b7
# 202 214 228	cad6e4
2fe9b7
# 221 230 238	dde6ee
2fe9b7
# 235 241 245	ebf1f5
2fe9b7
# 246 251 254	f6fbfe
2fe9b7
# 254 255 252	fefffc
4c79b5
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
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
6b44b6
function 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.
8c13b6
    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
6b44b6
    # provided by the design model through subversion (to keep track
6b44b6
    # of the change) and expand translation markers in the copied
6b44b6
    # instance.
33f612
    if [[ ! -f $PALETTE_GPL ]];then
6b44b6
        svn cp ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/grub.gpl ${PALETTE_GPL}
54cb18
        cli_expandTMarkers ${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.
8c13b6
    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
}