[vte/wip/sixels: 75/82] sixelparser: Eliminate PS_DCS, which is handled in the regular parser



commit 5aeedcbde9f1cc7705c143fedfd0885de456e431
Author: Hans Petter Jansson <hpj cl no>
Date:   Fri Jun 26 01:30:05 2020 +0200

    sixelparser: Eliminate PS_DCS, which is handled in the regular parser

 src/sixelparser.cc | 79 ++++--------------------------------------------------
 src/sixelparser.hh | 14 +++++-----
 2 files changed, 13 insertions(+), 80 deletions(-)
---
diff --git a/src/sixelparser.cc b/src/sixelparser.cc
index 74434223..86ca1438 100644
--- a/src/sixelparser.cc
+++ b/src/sixelparser.cc
@@ -325,55 +325,6 @@ parser_collect_param_or_zero(sixel_state_t *st)
         return 0;
 }
 
-static int
-parser_action_dcs_attributes(sixel_state_t *st)
-{
-        if (st->nparams > 0) {
-                /* Pn1 */
-                switch (st->params[0]) {
-                case 0:
-                case 1:
-                        st->attributed_pad = 2;
-                        break;
-                case 2:
-                        st->attributed_pad = 5;
-                        break;
-                case 3:
-                case 4:
-                        st->attributed_pad = 4;
-                        break;
-                case 5:
-                case 6:
-                        st->attributed_pad = 3;
-                        break;
-                case 7:
-                case 8:
-                        st->attributed_pad = 2;
-                        break;
-                case 9:
-                        st->attributed_pad = 1;
-                        break;
-                default:
-                        st->attributed_pad = 2;
-                        break;
-                }
-        }
-
-        if (st->nparams > 2) {
-                /* Pn3 */
-                if (st->params[2] == 0)
-                        st->params[2] = 10;
-                st->attributed_pan = st->attributed_pan * st->params[2] / 10;
-                st->attributed_pad = st->attributed_pad * st->params[2] / 10;
-                if (st->attributed_pan <= 0)
-                        st->attributed_pan = 1;
-                if (st->attributed_pad <= 0)
-                        st->attributed_pad = 1;
-        }
-
-        return 0;
-}
-
 static void
 draw_sixels(sixel_state_t *st, uint32_t bits)
 {
@@ -568,31 +519,6 @@ parser_feed_char(sixel_state_t *st, uint32_t raw)
 
         for (;;) {
                 switch (st->state) {
-                case PS_ESC:
-                        switch (raw) {
-                        case '\\':
-                        case 0x9c:
-                                return 0;
-                        case 'P':
-                                return parser_transition(st, PS_DCS);
-                        }
-                        return 0;
-
-                case PS_DCS:
-                        switch (raw) {
-                        case 0x1b:
-                                return parser_transition(st, PS_ESC);
-                        case '0' ... '9':
-                                return parser_push_param_ascii_dec_digit(st, raw);
-                        case ';':
-                                return parser_collect_param_or_zero(st);
-                        case 'q':
-                                parser_collect_param(st);
-                                parser_action_dcs_attributes(st);
-                                return parser_transition(st, PS_DECSIXEL);
-                        }
-                        return 0;
-
                 case PS_DECSIXEL:
                         switch (raw) {
                         case 0x1b:
@@ -658,6 +584,11 @@ parser_feed_char(sixel_state_t *st, uint32_t raw)
                         parser_action_decgci(st);
                         parser_transition(st, PS_DECSIXEL);
                         continue;
+
+                case PS_ESC:
+                        /* The only escape code that can occur is end-of-input, "\x1b\\".
+                         * When we get to this state, just consume the rest quietly. */
+                        return 0;
                 }
         } /* for (;;) */
 }
diff --git a/src/sixelparser.hh b/src/sixelparser.hh
index 704dd029..c1eb58f2 100644
--- a/src/sixelparser.hh
+++ b/src/sixelparser.hh
@@ -39,12 +39,11 @@ typedef struct sixel_image_buffer {
 } sixel_image_t;
 
 typedef enum parse_state {
-       PS_ESC        = 1,  /* ESC */
-       PS_DCS        = 2,  /* DCS */
-       PS_DECSIXEL   = 3,  /* DECSIXEL body part ", $, -, ? ... ~ */
-       PS_DECGRA     = 4,  /* DECGRA Set Raster Attributes " Pan; Pad; Ph; Pv */
-       PS_DECGRI     = 5,  /* DECGRI Graphics Repeat Introducer ! Pn Ch */
-       PS_DECGCI     = 6,  /* DECGCI Graphics Color Introducer # Pc; Pu; Px; Py; Pz */
+       PS_ESC = 1,   /* ESC */
+       PS_DECSIXEL,  /* DECSIXEL body part ", $, -, ? ... ~ */
+       PS_DECGRA,    /* DECGRA Set Raster Attributes " Pan; Pad; Ph; Pv */
+       PS_DECGRI,    /* DECGRI Graphics Repeat Introducer ! Pn Ch */
+       PS_DECGCI,    /* DECGCI Graphics Color Introducer # Pc; Pu; Px; Py; Pz */
 } parse_state_t;
 
 typedef struct parser_context {
@@ -53,8 +52,11 @@ typedef struct parser_context {
        int pos_y;
        int max_x;
        int max_y;
+
+        /* Pixel aspect ratio; unused */
        int attributed_pan;
        int attributed_pad;
+
        int attributed_ph;
        int attributed_pv;
        int repeat_count;


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