[core] add raster-resampling property (#12176)

* update style-code for raster-resampling

* implement user-defined raster-resampling

* invert filter condition

* raster-resampling -> raster-resampling-mode for darwin language conventions
This commit is contained in:
Molly Lloyd
2018-06-21 14:37:17 -07:00
committed by GitHub
parent eb70b89849
commit e1af62e87d
24 changed files with 341 additions and 6 deletions

View File

@@ -570,6 +570,27 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface FILL_EXTRUSION_TRANSLATE_ANCHOR {}
// RASTER_RESAMPLING: The resampling/interpolation method to use for overscaling, also known as texture magnification filter
/**
* (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
*/
public static final String RASTER_RESAMPLING_LINEAR = "linear";
/**
* Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled
*/
public static final String RASTER_RESAMPLING_NEAREST = "nearest";
/**
* The resampling/interpolation method to use for overscaling, also known as texture magnification filter
*/
@StringDef({
RASTER_RESAMPLING_LINEAR,
RASTER_RESAMPLING_NEAREST,
})
@Retention(RetentionPolicy.SOURCE)
public @interface RASTER_RESAMPLING {}
// HILLSHADE_ILLUMINATION_ANCHOR: Direction of light source when map is rotated.
/**

View File

@@ -1335,6 +1335,26 @@ public class PropertyFactory {
return new PaintPropertyValue<>("raster-contrast", expression);
}
/**
* The resampling/interpolation method to use for overscaling, also known as texture magnification filter
*
* @param value a String value
* @return property wrapper around String
*/
public static PropertyValue<String> rasterResampling(@Property.RASTER_RESAMPLING String value) {
return new PaintPropertyValue<>("raster-resampling", value);
}
/**
* The resampling/interpolation method to use for overscaling, also known as texture magnification filter
*
* @param expression an expression statement
* @return property wrapper around an expression statement
*/
public static PropertyValue<Expression> rasterResampling(Expression expression) {
return new PaintPropertyValue<>("raster-resampling", expression);
}
/**
* Fade duration when a new tile is added.
*

View File

@@ -263,6 +263,17 @@ public class RasterLayer extends Layer {
nativeSetRasterContrastTransition(options.getDuration(), options.getDelay());
}
/**
* Get the RasterResampling property
*
* @return property wrapper value around String
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getRasterResampling() {
checkThread();
return (PropertyValue<String>) new PropertyValue("raster-resampling", nativeGetRasterResampling());
}
/**
* Get the RasterFadeDuration property
*
@@ -310,6 +321,8 @@ public class RasterLayer extends Layer {
private native void nativeSetRasterContrastTransition(long duration, long delay);
private native Object nativeGetRasterResampling();
private native Object nativeGetRasterFadeDuration();
@Override

View File

@@ -241,6 +241,20 @@ public class RasterLayerTest extends BaseActivityTest {
});
}
@Test
public void testRasterResamplingAsConstant() {
validateTestSetup();
setupLayer();
Timber.i("raster-resampling");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterResampling(RASTER_RESAMPLING_LINEAR));
assertEquals((String) layer.getRasterResampling().getValue(), (String) RASTER_RESAMPLING_LINEAR);
});
}
@Test
public void testRasterFadeDurationAsConstant() {
validateTestSetup();

View File

@@ -92,6 +92,13 @@ struct Converter<jni::jobject*, mbgl::style::CirclePitchScaleType> {
}
};
template <>
struct Converter<jni::jobject*, mbgl::style::RasterResamplingType> {
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::RasterResamplingType& value) const {
return convert<jni::jobject*, std::string>(env, toString(value));
}
};
template <>
struct Converter<jni::jobject*, mbgl::style::HillshadeIlluminationAnchorType> {
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::HillshadeIlluminationAnchorType& value) const {

View File

@@ -206,6 +206,20 @@ namespace conversion {
}
}
// raster-resampling
inline std::string toString(mbgl::style::RasterResamplingType value) {
switch (value) {
case mbgl::style::RasterResamplingType::Linear:
return "linear";
break;
case mbgl::style::RasterResamplingType::Nearest:
return "nearest";
break;
default:
throw std::runtime_error("Not implemented");
}
}
// hillshade-illumination-anchor
inline std::string toString(mbgl::style::HillshadeIlluminationAnchorType value) {
switch (value) {

View File

@@ -149,6 +149,12 @@ namespace android {
layer.as<mbgl::style::RasterLayer>()->RasterLayer::setRasterContrastTransition(options);
}
jni::Object<jni::ObjectTag> RasterLayer::getRasterResampling(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::RasterLayer>()->RasterLayer::getRasterResampling());
return jni::Object<jni::ObjectTag>(*converted);
}
jni::Object<jni::ObjectTag> RasterLayer::getRasterFadeDuration(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::RasterLayer>()->RasterLayer::getRasterFadeDuration());
@@ -193,6 +199,7 @@ namespace android {
METHOD(&RasterLayer::getRasterContrastTransition, "nativeGetRasterContrastTransition"),
METHOD(&RasterLayer::setRasterContrastTransition, "nativeSetRasterContrastTransition"),
METHOD(&RasterLayer::getRasterContrast, "nativeGetRasterContrast"),
METHOD(&RasterLayer::getRasterResampling, "nativeGetRasterResampling"),
METHOD(&RasterLayer::getRasterFadeDuration, "nativeGetRasterFadeDuration"));
}

View File

@@ -53,6 +53,8 @@ public:
void setRasterContrastTransition(jni::JNIEnv&, jlong duration, jlong delay);
jni::Object<TransitionOptions> getRasterContrastTransition(jni::JNIEnv&);
jni::Object<jni::ObjectTag> getRasterResampling(jni::JNIEnv&);
jni::Object<jni::ObjectTag> getRasterFadeDuration(jni::JNIEnv&);
jni::jobject* createJavaPeer(jni::JNIEnv&);