]> marstr Code Repo - orthographic/commitdiff
Removed O4XP-like mask generation, fixed inland water cutting instead by passing...
authorMarcus Str. <marcus@marstr.online>
Fri, 29 Nov 2024 19:54:18 +0000 (20:54 +0100)
committerMarcus Str. <marcus@marstr.online>
Fri, 29 Nov 2024 19:54:18 +0000 (20:54 +0100)
layergen.py
orthographic.py
photogen.py
xp_scenery.py

index b699dfa42abfefffeecd0346e4272e5af34a5989..cb7259556bac07abbdc9427b81fa1afd216cc6e1 100644 (file)
@@ -457,6 +457,7 @@ class mstr_layergen:
 \r
 \r
             # Create a water mask we need to remove from the DDS later\r
+            """\r
             if (self._tag == "natural" and self._value == "water") or (self._tag == "water" and self._value == "lake") or (self._tag == "water" and self._value == "pond") or (self._tag == "water" and self._value == "river") or (self._tag == "leisure" and self._value == "swimming_pool"):\r
                 mstr_msg("layergen", "Generating inland water mask")\r
                 water_file = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._lat_number) + "_" + str(self._lng_number) + "_water.png"\r
@@ -464,7 +465,7 @@ class mstr_layergen:
                 if os.path.isfile(water_file):\r
                     inl_mask = Image.open(water_file)\r
                 else:\r
-                    inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (255,255,255,255))\r
+                    inl_mask = Image.new("L", (self._imgsize, self._imgsize), (255))\r
                 lyr_pix = layer_comp.load()\r
                 inl_pix = inl_mask.load()\r
                 for y in range(self._imgsize):\r
@@ -472,7 +473,7 @@ class mstr_layergen:
                         l = lyr_pix[x,y]\r
                         if l[3] > 50:\r
                             clr = 255-l[3]\r
-                            c = (clr,clr,clr,255)\r
+                            c = (clr)\r
                             inl_pix[x,y] = c\r
                 inl_mask.save(water_file)\r
                         #if l[3] > 65:\r
@@ -481,6 +482,7 @@ class mstr_layergen:
                 #inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png")\r
                 #layer_comp = inl_mask\r
                 mstr_msg("layergen", "Inland water mask generated and saved")\r
+            """\r
 \r
             # Return the completed image\r
             return layer_comp\r
index 4be989ab1a21fe237510a98aa40ab6b58751627c..b9fdd84402d598ad31bf9df2c3552f430fd3bd92 100644 (file)
@@ -234,11 +234,13 @@ class mstr_orthographic:
 \r
                 # In here we store the layers\r
                 photolayers = []\r
+                waterlayers = []\r
 \r
                 # The masks are handed to layergen in sequence. The layers are then\r
                 # in turn handed to photogen.\r
 \r
                 curlyr = 1\r
