From 0bdaf44363bfb3622b7d5a3e51a961443d966ec5 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 9 Dec 2018 12:31:52 -0800 Subject: Delete routed.1 --- docs/man/routed.1 | 129 ------------------------------------------------------ 1 file changed, 129 deletions(-) delete mode 100644 docs/man/routed.1 diff --git a/docs/man/routed.1 b/docs/man/routed.1 deleted file mode 100644 index 14736b1..0000000 --- a/docs/man/routed.1 +++ /dev/null @@ -1,129 +0,0 @@ -.Dd December 12, 2017 -.Dt ROUTED 1 URM - - -.Sh NAME -.Nm routed -.Nd TLS termination and reverse reverse proxying daemon. - - -.Sh SYNOPSIS -.Nm - - -.Sh ENVIRONMENT - -.Bl -tag -width "routed" -offset indent -compact - -.It Ev BOLTDB_PATH -Specifies the path to the boltdb database -.Nm -stores all of its relevant data in. - -.It Ev WEB_ADDR -Specifies the host+port that -.Nm -will listen on for unsecured HTTP traffic. This will only forward traffic to HTTPS. - -.It Ev SSL_ADDR -Specifies the host+port that -.Nm -will listen on for secure (TLS) traffic. This should have port 443 if you want Let's Encrypt to work (you probably want Let's Encrypt to work). - -.It Ev QUIC_ADDR -Specifies the host+port that -.Nm -will listen on for secure (TLS) QUIC traffic. For more information see https://datatracker.ietf.org/wg/quic/about/. This should also be port 443, but is not essential for Let's Encrypt to work. - -.It Ev BACKEND_TCP_ADDR -Specifies the host+port that -.Nm -will listen on for secure (TLS) TCP connections from backends. Any client that is successfully able to authenticate with -.Nm -on this port will relay HTTP traffic from to and from end users. - -.It Ev BACKEND_KCP_ADDR -Specifies the host+port that -.Nm -will listen on for secure (TLS) KCP (reliable-UDP) connections from backends. Any client that is successfully able to authenticate with -.Nm -on this port will relay HTTP traffic from to and from end users. - -For more information about KCP, see https://github.com/xtaci/kcp-go - -.It Ev GRPC_ADDR -Specifies the host+post that -.Nm -will listen on for secure (TLS) TCP gRPC connections from clients wishing to control -.Nm -configuration. Authentication is enforced and requires the use of an API token generated by the API call route.Tokens.Put. - -.It Ev DOMAIN_SUFFIX -Specifies the domain suffix that -.Nm -will use when automatically generating a domain name for a newly created route. Please set this to something that has a wildcard DNS record pointing to your instances of routed. - -.It Ev ACME_EMAIL -Specifies the email address that -.Nm -will use when creating a new account with Let's Encrypt. This assumes you have read (and agree to) the Let's Encrypt terms of service found here: https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf. - -.It Ev SSL_CERT_KEY -Specifies the encryption key that -.Nm -will use when encrypting and decrypting SSL certificates when loading them from and saving them to the database. This can be created with -.Xr route-cli 1 . - -.El - - -.Sh IMPLEMENTATION NOTES - -In order for -.Nm -to route traffic, a route must be set up using -.Xr route-cli 1 . -Please see its manpage for more information on how to do this. - -.Nm -exposes debugging and introspection information on a randomly generated port every time it starts up. The message will look something like: - -2017/12/13 02:06:56 manhole: Now listening on http://127.0.0.1:39245 - -Expose this using -.Xr route-httpagent 1 -or similar tools. - -.Nm -can be managed using terraform. See -.Xr terraform-provider-route 1 -for more information. - - -.Sh EXAMPLES - -routed - - -.Sh DIAGNOSTICS - -.Ex -std routed - - -.Sh SEE ALSO - -.Bl -bullet - -.It -https://datatracker.ietf.org/wg/quic/about/ - -.It -https://github.com/xtaci/kcp-go - -.It -https://grpc.io/ - -.It -https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf - -.El -- cgit v1.2.3 From f5279a6acc1fa11e4f39a3370190974c39e27afd Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 9 Dec 2018 20:32:20 +0000 Subject: docs/man: build markdown versions of manpages --- Dockerfile | 4 ++-- docs/man/README.md | 11 +++++++++++ docs/man/prepare.sh | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 docs/man/README.md diff --git a/Dockerfile b/Dockerfile index c48ae3a..19f23a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,9 @@ COPY . . ENV GOPROXY=https://cache.greedo.xeserv.us ENV CGO_ENABLED=0 RUN GOBIN=/x/bin go install -v ./... -RUN cd ./docs/man && ./prepare.sh +RUN apk --no-cache add mdocml && cd ./docs/man && ./prepare.sh FROM xena/alpine COPY --from=build /x/bin/ /usr/local/bin/ -COPY --from=build /x/doc/man /usr/share/man/man1 +COPY --from=build /x/docs/man /usr/share/man/man1 RUN apk --no-cache add man diff --git a/docs/man/README.md b/docs/man/README.md new file mode 100644 index 0000000..b0a74fc --- /dev/null +++ b/docs/man/README.md @@ -0,0 +1,11 @@ +# manpages + +These are manpages for a selected group of commands that I consider really useful. I have created a web version of these manpages too at TODO: add link to deployed site. + +## Deployment + +- gzip all the files (`$ gzip *.1`) +- copy to (`/usr/share/man/man1/`) +- `$ man appsluggr` + + diff --git a/docs/man/prepare.sh b/docs/man/prepare.sh index 2180c32..c56f8f1 100755 --- a/docs/man/prepare.sh +++ b/docs/man/prepare.sh @@ -1,3 +1,8 @@ #!/bin/sh +for file in *.1 +do + mandoc -T markdown $file > ../$file.md +done + gzip *.1 -- cgit v1.2.3 From 7680f8cc6d7f3435e1aa67e5b00844880ff4bfd2 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 9 Dec 2018 20:50:12 +0000 Subject: tools.go --- go.mod | 1 + go.sum | 2 ++ tools.go | 9 +++++++++ tools_install.go | 22 ++++++++++++++++++++++ version/ko/main.go | 6 +++--- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tools.go create mode 100644 tools_install.go diff --git a/go.mod b/go.mod index 01ac2f3..8b79346 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( github.com/peterh/liner v1.1.0 github.com/pkg/errors v0.8.0 github.com/pkg/sftp v1.8.3 // indirect + github.com/russross/blackfriday-tool v0.0.0-20120308051103-a78eb387e806 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/streamrail/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6 github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 // indirect diff --git a/go.sum b/go.sum index 59ec658..5e6f236 100644 --- a/go.sum +++ b/go.sum @@ -167,6 +167,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday v1.5.1 h1:B8ZN6pD4PVofmlDCDUdELeYrbsVIDM/bpjW3v3zgcRc= github.com/russross/blackfriday v1.5.1/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday-tool v0.0.0-20120308051103-a78eb387e806 h1:eehmvKp7Y/oJnZLyFrC+NFtDb5aMVW25QHzXjs+egWE= +github.com/russross/blackfriday-tool v0.0.0-20120308051103-a78eb387e806/go.mod h1:Dn/w91XVDVHljHfa908Dn3l6S8XF0zRm67IbS87oFRI= github.com/sendgrid/rest v2.4.1+incompatible h1:HDib/5xzQREPq34lN3YMhQtMkdXxS/qLp5G3k9a5++4= github.com/sendgrid/rest v2.4.1+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..23b32c6 --- /dev/null +++ b/tools.go @@ -0,0 +1,9 @@ +// +build tools + +package main + +import ( + _ "github.com/russross/blackfriday-tool" +) + +func main() {} diff --git a/tools_install.go b/tools_install.go new file mode 100644 index 0000000..178f104 --- /dev/null +++ b/tools_install.go @@ -0,0 +1,22 @@ +// +build ignore + +package main + +import ( + "context" + "os" + "time" + + "github.com/Xe/x/internal/yeet" +) + +func main() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + defer cancel() + + env := append(os.Environ(), []string{"GO111MODULE=on"}...) + + for _, tool := range []string{"github.com/russross/blackfriday-tool"} { + yeet.ShouldWork(ctx, env, yeet.WD, "go", "install", tool) + } +} diff --git a/version/ko/main.go b/version/ko/main.go index 584ae4d..3b333c8 100644 --- a/version/ko/main.go +++ b/version/ko/main.go @@ -13,10 +13,10 @@ func main() { ver := os.Getenv("GO_VERSION") if ver == "" { - log.Printf("ko: No GO_VERSION specified (wanted GO_VERSION=%[1]s) specified, assuming %[1]s", runtime.Version()) + ver = runtime.Version() + } else { + ver = "go" + ver } - ver = "go" + ver - version.Run(ver) } -- cgit v1.2.3 From 02ba508eeb28480fa5a3d4de8184702a54ab7b12 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 10 Dec 2018 04:14:21 +0000 Subject: fix ko --- Dockerfile | 9 +++++++-- go.sum | 1 + version/ko/main.go | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19f23a4..dd0e297 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,13 @@ WORKDIR /x COPY . . ENV GOPROXY=https://cache.greedo.xeserv.us ENV CGO_ENABLED=0 -RUN GOBIN=/x/bin go install -v ./... -RUN apk --no-cache add mdocml && cd ./docs/man && ./prepare.sh +RUN go run tools_install.go \ + && GOBIN=/x/bin go install -v ./... +RUN apk --no-cache add mdocml \ + && cd ./docs/man \ + && ./prepare.sh +RUN apk --no-cache add upx \ + && upx /x/bin/* FROM xena/alpine COPY --from=build /x/bin/ /usr/local/bin/ diff --git a/go.sum b/go.sum index 5e6f236..e0a989a 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/ThomasRooney/gexpect v0.0.0-20161231170123-5482f0350944/go.mod h1:sPM github.com/Xe/johaus v0.0.0-20181126154118-fe870a11f3b2 h1:UGyUwa0KVLJ8lA7A5wj9vreeQRDxnWCpTqyI6DRFM6s= github.com/Xe/johaus v0.0.0-20181126154118-fe870a11f3b2/go.mod h1:AxheHD7a8X/KIoOUFa2krQkHFIKqhoP+VTWqNJ+3Joo= github.com/Xe/johaus v0.0.0-20181205212019-e9efbbc86339/go.mod h1:AxheHD7a8X/KIoOUFa2krQkHFIKqhoP+VTWqNJ+3Joo= +github.com/Xe/johaus v0.3.0 h1:zw+G99Q/xHx0bL4CQHi2y1C3xGpoXMURrAwhIMsclrk= github.com/Xe/johaus v0.3.0/go.mod h1:AxheHD7a8X/KIoOUFa2krQkHFIKqhoP+VTWqNJ+3Joo= github.com/Xe/ln v0.1.2 h1:VTF6Z95Kdd6S1RSjpnn0DFJV5Do9cfmHTHsE9OGI1dw= github.com/Xe/ln v0.1.2/go.mod h1:GWZDvjL0ZC/9SSjY8DJ2IOrID6Lejs7D8pgQyjqMYSk= diff --git a/version/ko/main.go b/version/ko/main.go index 3b333c8..c1a30b6 100644 --- a/version/ko/main.go +++ b/version/ko/main.go @@ -1,7 +1,6 @@ package main import ( - "log" "os" "runtime" -- cgit v1.2.3 From 1d0f9670611832eb9a80c34fa7285b42e94aaace Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 15 Dec 2018 06:32:52 +0000 Subject: within.website: --- discord/ilo-kesi/within.go | 2 + farbfeld/ff-primitive/vendor-log | 10 - .../vendor/github.com/fogleman/gg/bezier.go | 59 - .../vendor/github.com/fogleman/gg/context.go | 795 --- .../vendor/github.com/fogleman/gg/gradient.go | 202 - .../vendor/github.com/fogleman/gg/matrix.go | 88 - .../vendor/github.com/fogleman/gg/path.go | 140 - .../vendor/github.com/fogleman/gg/pattern.go | 123 - .../vendor/github.com/fogleman/gg/point.go | 25 - .../vendor/github.com/fogleman/gg/util.go | 117 - .../vendor/github.com/fogleman/gg/wrap.go | 58 - .../fogleman/primitive/primitive/color.go | 44 - .../fogleman/primitive/primitive/core.go | 124 - .../fogleman/primitive/primitive/ellipse.go | 179 - .../fogleman/primitive/primitive/heatmap.go | 59 - .../github.com/fogleman/primitive/primitive/log.go | 23 - .../fogleman/primitive/primitive/model.go | 174 - .../fogleman/primitive/primitive/optimize.go | 75 - .../fogleman/primitive/primitive/polygon.go | 111 - .../fogleman/primitive/primitive/quadratic.go | 100 - .../fogleman/primitive/primitive/raster.go | 46 - .../fogleman/primitive/primitive/rectangle.go | 198 - .../fogleman/primitive/primitive/scanline.go | 29 - .../fogleman/primitive/primitive/shape.go | 25 - .../fogleman/primitive/primitive/state.go | 48 - .../fogleman/primitive/primitive/triangle.go | 171 - .../fogleman/primitive/primitive/util.go | 195 - .../fogleman/primitive/primitive/worker.go | 108 - .../github.com/golang/freetype/raster/geom.go | 245 - .../github.com/golang/freetype/raster/paint.go | 287 - .../github.com/golang/freetype/raster/raster.go | 601 -- .../github.com/golang/freetype/raster/stroke.go | 483 -- .../github.com/golang/freetype/truetype/face.go | 507 -- .../github.com/golang/freetype/truetype/glyph.go | 522 -- .../github.com/golang/freetype/truetype/hint.go | 1770 ------ .../github.com/golang/freetype/truetype/opcodes.go | 289 - .../golang/freetype/truetype/truetype.go | 653 -- .../github.com/hullerob/go.farbfeld/farbfeld.go | 96 - .../vendor/golang.org/x/image/draw/draw.go | 43 - .../vendor/golang.org/x/image/draw/gen.go | 1403 ---- .../vendor/golang.org/x/image/draw/go1_8.go | 49 - .../vendor/golang.org/x/image/draw/go1_9.go | 57 - .../vendor/golang.org/x/image/draw/impl.go | 6668 -------------------- .../vendor/golang.org/x/image/draw/scale.go | 527 -- .../vendor/golang.org/x/image/draw/stdlib_test.go | 96 - .../golang.org/x/image/font/basicfont/basicfont.go | 126 - .../golang.org/x/image/font/basicfont/data.go | 1456 ----- .../golang.org/x/image/font/basicfont/gen.go | 115 - .../vendor/golang.org/x/image/font/font.go | 359 -- .../vendor/golang.org/x/image/math/f64/f64.go | 37 - .../vendor/golang.org/x/image/math/fixed/fixed.go | 410 -- go.mod | 12 +- go.sum | 18 +- mastodon/almarid/main.go | 2 +- mastodon/furrybb/main.go | 2 +- mastodon/sona-pi-toki-pona/main.go | 4 +- tools.go | 1 + tools_install.go | 2 +- tun2/client.go | 4 +- tun2/connection.go | 4 +- tun2/server.go | 4 +- tun2/server_test.go | 2 +- 62 files changed, 27 insertions(+), 20155 deletions(-) delete mode 100644 farbfeld/ff-primitive/vendor-log delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/bezier.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/context.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/gradient.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/matrix.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/path.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/pattern.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/point.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/util.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/gg/wrap.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/color.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/core.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/ellipse.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/heatmap.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/log.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/model.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/optimize.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/polygon.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/quadratic.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/raster.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/rectangle.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/scanline.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/shape.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/state.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/triangle.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/util.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/worker.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/raster/geom.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/raster/paint.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/raster/raster.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/raster/stroke.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/truetype/face.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/truetype/glyph.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/truetype/hint.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/truetype/opcodes.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/golang/freetype/truetype/truetype.go delete mode 100644 farbfeld/ff-primitive/vendor/github.com/hullerob/go.farbfeld/farbfeld.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/draw.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/gen.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/go1_8.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/go1_9.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/impl.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/scale.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/draw/stdlib_test.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/font/basicfont/basicfont.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/font/basicfont/data.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/font/basicfont/gen.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/font/font.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/math/f64/f64.go delete mode 100644 farbfeld/ff-primitive/vendor/golang.org/x/image/math/fixed/fixed.go diff --git a/discord/ilo-kesi/within.go b/discord/ilo-kesi/within.go index 1b4d291..0987342 100644 --- a/discord/ilo-kesi/within.go +++ b/discord/ilo-kesi/within.go @@ -6,6 +6,7 @@ var tokiToWithin = map[string]string{ "Lesi": "Jessie", "Sesi": "Sephie", "Ase": "Ashe", + "Mai": "Mai", } var withinToToki = map[string]string{ @@ -14,4 +15,5 @@ var withinToToki = map[string]string{ "Jessie": "Lesi", "Sephie": "Sesi", "Ashe": "Ase", + "Mai": "Mai", } diff --git a/farbfeld/ff-primitive/vendor-log b/farbfeld/ff-primitive/vendor-log deleted file mode 100644 index 6b5a045..0000000 --- a/farbfeld/ff-primitive/vendor-log +++ /dev/null @@ -1,10 +0,0 @@ -b572f0728b691aae4256edb2e408279146eafe52 github.com/hullerob/go.farbfeld -ee8994ff90057955c428a5a949da5d064bf3ce6b github.com/fogleman/gg -80f39ceaa8f4c66acb28aba6abe6b15128c06113 github.com/fogleman/primitive/primitive -bcfeb16b74e8aea9e2fe043406f2ef74b1cb0759 github.com/golang/freetype/raster -bcfeb16b74e8aea9e2fe043406f2ef74b1cb0759 github.com/golang/freetype/truetype -426cfd8eeb6e08ab1932954e09e3c2cb2bc6e36d golang.org/x/image/draw -426cfd8eeb6e08ab1932954e09e3c2cb2bc6e36d golang.org/x/image/font -426cfd8eeb6e08ab1932954e09e3c2cb2bc6e36d golang.org/x/image/font/basicfont -426cfd8eeb6e08ab1932954e09e3c2cb2bc6e36d golang.org/x/image/math/f64 -426cfd8eeb6e08ab1932954e09e3c2cb2bc6e36d golang.org/x/image/math/fixed diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/bezier.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/bezier.go deleted file mode 100644 index f2cd7ab..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/bezier.go +++ /dev/null @@ -1,59 +0,0 @@ -package gg - -import "math" - -func quadratic(x0, y0, x1, y1, x2, y2, t float64) (x, y float64) { - u := 1 - t - a := u * u - b := 2 * u * t - c := t * t - x = a*x0 + b*x1 + c*x2 - y = a*y0 + b*y1 + c*y2 - return -} - -func QuadraticBezier(x0, y0, x1, y1, x2, y2 float64) []Point { - l := (math.Hypot(x1-x0, y1-y0) + - math.Hypot(x2-x1, y2-y1)) - n := int(l + 0.5) - if n < 4 { - n = 4 - } - d := float64(n) - 1 - result := make([]Point, n) - for i := 0; i < n; i++ { - t := float64(i) / d - x, y := quadratic(x0, y0, x1, y1, x2, y2, t) - result[i] = Point{x, y} - } - return result -} - -func cubic(x0, y0, x1, y1, x2, y2, x3, y3, t float64) (x, y float64) { - u := 1 - t - a := u * u * u - b := 3 * u * u * t - c := 3 * u * t * t - d := t * t * t - x = a*x0 + b*x1 + c*x2 + d*x3 - y = a*y0 + b*y1 + c*y2 + d*y3 - return -} - -func CubicBezier(x0, y0, x1, y1, x2, y2, x3, y3 float64) []Point { - l := (math.Hypot(x1-x0, y1-y0) + - math.Hypot(x2-x1, y2-y1) + - math.Hypot(x3-x2, y3-y2)) - n := int(l + 0.5) - if n < 4 { - n = 4 - } - d := float64(n) - 1 - result := make([]Point, n) - for i := 0; i < n; i++ { - t := float64(i) / d - x, y := cubic(x0, y0, x1, y1, x2, y2, x3, y3, t) - result[i] = Point{x, y} - } - return result -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/context.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/context.go deleted file mode 100644 index e828af8..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/context.go +++ /dev/null @@ -1,795 +0,0 @@ -// Package gg provides a simple API for rendering 2D graphics in pure Go. -package gg - -import ( - "image" - "image/color" - "image/png" - "io" - "math" - - "github.com/golang/freetype/raster" - "golang.org/x/image/draw" - "golang.org/x/image/font" - "golang.org/x/image/font/basicfont" - "golang.org/x/image/math/f64" -) - -type LineCap int - -const ( - LineCapRound LineCap = iota - LineCapButt - LineCapSquare -) - -type LineJoin int - -const ( - LineJoinRound LineJoin = iota - LineJoinBevel -) - -type FillRule int - -const ( - FillRuleWinding FillRule = iota - FillRuleEvenOdd -) - -type Align int - -const ( - AlignLeft Align = iota - AlignCenter - AlignRight -) - -var ( - defaultFillStyle = NewSolidPattern(color.White) - defaultStrokeStyle = NewSolidPattern(color.Black) -) - -type Context struct { - width int - height int - im *image.RGBA - mask *image.Alpha - color color.Color - fillPattern Pattern - strokePattern Pattern - strokePath raster.Path - fillPath raster.Path - start Point - current Point - hasCurrent bool - dashes []float64 - lineWidth float64 - lineCap LineCap - lineJoin LineJoin - fillRule FillRule - fontFace font.Face - fontHeight float64 - matrix Matrix - stack []*Context -} - -// NewContext creates a new image.RGBA with the specified width and height -// and prepares a context for rendering onto that image. -func NewContext(width, height int) *Context { - return NewContextForRGBA(image.NewRGBA(image.Rect(0, 0, width, height))) -} - -// NewContextForImage copies the specified image into a new image.RGBA -// and prepares a context for rendering onto that image. -func NewContextForImage(im image.Image) *Context { - return NewContextForRGBA(imageToRGBA(im)) -} - -// NewContextForRGBA prepares a context for rendering onto the specified image. -// No copy is made. -func NewContextForRGBA(im *image.RGBA) *Context { - return &Context{ - width: im.Bounds().Size().X, - height: im.Bounds().Size().Y, - im: im, - color: color.Transparent, - fillPattern: defaultFillStyle, - strokePattern: defaultStrokeStyle, - lineWidth: 1, - fillRule: FillRuleWinding, - fontFace: basicfont.Face7x13, - fontHeight: 13, - matrix: Identity(), - } -} - -// Image returns the image that has been drawn by this context. -func (dc *Context) Image() image.Image { - return dc.im -} - -// Width returns the width of the image in pixels. -func (dc *Context) Width() int { - return dc.width -} - -// Height returns the height of the image in pixels. -func (dc *Context) Height() int { - return dc.height -} - -// SavePNG encodes the image as a PNG and writes it to disk. -func (dc *Context) SavePNG(path string) error { - return SavePNG(path, dc.im) -} - -// EncodePNG encodes the image as a PNG and writes it to the provided io.Writer. -func (dc *Context) EncodePNG(w io.Writer) error { - return png.Encode(w, dc.im) -} - -// SetDash sets the current dash pattern to use. Call with zero arguments to -// disable dashes. The values specify the lengths of each dash, with -// alternating on and off lengths. -func (dc *Context) SetDash(dashes ...float64) { - dc.dashes = dashes -} - -func (dc *Context) SetLineWidth(lineWidth float64) { - dc.lineWidth = lineWidth -} - -func (dc *Context) SetLineCap(lineCap LineCap) { - dc.lineCap = lineCap -} - -func (dc *Context) SetLineCapRound() { - dc.lineCap = LineCapRound -} - -func (dc *Context) SetLineCapButt() { - dc.lineCap = LineCapButt -} - -func (dc *Context) SetLineCapSquare() { - dc.lineCap = LineCapSquare -} - -func (dc *Context) SetLineJoin(lineJoin LineJoin) { - dc.lineJoin = lineJoin -} - -func (dc *Context) SetLineJoinRound() { - dc.lineJoin = LineJoinRound -} - -func (dc *Context) SetLineJoinBevel() { - dc.lineJoin = LineJoinBevel -} - -func (dc *Context) SetFillRule(fillRule FillRule) { - dc.fillRule = fillRule -} - -func (dc *Context) SetFillRuleWinding() { - dc.fillRule = FillRuleWinding -} - -func (dc *Context) SetFillRuleEvenOdd() { - dc.fillRule = FillRuleEvenOdd -} - -// Color Setters - -func (dc *Context) setFillAndStrokeColor(c color.Color) { - dc.color = c - dc.fillPattern = NewSolidPattern(c) - dc.strokePattern = NewSolidPattern(c) -} - -// SetFillStyle sets current fill style -func (dc *Context) SetFillStyle(pattern Pattern) { - // if pattern is SolidPattern, also change dc.color(for dc.Clear, dc.drawString) - if fillStyle, ok := pattern.(*solidPattern); ok { - dc.color = fillStyle.color - } - dc.fillPattern = pattern -} - -// SetStrokeStyle sets current stroke style -func (dc *Context) SetStrokeStyle(pattern Pattern) { - dc.strokePattern = pattern -} - -// SetColor sets the current color(for both fill and stroke). -func (dc *Context) SetColor(c color.Color) { - dc.setFillAndStrokeColor(c) -} - -// SetHexColor sets the current color using a hex string. The leading pound -// sign (#) is optional. Both 3- and 6-digit variations are supported. 8 digits -// may be provided to set the alpha value as well. -func (dc *Context) SetHexColor(x string) { - r, g, b, a := parseHexColor(x) - dc.SetRGBA255(r, g, b, a) -} - -// SetRGBA255 sets the current color. r, g, b, a values should be between 0 and -// 255, inclusive. -func (dc *Context) SetRGBA255(r, g, b, a int) { - dc.color = color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(a)} - dc.setFillAndStrokeColor(dc.color) -} - -// SetRGB255 sets the current color. r, g, b values should be between 0 and 255, -// inclusive. Alpha will be set to 255 (fully opaque). -func (dc *Context) SetRGB255(r, g, b int) { - dc.SetRGBA255(r, g, b, 255) -} - -// SetRGBA sets the current color. r, g, b, a values should be between 0 and 1, -// inclusive. -func (dc *Context) SetRGBA(r, g, b, a float64) { - dc.color = color.NRGBA{ - uint8(r * 255), - uint8(g * 255), - uint8(b * 255), - uint8(a * 255), - } - dc.setFillAndStrokeColor(dc.color) -} - -// SetRGB sets the current color. r, g, b values should be between 0 and 1, -// inclusive. Alpha will be set to 1 (fully opaque). -func (dc *Context) SetRGB(r, g, b float64) { - dc.SetRGBA(r, g, b, 1) -} - -// Path Manipulation - -// MoveTo starts a new subpath within the current path starting at the -// specified point. -func (dc *Context) MoveTo(x, y float64) { - if dc.hasCurrent { - dc.fillPath.Add1(dc.start.Fixed()) - } - x, y = dc.TransformPoint(x, y) - p := Point{x, y} - dc.strokePath.Start(p.Fixed()) - dc.fillPath.Start(p.Fixed()) - dc.start = p - dc.current = p - dc.hasCurrent = true -} - -// LineTo adds a line segment to the current path starting at the current -// point. If there is no current point, it is equivalent to MoveTo(x, y) -func (dc *Context) LineTo(x, y float64) { - if !dc.hasCurrent { - dc.MoveTo(x, y) - } else { - x, y = dc.TransformPoint(x, y) - p := Point{x, y} - dc.strokePath.Add1(p.Fixed()) - dc.fillPath.Add1(p.Fixed()) - dc.current = p - } -} - -// QuadraticTo adds a quadratic bezier curve to the current path starting at -// the current point. If there is no current point, it first performs -// MoveTo(x1, y1) -func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64) { - if !dc.hasCurrent { - dc.MoveTo(x1, y1) - } - x1, y1 = dc.TransformPoint(x1, y1) - x2, y2 = dc.TransformPoint(x2, y2) - p1 := Point{x1, y1} - p2 := Point{x2, y2} - dc.strokePath.Add2(p1.Fixed(), p2.Fixed()) - dc.fillPath.Add2(p1.Fixed(), p2.Fixed()) - dc.current = p2 -} - -// CubicTo adds a cubic bezier curve to the current path starting at the -// current point. If there is no current point, it first performs -// MoveTo(x1, y1). Because freetype/raster does not support cubic beziers, -// this is emulated with many small line segments. -func (dc *Context) CubicTo(x1, y1, x2, y2, x3, y3 float64) { - if !dc.hasCurrent { - dc.MoveTo(x1, y1) - } - x0, y0 := dc.current.X, dc.current.Y - x1, y1 = dc.TransformPoint(x1, y1) - x2, y2 = dc.TransformPoint(x2, y2) - x3, y3 = dc.TransformPoint(x3, y3) - points := CubicBezier(x0, y0, x1, y1, x2, y2, x3, y3) - previous := dc.current.Fixed() - for _, p := range points[1:] { - f := p.Fixed() - if f == previous { - // TODO: this fixes some rendering issues but not all - continue - } - previous = f - dc.strokePath.Add1(f) - dc.fillPath.Add1(f) - dc.current = p - } -} - -// ClosePath adds a line segment from the current point to the beginning -// of the current subpath. If there is no current point, this is a no-op. -func (dc *Context) ClosePath() { - if dc.hasCurrent { - dc.strokePath.Add1(dc.start.Fixed()) - dc.fillPath.Add1(dc.start.Fixed()) - dc.current = dc.start - } -} - -// ClearPath clears the current path. There is no current point after this -// operation. -func (dc *Context) ClearPath() { - dc.strokePath.Clear() - dc.fillPath.Clear() - dc.hasCurrent = false -} - -// NewSubPath starts a new subpath within the current path. There is no current -// point after this operation. -func (dc *Context) NewSubPath() { - if dc.hasCurrent { - dc.fillPath.Add1(dc.start.Fixed()) - } - dc.hasCurrent = false -} - -// Path Drawing - -func (dc *Context) capper() raster.Capper { - switch dc.lineCap { - case LineCapButt: - return raster.ButtCapper - case LineCapRound: - return raster.RoundCapper - case LineCapSquare: - return raster.SquareCapper - } - return nil -} - -func (dc *Context) joiner() raster.Joiner { - switch dc.lineJoin { - case LineJoinBevel: - return raster.BevelJoiner - case LineJoinRound: - return raster.RoundJoiner - } - return nil -} - -func (dc *Context) stroke(painter raster.Painter) { - path := dc.strokePath - if len(dc.dashes) > 0 { - path = dashed(path, dc.dashes) - } else { - // TODO: this is a temporary workaround to remove tiny segments - // that result in rendering issues - path = rasterPath(flattenPath(path)) - } - r := raster.NewRasterizer(dc.width, dc.height) - r.UseNonZeroWinding = true - r.AddStroke(path, fix(dc.lineWidth), dc.capper(), dc.joiner()) - r.Rasterize(painter) -} - -func (dc *Context) fill(painter raster.Painter) { - path := dc.fillPath - if dc.hasCurrent { - path = make(raster.Path, len(dc.fillPath)) - copy(path, dc.fillPath) - path.Add1(dc.start.Fixed()) - } - r := raster.NewRasterizer(dc.width, dc.height) - r.UseNonZeroWinding = dc.fillRule == FillRuleWinding - r.AddPath(path) - r.Rasterize(painter) -} - -// StrokePreserve strokes the current path with the current color, line width, -// line cap, line join and dash settings. The path is preserved after this -// operation. -func (dc *Context) StrokePreserve() { - painter := newPatternPainter(dc.im, dc.mask, dc.strokePattern) - dc.stroke(painter) -} - -// Stroke strokes the current path with the current color, line width, -// line cap, line join and dash settings. The path is cleared after this -// operation. -func (dc *Context) Stroke() { - dc.StrokePreserve() - dc.ClearPath() -} - -// FillPreserve fills the current path with the current color. Open subpaths -// are implicity closed. The path is preserved after this operation. -func (dc *Context) FillPreserve() { - painter := newPatternPainter(dc.im, dc.mask, dc.fillPattern) - dc.fill(painter) -} - -// Fill fills the current path with the current color. Open subpaths -// are implicity closed. The path is cleared after this operation. -func (dc *Context) Fill() { - dc.FillPreserve() - dc.ClearPath() -} - -// ClipPreserve updates the clipping region by intersecting the current -// clipping region with the current path as it would be filled by dc.Fill(). -// The path is preserved after this operation. -func (dc *Context) ClipPreserve() { - clip := image.NewAlpha(image.Rect(0, 0, dc.width, dc.height)) - painter := raster.NewAlphaOverPainter(clip) - dc.fill(painter) - if dc.mask == nil { - dc.mask = clip - } else { - mask := image.NewAlpha(image.Rect(0, 0, dc.width, dc.height)) - draw.DrawMask(mask, mask.Bounds(), clip, image.ZP, dc.mask, image.ZP, draw.Over) - dc.mask = mask - } -} - -// Clip updates the clipping region by intersecting the current -// clipping region with the current path as it would be filled by dc.Fill(). -// The path is cleared after this operation. -func (dc *Context) Clip() { - dc.ClipPreserve() - dc.ClearPath() -} - -// ResetClip clears the clipping region. -func (dc *Context) ResetClip() { - dc.mask = nil -} - -// Convenient Drawing Functions - -// Clear fills the entire image with the current color. -func (dc *Context) Clear() { - src := image.NewUniform(dc.color) - draw.Draw(dc.im, dc.im.Bounds(), src, image.ZP, draw.Src) -} - -// SetPixel sets the color of the specified pixel using the current color. -func (dc *Context) SetPixel(x, y int) { - dc.im.Set(x, y, dc.color) -} - -// DrawPoint is like DrawCircle but ensures that a circle of the specified -// size is drawn regardless of the current transformation matrix. The position -// is still transformed, but not the shape of the point. -func (dc *Context) DrawPoint(x, y, r float64) { - dc.Push() - tx, ty := dc.TransformPoint(x, y) - dc.Identity() - dc.DrawCircle(tx, ty, r) - dc.Pop() -} - -func (dc *Context) DrawLine(x1, y1, x2, y2 float64) { - dc.MoveTo(x1, y1) - dc.LineTo(x2, y2) -} - -func (dc *Context) DrawRectangle(x, y, w, h float64) { - dc.NewSubPath() - dc.MoveTo(x, y) - dc.LineTo(x+w, y) - dc.LineTo(x+w, y+h) - dc.LineTo(x, y+h) - dc.ClosePath() -} - -func (dc *Context) DrawRoundedRectangle(x, y, w, h, r float64) { - x0, x1, x2, x3 := x, x+r, x+w-r, x+w - y0, y1, y2, y3 := y, y+r, y+h-r, y+h - dc.NewSubPath() - dc.MoveTo(x1, y0) - dc.LineTo(x2, y0) - dc.DrawArc(x2, y1, r, Radians(270), Radians(360)) - dc.LineTo(x3, y2) - dc.DrawArc(x2, y2, r, Radians(0), Radians(90)) - dc.LineTo(x1, y3) - dc.DrawArc(x1, y2, r, Radians(90), Radians(180)) - dc.LineTo(x0, y1) - dc.DrawArc(x1, y1, r, Radians(180), Radians(270)) - dc.ClosePath() -} - -func (dc *Context) DrawEllipticalArc(x, y, rx, ry, angle1, angle2 float64) { - const n = 16 - for i := 0; i < n; i++ { - p1 := float64(i+0) / n - p2 := float64(i+1) / n - a1 := angle1 + (angle2-angle1)*p1 - a2 := angle1 + (angle2-angle1)*p2 - x0 := x + rx*math.Cos(a1) - y0 := y + ry*math.Sin(a1) - x1 := x + rx*math.Cos(a1+(a2-a1)/2) - y1 := y + ry*math.Sin(a1+(a2-a1)/2) - x2 := x + rx*math.Cos(a2) - y2 := y + ry*math.Sin(a2) - cx := 2*x1 - x0/2 - x2/2 - cy := 2*y1 - y0/2 - y2/2 - if i == 0 && !dc.hasCurrent { - dc.MoveTo(x0, y0) - } - dc.QuadraticTo(cx, cy, x2, y2) - } -} - -func (dc *Context) DrawEllipse(x, y, rx, ry float64) { - dc.NewSubPath() - dc.DrawEllipticalArc(x, y, rx, ry, 0, 2*math.Pi) - dc.ClosePath() -} - -func (dc *Context) DrawArc(x, y, r, angle1, angle2 float64) { - dc.DrawEllipticalArc(x, y, r, r, angle1, angle2) -} - -func (dc *Context) DrawCircle(x, y, r float64) { - dc.NewSubPath() - dc.DrawEllipticalArc(x, y, r, r, 0, 2*math.Pi) - dc.ClosePath() -} - -func (dc *Context) DrawRegularPolygon(n int, x, y, r, rotation float64) { - angle := 2 * math.Pi / float64(n) - rotation -= math.Pi / 2 - if n%2 == 0 { - rotation += angle / 2 - } - dc.NewSubPath() - for i := 0; i < n; i++ { - a := rotation + angle*float64(i) - dc.LineTo(x+r*math.Cos(a), y+r*math.Sin(a)) - } - dc.ClosePath() -} - -// DrawImage draws the specified image at the specified point. -func (dc *Context) DrawImage(im image.Image, x, y int) { - dc.DrawImageAnchored(im, x, y, 0, 0) -} - -// DrawImageAnchored draws the specified image at the specified anchor point. -// The anchor point is x - w * ax, y - h * ay, where w, h is the size of the -// image. Use ax=0.5, ay=0.5 to center the image at the specified point. -func (dc *Context) DrawImageAnchored(im image.Image, x, y int, ax, ay float64) { - s := im.Bounds().Size() - x -= int(ax * float64(s.X)) - y -= int(ay * float64(s.Y)) - transformer := draw.BiLinear - fx, fy := float64(x), float64(y) - m := dc.matrix.Translate(fx, fy) - s2d := f64.Aff3{m.XX, m.XY, m.X0, m.YX, m.YY, m.Y0} - if dc.mask == nil { - transformer.Transform(dc.im, s2d, im, im.Bounds(), draw.Over, nil) - } else { - transformer.Transform(dc.im, s2d, im, im.Bounds(), draw.Over, &draw.Options{ - DstMask: dc.mask, - DstMaskP: image.ZP, - }) - } -} - -// Text Functions - -func (dc *Context) SetFontFace(fontFace font.Face) { - dc.fontFace = fontFace - dc.fontHeight = float64(fontFace.Metrics().Height) / 64 -} - -func (dc *Context) LoadFontFace(path string, points float64) error { - face, err := LoadFontFace(path, points) - if err == nil { - dc.fontFace = face - dc.fontHeight = points * 72 / 96 - } - return err -} - -func (dc *Context) drawString(im *image.RGBA, s string, x, y float64) { - d := &font.Drawer{ - Dst: im, - Src: image.NewUniform(dc.color), - Face: dc.fontFace, - Dot: fixp(x, y), - } - // based on Drawer.DrawString() in golang.org/x/image/font/font.go - prevC := rune(-1) - for _, c := range s { - if prevC >= 0 { - d.Dot.X += d.Face.Kern(prevC, c) - } - dr, mask, maskp, advance, ok := d.Face.Glyph(d.Dot, c) - if !ok { - // TODO: is falling back on the U+FFFD glyph the responsibility of - // the Drawer or the Face? - // TODO: set prevC = '\ufffd'? - continue - } - sr := dr.Sub(dr.Min) - transformer := draw.BiLinear - fx, fy := float64(dr.Min.X), float64(dr.Min.Y) - m := dc.matrix.Translate(fx, fy) - s2d := f64.Aff3{m.XX, m.XY, m.X0, m.YX, m.YY, m.Y0} - transformer.Transform(d.Dst, s2d, d.Src, sr, draw.Over, &draw.Options{ - SrcMask: mask, - SrcMaskP: maskp, - }) - d.Dot.X += advance - prevC = c - } -} - -// DrawString draws the specified text at the specified point. -func (dc *Context) DrawString(s string, x, y float64) { - dc.DrawStringAnchored(s, x, y, 0, 0) -} - -// DrawStringAnchored draws the specified text at the specified anchor point. -// The anchor point is x - w * ax, y - h * ay, where w, h is the size of the -// text. Use ax=0.5, ay=0.5 to center the text at the specified point. -func (dc *Context) DrawStringAnchored(s string, x, y, ax, ay float64) { - w, h := dc.MeasureString(s) - x -= ax * w - y += ay * h - if dc.mask == nil { - dc.drawString(dc.im, s, x, y) - } else { - im := image.NewRGBA(image.Rect(0, 0, dc.width, dc.height)) - dc.drawString(im, s, x, y) - draw.DrawMask(dc.im, dc.im.Bounds(), im, image.ZP, dc.mask, image.ZP, draw.Over) - } -} - -// DrawStringWrapped word-wraps the specified string to the given max width -// and then draws it at the specified anchor point using the given line -// spacing and text alignment. -func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align) { - lines := dc.WordWrap(s, width) - h := float64(len(lines)) * dc.fontHeight * lineSpacing - h -= (lineSpacing - 1) * dc.fontHeight - x -= ax * width - y -= ay * h - switch align { - case AlignLeft: - ax = 0 - case AlignCenter: - ax = 0.5 - x += width / 2 - case AlignRight: - ax = 1 - x += width - } - ay = 1 - for _, line := range lines { - dc.DrawStringAnchored(line, x, y, ax, ay) - y += dc.fontHeight * lineSpacing - } -} - -// MeasureString returns the rendered width and height of the specified text -// given the current font face. -func (dc *Context) MeasureString(s string) (w, h float64) { - d := &font.Drawer{ - Face: dc.fontFace, - } - a := d.MeasureString(s) - return float64(a >> 6), dc.fontHeight -} - -// WordWrap wraps the specified string to the given max width and current -// font face. -func (dc *Context) WordWrap(s string, w float64) []string { - return wordWrap(dc, s, w) -} - -// Transformation Matrix Operations - -// Identity resets the current transformation matrix to the identity matrix. -// This results in no translating, scaling, rotating, or shearing. -func (dc *Context) Identity() { - dc.matrix = Identity() -} - -// Translate updates the current matrix with a translation. -func (dc *Context) Translate(x, y float64) { - dc.matrix = dc.matrix.Translate(x, y) -} - -// Scale updates the current matrix with a scaling factor. -// Scaling occurs about the origin. -func (dc *Context) Scale(x, y float64) { - dc.matrix = dc.matrix.Scale(x, y) -} - -// ScaleAbout updates the current matrix with a scaling factor. -// Scaling occurs about the specified point. -func (dc *Context) ScaleAbout(sx, sy, x, y float64) { - dc.Translate(x, y) - dc.Scale(sx, sy) - dc.Translate(-x, -y) -} - -// Rotate updates the current matrix with a clockwise rotation. -// Rotation occurs about the origin. Angle is specified in radians. -func (dc *Context) Rotate(angle float64) { - dc.matrix = dc.matrix.Rotate(angle) -} - -// RotateAbout updates the current matrix with a clockwise rotation. -// Rotation occurs about the specified point. Angle is specified in radians. -func (dc *Context) RotateAbout(angle, x, y float64) { - dc.Translate(x, y) - dc.Rotate(angle) - dc.Translate(-x, -y) -} - -// Shear updates the current matrix with a shearing angle. -// Shearing occurs about the origin. -func (dc *Context) Shear(x, y float64) { - dc.matrix = dc.matrix.Shear(x, y) -} - -// ShearAbout updates the current matrix with a shearing angle. -// Shearing occurs about the specified point. -func (dc *Context) ShearAbout(sx, sy, x, y float64) { - dc.Translate(x, y) - dc.Shear(sx, sy) - dc.Translate(-x, -y) -} - -// TransformPoint multiplies the specified point by the current matrix, -// returning a transformed position. -func (dc *Context) TransformPoint(x, y float64) (tx, ty float64) { - return dc.matrix.TransformPoint(x, y) -} - -// InvertY flips the Y axis so that Y grows from bottom to top and Y=0 is at -// the bottom of the image. -func (dc *Context) InvertY() { - dc.Translate(0, float64(dc.height)) - dc.Scale(1, -1) -} - -// Stack - -// Push saves the current state of the context for later retrieval. These -// can be nested. -func (dc *Context) Push() { - x := *dc - dc.stack = append(dc.stack, &x) -} - -// Pop restores the last saved context state from the stack. -func (dc *Context) Pop() { - before := *dc - s := dc.stack - x, s := s[len(s)-1], s[:len(s)-1] - *dc = *x - dc.mask = before.mask - dc.strokePath = before.strokePath - dc.fillPath = before.fillPath - dc.start = before.start - dc.current = before.current - dc.hasCurrent = before.hasCurrent -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/gradient.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/gradient.go deleted file mode 100644 index 1625520..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/gradient.go +++ /dev/null @@ -1,202 +0,0 @@ -package gg - -import ( - "image/color" - "math" - "sort" -) - -type stop struct { - pos float64 - color color.Color -} - -type stops []stop - -// Len satisfies the Sort interface. -func (s stops) Len() int { - return len(s) -} - -// Less satisfies the Sort interface. -func (s stops) Less(i, j int) bool { - return s[i].pos < s[j].pos -} - -// Swap satisfies the Sort interface. -func (s stops) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - -type Gradient interface { - Pattern - AddColorStop(offset float64, color color.Color) -} - -// Linear Gradient -type linearGradient struct { - x0, y0, x1, y1 float64 - stops stops -} - -func (g *linearGradient) ColorAt(x, y int) color.Color { - if len(g.stops) == 0 { - return color.Transparent - } - - fx, fy := float64(x), float64(y) - x0, y0, x1, y1 := g.x0, g.y0, g.x1, g.y1 - dx, dy := x1-x0, y1-y0 - - // Horizontal - if dy == 0 && dx != 0 { - return getColor((fx-x0)/dx, g.stops) - } - - // Vertical - if dx == 0 && dy != 0 { - return getColor((fy-y0)/dy, g.stops) - } - - // Dot product - s0 := dx*(fx-x0) + dy*(fy-y0) - if s0 < 0 { - return g.stops[0].color - } - // Calculate distance to (x0,y0) alone (x0,y0)->(x1,y1) - mag := math.Hypot(dx, dy) - u := ((fx-x0)*-dy + (fy-y0)*dx) / (mag * mag) - x2, y2 := x0+u*-dy, y0+u*dx - d := math.Hypot(fx-x2, fy-y2) / mag - return getColor(d, g.stops) -} - -func (g *linearGradient) AddColorStop(offset float64, color color.Color) { - g.stops = append(g.stops, stop{pos: offset, color: color}) - sort.Sort(g.stops) -} - -func NewLinearGradient(x0, y0, x1, y1 float64) Gradient { - g := &linearGradient{ - x0: x0, y0: y0, - x1: x1, y1: y1, - } - return g -} - -// Radial Gradient -type circle struct { - x, y, r float64 -} - -type radialGradient struct { - c0, c1, cd circle - a, inva float64 - mindr float64 - stops stops -} - -func dot3(x0, y0, z0, x1, y1, z1 float64) float64 { - return x0*x1 + y0*y1 + z0*z1 -} - -func (g *radialGradient) ColorAt(x, y int) color.Color { - if len(g.stops) == 0 { - return color.Transparent - } - - // copy from pixman's pixman-radial-gradient.c - - dx, dy := float64(x)+0.5-g.c0.x, float64(y)+0.5-g.c0.y - b := dot3(dx, dy, g.c0.r, g.cd.x, g.cd.y, g.cd.r) - c := dot3(dx, dy, -g.c0.r, dx, dy, g.c0.r) - - if g.a == 0 { - if b == 0 { - return color.Transparent - } - t := 0.5 * c / b - if t*g.cd.r >= g.mindr { - return getColor(t, g.stops) - } - return color.Transparent - } - - discr := dot3(b, g.a, 0, b, -c, 0) - if discr >= 0 { - sqrtdiscr := math.Sqrt(discr) - t0 := (b + sqrtdiscr) * g.inva - t1 := (b - sqrtdiscr) * g.inva - - if t0*g.cd.r >= g.mindr { - return getColor(t0, g.stops) - } else if t1*g.cd.r >= g.mindr { - return getColor(t1, g.stops) - } - } - - return color.Transparent -} - -func (g *radialGradient) AddColorStop(offset float64, color color.Color) { - g.stops = append(g.stops, stop{pos: offset, color: color}) - sort.Sort(g.stops) -} - -func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) Gradient { - c0 := circle{x0, y0, r0} - c1 := circle{x1, y1, r1} - cd := circle{x1 - x0, y1 - y0, r1 - r0} - a := dot3(cd.x, cd.y, -cd.r, cd.x, cd.y, cd.r) - var inva float64 - if a != 0 { - inva = 1.0 / a - } - mindr := -c0.r - g := &radialGradient{ - c0: c0, - c1: c1, - cd: cd, - a: a, - inva: inva, - mindr: mindr, - } - return g -} - -func getColor(pos float64, stops stops) color.Color { - if pos <= 0.0 || len(stops) == 1 { - return stops[0].color - } - - last := stops[len(stops)-1] - - if pos >= last.pos { - return last.color - } - - for i, stop := range stops[1:] { - if pos < stop.pos { - pos = (pos - stops[i].pos) / (stop.pos - stops[i].pos) - return colorLerp(stops[i].color, stop.color, pos) - } - } - - return last.color -} - -func colorLerp(c0, c1 color.Color, t float64) color.Color { - r0, g0, b0, a0 := c0.RGBA() - r1, g1, b1, a1 := c1.RGBA() - - return color.NRGBA{ - lerp(r0, r1, t), - lerp(g0, g1, t), - lerp(b0, b1, t), - lerp(a0, a1, t), - } -} - -func lerp(a, b uint32, t float64) uint8 { - return uint8(int32(float64(a)*(1.0-t)+float64(b)*t) >> 8) -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/matrix.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/matrix.go deleted file mode 100644 index 7d5b312..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/matrix.go +++ /dev/null @@ -1,88 +0,0 @@ -package gg - -import "math" - -type Matrix struct { - XX, YX, XY, YY, X0, Y0 float64 -} - -func Identity() Matrix { - return Matrix{ - 1, 0, - 0, 1, - 0, 0, - } -} - -func Translate(x, y float64) Matrix { - return Matrix{ - 1, 0, - 0, 1, - x, y, - } -} - -func Scale(x, y float64) Matrix { - return Matrix{ - x, 0, - 0, y, - 0, 0, - } -} - -func Rotate(angle float64) Matrix { - c := math.Cos(angle) - s := math.Sin(angle) - return Matrix{ - c, s, - -s, c, - 0, 0, - } -} - -func Shear(x, y float64) Matrix { - return Matrix{ - 1, y, - x, 1, - 0, 0, - } -} - -func (a Matrix) Multiply(b Matrix) Matrix { - return Matrix{ - a.XX*b.XX + a.YX*b.XY, - a.XX*b.YX + a.YX*b.YY, - a.XY*b.XX + a.YY*b.XY, - a.XY*b.YX + a.YY*b.YY, - a.X0*b.XX + a.Y0*b.XY + b.X0, - a.X0*b.YX + a.Y0*b.YY + b.Y0, - } -} - -func (a Matrix) TransformVector(x, y float64) (tx, ty float64) { - tx = a.XX*x + a.XY*y - ty = a.YX*x + a.YY*y - return -} - -func (a Matrix) TransformPoint(x, y float64) (tx, ty float64) { - tx = a.XX*x + a.XY*y + a.X0 - ty = a.YX*x + a.YY*y + a.Y0 - return -} - -func (a Matrix) Translate(x, y float64) Matrix { - return Translate(x, y).Multiply(a) -} - -func (a Matrix) Scale(x, y float64) Matrix { - return Scale(x, y).Multiply(a) -} - -func (a Matrix) Rotate(angle float64) Matrix { - return Rotate(angle).Multiply(a) -} - -func (a Matrix) Shear(x, y float64) Matrix { - return Shear(x, y).Multiply(a) -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/path.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/path.go deleted file mode 100644 index 74785b6..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/path.go +++ /dev/null @@ -1,140 +0,0 @@ -package gg - -import ( - "github.com/golang/freetype/raster" - "golang.org/x/image/math/fixed" -) - -func flattenPath(p raster.Path) [][]Point { - var result [][]Point - var path []Point - var cx, cy float64 - for i := 0; i < len(p); { - switch p[i] { - case 0: - if len(path) > 0 { - result = append(result, path) - path = nil - } - x := unfix(p[i+1]) - y := unfix(p[i+2]) - path = append(path, Point{x, y}) - cx, cy = x, y - i += 4 - case 1: - x := unfix(p[i+1]) - y := unfix(p[i+2]) - path = append(path, Point{x, y}) - cx, cy = x, y - i += 4 - case 2: - x1 := unfix(p[i+1]) - y1 := unfix(p[i+2]) - x2 := unfix(p[i+3]) - y2 := unfix(p[i+4]) - points := QuadraticBezier(cx, cy, x1, y1, x2, y2) - path = append(path, points...) - cx, cy = x2, y2 - i += 6 - case 3: - x1 := unfix(p[i+1]) - y1 := unfix(p[i+2]) - x2 := unfix(p[i+3]) - y2 := unfix(p[i+4]) - x3 := unfix(p[i+5]) - y3 := unfix(p[i+6]) - points := CubicBezier(cx, cy, x1, y1, x2, y2, x3, y3) - path = append(path, points...) - cx, cy = x3, y3 - i += 8 - default: - panic("bad path") - } - } - if len(path) > 0 { - result = append(result, path) - } - return result -} - -func dashPath(paths [][]Point, dashes []float64) [][]Point { - var result [][]Point - if len(dashes) == 0 { - return paths - } - if len(dashes) == 1 { - dashes = append(dashes, dashes[0]) - } - for _, path := range paths { - if len(path) < 2 { - continue - } - previous := path[0] - pathIndex := 1 - dashIndex := 0 - segmentLength := 0.0 - var segment []Point - segment = append(segment, previous) - for pathIndex < len(path) { - dashLength := dashes[dashIndex] - point := path[pathIndex] - d := previous.Distance(point) - maxd := dashLength - segmentLength - if d > maxd { - t := maxd / d - p := previous.Interpolate(point, t) - segment = append(segment, p) - if dashIndex%2 == 0 && len(segment) > 1 { - result = append(result, segment) - } - segment = nil - segment = append(segment, p) - segmentLength = 0 - previous = p - dashIndex = (dashIndex + 1) % len(dashes) - } else { - segment = append(segment, point) - previous = point - segmentLength += d - pathIndex++ - } - } - if dashIndex%2 == 0 && len(segment) > 1 { - result = append(result, segment) - } - } - return result -} - -func rasterPath(paths [][]Point) raster.Path { - var result raster.Path - for _, path := range paths { - var previous fixed.Point26_6 - for i, point := range path { - f := point.Fixed() - if i == 0 { - result.Start(f) - } else { - dx := f.X - previous.X - dy := f.Y - previous.Y - if dx < 0 { - dx = -dx - } - if dy < 0 { - dy = -dy - } - if dx+dy > 8 { - // TODO: this is a hack for cases where two points are - // too close - causes rendering issues with joins / caps - result.Add1(f) - } - } - previous = f - } - } - return result -} - -func dashed(path raster.Path, dashes []float64) raster.Path { - return rasterPath(dashPath(flattenPath(path), dashes)) -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/pattern.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/pattern.go deleted file mode 100644 index 6b396ec..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/pattern.go +++ /dev/null @@ -1,123 +0,0 @@ -package gg - -import ( - "image" - "image/color" - - "github.com/golang/freetype/raster" -) - -type RepeatOp int - -const ( - RepeatBoth RepeatOp = iota - RepeatX - RepeatY - RepeatNone -) - -type Pattern interface { - ColorAt(x, y int) color.Color -} - -// Solid Pattern -type solidPattern struct { - color color.Color -} - -func (p *solidPattern) ColorAt(x, y int) color.Color { - return p.color -} - -func NewSolidPattern(color color.Color) Pattern { - return &solidPattern{color: color} -} - -// Surface Pattern -type surfacePattern struct { - im image.Image - op RepeatOp -} - -func (p *surfacePattern) ColorAt(x, y int) color.Color { - b := p.im.Bounds() - switch p.op { - case RepeatX: - if y >= b.Dy() { - return color.Transparent - } - case RepeatY: - if x >= b.Dx() { - return color.Transparent - } - case RepeatNone: - if x >= b.Dx() || y >= b.Dy() { - return color.Transparent - } - } - x = x%b.Dx() + b.Min.X - y = y%b.Dy() + b.Min.Y - return p.im.At(x, y) -} - -func NewSurfacePattern(im image.Image, op RepeatOp) Pattern { - return &surfacePattern{im: im, op: op} -} - -type patternPainter struct { - im *image.RGBA - mask *image.Alpha - p Pattern -} - -// Paint satisfies the Painter interface. -func (r *patternPainter) Paint(ss []raster.Span, done bool) { - b := r.im.Bounds() - for _, s := range ss { - if s.Y < b.Min.Y { - continue - } - if s.Y >= b.Max.Y { - return - } - if s.X0 < b.Min.X { - s.X0 = b.Min.X - } - if s.X1 > b.Max.X { - s.X1 = b.Max.X - } - if s.X0 >= s.X1 { - continue - } - const m = 1<<16 - 1 - y := s.Y - r.im.Rect.Min.Y - x0 := s.X0 - r.im.Rect.Min.X - // RGBAPainter.Paint() in $GOPATH/src/github.com/golang/freetype/raster/paint.go - i0 := (s.Y-r.im.Rect.Min.Y)*r.im.Stride + (s.X0-r.im.Rect.Min.X)*4 - i1 := i0 + (s.X1-s.X0)*4 - for i, x := i0, x0; i < i1; i, x = i+4, x+1 { - ma := s.Alpha - if r.mask != nil { - ma = ma * uint32(r.mask.AlphaAt(x, y).A) / 255 - if ma == 0 { - continue - } - } - c := r.p.ColorAt(x, y) - cr, cg, cb, ca := c.RGBA() - dr := uint32(r.im.Pix[i+0]) - dg := uint32(r.im.Pix[i+1]) - db := uint32(r.im.Pix[i+2]) - da := uint32(r.im.Pix[i+3]) - a := (m - (ca * ma / m)) * 0x101 - r.im.Pix[i+0] = uint8((dr*a + cr*ma) / m >> 8) - r.im.Pix[i+1] = uint8((dg*a + cg*ma) / m >> 8) - r.im.Pix[i+2] = uint8((db*a + cb*ma) / m >> 8) - r.im.Pix[i+3] = uint8((da*a + ca*ma) / m >> 8) - } - } -} - -func newPatternPainter(im *image.RGBA, mask *image.Alpha, p Pattern) *patternPainter { - return &patternPainter{im, mask, p} -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/point.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/point.go deleted file mode 100644 index d258653..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/point.go +++ /dev/null @@ -1,25 +0,0 @@ -package gg - -import ( - "math" - - "golang.org/x/image/math/fixed" -) - -type Point struct { - X, Y float64 -} - -func (a Point) Fixed() fixed.Point26_6 { - return fixp(a.X, a.Y) -} - -func (a Point) Distance(b Point) float64 { - return math.Hypot(a.X-b.X, a.Y-b.Y) -} - -func (a Point) Interpolate(b Point, t float64) Point { - x := a.X + (b.X-a.X)*t - y := a.Y + (b.Y-a.Y)*t - return Point{x, y} -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/util.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/util.go deleted file mode 100644 index a530fcb..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/util.go +++ /dev/null @@ -1,117 +0,0 @@ -package gg - -import ( - "fmt" - "image" - "image/draw" - _ "image/jpeg" - "image/png" - "io/ioutil" - "math" - "os" - "strings" - - "github.com/golang/freetype/truetype" - - "golang.org/x/image/font" - "golang.org/x/image/math/fixed" -) - -func Radians(degrees float64) float64 { - return degrees * math.Pi / 180 -} - -func Degrees(radians float64) float64 { - return radians * 180 / math.Pi -} - -func LoadImage(path string) (image.Image, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - im, _, err := image.Decode(file) - return im, err -} - -func LoadPNG(path string) (image.Image, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - return png.Decode(file) -} - -func SavePNG(path string, im image.Image) error { - file, err := os.Create(path) - if err != nil { - return err - } - defer file.Close() - return png.Encode(file, im) -} - -func imageToRGBA(src image.Image) *image.RGBA { - dst := image.NewRGBA(src.Bounds()) - draw.Draw(dst, dst.Rect, src, image.ZP, 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 fixp(x, y float64) fixed.Point26_6 { - return fixed.Point26_6{fix(x), fix(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 -} - -func LoadFontFace(path string, points float64) (font.Face, error) { - fontBytes, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - f, err := truetype.Parse(fontBytes) - if err != nil { - return nil, err - } - face := truetype.NewFace(f, &truetype.Options{ - Size: points, - // Hinting: font.HintingFull, - }) - return face, nil -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/wrap.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/wrap.go deleted file mode 100644 index 3dfe6e1..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/gg/wrap.go +++ /dev/null @@ -1,58 +0,0 @@ -package gg - -import ( - "strings" - "unicode" -) - -type measureStringer interface { - MeasureString(s string) (w, h float64) -} - -func splitOnSpace(x string) []string { - var result []string - pi := 0 - ps := false - for i, c := range x { - s := unicode.IsSpace(c) - if s != ps && i > 0 { - result = append(result, x[pi:i]) - pi = i - } - ps = s - } - result = append(result, x[pi:]) - return result -} - -func wordWrap(m measureStringer, s string, width float64) []string { - var result []string - for _, line := range strings.Split(s, "\n") { - fields := splitOnSpace(line) - if len(fields)%2 == 1 { - fields = append(fields, "") - } - x := "" - for i := 0; i < len(fields); i += 2 { - w, _ := m.MeasureString(x + fields[i]) - if w > width { - if x == "" { - result = append(result, fields[i]) - x = "" - continue - } else { - result = append(result, x) - x = "" - } - } - x += fields[i] + fields[i+1] - } - if x != "" { - result = append(result, x) - } - } - for i, line := range result { - result[i] = strings.TrimSpace(line) - } - return result -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/color.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/color.go deleted file mode 100644 index 2828957..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/color.go +++ /dev/null @@ -1,44 +0,0 @@ -package primitive - -import ( - "fmt" - "image/color" - "strings" -) - -type Color struct { - R, G, B, A int -} - -func MakeColor(c color.Color) Color { - r, g, b, a := c.RGBA() - return Color{int(r / 257), int(g / 257), int(b / 257), int(a / 257)} -} - -func MakeHexColor(x string) Color { - x = strings.Trim(x, "#") - var r, g, b, a int - a = 255 - switch len(x) { - case 3: - fmt.Sscanf(x, "%1x%1x%1x", &r, &g, &b) - r = (r << 4) | r - g = (g << 4) | g - b = (b << 4) | b - case 4: - fmt.Sscanf(x, "%1x%1x%1x%1x", &r, &g, &b, &a) - r = (r << 4) | r - g = (g << 4) | g - b = (b << 4) | b - a = (a << 4) | a - case 6: - fmt.Sscanf(x, "%02x%02x%02x", &r, &g, &b) - case 8: - fmt.Sscanf(x, "%02x%02x%02x%02x", &r, &g, &b, &a) - } - return Color{r, g, b, a} -} - -func (c *Color) NRGBA() color.NRGBA { - return color.NRGBA{uint8(c.R), uint8(c.G), uint8(c.B), uint8(c.A)} -} diff --git a/farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/core.go b/farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/core.go deleted file mode 100644 index 5a0c0aa..0000000 --- a/farbfeld/ff-primitive/vendor/github.com/fogleman/primitive/primitive/core.go +++ /dev/null @@ -1,124 +0,0 @@ -package primitive - -import ( - "image" - "math" -) - -func computeColor(target, current *image.RGBA, lines []Scanline, alpha int) Color { - var rsum, gsum, bsum, count int64 - a := 0x101 * 255 / alpha - for _, line := range lines { - i := target.PixOffset(line.X1, line.Y) - for x := line.X1; x <= line.X2; x++ { - tr := int(target.Pix[i]) - tg := int(target.Pix[i+1]) - tb := int(target.Pix[i+2]) - cr := int(current.Pix[i]) - cg := int(current.Pix[i+1]) - cb := int(current.Pix[i+2]) - i += 4 - rsum += int64((tr-cr)*a + cr*0x101) - gsum += int64((tg-cg)*a + cg*0x101) - bsum += int64((tb-cb)*a + cb*0x101) - count++ - } - } - if count == 0 { - return Color{} - } - r := clampInt(int(rsum/count)>>8, 0, 255) - g := clampInt(int(gsum/count)>>8, 0, 255) - b := clampInt(int(bsum/count)>>8, 0, 255) - return Color{r, g, b, alpha} -} - -func copyLines(dst, src *image.RGBA, lines []Scanline) { - for _, line := range lines { - a := dst.PixOffset(line.X1, line.Y) - b := a + (line.X2-line.X1+1)*4 - copy(dst.Pix[a:b], src.Pix[a:b]) - } -} - -func drawLines(im *image.RGBA, c Color, lines []Scanline) { - const m = 0xffff - sr, sg, sb, sa := c.NRGBA().RGBA() - for _, line := range lines { - ma := line.Alpha - a := (m - sa*ma/m) * 0x101 - i := im.PixOffset(line.X1, line.Y) - for x := line.X1; x <= line.X2; x++ { - dr := uint32(im.Pix[i+0]) - dg := uint32(im.Pix[i+1]) - db := uint32(im.Pix[i+2]) - da := uint32(im.Pix[i+3]) - im.Pix[i+0] = uint8((dr*a + sr*ma) / m >> 8) - im.Pix[i+1] = uint8((dg*a + sg*ma) / m >> 8) - im.Pix[i+2] = uint8((db*a + sb*ma) / m >> 8) - im.Pix[i+3] = uint8((da*a + sa*ma) / m >> 8) - i += 4 - } - } -} - -func differenceFull(a, b *image.RGBA) float64 { - size := a.Bounds().Size() - w, h := size.X, size.Y - var total uint64 - for y := 0; y < h; y++ { - i := a.PixOffset(0, y) - for x := 0; x < w; x++ { - ar := int(a.Pix[i]) - ag := int(a.Pix[i+1]) - ab := int(a.Pix[i+2]) - aa := int(a.Pix[i+3]) - br := int(b.Pix[i]) - bg := i