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

4c79b5
#!/bin/bash
4c79b5
#
673f99
# svg_convertPngToSyslinux.sh -- This function provides post-rendition
8fc04a
# action used to produce LSS16 images, the images used by isolinux.
8fc04a
#
673f99
# Initially, the color information is defined with GIMP (The GNU Image
673f99
# Manipulation Program) as a `.gpl' palette of color. This palette of
673f99
# colors contains 16 colors only and is saved in a file named
673f99
# `syslinux.gpl.  The `syslinux.gpl' file is used to build two other
673f99
# files: the `syslinux.ppm' file and the `syslinux.hex' file. The
673f99
# `syslinux.ppm' provides the color information needed to reduce the
673f99
# full color PNG image, produced as result of SVG base-rendition, to
673f99
# the amount of colors specified (i.e., 16 colors). Later, with the 16
673f99
# color PNG image already created, the `syslinux.hex' file is used to
673f99
# build the LSS16 image.
8fc04a
#
673f99
# In order to produce images in LSS16 format correctly, it is required
673f99
# that both the `syslinux.ppm' and `syslinux.hex' files do contain the
8fc04a
# same color information. This is, both `syslinux.ppm' and
673f99
# `syslinux.hex' must represent the same color values and in the same
8fc04a
# color index.
8fc04a
#
8fc04a
# In order for this function to work, the `syslinux.gpl' file should
8fc04a
# have a format similar to the following:
8fc04a
#
2fe9b7
# GIMP Palette
2fe9b7
# Name: CentOS-TreeFlower-4-Syslinux
2fe9b7
# Columns: 16
2fe9b7
# #
2fe9b7
# 32  76 141	204c8d
2fe9b7
# 37  82 146	255292
2fe9b7
# 52  94 153	345e99
2fe9b7
# 73 110 162	496ea2
2fe9b7
# 91 124 172	5b7cac
2fe9b7
# 108 136 180	6c88b4
2fe9b7
# 120 146 186	7892ba
2fe9b7
# 131 158 193	839ec1
2fe9b7
# 255 255 255	ffffff
2fe9b7
# 146 170 200	92aac8
2fe9b7
# 162 182 209	a2b6d1
2fe9b7
# 183 199 219	b7c7db
2fe9b7
# 204 216 230	ccd8e6
2fe9b7
# 221 229 238	dde5ee
2fe9b7
# 235 241 245	ebf1f5
2fe9b7
# 246 251 254	f6fbfe
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
673f99
function svg_convertPngToSyslinux {
4c79b5
8fc04a
    # Define number of colors the images will be produced on.
4b1274
    local COLORS='16'
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.
bcfc42
    local OPTIONS=$(${CLI_FUNCNAME}_getConfigOption "$ACTION" '2-')
f16762
f16762
    # Check options passed to action. This is required in order to
8fc04a
    # aviod using options already used in this script. For example
f16762
    # -verbose and -mapfile options.
f16762
    for OPTION in $OPTIONS;do
f16762
        # Remove anything after equal sign inside option.
f16762
        OPTION=$(echo $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
8fc04a
    # Define default file name prefix for 16 colors images.
4b1274
    local PREFIX="-${COLORS}c"
8fc04a
379ebf
    # Re-define 16 colors images default file name prefix using
379ebf
    # options as reference. This is useful to differenciate final
379ebf
    # files produced using Floyd-Steinberg dithering and final files
379ebf
    # which are not.
379ebf
    if [[ "$OPTIONS" =~ '-floyd' ]];then
379ebf
        PREFIX="${PREFIX}-floyd"
379ebf
    fi
379ebf
8fc04a
    # Define absolute path to GPL palette. The GPL palette defines the
8fc04a
    # color information used to build syslinux images.  This palette
8fc04a
    # should be set to 16 colors and, as specified in isolinux
8fc04a
    # documentation, the background color should be indexed on
8fc04a
    # position 0 and the forground in position 7 (see
8fc04a
    # /usr/share/doc/syslinux-X.XX/isolinux.doc, for more
8fc04a
    # information.)
4b1274
    local PALETTE_GPL=${MOTIF_DIR}/Palettes/syslinux.gpl
8fc04a
4b1274
    # Verify GPL palette existence. If it doesn't exist copy the one
673f99
    # provided by the design model through subversion (to keep track
673f99
    # of the change) and expand translation markers in the copied
673f99
    # instance.
4b1274
    if [[ ! -f $PALETTE_GPL ]];then
673f99
        svn cp ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/syslinux.gpl ${PALETTE_GPL}
54cb18
        cli_expandTMarkers ${PALETTE_GPL}
4b1274
    fi
8fc04a
8fc04a
    # Define absolute path to PPM palette. The PPM palette is built
8fc04a
    # from source palette (PALETTE_GPL) and provides the color
8fc04a
    # information understood by `ppmremap', the program used to
8fc04a
    # produce images in a specific amount of colors.
8fc04a
    local PALETTE_PPM=$(cli_getTemporalFile "syslinux.ppm")
8fc04a
8fc04a
    # Define the HEX palette. The HEX palette is built from source
8fc04a
    # palette (PALETTE_GPL) and provides the color information in the
8fc04a
    # format understood by `ppmtolss16', the program used to produce
8fc04a
    # images in LSS16 format.  The HEX palette stores just one line
8fc04a
    # with the color information as described in isolinux
8fc04a
    # documentation (i.e #RRGGBB=0 #RRGGBB=1 ... [all values in the
8fc04a
    # same line])
8fc04a
    local PALETTE_HEX=$(cli_getTemporalFile "syslinux.hex")
8fc04a
8fc04a
    # Create image in Netpbm superformat (PNM). The PNM image file is
8fc04a
    # created from the PNG image rendered previously as centos-art
8fc04a
    # base-rendition output. The PNM image is an intermediate format
8fc04a
    # used to manipulate images through Netpbm tools.
0ff158
    cli_printMessage "${FILE}.pnm" --as-savedas-line
9b4d7d
    pngtopnm -verbose \
9b4d7d
        < ${FILE}.png 2>${FILE}.log > ${FILE}.pnm
8fc04a
8fc04a
    # Print the path to GPL palette.
0ff158
    cli_printMessage "$PALETTE_GPL" --as-palette-line
8fc04a
8fc04a
    # Create PPM palette using GPL palette.
673f99
    ${RENDER_BACKEND}_convertGplToPpm "$PALETTE_GPL" "$PALETTE_PPM" "$COLORS"
8fc04a
 
8fc04a
    # Create HEX palette using GPL palette.
673f99
    ${RENDER_BACKEND}_convertGplToHex "$PALETTE_GPL" "$PALETTE_HEX" "$COLORS"
8fc04a
8fc04a
    # Reduce colors as specified in PPM palette.  Here we use the PPM
8fc04a
    # palette to enforce the color position in the image index and the
4c79b5
    # Floyd-Steinberg dithering in order to improve color reduction.
0ff158
    cli_printMessage "${FILE}${PREFIX}.pnm" --as-savedas-line
379ebf
    pnmremap -verbose -mapfile=$PALETTE_PPM $OPTIONS \
9b4d7d
        < ${FILE}.pnm 2>> ${FILE}.log > ${FILE}${PREFIX}.pnm
f16762
8fc04a
    # Create LSS16 image. 
0ff158
    cli_printMessage "${FILE}${PREFIX}.lss" --as-savedas-line
8fc04a
    ppmtolss16 $(cat $PALETTE_HEX) \
9b4d7d
        < ${FILE}${PREFIX}.pnm 2>>${FILE}.log > ${FILE}${PREFIX}.lss
4c79b5
     
8fc04a
    # Remove HEX palette. It is no longer needed.
8fc04a
    if [[ -f ${PALETTE_HEX} ]];then
8fc04a
        rm $PALETTE_HEX
8fc04a
    fi
8fc04a
4c79b5
    # Create the PPM image indexed to 16 colors. Also the colormap
9b4d7d
    # used in the LSS16 image is saved on ${FILE}.log; this is useful to
4c79b5
    # verify the correct order of colors in the image index.
0ff158
    cli_printMessage "${FILE}${PREFIX}.ppm" --as-savedas-line
9b4d7d
    lss16toppm -map \
9b4d7d
        < ${FILE}${PREFIX}.lss 2>>${FILE}.log > ${FILE}${PREFIX}.ppm
4c79b5
      
4c79b5
    # Create the 16 colors PNG image.
0ff158
    cli_printMessage "${FILE}${PREFIX}.png" --as-savedas-line
4c79b5
    pnmtopng -verbose -palette=$PALETTE_PPM \
9b4d7d
        < ${FILE}${PREFIX}.pnm 2>>${FILE}.log > ${FILE}${PREFIX}.png
4c79b5
   
8fc04a
    # Remove PPM palette. It is no longer needed.
8fc04a
    if [[ -f ${PALETTE_PPM} ]];then
8fc04a
        rm $PALETTE_PPM
8fc04a
    fi
8fc04a
4c79b5
}