Skip to content

Commit ef10dde

Browse files
src/: fix test_4254() valgrind failure.
We use new extra.pixmap_copy(), a fixed version of mupdf.ll_fz_pixmap_copy().
1 parent 82e1167 commit ef10dde

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

src/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9870,10 +9870,9 @@ def __init__(self, *args):
98709870

98719871
# copy samples data ------------------------------------------
98729872
if 1:
9873-
# We use specially-provided (by MuPDF Python bindings)
9874-
# ll_fz_pixmap_copy() to get best performance.
9873+
# We use our pixmap_copy() to get best performance.
98759874
# test_pixmap.py:test_setalpha(): 3.9s t=0.0062
9876-
mupdf.ll_fz_pixmap_copy( pm.m_internal, src_pix.m_internal, n)
9875+
extra.pixmap_copy( pm.m_internal, src_pix.m_internal, n)
98779876
elif 1:
98789877
# Use memoryview.
98799878
# test_pixmap.py:test_setalpha(): 4.6 t=0.51

src/extra.i

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4039,6 +4039,58 @@ no_more_matches:;
40394039
return quads;
40404040
}
40414041

4042+
void pixmap_copy( fz_pixmap* pm, const fz_pixmap* src, int n)
4043+
{
4044+
assert( pm->w == src->w);
4045+
assert( pm->h == src->h);
4046+
assert( n <= pm->n);
4047+
assert( n <= src->n);
4048+
4049+
if (pm->n == src->n)
4050+
{
4051+
// identical samples
4052+
assert( pm->stride == src->stride);
4053+
memcpy( pm->samples, src->samples, pm->w * pm->h * pm->n);
4054+
}
4055+
else
4056+
{
4057+
int nn;
4058+
int do_alpha;
4059+
if (pm->n > src->n)
4060+
{
4061+
assert(pm->n == src->n + 1);
4062+
nn = src->n;
4063+
assert(!src->alpha);
4064+
assert(pm->alpha);
4065+
do_alpha = 1;
4066+
}
4067+
else
4068+
{
4069+
assert(src->n == pm->n + 1);
4070+
nn = pm->n;
4071+
assert(src->alpha);
4072+
assert(!pm->alpha);
4073+
do_alpha = 0;
4074+
}
4075+
for ( int y=0; y<pm->h; ++y)
4076+
{
4077+
for ( int x=0; x<pm->w; ++x)
4078+
{
4079+
memcpy(
4080+
pm->samples + pm->stride * y + pm->n * x,
4081+
src->samples + src->stride * y + src->n * x,
4082+
nn
4083+
);
4084+
if (do_alpha)
4085+
{
4086+
pm->samples[pm->stride * y + pm->n * x + pm->n-1] = 255;
4087+
}
4088+
}
4089+
}
4090+
}
4091+
}
4092+
4093+
40424094
%}
40434095

40444096
/* Declarations for functions defined above. */
@@ -4162,3 +4214,9 @@ int pixmap_n(mupdf::FzPixmap& pixmap);
41624214
PyObject* JM_search_stext_page(fz_stext_page *page, const char *needle);
41634215

41644216
PyObject *set_pixel(fz_pixmap* pm, int x, int y, PyObject *color);
4217+
4218+
/* Copies from <src> to <pm>, which must have same width and height. pm->n -
4219+
src->n must be -1, 0 or +1. If -1, <src> must have alpha and <pm> must not have
4220+
alpha, and we copy the non-alpha bytes. If +1 <src> must not have alpha and
4221+
<pm> must have alpha and we set <pm>'s alpha bytes all to 255.*/
4222+
void pixmap_copy(fz_pixmap* pm, const fz_pixmap* src, int n);

0 commit comments

Comments
 (0)