Skip to content

Commit

Permalink
Add GitHub test action etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 12, 2021
1 parent 38d8f20 commit 20d9cfe
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [bep]
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [bep]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
5 changes: 3 additions & 2 deletions internal/libwebp/a__encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions libwebp/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions libwebp/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Binary file modified test_data/images/golden/source-lossless.webp
Binary file not shown.
Binary file removed test_data/images/golden/source-lossy.webp
Binary file not shown.
Binary file added test_data/images/golden/sunset-lossy.webp
Binary file not shown.
Binary file added test_data/images/sunset.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 20d9cfe

Please sign in to comment.