Removed O4XP-like mask generation, fixed inland water cutting instead by passing water layers for cutting to photogen

This commit is contained in:
Marcus Str. 2024-11-29 20:54:18 +01:00
parent 642b42de1e
commit 43d00df062
4 changed files with 41 additions and 30 deletions

View File

@ -457,6 +457,7 @@ class mstr_layergen:
# Create a water mask we need to remove from the DDS later
"""
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"):
mstr_msg("layergen", "Generating inland water mask")
water_file = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._lat_number) + "_" + str(self._lng_number) + "_water.png"
@ -464,7 +465,7 @@ class mstr_layergen:
if os.path.isfile(water_file):
inl_mask = Image.open(water_file)
else:
inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (255,255,255,255))
inl_mask = Image.new("L", (self._imgsize, self._imgsize), (255))
lyr_pix = layer_comp.load()
inl_pix = inl_mask.load()
for y in range(self._imgsize):
@ -472,7 +473,7 @@ class mstr_layergen:
l = lyr_pix[x,y]
if l[3] > 50:
clr = 255-l[3]
c = (clr,clr,clr,255)
c = (clr)
inl_pix[x,y] = c
inl_mask.save(water_file)
#if l[3] > 65:
@ -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")
#layer_comp = inl_mask
mstr_msg("layergen", "Inland water mask generated and saved")
"""
# Return the completed image
return layer_comp

View File

@ -234,11 +234,13 @@ class mstr_orthographic:
# In here we store the layers
photolayers = []
waterlayers = []
# The masks are handed to layergen in sequence. The layers are then
# in turn handed to photogen.
curlyr = 1
wtr_info = False
for layer in layers:
# Let the user know
mstr_msg("orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))
@ -256,7 +258,15 @@ class mstr_orthographic:
lg.set_latlng_folder(self._latlngfld)
#lg.open_db()
lg.open_tile_info()
photolayers.append(lg.genlayer(mask, osmxml))
lyr = lg.genlayer(mask, osmxml)
photolayers.append(lyr)
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"):
waterlayers.append(lyr)
if wtr_info == False:
wtr_info = True
wtrfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/wtrfile"
with open(wtrfile, 'a') as textfile:
textfile.write(str(grid_lat) + " " + str(grid_lng) + "\r\n")
curlyr = curlyr+1
mstr_msg("orthographic", "All layers created")
@ -264,7 +274,7 @@ class mstr_orthographic:
# Snap a photo with our satellite :)
mstr_msg("orthographic", "Generating ortho photo")
pg = mstr_photogen(self._lat, self._long, grid_lat, grid_lng, maxlatlng[0], maxlatlng[1])
pg.genphoto(photolayers)
pg.genphoto(photolayers, waterlayers)
mstr_msg("orthographic", " -- Ortho photo generated -- ")
print("")
print("")

View File

@ -39,7 +39,7 @@ class mstr_photogen:
# This puts it all together. Bonus: AND saves it.
def genphoto(self, layers):
def genphoto(self, layers, waterlayers):
# Template for the file name which is always the same
#root_filename = mstr_datafolder + "/_cache/" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_"
@ -138,26 +138,6 @@ class mstr_photogen:
t = (0,0,0,0)
ocean_pix[x,y] = t
# Now cut out inland water
water_layers = (
["natural", "water"],
["water", "lake"],
["water", "pond"],
["water", "river"],
["leisure", "swimming_pool"]
)
for l in water_layers:
fn = mstr_datafolder + "_cache/" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_" + l[0] + "-" + l[1] + "_layer_mask.png"
if os.path.isfile(fn) == True:
wtr = Image.open(fn)
wtr_pix = wtr.load()
tilepix = self._tile.load()
for y in range(wtr.height):
for x in range(wtr.width):
wp = wtr_pix[x,y]
if wp[0] == 255 and wp[1] == 0 and wp[2] == 255 and wp[3] == 255:
tilepix[x,y] = (0,0,0,0)
# Alpha correction on final image
corrpix = self._tile.load()
for y in range(0, self._tile.height):
@ -169,6 +149,29 @@ class mstr_photogen:
if c[3] == 0:
corrpix[x,y] = (0,0,0,0)
# Now cut out inland water
for w in waterlayers:
wtr_pix = w.load()
for y in range(w.height):
for x in range(w.width):
v = wtr_pix[x,y]
if v[3] >= 50:
c = (0,0,0,0)
corrpix[x,y] = c
"""
ddsf_water = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._ty) + "_" + str(self._tx) + "_water.png"
if os.path.isfile(ddsf_water) == True:
wtr = Image.open(ddsf_water)
wtr_pix = wtr.load()
for y in range(wtr.height):
for x in range(wtr.width):
v = wtr_pix[x,y]
if v <= 50:
c = (0,0,0,0)
corrpix[x,y] = c
"""
# We are now in posession of the final image.
# Contrast

View 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: