]> marstr Code Repo - orthographic/commitdiff
Further fine tuning to rendering and layering, added subtle details to different...
authorMarcus Str. <marcus@marstr.online>
Sat, 12 Oct 2024 19:18:39 +0000 (21:18 +0200)
committerMarcus Str. <marcus@marstr.online>
Sat, 12 Oct 2024 19:18:39 +0000 (21:18 +0200)
21 files changed:
defines.py
layergen.py
photogen.py
textures/building/area/p1.png
textures/building/area/p10.png
textures/building/area/p11.png
textures/building/area/p12.png
textures/building/area/p13.png
textures/building/area/p14.png
textures/building/area/p15.png
textures/building/area/p16.png [new file with mode: 0644]
textures/building/area/p17.png [new file with mode: 0644]
textures/building/area/p18.png [new file with mode: 0644]
textures/building/area/p2.png
textures/building/area/p3.png
textures/building/area/p4.png
textures/building/area/p5.png
textures/building/area/p6.png
textures/building/area/p7.png
textures/building/area/p8.png
textures/building/area/p9.png

index baf0c4464d77ca44e7ce7111486d9fbe471775c2..89ed6310c139e809888c18b1f093b43b9b0a6d0c 100644 (file)
@@ -148,6 +148,8 @@ mstr_ortho_layers = [
     ("highway", "living_street", 12),\r
     ("waterway", "river", 10),\r
     ("waterway", "stream", 2),\r
+    ("amenity", "parking", "amenity", "parking"),\r
+    ("amenity", "school", "amenity", "school"),\r
     ("leisure", "nature_reserve", "landuse", "forest"),\r
     ("landuse", "forest", "landuse", "forest"),\r
     ("natural", "wood", "natural", "wood"),\r
@@ -165,8 +167,6 @@ mstr_ortho_layers = [
     ("water", "pond", "natural", "water"),\r
     ("water", "river", "natural", "water"),\r
     ("leisure", "swimming_pool", "natural", "water"),\r
-    ("amenity", "parking", "amenity", "parking"),\r
-    ("amenity", "school", "amenity", "school"),\r
     ("highway", "pedestrian", 4),\r
     # Z-Order 4\r
     ("highway", "motorway", 32),\r
@@ -189,9 +189,9 @@ mstr_ortho_layers = [
     ("building", "terrace", "building", "industrial"),\r
     ("building", "hangar", "building", "industrial"),\r
     ("building", "school", "building", "common"),\r
-       ("building", "kindergarten", "building", "kindergarten"),\r
-       ("building", "public", "building", "public"),\r
-       ("building", "commercial", "building", "commercial"),\r
+    ("building", "kindergarten", "building", "kindergarten"),\r
+    ("building", "public", "building", "public"),\r
+    ("building", "commercial", "building", "commercial"),\r
     ("building", "yes", "building", "common"),\r
     ("place", "sea", "natural", "sea"),\r
     ("place", "ocean", "natural", "sea")\r
@@ -395,6 +395,15 @@ mstr_building_base_colors = [
 ]\r
 \r
 \r
+# Base colors to add some details to all kinds of buildings\r
+mstr_building_detail_colors = [\r
+    (136, 132, 86),  # Some kind of moss\r
+    (136, 90, 86),   # Some kind of rust or darkening\r
+    (154, 154, 154), # Other random details\r
+    (97, 97, 97)     # Square or line details, alpha-blended\r
+]\r
+\r
+\r
 mstr_completion_colors = [\r
     ("+50+000", [\r
         (48,63,34),\r
index a74b2347f201d920bdf2149cb284c5b2f9c279b6..c873a2b17bd6601875703b8d55f9d7f436c89e8c 100644 (file)
@@ -16,7 +16,7 @@ import glob
 import os\r
 from random import randrange\r
 import random\r
-from PIL import Image, ImageFilter, ImageDraw, ImagePath, ImageEnhance\r
+from PIL import Image, ImageFilter, ImageDraw\r
 from defines import *\r
 from log import *\r
 from tileinfo import *\r
@@ -56,11 +56,6 @@ class mstr_layergen:
     def set_latlng_folder(self, latlngfld):\r
         self._latlngfld = latlngfld\r
 \r
-    # Open DB\r
-    def open_db(self):\r
-        self._tiledb = mstr_tiledb(self._latitude, self._longitude, self._latlngfld)\r
-        self._tiledb.create_tables()\r
-\r
     # Tile info object\r
     def open_tile_info(self):\r
         self._tileinfo = mstr_tileinfo(self._latitude, self._longitude, self._lat_number, self._lng_number, self._latlngfld)\r
@@ -473,7 +468,8 @@ class mstr_layergen:
                     for x in range(self._imgsize):\r
                         tp = tree_pix[x,y]\r
                         if tp[3] > 0:\r
-                            sc = (0,0,0,180)\r
+                            rndshd = randrange(5, 210)\r
+                            sc = (0,0,0,rndshd)\r
                             if x+8 < self._imgsize and y+5 < self._imgsize:\r
                                 shadow_pix[x+8,y+5] = sc\r
                 tree_shadow = tree_shadow.filter(ImageFilter.GaussianBlur(radius=2))\r
@@ -547,18 +543,12 @@ class mstr_layergen:
                 if os.path.isfile(fn):\r
                     rsd = Image.open(fn)\r
                     rsd_pix = rsd.load()\r
-                    forest_layer = Image.new("RGBA", (self._imgsize, self._imgsize))\r
-                    for_pix = forest_layer.load()\r
                     for y in range(self._imgsize):\r
                         for x in range(self._imgsize):\r
                             rpix = rsd_pix[x,y]\r
                             lpix = layer_comp_pix[x,y]\r
                             if rpix[3] > 0 and lpix[3] > 0:\r
-                                for_pix[x,y] = (rpix[0], rpix[1], rpix[2], rpix[3])\r
-                    layer_comp.alpha_composite(forest_layer)\r
-                #if os.path.isfile(fn) == True:\r
-                #    rsd = Image.open(fn)\r
-                #    layer_comp.alpha_composite(rsd)\r
+                                layer_comp_pix[x,y] = (lpix[0], lpix[1], lpix[2], 255-rpix[3])\r
 \r
             # Store layer\r
             if self._is_completion == False:\r
@@ -612,20 +602,6 @@ class mstr_layergen:
 \r
                             shadow = shadow.filter(ImageFilter.GaussianBlur(radius=1.5))\r
 \r
-                            """\r
-                            for y in range(self._imgsize-1):\r
-                                for x in range(self._imgsize-1):\r
-                                    m = mask_pix[x,y]\r
-                                    shf_x = 0\r
-                                    shf_x = x + mstr_shadow_shift\r
-                                    if shf_x < self._imgsize:\r
-                                        a = mask_pix[x,y][3]\r
-                                        st = 0\r
-                                        st = random.uniform(0.45, mstr_shadow_strength)\r
-                                        ca = a * st\r
-                                        aa = int(ca)\r
-                                        shadow_pix[shf_x, y] = (0,0,0,aa)\r
-                            """\r
                             shadow.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")\r
                             mstr_msg("layergen", "Shadow layer completed")\r
 \r
@@ -638,14 +614,14 @@ class mstr_layergen:
             ab=False\r
             al=False\r
             layer_pix = layer_comp.load() # <- Just to be safe\r
-            \r
+\r
             # Top scan\r
             for i in range(0, self._imgsize-1):\r
                 p = layer_pix[i,0]\r
                 if p[3] > 0:\r
                     at=True\r
                     break\r
-            \r
+           \r
             # Right scan\r
             for i in range(0, self._imgsize-1):\r
                 p = layer_pix[self._imgsize-1,i]\r
@@ -842,8 +818,8 @@ class mstr_layergen:
                     details = Image.new("RGBA", (self._imgsize, self._imgsize))\r
                     details_pix = details.load()\r
                     layer_pix = layer_comp.load()\r
-                    for y in range(self._imgsize-1):\r
-                        for x in range(self._imgsize-1):\r
+                    for y in range(self._imgsize):\r
+                        for x in range(self._imgsize):\r
                             p = layer_pix[x,y]\r
                             if p[3] > 0:\r
                                 shf_x = x+randrange(1, 16)\r
@@ -859,6 +835,25 @@ class mstr_layergen:
                                     details_pix[shf_x, shf_y] = (187-d, 179-d, 176-d, aa)\r
                                     details_pix[shf_x2, shf_y2] = (187-d2, 179-d2, 176-d2, aa)\r
 \r
+                    # Image for roof details\r
+                    roof_details = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+                    roof_det_pix = roof_details.load()\r
+                    for y in range(self._imgsize):\r
+                        for x in range(self._imgsize):\r
+                            mp = mask_pix[x,y]\r
+                            if mp[3] == 255:\r
+                                # Determine if we render some pixel\r
+                                rnd = randrange(1, 3)\r
+                                if rnd == 2:\r
+                                    # Find a range for the base color of the pixel\r
+                                    d = randrange(21)\r
+                                    # Find a random alpha value\r
+                                    a = randrange(1, 151)\r
+                                    nc = (mstr_building_detail_colors[0][0]-d, mstr_building_detail_colors[0][1]-d, mstr_building_detail_colors[0][2]-d, a)\r
+                                    roof_det_pix[x,y] = nc\r
+                    layer_comp.alpha_composite(roof_details)\r
+\r
+\r
                     # Let's see how it works with this method\r
                     details.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_details.png")\r
 \r
@@ -899,7 +894,8 @@ class mstr_layergen:
                             for x in range(self._imgsize):\r
                                 tp = tree_pix[x,y]\r
                                 if tp[3] > 0:\r
-                                    sc = (0,0,0,180)\r
+                                    rndshd = randrange(5, 210)\r
+                                    sc = (0,0,0,rndshd)\r
                                     if x+8 < self._imgsize and y+5 < self._imgsize:\r
                                         shadow_pix[x+8,y+5] = sc\r
                         tree_shadow = tree_shadow.filter(ImageFilter.GaussianBlur(radius=2))\r
@@ -959,6 +955,61 @@ class mstr_layergen:
                                 layer_comp_pix[x,y] = (nr, ng, nb, c[3])\r
                     #layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=1))\r
 \r
+\r
+            # Let's add some details to the roofs\r
+            if self._tag == "building":\r
+                vls = [ "detached", "hotel", "farm", "semidetached_house", "apartments", "civic", "house", "school", "kindergarten", "yes" ]\r
+                if self._value in vls:\r
+                    roof_additional_detail = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+                    rad_pix = roof_additional_detail.load()\r
+                    for r in range(30001):\r
+                        lx = randrange(self._imgsize)\r
+                        ly = randrange(self._imgsize)\r
+                        mp = mask_pix[lx,ly]\r
+                        if mp[3] == 255:\r
+                            # Brighter or darker pixel\r
+                            bod = randrange(1,3)\r
+                            c = 0\r
+                            if bod == 2:\r
+                                c = 40\r
+                            else:\r
+                                c = 200\r
+                            dt = (c, c, c, 130)\r
+                            rad_pix[lx,ly] = dt\r
+                            if lx+1 < self._imgsize:\r
+                                rad_pix[lx+1, ly] = dt\r
+                            if lx+1 < self._imgsize and ly+1 < self._imgsize:\r
+                                rad_pix[lx+1, ly+1] = dt\r
+                            if ly+1 < self._imgsize:\r
+                                rad_pix[lx, ly+1] = dt\r
+                    layer_comp.alpha_composite(roof_additional_detail)\r
+            \r
+            # Let's put some other details on commercial buildings\r
+            if self._tag == "building":\r
+                vls = [ "office", "retail", "industrial" ]\r
+                if self._value in vls:\r
+\r
+                    # Find a suitable location to render something\r
+                    for r in range(15001):\r
+                        lx = randrange(self._imgsize)\r
+                        ly = randrange(self._imgsize)\r
+                        mp = mask_pix[lx,ly]\r
+\r
+                        # Think of some random shape\r
+                        if mp[3] == 255:\r
+                            rw = randrange(3,8)\r
+                            rh = randrange(3,8)\r
+                            sh = Image.new("RGBA", (rw, rh), (30,30,30,130))\r
+                            shp = sh.load()\r
+                            for sy in range(rh):\r
+                                for sx in range(rw):\r
+                                    if sx > 0 and sx < rw and sy > 0 and sy < rh: shp[sx, sy] = (180,180,180,160)\r
+                            rt = randrange(1, 3)\r
+                            if rt == 2:\r
+                                sh = sh.rotate(45, expand=True)\r
+\r
+                            layer_comp.alpha_composite(sh, (lx, ly))\r
+\r
             \r
             # Highways and runways of any kind get some special treatment\r
             if (self._tag == "highway" and self._value == "motorway") or (self._tag == "highway" and self._value == "primary") or (self._tag == "highway" and self._value == "secondary") or (self._tag == "highway" and self._value == "tertiary") or (self._tag == "aeroway" and self._value == "runway"):\r
@@ -1072,6 +1123,7 @@ class mstr_layergen:
                     ptc_src.append(Image.open(p))\r
 \r
                 osm_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )\r
+                lyr_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )\r
 \r
                 for i in mstr_mask_blur:\r
                     if i[0] == self._tag and i[1] == self._value:\r
@@ -1095,11 +1147,12 @@ class mstr_layergen:
 \r
                 adj_image.alpha_composite( brd_src )\r
 \r
+                lyr_pix = lyr_mask.load()\r
                 for y in range(self._imgsize):\r
                     for x in range(self._imgsize):\r
-                        if mask_pix[x, y][3] > 0:\r
+                        if lyr_pix[x, y][3] > 0:\r
                             rgb=adj_pix[x,y]\r
-                            a=mask_pix[x,y]\r
+                            a=lyr_pix[x,y]\r
                             adj_pix[x, y] = ( rgb[0], rgb[1], rgb[2], a[3])\r
 \r
                 # Up until here we mimiced the exact same behavior as layergen. However, now\r
index 38cc7c7fb387286585efa8216b125c84cbba2d85..033bef0cbe23b84e5c450c3c97beb95887837fc0 100644 (file)
@@ -71,7 +71,7 @@ class mstr_photogen:
             if l[0] == "building":\r
                 if os.path.isfile(root_filename + l[0] + "-" + l[1] + "_layer.png"):\r
                     bld = Image.open(root_filename + l[0] + "-" + l[1] + "_layer.png")\r
-                    bld = bld.filter(ImageFilter.GaussianBlur(radius=1))\r
+                    bld = bld.filter(ImageFilter.GaussianBlur(radius=0.7))\r
                     bldg_main.alpha_composite(bld)\r
         # Trees merging\r
         tree_main = Image.new("RGBA", (self._imgsize, self._imgsize))\r
index 0791426dcfb653a94a3457c1bfc368537f2ab7a2..7ee361264eb0d28baff6520fa35ec2b979393ecc 100644 (file)
Binary files a/textures/building/area/p1.png and b/textures/building/area/p1.png differ
index 94c7db12efed8bf3b66f4debfc96c1fb947e6ac2..c88100edffb4135ff97cbb96aed15e38802247c6 100644 (file)
Binary files a/textures/building/area/p10.png and b/textures/building/area/p10.png differ
index 5fdda5a9b0484bc86c3aba7e28118622624bd3a1..2f44d725ccc3b396674b86d495ee4af334799faa 100644 (file)
Binary files a/textures/building/area/p11.png and b/textures/building/area/p11.png differ
index fbaff7fc6ca7d5dc25a0f8543a46b7f090e93700..9c22767e0d6bec7fd77de12c5a3de668a48beeab 100644 (file)
Binary files a/textures/building/area/p12.png and b/textures/building/area/p12.png differ
index 13becc639ec5e1b42efad82a1495e973a2293339..972b2bde66b6f224e7167cc51afcd7ec5bae9520 100644 (file)
Binary files a/textures/building/area/p13.png and b/textures/building/area/p13.png differ
index 7d0b7f716c00838f69c59e9be08dccbc0290b3d3..f6597bef71410b004890014fb2e71011fea69893 100644 (file)
Binary files a/textures/building/area/p14.png and b/textures/building/area/p14.png differ
index 9c19a398f7602ecad323a512038d318505a3f156..936e9a76b93bee0a9c5e0f68e5ff77623e57597d 100644 (file)
Binary files a/textures/building/area/p15.png and b/textures/building/area/p15.png differ
diff --git a/textures/building/area/p16.png b/textures/building/area/p16.png
new file mode 100644 (file)
index 0000000..e64aa11
Binary files /dev/null and b/textures/building/area/p16.png differ
diff --git a/textures/building/area/p17.png b/textures/building/area/p17.png
new file mode 100644 (file)
index 0000000..c5f40de
Binary files /dev/null and b/textures/building/area/p17.png differ
diff --git a/textures/building/area/p18.png b/textures/building/area/p18.png
new file mode 100644 (file)
index 0000000..3a4aafc
Binary files /dev/null and b/textures/building/area/p18.png differ
index c4bc6426bbc9a5096d7417bc0f06c2f4648096ed..c7462fe58dec0e9112987b65a06228c40154bdbb 100644 (file)
Binary files a/textures/building/area/p2.png and b/textures/building/area/p2.png differ
index c88a171c468d260a18820afdcd67c32f57c9ed15..4571a5a9fff4614cc271e7b5f78a7a28619f99e1 100644 (file)
Binary files a/textures/building/area/p3.png and b/textures/building/area/p3.png differ
index cb1962aa0135ff0a9f75b94beb7a9e3797409acd..4de2c92150cc006ad7e941c82a7932299beae74c 100644 (file)
Binary files a/textures/building/area/p4.png and b/textures/building/area/p4.png differ
index c6d2fa8aab616eda0b6f1e8cedca5f45a1e51f8b..4ba02e2539a6927c0abe618ca597a53edc57cc44 100644 (file)
Binary files a/textures/building/area/p5.png and b/textures/building/area/p5.png differ
index 942bc9ef55d64baa5929d252ef26fea9b6bbd730..f77539f48772c4a881f6bc9531b6386dc5ca0a93 100644 (file)
Binary files a/textures/building/area/p6.png and b/textures/building/area/p6.png differ
index f79a29e5ac402651e4dc23e23181bc9a4766025a..509203ab07f26bad796dad58999a898ff51b33ed 100644 (file)
Binary files a/textures/building/area/p7.png and b/textures/building/area/p7.png differ
index 4e21e300140730f85cf9545d6300b46d0707eb70..718d6ea826554dc8f978c583a20e78df771764db 100644 (file)
Binary files a/textures/building/area/p8.png and b/textures/building/area/p8.png differ
index a8680da488dd1592cc9ba6fe0606c89ea606c1ef..eb5764edbe4220575ae0f56b7ce23311edfe8551 100644 (file)
Binary files a/textures/building/area/p9.png and b/textures/building/area/p9.png differ