summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-01-15 17:39:08 -0800
committerAnsis Brammanis <brammanis@gmail.com>2016-01-19 18:23:21 -0800
commitd34f8eb674b9753c47616f37ae88ff7a02f61ba0 (patch)
treec19cfd5ba6b68c229b6e395f9a62294ab33d46f9 /platform
parent26faa6a5ade54c0a423aab84106876dc59be868f (diff)
downloadqtlocation-mapboxgl-d34f8eb674b9753c47616f37ae88ff7a02f61ba0.tar.gz
[core][ios][osx][android] make SpriteImage accept PremultipliedImage
the SpriteImage constructor signature changes from SpriteImage( uint16_t width, uint16_t height, float pixelRatio, std::string&& data, bool sdf = false); to SpriteImage(PremultipliedImage&&, float pixelRatio, bool sdf = false)
Diffstat (limited to 'platform')
-rw-r--r--platform/android/src/jni.cpp17
-rw-r--r--platform/default/glfw_view.cpp6
-rw-r--r--platform/ios/src/MGLMapView.mm11
-rw-r--r--platform/osx/src/MGLMapView.mm9
4 files changed, 22 insertions, 21 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 8157820d70..23be6a38f8 100644
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -24,6 +24,7 @@
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/storage/network_status.hpp>
+#include <mbgl/util/exception.hpp>
#pragma clang diagnostic ignored "-Wunused-parameter"
@@ -1225,16 +1226,18 @@ void JNICALL nativeAddAnnotationIcon(JNIEnv *env, jobject obj, jlong nativeMapVi
const std::string symbolName = std_string_from_jstring(env, symbol);
- jbyte* pixelData = env->GetByteArrayElements(jpixels, nullptr);
jsize size = env->GetArrayLength(jpixels);
- std::string pixels(reinterpret_cast<char*>(pixelData), size);
- env->ReleaseByteArrayElements(jpixels, pixelData, JNI_ABORT);
+ mbgl::PremultipliedImage premultipliedImage(width, height);
+
+ if (premultipliedImage.size() != uint32_t(size)) {
+ throw mbgl::util::SpriteImageException("Sprite image pixel count mismatch");
+ }
+
+ env->GetByteArrayRegion(jpixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get()));
auto iconImage = std::make_shared<mbgl::SpriteImage>(
- uint16_t(width),
- uint16_t(height),
- float(scale),
- std::move(pixels));
+ std::move(premultipliedImage),
+ float(scale));
nativeMapView->getMap().addAnnotationIcon(symbolName, iconImage);
}
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index bdd48d9d96..3103f09831 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -200,8 +200,8 @@ GLFWView::makeSpriteImage(int width, int height, float pixelRatio) {
const int w = std::ceil(pixelRatio * width);
const int h = std::ceil(pixelRatio * height);
- std::string pixels(w * h * 4, '\x00');
- auto data = reinterpret_cast<uint32_t*>(const_cast<char*>(pixels.data()));
+ mbgl::PremultipliedImage image(w, h);
+ auto data = reinterpret_cast<uint32_t*>(image.data.get());
const int dist = (w / 2) * (w / 2);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
@@ -217,7 +217,7 @@ GLFWView::makeSpriteImage(int width, int height, float pixelRatio) {
}
}
- return std::make_shared<mbgl::SpriteImage>(width, height, pixelRatio, std::move(pixels));
+ return std::make_shared<mbgl::SpriteImage>(std::move(image), pixelRatio);
}
void GLFWView::nextOrientation() {
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 3e63cd4b76..bc1419ef63 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2334,22 +2334,19 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- std::string pixels(width * height * 4, '\0');
+ mbgl::PremultipliedImage cPremultipliedImage(width, height);
size_t bytesPerPixel = 4;
size_t bytesPerRow = bytesPerPixel * width;
size_t bitsPerComponent = 8;
- char *pixelData = const_cast<char *>(pixels.data());
- CGContextRef context = CGBitmapContextCreate(pixelData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
+ CGContextRef context = CGBitmapContextCreate(cPremultipliedImage.data.get(), width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
// add sprite
auto cSpriteImage = std::make_shared<mbgl::SpriteImage>(
- uint16_t(width),
- uint16_t(height),
- float(annotationImage.image.scale),
- std::move(pixels));
+ std::move(cPremultipliedImage),
+ float(annotationImage.image.scale));
// sprite upload
NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 596b909fa2..9c32e7204d 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -1590,10 +1590,11 @@ public:
// Get the image’s raw pixel data as an RGBA buffer.
std::string pixelString((const char *)rep.bitmapData, rep.pixelsWide * rep.pixelsHigh * 4 /* RGBA */);
- auto cSpriteImage = std::make_shared<mbgl::SpriteImage>((uint16_t)rep.pixelsWide,
- (uint16_t)rep.pixelsHigh,
- (float)(rep.pixelsWide / size.width),
- std::move(pixelString));
+
+ mbgl::PremultipliedImage cPremultipliedImage(rep.pixelsWide, rep.pixelsHigh);
+ std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.size(), cPremultipliedImage.data.get());
+ auto cSpriteImage = std::make_shared<mbgl::SpriteImage>(std::move(cPremultipliedImage),
+ (float)(rep.pixelsWide / size.width));
NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
_mbglMap->addAnnotationIcon(symbolName.UTF8String, cSpriteImage);