Skip to content

Commit

Permalink
Added python scripts to create and prepare patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
berCamargos committed Oct 13, 2017
1 parent aefb812 commit 599f20f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions createImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import colorsys

font = ImageFont.truetype("/usr/share/fonts/truetype/DejaVuSans.ttf",275)

#RGB represent a 4 byte int
img_std=Image.new("RGBA", (1920,1080),(0, 0, 0, 0))

#This is the actual color
img=Image.new("RGBA", (1920,1080),(255,255,255,255))

draw = ImageDraw.Draw(img)
textcolor = list(colorsys.hsv_to_rgb(200/360.0, 1, 1))
textcolor.append(1)
textcolor = tuple([int(color*255) for color in textcolor])
draw.text((1000, 100),"aMuDi",textcolor,font=font)

draw_std = ImageDraw.Draw(img_std)
draw_std.text((1000, 100),"aMuDi",(255, 255, 255, 255),font=font)

img = img.convert('RGBA')
img.save("test.png")
img_std.save("test_std.png")
33 changes: 33 additions & 0 deletions parseImages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from PIL import Image
import colorsys
import struct


filebase = 'test'
img = Image.open(filebase + ".png")
img_std = Image.open(filebase + "_std.png")

pix = img.load()
pix_std = img_std.load()
if img.size != img_std.size:
raise Exception("Images should have the same size")
print(img.size) #Get the width and hight of the image for iterating over
result = open(filebase+'.res', 'wb')
for y in range(img.size[1]):
print(y)
for x in range(img.size[0]):
# For std image we have to convert RGBA to a 4 byte int
rgba = pix_std[x, y]
bvalues = []
for val in rgba:
bvalues.append(struct.pack('>B', val))
for bvalue in reversed(bvalues):
result.write(bvalue)

# For normal image we have to convert RGB to HSV, but if A is deferent than
rgba = pix[x, y]
hue = colorsys.rgb_to_hsv(rgba[0]/255.0, rgba[1]/255.0, rgba[2]/255.0)[0]*360
#Need to convert to 2 byte
hue = struct.pack('>H', int(hue))
result.write(hue)
result.close()

0 comments on commit 599f20f

Please sign in to comment.