Skip to content

Commit 516fee5

Browse files
authored
morph: fix Orc path with large masks (#4365)
Resolves: #4363.
1 parent 3848af5 commit 516fee5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- tiffsave: honor disc threshold during pyramid save [kleisauke]
1919
- fill_nearest: fix a leak
2020
- colour: use suggested rendering intent as fallback [kleisauke]
21+
- morph: fix Orc path with large masks [kleisauke]
2122

2223
10/10/24 8.16.0
2324

libvips/morphology/morph.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ typedef struct {
9494
int r; /* Set previous result in this var */
9595
int d1; /* The destination var */
9696

97+
int n_const;
9798
int n_scanline;
9899

99100
/* The associated line corresponding to the scanline.
@@ -426,6 +427,7 @@ vips_morph_compile_section(VipsMorph *morph, Pass *pass, gboolean first_pass)
426427

427428
CONST("zero", 0, 1);
428429
CONST("one", 255, 1);
430+
pass->n_const += 2;
429431

430432
/* Init the sum. If this is the first pass, it's a constant. If this
431433
* is a later pass, we have to init the sum from the result
@@ -465,8 +467,10 @@ vips_morph_compile_section(VipsMorph *morph, Pass *pass, gboolean first_pass)
465467
*/
466468
if (x > 0) {
467469
g_snprintf(offset, 256, "c%db", x);
468-
if (orc_program_find_var_by_name(p, offset) == -1)
470+
if (orc_program_find_var_by_name(p, offset) == -1) {
469471
CONST(offset, morphology->in->Bands * x, 1);
472+
pass->n_const++;
473+
}
470474
ASM3("loadoffb", "value", source, offset);
471475
}
472476
else
@@ -493,6 +497,12 @@ vips_morph_compile_section(VipsMorph *morph, Pass *pass, gboolean first_pass)
493497
ASM3("andb", "sum", "sum", "value");
494498
}
495499

500+
/* orc allows up to 8 constants, so break early once we
501+
* approach this limit.
502+
*/
503+
if (pass->n_const >= 7 /*ORC_MAX_CONST_VARS - 1*/)
504+
break;
505+
496506
/* You can have 8 sources, and pass->r counts as one of them,
497507
* so +1 there.
498508
*/
@@ -553,6 +563,7 @@ vips_morph_compile(VipsMorph *morph)
553563
pass->first = i;
554564
pass->last = i;
555565
pass->r = -1;
566+
pass->n_const = 0;
556567
pass->n_scanline = 0;
557568

558569
if (vips_morph_compile_section(morph, pass, morph->n_pass == 1))

0 commit comments

Comments
 (0)