|
|
913568 |
#!/bin/bash
|
|
|
913568 |
#
|
|
|
56ec77 |
# 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 |
#
|
|
|
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.
|
|
|
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 |
|
|
|
56ec77 |
function svg_convertGplToPpm {
|
|
|
913568 |
|
|
|
913568 |
local COLOR=''
|
|
|
913568 |
local COUNT=0
|
|
|
913568 |
local -a FILES
|
|
|
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.
|
|
|
913568 |
local COLOR_NUMBER="$3"
|
|
|
913568 |
|
|
|
913568 |
# Verify the number of colors this function should return. As
|
|
|
913568 |
# convenction, we are producing images in 14 and 16 colors only to
|
|
|
913568 |
# cover Grub and Syslinux images need respectively.
|
|
|
913568 |
if [[ ! $COLOR_NUMBER =~ '^(14|16)$' ]];then
|
|
|
0ff158 |
cli_printMessage "`eval_gettext "Reducing image to \\\"\\\$COLOR_NUMBER\\\" colors is not supported."`" --as-error-line
|
|
|
913568 |
fi
|
|
|
913568 |
|
|
|
913568 |
# Define list of colors from GPL palette.
|
|
|
913568 |
local COLORS=$(render_getColors "$PALETTE_GPL")
|
|
|
913568 |
|
|
|
913568 |
# Verify number of colors returned in the list.
|
|
|
913568 |
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
|
|
|
913568 |
fi
|
|
|
913568 |
|
|
|
913568 |
# Verify format of colors inside the list.
|
|
|
913568 |
for COLOR in $COLORS;do
|
|
|
913568 |
if [[ ! $COLOR =~ '^[0-9a-f]{6}$' ]];then
|
|
|
0ff158 |
cli_printMessage "`eval_gettext "The \\\"\\\$COLOR\\\" string is not a valid color code."`" --as-error-line
|
|
|
913568 |
fi
|
|
|
913568 |
done
|
|
|
913568 |
|
|
|
913568 |
# Create temporal images (of 1x1 pixel each) for each color
|
|
|
913568 |
# retrived from Gimp's palette.
|
|
|
913568 |
for COLOR in $COLORS;do
|
|
|
913568 |
FILES[$COUNT]=$(cli_getTemporalFile "color-${COUNT}.ppm")
|
|
|
913568 |
ppmmake $(echo "$COLOR" \
|
|
|
913568 |
| sed -r 's!(.{2})(.{2})(.{2})!rgb:\1/\2/\3!') 1 1 \
|
|
|
913568 |
> ${FILES[$COUNT]}
|
|
|
913568 |
COUNT=$(($COUNT + 1))
|
|
|
913568 |
done
|
|
|
913568 |
|
|
|
913568 |
# Concatenate temporal images from left to right to create the PPM
|
|
|
913568 |
# file.
|
|
|
913568 |
pnmcat -lr ${FILES[*]} > $PALETTE_PPM
|
|
|
913568 |
|
|
|
913568 |
# Remove temporal images.
|
|
|
913568 |
rm ${FILES[*]}
|
|
|
913568 |
|
|
|
913568 |
# Verify PPM palette existence.
|
|
|
97f5f0 |
cli_checkFiles "$PALETTE_PPM"
|
|
|
913568 |
|
|
|
913568 |
}
|