summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-26 15:22:31 -0700
committerKonstantin Käfer <mail@kkaefer.com>2016-10-27 18:30:58 -0700
commit62b56b799a7d4fcd1a8f151eed878054b862da5b (patch)
tree34d510a69f9dd1bca30e9b137feffbd1eb6495d0 /platform/default
parentef8017198ce8f0bd79ba5a5ed31e35a16e3433bb (diff)
downloadqtlocation-mapboxgl-62b56b799a7d4fcd1a8f151eed878054b862da5b.tar.gz
[core] change std::array<uint16_t, 2> to mbgl::Size
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/glfw_view.cpp21
-rw-r--r--platform/default/image.cpp12
-rw-r--r--platform/default/jpeg_reader.cpp2
-rw-r--r--platform/default/offscreen_view.cpp18
-rw-r--r--platform/default/png_reader.cpp2
-rw-r--r--platform/default/webp_reader.cpp4
6 files changed, 26 insertions, 33 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 47551d786f..e9b32b21c8 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -132,14 +132,12 @@ void GLFWView::setMap(mbgl::Map *map_) {
void GLFWView::updateViewBinding() {
getContext().bindFramebuffer.setCurrentValue(0);
- getContext().viewport.setCurrentValue(
- { 0, 0, static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) });
+ getContext().viewport.setCurrentValue({ 0, 0, getFramebufferSize() });
}
void GLFWView::bind() {
getContext().bindFramebuffer = 0;
- getContext().viewport = { 0, 0, static_cast<uint16_t>(fbWidth),
- static_cast<uint16_t>(fbHeight) };
+ getContext().viewport = { 0, 0, getFramebufferSize() };
}
void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) {
@@ -192,7 +190,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
view->nextOrientation();
break;
case GLFW_KEY_Q: {
- auto result = view->map->queryPointAnnotations({ {}, { double(view->getSize()[0]), double(view->getSize()[1]) } });
+ auto result = view->map->queryPointAnnotations({ {}, { double(view->getSize().width), double(view->getSize().height) } });
printf("visible point annotations: %lu\n", result.size());
} break;
case GLFW_KEY_C:
@@ -267,7 +265,7 @@ GLFWView::makeSpriteImage(int width, int height, float pixelRatio) {
const int w = std::ceil(pixelRatio * width);
const int h = std::ceil(pixelRatio * height);
- mbgl::PremultipliedImage image(w, h);
+ mbgl::PremultipliedImage image({ static_cast<uint32_t>(w), static_cast<uint32_t>(h) });
auto data = reinterpret_cast<uint32_t*>(image.data.get());
const int dist = (w / 2) * (w / 2);
for (int y = 0; y < h; y++) {
@@ -374,8 +372,7 @@ void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
view->width = width;
view->height = height;
- view->map->setSize({{ static_cast<uint16_t>(view->width),
- static_cast<uint16_t>(view->height) }});
+ view->map->setSize({ static_cast<uint32_t>(view->width), static_cast<uint32_t>(view->height) });
}
void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) {
@@ -480,12 +477,12 @@ float GLFWView::getPixelRatio() const {
return pixelRatio;
}
-std::array<uint16_t, 2> GLFWView::getSize() const {
- return {{ static_cast<uint16_t>(width), static_cast<uint16_t>(height) }};
+mbgl::Size GLFWView::getSize() const {
+ return { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
}
-std::array<uint16_t, 2> GLFWView::getFramebufferSize() const {
- return {{ static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }};
+mbgl::Size GLFWView::getFramebufferSize() const {
+ return { static_cast<uint32_t>(fbWidth), static_cast<uint32_t>(fbHeight) };
}
void GLFWView::activate() {
diff --git a/platform/default/image.cpp b/platform/default/image.cpp
index 890d442683..84db1e9c71 100644
--- a/platform/default/image.cpp
+++ b/platform/default/image.cpp
@@ -25,8 +25,8 @@ const static bool png_version_check __attribute__((unused)) = []() {
namespace mbgl {
std::string encodePNG(const PremultipliedImage& pre) {
- PremultipliedImage copy { pre.width, pre.height };
- std::copy(pre.data.get(), pre.data.get() + pre.size(), copy.data.get());
+ PremultipliedImage copy(pre.size);
+ std::copy(pre.data.get(), pre.data.get() + pre.bytes(), copy.data.get());
UnassociatedImage src = util::unpremultiply(std::move(copy));
@@ -42,8 +42,8 @@ std::string encodePNG(const PremultipliedImage& pre) {
throw std::runtime_error("couldn't create info_ptr");
}
- png_set_IHDR(png_ptr, info_ptr, src.width, src.height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR(png_ptr, info_ptr, src.size.width, src.size.height, 8, PNG_COLOR_TYPE_RGB_ALPHA,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
jmp_buf *jmp_context = (jmp_buf *)png_get_error_ptr(png_ptr);
if (jmp_context) {
@@ -61,9 +61,9 @@ std::string encodePNG(const PremultipliedImage& pre) {
ptrs(size_t count) : rows(new png_bytep[count]) {}
~ptrs() { delete[] rows; }
png_bytep *rows = nullptr;
- } pointers(src.height);
+ } pointers(src.size.height);
- for (size_t i = 0; i < src.height; i++) {
+ for (size_t i = 0; i < src.size.height; i++) {
pointers.rows[i] = src.data.get() + src.stride() * i;
}
diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp
index 5151060a12..78c74f2fd7 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 { static_cast<uint16_t>(width), static_cast<uint16_t>(height) };
+ PremultipliedImage image({ static_cast<uint32_t>(width), static_cast<uint32_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/offscreen_view.cpp b/platform/default/offscreen_view.cpp
index eaf87d0f87..613e00fc2b 100644
--- a/platform/default/offscreen_view.cpp
+++ b/platform/default/offscreen_view.cpp
@@ -7,9 +7,9 @@
namespace mbgl {
-OffscreenView::OffscreenView(gl::Context& context_, std::array<uint16_t, 2> size_)
- : context(context_), size(std::move(size_)) {
- assert(size[0] > 0 && size[1] > 0);
+OffscreenView::OffscreenView(gl::Context& context_, const Size size_)
+ : size(std::move(size_)), context(context_) {
+ assert(size);
}
void OffscreenView::bind() {
@@ -21,17 +21,17 @@ void OffscreenView::bind() {
context.bindFramebuffer = framebuffer->framebuffer;
}
- context.viewport = { 0, 0, size[0], size[1] };
+ context.viewport = { 0, 0, size };
}
PremultipliedImage OffscreenView::readStillImage() {
- PremultipliedImage image { size[0], size[1] };
- MBGL_CHECK_ERROR(glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
+ PremultipliedImage image { size };
+ MBGL_CHECK_ERROR(glReadPixels(0, 0, size.width, size.height, 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 = size[1] - 1; i < j; i++, j--) {
+ for (int i = 0, j = size.height - 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);
@@ -40,8 +40,4 @@ PremultipliedImage OffscreenView::readStillImage() {
return image;
}
-std::array<uint16_t, 2> OffscreenView::getSize() const {
- return size;
-}
-
} // namespace mbgl
diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp
index 5111edaa59..7c10f20667 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 { static_cast<uint16_t>(width), static_cast<uint16_t>(height) };
+ UnassociatedImage image({ width, 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 6f90fe02f5..a56632157f 100644
--- a/platform/default/webp_reader.cpp
+++ b/platform/default/webp_reader.cpp
@@ -23,8 +23,8 @@ PremultipliedImage decodeWebP(const uint8_t* data, size_t size) {
throw std::runtime_error("failed to decode WebP data");
}
- UnassociatedImage image{ static_cast<uint16_t>(width), static_cast<uint16_t>(height),
- std::move(webp) };
+ UnassociatedImage image({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) },
+ std::move(webp));
return util::premultiply(std::move(image));
}