summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-07-07 08:25:26 -0700
committerKonstantin Käfer <mail@kkaefer.com>2015-07-08 19:46:04 +0200
commite0da13dbfd986f780f7328748cb7700dc396685b (patch)
tree288bef9d4573230ba9bba6552105dee30fa3d65a
parente3b823b11b4be58457498a4853580702c747d6dc (diff)
downloadqtlocation-mapboxgl-e0da13dbfd986f780f7328748cb7700dc396685b.tar.gz
fixes for runtime Cocoa imagery
-rw-r--r--ios/app/MBXViewController.mm2
-rw-r--r--platform/ios/MGLMapView.mm49
2 files changed, 19 insertions, 32 deletions
diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm
index 995ae9d448..38b49454c5 100644
--- a/ios/app/MBXViewController.mm
+++ b/ios/app/MBXViewController.mm
@@ -361,7 +361,7 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(ctx, [[[UIColor redColor] colorWithAlphaComponent:0.25] CGColor]);
- CGContextFillEllipseInRect(ctx, rect);
+ CGContextFillRect(ctx, rect);
image = [MGLAnnotationImage annotationImageWithImage:UIGraphicsGetImageFromCurrentImageContext() reuseIdentifier:identifier];
UIGraphicsEndImageContext();
}
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index e0a5407f33..c8040b6290 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -18,6 +18,7 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/image.hpp>
#import "MapboxGL.h"
@@ -1882,40 +1883,26 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
// store image & symbol name
[self.annotationImages setObject:annotationImage forKey:annotationImage.reuseIdentifier];
- // manually draw random-colored sprite for now
- float pixelRatio = [[UIScreen mainScreen] scale];
- float width = 20;
- float height = 20;
-
- const int r = 255 * (double(std::rand()) / RAND_MAX);
- const int g = 255 * (double(std::rand()) / RAND_MAX);
- const int b = 255 * (double(std::rand()) / RAND_MAX);
-
- 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()));
- const int dist = (w / 2) * (w / 2);
- for (int y = 0; y < h; y++) {
- for (int x = 0; x < w; x++) {
- const int dx = x - w / 2;
- const int dy = y - h / 2;
- const int diff = dist - (dx * dx + dy * dy);
- if (diff > 0) {
- const int a = std::min(0xFF, diff) * 0xFF / dist;
- // Premultiply the rgb values with alpha
- data[w * y + x] =
- (a << 24) | ((a * r / 0xFF) << 16) | ((a * g / 0xFF) << 8) | (a * b / 0xFF);
- }
- }
- }
+ // retrieve pixels
+ CGImageRef image = annotationImage.image.CGImage;
+ size_t width = CGImageGetWidth(image);
+ size_t height = CGImageGetHeight(image);
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ std::string pixels(width * height * 4, '\0');
+ 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);
+ CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
+ CGContextRelease(context);
+ CGColorSpaceRelease(colorSpace);
// add sprite
auto cSpriteImage = std::make_shared<mbgl::SpriteImage>(
- width,
- height,
- pixelRatio,
+ uint16_t(annotationImage.image.size.width),
+ uint16_t(annotationImage.image.size.height),
+ float(annotationImage.image.scale),
std::move(pixels));
// sprite upload