diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:18:06 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:18:06 -0700 |
| commit | 83d5ba42f8a98fc0df177efef4333f74a0481f61 (patch) | |
| tree | 6f1fcff64ec9adb2fc51a7cfcc451eb22a103fb3 /include/image.hpp | |
Diffstat (limited to 'include/image.hpp')
| -rw-r--r-- | include/image.hpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/image.hpp b/include/image.hpp new file mode 100644 index 0000000..3124b58 --- /dev/null +++ b/include/image.hpp @@ -0,0 +1,54 @@ +// Display images inside a terminal +// Copyright (C) 2023 JustKidding +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +#ifndef IMAGE_H +#define IMAGE_H + +#include <filesystem> +#include <memory> +#include <nlohmann/json.hpp> +#include <string> + +#include "dimensions.hpp" +#include "terminal.hpp" + +class Image +{ + public: + static auto load(const nlohmann::json &command, const Terminal *terminal) -> std::unique_ptr<Image>; + static auto check_cache(const Dimensions &dimensions, const std::filesystem::path &orig_path) -> std::string; + static auto get_dimensions(const nlohmann::json &json, const Terminal *terminal) -> std::shared_ptr<Dimensions>; + + virtual ~Image() = default; + + [[nodiscard]] virtual auto dimensions() const -> const Dimensions & = 0; + [[nodiscard]] virtual auto width() const -> int = 0; + [[nodiscard]] virtual auto height() const -> int = 0; + [[nodiscard]] virtual auto size() const -> size_t = 0; + [[nodiscard]] virtual auto data() const -> const unsigned char * = 0; + [[nodiscard]] virtual auto channels() const -> int = 0; + + [[nodiscard]] virtual auto frame_delay() const -> int { return -1; } + [[nodiscard]] virtual auto is_animated() const -> bool { return false; } + [[nodiscard]] virtual auto filename() const -> std::string = 0; + virtual auto next_frame() -> void {} + + protected: + [[nodiscard]] auto get_new_sizes(double max_width, double max_height, std::string_view scaler, + int scale_factor = 0) const -> std::pair<int, int>; +}; + +#endif |
