diff options
author | Hans Petter Jansson <hpj@cl.no> | 2020-08-08 21:55:09 +0200 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2020-08-08 21:55:09 +0200 |
commit | 9b879a3c326118ec8bd7657a7ac11d78f084e6c0 (patch) | |
tree | 93bb172f941e72e0ccfb080293b9e0b765f5c5be /src/image.hh | |
parent | acc15425af882bb541bff14557bafbdc77530c7d (diff) | |
download | vte-9b879a3c326118ec8bd7657a7ac11d78f084e6c0.tar.gz |
all: Add SIXEL support
This adds support for SIXEL images to VTE. Based on initial work by
Hayaki Saito <saitoha@me.com>, updated and improved by
Hans Petter Jansson <hpj@cl.no>
For now this is off by default; build with -Dsixel=true to enable.
(This is the contents of the wip/sixels branch, squashed together
into one commit.)
https://gitlab.gnome.org/GNOME/vte/-/issues/253
Diffstat (limited to 'src/image.hh')
-rw-r--r-- | src/image.hh | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/image.hh b/src/image.hh new file mode 100644 index 00000000..fa972c9b --- /dev/null +++ b/src/image.hh @@ -0,0 +1,102 @@ +/* + * Copyright © 2016-2020 Hayaki Saito <saitoha@me.com> + * Copyright © 2020 Hans Petter Jansson <hpj@cl.no> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser 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/>. + */ + +#pragma once + +#include <pango/pangocairo.h> +#include "cairo-glue.hh" + +namespace vte { + +namespace image { + +class Image { +private: + // Device-friendly Cairo surface + vte::cairo::Surface m_surface{}; + + // Draw/prune priority, must be unique + int m_priority; + + // Image dimensions in pixels + int m_width_pixels; + int m_height_pixels; + + // Top left corner offset in cell units + int m_left_cells; + int m_top_cells; + + // Cell dimensions in pixels at time of image creation + int m_cell_width; + int m_cell_height; + +public: + Image(vte::cairo::Surface&& surface, + int priority, + int width_pixels, + int height_pixels, + int col, + int row, + int cell_width, + int cell_height) noexcept + : m_surface{std::move(surface)}, + m_priority{priority}, + m_width_pixels{width_pixels}, + m_height_pixels{height_pixels}, + m_left_cells{col}, + m_top_cells{row}, + m_cell_width{cell_width}, + m_cell_height{cell_height} + { + } + + ~Image() = default; + + Image(Image const&) = delete; + Image(Image&&) = delete; + Image operator=(Image const&) = delete; + Image operator=(Image&&) = delete; + + inline constexpr auto get_priority() const noexcept { return m_priority; } + inline constexpr auto get_left() const noexcept { return m_left_cells; } + inline auto get_top() const noexcept { return m_top_cells; } + inline void set_top(int row) noexcept { m_top_cells = row; } + inline constexpr auto get_width() const noexcept { return (m_width_pixels + m_cell_width - 1) / m_cell_width; } + inline constexpr auto get_height() const noexcept { return (m_height_pixels + m_cell_height - 1) / m_cell_height; } + inline auto get_bottom() const noexcept { return m_top_cells + get_height() - 1; } + + inline auto resource_size() const noexcept + { + if (cairo_image_surface_get_stride(m_surface.get()) != 0) + return cairo_image_surface_get_stride(m_surface.get()) * m_height_pixels; + + /* Not an image surface: Only the device knows for sure, so we guess */ + return m_width_pixels * m_height_pixels * 4; + } + + void paint(cairo_t* cr, + int offset_x, + int offset_y, + int cell_width, + int cell_height) const noexcept; + +}; // class Image + +} // namespace image + +} // namespace vte |