From 4c5755ccb2e6779f7b5f2ed69a59ca4863ab7552 Mon Sep 17 00:00:00 2001 From: actionless Date: Sun, 5 Aug 2018 02:42:22 +0200 Subject: [PATCH] render assets in parallel --- common/gtk-2.0/render-asset.sh | 35 ++++++++++++++++++++++ common/gtk-2.0/render-assets.sh | 43 ++++++++-------------------- common/gtk-3.0/3.18/render-asset.sh | 23 +++++++++++++++ common/gtk-3.0/3.18/render-assets.sh | 40 ++++++-------------------- common/gtk-3.0/3.20/render-asset.sh | 23 +++++++++++++++ common/gtk-3.0/3.20/render-assets.sh | 40 ++++++-------------------- common/xfwm4/render-asset.sh | 35 ++++++++++++++++++++++ common/xfwm4/render-assets.sh | 43 +++++++--------------------- 8 files changed, 156 insertions(+), 126 deletions(-) create mode 100755 common/gtk-2.0/render-asset.sh create mode 100755 common/gtk-3.0/3.18/render-asset.sh create mode 100755 common/gtk-3.0/3.20/render-asset.sh create mode 100755 common/xfwm4/render-asset.sh diff --git a/common/gtk-2.0/render-asset.sh b/common/gtk-2.0/render-asset.sh new file mode 100755 index 0000000..6685414 --- /dev/null +++ b/common/gtk-2.0/render-asset.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -ueo pipefail + +INKSCAPE="$(which inkscape)" +OPTIPNG="$(which optipng)" + +ASSETS_DIR="$1" +SRC_FILE="${ASSETS_DIR}".svg + +i="$2" + +result_file="$ASSETS_DIR/$i.png" +if [[ -f "${result_file}" ]] ; then + echo "${result_file} already exists." +else + echo "Rendering '${result_file}'" + "$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-png="${result_file}" "$SRC_FILE" >/dev/null \ + && "$OPTIPNG" -o7 --quiet "${result_file}" +fi + +if [[ "$OPTION_GTK2_HIDPI" == "true" ]]; then + result_file_hidpi="$ASSETS_DIR/$i@2.png" + if [[ -f "${result_file_hidpi}" ]] ; then + echo "${result_file_hidpi} already exists." + else + echo "Rendering '${result_file_hidpi}'" + "$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-dpi=192 \ + --export-png="${result_file_hidpi}" "$SRC_FILE" >/dev/null \ + && "$OPTIPNG" -o7 --quiet "${result_file_hidpi}" + fi +fi diff --git a/common/gtk-2.0/render-assets.sh b/common/gtk-2.0/render-assets.sh index 71114bf..5cf4be7 100755 --- a/common/gtk-2.0/render-assets.sh +++ b/common/gtk-2.0/render-assets.sh @@ -1,41 +1,22 @@ -#! /bin/bash +#!/bin/bash +set -ueo pipefail + +# Make sure that parallel is GNU parallel and not moreutils. +# Otherwise, it fails silently. There's no smooth way to detect this. +if [[ "$(which parallel 2> /dev/null)" ]]; then + cmd=(parallel) +else + cmd=(xargs -n1) +fi -INKSCAPE="/usr/bin/inkscape" -OPTIPNG="/usr/bin/optipng" -SRC_FILE="assets.svg" ASSETS_DIR="assets" - -DARK_SRC_FILE="assets-dark.svg" DARK_ASSETS_DIR="assets-dark" -INDEX="assets.txt" -for i in `cat $INDEX` -do +"${cmd[@]}" ./render-asset.sh ${ASSETS_DIR} < assets.txt +"${cmd[@]}" ./render-asset.sh ${DARK_ASSETS_DIR} < assets.txt -if [ -f $ASSETS_DIR/$i.png ]; then - echo $ASSETS_DIR/$i.png exists. -else - echo - echo Rendering $ASSETS_DIR/$i.png - $INKSCAPE --export-id=$i \ - --export-id-only \ - --export-png=$ASSETS_DIR/$i.png $SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $ASSETS_DIR/$i.png -fi - -if [ -f $DARK_ASSETS_DIR/$i.png ]; then - echo $DARK_ASSETS_DIR/$i.png exists. -else - echo - echo Rendering $DARK_ASSETS_DIR/$i.png - $INKSCAPE --export-id=$i \ - --export-id-only \ - --export-png=$DARK_ASSETS_DIR/$i.png $DARK_SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $DARK_ASSETS_DIR/$i.png -fi -done cp $ASSETS_DIR/entry-toolbar.png menubar-toolbar/entry-toolbar.png cp $ASSETS_DIR/entry-active-toolbar.png menubar-toolbar/entry-active-toolbar.png diff --git a/common/gtk-3.0/3.18/render-asset.sh b/common/gtk-3.0/3.18/render-asset.sh new file mode 100755 index 0000000..7d460a7 --- /dev/null +++ b/common/gtk-3.0/3.18/render-asset.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -ueo pipefail + +INKSCAPE="$(which inkscape)" +OPTIPNG="$(which optipng)" + +SRC_FILE="assets.svg" +ASSETS_DIR="assets" + +i="$1" + +echo "Rendering '$ASSETS_DIR/$i.png'" +"$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-png="$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null \ +&& "$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png" + +echo "Rendering '$ASSETS_DIR/$i@2.png'" +"$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-dpi=192 \ + --export-png="$ASSETS_DIR/$i@2.png" "$SRC_FILE" >/dev/null \ +&& "$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i@2.png" diff --git a/common/gtk-3.0/3.18/render-assets.sh b/common/gtk-3.0/3.18/render-assets.sh index d31fbb8..6634c78 100755 --- a/common/gtk-3.0/3.18/render-assets.sh +++ b/common/gtk-3.0/3.18/render-assets.sh @@ -1,34 +1,12 @@ -#! /bin/bash +#!/bin/bash +set -ueo pipefail -INKSCAPE="/usr/bin/inkscape" -OPTIPNG="/usr/bin/optipng" - -SRC_FILE="assets.svg" -ASSETS_DIR="assets" -INDEX="assets.txt" - -for i in `cat $INDEX` -do -if [ -f $ASSETS_DIR/$i.png ]; then - echo $ASSETS_DIR/$i.png exists. +# Make sure that parallel is GNU parallel and not moreutils. +# Otherwise, it fails silently. There's no smooth way to detect this. +if [[ "$(which parallel 2> /dev/null)" ]]; then + cmd=(parallel) else - echo - echo Rendering $ASSETS_DIR/$i.png - $INKSCAPE --export-id=$i \ - --export-id-only \ - --export-png=$ASSETS_DIR/$i.png $SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $ASSETS_DIR/$i.png + cmd=(xargs -n1) fi -if [ -f $ASSETS_DIR/$i@2.png ]; then - echo $ASSETS_DIR/$i@2.png exists. -else - echo - echo Rendering $ASSETS_DIR/$i@2.png - $INKSCAPE --export-id=$i \ - --export-dpi=180 \ - --export-id-only \ - --export-png=$ASSETS_DIR/$i@2.png $SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $ASSETS_DIR/$i@2.png -fi -done -exit 0 + +"${cmd[@]}" ./render-asset.sh < assets.txt diff --git a/common/gtk-3.0/3.20/render-asset.sh b/common/gtk-3.0/3.20/render-asset.sh new file mode 100755 index 0000000..7d460a7 --- /dev/null +++ b/common/gtk-3.0/3.20/render-asset.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -ueo pipefail + +INKSCAPE="$(which inkscape)" +OPTIPNG="$(which optipng)" + +SRC_FILE="assets.svg" +ASSETS_DIR="assets" + +i="$1" + +echo "Rendering '$ASSETS_DIR/$i.png'" +"$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-png="$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null \ +&& "$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png" + +echo "Rendering '$ASSETS_DIR/$i@2.png'" +"$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-dpi=192 \ + --export-png="$ASSETS_DIR/$i@2.png" "$SRC_FILE" >/dev/null \ +&& "$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i@2.png" diff --git a/common/gtk-3.0/3.20/render-assets.sh b/common/gtk-3.0/3.20/render-assets.sh index d31fbb8..6634c78 100755 --- a/common/gtk-3.0/3.20/render-assets.sh +++ b/common/gtk-3.0/3.20/render-assets.sh @@ -1,34 +1,12 @@ -#! /bin/bash +#!/bin/bash +set -ueo pipefail -INKSCAPE="/usr/bin/inkscape" -OPTIPNG="/usr/bin/optipng" - -SRC_FILE="assets.svg" -ASSETS_DIR="assets" -INDEX="assets.txt" - -for i in `cat $INDEX` -do -if [ -f $ASSETS_DIR/$i.png ]; then - echo $ASSETS_DIR/$i.png exists. +# Make sure that parallel is GNU parallel and not moreutils. +# Otherwise, it fails silently. There's no smooth way to detect this. +if [[ "$(which parallel 2> /dev/null)" ]]; then + cmd=(parallel) else - echo - echo Rendering $ASSETS_DIR/$i.png - $INKSCAPE --export-id=$i \ - --export-id-only \ - --export-png=$ASSETS_DIR/$i.png $SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $ASSETS_DIR/$i.png + cmd=(xargs -n1) fi -if [ -f $ASSETS_DIR/$i@2.png ]; then - echo $ASSETS_DIR/$i@2.png exists. -else - echo - echo Rendering $ASSETS_DIR/$i@2.png - $INKSCAPE --export-id=$i \ - --export-dpi=180 \ - --export-id-only \ - --export-png=$ASSETS_DIR/$i@2.png $SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $ASSETS_DIR/$i@2.png -fi -done -exit 0 + +"${cmd[@]}" ./render-asset.sh < assets.txt diff --git a/common/xfwm4/render-asset.sh b/common/xfwm4/render-asset.sh new file mode 100755 index 0000000..6685414 --- /dev/null +++ b/common/xfwm4/render-asset.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -ueo pipefail + +INKSCAPE="$(which inkscape)" +OPTIPNG="$(which optipng)" + +ASSETS_DIR="$1" +SRC_FILE="${ASSETS_DIR}".svg + +i="$2" + +result_file="$ASSETS_DIR/$i.png" +if [[ -f "${result_file}" ]] ; then + echo "${result_file} already exists." +else + echo "Rendering '${result_file}'" + "$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-png="${result_file}" "$SRC_FILE" >/dev/null \ + && "$OPTIPNG" -o7 --quiet "${result_file}" +fi + +if [[ "$OPTION_GTK2_HIDPI" == "true" ]]; then + result_file_hidpi="$ASSETS_DIR/$i@2.png" + if [[ -f "${result_file_hidpi}" ]] ; then + echo "${result_file_hidpi} already exists." + else + echo "Rendering '${result_file_hidpi}'" + "$INKSCAPE" --export-id="$i" \ + --export-id-only \ + --export-dpi=192 \ + --export-png="${result_file_hidpi}" "$SRC_FILE" >/dev/null \ + && "$OPTIPNG" -o7 --quiet "${result_file_hidpi}" + fi +fi diff --git a/common/xfwm4/render-assets.sh b/common/xfwm4/render-assets.sh index f38ea37..1509033 100755 --- a/common/xfwm4/render-assets.sh +++ b/common/xfwm4/render-assets.sh @@ -1,36 +1,13 @@ -#! /bin/bash +#!/bin/bash +set -ueo pipefail -INKSCAPE="/usr/bin/inkscape" -OPTIPNG="/usr/bin/optipng" - -SRC_FILE="assets.svg" -DARK_SRC_FILE="assets-dark.svg" -ASSETS_DIR="assets" -DARK_ASSETS_DIR="assets-dark" - -INDEX="assets.txt" - -for i in `cat $INDEX` -do -if [ -f $ASSETS_DIR/$i.png ]; then - echo $ASSETS_DIR/$i.png exists. +# Make sure that parallel is GNU parallel and not moreutils. +# Otherwise, it fails silently. There's no smooth way to detect this. +if [[ "$(which parallel 2> /dev/null)" ]]; then + cmd=(parallel) else - echo - echo Rendering $ASSETS_DIR/$i.png - $INKSCAPE --export-id=$i \ - --export-id-only \ - --export-png=$ASSETS_DIR/$i.png $SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $ASSETS_DIR/$i.png + cmd=(xargs -n1) fi -if [ -f $DARK_ASSETS_DIR/$i.png ]; then - echo $DARK_ASSETS_DIR/$i.png exists. -else - echo - echo Rendering $DARK_ASSETS_DIR/$i.png - $INKSCAPE --export-id=$i \ - --export-id-only \ - --export-png=$DARK_ASSETS_DIR/$i.png $DARK_SRC_FILE >/dev/null \ - && $OPTIPNG -o7 --quiet $DARK_ASSETS_DIR/$i.png -fi -done -exit 0 + +"${cmd[@]}" ./render-asset.sh assets < assets.txt +"${cmd[@]}" ./render-asset.sh assets-dark < assets.txt