-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added python scripts to create and prepare patterns
- Loading branch information
1 parent
aefb812
commit 599f20f
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |