Untested. Here is a framework. It's not pretty, but this
computation is just not parallelizable.
NB. convert to array, reverse, add bottom/right 0
array =. ({.~ >:@$);.0 (height, width) $ pixels
NB. y is 2x2 of (unused,above),:(left,upper-left)
NB. Result is Paeth predictor
paeth =. ({~ (i. <./)@:|@:(- +`-/))@:(}.@,)
NB. y is 2x2 of (new pixel diff,above),:(left,upper-left)
NB. Result is (new pixel total,next upper-left (same as input 'above')
pixels2x2 =. ({. + 2 {. 256 | paeth)
NB. y is is a pair of scanlines (current,above)
NB. transpose, then decompress on each 2x2 producing a table of
NB. (uncompressed value,above). Discard the above part, leaving a list
scanlinepair =. 0 {"1 pixels2x2/\.@|:
NB. Operate on each scanline-pair; reverse and remove added row/col
xformimage =. 1 1&}.;.0 scanlinepair/\. array
Henry Rich
On 9/1/2014 1:44 AM, bill lam wrote:
Context for discussion, section 6.6 of this png rfc
* http://tools.ietf.org/html/rfc2083
The forward filter seems trivial, but the backward filter seems
tricky to me if not using loop. Any idea on a loop free
solution?
NB. Paeth Predictor
paeth=: 3 : 0
p=. +/ 1 1 _1 * y
y{~ (i.<./) |p-y
)
forward=: 4 : 0
prev=. 10$ 3 5 8
iy=. i.10
pae=. 256&| iy - paeth"1 ((-x)}.(x#0),iy),.prev,.((-x)}.(x#0),prev)
)
3 forward''
253 252 250 3 3 3 3 3 3 3
4 forward''
253 252 250 0 1 0 4 2 0 6
NB. backward ??
NB. 4 backward 4 forward ''
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm