Are there any GIMP functions to detect whether a selection is purely rectangular (as opposed to round, rounded, feathered, non-contiguous, etc.)?
I mean something relatively simple, not involving iterating through every pixel in the selection bounds.
Alternative using channels
Nice!
Solution to determining if a selection is rectangular
(let* ( (bounds (gimp-selection-bounds 1)) (area (cadddr (gimp-histogram 2 HISTOGRAM-VALUE 0 256))) ) (= (* (- (list-ref bounds 3) (list-ref bounds 1)) (- (list-ref bounds 4) (list-ref bounds 2))) area) )-Rob A>Works for some definitions of rectangle
- No selection:
- Background: no mask (correct)
- Non-transparent layer: no mask (correct)
- Transparent layer: no mask (correct)
- Rectangular selection:
- Background: no mask (correct)
- Non-transparent layer: no mask (correct)
- Transparent layer: mask (incorrect but harmless)
- Rectangular selection inverted:
- Background: mask (correct)
- Non-transparent layer: mask (correct)
- Transparent layer: mask (correct)
- Rectangular selection feathered:
- Background: mask if feathered 1 pixel or more (correct enough)
- Non-transparent layer: mask if feathered 1 pixel or more (correct enough)
- Transparent layer: mask if feathered at all (correct)
- Rectangular selection with pixel punched out:
- Background: mask (correct)
- Non-transparent layer: mask (correct)
- Transparent layer: mask (correct)
- Rectangular selection with internal pixel faded:
- Background: mask (correct down to even 1% opacity for the faded pixel; sweet!)
- Non-transparent layer: mask (correct down to even 1% opacity for the faded pixel; sweet!)
- Transparent layer: mask (correct down to even 1% opacity for the faded pixel; sweet!)
- Oval selection:
- Background: mask (correct)
- Non-transparent layer: mask (correct)
- Transparent layer: mask (correct)
so I'll probably use this because the code is simpler, although it is helpful to know the other method as well.