Skip to content

Commit

Permalink
add raster-resampling raster paint property (#6411)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewharvey authored Jun 19, 2018
1 parent e71c5e9 commit f546de2
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 6 deletions.
7 changes: 5 additions & 2 deletions debug/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
"id": "background",
"type": "background",
"paint": {
"background-color": "rgb(4,7,14)"
"background-color": "rgb(128,128,128)"
}
}, {
"id": "image",
"type": "raster",
"source": "image"
"source": "image",
"paint": {
"raster-resampling": "nearest"
}
}]
};

Expand Down
8 changes: 5 additions & 3 deletions src/render/draw_raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ function drawRaster(painter: Painter, sourceCache: SourceCache, layer: RasterSty

let parentScaleBy, parentTL;

const textureFilter = layer.paint.get('raster-resampling') === 'nearest' ? gl.NEAREST : gl.LINEAR;

context.activeTexture.set(gl.TEXTURE0);
tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
tile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);

context.activeTexture.set(gl.TEXTURE1);

if (parentTile) {
parentTile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
parentTile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
parentScaleBy = Math.pow(2, parentTile.tileID.overscaledZ - tile.tileID.overscaledZ);
parentTL = [tile.tileID.canonical.x * parentScaleBy % 1, tile.tileID.canonical.y * parentScaleBy % 1];

} else {
tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
tile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
}

// cross-fade parameters
Expand Down
26 changes: 26 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -5013,6 +5013,32 @@
},
"property-type": "data-constant"
},
"raster-resampling": {
"type": "enum",
"doc": "The resampling/interpolation method to use for overscaling, also known as texture magnification filter",
"values": {
"linear": {
"doc": "(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": {
"doc": "Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled"
}
},
"default": "linear",
"sdk-support": {
"basic functionality": {
"js": "0.47.0"
},
"data-driven styling": {}
},
"expression": {
"interpolated": false,
"parameters": [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-fade-duration": {
"type": "number",
"default": 300,
Expand Down
2 changes: 2 additions & 0 deletions src/style/style_layer/raster_style_layer_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type PaintProps = {|
"raster-brightness-max": DataConstantProperty<number>,
"raster-saturation": DataConstantProperty<number>,
"raster-contrast": DataConstantProperty<number>,
"raster-resampling": DataConstantProperty<"linear" | "nearest">,
"raster-fade-duration": DataConstantProperty<number>,
|};

Expand All @@ -32,6 +33,7 @@ const paint: Properties<PaintProps> = new Properties({
"raster-brightness-max": new DataConstantProperty(styleSpec["paint_raster"]["raster-brightness-max"]),
"raster-saturation": new DataConstantProperty(styleSpec["paint_raster"]["raster-saturation"]),
"raster-contrast": new DataConstantProperty(styleSpec["paint_raster"]["raster-contrast"]),
"raster-resampling": new DataConstantProperty(styleSpec["paint_raster"]["raster-resampling"]),
"raster-fade-duration": new DataConstantProperty(styleSpec["paint_raster"]["raster-fade-duration"]),
});

Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are two test suites associated with Mapbox GL JS
To run individual tests:

- Unit tests: `yarn test-unit path/to/file.test.js` where the path begins within the `/test/unit/` directory
- Render tests: `yarn test-render render-test-name`
- Render tests: `yarn test-render render-test-name` (e.g. `yarn test-render background-color/default`)

## Writing Unit Tests

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions test/integration/render-tests/image/raster-resampling/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64
}
},
"center": [
-122.514526,
37.562984
],
"zoom": 20,
"sources": {
"image": {
"type": "image",
"coordinates": [
[
-122.51596391201019,
37.56238816766053
],
[
-122.51467645168304,
37.56410183312965
],
[
-122.51309394836426,
37.563391708549425
],
[
-122.51423120498657,
37.56161849366671
]
],
"url": "local://image/0.png"
}
},
"layers": [
{
"id": "image",
"type": "raster",
"source": "image",
"paint": {
"raster-fade-duration": 0,
"raster-resampling": "nearest"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions test/integration/render-tests/raster-resampling/default/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 20,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 17,
"tileSize": 256
}
},
"layers": [
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 20,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 17,
"tileSize": 256
}
},
"layers": [
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0,
"raster-resampling": {
"stops": [
[
19,
"linear"
],
[
20,
"nearest"
]
]
}
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/integration/render-tests/raster-resampling/literal/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 20,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 17,
"tileSize": 256
}
},
"layers": [
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0,
"raster-resampling": "nearest"
}
}
]
}

0 comments on commit f546de2

Please sign in to comment.