From bb815b96d680a95dffcd37f85c943e1957eb47ed Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Sat, 11 Sep 2021 16:33:31 +0200 Subject: [PATCH] font/fixed: add convenience method to convert Int12_20 to Int26_6 Signed-off-by: Sebastien Binet --- font/fixed/int12_20.go | 9 +++++++++ go.mod | 2 ++ go.sum | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 go.sum diff --git a/font/fixed/int12_20.go b/font/fixed/int12_20.go index a4be82f..2842d5d 100644 --- a/font/fixed/int12_20.go +++ b/font/fixed/int12_20.go @@ -7,6 +7,8 @@ package fixed import ( "fmt" "strconv" + + "golang.org/x/image/math/fixed" ) // Int12_20 is a signed 12.20 fixed-point number. @@ -31,6 +33,7 @@ func ParseInt12_20(s string) (Int12_20, error) { return Int12_20(f * (1 << 20)), nil } +// Float64 converts the 12.20 fixed-point number to a floating point one. func (x Int12_20) Float64() float64 { v := int32(x) return float64(v) / (1 << 20) @@ -51,3 +54,9 @@ func (x Int12_20) String() string { } return "-2048:00" // The minimum value is -(1<<(12-1)). } + +// ToInt26_6 converts the 12.20 fixed-point number to a 26.6 one. +func (x Int12_20) ToInt26_6() fixed.Int26_6 { + f := x.Float64() + return fixed.Int26_6(f * (1 << 6)) +} diff --git a/go.mod b/go.mod index bc2c355..b25cc79 100644 --- a/go.mod +++ b/go.mod @@ -10,3 +10,5 @@ retract ( v0.1.1 v0.1.0 ) + +require golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7e318f7 --- /dev/null +++ b/go.sum @@ -0,0 +1,5 @@ +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -- 2.34.2