Right. So this is the way to get the original from the forward filter. If it works.

Henry Rich

On 9/1/2014 9:48 PM, bill lam wrote:
Sorry, I might use the wrong terminology. I meant the filter
that would give the original data from the output of the
forward filter, ie

data <--> m&backwad m&forward data

forward: (encode):

Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))


backward (decode, back-feed, inverse, reverse):

Raw(x) = Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))

(value for element with negative index assumed 0)

You can see there are raw(..) in both side of the equation for
backward. Iteration or recursion seems needed and that is the reason
why I asked the question.

Пн, 01 сен 2014, Henry Rich написал(а):
backward.  'paeth' is the paeth filter, which could be forward or backward,
depending on use.  Backward was what you wanted, no?

Henry Rich

On 9/1/2014 9:09 PM, bill lam wrote:
Just want to confirm, is you code for forward or backward
filter?

Пн, 01 сен 2014, Henry Rich написал(а):
Well, I said it was untested.  It's just the framework.  Here's a version
that at least produces a result:


y =. i. 5 10
'height width'=: $y
pixels=: ,y
NB. convert to array, reverse, add bottom/right 0
array =: ({.~ >:@$);.0 (height, width) $ pixels

NB. x is unused,above), y is left,upper-left
NB. Result is Paeth predictor
paeth =: (({~   (i. <./)@:|@:(- +`-/)))@:(}.@,)
NB. x is unused,above), y is left,upper-left
NB. Result is (new pixel total,next upper-left (same as input 'above')
pixels2x2 =: (256 | [ + 2 {. 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


To support bpp you would need to keep an nx2 instead of a 2x2 history. Ecch.

Henry Rich

On 9/1/2014 11:04 AM, bill lam wrote:
I assume your code is for backward filter (from paeth to raw).
I tried with test data: y =. i. 5 10
'height width'=. $y
pixels=. ,y

but it ran into error
|index error: scanlinepair
|   xformimage=.1 1&}.;.0     scanlinepair/\.array

Also the bpp meant comparison with bpp byte apart. this bpp can
be 1 to 7 depending on pixel format. so that each of the current
and above line can be reshaped or partition before processing
the 2x2 blocks.


Пн, 01 сен 2014, Henry Rich написал(а):
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

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to