File: ImageSizeLimits.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (38 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package tim.prune.save;

import tim.prune.data.Track;
import tim.prune.data.TrackExtents;

/**
 * Extract image size logic into single place
 */
public abstract class ImageSizeLimits
{
	private static final int MIN_PIXELS_ALLOWED = 100;
	private static final int MAX_PIXELS_ALLOWED = 8000;


	/**
	 * @param inTrack track object
	 * @param inZoom selected zoom level
	 * @return true if the image size is acceptable
	 */
	public static boolean isZoomLevelOk(Track inTrack, int inZoom)
	{
		final int pixelCount = getPixelCount(inTrack, inZoom);
		return pixelCount > MIN_PIXELS_ALLOWED
				&& pixelCount < MAX_PIXELS_ALLOWED;
	}

	/** @return the pixel width / height of the resulting image including border */
	private static int getPixelCount(Track inTrack, int inZoom)
	{
		// Get the extents of the track including a standard (10%) border around the data
		TrackExtents extents = new TrackExtents(inTrack);
		extents.applySquareBorder();

		// Work out how big the final image will be
		final int zoomFactor = 1 << inZoom;
		return (int) (extents.getXRange().getRange() * zoomFactor * 256);
	}
}