diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 1f5a0ec98..10d6ed8f4 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #if MBGL_USE_GLX #ifdef GLX_ARB_create_context @@ -237,6 +238,15 @@ std::unique_ptr HeadlessView::readPixels() { glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); make_inactive(); + const int stride = w * 4; + auto tmp = std::unique_ptr(new char[stride]()); + char *rgba = reinterpret_cast(pixels.get()); + for (int i = 0, j = 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); + } + return pixels; } diff --git a/test/headless.cpp b/test/headless.cpp index 680f51aeb..e0409c473 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -203,15 +203,6 @@ TEST_P(HeadlessTest, render) { auto pixels = view.readPixels(); - const int stride = w * 4; - auto tmp = std::unique_ptr(new char[stride]()); - char *rgba = reinterpret_cast(pixels.get()); - for (int i = 0, j = height - 1; i < j; i++, j--) { - memcpy(tmp.get(), rgba + i * stride, stride); - memcpy(rgba + i * stride, rgba + j * stride, stride); - memcpy(rgba + j * stride, tmp.get(), stride); - } - const std::string image = util::compress_png(w, h, pixels.get()); util::write_file(actual_image, image); }