mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-21 20:39:57 +01:00
Continue image tool
This commit is contained in:
parent
d9c53f4bd5
commit
4a3be94d79
2 changed files with 43 additions and 11 deletions
48
img2array.py
48
img2array.py
|
@ -3,16 +3,39 @@
|
||||||
# by drummyfish
|
# by drummyfish
|
||||||
# released under CC0 1.0.
|
# released under CC0 1.0.
|
||||||
|
|
||||||
|
import sys
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
def printHelp():
|
||||||
|
print("Convert image to C array for small3dlib.")
|
||||||
|
print("usage:\n")
|
||||||
|
print(" python img2array.py [TODO] file\n")
|
||||||
|
print(" TODO\n")
|
||||||
|
print("");
|
||||||
|
print("by Miloslav \"drummyfish\" Ciz")
|
||||||
|
print("released under CC0 1.0")
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
printHelp()
|
||||||
|
quit()
|
||||||
|
|
||||||
|
FILENAME = ""
|
||||||
|
NAME = "texture"
|
||||||
|
GUARDS = False
|
||||||
|
OUT_WIDTH = 64
|
||||||
|
OUT_HEIGHT = 64
|
||||||
|
|
||||||
FILENAME = "house.png"
|
for s in sys.argv:
|
||||||
NAME = "house"
|
if s [:2] == "-x":
|
||||||
|
OUT_WIDTH = int(s[2:])
|
||||||
OUT_WIDTH = 256
|
elif s [:2] == "-y":
|
||||||
OUT_HEIGHT = 256
|
OUT_HEIGHT = int(s[2:])
|
||||||
|
elif s == "-h":
|
||||||
|
GUARDS = True
|
||||||
|
elif s[:2] == "-n":
|
||||||
|
NAME = s[2:]
|
||||||
|
else:
|
||||||
|
FILENAME = s
|
||||||
|
|
||||||
image = Image.open(FILENAME).convert("RGB")
|
image = Image.open(FILENAME).convert("RGB")
|
||||||
pixels = image.load()
|
pixels = image.load()
|
||||||
|
@ -22,8 +45,8 @@ pixels2 = image2.load()
|
||||||
|
|
||||||
imageArray = []
|
imageArray = []
|
||||||
|
|
||||||
for y in range(OUT_WIDTH):
|
for y in range(OUT_HEIGHT):
|
||||||
for x in range(OUT_HEIGHT):
|
for x in range(OUT_WIDTH):
|
||||||
coord = (
|
coord = (
|
||||||
int(x / float(OUT_WIDTH) * image.size[0]),
|
int(x / float(OUT_WIDTH) * image.size[0]),
|
||||||
int(y / float(OUT_HEIGHT) * image.size[1]))
|
int(y / float(OUT_HEIGHT) * image.size[1]))
|
||||||
|
@ -34,6 +57,12 @@ for y in range(OUT_WIDTH):
|
||||||
|
|
||||||
pixels2[x,y] = pixel
|
pixels2[x,y] = pixel
|
||||||
|
|
||||||
|
#-----------------------
|
||||||
|
|
||||||
|
if GUARDS:
|
||||||
|
print("#ifndef " + NAME.upper() + "_TEXTURE_H")
|
||||||
|
print("#define " + NAME.upper() + "_TEXTURE_H\n")
|
||||||
|
|
||||||
print("#define " + NAME.upper() + "_WIDTH " + str(OUT_WIDTH))
|
print("#define " + NAME.upper() + "_WIDTH " + str(OUT_WIDTH))
|
||||||
print("#define " + NAME.upper() + "_HEIGHT " + str(OUT_HEIGHT))
|
print("#define " + NAME.upper() + "_HEIGHT " + str(OUT_HEIGHT))
|
||||||
print("")
|
print("")
|
||||||
|
@ -57,4 +86,7 @@ for v in imageArray:
|
||||||
print(arrayString[:-1])
|
print(arrayString[:-1])
|
||||||
print("}; // " + NAME + "Texture")
|
print("}; // " + NAME + "Texture")
|
||||||
|
|
||||||
image2.save("out.png")
|
if GUARDS:
|
||||||
|
print("\n#endif // guard")
|
||||||
|
|
||||||
|
image2.save(NAME + "_preview.png")
|
||||||
|
|
|
@ -150,8 +150,8 @@ def arrayString(name, array, components, scales, align, short, dataType):
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
if GUARDS:
|
if GUARDS:
|
||||||
print("#ifndef " + NAME.upper() + "_H")
|
print("#ifndef " + NAME.upper() + "_MODEL_H")
|
||||||
print("#define " + NAME.upper() + "_H\n")
|
print("#define " + NAME.upper() + "_MODEL_H\n")
|
||||||
|
|
||||||
print(arrayString(NAME + "Vertices",vertices,3,[VERTEX_SCALE],5,False,"S3L_Unit"))
|
print(arrayString(NAME + "Vertices",vertices,3,[VERTEX_SCALE],5,False,"S3L_Unit"))
|
||||||
print(arrayString(NAME + "TriangleIndices",triangles,3,[1],5,True,"S3L_Index"))
|
print(arrayString(NAME + "TriangleIndices",triangles,3,[1],5,True,"S3L_Index"))
|
||||||
|
@ -172,7 +172,7 @@ else:
|
||||||
|
|
||||||
print(arrayString(NAME + "TriangleUVs",uvs2,6,[U_SCALE,V_SCALE],5,False,"S3L_Unit"))
|
print(arrayString(NAME + "TriangleUVs",uvs2,6,[U_SCALE,V_SCALE],5,False,"S3L_Unit"))
|
||||||
|
|
||||||
print("S3L_Model3D " + NAME + " = ")
|
print("S3L_Model3D " + NAME + "Model = ")
|
||||||
|
|
||||||
if COMPACT:
|
if COMPACT:
|
||||||
print("{.vertices=" +
|
print("{.vertices=" +
|
||||||
|
|
Loading…
Reference in a new issue