("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
("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
("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
]\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
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
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
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
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
\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
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
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
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
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
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
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
\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