@@ -94,6 +94,7 @@ typedef struct {
94
94
int r ; /* Set previous result in this var */
95
95
int d1 ; /* The destination var */
96
96
97
+ int n_const ;
97
98
int n_scanline ;
98
99
99
100
/* The associated line corresponding to the scanline.
@@ -426,6 +427,7 @@ vips_morph_compile_section(VipsMorph *morph, Pass *pass, gboolean first_pass)
426
427
427
428
CONST ("zero" , 0 , 1 );
428
429
CONST ("one" , 255 , 1 );
430
+ pass -> n_const += 2 ;
429
431
430
432
/* Init the sum. If this is the first pass, it's a constant. If this
431
433
* 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)
465
467
*/
466
468
if (x > 0 ) {
467
469
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 ) {
469
471
CONST (offset , morphology -> in -> Bands * x , 1 );
472
+ pass -> n_const ++ ;
473
+ }
470
474
ASM3 ("loadoffb" , "value" , source , offset );
471
475
}
472
476
else
@@ -493,6 +497,12 @@ vips_morph_compile_section(VipsMorph *morph, Pass *pass, gboolean first_pass)
493
497
ASM3 ("andb" , "sum" , "sum" , "value" );
494
498
}
495
499
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
+
496
506
/* You can have 8 sources, and pass->r counts as one of them,
497
507
* so +1 there.
498
508
*/
@@ -553,6 +563,7 @@ vips_morph_compile(VipsMorph *morph)
553
563
pass -> first = i ;
554
564
pass -> last = i ;
555
565
pass -> r = -1 ;
566
+ pass -> n_const = 0 ;
556
567
pass -> n_scanline = 0 ;
557
568
558
569
if (vips_morph_compile_section (morph , pass , morph -> n_pass == 1 ))
0 commit comments