+                wtr_info = False\r
                 for layer in layers:\r
                     # Let the user know\r
                     mstr_msg("orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))\r
@@ -256,7 +258,15 @@ class mstr_orthographic:
                     lg.set_latlng_folder(self._latlngfld)\r
                     #lg.open_db()\r
                     lg.open_tile_info()\r
-                    photolayers.append(lg.genlayer(mask, osmxml))\r
+                    lyr = lg.genlayer(mask, osmxml)\r
+                    photolayers.append(lyr)\r
+                    if (layer[0] == "natural" and layer[1] == "water") or (layer[0] == "water" and layer[1] == "lake") or (layer[0] == "water" and layer[1] == "pond") or (layer[0] == "water" and layer[1] == "river") or (layer[0] == "waterway" and layer[1] == "river"):\r
+                        waterlayers.append(lyr)\r
+                        if wtr_info == False:\r
+                            wtr_info = True\r
+                            wtrfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/wtrfile"\r
+                            with open(wtrfile, 'a') as textfile:\r
+                                textfile.write(str(grid_lat) + " " + str(grid_lng) + "\r\n")\r
                     curlyr = curlyr+1\r
                 mstr_msg("orthographic", "All layers created")\r
 \r
@@ -264,7 +274,7 @@ class mstr_orthographic:
                 # Snap a photo with our satellite :)\r
                 mstr_msg("orthographic", "Generating ortho photo")\r
                 pg = mstr_photogen(self._lat, self._long, grid_lat, grid_lng,  maxlatlng[0], maxlatlng[1])\r
-                pg.genphoto(photolayers)\r
+                pg.genphoto(photolayers, waterlayers)\r
                 mstr_msg("orthographic", " -- Ortho photo generated -- ")\r
                 print("")\r
                 print("")\r
index 9099f6183964705f5ce1419936f6e0c0de7e21f6..54b016bb5cc5f52d511a5347152a6604882a7d0d 100644 (file)
@@ -39,7 +39,7 @@ class mstr_photogen:
 \r
     \r
     # This puts it all together. Bonus: AND saves it.\r
-    def genphoto(self, layers):\r
+    def genphoto(self, layers, waterlayers):\r
         # Template for the file name which is always the same\r
         #root_filename = mstr_datafolder + "/_cache/" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_"\r
 \r
@@ -138,26 +138,6 @@ class mstr_photogen:
                     t = (0,0,0,0)\r
                     ocean_pix[x,y] = t\r
 \r
-        # Now cut out inland water\r
-        water_layers = (\r
-            ["natural", "water"],\r
-            ["water", "lake"],\r
-            ["water", "pond"],\r
-            ["water", "river"],\r
-            ["leisure", "swimming_pool"]\r
-        )\r
-        for l in water_layers:\r
-            fn = mstr_datafolder + "_cache/" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_" + l[0] + "-" + l[1] + "_layer_mask.png"\r
-            if os.path.isfile(fn) == True:\r
-                wtr = Image.open(fn)\r
-                wtr_pix = wtr.load()\r
-                tilepix = self._tile.load()\r
-                for y in range(wtr.height):\r
-                    for x in range(wtr.width):\r
-                        wp = wtr_pix[x,y]\r
-                        if wp[0] == 255 and wp[1] == 0 and wp[2] == 255 and wp[3] == 255:\r
-                            tilepix[x,y] = (0,0,0,0)\r
-\r
         # Alpha correction on final image\r
         corrpix = self._tile.load()\r
         for y in range(0, self._tile.height):\r
@@ -168,6 +148,29 @@ class mstr_photogen:
                     corrpix[x,y] = nc\r
                 if c[3] == 0:\r
                     corrpix[x,y] = (0,0,0,0)\r
+\r
+        # Now cut out inland water\r
+        for w in waterlayers:\r
+            wtr_pix = w.load()\r
+            for y in range(w.height):\r
+                for x in range(w.width):\r
+                    v = wtr_pix[x,y]\r
+                    if v[3] >= 50:\r
+                        c = (0,0,0,0)\r
+                        corrpix[x,y] = c\r
+\r
+        """\r
+        ddsf_water = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._ty) + "_" + str(self._tx) + "_water.png"\r
+        if os.path.isfile(ddsf_water) == True:\r
+            wtr = Image.open(ddsf_water)\r
+            wtr_pix = wtr.load()\r
+            for y in range(wtr.height):\r
+                for x in range(wtr.width):\r
+                    v = wtr_pix[x,y]\r
+                    if v <= 50:\r
+                        c = (0,0,0,0)\r
+                        corrpix[x,y] = c\r
+        """\r
         \r
         # We are now in posession of the final image.\r
         \r
index b87cc754e3429cfbb051ee05b6e460b83b0fd584..ca07034f711b0da7d22ede567fd14d319545ccf8 100644 (file)
@@ -154,21 +154,17 @@ class mstr_xp_scenery:
                 cnt_x = cur_lat + (self._vstep/2)
                 cnt_y = cur_lng + (mstr_zl_18/2)
 
-                ddsf_water = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + "_water.png"
-
                 terstr = ""
                 terstr = terstr + "A\r\n"
                 terstr = terstr + "800\r\n"
                 terstr = terstr + "TERRAIN\r\n"
                 terstr = terstr + "\r\n"
                 terstr = terstr + "LOAD_CENTER " + str(cnt_x) + " " + str(cnt_y) + " " + str(dmt) + " 2048\r\n"
+                #terstr = terstr + "BASE_TEX_NOWRAP ../../orthos/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".dds\r\n"
                 terstr = terstr + "TEXTURE_NOWRAP ../../orthos/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".dds\r\n"
                 if mstr_xp_scn_normalmaps == True:
                     terstr = terstr + "NORMAL_TEX 1.0 ../../normals/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".png\r\n"
 
-                if os.path.isfile(ddsf_water) == True:
-                    terstr = terstr + "BORDER_TEX ../../orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + "_water.png\r\n"
-
                 terfln = mstr_datafolder + "z_orthographic/terrain/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".ter"
 
                 with open(terfln, 'w') as textfile: