out of curiousity I took a look at source of ppmspread from the netpbm package (version 10.66.2) with which I assume the IM version had a common ancestor.
First it only deals with whole pixels, no interpolation or virtual pixels. Which were never normal features of the NetPBM package.
Psuedo Code....
Code: Select all
For each pixel P, selects a random location nearby N
If N is outside image proper (a virtual pixel location) It just copies src P to dest P
Otherwise... and this is a ltlle strange.
it copies src P into dest N
then copies src N into dest P
Now as it only reads from the source image, you cannot get a double swap.
now if N is behind the current P's location the two pixels effectively get swapped,
but at the code of destorying whatever value was already saved into N
But if N is ahead of the current P's location the pixel in N will always be replaced with a new pixel.
This seems different to just the simple single 'random pick' from destination ImageMagick's origina spread function is doing, but it still losses information.
The PPM source code also says it is 'pixel swapping' though obviously that is not actually the case.
For example.. I create a 3x3 pixel image, with unique numbers 1 to 9, the use ppmspread 1
Confirmation....
Code: Select all
echo P2 3 3 9 1 2 3 4 5 6 7 8 9 | ppmspread 1 | ppmtopgm | pnmdepth 9 | pnmtopnm -plain
P2
3 3
9
2 6 3
4 2 2
8 9 8
As you can see in this run we lost pixel's 1, 5, and 7. replace by two duplicates of pixel 2 and one of pixel 8
However IM using the new method (even with the directional bias cause by double-swapping) does indeed preserve
the pixel data without loss/duplication.
Code: Select all
echo P2 3 3 9 1 2 3 4 5 6 7 8 9 | magick - -spread 1 pgm:- | pnmdepth 9 | pnmtopnm -plain
P2
3 3
9
3 6 4
7 1 5
2 9 8