Commit a320665c authored by Baptiste Jonglez's avatar Baptiste Jonglez

WIP: repeat tiles horizontally when the panorama wraps

Not the best idea actually...
parent b8b61063
......@@ -17,6 +17,7 @@ import os
import tempfile
import PIL.Image
from PIL import ImageDraw
def gen_tiles(image, output_path, min_scale=0, max_scale=8, crop_x=256, crop_y=256):
......@@ -24,21 +25,34 @@ def gen_tiles(image, output_path, min_scale=0, max_scale=8, crop_x=256, crop_y=2
for scale in range(min_scale, max_scale + 1):
if scale == 0:
im = orig_im
scaled_size = im.size
else:
scaled_size = (orig_im.size[0] >> scale, orig_im.size[1] >> scale)
im = orig_im.resize(scaled_size, resample=PIL.Image.BILINEAR)
# Compute a size that is a multiple of the tile size
rounded_size = (crop_x + crop_x * ((im.size[0] - 1) // crop_x),
crop_y + crop_y * ((im.size[1] - 1) // crop_y))
if rounded_size != scaled_size:
im = im.transform(rounded_size, PIL.Image.AFFINE, (1, 0, 0, 0, 1, 0))
if False and rounded_size[0] != scaled_size[0]: # TODO: check if 360 or not
# Repeat the same image horizontally
print((scale, 0, 0, rounded_size[0] - scaled_size[0], scaled_size[1]))
print((scale, scaled_size[0], 0, rounded_size[0], scaled_size[1]))
cropped = im.crop((0, 0, rounded_size[0] - scaled_size[0], scaled_size[1]))
im.paste(cropped, (scaled_size[0], 0, rounded_size[0], scaled_size[1]))
for x in range(0, im.size[0], crop_x):
for y in range(0, im.size[1], crop_y):
geom = (x, y, min(im.size[0], x + crop_x),
min(im.size[1], y + crop_y))
geom = (x, y, min(im.size[0], x + crop_x), min(im.size[1], y + crop_y))
dest = os.path.join(output_path,
"{}-{}-{}.jpg".format(-scale,
x // crop_x,
y // crop_y))
tile = im.crop(geom)
if x + crop_x > im.size[0] or y + crop_y > im.size[1]:
# The tile is smaller than 256x256, so fill the rest with black
tile = im.transform((crop_x, crop_y), PIL.Image.AFFINE, (1, 0, x, 0, 1, y))
#draw = ImageDraw.Draw(tile)
#draw.line((0, 0, 0, 255), width=2, fill="red")
#draw.line((0, 255, 255, 255), width=2, fill="red")
#draw.line((255, 255, 255, 0), width=2, fill="red")
#draw.line((255, 0, 0, 0), width=2, fill="red")
tile.save(dest)
......
......@@ -222,6 +222,7 @@ class Panorama(ReferencePoint):
return enumerate([{"id": r.pk,
"name": r.name,
"url": get_url(r),
"kind": r.kind,
"cap": self.bearing(r),
"elevation": self.elevation(r),
"elevation_ground": self.elevation(Point(latitude=r.latitude, longitude=r.longitude, ground_altitude=r.ground_altitude, height_above_ground=0)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment