/* * This file is subject to the terms and conditions defined in * file 'LICENSE.md', which is part of this source code package. */ package imagerender import ( "fmt" "image" "image/draw" "math" "strings" "golang.org/x/image/math/fixed" "github.com/unidoc/unipdf/v3/internal/transform" ) func degreesToRadians(degrees float64) float64 { return degrees * math.Pi / 180 } func imageToRGBA(src image.Image) *image.RGBA { bounds := src.Bounds() dst := image.NewRGBA(bounds) draw.Draw(dst, bounds, src, bounds.Min, draw.Src) return dst } func parseHexColor(x string) (r, g, b, a int) { x = strings.TrimPrefix(x, "#") a = 255 if len(x) == 3 { format := "%1x%1x%1x" fmt.Sscanf(x, format, &r, &g, &b) r |= r << 4 g |= g << 4 b |= b << 4 } if len(x) == 6 { format := "%02x%02x%02x" fmt.Sscanf(x, format, &r, &g, &b) } if len(x) == 8 { format := "%02x%02x%02x%02x" fmt.Sscanf(x, format, &r, &g, &b, &a) } return } func fixedPoint(p transform.Point) fixed.Point26_6 { return fixed.Point26_6{ X: fix(p.X), Y: fix(p.Y), } } func fix(x float64) fixed.Int26_6 { return fixed.Int26_6(x * 64) } func unfix(x fixed.Int26_6) float64 { const shift, mask = 6, 1<<6 - 1 if x >= 0 { return float64(x>>shift) + float64(x&mask)/64 } x = -x if x >= 0 { return -(float64(x>>shift) + float64(x&mask)/64) } return 0 }