summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-08-22 17:57:22 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-27 10:42:10 +0200
commit63e53de157e75e504a6bf1a678cebaea5acf72b9 (patch)
tree234cb14695f21df69012f1470ee512b8fc8d9904 /platform
parent512037cfdc14fb1f7686254efe97b72433c5e4b6 (diff)
downloadqtlocation-mapboxgl-63e53de157e75e504a6bf1a678cebaea5acf72b9.tar.gz
[core] standardize on uint16_t for texture sizes
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/android/src/native_map_view.cpp2
-rw-r--r--platform/darwin/src/image.mm3
-rw-r--r--platform/default/headless_view.cpp14
-rw-r--r--platform/default/jpeg_reader.cpp2
-rw-r--r--platform/default/png_reader.cpp2
-rw-r--r--platform/default/webp_reader.cpp3
-rw-r--r--platform/macos/src/MGLMapView.mm16
-rw-r--r--platform/qt/src/image.cpp4
-rw-r--r--platform/qt/src/qmapboxgl.cpp8
9 files changed, 30 insertions, 24 deletions
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<uint16_t>(w), static_cast<uint16_t>(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<uint8_t[]>(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<uint16_t>(CGImageGetWidth(image)),
+ static_cast<uint16_t>(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<uint16_t, 2> 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<uint8_t[]>(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<uint16_t>(width), static_cast<uint16_t>(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<uint16_t>(width), static_cast<uint16_t>(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<uint16_t>(width), static_cast<uint16_t>(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<uint16_t, 2> 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<uint8_t[]>(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<uint8_t[]>(image.byteCount());
memcpy(img.get(), image.constBits(), image.byteCount());
- return { size_t(image.width()), size_t(image.height()), std::move(img) };
+ return { static_cast<uint16_t>(image.width()), static_cast<uint16_t>(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<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) {
auto img = std::make_unique<uint8_t[]>(swapped.byteCount());
memcpy(img.get(), swapped.constBits(), swapped.byteCount());
- return std::make_unique<mbgl::SpriteImage>(mbgl::PremultipliedImage
- { size_t(swapped.width()), size_t(swapped.height()), std::move(img) }, 1.0);
+ return std::make_unique<mbgl::SpriteImage>(
+ mbgl::PremultipliedImage{ static_cast<uint16_t>(swapped.width()),
+ static_cast<uint16_t>(swapped.height()), std::move(img) },
+ 1.0);
}
-}
+} // namespace
/*!
\class QMapboxGLSettings