#!/bin/bash
# Requirements: imagemagick, wine, PalmRI.exe
# Creates a SlideShowM.prc file with several images to be viewed in Slider Manga for palm.
# Edit SlideShowM.prc with RscrEdit.prc, tSTR 5000 and put the desired title there.
# v.0.1

		rm -r ./images > /dev/null 2>&1
		mkdir -p ./images/processed > /dev/null 2>&1
		cp ./SliderDBM_template.prc ./SlideShowM.prc
		
		clear
		echo
		echo "----------------------------------------------------"
		echo
		echo "Slider Manga generator."
		echo
		echo "----------------------------------------------------"
		echo
		echo "----------------------------------------------------"
		echo
		echo "Starting Image Conversion."
		echo
		echo "Place all image files to be converted in the folder 'images'."
		echo
		echo "Press Return to continue."
		echo
		echo "----------------------------------------------------"
		echo
		read junk
		
		cd ./images

		shopt -s nullglob
		TBMP_NR=1000

		echo

		# Change extensions as needed
		for i in *.{jpg,png,gif,bmp}

		do
		
		FULLPATH="$i"
		FILE="$(basename "${FULLPATH}")"
		DIR="$(dirname "${FULLPATH}")"
		FILE_NOEXT=$(echo "$FILE" | sed 's/\.[^.]*$//')
		EXT=$(echo "$FILE" | sed 's/^.*\.//')

		# Manga b/w
		 convert -depth 4 -colorspace Gray -threshold 60% -resize 160x160! "$i" ./processed/"$FILE_NOEXT"_160.bmp 

		# Manga color
		# convert -colors 256 -depth 8 -resize 160x160! "$i" ./processed/"$filename"_160.bmp 

		echo
		echo "----------------------------------------------------"
		echo
		echo "Inserting images into Manga prc."
		echo
		echo "----------------------------------------------------"
		echo

		# Insert bmps into prc

		wine ./../PalmRI.exe ./processed/"$FILE_NOEXT"_160.bmp:8 ./../SlideShowM.prc Tbmp $TBMP_NR

		TBMP_NR=$[TBMP_NR + 1]

		done

		echo
		echo "SlideShowM.prc generated."
		echo
		echo "Done."

