You are here: Appendix A - Technical Notes > Zoom Levels

Zoom Levels

The following describes the MrSID SDK’s handling of zoom levels for MG2, MG3, MG4 and JP2. In the code below, assume the following:

W = image width (constant)

H = image height (constant)

n = number of levels

MG2 Behavior

The default number of zoom levels is computed by initially assuming the maximum possible number of levels. The size of the image that would be needed to support that number of levels is then computed. If the actual image is larger than the computed size, the number is determined and the SDK inquires no further. Otherwise, the SDK recomputes the image size with a reduced number of levels, and continues to do so until the actual image size is equal to or greater than the required size.

n = 9

loop

{

min_length = (IPOW(2, n+1) - 2) * 4 + 1

if (W > min_length) and (H > min_length) break;

--n

}

The min_length values for n=9, 8, …, 3 are 4089, 2041, …, 57.

The maximum number of levels for the image is computed the same way.

These zoom level calculations are in the MG2WriterParams class. However, if you request less than 3 levels (or more than 9), the SDK will clamp your request to 3 (or 9). These are hard limits for MG2.

MG3 and MG4 Behavior

MG3 and MG4 use different equations than MG2 and do not have the hard limits of 3 and 9 levels.

The default number of zoom levels is determined by initially assuming zero levels, then reducing the minimum image dimension by a factor of two until it falls below 32.

n = 0

minWH = MIN(W,H)

while (minWH >= 32)

{

minWH = minWH / 2

++n

}

The maximum number of zoom levels is computed by a different method: the number of levels is increased as long as the dimension at that number of levels is not greater than the minimum actual image dimension.

n = 1

minWH = MIN(W,H)

while (minWH > (1 << (n+1) )

{

++n

}

--n

These zoom level calculations are in the MG3WriterParams and MG4WriterParams classes.

JP2 Behavior

JP2 behaves identically to MG3 and MG4. These zoom level calculations are in the JP2WriterParams class.

Example

Consider a 512x512 image. Using the SDK encoder and info tools, the following results are obtained:

mg2: image is encoded to 6 levels

0: 512x512

1: 256x256

..

5: 16x16

6: 8x8

mg3: image is encoded to 5 levels

0: 512x512

1: 256x256

..

5: 16x16

jp2: image is encoded to 5 levels

0: 512x512

1: 256x256

..

5: 16x16