diff options
author | Molly Lloyd <mollymerp@users.noreply.github.com> | 2018-06-21 14:37:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-21 14:37:17 -0700 |
commit | e1af62e87dfd77d1c38802f082c4981dab1beeab (patch) | |
tree | 8371dccdcf8545fd50b2edddbdd3a622bb00b27a /platform/darwin | |
parent | eb70b8984901d8113f3a29d26cc355d5b3ed46fd (diff) | |
download | qtlocation-mapboxgl-e1af62e87dfd77d1c38802f082c4981dab1beeab.tar.gz |
[core] add raster-resampling property (#12176)upstream/rclee
* update style-code for raster-resampling
* implement user-defined raster-resampling
* invert filter condition
* raster-resampling -> raster-resampling-mode for darwin language conventions
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/scripts/style-spec-cocoa-conventions-v8.json | 3 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterStyleLayer.h | 78 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterStyleLayer.mm | 47 | ||||
-rw-r--r-- | platform/darwin/test/MGLRasterStyleLayerTests.mm | 49 |
4 files changed, 176 insertions, 1 deletions
diff --git a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json index 830b6d69f9..dfc7d76a3c 100644 --- a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json +++ b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json @@ -37,7 +37,8 @@ "paint_raster": { "raster-brightness-min": "minimum-raster-brightness", "raster-brightness-max": "maximum-raster-brightness", - "raster-hue-rotate": "raster-hue-rotation" + "raster-hue-rotate": "raster-hue-rotation", + "raster-resampling": "raster-resampling-mode" }, "paint_line": { "line-dasharray": "line-dash-pattern", diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h index ff055d24f6..a74d4f7f26 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.h +++ b/platform/darwin/src/MGLRasterStyleLayer.h @@ -7,6 +7,27 @@ NS_ASSUME_NONNULL_BEGIN /** + The resampling/interpolation method to use for overscaling, also known as + texture magnification filter + + Values of this type are used in the `MGLRasterStyleLayer.rasterResamplingMode` + property. + */ +typedef NS_ENUM(NSUInteger, MGLRasterResamplingMode) { + /** + (Bi)linear filtering interpolates point values using the weighted average + of the four closest original source points creating a smooth but blurry + look when overscaled + */ + MGLRasterResamplingModeLinear, + /** + Nearest neighbor filtering interpolates point values using the nearest + original source point creating a sharp but pointated look when overscaled + */ + MGLRasterResamplingModeNearest, +}; + +/** An `MGLRasterStyleLayer` is a style layer that renders georeferenced raster imagery on the map, especially raster tiles. @@ -233,6 +254,40 @@ MGL_EXPORT @property (nonatomic) MGLTransition rasterOpacityTransition; /** + The resampling/interpolation method to use for overscaling, also known as + texture magnification filter + + The default value of this property is an expression that evaluates to `linear`. + Set this property to `nil` to reset it to the default value. + + This attribute corresponds to the <a + href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-resampling"><code>raster-resampling</code></a> + layout property in the Mapbox Style Specification. + + You can set this property to an expression containing any of the following: + + * Constant `MGLRasterResamplingMode` values + * Any of the following constant string values: + * `linear`: (Bi)linear filtering interpolates pixel values using the weighted + average of the four closest original source pixels creating a smooth but blurry + look when overscaled + * `nearest`: Nearest neighbor filtering interpolates pixel values using the + nearest original source pixel creating a sharp but pixelated look when + overscaled + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. + */ +@property (nonatomic, null_resettable) NSExpression *rasterResamplingMode; + +@property (nonatomic, null_resettable) NSExpression *rasterResampling __attribute__((unavailable("Use rasterResamplingMode instead."))); + +/** Increase or reduce the saturation of the image. The default value of this property is an expression that evaluates to the float @@ -260,4 +315,27 @@ MGL_EXPORT @end +/** + Methods for wrapping an enumeration value for a style layer attribute in an + `MGLRasterStyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGLRasterStyleLayerAdditions) + +#pragma mark Working with Raster Style Layer Attribute Values + +/** + Creates a new value object containing the given `MGLRasterResamplingMode` enumeration. + + @param rasterResamplingMode The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLRasterResamplingMode:(MGLRasterResamplingMode)rasterResamplingMode; + +/** + The `MGLRasterResamplingMode` enumeration representation of the value. + */ +@property (readonly) MGLRasterResamplingMode MGLRasterResamplingModeValue; + +@end + NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 0e31512491..96ed5ab513 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -11,6 +11,15 @@ #include <mbgl/style/transition_options.hpp> #include <mbgl/style/layers/raster_layer.hpp> +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLRasterResamplingMode, { + { MGLRasterResamplingModeLinear, "linear" }, + { MGLRasterResamplingModeNearest, "nearest" }, + }); + +} + @interface MGLRasterStyleLayer () @property (nonatomic, readonly) mbgl::style::RasterLayer *rawLayer; @@ -252,6 +261,30 @@ return transition; } +- (void)setRasterResamplingMode:(NSExpression *)rasterResamplingMode { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::style::RasterResamplingType, NSValue *, mbgl::style::RasterResamplingType, MGLRasterResamplingMode>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::RasterResamplingType>>(rasterResamplingMode); + self.rawLayer->setRasterResampling(mbglValue); +} + +- (NSExpression *)rasterResamplingMode { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getRasterResampling(); + if (propertyValue.isUndefined()) { + propertyValue = self.rawLayer->getDefaultRasterResampling(); + } + return MGLStyleValueTransformer<mbgl::style::RasterResamplingType, NSValue *, mbgl::style::RasterResamplingType, MGLRasterResamplingMode>().toExpression(propertyValue); +} + +- (void)setRasterResampling:(NSExpression *)rasterResampling { +} + +- (NSExpression *)rasterResampling { + return self.rasterResamplingMode; +} + - (void)setRasterSaturation:(NSExpression *)rasterSaturation { MGLAssertStyleLayerIsValid(); @@ -288,3 +321,17 @@ } @end + +@implementation NSValue (MGLRasterStyleLayerAdditions) + ++ (NSValue *)valueWithMGLRasterResamplingMode:(MGLRasterResamplingMode)rasterResamplingMode { + return [NSValue value:&rasterResamplingMode withObjCType:@encode(MGLRasterResamplingMode)]; +} + +- (MGLRasterResamplingMode)MGLRasterResamplingModeValue { + MGLRasterResamplingMode rasterResamplingMode; + [self getValue:&rasterResamplingMode]; + return rasterResamplingMode; +} + +@end diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.mm b/platform/darwin/test/MGLRasterStyleLayerTests.mm index cf5175812e..cc5c1b6984 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.mm +++ b/platform/darwin/test/MGLRasterStyleLayerTests.mm @@ -306,6 +306,49 @@ XCTAssertEqual(rasterOpacityTransition.duration, transitionTest.duration); } + // raster-resampling + { + XCTAssertTrue(rawLayer->getRasterResampling().isUndefined(), + @"raster-resampling should be unset initially."); + NSExpression *defaultExpression = layer.rasterResamplingMode; + + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'nearest'"]; + layer.rasterResamplingMode = constantExpression; + mbgl::style::PropertyValue<mbgl::style::RasterResamplingType> propertyValue = { mbgl::style::RasterResamplingType::Nearest }; + XCTAssertEqual(rawLayer->getRasterResampling(), propertyValue, + @"Setting rasterResamplingMode to a constant value expression should update raster-resampling."); + XCTAssertEqualObjects(layer.rasterResamplingMode, constantExpression, + @"rasterResamplingMode should round-trip constant value expressions."); + + constantExpression = [NSExpression expressionWithFormat:@"'nearest'"]; + NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; + layer.rasterResamplingMode = functionExpression; + + mbgl::style::IntervalStops<mbgl::style::RasterResamplingType> intervalStops = {{ + { -INFINITY, mbgl::style::RasterResamplingType::Nearest }, + { 18, mbgl::style::RasterResamplingType::Nearest }, + }}; + propertyValue = mbgl::style::CameraFunction<mbgl::style::RasterResamplingType> { intervalStops }; + + XCTAssertEqual(rawLayer->getRasterResampling(), propertyValue, + @"Setting rasterResamplingMode to a camera expression should update raster-resampling."); + XCTAssertEqualObjects(layer.rasterResamplingMode, functionExpression, + @"rasterResamplingMode should round-trip camera expressions."); + + + layer.rasterResamplingMode = nil; + XCTAssertTrue(rawLayer->getRasterResampling().isUndefined(), + @"Unsetting rasterResamplingMode should return raster-resampling to the default value."); + XCTAssertEqualObjects(layer.rasterResamplingMode, defaultExpression, + @"rasterResamplingMode should return the default value after being unset."); + + functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; + XCTAssertThrowsSpecificNamed(layer.rasterResamplingMode = functionExpression, NSException, NSInvalidArgumentException, @"MGLRasterLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); + functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:(bogus, %@, %@)", constantExpression, @{@18: constantExpression}]; + functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; + XCTAssertThrowsSpecificNamed(layer.rasterResamplingMode = functionExpression, NSException, NSInvalidArgumentException, @"MGLRasterLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); + } + // raster-saturation { XCTAssertTrue(rawLayer->getRasterSaturation().isUndefined(), @@ -366,7 +409,13 @@ [self testPropertyName:@"raster-fade-duration" isBoolean:NO]; [self testPropertyName:@"raster-hue-rotation" isBoolean:NO]; [self testPropertyName:@"raster-opacity" isBoolean:NO]; + [self testPropertyName:@"raster-resampling-mode" isBoolean:NO]; [self testPropertyName:@"raster-saturation" isBoolean:NO]; } +- (void)testValueAdditions { + XCTAssertEqual([NSValue valueWithMGLRasterResamplingMode:MGLRasterResamplingModeLinear].MGLRasterResamplingModeValue, MGLRasterResamplingModeLinear); + XCTAssertEqual([NSValue valueWithMGLRasterResamplingMode:MGLRasterResamplingModeNearest].MGLRasterResamplingModeValue, MGLRasterResamplingModeNearest); +} + @end |