| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// This file is part of INSTINCT, the INS Toolkit for Integrated | ||
| 2 | /// Navigation Concepts and Training by the Institute of Navigation of | ||
| 3 | /// the University of Stuttgart, Germany. | ||
| 4 | /// | ||
| 5 | /// This Source Code Form is subject to the terms of the Mozilla Public | ||
| 6 | /// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| 7 | /// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| 8 | |||
| 9 | #include "ImPlot.hpp" | ||
| 10 | |||
| 11 | #include <filesystem> | ||
| 12 | |||
| 13 | #include "internal/FlowManager.hpp" | ||
| 14 | #include "util/Json.hpp" | ||
| 15 | #include "util/Logger.hpp" | ||
| 16 | |||
| 17 | #ifdef IMGUI_IMPL_OPENGL_LOADER_GL3W | ||
| 18 | #ifdef __APPLE__ | ||
| 19 | #define GL_SILENCE_DEPRECATION | ||
| 20 | #include <OpenGL/gl.h> | ||
| 21 | #else | ||
| 22 | #include <GL/gl.h> | ||
| 23 | #endif | ||
| 24 | #define STB_IMAGE_WRITE_IMPLEMENTATION | ||
| 25 | #include "stb_image_write.h" | ||
| 26 | #endif | ||
| 27 | |||
| 28 | ✗ | void NAV::loadImPlotStyleFromConfigFile(const char* path, ImPlotStyle& imPlotStyle) | |
| 29 | { | ||
| 30 | ✗ | std::filesystem::path filepath = flow::GetConfigPath(); | |
| 31 | ✗ | if (std::filesystem::path inputPath{ path }; | |
| 32 | ✗ | inputPath.is_relative()) | |
| 33 | { | ||
| 34 | ✗ | filepath /= inputPath; | |
| 35 | } | ||
| 36 | else | ||
| 37 | { | ||
| 38 | ✗ | filepath = inputPath; | |
| 39 | ✗ | } | |
| 40 | ✗ | std::ifstream filestream(filepath); | |
| 41 | |||
| 42 | ✗ | if (!filestream.good()) | |
| 43 | { | ||
| 44 | ✗ | LOG_ERROR("The ImPlot style config file could not be loaded: {}", filepath.string()); | |
| 45 | } | ||
| 46 | else | ||
| 47 | { | ||
| 48 | ✗ | json j; | |
| 49 | ✗ | filestream >> j; | |
| 50 | |||
| 51 | ✗ | if (j.contains("implot") && j.at("implot").contains("style")) | |
| 52 | { | ||
| 53 | ✗ | j.at("implot").at("style").get_to(imPlotStyle); | |
| 54 | ✗ | LOG_DEBUG("Loaded ImPlot style from file {}", path); | |
| 55 | } | ||
| 56 | ✗ | } | |
| 57 | ✗ | } | |
| 58 | |||
| 59 | #ifdef IMGUI_IMPL_OPENGL_LOADER_GL3W | ||
| 60 | |||
| 61 | ✗ | NAV::ImGuiScreenshotImageBuf::ImGuiScreenshotImageBuf(int x, int y, size_t w, size_t h) | |
| 62 | ✗ | : Width(w), Height(h), Data(Width * Height * 4, 0) | |
| 63 | { | ||
| 64 | ✗ | glPixelStorei(GL_PACK_ALIGNMENT, 1); | |
| 65 | ✗ | glReadPixels(x, y, static_cast<int>(w), static_cast<int>(h), GL_RGBA, GL_UNSIGNED_BYTE, Data.data()); | |
| 66 | ✗ | RemoveAlpha(); | |
| 67 | ✗ | FlipVertical(); | |
| 68 | ✗ | } | |
| 69 | |||
| 70 | ✗ | void NAV::ImGuiScreenshotImageBuf::SaveFile(const char* filename) | |
| 71 | { | ||
| 72 | ✗ | stbi_write_png(filename, static_cast<int>(Width), | |
| 73 | ✗ | static_cast<int>(Height), | |
| 74 | 4, | ||
| 75 | ✗ | Data.data(), | |
| 76 | ✗ | static_cast<int>(Width * 4)); | |
| 77 | ✗ | } | |
| 78 | |||
| 79 | ✗ | void NAV::ImGuiScreenshotImageBuf::RemoveAlpha() | |
| 80 | { | ||
| 81 | ✗ | uint32_t* p = Data.data(); | |
| 82 | ✗ | auto n = static_cast<int>(Width * Height); | |
| 83 | ✗ | while (n-- > 0) | |
| 84 | { | ||
| 85 | ✗ | *p |= 0xFF000000; | |
| 86 | ✗ | p++; | |
| 87 | } | ||
| 88 | ✗ | } | |
| 89 | |||
| 90 | ✗ | void NAV::ImGuiScreenshotImageBuf::FlipVertical() | |
| 91 | { | ||
| 92 | ✗ | size_t comp = 4; | |
| 93 | ✗ | size_t stride = Width * comp; | |
| 94 | ✗ | std::vector<unsigned char> line_tmp(stride); | |
| 95 | ✗ | auto* line_a = reinterpret_cast<unsigned char*>(Data.data()); | |
| 96 | ✗ | auto* line_b = reinterpret_cast<unsigned char*>(Data.data()) + (stride * (Height - 1)); | |
| 97 | ✗ | while (line_a < line_b) | |
| 98 | { | ||
| 99 | ✗ | memcpy(line_tmp.data(), line_a, stride); | |
| 100 | ✗ | memcpy(line_a, line_b, stride); | |
| 101 | ✗ | memcpy(line_b, line_tmp.data(), stride); | |
| 102 | ✗ | line_a += stride; | |
| 103 | ✗ | line_b -= stride; | |
| 104 | } | ||
| 105 | ✗ | } | |
| 106 | |||
| 107 | #endif | ||
| 108 |