comparison base/ZoomConstraint.h @ 1324:d4a28d1479a8 zoom

Some hackery toward having a zoomlevel type
author Chris Cannam
date Mon, 12 Dec 2016 15:18:52 +0000
parents 12f3b48668d4
children 710e6250a401
comparison
equal deleted inserted replaced
1323:4dbb7a7c9c28 1324:d4a28d1479a8
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #ifndef _ZOOM_CONSTRAINT_H_ 16 #ifndef SV_ZOOM_CONSTRAINT_H
17 #define _ZOOM_CONSTRAINT_H_ 17 #define SV_ZOOM_CONSTRAINT_H
18 18
19 #include <stdlib.h> 19 #include <stdlib.h>
20
21 #include "BaseTypes.h"
20 22
21 /** 23 /**
22 * ZoomConstraint is a simple interface that describes a limitation on 24 * ZoomConstraint is a simple interface that describes a limitation on
23 * the available zoom sizes for a view, for example based on cache 25 * the available zoom sizes for a view, for example based on cache
24 * strategy or a (processing) window-size limitation. 26 * strategy or a (processing) window-size limitation.
37 RoundUp, 39 RoundUp,
38 RoundNearest 40 RoundNearest
39 }; 41 };
40 42
41 /** 43 /**
42 * Given the "ideal" block size (frames per pixel) for a given 44 * Given an "ideal" zoom level (frames per pixel or pixels per
43 * zoom level, return the nearest viable block size for this 45 * frame) for a given zoom level, return the nearest viable block
44 * constraint. 46 * size for this constraint.
45 * 47 *
46 * For example, if a block size of 1523 frames per pixel is 48 * For example, if a block size of 1523 frames per pixel is
47 * requested but the underlying model only supports value 49 * requested but the underlying model only supports value
48 * summaries at powers-of-two block sizes, return 1024 or 2048 50 * summaries at powers-of-two block sizes, return 1024 or 2048
49 * depending on the rounding direction supplied. 51 * depending on the rounding direction supplied.
50 */ 52 */
51 virtual int getNearestBlockSize(int requestedBlockSize, 53 virtual ZoomLevel getNearestZoomLevel(ZoomLevel requestedZoomLevel,
52 RoundingDirection = RoundNearest) 54 RoundingDirection = RoundNearest)
53 const 55 const
54 { 56 {
55 if (requestedBlockSize > getMaxZoomLevel()) return getMaxZoomLevel(); 57 if (getMaxZoomLevel() < requestedZoomLevel) return getMaxZoomLevel();
56 else return requestedBlockSize; 58 else return requestedZoomLevel;
57 } 59 }
58 60
61 /**
62 * Return the minimum zoom level within range for this constraint.
63 * Individual views will probably want to limit this, for example
64 * in order to ensure that at least one or two samples fit in the
65 * current window size, or in order to save on interpolation cost.
66 */
67 virtual ZoomLevel getMinZoomLevel() const {
68 return { ZoomLevel::PixelsPerFrame, 16384 };
69 }
70
59 /** 71 /**
60 * Return the maximum zoom level within range for this constraint. 72 * Return the maximum zoom level within range for this constraint.
61 * This is quite large -- individual views will probably want to 73 * This is quite large -- individual views will probably want to
62 * limit how far a user might reasonably zoom out based on other 74 * limit how far a user might reasonably zoom out based on other
63 * factors such as the duration of the file. 75 * factors such as the duration of the file.
64 */ 76 */
65 virtual int getMaxZoomLevel() const { return 4194304; } // 2^22, arbitrarily 77 virtual ZoomLevel getMaxZoomLevel() const {
78 return { ZoomLevel::FramesPerPixel, 4194304 }; // 2^22, arbitrarily
79 }
66 }; 80 };
67 81
68 #endif 82 #endif
69 83