+ minetestmapper2, colors modified for Minetest Δ
authorNils Dagsson Moskopp <nils@dieweltistgarnichtso.net>
Thu, 2 Jun 2011 14:17:50 +0000 (16:17 +0200)
committerNils Dagsson Moskopp <nils@dieweltistgarnichtso.net>
Thu, 2 Jun 2011 14:17:50 +0000 (16:17 +0200)
minetestmapper/colors.txt [new file with mode: 0644]
minetestmapper/minetestmapper2.py [new file with mode: 0755]

diff --git a/minetestmapper/colors.txt b/minetestmapper/colors.txt
new file mode 100644 (file)
index 0000000..a7f8a36
--- /dev/null
@@ -0,0 +1,22 @@
+0 128 128 128\r
+1 107 134 51\r
+2 39 66 106\r
+3 255 255 0\r
+4 86 58 31\r
+5 48 95 8\r
+6 102 129 38\r
+7 178 178 0\r
+8 101 84 36\r
+9 39 66 106\r
+12 104 78 42\r
+13 210 194 156\r
+14 117 86 41\r
+15 128 79 0\r
+16 118 118 118\r
+18 123 123 123\r
+19 199 199 199\r
+20 183 183 222\r
+21 103 78 42\r
+23 115 210 22\r
+24 204 0 0\r
+25 211 215 207\r
diff --git a/minetestmapper/minetestmapper2.py b/minetestmapper/minetestmapper2.py
new file mode 100755 (executable)
index 0000000..f9b681b
--- /dev/null
@@ -0,0 +1,272 @@
+#!/usr/bin/env python\r
+# -*- coding: windows-1252 -*-\r
+\r
+# Made by j0gge, modified by celeron55\r
+\r
+# This program is free software. It comes without any warranty, to\r
+# the extent permitted by applicable law. You can redistribute it\r
+# and/or modify it under the terms of the Do What The Fuck You Want\r
+# To Public License, Version 2, as published by Sam Hocevar. See\r
+# http://sam.zoy.org/wtfpl/COPYING for more details.\r
+\r
+# Requires Python Imaging Library: http://www.pythonware.com/products/pil/\r
+\r
+# Some speed-up: ...lol, actually it slows it down.\r
+#import psyco ; psyco.full() \r
+#from psyco.classes import *\r
+\r
+import zlib\r
+import Image, ImageDraw\r
+import os\r
+import string\r
+import time\r
+\r
+def hex_to_int(h):\r
+       i = int(h,16)\r
+       if(i > 2047):\r
+               i-=4096\r
+       return i\r
+\r
+def hex4_to_int(h):\r
+       i = int(h,16)\r
+       if(i > 32767):\r
+               i-=65536\r
+       return i\r
+\r
+def int_to_hex3(i):\r
+       if(i < 0):\r
+               return "%03X" % (i + 4096)\r
+       else:\r
+               return "%03X" % i\r
+\r
+def int_to_hex4(i):\r
+       if(i < 0):\r
+               return "%04X" % (i + 65536)\r
+       else:\r
+               return "%04X" % i\r
+\r
+def limit(i,l,h):\r
+       if(i>h):\r
+               i=h\r
+       if(i<l):\r
+               i=l\r
+       return i\r
+       \r
+# Fix these!\r
+path="../map/"\r
+output="map.png"\r
+\r
+sector_xmin = -1000/16\r
+sector_xmax = 1000/16\r
+sector_zmin = -1000/16\r
+sector_zmax = 1000/16\r
+\r
+# Load color information for the blocks.\r
+colors = {}\r
+f = file("colors.txt")\r
+for line in f:\r
+       values = string.split(line)\r
+       colors[int(values[0])] = (int(values[1]), int(values[2]), int(values[3]))\r
+f.close()\r
+\r
+xlist = []\r
+zlist = []\r
+\r
+# List all sectors to memory and calculate the width and heigth of the resulting picture.\r
+for filename in os.listdir(path + "sectors2"):\r
+       for filename2 in os.listdir(path + "sectors2/" + filename):\r
+               x = hex_to_int(filename)\r
+               z = hex_to_int(filename2)\r
+               if x < sector_xmin or x > sector_xmax:\r
+                       continue\r
+               if z < sector_zmin or z > sector_zmax:\r
+                       continue\r
+               xlist.append(x)\r
+               zlist.append(z)\r
+for filename in os.listdir(path + "sectors"):\r
+       x = hex4_to_int(filename[:4])\r
+       z = hex4_to_int(filename[-4:])\r
+       if x < sector_xmin or x > sector_xmax:\r
+               continue\r
+       if z < sector_zmin or z > sector_zmax:\r
+               continue\r
+       xlist.append(x)\r
+       zlist.append(z)\r
+\r
+w = (max(xlist) - min(xlist)) * 16 + 16\r
+h = (max(zlist) - min(zlist)) * 16 + 16\r
+\r
+print "w="+str(w)+" h="+str(h)\r
+\r
+im = Image.new("RGB", (w, h), "white")\r
+impix = im.load()\r
+\r
+stuff={}\r
+\r
+starttime = time.time()\r
+\r
+# Go through all sectors.\r
+for n in range(len(xlist)):\r
+       #if n > 500:\r
+       #       break\r
+       if n % 200 == 0:\r
+               nowtime = time.time()\r
+               dtime = nowtime - starttime\r
+               n_per_second = 1.0 * n / dtime\r
+               if n_per_second != 0:\r
+                       seconds_per_n = 1.0 / n_per_second\r
+                       time_guess = seconds_per_n * len(xlist)\r
+                       remaining_s = time_guess - dtime\r
+                       remaining_minutes = int(remaining_s / 60)\r
+                       remaining_s -= remaining_minutes * 60;\r
+                       print("Processing sector "+str(n)+" of "+str(len(xlist))\r
+                                       +" ("+str(round(100.0*n/len(xlist), 1))+"%)"\r
+                                       +" (ETA: "+str(remaining_minutes)+"m "\r
+                                       +str(int(remaining_s))+"s)")\r
+\r
+       xpos = xlist[n]\r
+       zpos = zlist[n]\r
+       \r
+       xhex = int_to_hex3(xpos)\r
+       zhex = int_to_hex3(zpos)\r
+       xhex4 = int_to_hex4(xpos)\r
+       zhex4 = int_to_hex4(zpos)\r
+       \r
+       sector1 = xhex4.lower() + zhex4.lower()\r
+       sector2 = xhex.lower() + "/" + zhex.lower()\r
+       \r
+       ylist=[]\r
+       \r
+       sectortype = ""\r
+       \r
+       try:\r
+               for filename in os.listdir(path + "sectors/" + sector1):\r
+                       if(filename != "meta"):\r
+                               pos = int(filename,16)\r
+                               if(pos > 32767):\r
+                                       pos-=65536\r
+                               ylist.append(pos)\r
+                               sectortype = "old"\r
+       except OSError:\r
+               pass\r
+       \r
+       if sectortype != "old":\r
+               try:\r
+                       for filename in os.listdir(path + "sectors2/" + sector2):\r
+                               if(filename != "meta"):\r
+                                       pos = int(filename,16)\r
+                                       if(pos > 32767):\r
+                                               pos-=65536\r
+                                       ylist.append(pos)\r
+                                       sectortype = "new"\r
+               except OSError:\r
+                       pass\r
+       \r
+       if sectortype == "":\r
+               continue\r
+\r
+       ylist.sort()\r
+       \r
+       # Make a list of pixels of the sector that are to be looked for.\r
+       pixellist = []\r
+       for x in range(16):\r
+               for y in range(16):\r
+                       pixellist.append((x,y))\r
+       \r
+       # Go through the Y axis from top to bottom.\r
+       for ypos in reversed(ylist):\r
+               \r
+               yhex = int_to_hex4(ypos)\r
+\r
+               filename = ""\r
+               if sectortype == "old":\r
+                       filename = path + "sectors/" + sector1 + "/" + yhex.lower()\r
+               else:\r
+                       filename = path + "sectors2/" + sector2 + "/" + yhex.lower()\r
+\r
+               f = file(filename, "rb")\r
+\r
+               # Let's just memorize these even though it's not really necessary.\r
+               version = f.read(1)\r
+               flags = f.read(1)\r
+\r
+               dec_o = zlib.decompressobj()\r
+               try:\r
+                       mapdata = dec_o.decompress(f.read())\r
+               except:\r
+                       mapdata = []\r
+                       \r
+               f.close()\r
+               \r
+               if(len(mapdata)<4096):\r
+                       print "bad: " + xhex+zhex+"/"+yhex + " " + len(mapdata)\r
+               else:\r
+                       chunkxpos=xpos*16\r
+                       chunkypos=ypos*16\r
+                       chunkzpos=zpos*16\r
+                       for (x,z) in reversed(pixellist):\r
+                               for y in reversed(range(16)):\r
+                                       datapos=x+y*16+z*256\r
+                                       if(ord(mapdata[datapos])!=254):\r
+                                               try:\r
+                                                       pixellist.remove((x,z))\r
+                                                       # Memorize information on the type and height of the block and for drawing the picture.\r
+                                                       stuff[(chunkxpos+x,chunkzpos+z)]=(chunkypos+y,ord(mapdata[datapos]))\r
+                                                       break\r
+                                               except:\r
+                                                       print "strange block: " + xhex+zhex+"/"+yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " block: " + str(ord(mapdata[datapos]))\r
+               \r
+               # After finding all the pixeld in the sector, we can move on to the next sector without having to continue the Y axis.\r
+               if(len(pixellist)==0):\r
+                       break\r
+\r
+print "Drawing image"\r
+# Drawing the picture\r
+starttime = time.time()\r
+n = 0\r
+minx = min(xlist)\r
+minz = min(zlist)\r
+for (x,z) in stuff.iterkeys():\r
+       if n % 500000 == 0:\r
+               nowtime = time.time()\r
+               dtime = nowtime - starttime\r
+               n_per_second = 1.0 * n / dtime\r
+               if n_per_second != 0:\r
+                       listlen = len(stuff)\r
+                       seconds_per_n = 1.0 / n_per_second\r
+                       time_guess = seconds_per_n * listlen\r
+                       remaining_s = time_guess - dtime\r
+                       remaining_minutes = int(remaining_s / 60)\r
+                       remaining_s -= remaining_minutes * 60;\r
+                       print("Drawing pixel "+str(n)+" of "+str(listlen)\r
+                                       +" ("+str(round(100.0*n/listlen, 1))+"%)"\r
+                                       +" (ETA: "+str(remaining_minutes)+"m "\r
+                                       +str(int(remaining_s))+"s)")\r
+       n += 1\r
+\r
+       (r,g,b)=colors[stuff[(x,z)][1]]\r
+       \r
+       # Comparing heights of a couple of adjacent blocks and changing brightness accordingly.\r
+       try:\r
+               y1=stuff[(x-1,z)][0]\r
+               y2=stuff[(x,z-1)][0]\r
+               y=stuff[(x,z)][0]\r
+               \r
+               d=(y-y1+y-y2)*12\r
+               \r
+               if(d>36):\r
+                       d=36\r
+                       \r
+               r=limit(r+d,0,255)\r
+               g=limit(g+d,0,255)\r
+               b=limit(b+d,0,255)\r
+       except:\r
+               pass\r
+       #impix[w-1-(x-minx*16),h-1-(z-minz*16)]=(r,g,b)\r
+       impix[x-minx*16,h-1-(z-minz*16)]=(r,g,b)\r
+\r
+# Flip the picture to make it right and save.\r
+#print "Transposing"\r
+#im=im.transpose(Image.FLIP_TOP_BOTTOM)        \r
+print "Saving"\r
+im.save(output)\r