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

878a2b
#!/bin/bash
878a2b
#
878a2b
# svg_convertPngToSyslinux.sh -- This function provides post-rendition
878a2b
# action used to produce LSS16 images, the images used by isolinux.
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 16 colors only and is saved in a file named
878a2b
# `syslinux.gpl.  The `syslinux.gpl' file is used to build two other
878a2b
# files: the `syslinux.ppm' file and the `syslinux.hex' file. The
878a2b
# `syslinux.ppm' provides the color information needed to reduce the
878a2b
# full color PNG image, produced as result of SVG base-rendition, to
878a2b
# the amount of colors specified (i.e., 16 colors). Later, with the 16
878a2b
# color PNG image already created, the `syslinux.hex' file is used to
878a2b
# build the LSS16 image.
878a2b
#
878a2b
# In order to produce images in LSS16 format correctly, it is required
878a2b
# that both the `syslinux.ppm' and `syslinux.hex' files do contain the
878a2b
# same color information. This is, both `syslinux.ppm' and
878a2b
# `syslinux.hex' must represent the same color values and in the same
878a2b
# color index.
878a2b
#
878a2b
# In order for this function to work, the `syslinux.gpl' file should
878a2b
# have a format similar to the following:
878a2b
#
878a2b
# GIMP Palette
878a2b
# Name: CentOS-TreeFlower-4-Syslinux
878a2b
# Columns: 16
878a2b
# #
878a2b
# 32  76 141	204c8d
878a2b
# 37  82 146	255292
878a2b
# 52  94 153	345e99
878a2b
# 73 110 162	496ea2
878a2b
# 91 124 172	5b7cac
878a2b
# 108 136 180	6c88b4
878a2b
# 120 146 186	7892ba
878a2b
# 131 158 193	839ec1
878a2b
# 255 255 255	ffffff
878a2b
# 146 170 200	92aac8
878a2b
# 162 182 209	a2b6d1
878a2b
# 183 199 219	b7c7db
878a2b
# 204 216 230	ccd8e6
878a2b
# 221 229 238	dde5ee
878a2b
# 235 241 245	ebf1f5
878a2b
# 246 251 254	f6fbfe
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 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_convertPngToSyslinux {
878a2b
878a2b
    # Define number of colors the images will be produced on.
878a2b
    local COLORS='16'
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 already used 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 $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 default file name prefix for 16 colors images.
878a2b
    local PREFIX="-${COLORS}c"
878a2b
878a2b
    # Re-define 16 colors images default file name prefix using
878a2b
    # options as reference. This is useful to differenciate final
878a2b
    # files produced using Floyd-Steinberg dithering and final files
878a2b
    # which are not.
878a2b
    if [[ "$OPTIONS" =~ '-floyd' ]];then
878a2b
        PREFIX="${PREFIX}-floyd"
878a2b
    fi
878a2b
b2fd79
    # Define logs' file. Log files are stored in the same place of
b2fd79
    # images and are used to store output information produced by
b2fd79
    # programs when the image files are built up.
b2fd79
    local LOGS=${FILE}${PREFIX}.log
b2fd79
878a2b
    # Define absolute path to GPL palette. The GPL palette defines the
878a2b
    # color information used to build syslinux images.  This palette
878a2b
    # should be set to 16 colors and, as specified in isolinux
878a2b
    # documentation, the background color should be indexed on
878a2b
    # position 0 and the forground in position 7 (see
878a2b
    # /usr/share/doc/syslinux-X.XX/isolinux.doc, for more
878a2b
    # information.)
878a2b
    local PALETTE_GPL=${MOTIF_DIR}/Palettes/syslinux.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
ca09ac
        ${CLI_NAME} svn --copy ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/syslinux.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 "syslinux.ppm")
878a2b
878a2b
    # Define the HEX palette. The HEX palette is built from source
878a2b
    # palette (PALETTE_GPL) and provides the color information in the
878a2b
    # format understood by `ppmtolss16', the program used to produce
878a2b
    # images in LSS16 format.  The HEX palette stores just one line
878a2b
    # with the color information as described in isolinux
878a2b
    # documentation (i.e #RRGGBB=0 #RRGGBB=1 ... [all values in the
878a2b
    # same line])
878a2b
    local PALETTE_HEX=$(cli_getTemporalFile "syslinux.hex")
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 \
b2fd79
        < ${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
    # Create HEX palette using GPL palette.
878a2b
    svg_convertGplToHex "$PALETTE_GPL" "$PALETTE_HEX" "$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}.pnm" --as-savedas-line
878a2b
    pnmremap -verbose -mapfile=$PALETTE_PPM $OPTIONS \
b2fd79
        < ${FILE}.pnm 2>> ${LOGS} > ${FILE}${PREFIX}.pnm
878a2b
878a2b
    # Create LSS16 image. 
878a2b
    cli_printMessage "${FILE}${PREFIX}.lss" --as-savedas-line
878a2b
    ppmtolss16 $(cat $PALETTE_HEX) \
b2fd79
        < ${FILE}${PREFIX}.pnm 2>>${LOGS} > ${FILE}${PREFIX}.lss
878a2b
     
878a2b
    # Remove HEX palette. It is no longer needed.
878a2b
    if [[ -f ${PALETTE_HEX} ]];then
878a2b
        rm $PALETTE_HEX
878a2b
    fi
878a2b
b2fd79
    # Create PPM image indexed to 16 colors. Also the colormap used in
b2fd79
    # the LSS16 image is saved on ${FILE}.log; this is useful to
878a2b
    # verify the correct order of colors in the image index.
878a2b
    cli_printMessage "${FILE}${PREFIX}.ppm" --as-savedas-line
878a2b
    lss16toppm -map \
b2fd79
        < ${FILE}${PREFIX}.lss 2>>${LOGS} > ${FILE}${PREFIX}.ppm
b2fd79
b2fd79
    # Create PNG image indexed to 16 colors.
878a2b
    cli_printMessage "${FILE}${PREFIX}.png" --as-savedas-line
b2fd79
    pnmtopng -verbose \
b2fd79
        < ${FILE}${PREFIX}.pnm 2>>${LOGS} > ${FILE}${PREFIX}.png
b2fd79
      
878a2b
    # Remove PPM palette. It is no longer needed.
878a2b
    if [[ -f ${PALETTE_PPM} ]];then
878a2b
        rm $PALETTE_PPM
878a2b
    fi
878a2b
878a2b
}