diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..82f3f17 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [bep] \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9ed560d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +on: [push, pull_request] +name: Test +jobs: + test: + strategy: + matrix: + go-version: [1.16.x] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Test + run: go test -race ./libwebp -coverprofile=coverage.txt -covermode=atomic + - name: Upload coverage + if: success() && matrix.os == 'ubuntu-latest' + run: | + curl -s https://codecov.io/bash | bash + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + shell: bash \ No newline at end of file diff --git a/FUNDING.yml b/FUNDING.yml new file mode 100644 index 0000000..82f3f17 --- /dev/null +++ b/FUNDING.yml @@ -0,0 +1 @@ +github: [bep] \ No newline at end of file diff --git a/README.md b/README.md index d309ca4..8c79516 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![Go Report Card](https://goreportcard.com/badge/github.com/bep/golibwebp)](https://goreportcard.com/report/github.com/bep/golibwebp) -[![libwebp Version](https://img.shields.io/badge/libwebp-v1.2.0-blue)](https://github.com/sass/libwebp) -[![codecov](https://codecov.io/gh/bep/golibwebp/branch/master/graph/badge.svg)](https://codecov.io/gh/bep/golibwebp) -[![GoDoc](https://godoc.org/github.com/bep/golibwebp/libwebp?status.svg)](https://godoc.org/github.com/bep/golibwebp/libwebp) +[![Go Report Card](https://goreportcard.com/badge/github.com/bep/gowebp)](https://goreportcard.com/report/github.com/bep/gowebp) +[![libwebp Version](https://img.shields.io/badge/libwebp-v1.2.0-blue)](https://github.com/webmproject/libwebp) +[![codecov](https://codecov.io/gh/bep/gowebp/branch/master/graph/badge.svg)](https://codecov.io/gh/bep/gowebp) +[![GoDoc](https://godoc.org/github.com/bep/gowebp/libwebp?status.svg)](https://godoc.org/github.com/bep/gowebp/libwebp) This library provides C bindings and an API for **encoding** Webp images using Google's [libwebp](https://github.com/webmproject/libwebp). diff --git a/internal/libwebp/a__encoder.go b/internal/libwebp/a__encoder.go index e020327..0df2124 100644 --- a/internal/libwebp/a__encoder.go +++ b/internal/libwebp/a__encoder.go @@ -103,8 +103,9 @@ type ( // Encode encodes src into w considering the options in o. // -// TODO(bep) Can we handle *image.YCbCr without conversion? -// TODO(bep) check filled alpha channel. +// Any src that isn't one of *image.RGBA, *image.NRGBA, or *image.Gray +// will be converted to *image.NRGBA using draw.Draw first. +// func Encode(w io.Writer, src image.Image, o webpoptions.EncodingOptions) error { config, err := encodingOptionsToCConfig(o) if err != nil { diff --git a/libwebp/encode.go b/libwebp/encode.go index 55be8c1..370ac61 100644 --- a/libwebp/encode.go +++ b/libwebp/encode.go @@ -10,6 +10,10 @@ import ( ) // Encode encodes src as Webp into w using the options in o. +// +// Any src that isn't one of *image.RGBA, *image.NRGBA, or *image.Gray +// will be converted to *image.NRGBA using draw.Draw first. +// func Encode(w io.Writer, src image.Image, o webpoptions.EncodingOptions) error { return libwebp.Encode(w, src, o) } diff --git a/libwebp/encode_test.go b/libwebp/encode_test.go index 4d617ac..ede113b 100644 --- a/libwebp/encode_test.go +++ b/libwebp/encode_test.go @@ -30,13 +30,13 @@ type testCase struct { } var testCases = []testCase{ - {"lossy", "source.jpg", webpoptions.EncodingOptions{Quality: 75, EncodingPreset: webpoptions.EncodingPresetPhoto, UseSharpYuv: true}}, + {"lossy", "sunset.jpg", webpoptions.EncodingOptions{Quality: 75, EncodingPreset: webpoptions.EncodingPresetPhoto, UseSharpYuv: true}}, {"lossless", "source.jpg", webpoptions.EncodingOptions{}}, {"bw", "bw-gopher.png", webpoptions.EncodingOptions{Quality: 75}}, } func TestEncode(t *testing.T) { - writeGolden := false + writeGolden := true for _, test := range testCases { t.Run(test.name, func(t *testing.T) { r, err := os.Open(filepath.Join("../test_data/images", test.inputFile)) diff --git a/test_data/images/golden/source-lossless.webp b/test_data/images/golden/source-lossless.webp index 9884933..abdeda0 100644 Binary files a/test_data/images/golden/source-lossless.webp and b/test_data/images/golden/source-lossless.webp differ diff --git a/test_data/images/golden/source-lossy.webp b/test_data/images/golden/source-lossy.webp deleted file mode 100644 index 695b743..0000000 Binary files a/test_data/images/golden/source-lossy.webp and /dev/null differ diff --git a/test_data/images/golden/sunset-lossy.webp b/test_data/images/golden/sunset-lossy.webp new file mode 100644 index 0000000..80d3aa8 Binary files /dev/null and b/test_data/images/golden/sunset-lossy.webp differ diff --git a/test_data/images/sunset.jpg b/test_data/images/sunset.jpg new file mode 100644 index 0000000..6281662 Binary files /dev/null and b/test_data/images/sunset.jpg differ