I should explain that this is not a very well written script. I just did a brute-force transcription of the steps you described. If I were to write it as a "published" script, I would do things a bit different.
Nonetheless, I will address a few of your suppositions; just don't be too concerned if it doesn't make much sense.
PegLeg44 wrote:
(set! nb-levels (truncate nb-levels)) brings up the dialog box.
No, the dialog box is a result of the SF-ADJUSTMENT line at the end of the script. This line corrects a bug in GIMP that results in fractional values being supplied by a SF-ADJUSTMENT slider even if it is configured to supply integers. Since I switched from a slider widget to a numeric entry with UP/DOWN arrows, this line isn't even needed.
PegLeg44 wrote:
(let ((levels (let loop ((count (- nb-levels 1))
(result '(0)) )
(if (zero? count)
(cdr (reverse result))
(loop (- count 1)
(cons (+ (/ 256 nb-levels)
(car result) )
result ))))))
This code says figure out the iterations by the number set in the dialog.
Correct. It starts with "0" and adds the appropriate increment amount each time through the loop; creating a list in reverse order (it is common to add new items to the beginning of a list so that you don't have to "walk through" the entire list to find its end each time you add an item). When 'count' reaches zero, we reverse the list and strip the initial "0" (there is no need to dilate the original layer by "0").
--------------------------------------------------------------
PegLeg44 wrote:
(let loop ((iterations (- nb-levels 1))
(layers (list drawable)) )
(if (zero? iterations)
(map (lambda (layer low-output high-input)
(gimp-levels layer HISTOGRAM-VALUE 0 high-input 1.0 low-output 255) )
(cdr (reverse layers))
levels
(reverse levels) )
This tells the layers to change levels when called upon.
Yes. It would probably make more sense to calculate the high- and low-input for each level, rather than using the 'levels' list; but I'd already had a function to generate the correct levels available.
PegLeg44 wrote:
I'm going to play around with the all directions for the propogate and see if I can make it do this in various directions. I think there are 0 through 15 directrions to try.
Whether to propagate in each of the four directions is controlled by a binary digit in a 4-bit number. The weights of these digits are as follows:
Right->Left = 1
Bottom->Top = 2
Left->Right = 4
Top->Bottom = 8
The value of the argument should be the sum of the weights corresponding to the directions you want to propagate. For example, propagating vertically (bottom->top and top->bottom) would require an argument of 2+8, or "10". Propagating in all four directions requires 1+2+4+8, or "15".