This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
scalers.go
88 lines (80 loc) · 1.62 KB
/
scalers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2013 Benoît Amiaux. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package rez
import (
"math"
)
const (
// Bits exports the number of significant bits used by kernels
Bits = 14
)
func u8(x int) byte {
if x < 0 {
x = 0
}
if x > 0xFF {
x = 0xFF
}
return byte(x)
}
func copyPlane(dst, src []byte, width, height, dp, sp int) {
di := 0
si := 0
for y := 0; y < height; y++ {
copy(dst[di:di+width], src[si:si+width])
di += dp
si += sp
}
}
func psnrPlane(dst, src []byte, width, height, dp, sp int) float64 {
mse := 0
di := 0
si := 0
for y := 0; y < height; y++ {
for x, v := range src[si : si+width] {
n := int(v) - int(dst[di+x])
mse += n * n
}
di += dp
si += sp
}
fmse := float64(mse) / float64(width*height)
return 10 * math.Log10(255*255/fmse)
}
func h8scaleNGo(dst, src []byte, cof, off []int16,
taps, width, height, dp, sp int) {
di := 0
si := 0
for y := 0; y < height; y++ {
c := cof
s := src[si:]
d := dst[di:]
for x, xoff := range off[:width] {
pix := 0
for i, v := range s[xoff : xoff+int16(taps)] {
pix += int(v) * int(c[i])
}
d[x] = u8((pix + 1<<(Bits-1)) >> Bits)
c = c[taps:]
}
di += dp
si += sp
}
}
func v8scaleNGo(dst, src []byte, cof, off []int16,
taps, width, height, dp, sp int) {
di := 0
for _, yoff := range off[:height] {
src = src[sp*int(yoff):]
for x := range dst[di : di+width] {
pix := 0
for i, c := range cof[:taps] {
pix += int(c) * int(src[sp*i+x])
}
dst[di+x] = u8((pix + 1<<(Bits-1)) >> Bits)
}
cof = cof[taps:]
di += dp
}
}