Skip to content

Commit 5cbeb2a

Browse files
committed
Replace pixmap color inversion logic
We currently use our own code for this - which is erroneous and also is very slow (written in Python). This fix falls back to using MuPDF native functions fz_invert_pixmap and fz_invert_pixmap_rect. This obsoletes function "JM_invert_pixmap_rect" and significantly improves speed.
1 parent 15149a9 commit 5cbeb2a

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

src/__init__.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10185,8 +10185,10 @@ def invert_irect(self, bbox=None):
1018510185
return False
1018610186
r = JM_irect_from_py(bbox)
1018710187
if mupdf.fz_is_infinite_irect(r):
10188-
r = mupdf.fz_pixmap_bbox( pm)
10189-
return bool(JM_invert_pixmap_rect( pm, r))
10188+
mupdf.fz_invert_pixmap(pm)
10189+
return True
10190+
mupdf.fz_invert_pixmap_rect(pm, r)
10191+
return True
1019010192

1019110193
@property
1019210194
def irect(self):
@@ -16282,42 +16284,6 @@ def JM_insert_font(pdf, bfname, fontfile, fontbuffer, set_simple, idx, wmode, se
1628216284
]
1628316285
return value
1628416286

16285-
16286-
def JM_invert_pixmap_rect( dest, b):
16287-
'''
16288-
invert a rectangle - also supports non-alpha pixmaps
16289-
'''
16290-
assert isinstance( dest, mupdf.FzPixmap)
16291-
assert isinstance( b, mupdf.FzIrect)
16292-
b = mupdf.fz_intersect_irect(b, mupdf.fz_pixmap_bbox( dest))
16293-
w = b.x1 - b.x0
16294-
y = b.y1 - b.y0
16295-
if w <= 0 or y <= 0:
16296-
return 0
16297-
16298-
destspan = dest.stride()
16299-
destp = destspan * (b.y0 - dest.y()) + dest.n() * (b.x0 - dest.x())
16300-
n0 = dest.n() - dest.alpha()
16301-
alpha = dest.alpha()
16302-
while 1:
16303-
s = destp
16304-
for x in range( w):
16305-
for i in range( n0):
16306-
ss = mupdf.fz_samples_get( dest, s)
16307-
ss = 255 - ss
16308-
mupdf.fz_samples_set( dest, s, ss)
16309-
s += 1
16310-
if alpha:
16311-
ss = mupdf.fz_samples_get( dest, s)
16312-
ss += 1
16313-
mupdf.fz_samples_set( dest, s, ss)
16314-
destp += destspan
16315-
y -= 1
16316-
if y == 0:
16317-
break
16318-
return 1
16319-
16320-
1632116287
def JM_irect_from_py(r):
1632216288
'''
1632316289
PySequence to mupdf.FzIrect. Default: infinite irect

0 commit comments

Comments
 (0)