// Copyright 2012 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package png// intSize is either 32 or 64.const intSize = 32 << (^uint(0) >> 63)func abs( int) int {// m := -1 if x < 0. m := 0 otherwise. := >> (intSize - 1)// In two's complement representation, the negative number // of any number (except the smallest one) can be computed // by flipping all the bits and add 1. This is faster than // code with a branch. // See Hacker's Delight, section 2-4.return ( ^ ) - }// paeth implements the Paeth filter function, as per the PNG specification.func paeth(, , uint8) uint8 {// This is an optimized version of the sample code in the PNG spec. // For example, the sample code starts with: // p := int(a) + int(b) - int(c) // pa := abs(p - int(a)) // but the optimized form uses fewer arithmetic operations: // pa := int(b) - int(c) // pa = abs(pa) := int() := int() - := int() - = abs( + ) = abs() = abs()if <= && <= {return } elseif <= {return }return}// filterPaeth applies the Paeth filter to the cdat slice.// cdat is the current row's data, pdat is the previous row's data.func filterPaeth(, []byte, int) {var , , , , , intfor := 0; < ; ++ { , = 0, 0for := ; < len(); += { = int([]) = - = - = abs( + ) = abs() = abs()if <= && <= {// No-op. } elseif <= { = } else { = } += int([]) &= 0xff [] = uint8() = } }}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.