[vte/wip/sixels: 41/82] image: Fix resource calculation for non-image surfaces



commit b9d50712080bb5951a9c7e0b9883afc2ff48fb1d
Author: Hans Petter Jansson <hpj cl no>
Date:   Wed Jun 10 14:59:53 2020 +0200

    image: Fix resource calculation for non-image surfaces

 src/image.hh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/src/image.hh b/src/image.hh
index 01fec072..ad411656 100644
--- a/src/image.hh
+++ b/src/image.hh
@@ -65,7 +65,11 @@ public:
         inline constexpr auto get_top() const noexcept { return m_top_cells; }
         inline constexpr auto get_bottom() const noexcept { return m_top_cells + m_height_cells - 1; }
         inline auto resource_size() const noexcept {
-                return cairo_image_surface_get_stride(m_surface.get()) * m_height_pixels;
+                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;
         }
         bool contains(const Image &other) const noexcept;
         void paint(cairo_t *cr, gint offset_x, gint offset_y) const noexcept;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]