Blame Automation/centos-art.sh-render/Svg/svg_convertGplToHex.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_convertGplToHex.sh -- This function takes one palette produced
Alain Reguera Delgado 8f60cb
# by Gimp (e.g., syslinux.gpl) as input and outputs the list of
Alain Reguera Delgado 8f60cb
# hexadecimal colors and their respective index position the
Alain Reguera Delgado 8f60cb
# `pnmtolss16' program needs (e.g., #RRGGBB=0 #RRGGBB=1 ... [all
Alain Reguera Delgado 8f60cb
# values in the same line]).
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_convertGplToHex {
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 HEX palette. This is the palette used to stored
Alain Reguera Delgado 8f60cb
    # the color information the `ppmtolss16' program needs.
Alain Reguera Delgado 8f60cb
    local PALETTE_HEX="$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 COLORS=$(svg_getColors $PALETTE_GPL --head=$NUMBER --tail=$NUMBER)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify number of colors returned in the list. They must match
Alain Reguera Delgado 8f60cb
    # exactly the amount specified, no more no less. Sometimes, the
Alain Reguera Delgado 8f60cb
    # list of colors may have less colors than it should have, so we
Alain Reguera Delgado 8f60cb
    # need to prevent such palettes from being used.
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 list of colors to be processed by `pnmtolss16'.
Alain Reguera Delgado 8f60cb
    echo "$COLORS" | nl | gawk '{ printf "%s=%d ", $2, $1 - 1 }' \
Alain Reguera Delgado 8f60cb
        > $PALETTE_HEX
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify HEX palette existence.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e $PALETTE_HEX
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}