emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 873cd63: Allow a :stride argument so XBM boolvecs a


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 873cd63: Allow a :stride argument so XBM boolvecs are in the right format.
Date: Tue, 24 Sep 2019 12:36:19 -0400 (EDT)

branch: master
commit 873cd63ff2a2fc738664065e84a997fe7b4e7051
Author: Pip Cet <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Allow a :stride argument so XBM boolvecs are in the right format.
    
    * src/image.c (xbm_image_p): Explicitly specify the right stride if a
    bool vector is used as argument.
    * doc/lispref/display.texi (XBM Images): Describe bool vectors
    accurately.
    * etc/NEWS: Document the change (bug#36337).
---
 doc/lispref/display.texi | 18 ++++++++++++------
 etc/NEWS                 |  5 +++++
 src/image.c              | 21 +++++++++++++++------
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 3c3ee1f..fd68208 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -5446,12 +5446,14 @@ because omitting them is what indicates the data has 
the format of an
 XBM file.  The file contents specify the height and width of the image.
 
 @item
-A string or a bool-vector containing the bits of the image (plus perhaps
-some extra bits at the end that will not be used).  It should contain at
-least @var{width} * @code{height} bits.  In this case, you must specify
-@code{:height} and @code{:width}, both to indicate that the string
-contains just the bits rather than a whole XBM file, and to specify the
-size of the image.
+A string or a bool-vector containing the bits of the image (plus
+perhaps some extra bits at the end that will not be used).  It should
+contain at least @w{@code{@var{stride} * @var{height}}} bits, where
+@var{stride} is the smallest multiple of 8 greater than or equal to
+the width of the image.  In this case, you should specify
+@code{:height}, @code{:width} and @code{:stride}, both to indicate
+that the string contains just the bits rather than a whole XBM file,
+and to specify the size of the image.
 @end itemize
 
 @item :width @var{width}
@@ -5459,6 +5461,10 @@ The value, @var{width}, specifies the width of the 
image, in pixels.
 
 @item :height @var{height}
 The value, @var{height}, specifies the height of the image, in pixels.
+
+@item :stride @var{stride}
+The number of bool vector entries stored for each row; the smallest
+multiple of 8 greater than or equal to @var{width}.
 @end table
 
 @node XPM Images
diff --git a/etc/NEWS b/etc/NEWS
index 50956f4..3072d40 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2152,6 +2152,11 @@ valid event type.
 ---
 ** The obsolete package xesam.el (since Emacs 24) has been removed.
 
++++
+** The XBM image handler now accepts a ':stride' argument, which should
+be specified in image specs representing the entire bitmap as a single
+bool vector.
+
 
 * Lisp Changes in Emacs 27.1
 
diff --git a/src/image.c b/src/image.c
index d9b7101..06a8154 100644
--- a/src/image.c
+++ b/src/image.c
@@ -3028,6 +3028,7 @@ enum xbm_keyword_index
   XBM_FILE,
   XBM_WIDTH,
   XBM_HEIGHT,
+  XBM_STRIDE,
   XBM_DATA,
   XBM_FOREGROUND,
   XBM_BACKGROUND,
@@ -3049,6 +3050,7 @@ static const struct image_keyword xbm_format[XBM_LAST] =
   {":file",            IMAGE_STRING_VALUE,                     0},
   {":width",           IMAGE_POSITIVE_INTEGER_VALUE,           0},
   {":height",          IMAGE_POSITIVE_INTEGER_VALUE,           0},
+  {":stride",          IMAGE_POSITIVE_INTEGER_VALUE,           0},
   {":data",            IMAGE_DONT_CHECK_VALUE_TYPE,            0},
   {":foreground",      IMAGE_STRING_OR_NIL_VALUE,              0},
   {":background",      IMAGE_STRING_OR_NIL_VALUE,              0},
@@ -3124,7 +3126,7 @@ xbm_image_p (Lisp_Object object)
   else
     {
       Lisp_Object data;
-      int width, height;
+      int width, height, stride;
 
       /* Entries for `:width', `:height' and `:data' must be present.  */
       if (!kw[XBM_WIDTH].count
@@ -3136,6 +3138,11 @@ xbm_image_p (Lisp_Object object)
       width = XFIXNAT (kw[XBM_WIDTH].value);
       height = XFIXNAT (kw[XBM_HEIGHT].value);
 
+      if (!kw[XBM_STRIDE].count)
+       stride = width;
+      else
+       stride = XFIXNAT (kw[XBM_STRIDE].value);
+
       /* Check type of data, and width and height against contents of
         data.  */
       if (VECTORP (data))
@@ -3154,8 +3161,7 @@ xbm_image_p (Lisp_Object object)
 
              if (STRINGP (elt))
                {
-                 if (SCHARS (elt)
-                     < (width + CHAR_BIT - 1) / CHAR_BIT)
+                 if (SCHARS (elt) < stride / CHAR_BIT)
                    return 0;
                }
              else if (BOOL_VECTOR_P (elt))
@@ -3169,13 +3175,16 @@ xbm_image_p (Lisp_Object object)
        }
       else if (STRINGP (data))
        {
-         if (SCHARS (data)
-             < (width + CHAR_BIT - 1) / CHAR_BIT * height)
+         if (SCHARS (data) < stride / CHAR_BIT * height)
            return 0;
        }
       else if (BOOL_VECTOR_P (data))
        {
-         if (bool_vector_size (data) / height < width)
+         if (height > 1 && stride != (width + CHAR_BIT - 1)
+             / CHAR_BIT * CHAR_BIT)
+           return 0;
+
+         if (bool_vector_size (data) / height < stride)
            return 0;
        }
       else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]