Advertisement
NoSloppy

Untitled

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