[vte/wip/sixels] sixel: Honor DECSIXEL Ps2 with optional opacity



commit a4c632cfdb2db2a9686b85cda2a751c6a2de2616
Author: Hans Petter Jansson <hpj hpjansson org>
Date:   Mon Nov 2 03:39:35 2020 +0100

    sixel: Honor DECSIXEL Ps2 with optional opacity
    
    When set to 1, this parameter will output an image with transparency
    in uninked pixels. Any other value will fill these pixels with the
    default background color.

 src/sixel-context.cc |  7 +++++--
 src/sixel-context.hh |  1 +
 src/sixel-test.cc    | 11 ++++++++---
 src/vteseq.cc        |  8 +++++---
 4 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/src/sixel-context.cc b/src/sixel-context.cc
index 4db40cd7..cb25fb56 100644
--- a/src/sixel-context.cc
+++ b/src/sixel-context.cc
@@ -305,6 +305,7 @@ Context::prepare(uint32_t introducer,
                  unsigned bg_green,
                  unsigned bg_blue,
                  bool private_color_registers,
+                 bool opaque_bg,
                  double pixel_aspect) noexcept
 {
         m_introducer = introducer;
@@ -315,8 +316,10 @@ Context::prepare(uint32_t introducer,
         if (private_color_registers)
                 reset_colors();
 
+        if (opaque_bg)
+                set_color(0, make_color(bg_red, bg_green, bg_blue));
+
         /* FIXMEchpe: this all seems bogus. */
-        set_color(param_to_color_register(0), make_color(bg_red, bg_green, bg_blue));
         if (private_color_registers)
                 set_color(param_to_color_register(0),
                           make_color(fg_red, fg_green, fg_blue));
@@ -328,7 +331,7 @@ Context::prepare(uint32_t introducer,
          */
         set_current_color(param_to_color_register(0));
 
-        /* Clear bufer, and scanline offsets */
+        /* Clear buffer and scanline offsets */
         std::memset(m_scanlines_offsets, 0, sizeof(m_scanlines_offsets));
 
         if (m_scanlines_data)
diff --git a/src/sixel-context.hh b/src/sixel-context.hh
index 8364702f..32ea942c 100644
--- a/src/sixel-context.hh
+++ b/src/sixel-context.hh
@@ -628,6 +628,7 @@ public:
                      unsigned bg_green,
                      unsigned bg_blue,
                      bool private_color_registers,
+                     bool opaque_bg,
                      double pixel_aspect = 1.0) noexcept;
 
         void reset_colors() noexcept;
diff --git a/src/sixel-test.cc b/src/sixel-test.cc
index e91c2cd7..db0f2d43 100644
--- a/src/sixel-test.cc
+++ b/src/sixel-test.cc
@@ -1020,13 +1020,15 @@ parse_image(C& context,
             unsigned bg_green,
             unsigned bg_blue,
             bool private_color_registers = true,
+            bool opaque_bg = true,
             int line = __builtin_LINE())
 {
         context.reset();
         context.prepare(0x50 /* C0 DCS */,
                         fg_red, fg_green, fg_blue,
                         bg_red, bg_green, bg_blue,
-                        private_color_registers);
+                        private_color_registers,
+                        opaque_bg);
 
         auto str_st = std::string{str};
         str_st.append(ST(StType::C0));
@@ -1045,12 +1047,15 @@ parse_image(C& context,
             unsigned bg_green,
             unsigned bg_blue,
             bool private_color_registers = true,
+            bool opaque_bg = true,
             int line = __builtin_LINE())
 {
         parse_image(context, ItemStringifier(items).string(),
                     fg_red, fg_green, fg_blue,
                     bg_red, bg_green, bg_blue,
-                    private_color_registers, line);
+                    private_color_registers,
+                    opaque_bg,
+                    line);
 }
 
 template<class C>
@@ -1059,7 +1064,7 @@ parse_image(C& context,
             std::string_view const& str,
             int line = __builtin_LINE())
 {
-        parse_image(context, str, 0xffu, 0xffu, 0xffu, 0xff8, 0xffu, 0xffu, true, line);
+        parse_image(context, str, 0xffu, 0xffu, 0xffu, 0xff8, 0xffu, 0xffu, true, true, line);
 }
 
 template<class C>
diff --git a/src/vteseq.cc b/src/vteseq.cc
index ac9c4993..aa5d91a3 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -4382,8 +4382,8 @@ Terminal::DECSIXEL(vte::parser::Sequence const& seq)
          *
          * Defaults:
          *   args[0]: 0
-         *   args[0]: 2 (1 for printers)
-         *   args[0]: no default
+         *   args[1]: 2 (1 for printers)
+         *   args[2]: no default
          *
          * References: VT330
          *             DEC PPLV2 ยง 5.4
@@ -4443,11 +4443,13 @@ Terminal::DECSIXEL(vte::parser::Sequence const& seq)
 
                 auto const fg = get_color(VTE_DEFAULT_FG);
                 auto const bg = get_color(VTE_DEFAULT_BG);
+                auto const opaque_bg = seq.collect1(1) == 1 ? false : true;
 
                 m_sixel_context->prepare(seq.st(),
                                          fg->red >> 8, fg->green >> 8, fg->blue >> 8,
                                          bg->red >> 8, bg->green >> 8, bg->blue >> 8,
-                                         m_modes_private.XTERM_SIXEL_PRIVATE_COLOR_REGISTERS());
+                                         m_modes_private.XTERM_SIXEL_PRIVATE_COLOR_REGISTERS(),
+                                         opaque_bg);
 
                 m_sixel_context->set_mode(mode);
 


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