iconsmooth.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2021 Space Wizards Federation
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in all
  12. # copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. # SOFTWARE.
  21. import PIL
  22. import PIL.Image
  23. import sys
  24. import iconsmooth_lib
  25. if len(sys.argv) != 5:
  26. print("iconsmooth.py in.png METRICS <" + iconsmooth_lib.all_conv + "> OUTPREFIX")
  27. print("OUTPREFIX is something like, say, " + iconsmooth_lib.explain_prefix)
  28. print(iconsmooth_lib.explain_mm)
  29. raise Exception("see printed help")
  30. # Input detail configuration
  31. input_name = sys.argv[1]
  32. metric_mode = sys.argv[2]
  33. conversion_mode = sys.argv[3]
  34. out_prefix = sys.argv[4]
  35. # Metric configuration
  36. tile_w, tile_h, subtile_w, subtile_h, remtile_w, remtile_h = iconsmooth_lib.parse_metric_mode(metric_mode)
  37. # Output state configuration
  38. out_states = iconsmooth_lib.conversion_modes[conversion_mode].states
  39. # Source loading
  40. src_img = PIL.Image.open(input_name)
  41. input_row = src_img.size[0] // tile_w
  42. tiles = []
  43. # 48 is the amount of tiles that usually exist, but 56 covers walls with diagonal variants.
  44. for i in range(56):
  45. tile = PIL.Image.new("RGBA", (tile_w, tile_h))
  46. tx = i % input_row
  47. ty = i // input_row
  48. tile.paste(src_img, (tx * -tile_w, ty * -tile_h))
  49. # now split that up
  50. # note that THIS is where the weird ordering gets put into place
  51. tile_a = PIL.Image.new("RGBA", (remtile_w, remtile_h))
  52. tile_a.paste(tile, (-subtile_w, -subtile_h))
  53. tile_b = PIL.Image.new("RGBA", (subtile_w, subtile_h))
  54. tile_b.paste(tile, ( 0, 0))
  55. tile_c = PIL.Image.new("RGBA", (remtile_w, subtile_h))
  56. tile_c.paste(tile, (-subtile_w, 0))
  57. tile_d = PIL.Image.new("RGBA", (subtile_w, remtile_h))
  58. tile_d.paste(tile, ( 0, -subtile_h))
  59. tiles.append([tile_a, tile_b, tile_c, tile_d])
  60. state_size = (tile_w * 2, tile_h * 2)
  61. for state in range(len(out_states)):
  62. full = PIL.Image.new("RGBA", state_size)
  63. full.paste(tiles[out_states[state][0]][0], (subtile_w, subtile_h))
  64. full.paste(tiles[out_states[state][1]][1], (tile_w, 0))
  65. full.paste(tiles[out_states[state][2]][2], (subtile_w, tile_h))
  66. full.paste(tiles[out_states[state][3]][3], (tile_w, tile_h + subtile_h))
  67. full.save(out_prefix + str(state) + ".png")
  68. full_finale = PIL.Image.new("RGBA", (tile_w, tile_h))
  69. full_finale.paste(tiles[out_states[0][0]][0], (subtile_w, subtile_h))
  70. full_finale.paste(tiles[out_states[0][1]][1], (0, 0))
  71. full_finale.paste(tiles[out_states[0][2]][2], (subtile_w, 0))
  72. full_finale.paste(tiles[out_states[0][3]][3], (0, subtile_h))
  73. full_finale.save(out_prefix + "full.png")