Blame Automation/centos-art.sh-mods/Render/Svg/svg_convertGplToPpm.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_convertGplToPpm.sh -- This function takes one palette produced
Alain Reguera Delgado 8f60cb
# by Gimp (e.g., syslinux.gpl) as input and outputs one PPM file based
Alain Reguera Delgado 8f60cb
# on it (e.g., syslinux.ppm).
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_convertGplToPpm {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local -a FILES
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define path to GPL palette. This is the .gpl file we use to
Alain Reguera Delgado 8f60cb
    # retrive color information from.
Alain Reguera Delgado 8f60cb
    local PALETTE_GPL="$1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define path to PPM palette. This is the .ppm file we'll save
Alain Reguera Delgado 8f60cb
    # color information to.
Alain Reguera Delgado 8f60cb
    local PALETTE_PPM="$2"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define the number of colors this function should return.
Alain Reguera Delgado 8f60cb
    local NUMBER="$3"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of colors from GPL palette.
Alain Reguera Delgado 8f60cb
    local COLOR=''
Alain Reguera Delgado 8f60cb
    local COLORS=$(svg_getColors "$PALETTE_GPL" --head=$NUMBER --tail=$NUMBER --format='rrrggbb')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify amount of colors in the list of colors.
Alain Reguera Delgado 8f60cb
    svg_checkColorAmount "$COLORS" "$NUMBER"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify format of colors.
Alain Reguera Delgado 8f60cb
    svg_checkColorFormats $COLORS --format='rrggbb'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create temporal images (of 1x1 pixel each) to store each color
Alain Reguera Delgado 8f60cb
    # retrived from Gimp's palette. 
Alain Reguera Delgado 8f60cb
    for COLOR in $COLORS;do
Alain Reguera Delgado 8f60cb
        FILES[$COUNT]=$(cli_getTemporalFile ${COUNT}.ppm)
Alain Reguera Delgado 8f60cb
        ppmmake $COLOR 1 1 > ${FILES[$COUNT]}
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Concatenate each temporal image from left to right to create the
Alain Reguera Delgado 8f60cb
    # PPM file.
Alain Reguera Delgado 8f60cb
    pnmcat -lr ${FILES[*]} > $PALETTE_PPM
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove temporal images used to build the PPM palette file.
Alain Reguera Delgado 8f60cb
    rm ${FILES[*]}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify PPM palette existence.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e "$PALETTE_PPM"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}