From 63e53de157e75e504a6bf1a678cebaea5acf72b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 22 Aug 2016 17:57:22 +0200 Subject: [core] standardize on uint16_t for texture sizes --- include/mbgl/map/view.hpp | 2 +- include/mbgl/platform/default/headless_view.hpp | 2 +- include/mbgl/util/image.hpp | 12 ++++++------ platform/android/src/native_map_view.cpp | 2 +- platform/darwin/src/image.mm | 3 ++- platform/default/headless_view.cpp | 14 ++++++++------ platform/default/jpeg_reader.cpp | 2 +- platform/default/png_reader.cpp | 2 +- platform/default/webp_reader.cpp | 3 ++- platform/macos/src/MGLMapView.mm | 16 ++++++++-------- platform/qt/src/image.cpp | 4 ++-- platform/qt/src/qmapboxgl.cpp | 8 +++++--- src/mbgl/map/view.cpp | 2 +- src/mbgl/util/raster.cpp | 2 +- src/mbgl/util/raster.hpp | 4 ++-- 15 files changed, 42 insertions(+), 36 deletions(-) diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index fa6f91d910..590eef7237 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -52,7 +52,7 @@ public: // Reads the pixel data from the current framebuffer. If your View implementation // doesn't support reading from the framebuffer, return a null pointer. - virtual PremultipliedImage readStillImage(); + virtual PremultipliedImage readStillImage(std::array size = {{ 0, 0 }}); // Notifies a watcher of map x/y/scale/rotation changes. virtual void notifyMapChange(MapChange change); diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index 89716643d4..c0ffd27fbf 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -45,7 +45,7 @@ public: void deactivate() override; void notifyMapChange(MapChange) override; - PremultipliedImage readStillImage() override; + PremultipliedImage readStillImage(std::array size = {{ 0, 0 }}) override; void resize(uint16_t width, uint16_t height); void setMapChangeCallback(std::function&& cb) { mapChangeCallback = std::move(cb); } diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index 124cdca7cd..795d1f9d1a 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -18,12 +18,12 @@ class Image : private util::noncopyable { public: Image() = default; - Image(size_t w, size_t h) + Image(uint16_t w, uint16_t h) : width(w), height(h), data(std::make_unique(size())) {} - Image(size_t w, size_t h, std::unique_ptr data_) + Image(uint16_t w, uint16_t h, std::unique_ptr data_) : width(w), height(h), data(std::move(data_)) {} @@ -46,11 +46,11 @@ public: rhs.data.get() + rhs.size()); } - size_t stride() const { return width * 4; } - size_t size() const { return width * height * 4; } + size_t stride() const { return static_cast(width) * 4; } + size_t size() const { return static_cast(width) * height * 4; } - size_t width = 0; - size_t height = 0; + uint16_t width = 0; + uint16_t height = 0; std::unique_ptr data; }; diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 385accfa9d..529511b6d9 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -208,7 +208,7 @@ void NativeMapView::render() { // take snapshot const unsigned int w = fbWidth; const unsigned int h = fbHeight; - mbgl::PremultipliedImage image { w, h }; + mbgl::PremultipliedImage image { static_cast(w), static_cast(h) }; MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); const size_t stride = image.stride(); auto tmp = std::make_unique(stride); diff --git a/platform/darwin/src/image.mm b/platform/darwin/src/image.mm index 854b9157f8..066535a58c 100644 --- a/platform/darwin/src/image.mm +++ b/platform/darwin/src/image.mm @@ -92,7 +92,8 @@ PremultipliedImage decodeImage(const std::string &source_data) { throw std::runtime_error("CGColorSpaceCreateDeviceRGB failed"); } - PremultipliedImage result { CGImageGetWidth(image), CGImageGetHeight(image) }; + PremultipliedImage result{ static_cast(CGImageGetWidth(image)), + static_cast(CGImageGetHeight(image)) }; CGContextRef context = CGBitmapContextCreate(result.data.get(), result.width, result.height, 8, result.stride(), color_space, kCGImageAlphaPremultipliedLast); diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 28c300b41e..95b196b746 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -40,19 +40,21 @@ void HeadlessView::resize(const uint16_t width, const uint16_t height) { needsResize = true; } -PremultipliedImage HeadlessView::readStillImage() { +PremultipliedImage HeadlessView::readStillImage(std::array size) { assert(active); - const unsigned int w = dimensions[0] * pixelRatio; - const unsigned int h = dimensions[1] * pixelRatio; + if (!size[0] || !size[1]) { + size[0] = dimensions[0] * pixelRatio; + size[1] = dimensions[1] * pixelRatio; + } - PremultipliedImage image { w, h }; - MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); + PremultipliedImage image { size[0], size[1] }; + MBGL_CHECK_ERROR(glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); const auto stride = image.stride(); auto tmp = std::make_unique(stride); uint8_t* rgba = image.data.get(); - for (int i = 0, j = h - 1; i < j; i++, j--) { + for (int i = 0, j = size[1] - 1; i < j; i++, j--) { std::memcpy(tmp.get(), rgba + i * stride, stride); std::memcpy(rgba + i * stride, rgba + j * stride, stride); std::memcpy(rgba + j * stride, tmp.get(), stride); diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp index 9bcf3c6bc1..5151060a12 100644 --- a/platform/default/jpeg_reader.cpp +++ b/platform/default/jpeg_reader.cpp @@ -119,7 +119,7 @@ PremultipliedImage decodeJPEG(const uint8_t* data, size_t size) { size_t components = cinfo.output_components; size_t rowStride = components * width; - PremultipliedImage image { width, height }; + PremultipliedImage image { static_cast(width), static_cast(height) }; uint8_t* dst = image.data.get(); JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, rowStride, 1); diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 0461ec61a6..5111edaa59 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -80,7 +80,7 @@ PremultipliedImage decodePNG(const uint8_t* data, size_t size) { int color_type = 0; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr); - UnassociatedImage image { width, height }; + UnassociatedImage image { static_cast(width), static_cast(height) }; if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); diff --git a/platform/default/webp_reader.cpp b/platform/default/webp_reader.cpp index 5b0eaf4741..6f90fe02f5 100644 --- a/platform/default/webp_reader.cpp +++ b/platform/default/webp_reader.cpp @@ -23,7 +23,8 @@ PremultipliedImage decodeWebP(const uint8_t* data, size_t size) { throw std::runtime_error("failed to decode WebP data"); } - UnassociatedImage image { size_t(width), size_t(height), std::move(webp) }; + UnassociatedImage image{ static_cast(width), static_cast(height), + std::move(webp) }; return util::premultiply(std::move(image)); } diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 8fae1e0174..13ec4508dc 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -2523,18 +2523,18 @@ public: [NSOpenGLContext clearCurrentContext]; } - mbgl::PremultipliedImage readStillImage() override { - auto size = getFramebufferSize(); - const unsigned int w = size[0]; - const unsigned int h = size[1]; - - mbgl::PremultipliedImage image { w, h }; - MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); + mbgl::PremultipliedImage readStillImage(std::array size = {{ 0, 0 }}) override { + if (!size[0] || !size[1]) { + size = getFramebufferSize(); + } + + mbgl::PremultipliedImage image { size[0], size[1] }; + MBGL_CHECK_ERROR(glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); const size_t stride = image.stride(); auto tmp = std::make_unique(stride); uint8_t *rgba = image.data.get(); - for (int i = 0, j = h - 1; i < j; i++, j--) { + for (int i = 0, j = size[1] - 1; i < j; i++, j--) { std::memcpy(tmp.get(), rgba + i * stride, stride); std::memcpy(rgba + i * stride, rgba + j * stride, stride); std::memcpy(rgba + j * stride, tmp.get(), stride); diff --git a/platform/qt/src/image.cpp b/platform/qt/src/image.cpp index f51f993d48..3918b35208 100644 --- a/platform/qt/src/image.cpp +++ b/platform/qt/src/image.cpp @@ -57,7 +57,7 @@ PremultipliedImage decodeImage(const std::string& string) { auto img = std::make_unique(image.byteCount()); memcpy(img.get(), image.constBits(), image.byteCount()); - return { size_t(image.width()), size_t(image.height()), std::move(img) }; + return { static_cast(image.width()), static_cast(image.height()), + std::move(img) }; } - } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 8a6be68c63..74238bd240 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -119,11 +119,13 @@ std::unique_ptr toSpriteImage(const QImage &sprite) { auto img = std::make_unique(swapped.byteCount()); memcpy(img.get(), swapped.constBits(), swapped.byteCount()); - return std::make_unique(mbgl::PremultipliedImage - { size_t(swapped.width()), size_t(swapped.height()), std::move(img) }, 1.0); + return std::make_unique( + mbgl::PremultipliedImage{ static_cast(swapped.width()), + static_cast(swapped.height()), std::move(img) }, + 1.0); } -} +} // namespace /*! \class QMapboxGLSettings diff --git a/src/mbgl/map/view.cpp b/src/mbgl/map/view.cpp index 9e3352daa8..8541753c7a 100644 --- a/src/mbgl/map/view.cpp +++ b/src/mbgl/map/view.cpp @@ -10,7 +10,7 @@ void View::initialize(Map *map_) { map = map_; } -PremultipliedImage View::readStillImage() { +PremultipliedImage View::readStillImage(std::array) { return {}; } diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp index 535d34b105..498f6027b7 100644 --- a/src/mbgl/util/raster.cpp +++ b/src/mbgl/util/raster.cpp @@ -18,7 +18,7 @@ GLuint Raster::getID() const { return texture ? *texture : 0; } -std::array Raster::getSize() const { +std::array Raster::getSize() const { return size; } diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp index 9d621668f4..860c533086 100644 --- a/src/mbgl/util/raster.hpp +++ b/src/mbgl/util/raster.hpp @@ -38,12 +38,12 @@ public: GLuint getID() const; // size of uploaded image. - std::array getSize() const; + std::array getSize() const; private: // raw pixels have been loaded std::atomic loaded { false }; - std::array size = {{ 0, 0 }}; + std::array size = {{ 0, 0 }}; // filters Scaling filter = Scaling::Nearest; -- cgit v1.2.1