Add implementation note about calculation of region and size for tiles#250
Add implementation note about calculation of region and size for tiles#250jpstroop merged 1 commit intoIIIF:masterfrom
Conversation
|
I'm OK with this being inline. It integer arithmetic OK? I think I've been doing |
|
Hmmm, Math.ceil() is an interesting choice, you always round up -- will have to think about that a little, but at least I know why it didn't always match my static file calculation ;-) The beauty of integer arithmetic is that is not (well, less frequently) implementation dependent. |
|
If I recall correctly, I decided to do https://github.com/openzoom/deepzoom.py/blob/develop/deepzoom.py which makes DZI tiles for OSd. |
|
I've not been able to reason whether rounding up (ceil) or rounding to nearest (as I have) is really best. My gut says nearest but I do see where you got it from in deepzoom... I can, however, replicate/verify the OSD algorithm using integer arithmetic. My conversion of the JavaScript to python is: (For comparison I have calculated an iiifSizeX and iiifSizeY instead of using just iiifSize for And then for the integer version one just changes my previous code in the I've compared the resulting parameters for quite a range of tiles, image sizes etc.. and have 100% agreement. |
|
So the OSd/IIIF algorithm has gone from Python -> Javascript -> Python. 😄. Happy to leave it as is. |
Add implementation note about calculation of region and size for tiles
Implementation note I promised for #225
I don't recall whether we'd thought of doing this in the same document or as a separate one, I have done it inline and I think it is OK.
There are choices to be made in implementation (e.g. what size image do you return for a 11x11 image at scale 2? Is it 5x5 or 6x6? Seems that "tradition" might dictate 6x6 but that is just one possible choice) so this isn't the only way to do the calculation. In order to be clearcut I have an integer-only algorithm expressed as Python code which I've tested quite carefully. One could make this shorter using Python's ternary/one-line "if" but I think that is less clear, especially for non-Python folks:
The other issue is that where is image API is implemented following the SHOULD of truncating if a region goes over the edge, then one doesn't really need to calculate special region parameters. However, the numbers are needed for the size parameter calculation and by calculating region also one has something that should work with all implementations.