Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- # This script will stitch together the many
- # Optifine CTM files into a single Fusion CTM image.
- # It WILL NOT assemble the resource pack for you
- # Python 3 and PyPNG must be installed!
- # USE AT YOUR OWN RISK! I AM NOT RESPONSIBLE FOR ANY DATA LOSS
- # 🐾 [email protected] 🐾
- # This bit makes sure that Python correctly recognizes which
- # folder the script runs in regardless of your OS
- import sys, os
- if sys.path[0] == "": sys.path[0] = os.getcwd()
- else: os.chdir(sys.path[0])
- def getFolderContents(address=sys.path[0]):
- if address[-1] == "/" or address[-1] == "\\":
- address = address[0:-1]
- if not os.path.isdir(address):
- return {}
- folders = {}
- files = {}
- names = os.listdir(address)
- for name in names:
- if os.path.isdir(address + "/" + name):
- folders[len(folders)] = name
- if os.path.isfile(address + "/" + name):
- files[len(files)] = name
- return folders, files
- #=================================================#
- print("\n S T A R T I N G \n")
- import png
- def getPixel(filenum, x, y):
- file = str(filenum) + ".png"
- if not os.path.isfile(file):
- return [ 0, 0, 0, 0 ]
- reader = png.Reader(filename=file)
- width, height, pixels, metadata = reader.read()
- pixel_list = list(pixels)
- red = pixel_list[y][x*4+0]
- green = pixel_list[y][x*4+1]
- blue = pixel_list[y][x*4+2]
- alpha = pixel_list[y][x*4+3]
- return [ red, green, blue, alpha ]
- grid_map = [
- [ 0, 1, 2, 3, 4, 5, 6, 7 ],
- [ 12, 13, 14, 15, 16, 17, 18, 19 ],
- [ 24, 25, 26, 27, 30, 31, 28, 29 ],
- [ 36, 37, 38, 39, 42, 43, 40, 41 ],
- [ 34, 46, 23, 22, 9, 21, 32, 33 ],
- [ 35, 99, 11, 10, 8, 20, 44, 45 ],
- [ 99, 99, 99, 99, 99, 99, 99, 99 ],
- [ 99, 99, 99, 99, 99, 99, 99, 99 ] ]
- grid_t = len(grid_map)
- grid_z = len(grid_map[0])
- # Read pixel dimension of the input images
- reader = png.Reader(filename="0.png")
- pixel_x, pixel_y, pixels, metadata = reader.read()
- image_data = [[0]*(pixel_x*grid_z*4)]*(pixel_y*grid_t)
- # Iterate through the grid
- for t in range(grid_t):
- for z in range(grid_z):
- # This happens for every block
- w = str(grid_map[t][z]) + ".png"
- if not os.path.isfile(w):
- continue
- reader = png.Reader(filename=w)
- pixel_x, pixel_y, pixels, metadata = reader.read()
- pixel_list = list(pixels)
- # Iterate through one block
- for y in range(pixel_y):
- for x in range(pixel_x):
- # This happens for every pixel
- image_data[t*pixel_y+y][z*pixel_x*4+x] = pixel_list[y][x]
- written = png.Writer(pixel_x*grid_z, pixel_y*grid_t,
- bitdepth=8, alpha=True, greyscale=False)
- with open("fusion_grid.png", "wb") as f:
- written.write(f, image_data)
- print("\n D O N E \n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement