Skip to content

Commit e1437fd

Browse files
committed
Merge pull request #253 from zimeon/implementation_notes_2
Adjust region/size calculation to use ceil rounding, add algoritm for rotation size calculation
2 parents 5c5aecd + f5b6745 commit e1437fd

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

source/api/image/2.0/index.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ Early sanity checking of URIs (lengths, trailing GET, invalid characters, out-of
645645
* This specification makes no assertion about the rights status of requested images or any other descriptive metadata, whether or not authentication has been accomplished. Please see the [IIIF Presentation API][prezi-api] for rights and other information.
646646
* This API does not specify how image servers fulfill requests, what quality the returned images will have for different parameters, or how parameters may affect performance.
647647
* Image identifiers that include the slash (/ %2F) or backslash (\ %5C) characters may cause problems with some HTTP servers. Apache servers from version 2.2.18 support the `AllowEncodedSlashes NoDecode` [configuration directive][apache-aesnd] which will correctly pass these characters to client applications without rejecting or decoding them. Servers using older versions of Apache and local identifiers which include these characters will need to use a workaround such as internally translating or escaping slash and backslash to safe value (perhaps by double URI-encoding them).
648-
* When requesting image tiles, the [Region][region] and [Size][size] parameters must be calculated to take account of partial tiles along the right and lower edges for a full imagine that is not an exact multiple of the scaled tile size. The algorithm below is shown as Python code and assumes integer inputs and integer arithmetic throughout (ie. remainder discarded on division). Inputs are: size of full image content `(width,height)`, scale factor `s`, tile size `(tw,th)`, and tile coordinate `(n,m)` counting from `(0,0)` in the upper-left corner.
648+
* When requesting image tiles, the [Region][region] and [Size][size] parameters must be calculated to take account of partial tiles along the right and lower edges for a full imagine that is not an exact multiple of the scaled tile size. The algorithm below is shown as Python code and assumes integer inputs and integer arithmetic throughout (ie. remainder discarded on division). Inputs are: size of full image content `(width,height)`, scale factor `s`, tile size `(tw,th)`, and tile coordinate `(n,m)` counting from `(0,0)` in the upper-left corner. Note that the rounding method is implementation dependent.
649649

650-
```python
650+
{% highlight python %}
651651
# Calculate region parameters /xr,yr,wr,hr/
652652
xr = n * tw * s
653653
yr = m * th * s
@@ -658,17 +658,23 @@ Early sanity checking of URIs (lengths, trailing GET, invalid characters, out-of
658658
if (yr + hr > height):
659659
hr = height - yr
660660
# Calculate size parameters /ws,hs/
661-
s2 = s/2 # use to implement rounding with integer arithmetic
662661
ws = tw
663662
if (xr + tw*s > width):
664-
ws = (width - xr + s2) / s
663+
ws = (width - xr + s - 1) / s # +s-1 in numerator to round up
665664
hs = th
666665
if (yr + th*s > height):
667-
hs = (height - yr + s2) / s
668-
```
666+
hs = (height - yr + s - 1) / s
667+
{% endhighlight %}
669668
{: .urltemplate}
670669

671-
* As described in [Rotation][rotation], in order to retain the size of the requested image contents, rotation will change the width and height dimensions of the returned image file. A formula for calculating the dimensions of the returned image file for a given rotation can be found here.
670+
* As described in [Rotation][rotation], in order to retain the size of the requested image contents, rotation will change the width and height dimensions of the image returned. A formula for calculating the dimensions of the image returned for a given starting size and rotation is given below. Note that the rounding method is implementation dependent and that some languages require conversion of the angle from degrees to radians.
671+
672+
{% highlight python %}
673+
# (w,h) are size parameters, n is rotation angle
674+
w_returned = abs(w*cos(n)) + abs(h*sin(n))
675+
h_returned = abs(h*cos(n)) + abs(w*sin(n))
676+
{% endhighlight %}
677+
{: .urltemplate}
672678

673679
### B. Versioning
674680

0 commit comments

Comments
 (0)