_convert.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. [ -z $1 ] && {
  3. echo "Specify an image"
  4. echo "gimp -> export -> c source file -> [x] gunit names"
  5. exit 2
  6. }
  7. echo $*
  8. for N in $* ; do
  9. [ ! -f $N ] && {
  10. echo "!! File missing $N"
  11. continue
  12. }
  13. # filename (sans extension)
  14. FN=$(basename -- "$N")
  15. EXT="${FN##*.}"
  16. NAME="${FN%.*}"
  17. OUTDIR=img_/
  18. mkdir -p ${OUTDIR}
  19. HDR=${OUTDIR}/images.h
  20. SRC=${OUTDIR}/images.c
  21. OUT=${OUTDIR}/img_${NAME}.c
  22. echo -e "\n¦${N}¦ == ¦${NAME}¦ -> ¦${OUT}¦"
  23. TESTX=test_${NAME}
  24. TESTC=test_${NAME}.c
  25. # compile name
  26. CONV=${NAME}_
  27. # clean up gimp output
  28. sed -e "s/gimp_image/img/g" \
  29. -e 's/guint8/unsigned char/g' \
  30. -e 's/width/w/g' \
  31. -e 's/height/h/g' \
  32. -e 's/bytes_per_pixel/bpp/g' \
  33. -e 's/pixel_data/b/g' \
  34. -e 's/guint/unsigned int/g' \
  35. $N \
  36. | grep -v ^/ \
  37. | grep -v ^$ \
  38. > ${CONV}.c
  39. # append conversion code
  40. cat _convert.c >> ${CONV}.c
  41. # compile & run converter
  42. rm -f ${CONV}
  43. gcc ${CONV}.c -DIMGTEST -o ${CONV}
  44. ./${CONV} ${NAME} ${OUT}
  45. rm -f ${CONV} ${CONV}.c
  46. # (create &) update header
  47. [[ ! -f ${HDR} ]] && cp _convert_images.h ${HDR}
  48. sed -i "/ img_${NAME};/d" ${HDR}
  49. sed -i "s#//\[TAG\]#//\[TAG\]\nextern const image_t img_${NAME};#" ${HDR}
  50. # sample FZ code
  51. [[ ! -f images.c ]] && cp _convert_images.c ${SRC}
  52. # test
  53. ROOT=${PWD}
  54. pushd ${OUTDIR} >/dev/null
  55. sed "s/zzz/${NAME}/" ${ROOT}/_convert_test.c > ${TESTC}
  56. rm -f ${TESTX}
  57. gcc ${TESTC} ${OUT##*/} -DIMGTEST -o ${TESTX}
  58. ./${TESTX}
  59. rm -f ${TESTX} ${TESTC}
  60. popd >/dev/null
  61. done