Public bug reported:
evince renders all PostScript/EPS documents blank: PS backend's
CAIRO_FORMAT_RGB24 surface is uploaded as B8G8R8A8 with alpha = 0
Every EPS document opens as a completely blank page in Evince on
Ubuntu 26.04. PDF documents are unaffected. This makes Evince unusable for EPS.
[Package versions]
evince 49~alpha-2ubuntu2.1
libspectre1 0.2.12-2
libgtk-4-1 4.22.4+ds-0ubuntu0.1
ghostscript 10.06.0~dfsg-3ubuntu1
Ubuntu 26.04.1 LTS, amd64
[Steps to reproduce]
1. Create a minimal EPS file:
cat > minimal.eps <<'EOF'
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 200 200
%%EndComments
newpath 20 20 moveto 180 20 lineto 180 180 lineto 20 180 lineto closepath
4 setlinewidth stroke
/Helvetica findfont 24 scalefont setfont
40 100 moveto (HELLO PS) show
showpage
%%EOF
EOF
2. evince minimal.eps
[Expected]
A square outline and the text "HELLO PS".
[Actual]
A blank white page. The page count, the page size and the thumbnail geometry are
all correct, so the document is parsed correctly -- only the pixels are missing.
Measuring the rendered pixels shows the content is not absent but almost fully
transparent: strokes that should be RGB(0,0,0) come out at RGB(250,250,251),
i.e. roughly 2% opacity. Only the anti-aliasing fringe survives.
[Root cause]
backend/ps/ev-spectre.c:ps_document_render() wraps the buffer returned by
libspectre in a CAIRO_FORMAT_RGB24 surface:
spectre_page_render (ps_page, src, &data, &stride);
...
surface = cairo_image_surface_create_for_data (data,
CAIRO_FORMAT_RGB24,
width, height, stride);
For CAIRO_FORMAT_RGB24 cairo defines the upper 8 bits of each 32-bit pixel as
unused, and libspectre leaves that byte at 0. I verified this directly by
calling spectre_page_render() from a small test program: for a 544x767 page,
all 417248 pixels have byte 3 == 0.
However evince's gdk_texture_new_for_surface() helper ignores the cairo format
and always uploads the buffer with GDK_MEMORY_DEFAULT, which is
GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
libview/ev-jobs.c:786
libview/ev-pixbuf-cache.c:271
libview/ev-view.c:5144
shell/ev-sidebar-thumbnails.c:600
so that unused byte is read as alpha. With alpha = 0 the entire page becomes
transparent.
PDF is unaffected because poppler renders into ARGB32 surfaces with alpha=0xff.
The PS backend is the only one shipping an RGB24 surface to that helper.
[Confirmation that the file, Ghostscript and libspectre are not at
fault]
* gs -q -dNOPAUSE -dBATCH -sDEVICE=png16m -o out.png minimal.eps
renders the file correctly.
* A small program calling spectre_page_render() directly and dumping the
buffer renders it correctly.
* ImageMagick's `display minimal.eps` renders it correctly.
* An LD_PRELOAD shim that does nothing but set byte 3 of every pixel to 0xff
after spectre_page_render() returns makes Evince render the document
correctly. This confirms the diagnosis.
[Fix]
The attached patch (ps-backend-opaque-alpha.patch) fills the unused byte with
0xff in ps_document_render(), so the surface is opaque regardless of how the
consumer interprets it. This is the minimal fix and touches only the PS backend.
A more general fix would be to make gdk_texture_new_for_surface() honour
cairo_image_surface_get_format() and select GDK_MEMORY_B8G8R8X8 for
CAIRO_FORMAT_RGB24 surfaces; that would require the same change in the four
copies of the helper listed above.
I rebuilt libpsdocument.so from the 49~alpha-2ubuntu2.1 source with this patch
and confirmed that PostScript and EPS documents then render correctly. The
rebuilt backend has the same exported symbols and the same NEEDED entries as the
shipped one. Testing without touching the system is possible via
EV_BACKENDS_DIR.
[Workarounds]
* Convert to PDF first (ps2pdf / epspdf) and open the PDF.
* Use ImageMagick's `display`.
(gv is also blank on this system, but that appears to be an unrelated problem
with ghostscript's x11 device.)
** Affects: evince (Ubuntu)
Importance: Undecided
Status: New
** Patch added: "ps-backend-opaque-alpha.patch"
https://bugs.launchpad.net/bugs/2166640/+attachment/5998156/+files/ps-backend-opaque-alpha.patch
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2166640
Title:
evince renders all EPS documents blank
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/evince/+bug/2166640/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs