My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

gen-tft-image.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. #
  3. # Marlin 3D Printer Firmware
  4. # Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. #
  6. # Based on Sprinter and grbl.
  7. # Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. #
  22. # Generate Marlin TFT Images from bitmaps/PNG/JPG
  23. import sys,struct
  24. from PIL import Image
  25. def image2bin(image, output_file):
  26. if output_file.endswith(('.c', '.cpp')):
  27. f = open(output_file, 'wt')
  28. is_cpp = True
  29. f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0]))
  30. else:
  31. f = open(output_file, 'wb')
  32. is_cpp = False
  33. pixs = image.load()
  34. for y in range(image.size[1]):
  35. for x in range(image.size[0]):
  36. R = pixs[x, y][0] >> 3
  37. G = pixs[x, y][1] >> 2
  38. B = pixs[x, y][2] >> 3
  39. rgb = (R << 11) | (G << 5) | B
  40. if is_cpp:
  41. strHex = '0x{0:04X}, '.format(rgb)
  42. f.write(strHex)
  43. else:
  44. f.write(struct.pack("B", (rgb & 0xFF)))
  45. f.write(struct.pack("B", (rgb >> 8) & 0xFF))
  46. if is_cpp:
  47. f.write("\n")
  48. if is_cpp:
  49. f.write("};\n")
  50. f.close()
  51. if len(sys.argv) <= 2:
  52. print("Utility to export a image in Marlin TFT friendly format.")
  53. print("It will dump a raw bin RGB565 image or create a CPP file with an array of 16 bit image pixels.")
  54. print("Usage: gen-tft-image.py INPUT_IMAGE.(png|bmp|jpg) OUTPUT_FILE.(cpp|bin)")
  55. print("Author: rhapsodyv")
  56. exit(1)
  57. output_img = sys.argv[2]
  58. img = Image.open(sys.argv[1])
  59. image2bin(img, output_img)