| 47 | | |
|---|
| 48 | | // /** |
|---|
| 49 | | // * Calculates the scale divisor. This is the number you must divide the |
|---|
| 50 | | // * original image size by to obtain the image size at the given zoom level. |
|---|
| 51 | | // * In other words, a number so that: (original width)/(scale divisor) = |
|---|
| 52 | | // * width at the given zoom level. |
|---|
| 53 | | // * <p> |
|---|
| 54 | | // * Multiply an image size or pixel coordinate with this number to convert to |
|---|
| 55 | | // * get an image size or pixel coordinate at the original zoom level. Divide |
|---|
| 56 | | // * by this number to get the image size or pixel coordinate at the given |
|---|
| 57 | | // * zoom level. |
|---|
| 58 | | // * <p> |
|---|
| 59 | | // * Because each zoom level shows the image at double the width and double |
|---|
| 60 | | // * the height of the previous zoom level, the scale divisor is always a |
|---|
| 61 | | // * power of two, i.e. 0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0 and so on. |
|---|
| 62 | | // * |
|---|
| 63 | | // * @param originalSize the original size of the image |
|---|
| 64 | | // * @param zoom the zoom level that the image is being displayed at |
|---|
| 65 | | // * @return the scale exponent |
|---|
| 66 | | // */ |
|---|
| 67 | | // public static double getScaleDivisor(Pixel originalSize, int zoom) { |
|---|
| 68 | | // float scaledWidth = originalSize.x; |
|---|
| 69 | | // float scaledHeight = originalSize.y; |
|---|
| 70 | | // int scaleExponent = 0; |
|---|
| 71 | | // while (scaledWidth > LEVEL_0_MAX_SIZE.x |
|---|
| 72 | | // || scaledHeight > LEVEL_0_MAX_SIZE.y) { |
|---|
| 73 | | // scaledWidth /= 2.0f; |
|---|
| 74 | | // scaledHeight /= 2.0f; |
|---|
| 75 | | // scaleExponent++; |
|---|
| 76 | | // } |
|---|
| 77 | | // |
|---|
| 78 | | // return Math.pow(2, scaleExponent - zoom); |
|---|
| 79 | | // } |
|---|
| 97 | | |
|---|
| 98 | | // /** |
|---|
| 99 | | // * Calculates the level of subsampling that should be applied to the image |
|---|
| 100 | | // * when decoding. This number can be given as a parameter to |
|---|
| 101 | | // * IIOParam.setSourceSubsampling(). |
|---|
| 102 | | // * |
|---|
| 103 | | // * @param originalSize the original size of the image |
|---|
| 104 | | // * @param zoom the zoom level that the image will be displayed at |
|---|
| 105 | | // * @return the scale divisor |
|---|
| 106 | | // */ |
|---|
| 107 | | // public static int getSubsampleLevel(Pixel originalSize, int zoom) { |
|---|
| 108 | | // |
|---|
| 109 | | // double scaleDivisor = getScaleDivisor(originalSize, zoom); |
|---|
| 110 | | // |
|---|
| 111 | | // if (scaleDivisor > 2) |
|---|
| 112 | | // // scaleDivisor is always an integer when >= 1. |
|---|
| 113 | | // return (int) scaleDivisor - 1; |
|---|
| 114 | | // else |
|---|
| 115 | | // return 1; |
|---|
| 116 | | // } |
|---|
| 135 | | |
|---|
| 136 | | // /** |
|---|
| 137 | | // * Converts pixel coordinates at the given zoom level so that they indicate |
|---|
| 138 | | // * the same spot on the image, when the image is being displayed at its |
|---|
| 139 | | // * original size. |
|---|
| 140 | | // * |
|---|
| 141 | | // * @param zoom the zoom level |
|---|
| 142 | | // * @param originalSize the original size of the image |
|---|
| 143 | | // * @return the recomputed coordinates, or null if the parameters are invalid |
|---|
| 144 | | // */ |
|---|
| 145 | | // public Pixel convertFromZoomlevelToOriginalSize(int zoom, Pixel originalSize) { |
|---|
| 146 | | // if (zoom < 0 || originalSize == null) |
|---|
| 147 | | // return null; |
|---|
| 148 | | // double scaleDivisor = getScaleDivisor(originalSize, zoom); |
|---|
| 149 | | // return convertFromZoomlevelToOriginalSize(scaleDivisor); |
|---|
| 150 | | // } |
|---|
| 151 | | // |
|---|
| 152 | | // /** |
|---|
| 153 | | // * Converts pixel coordinates at the given zoom level so that they indicate |
|---|
| 154 | | // * the same spot on the image, when the image is being displayed at its |
|---|
| 155 | | // * original size. |
|---|
| 156 | | // * |
|---|
| 157 | | // * @param scaleDivisor the scale divisor |
|---|
| 158 | | // * @return the recomputed coordinates |
|---|
| 159 | | // */ |
|---|
| 160 | | // public Pixel convertFromZoomlevelToOriginalSize(double scaleDivisor) { |
|---|
| 161 | | // return new Pixel((int) Math.round(x * scaleDivisor), (int) Math.round(y |
|---|
| 162 | | // * scaleDivisor)); |
|---|
| 163 | | // } |
|---|
| 164 | | |
|---|
| 165 | | // /** |
|---|
| 166 | | // * Converts pixel coordinates relative to the original image size so that |
|---|
| 167 | | // * they indicate the same spot on the image, when the image is being |
|---|
| 168 | | // * displayed at the given zoom level. |
|---|
| 169 | | // * |
|---|
| 170 | | // * @param zoom the zoom level |
|---|
| 171 | | // * @param originalSize the original size of the image |
|---|
| 172 | | // * @return the recomputed coordinates, or null if the parameters are invalid |
|---|
| 173 | | // */ |
|---|
| 174 | | // public Pixel convertFromOriginalSizeToZoomlevel(int zoom, Pixel originalSize) { |
|---|
| 175 | | // if (zoom < 0 || originalSize == null) |
|---|
| 176 | | // return null; |
|---|
| 177 | | // double scaleDivisor = getScaleDivisor(originalSize, zoom); |
|---|
| 178 | | // return convertFromOriginalSizeToZoomlevel(scaleDivisor); |
|---|
| 179 | | // } |
|---|
| 180 | | // |
|---|
| 181 | | // /** |
|---|
| 182 | | // * Converts pixel coordinates relative to the original image size so that |
|---|
| 183 | | // * they indicate the same spot on the image, when the image is being |
|---|
| 184 | | // * displayed at the given zoom level. |
|---|
| 185 | | // * |
|---|
| 186 | | // * @param scaleDivisor the scale divisor |
|---|
| 187 | | // * @return the recomputed coordinates |
|---|
| 188 | | // */ |
|---|
| 189 | | // public Pixel convertFromOriginalSizeToZoomlevel(double scaleDivisor) { |
|---|
| 190 | | // return new Pixel((int) Math.round(x / scaleDivisor), (int) Math.round(y |
|---|
| 191 | | // / scaleDivisor)); |
|---|
| 192 | | // } |
|---|