1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // paeth implements the Paeth filter function, as per the PNG specification.
8 func paeth(a
, b
, c
uint8) uint8 {
9 // This is an optimized version of the sample code in the PNG spec.
10 // For example, the sample code starts with:
11 // p := int(a) + int(b) - int(c)
12 // pa := abs(p - int(a))
13 // but the optimized form uses fewer arithmetic operations:
14 // pa := int(b) - int(c)
29 if pa
<= pb
&& pa
<= pc
{
37 // filterPaeth applies the Paeth filter to the cdat slice.
38 // cdat is the current row's data, pdat is the previous row's data.
39 func filterPaeth(cdat
, pdat
[]byte, bytesPerPixel
int) {
40 var a
, b
, c
, pa
, pb
, pc
int
41 for i
:= 0; i
< bytesPerPixel
; i
++ {
43 for j
:= i
; j
< len(cdat
); j
+= bytesPerPixel
{
57 if pa
<= pb
&& pa
<= pc
{