mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
lib/lowleveljpeg: add Abs method, nil checks
This commit is contained in:
1 parent
12b404f58d
commit
f483ef0849
4 files changed
+42
-2
No files matched your search
@@ -54,6 +54,9 @@ func (b BlockU8) String() string {
|
||||
|
||||
// SetToNeutral sets each element to BlockU8NeutralValue.
|
||||
func (b *BlockU8) SetToNeutral() {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
for i := range b {
|
||||
b[i] = BlockU8NeutralValue
|
||||
}
|
||||
@@ -139,8 +142,26 @@ func (b BlockI16) String() string {
|
||||
return string(buf[:])
|
||||
}
|
||||
|
||||
// Abs returns the elementwise absolute value of b.
|
||||
func (b *BlockI16) Abs() (ret BlockI16) {
|
||||
if b == nil {
|
||||
return ret
|
||||
}
|
||||
for i, v := range b {
|
||||
if v < 0 {
|
||||
ret[i] = -v
|
||||
} else {
|
||||
ret[i] = +v
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// SetToNeutral sets each element to BlockI16NeutralValue.
|
||||
func (b *BlockI16) SetToNeutral() {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
for i := range b {
|
||||
b[i] = BlockI16NeutralValue
|
||||
}
|
||||
@@ -241,6 +262,16 @@ func (b QuadBlockU8) String() string {
|
||||
return string(buf[:])
|
||||
}
|
||||
|
||||
// SetToNeutral sets each element to BlockU8NeutralValue.
|
||||
func (b *QuadBlockU8) SetToNeutral() {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
for i := range b {
|
||||
b[i] = BlockU8NeutralValue
|
||||
}
|
||||
}
|
||||
|
||||
// These are "1 / 2" and "1 / (2 * √2)" as 16.16 fixed point values.
|
||||
const (
|
||||
fixedPointHalf = +0x8000
|
||||
|
||||
Reference in new issue
Block a user