#!/bin/sh

. srcpkgpaths gimp32

DIR=$HOME/.config/GIMP/3.2
mkdir -p $DIR $DIR/gradients
GRCFILE=$DIR/gimprc

if [ \! -f $GRCFILE ]; then
    WHO=`whoami`
    WHODIR=/ram/gimp/$WHO
    mkdir -p $WHODIR

    cat  > $GRCFILE << END
(temp-path "$WHODIR")
(swap-path "$WHODIR")
(num-processors 4)
(tile-cache-size 512M)
END
fi

# (theme "System")
# (icon-theme "Color")

PRODGIMP=$PRODTREE/gimp32
cp -p $PRODGIMP/share/sessionrc $DIR/

if [ \! -f $DIR/tags.xml ]; then
    cp -p $PRODGIMP/share/tags.xml $DIR/
fi

str="$1"
if [ "@$1" \!= "@" ]; then
    if [ "@$2" == "@" ]; then
        str="$1"
        cvtname=`echo "$str" | sed -e 's@\.avif$@.png@'`
        if [ "@$str"  \!= "@$cvtname" ]; then
            convert "$str" "$cvtname"
            exec $PRODGIMP/bin/gimp-3.2.bin "$cvtname"
        fi
    fi
fi

exec $PRODGIMP/bin/gimp-3.2.bin $*
