Subject: 27.1; insert-image sometimes unexpectedly truncates images

From: Markus Triska <[email-masked]>
Date: Sat, 12 Feb 2022 11:12:37 +0100

To reproduce this issue, please start Emacs with:

    $ emacs -Q

and insert the following forms in the *scratch* buffer:

    (defun insert-bar (width)
      (let* ((height 5)
             (data (with-temp-buffer
                     (insert (format "P1\n%s %s\n" width height))
                     (dotimes (_ height)
                       (insert (make-string width ?1) "\n"))
                     (buffer-string))))
        (insert-image `(image :type pbm :data ,data)) "t"))

    (progn
      (insert "\n")
      (dotimes (_ 3)
        (insert-bar (/ (window-pixel-width) 3))
        (insert "         ")))

Then evaluate the forms with M-x eval-buffer RET.

The code is meant to insert 3 bars of equal length, each 1/3 of the
window size in pixels.

Unexpectedly, the rightmost bar is much shorter than the other two bars.

I say "unexpectedly", because the documentation of insert-image (which
is used to insert the image by the forms above) states:

    "If SLICE is ‘nil’ or omitted the whole image is inserted."

Yet, even though SLICE is omitted in the forms above, the whole image is
apparently not inserted, only a smaller slice is inserted.

If possible, I would like to insert the entire image no matter where it
appears in the buffer, even if scrolling is necessary to reveal
remaining parts. Is there a way to do this?

Thank you a lot!
Markus

In GNU Emacs 27.1 (build 1, x86_64-apple-darwin15.3.0, X toolkit, Xaw scroll bars)
 of 2020-12-12 built on mt-macbook
Windowing system distributor 'The X.Org Foundation', version 11.0.11502000
System Description:  Mac OS X 10.11.3

Configured using:
 'configure --prefix=/opt/local --disable-silent-rules --without-ns
 --without-dbus --without-gconf --without-libotf --without-m17n-flt
 --with-gmp --with-gnutls --with-json --with-xml2 --with-modules
 --infodir /opt/local/share/info/emacs --with-x-toolkit=lucid
 --without-xaw3d --without-imagemagick --with-xpm --with-jpeg
 --with-tiff --with-gif --with-png --with-lcms2 --without-rsvg
 --with-xft 'CFLAGS=-pipe -Os -arch x86_64'
 CPPFLAGS=-I/opt/local/include 'LDFLAGS=-L/opt/local/lib
 -Wl,-headerpad_max_install_names -lfreetype -lfontconfig -Wl,-no_pie
 -arch x86_64''

Configured features:
XPM JPEG TIFF GIF PNG GSETTINGS GLIB NOTIFY KQUEUE ACL GNUTLS LIBXML2
FREETYPE HARFBUZZ XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM
MODULES THREADS JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix