summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-10-19 17:13:21 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-22 09:35:26 +0200
commit6cfa8a9d90cbbc36077d49bee65f19923690b169 (patch)
treefe510709fb681de84ea6b81f89f6a20b40e89063
parenta22ed80ea31838a8aafdcf095b3418db1a41002f (diff)
downloadqtlocation-mapboxgl-upstream/mikhail_image.tar.gz
Adapt Mac to the new util::Imageupstream/mikhail_image
-rw-r--r--include/mbgl/util/image.hpp9
-rw-r--r--platform/darwin/src/image.mm13
-rw-r--r--platform/darwin/src/local_glyph_rasterizer.mm6
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.mm6
4 files changed, 21 insertions, 13 deletions
diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp
index e38a283d70..e57cfe054e 100644
--- a/include/mbgl/util/image.hpp
+++ b/include/mbgl/util/image.hpp
@@ -49,26 +49,33 @@ template <ImageAlphaMode Mode>
class Image : public ImageBase {
public:
static constexpr size_t channels = Mode == ImageAlphaMode::Exclusive ? 1 : 4;
+
Image() = default;
Image(const Size& s) : ImageBase(s, channels) {}
Image(const Size& s, std::unique_ptr<uint8_t[]> d) : ImageBase(s, std::move(d)) {}
Image(Image&& o) = default;
- ~Image() = default;
Image& operator=(Image&& o) = default;
+
+ ~Image() = default;
+
size_t stride() const { return ImageBase::stride(channels); }
size_t bytes() const { return ImageBase::bytes(channels); }
+
// Resizes this image. If the given size is more than the current one,
// extra space is filled with '0'.
void resize(const Size& s) { ImageBase::resize(s, channels); }
+
// Clears the rect area specified by `pt` and `size` from this image.
// The image must be valid.
void clear(const Point<uint32_t>& pt, const Size& s) {
ImageBase::clear(pt, s, channels);
}
+
bool operator==(const Image& o) const {
return std::equal(data(), data() + bytes(),
o.data(), o.data() + o.bytes());
}
+
bool operator!=(const Image& o) const {
return !(operator==(o));
}
diff --git a/platform/darwin/src/image.mm b/platform/darwin/src/image.mm
index 3a5adcca0a..d286cea71c 100644
--- a/platform/darwin/src/image.mm
+++ b/platform/darwin/src/image.mm
@@ -15,15 +15,16 @@ CGImageRef CGImageCreateWithMGLPremultipliedImage(mbgl::PremultipliedImage&& src
// We're converting the PremultipliedImage's backing store to a CGDataProvider, and are taking
// over ownership of the memory.
CGDataProviderHandle provider(CGDataProviderCreateWithData(
- NULL, src.data.get(), src.bytes(), [](void*, const void* data, size_t) {
- delete[] reinterpret_cast<const decltype(src.data)::element_type*>(data);
+ NULL, src.data(), src.bytes(), [](void*, const void* data, size_t) {
+ delete[] reinterpret_cast<const uint8_t*>(data);
}));
if (!provider) {
return nil;
}
// If we successfully created the provider, it will take over management of the memory segment.
- src.data.release();
+ mbgl::Size srcSize{src.size()};
+ src.takeData().release();
CGColorSpaceHandle colorSpace(CGColorSpaceCreateDeviceRGB());
if (!colorSpace) {
@@ -33,9 +34,9 @@ CGImageRef CGImageCreateWithMGLPremultipliedImage(mbgl::PremultipliedImage&& src
constexpr const size_t bitsPerComponent = 8;
constexpr const size_t bytesPerPixel = 4;
constexpr const size_t bitsPerPixel = bitsPerComponent * bytesPerPixel;
- const size_t bytesPerRow = bytesPerPixel * src.size.width;
+ const size_t bytesPerRow = bytesPerPixel * srcSize.width;
- return CGImageCreate(src.size.width, src.size.height, bitsPerComponent, bitsPerPixel,
+ return CGImageCreate(srcSize.width, srcSize.height, bitsPerComponent, bitsPerPixel,
bytesPerRow, *colorSpace,
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, *provider,
NULL, false, kCGRenderingIntentDefault);
@@ -57,7 +58,7 @@ mbgl::PremultipliedImage MGLPremultipliedImageFromCGImage(CGImageRef src) {
const size_t bytesPerRow = bytesPerPixel * width;
CGContextHandle context(CGBitmapContextCreate(
- image.data.get(), width, height, bitsPerComponent, bytesPerRow, *colorSpace,
+ image.data(), width, height, bitsPerComponent, bytesPerRow, *colorSpace,
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast));
if (!context) {
throw std::runtime_error("CGBitmapContextCreate failed");
diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm
index 14cee5063e..e43259889b 100644
--- a/platform/darwin/src/local_glyph_rasterizer.mm
+++ b/platform/darwin/src/local_glyph_rasterizer.mm
@@ -114,7 +114,7 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, Size size) {
const size_t bytesPerRow = bytesPerPixel * size.width;
CGContextHandle context(CGBitmapContextCreate(
- rgbaBitmap.data.get(),
+ rgbaBitmap.data(),
size.width,
size.height,
bitsPerComponent,
@@ -165,8 +165,8 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) {
// Copy alpha values from RGBA bitmap into the AlphaImage output
fixedMetrics.bitmap = AlphaImage(size);
- for (uint32_t i = 0; i < size.width * size.height; i++) {
- fixedMetrics.bitmap.data[i] = rgbaBitmap.data[4 * i + 3];
+ for (uint32_t i = 0; i < size.area(); ++i) {
+ fixedMetrics.bitmap.data()[i] = rgbaBitmap.data()[4 * i + 3];
}
return fixedMetrics;
diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm
index 2666dfe790..0e11b1b4a3 100644
--- a/platform/macos/src/NSImage+MGLAdditions.mm
+++ b/platform/macos/src/NSImage+MGLAdditions.mm
@@ -23,8 +23,8 @@
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:image];
CGImageRelease(image);
- CGFloat w = styleImage->getImage().size.width / styleImage->getPixelRatio();
- CGFloat h = styleImage->getImage().size.height / styleImage->getPixelRatio();
+ CGFloat w = styleImage->getImage().size().width / styleImage->getPixelRatio();
+ CGFloat h = styleImage->getImage().size().height / styleImage->getPixelRatio();
if (self = [self initWithSize:NSMakeSize(w, h)]) {
[self addRepresentation:rep];
[self setTemplate:styleImage->isSdf()];
@@ -34,7 +34,7 @@
- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier {
mbgl::PremultipliedImage cPremultipliedImage = self.mgl_premultipliedImage;
- auto imageWidth = cPremultipliedImage.size.width;
+ auto imageWidth = cPremultipliedImage.size().width;
return std::make_unique<mbgl::style::Image>([identifier UTF8String],
std::move(cPremultipliedImage),
(float)(imageWidth / self.size.width),