[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)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user