Advertisement
Guest User

Untitled

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