Blame Functions/Render/render_convertGplToHex.sh

bd5b82
#!/bin/bash
bd5b82
#
bd5b82
# render_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
#
bd5b82
# Copyright 2009-2011 Alain Reguera Delgado
bd5b82
#
bd5b82
# This program is free software; you can redistribute it and/or
bd5b82
# modify it under the terms of the GNU General Public License as
bd5b82
# published by the Free Software Foundation; either version 2 of the
bd5b82
# License, or (at your option) any later version.
bd5b82
# 
bd5b82
# This program is distributed in the hope that it will be useful, but
bd5b82
# 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
bd5b82
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
bd5b82
# USA.
bd5b82
# 
bd5b82
# ----------------------------------------------------------------------
bd5b82
# $Id$
bd5b82
# ----------------------------------------------------------------------
bd5b82
bd5b82
function render_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
bd5b82
        cli_printMessage "`eval_gettext "Reducing image to \\\`\\\$COLOR_NUMBER' colors is not supported."`" 'AsErrorLine'
bd5b82
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
bd5b82
    fi
bd5b82
bd5b82
    # Define list of colors from GPL palette.
bd5b82
    local COLORS=$(render_getColors "$PALETTE_GPL")
bd5b82
bd5b82
    # Verify number of colors returned in the list.
bd5b82
    if [[ ! $(echo "$COLORS" |  wc -l) =~ $COLOR_NUMBER ]];then
bd5b82
        cli_printMessage "`gettext "The palette doesn't have the correct number of colors."`" 'AsErrorLine'
bd5b82
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
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
bd5b82
            cli_printMessage "`eval_gettext "The \\\`\\\$COLOR' string isn't a valid color code."`" 'AsErrorLine'
bd5b82
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'
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.
bd5b82
    cli_checkFiles "$PALETTE_PPM" 'f'
bd5b82
bd5b82
}