|
Alain Reguera Delgado |
8f60cb |
#!/bin/bash
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# svg_convertPngToGrub.sh -- This function provides post-rendition
|
|
Alain Reguera Delgado |
8f60cb |
# action used to produce GRUB images.
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# Initially, the color information is defined with GIMP (The GNU Image
|
|
Alain Reguera Delgado |
8f60cb |
# Manipulation Program) as a `.gpl' palette of color. This palette of
|
|
Alain Reguera Delgado |
8f60cb |
# colors contains 14 colors only and is saved in a file named
|
|
Alain Reguera Delgado |
8f60cb |
# `grub.gpl. The `grub.gpl' file is used to build the `grub.ppm' file
|
|
Alain Reguera Delgado |
8f60cb |
# which provide the color information needed to reduce the full color
|
|
Alain Reguera Delgado |
8f60cb |
# PNG image, produced as result of SVG base-rendition, to the amount
|
|
Alain Reguera Delgado |
8f60cb |
# of colors specified (i.e., 14 colors). Later, with the 14 color PNG
|
|
Alain Reguera Delgado |
8f60cb |
# image already created, the `grub.ppm' file is used to build the
|
|
Alain Reguera Delgado |
8f60cb |
# `splash.xpm.gz' file.
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# In order for this function to work, the `grub.gpl' file should have
|
|
Alain Reguera Delgado |
8f60cb |
# a format similar to the following:
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# GIMP Palette
|
|
Alain Reguera Delgado |
8f60cb |
# Name: CentOS-TreeFlower-4-Syslinux
|
|
Alain Reguera Delgado |
8f60cb |
# Columns: 14
|
|
Alain Reguera Delgado |
8f60cb |
# #
|
|
Alain Reguera Delgado |
8f60cb |
# 32 76 141 204c8d
|
|
Alain Reguera Delgado |
8f60cb |
# 36 82 146 245292
|
|
Alain Reguera Delgado |
8f60cb |
# 52 93 152 345d98
|
|
Alain Reguera Delgado |
8f60cb |
# 72 108 162 486ca2
|
|
Alain Reguera Delgado |
8f60cb |
# 102 131 176 6683b0
|
|
Alain Reguera Delgado |
8f60cb |
# 126 153 190 7e99be
|
|
Alain Reguera Delgado |
8f60cb |
# 146 170 200 92aac8
|
|
Alain Reguera Delgado |
8f60cb |
# 161 182 209 a1b6d1
|
|
Alain Reguera Delgado |
8f60cb |
# 182 199 219 b6c7db
|
|
Alain Reguera Delgado |
8f60cb |
# 202 214 228 cad6e4
|
|
Alain Reguera Delgado |
8f60cb |
# 221 230 238 dde6ee
|
|
Alain Reguera Delgado |
8f60cb |
# 235 241 245 ebf1f5
|
|
Alain Reguera Delgado |
8f60cb |
# 246 251 254 f6fbfe
|
|
Alain Reguera Delgado |
8f60cb |
# 254 255 252 fefffc
|
|
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_convertPngToGrub {
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define number of colors the images will be produced on.
|
|
Alain Reguera Delgado |
8f60cb |
local COLORS='14'
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define options using those passed to actions from pre-rendition
|
|
Alain Reguera Delgado |
8f60cb |
# configuration script. These options are applied to pnmremap when
|
|
Alain Reguera Delgado |
8f60cb |
# doing color reduction, so any option available for pnmremap
|
|
Alain Reguera Delgado |
8f60cb |
# command can be passed to renderSyslinux functionality.
|
|
Alain Reguera Delgado |
8f60cb |
local OPTIONS=$(render_getConfigOption "$ACTION" '2-')
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Check options passed to action. This is required in order to
|
|
Alain Reguera Delgado |
8f60cb |
# aviod using options used already in this script. For example
|
|
Alain Reguera Delgado |
8f60cb |
# -verbose and -mapfile options.
|
|
Alain Reguera Delgado |
8f60cb |
for OPTION in $OPTIONS;do
|
|
Alain Reguera Delgado |
8f60cb |
# Remove anything after equal sign inside option.
|
|
Alain Reguera Delgado |
8f60cb |
OPTION=$(echo -n $OPTION | cut -d'=' -f1)
|
|
Alain Reguera Delgado |
8f60cb |
if [[ "$OPTION" =~ "-(mapfile|verbose)" ]];then
|
|
Alain Reguera Delgado |
8f60cb |
cli_printMessage "`eval_gettext "The \\\"\\\$OPTION\\\" option is already used."`" --as-error-line
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
done
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define file name prefix.
|
|
Alain Reguera Delgado |
8f60cb |
local PREFIX="-${COLORS}c"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Redefine file name prefix using options as reference. This is
|
|
Alain Reguera Delgado |
8f60cb |
# useful to differenciate final files produced using
|
|
Alain Reguera Delgado |
8f60cb |
# Floyd-Steinberg dithering and files which are not.
|
|
Alain Reguera Delgado |
8f60cb |
if [[ "$OPTIONS" =~ '-floyd' ]];then
|
|
Alain Reguera Delgado |
8f60cb |
PREFIX="${PREFIX}-floyd"
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define logs' file. Log files are stored in the same place of
|
|
Alain Reguera Delgado |
8f60cb |
# images and are used to store output information produced by
|
|
Alain Reguera Delgado |
8f60cb |
# programs when the image files are built up.
|
|
Alain Reguera Delgado |
8f60cb |
local LOGS=${FILE}${PREFIX}.log
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define absolute path to GPL palette. This palettes should have
|
|
Alain Reguera Delgado |
8f60cb |
# 14 colors only. For more information on this see the GRUB's
|
|
Alain Reguera Delgado |
8f60cb |
# documentation.
|
|
Alain Reguera Delgado |
8f60cb |
local PALETTE_GPL=${MOTIF_DIR}/Palettes/grub.gpl
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Verify GPL palette existence. If it doesn't exist copy the one
|
|
Alain Reguera Delgado |
8f60cb |
# provided by the design model through subversion (to keep track
|
|
Alain Reguera Delgado |
8f60cb |
# of the change) and expand translation markers in the copied
|
|
Alain Reguera Delgado |
8f60cb |
# instance.
|
|
Alain Reguera Delgado |
8f60cb |
if [[ ! -f $PALETTE_GPL ]];then
|
|
Alain Reguera Delgado |
8f60cb |
cli_runFnEnvironment vcs --copy ${MODEL_BASEDIR}/${FLAG_THEME_MODEL}/Palettes/grub.gpl ${PALETTE_GPL}
|
|
Alain Reguera Delgado |
8f60cb |
cli_expandTMarkers ${PALETTE_GPL}
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define absolute path to PPM palette. The PPM palette is built
|
|
Alain Reguera Delgado |
8f60cb |
# from source palette (PALETTE_GPL) and provides the color
|
|
Alain Reguera Delgado |
8f60cb |
# information understood by `ppmremap', the program used to
|
|
Alain Reguera Delgado |
8f60cb |
# produce images in a specific amount of colors.
|
|
Alain Reguera Delgado |
8f60cb |
local PALETTE_PPM=$(cli_getTemporalFile "grub.ppm")
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Create image in Netpbm superformat (PNM). The PNM image file is
|
|
Alain Reguera Delgado |
8f60cb |
# created from the PNG image rendered previously as centos-art
|
|
Alain Reguera Delgado |
8f60cb |
# base-rendition output. The PNM image is an intermediate format
|
|
Alain Reguera Delgado |
8f60cb |
# used to manipulate images through Netpbm tools.
|
|
Alain Reguera Delgado |
8f60cb |
cli_printMessage "${FILE}.pnm" --as-savedas-line
|
|
Alain Reguera Delgado |
8f60cb |
pngtopnm -verbose \
|
|
Alain Reguera Delgado |
8f60cb |
< ${FILE}.png 2>${LOGS} > ${FILE}.pnm
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Print the path to GPL palette.
|
|
Alain Reguera Delgado |
8f60cb |
cli_printMessage "$PALETTE_GPL" --as-palette-line
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Create PPM palette using GPL palette.
|
|
Alain Reguera Delgado |
8f60cb |
svg_convertGplToPpm "$PALETTE_GPL" "$PALETTE_PPM" "$COLORS"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Reduce colors as specified in PPM palette. Here we use the PPM
|
|
Alain Reguera Delgado |
8f60cb |
# palette to enforce the color position in the image index and the
|
|
Alain Reguera Delgado |
8f60cb |
# Floyd-Steinberg dithering in order to improve color reduction.
|
|
Alain Reguera Delgado |
8f60cb |
cli_printMessage "${FILE}${PREFIX}.ppm" --as-savedas-line
|
|
Alain Reguera Delgado |
8f60cb |
pnmremap -verbose -mapfile=$PALETTE_PPM $OPTIONS \
|
|
Alain Reguera Delgado |
8f60cb |
< ${FILE}.pnm 2>>${LOGS} > ${FILE}${PREFIX}.ppm
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Remove PPM palette. It is no longer needed.
|
|
Alain Reguera Delgado |
8f60cb |
if [[ -f ${PALETTE_PPM} ]];then
|
|
Alain Reguera Delgado |
8f60cb |
rm $PALETTE_PPM
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Create the 14 colors xpm.gz file.
|
|
Alain Reguera Delgado |
8f60cb |
cli_printMessage "${FILE}${PREFIX}.xpm.gz" --as-savedas-line
|
|
Alain Reguera Delgado |
8f60cb |
ppmtoxpm \
|
|
Alain Reguera Delgado |
8f60cb |
< ${FILE}${PREFIX}.ppm 2>>${LOGS} > ${FILE}.xpm \
|
|
Alain Reguera Delgado |
8f60cb |
&& gzip --force ${FILE}.xpm \
|
|
Alain Reguera Delgado |
8f60cb |
&& mv ${FILE}.xpm.gz ${FILE}${PREFIX}.xpm.gz
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
}
|