add image array code generator

This commit is contained in:
interfisch 2023-09-20 19:53:32 +02:00
parent f2aef6201a
commit be9d6091d1
5 changed files with 47 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -0,0 +1,47 @@
from PIL import Image
import math
import argparse
parser = argparse.ArgumentParser(
prog = 'Image Edit Script',
description = 'Manipulate or extract information from an image file',
epilog = '')
parser.add_argument('filename') # positional argument
parser.add_argument('-o', '--output') # option that takes a value
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
args = parser.parse_args()
print(args.filename, args.output, args.verbose)
im = Image.open(args.filename) # Can be many different formats.
pix = im.load()
print(im.size) # Get the width and hight of the image for iterating over
print(pix[10,10]) # Get the RGBA Value of the a pixel of an image
def calculateDistance(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
with open('result.txt', 'w') as f:
for x in range(im.size[0]):
f.write("backBuffer[")
f.write(str(x))
f.write("]=0b")
for y in range(im.size[1]):
c = pix[x,y] #get pixel
if (c[0]>127):
f.write("1")
else:
f.write("0")
f.write(";")
f.write('\r\n')

BIN
imagegenerator/rowsEven.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
imagegenerator/rowsOdd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB