Blame Scripts/Functions/Render/render_svg_convertGplToHex.sh

bd5b82
#!/bin/bash
bd5b82
#
ed4f4c
# render_svg_convertGplToHex.sh -- This function takes one palette
bd5b82
# produced by Gimp (e.g., syslinux.gpl) as input and outputs the list
bd5b82
# of hexadecimal colors and their respective index position the
bd5b82
# `pnmtolss16' program needs (e.g., #RRGGBB=0 #RRGGBB=1 ... [all
bd5b82
# values in the same line]).
bd5b82
#
2d3646
# 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.
bd5b82
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
bd5b82
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bd5b82
# General Public License for more details.
bd5b82
#
bd5b82
# You should have received a copy of the GNU General Public License
bd5b82
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
bd5b82
# ----------------------------------------------------------------------
bd5b82
# $Id$
bd5b82
# ----------------------------------------------------------------------
bd5b82
ed4f4c
function render_svg_convertGplToHex {
bd5b82
bd5b82
    local COLOR=''
bd5b82
    local COUNT=0
bd5b82
    local -a FILES
bd5b82
bd5b82
    # Define path to GPL palette. This is the .gpl file we use to
bd5b82
    # retrive color information from.
bd5b82
    local PALETTE_GPL="$1"
bd5b82
bd5b82
    # Define path to HEX palette. This is the palette used to stored
bd5b82
    # the color information the `ppmtolss16' program needs.
bd5b82
    local PALETTE_HEX="$2"
bd5b82
bd5b82
    # Define the number of colors this function should return.
bd5b82
    local COLOR_NUMBER="$3"
bd5b82
bd5b82
    # Verify the number of colors this function should return. As
bd5b82
    # convenction, we are producing images in 14 and 16 colors only to
bd5b82
    # cover Grub and Syslinux images need respectively.
bd5b82
    if [[ ! $COLOR_NUMBER =~ '^(14|16)$' ]];then
0ff158
        cli_printMessage "`eval_gettext "Reducing image to \\\"\\\$COLOR_NUMBER\\\" colors is not supported."`" --as-error-line
bd5b82
    fi
bd5b82
bd5b82
    # Define list of colors from GPL palette.
83bfa6
    local COLORS=$(render_svg_getColors "$PALETTE_GPL")
bd5b82
bd5b82
    # Verify number of colors returned in the list.
bd5b82
    if [[ ! $(echo "$COLORS" |  wc -l) =~ $COLOR_NUMBER ]];then
0ff158
        cli_printMessage "`gettext "The palette do not have the correct number of colors."`" --as-error-line
bd5b82
    fi
bd5b82
bd5b82
    # Verify format of colors inside the list.
bd5b82
    for COLOR in $COLORS;do
bd5b82
        if [[ ! $COLOR =~ '^[0-9a-f]{6}$' ]];then
0ff158
            cli_printMessage "`eval_gettext "The \\\"\\\$COLOR\\\" string is not a valid color code."`" --as-error-line
bd5b82
        fi
bd5b82
    done
bd5b82
bd5b82
    # Create list of colors to be process by pnmtolss16 
bd5b82
    echo "$COLORS" | nl | awk '{ printf "#%s=%d ", $2, $1 - 1 }' \
bd5b82
        > $PALETTE_HEX
bd5b82
bd5b82
    # Verify HEX palette existence.
81cea9
    cli_checkFiles "$PALETTE_PPM" --regular-file
bd5b82
bd5b82
}