layer_border = self.genborder(osm_edge, "landuse", "meadow")\r
layer_comp.alpha_composite(layer_border)\r
\r
+\r
+ # Here we want to make sure that the generated image fits well with others, so\r
+ # let's do that.\r
+ mstr_msg("layergen", "Generating adjacent fades")\r
+ self.generate_adjacent_fades()\r
+\r
+ # Determine if there are any fades, and if so, fade those in first before we save the layer\r
+ fade_fn = mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value\r
+ if os.path.isfile(fade_fn + "_fade_top.png") == True:\r
+ fade = Image.open(fade_fn + "_fade_top.png")\r
+ layer_comp.alpha_composite(fade)\r
+ if os.path.isfile(fade_fn + "_fade_right.png") == True:\r
+ fade = Image.open(fade_fn + "_fade_right.png")\r
+ layer_comp.alpha_composite(fade)\r
+ if os.path.isfile(fade_fn + "_fade_bottom.png") == True:\r
+ fade = Image.open(fade_fn + "_fade_bottom.png")\r
+ layer_comp.alpha_composite(fade)\r
+ if os.path.isfile(fade_fn + "_fade_left.png") == True:\r
+ fade = Image.open(fade_fn + "_fade_left.png")\r
+ layer_comp.alpha_composite(fade)\r
+ mstr_msg("layergen", "Adjacent fading completed")\r
+ \r
+\r
# Store layer\r
if self._is_completion == False:\r
layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )\r
if self._tag == "waterway" and (self._value == "river" or self._value == "stream"):\r
layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=4))\r
\r
+\r
# Store layer\r
layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )\r
mstr_msg("layergen", "Layer image finalized and saved.")\r
nrm = mstr_xp_normalmap(self._latitude, self._longitude, self._tag, self._value, self._lat_number, self._lng_number, self._latlngfld)\r
nrm.build_normalmap()\r
\r
+\r
+ # Should we find more than one source, the first one found will take precedence.\r
+ # For the others, we will need to generate fading images, so that the final layer \r
+ # image works with other tiles\r
+ def generate_adjacent_fades(self):\r
+ adj_sources = self.find_all_adjacent_sources()\r
+ precedence = -1\r
+\r
+ # Be prepared for every border\r
+ brd_t = Image.open(mstr_datafolder + "textures/multi_source/brd_t.png")\r
+ brd_r = Image.open(mstr_datafolder + "textures/multi_source/brd_r.png")\r
+ brd_b = Image.open(mstr_datafolder + "textures/multi_source/brd_b.png")\r
+ brd_l = Image.open(mstr_datafolder + "textures/multi_source/brd_l.png")\r
+\r
+ brd_t_pix = brd_t.load()\r
+ brd_r_pix = brd_r.load()\r
+ brd_b_pix = brd_b.load()\r
+ brd_l_pix = brd_l.load()\r
+\r
+ for s in range(0, 4):\r
+ if adj_sources[s] != -1:\r
+ precedence = adj_sources[s]\r
+ break\r
+\r
+ # Generate required images\r
+ # Basically a shortened version of the main layergen call\r
+ for s in range(0, 4):\r
+ if adj_sources[s] != precedence and adj_sources[s] != -1:\r
+ src = adj_sources[s]\r
+\r
+ adj_image = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+ adj_pix = adj_image.load()\r
+\r
+ # Root folder\r
+ root_folder = mstr_datafolder + "textures/" + self._tag + "/" + self._value\r
+\r
+ # Load in the sources to work with\r
+ ptc = glob.glob(root_folder + "/ptc/b" + str(src) + "_p*.png")\r
+ brd_src = Image.open(root_folder + "/brd/b" + str(src) + ".png")\r
+ ptc_src = []\r
+ for p in ptc:\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
+\r
+ for i in mstr_mask_blur:\r
+ if i[0] == self._tag and i[1] == self._value:\r
+ if self._tag != "place" and (self._value != "sea" or self._value != "ocean"): \r
+ osm_mask = osm_mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
+ break\r
+ mask_pix = osm_mask.load()\r
+ \r
+ # Begin producing a largely random image\r
+ samples = 250 # <- We need this in a moment\r
+ for i in range(samples):\r
+ imgid = 0\r
+ if len(ptc_src) == 1: imgid = 0\r
+ if len(ptc_src) >= 2:\r
+ imgid = randrange(1, len(ptc_src)+1) - 1\r
+ l = 0 - int(ptc_src[imgid].width / 2)\r
+ r = adj_image.width - int(ptc_src[imgid].width / 2)\r
+ t = 0 - int(ptc_src[imgid].height / 2)\r
+ b = adj_image.height - int(ptc_src[imgid].height / 2)\r
+ adj_image.alpha_composite( ptc_src[imgid], ( randrange(l, r), randrange(t, b) ) )\r
+\r
+ adj_image.alpha_composite( brd_src )\r
+\r
+ for y in range(self._imgsize):\r
+ for x in range(self._imgsize):\r
+ if mask_pix[x, y][3] > 0:\r
+ rgb=adj_pix[x,y]\r
+ a=mask_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
+ # we need to adjust the alpha to make this layer fade.\r
+ # Then, we save the image\r
+ if s == 0:\r
+ for y in range(self._imgsize):\r
+ for x in range(self._imgsize):\r
+ fade_a = brd_t_pix[0, y]\r
+ if mask_pix[x, y][3] > 0:\r
+ c = adj_pix[x,y]\r
+ adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
+ else:\r
+ adj_pix[x,y] = (0,0,0,0)\r
+ adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_top.png")\r
+ \r
+ if s == 1:\r
+ for y in range(self._imgsize):\r
+ for x in range(self._imgsize):\r
+ fade_a = brd_r_pix[x, 0]\r
+ if mask_pix[x, y][3] > 0:\r
+ c = adj_pix[x,y]\r
+ adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
+ else:\r
+ adj_pix[x,y] = (0,0,0,0)\r
+ adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_right.png")\r
+ \r
+ if s == 2:\r
+ for y in range(self._imgsize):\r
+ for x in range(self._imgsize):\r
+ fade_a = brd_b_pix[0, y]\r
+ if mask_pix[x, y][3] > 0:\r
+ c = adj_pix[x,y]\r
+ adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
+ else:\r
+ adj_pix[x,y] = (0,0,0,0)\r
+ adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_bottom.png")\r
+\r
+ if s == 3:\r
+ for y in range(self._imgsize):\r
+ for x in range(self._imgsize):\r
+ fade_a = brd_l_pix[x, 0]\r
+ if mask_pix[x, y][3] > 0:\r
+ c = adj_pix[x,y]\r
+ adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
+ else:\r
+ adj_pix[x,y] = (0,0,0,0)\r
+ adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_left.png")\r
+\r
+\r
+ def find_all_adjacent_sources(self):\r
+ # Sources for this tag and value - top, right, bottom, left\r
+ sources = [-1,-1,-1,-1] \r
+\r
+ # Perform query for each neighboring tile\r
+ src_top = self._tileinfo.get_adjacency_for_tag_and_value(self._lat_number+1, self._lng_number, self._tag, self._value)\r
+ src_rgt = self._tileinfo.get_adjacency_for_tag_and_value(self._lat_number, self._lng_number+1, self._tag, self._value)\r
+ src_btm = self._tileinfo.get_adjacency_for_tag_and_value(self._lat_number-1, self._lng_number, self._tag, self._value)\r
+ src_lft = self._tileinfo.get_adjacency_for_tag_and_value(self._lat_number, self._lng_number-1, self._tag, self._value)\r
+\r
+ if len(src_top) == 2:\r
+ if "b" in src_top[1]: sources[0] = src_top[0]\r
+ if len(src_rgt) == 2:\r
+ if "l" in src_rgt[1]: sources[1] = src_rgt[0]\r
+ if len(src_btm) == 2:\r
+ if "t" in src_btm[1]: sources[2] = src_btm[0]\r
+ if len(src_lft) == 2:\r
+ if "r" in src_lft[1]: sources[3] = src_lft[0]\r
+\r
+ # Report our findings\r
+ return sources\r