Skip to content

insert_image wrongly caches images when the mask is different, but image stream is the same as previous insert #1053

@MerlijnWajer

Description

@MerlijnWajer

Describe the bug (mandatory)

page.insert_image(..., stream=foo, mask=bar) seems to cache the results even if the mask is different (at a second insert).
This is evident from the example below, where the two pages should contain different images, but they actually do not.

The cache being to blame is entirely a guess on my side.

To Reproduce (mandatory)

import fitz

doc = fitz.open()


page = doc.new_page()
bg_contents = open('bgdiubkcdl.jp2', 'rb').read()
fg_contents = open('fgzvps8nir.jp2', 'rb').read()
mask_contents = open('mask8hq8yr37.png', 'rb').read()
page.insert_image(page.rect, stream=bg_contents, mask=None,
        overlay=False)
page.insert_image(page.rect, stream=fg_contents, mask=mask_contents,
        overlay=True)

page = doc.new_page()
bg_contents = open('bgoewrpg8w.jp2', 'rb').read()
fg_contents = open('fgio4gli63.jp2', 'rb').read()
mask_contents = open('maskk7dbuux0.png', 'rb').read()
page.insert_image(page.rect, stream=bg_contents, mask=None,
        overlay=False)
page.insert_image(page.rect, stream=fg_contents, mask=mask_contents,
        overlay=True)

doc.save('/tmp/bug.pdf')

Image for the above script are here: https://archive.org/~merlijn/pymupdf-insert-cache/

Expected behavior (optional)

The pages should have different images.

Screenshots (optional)

See PDF here:

https://archive.org/~merlijn/pymupdf-insert-cache/bug.pdf

If applicable, add screenshots to help explain your problem.

Your configuration (mandatory)

>>> print(sys.version, "\n", sys.platform, "\n", fitz.__doc__)
3.8.9 (default, May 16 2021, 12:11:24)
[GCC 9.2.0]
 linux

PyMuPDF 1.18.13: Python bindings for the MuPDF 1.18.0 library.
Version date: 2021-05-05 06:32:22.
Built for Python 3.8 on linux (64-bit).


## Additional context (optional)

Initially found by figuring out why this PDF exhibits the problem: https://archive.org/download/tbl105kRnd/tbl105kRnd.pdf

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions