_fx_slice_luminosity argument bug

There is a mis-specified argument in the implementation _fx_slice_luminosity affecting the creation of a mask for the second luminosity band. This affects the behavior of the Slice Luminosity filter in gmic_qt.

When I execute the underlying implementation:

   -input 256,16,1,1,255*x/(w-1)
   -_fx_slice_luminosity 1,1,2,1,20,30,0,0,1,60,70,0,0,1,100,120,0,0,1,230,240,0,0

In words: creating masks to select pixels in the luminosity bands (20,30), (60,70), (100,120), and (230,240) (none feathered: (0,0) for all masks) should generate a mask for a ramp that looks something like this:
db_0
Instead a mask like this appears:
db_1

In the implementation, the argument to select parameters for the second band mask ($9) appears to have been used instead of the argument that sets the upper limit of the second luminosity band ($11) See patch:

# commit 23958ff73bf04 (HEAD -> develop)
# Tue Jul 9 08:56:03 2024 +0200
#
diff --git a/src/gmic_stdlib.gmic b/src/gmic_stdlib.gmic
index 3078d7f..e5bbfb7 100644
--- a/src/gmic_stdlib.gmic
+++ b/src/gmic_stdlib.gmic
@@ -55358,7 +55358,7 @@ _fx_slice_luminosity :
   else +compose_channels max
   fi
   if $4 +apply_curve[1] 0,{$5-$7-0.1},0,$5,255,$6,255,{$6+$8+0.1},0,512,0 fi
-  if $9 +apply_curve[1] 0,{$10-$12-0.1},0,$10,255,$9,255,{$11+$13+0.1},0,512,0 fi
+  if $9 +apply_curve[1] 0,{$10-$12-0.1},0,$10,255,$11,255,{$11+$13+0.1},0,512,0 fi
   if $14 +apply_curve[1] 0,{$15-$17-0.1},0,$15,255,$16,255,{$16+$18+0.1},0,512,0 fi
   if $19 +apply_curve[1] 0,{$20-$22-0.1},0,$20,255,$21,255,{$21+$23+0.1},0,512,0 fi
   rm[1] max[^0]

a repair which gives rise to the expected mask.

This was found whilst investigating a question about Slice Luminosity posed by @PixLab , so that worthy should receive the fabulously munificent Bug Bounty that GreyC Labs awards.

Shouldn’t spend it in one place, though.

2 Likes

I had no idea that I did find this bug :joy:

You did a nice find @grosgood and… You already wrote a patch! That’s Impressive! :clap: