bashfblib.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. # Dependency, shell, printf, dd
  3. # TODO: Dependency on dd can be removed, but will be really slow
  4. # TODO: Implement double buffering
  5. # TODO: Propose no dependency on printf
  6. NO_DD=0
  7. USE_DOUBLE_BUFFERING=0
  8. NO_PRINTF=0
  9. # NEED TO FILL THIS INFORMATION
  10. # geometry 220 176 220 352 16
  11. # rgba 5/11,6/5,5/0,0/0
  12. # TODO: Adding a dependency on fbset we may be able to autoset this:
  13. SCREEN_WIDTH=220
  14. SCREEN_HEIGHT=176
  15. RED_DEPTH=5
  16. GREEN_DEPTH=6
  17. BLUE_DEPTH=5
  18. RED_POS=11
  19. GREEN_POS=5
  20. BLUE_POS=0
  21. TEMP=`mktemp`
  22. SCREEN_FB=/dev/fb0
  23. ###
  24. # AUTOCALCULATED VALUES
  25. BIT_PER_PIXEL=$((${RED_DEPTH}+${GREEN_DEPTH}+${BLUE_DEPTH}))
  26. BYTE_PER_PIXEL=$((${BIT_PER_PIXEL}/8))
  27. SCREEN_STRIDE=$((${BYTE_PER_PIXEL}*${SCREEN_WIDTH}))
  28. RED_MAX=$((2**${RED_DEPTH}))
  29. GREEN_MAX=$((2**${GREEN_DEPTH}))
  30. BLUE_MAX=$((2**${BLUE_DEPTH}))
  31. RED_SHIFT=$((2**${RED_POS}))
  32. GREEN_SHIFT=$((2**${GREEN_POS}))
  33. BLUE_SHIFT=$((2**${BLUE_POS}))
  34. drawpixel()
  35. {
  36. x=$1; shift 1
  37. y=$1; shift 1
  38. r=$1; shift 1
  39. g=$1; shift 1
  40. b=$1; shift 1
  41. skip=$(($((${x}*${BYTE_PER_PIXEL}-1))+$((${y}*${SCREEN_STRIDE}))))
  42. rc=$((${r}*${RED_MAX}/256))
  43. gc=$((${g}*${GREEN_MAX}/256))
  44. bc=$((${b}*${BLUE_MAX}/256))
  45. rs=$((${rc}*${RED_SHIFT}))
  46. gs=$((${gc}*${GREEN_SHIFT}))
  47. bs=$((${bc}*${BLUE_SHIFT}))
  48. value=$((${rs}+${gs}+${bs}))
  49. echo -ne "" > ${TEMP}
  50. for i in `seq $((${BIT_PER_PIXEL}-8)) -8 0`; do
  51. val=$(($((${value}/$((2**$i))))&255))
  52. echo -ne "$(printf '\\x%x' ${val})" >> ${TEMP}
  53. done
  54. dd if=${TEMP} of=${SCREEN_FB} bs=1 seek=${skip} count=${BYTE_PER_PIXEL} 2&> /dev/null
  55. }
  56. fblib_cleanup()
  57. {
  58. rm ${TEMP}
  59. }