Blame Automation/centos-art.sh-render/Svg/svg_convertPngToSyslinux.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_convertPngToSyslinux.sh -- This function provides post-rendition
Alain Reguera Delgado 8f60cb
# action used to produce LSS16 images, the images used by isolinux.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Initially, the color information is defined with GIMP (The GNU Image
Alain Reguera Delgado 8f60cb
# Manipulation Program) as a `.gpl' palette of color. This palette of
Alain Reguera Delgado 8f60cb
# colors contains 16 colors only and is saved in a file named
Alain Reguera Delgado 8f60cb
# `syslinux.gpl.  The `syslinux.gpl' file is used to build two other
Alain Reguera Delgado 8f60cb
# files: the `syslinux.ppm' file and the `syslinux.hex' file. The
Alain Reguera Delgado 8f60cb
# `syslinux.ppm' provides the color information needed to reduce the
Alain Reguera Delgado 8f60cb
# full color PNG image, produced as result of SVG base-rendition, to
Alain Reguera Delgado 8f60cb
# the amount of colors specified (i.e., 16 colors). Later, with the 16
Alain Reguera Delgado 8f60cb
# color PNG image already created, the `syslinux.hex' file is used to
Alain Reguera Delgado 8f60cb
# build the LSS16 image.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# In order to produce images in LSS16 format correctly, it is required
Alain Reguera Delgado 8f60cb
# that both the `syslinux.ppm' and `syslinux.hex' files do contain the
Alain Reguera Delgado 8f60cb
# same color information. This is, both `syslinux.ppm' and
Alain Reguera Delgado 8f60cb
# `syslinux.hex' must represent the same color values and in the same
Alain Reguera Delgado 8f60cb
# color index.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# In order for this function to work, the `syslinux.gpl' file should
Alain Reguera Delgado 8f60cb
# have a format similar to the following:
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# GIMP Palette
Alain Reguera Delgado 8f60cb
# Name: CentOS-TreeFlower-4-Syslinux
Alain Reguera Delgado 8f60cb
# Columns: 16
Alain Reguera Delgado 8f60cb
# #
Alain Reguera Delgado 8f60cb
# 32  76 141	204c8d
Alain Reguera Delgado 8f60cb
# 37  82 146	255292
Alain Reguera Delgado 8f60cb
# 52  94 153	345e99
Alain Reguera Delgado 8f60cb
# 73 110 162	496ea2
Alain Reguera Delgado 8f60cb
# 91 124 172	5b7cac
Alain Reguera Delgado 8f60cb
# 108 136 180	6c88b4
Alain Reguera Delgado 8f60cb
# 120 146 186	7892ba
Alain Reguera Delgado 8f60cb
# 131 158 193	839ec1
Alain Reguera Delgado 8f60cb
# 255 255 255	ffffff
Alain Reguera Delgado 8f60cb
# 146 170 200	92aac8
Alain Reguera Delgado 8f60cb
# 162 182 209	a2b6d1
Alain Reguera Delgado 8f60cb
# 183 199 219	b7c7db
Alain Reguera Delgado 8f60cb
# 204 216 230	ccd8e6
Alain Reguera Delgado 8f60cb
# 221 229 238	dde5ee
Alain Reguera Delgado 8f60cb
# 235 241 245	ebf1f5
Alain Reguera Delgado 8f60cb
# 246 251 254	f6fbfe
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function svg_convertPngToSyslinux {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define number of colors the images will be produced on.
Alain Reguera Delgado 8f60cb
    local COLORS='16'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define options using those passed to actions from pre-rendition
Alain Reguera Delgado 8f60cb
    # configuration script. These options are applied to pnmremap when
Alain Reguera Delgado 8f60cb
    # doing color reduction, so any option available for pnmremap
Alain Reguera Delgado 8f60cb
    # command can be passed to renderSyslinux functionality.
Alain Reguera Delgado 8f60cb
    local OPTIONS=$(render_getConfigOption "$ACTION" '2-')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Check options passed to action. This is required in order to
Alain Reguera Delgado 8f60cb
    # aviod using options already used in this script. For example
Alain Reguera Delgado 8f60cb
    # -verbose and -mapfile options.
Alain Reguera Delgado 8f60cb
    for OPTION in $OPTIONS;do
Alain Reguera Delgado 8f60cb
        # Remove anything after equal sign inside option.
Alain Reguera Delgado 8f60cb
        OPTION=$(echo $OPTION | cut -d'=' -f1)
Alain Reguera Delgado 8f60cb
        if [[ "$OPTION" =~ "-(mapfile|verbose)" ]];then
Alain Reguera Delgado 8f60cb
            cli_printMessage "`eval_gettext "The \\\"\\\$OPTION\\\" option is already used."`" --as-error-line
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define default file name prefix for 16 colors images.
Alain Reguera Delgado 8f60cb
    local PREFIX="-${COLORS}c"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Re-define 16 colors images default file name prefix using
Alain Reguera Delgado 8f60cb
    # options as reference. This is useful to differenciate final
Alain Reguera Delgado 8f60cb
    # files produced using Floyd-Steinberg dithering and final files
Alain Reguera Delgado 8f60cb
    # which are not.
Alain Reguera Delgado 8f60cb
    if [[ "$OPTIONS" =~ '-floyd' ]];then
Alain Reguera Delgado 8f60cb
        PREFIX="${PREFIX}-floyd"
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define logs' file. Log files are stored in the same place of
Alain Reguera Delgado 8f60cb
    # images and are used to store output information produced by
Alain Reguera Delgado 8f60cb
    # programs when the image files are built up.
Alain Reguera Delgado 8f60cb
    local LOGS=${FILE}${PREFIX}.log
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to GPL palette. The GPL palette defines the
Alain Reguera Delgado 8f60cb
    # color information used to build syslinux images.  This palette
Alain Reguera Delgado 8f60cb
    # should be set to 16 colors and, as specified in isolinux
Alain Reguera Delgado 8f60cb
    # documentation, the background color should be indexed on
Alain Reguera Delgado 8f60cb
    # position 0 and the forground in position 7 (see
Alain Reguera Delgado 8f60cb
    # /usr/share/doc/syslinux-X.XX/isolinux.doc, for more
Alain Reguera Delgado 8f60cb
    # information.)
Alain Reguera Delgado 8f60cb
    local PALETTE_GPL=${MOTIF_DIR}/Palettes/syslinux.gpl
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify GPL palette existence. If it doesn't exist copy the one
Alain Reguera Delgado 8f60cb
    # provided by the design model through subversion (to keep track
Alain Reguera Delgado 8f60cb
    # of the change) and expand translation markers in the copied
Alain Reguera Delgado 8f60cb
    # instance.
Alain Reguera Delgado 8f60cb
    if [[ ! -f $PALETTE_GPL ]];then
Alain Reguera Delgado 8f60cb
        cli_runFnEnvironment vcs --copy ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/syslinux.gpl ${PALETTE_GPL}
Alain Reguera Delgado 8f60cb
        cli_expandTMarkers ${PALETTE_GPL}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to PPM palette. The PPM palette is built
Alain Reguera Delgado 8f60cb
    # from source palette (PALETTE_GPL) and provides the color
Alain Reguera Delgado 8f60cb
    # information understood by `ppmremap', the program used to
Alain Reguera Delgado 8f60cb
    # produce images in a specific amount of colors.
Alain Reguera Delgado 8f60cb
    local PALETTE_PPM=$(cli_getTemporalFile "syslinux.ppm")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define the HEX palette. The HEX palette is built from source
Alain Reguera Delgado 8f60cb
    # palette (PALETTE_GPL) and provides the color information in the
Alain Reguera Delgado 8f60cb
    # format understood by `ppmtolss16', the program used to produce
Alain Reguera Delgado 8f60cb
    # images in LSS16 format.  The HEX palette stores just one line
Alain Reguera Delgado 8f60cb
    # with the color information as described in isolinux
Alain Reguera Delgado 8f60cb
    # documentation (i.e #RRGGBB=0 #RRGGBB=1 ... [all values in the
Alain Reguera Delgado 8f60cb
    # same line])
Alain Reguera Delgado 8f60cb
    local PALETTE_HEX=$(cli_getTemporalFile "syslinux.hex")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create image in Netpbm superformat (PNM). The PNM image file is
Alain Reguera Delgado 8f60cb
    # created from the PNG image rendered previously as centos-art
Alain Reguera Delgado 8f60cb
    # base-rendition output. The PNM image is an intermediate format
Alain Reguera Delgado 8f60cb
    # used to manipulate images through Netpbm tools.
Alain Reguera Delgado 8f60cb
    cli_printMessage "${FILE}.pnm" --as-savedas-line
Alain Reguera Delgado 8f60cb
    pngtopnm -verbose \
Alain Reguera Delgado 8f60cb
        < ${FILE}.png 2>${LOGS} > ${FILE}.pnm
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Print the path to GPL palette.
Alain Reguera Delgado 8f60cb
    cli_printMessage "$PALETTE_GPL" --as-palette-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create PPM palette using GPL palette.
Alain Reguera Delgado 8f60cb
    svg_convertGplToPpm "$PALETTE_GPL" "$PALETTE_PPM" "$COLORS"
Alain Reguera Delgado 8f60cb
 
Alain Reguera Delgado 8f60cb
    # Create HEX palette using GPL palette.
Alain Reguera Delgado 8f60cb
    svg_convertGplToHex "$PALETTE_GPL" "$PALETTE_HEX" "$COLORS"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Reduce colors as specified in PPM palette.  Here we use the PPM
Alain Reguera Delgado 8f60cb
    # palette to enforce the color position in the image index and the
Alain Reguera Delgado 8f60cb
    # Floyd-Steinberg dithering in order to improve color reduction.
Alain Reguera Delgado 8f60cb
    cli_printMessage "${FILE}${PREFIX}.pnm" --as-savedas-line
Alain Reguera Delgado 8f60cb
    pnmremap -verbose -mapfile=$PALETTE_PPM $OPTIONS \
Alain Reguera Delgado 8f60cb
        < ${FILE}.pnm 2>> ${LOGS} > ${FILE}${PREFIX}.pnm
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create LSS16 image. 
Alain Reguera Delgado 8f60cb
    cli_printMessage "${FILE}${PREFIX}.lss" --as-savedas-line
Alain Reguera Delgado 8f60cb
    ppmtolss16 $(cat $PALETTE_HEX) \
Alain Reguera Delgado 8f60cb
        < ${FILE}${PREFIX}.pnm 2>>${LOGS} > ${FILE}${PREFIX}.lss
Alain Reguera Delgado 8f60cb
     
Alain Reguera Delgado 8f60cb
    # Remove HEX palette. It is no longer needed.
Alain Reguera Delgado 8f60cb
    if [[ -f ${PALETTE_HEX} ]];then
Alain Reguera Delgado 8f60cb
        rm $PALETTE_HEX
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create PPM image indexed to 16 colors. Also the colormap used in
Alain Reguera Delgado 8f60cb
    # the LSS16 image is saved on ${FILE}.log; this is useful to
Alain Reguera Delgado 8f60cb
    # verify the correct order of colors in the image index.
Alain Reguera Delgado 8f60cb
    cli_printMessage "${FILE}${PREFIX}.ppm" --as-savedas-line
Alain Reguera Delgado 8f60cb
    lss16toppm -map \
Alain Reguera Delgado 8f60cb
        < ${FILE}${PREFIX}.lss 2>>${LOGS} > ${FILE}${PREFIX}.ppm
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create PNG image indexed to 16 colors.
Alain Reguera Delgado 8f60cb
    cli_printMessage "${FILE}${PREFIX}.png" --as-savedas-line
Alain Reguera Delgado 8f60cb
    pnmtopng -verbose \
Alain Reguera Delgado 8f60cb
        < ${FILE}${PREFIX}.pnm 2>>${LOGS} > ${FILE}${PREFIX}.png
Alain Reguera Delgado 8f60cb
      
Alain Reguera Delgado 8f60cb
    # Remove PPM palette. It is no longer needed.
Alain Reguera Delgado 8f60cb
    if [[ -f ${PALETTE_PPM} ]];then
Alain Reguera Delgado 8f60cb
        rm $PALETTE_PPM
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}