Skip to content

Commit 621d26e

Browse files
Fix fitz.Pixmap contruction and .yres().
* Fix fitz.Pixmap construction from (Colorspace, Pixmap). * Fix fitz.Pixmap construction from (Pixmap, Pixmap). * Fix fitz.Pixmap construction from ('raw', Pixmap). * Fix Pixmap.yres()
1 parent dfea000 commit 621d26e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/__init__.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -9407,9 +9407,13 @@ def __init__(self, *args):
94079407
pm = mupdf.fz_new_pixmap_with_bbox(cs, JM_irect_from_py(rect), mupdf.FzSeparations(0), alpha)
94089408
self.this = pm
94099409

9410-
elif args_match(args, mupdf.FzColorspace, mupdf.FzPixmap):
9410+
elif args_match(args, (Colorspace, mupdf.FzColorspace), (Pixmap, mupdf.FzPixmap)):
94119411
# copy pixmap, converting colorspace
94129412
cs, spix = args
9413+
if isinstance(cs, Colorspace):
9414+
cs = cs.this
9415+
if isinstance(spix, Pixmap):
9416+
spix = spix.this
94139417
if not mupdf.fz_pixmap_colorspace(spix).m_internal:
94149418
raise ValueError( "source colorspace must not be None")
94159419

@@ -9427,9 +9431,13 @@ def __init__(self, *args):
94279431
if not self.this.m_internal:
94289432
raise RuntimeError( MSG_PIX_NOALPHA)
94299433

9430-
elif args_match(args, mupdf.FzPixmap, mupdf.FzPixmap):
9434+
elif args_match(args, (Pixmap, mupdf.FzPixmap), (Pixmap, mupdf.FzPixmap)):
94319435
# add mask to a pixmap w/o alpha channel
94329436
spix, mpix = args
9437+
if isinstance(spix, Pixmap):
9438+
spix = spix.this
9439+
if isinstance(mpix, Pixmap):
9440+
mpix = mpix.this
94339441
spm = spix
94349442
mpm = mpix
94359443
if not spix.m_internal: # intercept NULL for spix: make alpha only pix
@@ -9438,7 +9446,7 @@ def __init__(self, *args):
94389446
raise RuntimeError( MSG_PIX_NOALPHA)
94399447
else:
94409448
dst = mupdf.fz_new_pixmap_from_color_and_mask( spm, mpm)
9441-
return dst
9449+
self.this = dst
94429450

94439451
elif args_match(args, (Pixmap, mupdf.FzPixmap), (float, int), (float, int), None):
94449452
# create pixmap as scaled copy of another one
@@ -9453,9 +9461,11 @@ def __init__(self, *args):
94539461
pm = mupdf.fz_scale_pixmap(src_pix, src_pix.x(), src_pix.y(), w, h, mupdf.FzIrect(mupdf.fz_infinite_irect))
94549462
self.this = pm
94559463

9456-
elif args_match(args, str, mupdf.FzPixmap) and args[0] == 'raw':
9464+
elif args_match(args, str, (Pixmap, mupdf.FzPixmap)) and args[0] == 'raw':
94579465
# Special raw construction where we set .this directly.
94589466
_, pm = args
9467+
if isinstance(pm, Pixmap):
9468+
pm = pm.this
94599469
self.this = pm
94609470

94619471
elif args_match(args, (Pixmap, mupdf.FzPixmap), (int, None)):
@@ -10190,7 +10200,7 @@ def y(self):
1019010200
@property
1019110201
def yres(self):
1019210202
"""Resolution in y direction."""
10193-
return mupdf.fz_pixmap_width(self.this)
10203+
return self.this.yres()
1019410204

1019510205
width = w
1019610206
height = h

tests/test_pixmap.py

+2
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,5 @@ def test_fz_write_pixmap_as_jpeg():
150150
def test_3020():
151151
pm = fitz.Pixmap(imgfile)
152152
pm2 = fitz.Pixmap(pm, 20, 30, None)
153+
pm3 = fitz.Pixmap(fitz.csGRAY, pm)
154+
pm4 = fitz.Pixmap(pm, pm3)

0 commit comments

Comments
 (0)