1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-12-22 01:26:17 +01:00

Continue image tool

This commit is contained in:
Miloslav Číž 2019-06-02 20:22:42 +02:00
parent d9c53f4bd5
commit 4a3be94d79
2 changed files with 43 additions and 11 deletions

View file

@ -3,16 +3,39 @@
# by drummyfish
# released under CC0 1.0.
import sys
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"
NAME = "house"
OUT_WIDTH = 256
OUT_HEIGHT = 256
for s in sys.argv:
if s [:2] == "-x":
OUT_WIDTH = int(s[2:])
elif s [:2] == "-y":
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")
pixels = image.load()
@ -22,8 +45,8 @@ pixels2 = image2.load()
imageArray = []
for y in range(OUT_WIDTH):
for x in range(OUT_HEIGHT):
for y in range(OUT_HEIGHT):
for x in range(OUT_WIDTH):
coord = (
int(x / float(OUT_WIDTH) * image.size[0]),
int(y / float(OUT_HEIGHT) * image.size[1]))
@ -34,6 +57,12 @@ for y in range(OUT_WIDTH):
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() + "_HEIGHT " + str(OUT_HEIGHT))
print("")
@ -57,4 +86,7 @@ for v in imageArray:
print(arrayString[:-1])
print("}; // " + NAME + "Texture")
image2.save("out.png")
if GUARDS:
print("\n#endif // guard")
image2.save(NAME + "_preview.png")

View file

@ -150,8 +150,8 @@ def arrayString(name, array, components, scales, align, short, dataType):
result = ""
if GUARDS:
print("#ifndef " + NAME.upper() + "_H")
print("#define " + NAME.upper() + "_H\n")
print("#ifndef " + NAME.upper() + "_MODEL_H")
print("#define " + NAME.upper() + "_MODEL_H\n")
print(arrayString(NAME + "Vertices",vertices,3,[VERTEX_SCALE],5,False,"S3L_Unit"))
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("S3L_Model3D " + NAME + " = ")
print("S3L_Model3D " + NAME + "Model = ")
if COMPACT:
print("{.vertices=" +