summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadia Barbosa <nadiabarbosa@me.com>2019-04-11 17:00:10 -0700
committerNadia Barbosa <nadiabarbosa@me.com>2019-04-11 17:00:10 -0700
commit837e42e07d52333bd790f81df3c2f5600b115faa (patch)
tree3920ba32d439307095c3f38725bf64596d1cbf69
parente95bf4dd9b804d6ec13417478dd1f87e888213bb (diff)
downloadqtlocation-mapboxgl-upstream/fix-halo-color-nb.tar.gz
[ios, macos] Premultiply color values for mgl_colorupstream/fix-halo-color-nb
Fixes https://github.com/mapbox/mapbox-gl-native/issues/14329
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm9
-rw-r--r--platform/ios/CHANGELOG.md1
-rw-r--r--platform/ios/src/UIColor+MGLAdditions.mm11
-rw-r--r--platform/macos/CHANGELOG.md1
-rw-r--r--platform/macos/src/NSColor+MGLAdditions.mm13
5 files changed, 28 insertions, 7 deletions
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 06f06d8c6e..e7d1608018 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -282,9 +282,14 @@ using namespace std::string_literals;
XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], color);
}
{
- MGLColor *color = [MGLColor mgl_colorWithColor:{ 255.0/255, 239.0/255, 213.0/255, 0.5 }]; // papayawhip
+ // Transform color components to non-premultiplied values
+ float alpha = 0.5;
+ float red = (255.0 * alpha) / 255;
+ float green = (239.0 * alpha) / 255;
+ float blue = (213.0 * alpha) / 255;
+ MGLColor *color = [MGLColor mgl_colorWithColor:{ red, green, blue, alpha }]; // papayawhip
NSExpression *expression = [NSExpression expressionForConstantValue:color];
- NSArray *jsonExpression = @[@"rgba", @255, @239, @213, @0.5];
+ NSArray *jsonExpression = @[@"rgba", @127.5, @119.5, @106.5, @0.5];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], color);
}
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index 72e3e75cb2..86b501e13f 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed an Interface Builder crash when using an `MGLMapView` in a storyboard. ([#14379](https://github.com/mapbox/mapbox-gl-native/pull/14379))
* Fix a bug that wrong position of attribution dialog after rotation. ([#14185](https://github.com/mapbox/mapbox-gl-native/pull/14185))
+* Fixed a bug where using `MGLSymbolStyleLayer.textHaloColor` with an alpha value would result in incorrect color values. ([#14406](https://github.com/mapbox/mapbox-gl-native/pull/14406))
## 4.10.0
diff --git a/platform/ios/src/UIColor+MGLAdditions.mm b/platform/ios/src/UIColor+MGLAdditions.mm
index 7c1fbddc20..5a4b5cf06e 100644
--- a/platform/ios/src/UIColor+MGLAdditions.mm
+++ b/platform/ios/src/UIColor+MGLAdditions.mm
@@ -6,7 +6,8 @@
{
CGFloat r, g, b, a;
[self getRed:&r green:&g blue:&b alpha:&a];
- return { (float)r, (float)g, (float)b, (float)a };
+ // Premultiply color components
+ return { static_cast<float>(r*a), static_cast<float>(g*a), static_cast<float>(b*a), static_cast<float>(a) };
}
- (mbgl::style::PropertyValue<mbgl::Color>)mgl_colorPropertyValue
@@ -17,7 +18,13 @@
+ (UIColor *)mgl_colorWithColor:(mbgl::Color)color
{
- return [UIColor colorWithRed:color.r green:color.g blue:color.b alpha:color.a];
+ // Since CIColor expects color values to be non-multiplied, we transform them here
+ // to non-premultiplied values
+ float red = static_cast<float>((color.r / color.a));
+ float green = static_cast<float>((color.g / color.a));
+ float blue = static_cast<float>((color.b / color.a));
+
+ return [UIColor colorWithRed:red green:green blue:blue alpha:color.a];
}
@end
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index ebfb3f335a..26f93377b2 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -12,6 +12,7 @@
* Added `mgl_attributed:` expression operator, which concatenate `MGLAttributedExpression` objects for specifying rich text in the `MGLSymbolStyleLayer.text` property. ([#14094](https://github.com/mapbox/mapbox-gl-native/pull/14094))
* Fixed an issue that caused conditional expressions to crash when passed nested conditional expressions as parameters. ([#14181](https://github.com/mapbox/mapbox-gl-native/pull/14181))
* Added `-[MGLMapViewDelegate mapView:didFailToLoadImage:]` to load missing symbol icons in the style if they are not found. ([#14302](https://github.com/mapbox/mapbox-gl-native/pull/14302))
+* Fixed a bug where using `MGLSymbolStyleLayer.textHaloColor` with an alpha value would result in incorrect color values. ([#14406](https://github.com/mapbox/mapbox-gl-native/pull/14406))
### Offline
diff --git a/platform/macos/src/NSColor+MGLAdditions.mm b/platform/macos/src/NSColor+MGLAdditions.mm
index ea7d99f66d..0714ac1ada 100644
--- a/platform/macos/src/NSColor+MGLAdditions.mm
+++ b/platform/macos/src/NSColor+MGLAdditions.mm
@@ -15,15 +15,22 @@
}
[srgbColor getRed:&r green:&g blue:&b alpha:&a];
- return { (float)r, (float)g, (float)b, (float)a };
+ // Premultiply color components
+ return { static_cast<float>(r*a), static_cast<float>(g*a), static_cast<float>(b*a), static_cast<float>(a) };
}
+ (NSColor *)mgl_colorWithColor:(mbgl::Color)color {
+ // Since CIColor expects color values to be non-multiplied, we transform them here
+ // to non-premultiplied values
+ float red = static_cast<float>((color.r / color.a));
+ float green = static_cast<float>((color.g / color.a));
+ float blue = static_cast<float>((color.b / color.a));
+
// macOS 10.12 Sierra and below uses calibrated RGB by default.
if ([NSColor redColor].colorSpaceName == NSCalibratedRGBColorSpace) {
- return [NSColor colorWithCalibratedRed:color.r green:color.g blue:color.b alpha:color.a];
+ return [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:color.a];
} else {
- return [NSColor colorWithRed:color.r green:color.g blue:color.b alpha:color.a];
+ return [NSColor colorWithRed:red green:green blue:blue alpha:color.a];
}
}