Blame Scripts/Functions/Render/render_svg_convertGplToPpm.sh

913568
#!/bin/bash
913568
#
50858a
# render_svg_convertGplToPpm.sh -- This function takes one palette
913568
# produced by Gimp (e.g., syslinux.gpl) as input and outputs one PPM
913568
# file based on it (e.g., syslinux.ppm).
913568
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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.
913568
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
913568
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
913568
# General Public License for more details.
913568
#
913568
# You should have received a copy of the GNU General Public License
913568
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
913568
# ----------------------------------------------------------------------
913568
# $Id$
913568
# ----------------------------------------------------------------------
913568
50858a
function render_svg_convertGplToPpm {
913568
0fa4e2
    local FILE=''
913568
    local -a FILES
0fa4e2
    local COUNT=0
913568
913568
    # Define path to GPL palette. This is the .gpl file we use to
913568
    # retrive color information from.
913568
    local PALETTE_GPL="$1"
913568
913568
    # Define path to PPM palette. This is the .ppm file we'll save
913568
    # color information to.
913568
    local PALETTE_PPM="$2"
913568
913568
    # Define the number of colors this function should return.
0fa4e2
    local NUMBER="$3"
913568
913568
    # Define list of colors from GPL palette.
0fa4e2
    local COLOR=''
0fa4e2
    local COLORS=$(render_svg_getColors "$PALETTE_GPL" --head=$NUMBER --tail=$NUMBER --format='rrrggbb')
913568
0fa4e2
    # Verify amount of colors in the list of colors.
0fa4e2
    render_svg_checkColorAmount "$COLORS" "$NUMBER"
913568
0fa4e2
    # Verify format of colors.
0fa4e2
    render_svg_checkColorFormats $COLORS --format='rrggbb'
913568
0fa4e2
    # Create temporal images (of 1x1 pixel each) to store each color
0fa4e2
    # retrived from Gimp's palette. 
913568
    for COLOR in $COLORS;do
0fa4e2
        FILES[$COUNT]=$(cli_getTemporalFile ${COUNT}.ppm)
0fa4e2
        ppmmake $COLOR 1 1 > ${FILES[$COUNT]}
913568
        COUNT=$(($COUNT + 1))
913568
    done
913568
0fa4e2
    # Concatenate each temporal image from left to right to create the
0fa4e2
    # PPM file.
913568
    pnmcat -lr ${FILES[*]} > $PALETTE_PPM
913568
0fa4e2
    # Remove temporal images used to build the ppm palette file.
913568
    rm ${FILES[*]}
913568
913568
    # Verify PPM palette existence.
97f5f0
    cli_checkFiles "$PALETTE_PPM"
913568
913568
}