Skip to content

Commit

Permalink
src/ tests/: allow construction of Pixmap from Pixmap with colorspace…
Browse files Browse the repository at this point in the history
…=None.

This addresses #3177.
  • Loading branch information
julian-smith-artifex-com committed Feb 18, 2024
1 parent 06bfc11 commit 9fce454
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9463,11 +9463,13 @@ def __init__(self, *args):
pm = mupdf.fz_new_pixmap_with_bbox(cs, JM_irect_from_py(rect), mupdf.FzSeparations(0), alpha)
self.this = pm

elif args_match(args, (Colorspace, mupdf.FzColorspace), (Pixmap, mupdf.FzPixmap)):
elif args_match(args, (Colorspace, mupdf.FzColorspace, type(None)), (Pixmap, mupdf.FzPixmap)):
# copy pixmap, converting colorspace
cs, spix = args
if isinstance(cs, Colorspace):
cs = cs.this
elif cs is None:
cs = mupdf.FzColorspace(None)
if isinstance(spix, Pixmap):
spix = spix.this
if not mupdf.fz_pixmap_colorspace(spix).m_internal:
Expand Down Expand Up @@ -17965,7 +17967,8 @@ def args_match(args, *types):
Returns true if <args> matches <types>.

Each item in <types> is a type or tuple of types. Any of these types will
match an item in <args>. None will match anything in <args>.
match an item in <args>. `None` will match anything in <args>. `type(None)`
will match an arg whose value is `None`.
'''
j = 0
for i in range(len(types)):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_pixmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,7 @@ def test_3134():
print(f'{stat_irect=}')
assert stat_rect.st_size == stat_irect.st_size

def test_3177():
path = os.path.abspath(f'{__file__}/../../tests/resources/img-transparent.png')
pixmap = fitz.Pixmap(path)
pixmap2 = fitz.Pixmap(None, pixmap)

0 comments on commit 9fce454

Please sign in to comment.