lovasoa / dezoomify-rs

Zoomable image downloader for Google Arts & Culture, Zoomify, IIIF, and others
https://dezoomify-rs.ophir.dev
GNU General Public License v3.0
739 stars 66 forks source link

Fill in missing tiles with lower-res tiles #37

Open quentinmit opened 4 years ago

quentinmit commented 4 years ago

Sometimes there is something wrong upstream and one or more tiles are missing:

ERROR Only 125 tiles out of 126 could be downloaded. The resulting image was still created as dezoomified.jpg.

It would be really nice if dezoomify-rs could fill in the missing tile with an upscaled version of the next lower zoom, instead of the current black square.

lovasoa commented 4 years ago

This would indeed be very cool! Would you be interested in implementing that and making a pull request? I can provide help and guidance.

quentinmit commented 4 years ago

I don't know Rust at all so it might be quite difficult. It looks like I would need to change find_zoomlevel to find_zoomlevels and return a list of all zoom levels less than or equal to the desired zoom level, and then after a fetch of one zoom level finishes with one or more missing tiles, start over again with a new canvas at the next-smaller zoom level (optimally only downloading tiles that overlap with the missing tiles), then imageops::resize that up to the larger size, and then imageops::overlay the two canvases together. (And potentially, repeat this for the next-larger zoom level until all the gaps are filled.)

I think it's probably important to draw the next zoom level to a canvas instead of just trying to resize and clip a single tile, because resizing the tiles separately could produce artifacts at tile edges.

lovasoa commented 4 years ago

Yes, all of these steps make sense.

Ideally we would break up the huge dezoomify function that currently drives the whole dezoomifying process. We could have a function that accepts a zoom level, a canvas, and the coordinates of the rectangle to fill, and call it repetitively : initially with a rectangle covering the whole image, then with the same canvas and only the missing rectangles, until we have no missing rectangles or no more zoom levels. This represents a consequent amount of work, but would also make it very easy to then implement seemingly unrelated features such as downloading only a small region of an image.