all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Markus Triska <triska@metalevel.at>
Cc: 36337@debbugs.gnu.org
Subject: bug#36337: 26.1; XBM images are sometimes not displayed correctly
Date: Sun, 23 Jun 2019 08:05:55 +0000	[thread overview]
Message-ID: <CAOqdjBdmC4y9EJaqFegN+jbVJ3jLLMyY4ciPe6++Uxk-D6Lb3g@mail.gmail.com> (raw)
In-Reply-To: <m2v9wwvkkt.fsf@metalevel.at>

[-- Attachment #1: Type: text/plain, Size: 1688 bytes --]

The code does indeed assume that it is passed a bool vector which is
padded to a multiple of 8 bits per line, but doesn't verify that the
bool vector it is passed indeed matches this format, so it displays
past the end of the bool vector.

This is easy enough to fix by rewriting the bool vector, but that's
potentially very slow (on debug builds), so maybe we shouldn't do
that?

Does the attached patch work for you?



On Sun, Jun 23, 2019 at 7:16 AM Markus Triska <triska@metalevel.at> wrote:
>
>
> Please start Emacs with "$ emacs -Q", and insert the form:
>
>     (let* ((width 100)
>            (height 100)
>            (data (make-bool-vector (* width height) t)))
>       (insert "\n")
>       (insert-image `(image :type xbm
>                             :data ,data
>                             :width ,width
>                             :height ,height) "t")
>       (insert "\n"))
>
> Please move point to the end of the form, and evaluate it with C-x C-e.
>
> This displays a 100x100 XBM image. However, the bottom of the image is
> not displayed as intended: I see a mix of black and white pixels at the
> bottom of the image, whereas I intend it to be filled with black pixels.
>
> For comparison, it works correctly when I change both width and height
> from 100 to 200, or both to 400, and also for several other values.
>
> In GNU Emacs 26.1 (build 1, x86_64-apple-darwin15.3.0, X toolkit, Xaw scroll bars)
>  of 2018-09-22
> Windowing system distributor 'The X.Org Foundation', version 11.0.11502000
>
> Configured features:
> XPM JPEG TIFF GIF PNG GSETTINGS NOTIFY ACL GNUTLS LIBXML2 FREETYPE XFT
> ZLIB TOOLKIT_SCROLL_BARS LUCID X11 MODULES THREADS LCMS2
>
>
>
>

[-- Attachment #2: 0001-Don-t-assume-the-width-of-xbm-images-is-divisible-by.patch --]
[-- Type: text/x-patch, Size: 1174 bytes --]

From eb46f70db5c79bd3f711e4958b78cbf9ae91bc98 Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Sun, 23 Jun 2019 08:02:18 +0000
Subject: [PATCH] Don't assume the width of xbm images is divisible by 8.

---
 src/image.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/image.c b/src/image.c
index 866323ba6e..7ca6033697 100644
--- a/src/image.c
+++ b/src/image.c
@@ -3814,7 +3814,24 @@ xbm_load (struct frame *f, struct image *img)
 	  else if (STRINGP (data))
 	    bits = SSDATA (data);
 	  else
-	    bits = (char *) bool_vector_data (data);
+	    {
+	      if (img->width & 7)
+		{
+		  int nbytes = (img->width + CHAR_BIT - 1) / CHAR_BIT;
+		  Lisp_Object newdata =
+		    Fmake_bool_vector (make_fixnum (img->height * nbytes * CHAR_BIT), Qnil);
+
+		  for (int y = 0; y < img->height; y++)
+		    {
+		      int i = y * nbytes * CHAR_BIT;
+		      for (int j = y * img->width; j < (y+1) * img->width; i++, j++)
+			bool_vector_set (newdata, i, bool_vector_ref (data, j));
+		    }
+
+		  data = newdata;
+		}
+	      bits = (char *) bool_vector_data (data);
+	    }
 
 #ifdef HAVE_NTGUI
           {
-- 
2.20.1


  reply	other threads:[~2019-06-23  8:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-23  7:15 bug#36337: 26.1; XBM images are sometimes not displayed correctly Markus Triska
2019-06-23  8:05 ` Pip Cet [this message]
2019-06-23  8:22   ` Markus Triska
2019-06-23 14:29   ` Eli Zaretskii
2019-06-23 16:26     ` Pip Cet
2019-06-23 16:40       ` Eli Zaretskii
2019-06-23 19:16         ` Pip Cet
2019-06-28  7:57           ` Eli Zaretskii
2019-06-28  8:29             ` Pip Cet
2019-06-28 12:43               ` Eli Zaretskii
2019-06-29  7:20                 ` Pip Cet
2019-06-29  7:56                   ` Eli Zaretskii
2019-06-29  8:25                     ` Pip Cet
2019-06-29  9:54                       ` Eli Zaretskii
2019-06-30  9:48                         ` Pip Cet
2019-06-30 14:34                           ` Eli Zaretskii
2019-06-30 14:53                             ` Pip Cet
2019-06-30 15:15                               ` Eli Zaretskii
2019-06-30 15:36                                 ` Pip Cet
2019-06-30 16:09                                   ` Eli Zaretskii
2019-06-30 17:12                                     ` Pip Cet
2019-06-30 17:35                                       ` Eli Zaretskii
2019-09-24 16:35                                         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOqdjBdmC4y9EJaqFegN+jbVJ3jLLMyY4ciPe6++Uxk-D6Lb3g@mail.gmail.com \
    --to=pipcet@gmail.com \
    --cc=36337@debbugs.gnu.org \
    --cc=triska@metalevel.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.