diff --git a/README.md b/README.md index 8ae9adc..b84083f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # RepRapFirmware-Image-Tools -Tools to generate and test RepRapFirmware LCD images +Python tools to generate and test RepRapFirmware LCD images from any common image format. Preserves the pixel dimensions, reduces to single-colour. + +## Requirements +Python3 +math, sys, and PIL libraries installed + +## RRF-Gen.py +Generates images for use with the [RepRapFirmware 128x64 LCD implementation](https://duet3d.dozuki.com/Wiki/Duet_2_Maestro_12864_display_menu_system) +Usage: `./RRF-Gen.py [inputfile] [outputfile]` +eg: `./RRF-Gen.py nozzle.gif nozzle.img` + +## RRF-View.py +Displays a preview of the images + +## In use +I used this to generate some images for [my menu setup](https://github.com/jameswood/Duet-Maestro-Menu) \ No newline at end of file diff --git a/RRF-Gen.py b/RRF-Gen.py new file mode 100644 index 0000000..6cad09a --- /dev/null +++ b/RRF-Gen.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 +import math +import sys +from PIL import Image + +image = Image.open(sys.argv[1]).convert('L') + +bitsPerRow = math.ceil(image.width/8) * 8 +paddingBits = bitsPerRow - image.width +outputFile = open(sys.argv[2], "wb") + +outputFile.write(bytes((image.width,))) +outputFile.write(bytes((image.height,))) + +for row in range(image.height): + outputByte = "" + bitCounter = 0 + for column in range(image.width): + pixel = image.getpixel((column,row)) + if bitCounter > 7: + outputFile.write(bytes((int(outputByte,2),))) + outputByte = "" + bitCounter = 0 + if pixel > 128: + outputByte += "0" + else: + outputByte += "1" + bitCounter += 1 + for i in range(0, paddingBits): + outputByte += "0" + outputFile.write(bytes((int(outputByte,2),))) + +outputFile.close() \ No newline at end of file diff --git a/RRF-View.py b/RRF-View.py new file mode 100644 index 0000000..1c17fe5 --- /dev/null +++ b/RRF-View.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +import math +import sys + +inputFile = open(sys.argv[1], "rb") +print("opening ", sys.argv[1]) +contents = inputFile.read() +byteCount = 0 +imageBytes = '' + +for char in contents: + if byteCount == 0: width=char + elif byteCount == 1: height = char + else: + imageBytes += "{:08b}".format(char) + byteCount += 1 + +bitsPerRow = math.ceil(width/8) * 8 + +print(" width: ", width) +print("height: ", height) +print("padded bits per row: ", bitsPerRow) + +bitNumber = 1 +row = 0 +for bit in imageBytes: + if bit == '0': bit = '◻︎' + if bit == '1': bit = '◼︎' + if bitNumber - (bitsPerRow * row) <= width: + print(bit, end='') + if bitNumber % bitsPerRow == 0: + print() + row += 1 + bitNumber += 1 diff --git a/nozzle.gif b/nozzle.gif new file mode 100644 index 0000000..1815e7e Binary files /dev/null and b/nozzle.gif differ diff --git a/nozzle.img b/nozzle.img new file mode 100644 index 0000000..0c23641 --- /dev/null +++ b/nozzle.img @@ -0,0 +1 @@ +øÀøÀøÀððÀÀ€ \ No newline at end of file