Advertisement
kaQnub

create_POV_data_files with fill

Jan 29th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # create_POV_data_files
  4. # version - all .png files that don't contain 'preview' are processed
  5. OIFS="$IFS"
  6. IFS=$'\n'
  7. cd "$(dirname "$0")"
  8. clear
  9. height_only=0
  10. preset=0
  11. fillstr=""
  12. download=0
  13.  
  14. echo ""
  15. echo "Welcome! Let's make some POV images!"
  16. echo ""
  17. echo "Found these image files:"
  18. # get .png files except containing 'preview' and build array
  19. pngs=($(find . -maxdepth 1 -type f -name "*.png" ! -name "*preview*"))
  20. for strip in ${pngs[@]}; do echo "${strip##*/}"; done
  21. # get number of files in array
  22. files=${#pngs[@]}
  23. echo ""
  24.  
  25. # If NO images in the folder, offer logo
  26. if [[ $files -lt 1 ]]; then
  27.     echo ""
  28.     echo "OOPS! No .png image files found!"
  29.     echo ""
  30.     echo "Do you want to download a sample Star Wars logo image?"
  31.     echo "Type y for yes,"
  32.     echo "type q to quit,"
  33.     read -p $'or press ENTER to start over..\n' dl
  34.     case $dl in
  35.         y) download=1;;
  36.         q) exit;;
  37.         *) exec "./create_POV_data_files";;
  38.     esac
  39. fi
  40. if [[ $download == 1 ]]; then
  41.     echo ""
  42.     wget https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1024px-Star_Wars_Logo.svg.png
  43.     pngs=$"1024px-Star_Wars_Logo.svg.png"
  44. fi
  45.  
  46. valid_option=0
  47. while [[ $valid_option != 1 ]]; do
  48.     echo "Please select the settings you want to create the POV image(s) with:"
  49.     echo "  height - number of pixels in your blade (one strip emitter to tip)"
  50.     echo "  length - blade length in the measurement unit of choice"
  51.     echo "  offset - the distance (in same unit as length) from the bottom of the blade"
  52.     echo "       to the fulcrum (e.g. the joint you are swinging with)"
  53.     echo ""
  54.     echo "1 - Preset 1 (units=inches height=144 length=39 offset=18)"
  55.     echo "2 - Preset 2 (units=centimeters height=97 length=63 offset=50)"
  56.     echo "3 - Preset 3 (units=centimeters height=72 length=50 offset=15)"
  57.     echo "4 - Preset 4 (units=centimeters height=72 length=50 offset=15 fill)"
  58.     echo "5 - Height entry only"
  59.     echo "6 - Custom options"
  60.     echo "q - to quit"
  61.     read option
  62.     case $option in
  63.         "") echo "! Some option is needed. Please try again"; echo "";;
  64.         1) units="inches" height=144 length=39 offset=18 preset=1 valid_option=1;;
  65.         2) units="centimeters" height=97 length=63 offset=50 preset=1 valid_option=1;;
  66.         3) units="centimeters" height=72 length=50 offset=15 preset=1 valid_option=1;;
  67.         4) units="centimeters" height=72 length=50 offset=15 fillstr="--fill" preset=1 valid_option=1;;
  68.         5) height_only=1 valid_option=1;;
  69.         6) valid_option=1;;
  70. #       7) ------ ADDITIONAL USER PRESETS CAN BE ADDED HERE -------
  71. #       8) ------ or move 5 & 6 down to keep them all together -------------
  72. #       height is amount of pixels in your blade,
  73. #       length is the length of that blade in the unit of the distance of your choosing (most common inches or centimeters)
  74. #       offset - the distance (same unit as length) from the bottom of the blade to the fulcrum (e.g. the joint you are swinging with)
  75.         q) exit;;
  76.         *) echo ""
  77.             echo "! Not a valid option, Please try again,"
  78.             echo "or type q to quit. "; echo "";;
  79.     esac
  80. done
  81.  
  82. validinput=0
  83. while [[ $validinput != 1 ]] && [[ $preset == 0 ]]; do
  84.     echo ""
  85.     echo "How many pixels are in your blade? (Press ENTER for default 144)"
  86.     read height
  87.     if [[ $height == "" ]]; then height=144 validinput=1; echo "Default 144"
  88.     elif [[ $height == "q" ]]; then exit
  89.     elif [[ $height -gt 576 ]]; then
  90.         echo "! That is likely impossible."
  91.         echo "  Please try again or type 'q' to quit."; echo ""
  92.     elif [[ $height -gt 264 ]]; then
  93.         read -p $'Are you sure there are that many pixels?? (y/n)\n' too_many
  94.         if [[ $too_many == "y" ]]; then validinput=1; else echo ""; fi
  95.     elif [[ $height =~ ^[0-9]{1,3}$ ]]; then validinput=1
  96.     else
  97.         echo ""
  98.         echo "! Not a valid option, Please try again,"
  99.         echo "or type q to quit. "; echo ""
  100.     fi
  101. done
  102.  
  103. if [[ $height_only != 1 ]]; then
  104.     validinput=0
  105.     while [[ $validinput != 1 ]] && [[ $preset == 0 ]]; do
  106.         echo ""
  107.         echo "What is your preferred unit of measuring distance? (i - inches, c - cm) "
  108.         read pref
  109.         case $pref in
  110.         "") echo "! Some option is needed. Please try again"; echo "";;
  111.         i) calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18 validinput=1 units="inches";;
  112.         c) calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1; units="centimeters";;
  113.         q) exit;;
  114.         *) echo ""
  115.         echo "! Not a valid option, Please choose inches or cm,"
  116.         echo "or type q to quit. "; echo "";;
  117.         esac
  118.     done
  119.  
  120.     validinput=0
  121.     while [[ $validinput != 1 ]] && [[ $preset == 0 ]]; do
  122.         echo ""
  123.         echo "How many $units is your blade? (Press ENTER for calculated default $calc_len)"
  124.         read length
  125.         if [[ $units == "inches" ]]; then max=48; else max=122; fi
  126.         if [[ $length == "" ]]; then length=$calc_len validinput=1; echo "Default $calc_len"
  127.         elif [[ $length == "q" ]]; then exit
  128.         elif [[ $length -gt $max ]]; then
  129.             echo "! That is likely impossible."
  130.             echo "  Please try again or type 'q' to quit."
  131.             echo ""
  132.         elif [[ $length =~ ^[0-9]{1,3}$ ]]; then validinput=1
  133.         else
  134.             echo ""
  135.             echo "! Not a valid option, Please try again,"
  136.             echo "or type q to quit. "; echo ""
  137.         fi
  138.     done
  139.  
  140.     validinput=0
  141.     while [[ $validinput != 1 ]] && [[ $preset == 0 ]]; do
  142.         echo ""
  143.         echo "How many "$units" distance from the bottom of the blade to the fulcrum?"
  144.         echo "The fulcrum is the pivot point. (Press ENTER for default $offset_default) "
  145.         read offset
  146.         if [[ $units == "inches" ]]; then max=30; else max=76; fi
  147.         if [[ $offset == "" ]]; then offset=$offset_default validinput=1; echo "Default $offset_default"
  148.         elif [[ $offset == "q" ]]; then exit
  149.         elif [[ $offset -gt $max ]]; then
  150.             echo "! That is likely impossible."
  151.             echo "  Please try again or type 'q' to quit."
  152.             echo ""
  153.         elif [[ $length =~ ^[0-9]{1,3}$ ]]; then validinput=1
  154.         else
  155.             echo ""
  156.             echo "! Not a valid option, Please try again,"
  157.             echo "or type q to quit. "; echo ""
  158.         fi
  159.     done
  160.  
  161.     validinput=0
  162.     while [[ $validinput != 1 ]] && [[ $preset == 0 ]]; do
  163.         echo ""
  164.         echo "Use fill option? (y/n)"
  165.         # add explanation for fill here, and probably at the preset case as well
  166.         read usefill
  167.         if [[ $usefill == "y" ]]; then fillstr="--fill" validinput=1;
  168.         elif [[ $usefill == "n" ]]; then validinput=1;
  169.         elif [[ $usefill == "q" ]]; then exit
  170.         else
  171.             echo ""
  172.             echo "! Not a valid option, Please try again,"
  173.             echo "or type q to quit. "; echo ""
  174.         fi
  175.     done
  176. else # height_only
  177. units="inches" length=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3") offset=18
  178. fi
  179.  
  180. echo "Number of images to process: " $files
  181. for process in "${pngs[@]}";do
  182.     # strip path for displaying file name to be processed
  183.     pngname="${process##*/}"
  184.     # additionally remove extension and spaces for finished file name
  185.     pngnoext="${pngname%.*}"
  186.     pngbase="${pngnoext// /_}"
  187.     echo ""
  188.     echo "Processing source image file: $pngname"
  189.     echo ""
  190.     # Rename to maketmp.png for make
  191.     cp $process ./maketmp.png
  192.     make IMAGE=./maketmp.png OPTIONS="--height=$height --length=$length --offset=$offset $fillstr"
  193.     #removing maketmp.png now that we're done with it
  194.     rm -- ./maketmp.png
  195.     mv ./preview.png ./${pngbase}_${height}_preview.png
  196.     mv ./image_rgb.h ../styles/${pngbase}_${height}_FC_POV_data.h
  197.     mv ./image_pgm.h ../styles/${pngbase}_${height}_SC_POV_data.h
  198.     mv ./image_8bit.h ../styles/${pngbase}_${height}_8b_POV_data.h
  199.     printf $'\nDate processesd: '$(date)$'\n' >> POV_conversions.log
  200.     printf $'POV image files created in /styles:\n'${pngbase}_${height}_FC_POV_data.h$'\n'${pngbase}_${height}_SC_POV_data.h$'\n'${pngbase}_${height}_8b_POV_data.h$'\n' >> POV_conversions.log
  201.     printf $'Settings used:\nheight = '$height$' pixels\nlength = '$length' '$units$'\noffset = '$offset' '$units$'\n' >> POV_conversions.log
  202.     echo ""
  203.     echo ""
  204.     echo "Conversion DONE! Find your files as shown below."
  205.     echo ""
  206.     echo "preview image:"
  207.     echo "  ProffieOS/pov_tools/"$pngbase"_"$height"_preview.png"
  208.     echo "Full color image data file:"
  209.     echo "  ProffieOS/styles/"$pngbase"_"$height"_FC_POV_data.h"
  210.     echo "Single color image data file:"
  211.     echo "  ProffieOS/styles/"$pngbase"_"$height"_SC_POV_data.h"
  212.     echo "256 color image data file:"
  213.     echo "  ProffieOS/styles/"$pngbase"_"$height"_8b_POV_data.h"
  214.     echo ""
  215.     echo ""
  216. done
  217. exit
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement