First commit

This commit is contained in:
James Wood 2020-08-24 14:39:10 +10:00
parent 2396a52752
commit 0fad25dc91
5 changed files with 84 additions and 1 deletions

View File

@ -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)

33
RRF-Gen.py Normal file
View File

@ -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()

34
RRF-View.py Normal file
View File

@ -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

BIN
nozzle.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 B

1
nozzle.img Normal file
View File

@ -0,0 +1 @@
øÀøÀøÀððÀÀ