Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc updates #12

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 40 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
on: [push, pull_request]
on:
push:
branches: [master]
pull_request:
name: Test
permissions:
contents: read
jobs:
test:
strategy:
matrix:
go-version: [1.20.x, 1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
go-version: [1.21.x, 1.22.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test Linux
if: matrix.os == 'ubuntu-latest'
run: go test -race ./libwebp -coverprofile=coverage.txt -covermode=atomic
- name: Test Other
if: matrix.os != 'ubuntu-latest'
run: go test ./libwebp
- 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
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Install golint
run: go install golang.org/x/lint/golint@latest
shell: bash
- name: Update PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@v4
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
- name: Staticcheck
run: staticcheck ./...
- name: Lint
run: golint ./...
- name: Test
run: go test -race ./libwebp -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![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.3.2-blue)](https://github.com/webmproject/libwebp)
[![libwebp Version](https://img.shields.io/badge/libwebp-v1.4.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)

Expand Down
6 changes: 2 additions & 4 deletions gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand All @@ -30,7 +29,7 @@ func main() {
// directory.
//
// The custom bindings are named with a "a__" prefix. Keep those.
fis, err := ioutil.ReadDir(dstDir)
fis, err := os.ReadDir(dstDir)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -61,7 +60,7 @@ func main() {
filename = strings.TrimPrefix(filename, "/")
target := filepath.Join(dstDir, fi.Name())

if err := ioutil.WriteFile(target, []byte(fmt.Sprintf(`#ifndef LIBWEBP_NO_SRC
if err := os.WriteFile(target, []byte(fmt.Sprintf(`#ifndef LIBWEBP_NO_SRC
#include "../../libwebp_src/%s"
#endif
`, filename)), 0o644); err != nil {
Expand All @@ -70,7 +69,6 @@ func main() {

return nil
})

if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/bep/gowebp

go 1.16
go 1.20

require golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
1 change: 0 additions & 1 deletion internal/libwebp/a__encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
)

type (
Encoder struct {

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, windows-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, windows-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, windows-latest)

exported type Encoder should have comment or be unexported

Check failure on line 98 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, windows-latest)

exported type Encoder should have comment or be unexported
config *C.WebPConfig
img *image.NRGBA
}
Expand All @@ -105,7 +105,6 @@
//
// 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 Expand Up @@ -169,7 +168,7 @@
return err
}

func ConvertToNRGBA(src image.Image) *image.NRGBA {

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, windows-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, windows-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, windows-latest)

exported function ConvertToNRGBA should have comment or be unexported

Check failure on line 171 in internal/libwebp/a__encoder.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, windows-latest)

exported function ConvertToNRGBA should have comment or be unexported
dst := image.NewNRGBA(src.Bounds())
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)

Expand Down
3 changes: 3 additions & 0 deletions internal/libwebp/palette.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef LIBWEBP_NO_SRC
#include "../../libwebp_src/src/utils/palette.c"
#endif
3 changes: 3 additions & 0 deletions internal/libwebp/palette.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef LIBWEBP_NO_SRC
#include "../../libwebp_src/src/utils/palette.h"
#endif
1 change: 0 additions & 1 deletion libwebp/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
//
// 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)
}
8 changes: 3 additions & 5 deletions libwebp/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"image"
"image/draw"
"image/jpeg"
_ "image/jpeg"
_ "image/png"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -108,7 +106,7 @@ func TestEncodeLongRunning(t *testing.T) {
t.Fatal(err)
}

if err = Encode(ioutil.Discard, img, test.opts); err != nil {
if err = Encode(io.Discard, img, test.opts); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -138,7 +136,7 @@ func BenchmarkEncode(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
if err = Encode(ioutil.Discard, imgrgba, test.opts); err != nil {
if err = Encode(io.Discard, imgrgba, test.opts); err != nil {
b.Fatal(err)
}
}
Expand All @@ -163,7 +161,7 @@ func BenchmarkEncodeJpeg(b *testing.B) {
}

for i := 0; i < b.N; i++ {
if err = jpeg.Encode(ioutil.Discard, img, opts); err != nil {
if err = jpeg.Encode(io.Discard, img, opts); err != nil {
b.Fatal(err)
}
}
Expand Down
7 changes: 7 additions & 0 deletions libwebp_src/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Contributors:
- Aidan O'Loan (aidanol at gmail dot com)
- Alan Browning (browning at google dot com)
- Alexandru Ardelean (ardeleanalex at gmail dot com)
- Anuraag Agrawal (anuraaga at gmail dot com)
- Arthur Eubanks (aeubanks at google dot com)
- Brian Ledger (brianpl at google dot com)
- Charles Munger (clm at google dot com)
- Cheng Yi (cyi at google dot com)
Expand All @@ -19,6 +21,8 @@ Contributors:
- Jehan (jehan at girinstud dot io)
- Jeremy Maitin-Shepard (jbms at google dot com)
- Johann Koenig (johann dot koenig at duck dot com)
- Jonathan Grant (jgrantinfotech at gmail dot com)
- Jonliu1993 (13720414433 at 163 dot com)
- Jovan Zelincevic (jovan dot zelincevic at imgtec dot com)
- Jyrki Alakuijala (jyrki at google dot com)
- Konstantin Ivlev (tomskside at gmail dot com)
Expand All @@ -28,13 +32,16 @@ Contributors:
- Marcin Kowalczyk (qrczak at google dot com)
- Martin Olsson (mnemo at minimum dot se)
- Maryla Ustarroz-Calonge (maryla at google dot com)
- Masahiro Hanada (hanada at atmark-techno dot com)
- Mikołaj Zalewski (mikolajz at google dot com)
- Mislav Bradac (mislavm at google dot com)
- natewood (natewood at fb dot com)
- Nico Weber (thakis at chromium dot org)
- Noel Chromium (noel at chromium dot org)
- Nozomi Isozaki (nontan at pixiv dot co dot jp)
- Oliver Wolff (oliver dot wolff at qt dot io)
- Owen Rodley (orodley at google dot com)
- Ozkan Sezer (sezeroz at gmail dot com)
- Parag Salasakar (img dot mips1 at gmail dot com)
- Pascal Massimino (pascal dot massimino at gmail dot com)
- Paweł Hajdan, Jr (phajdan dot jr at chromium dot org)
Expand Down
1 change: 1 addition & 0 deletions libwebp_src/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ utils_dec_srcs := \
src/utils/color_cache_utils.c \
src/utils/filters_utils.c \
src/utils/huffman_utils.c \
src/utils/palette.c \
src/utils/quant_levels_dec_utils.c \
src/utils/random_utils.c \
src/utils/rescaler_utils.c \
Expand Down
70 changes: 58 additions & 12 deletions libwebp_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ option(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces."
OFF)
set(WEBP_BITTRACE "0" CACHE STRING "Bit trace mode (0=none, 1=bit, 2=bytes)")
set_property(CACHE WEBP_BITTRACE PROPERTY STRINGS 0 1 2)
option(WEBP_ENABLE_WUNUSED_RESULT "Add [[nodiscard]] to some functions. \
CMake must be at least 3.21 to force C23" OFF)

if(WEBP_LINK_STATIC)
if(WIN32)
Expand Down Expand Up @@ -133,7 +135,7 @@ if(WEBP_UNICODE)
add_definitions(-DUNICODE -D_UNICODE)
endif()

if(MSVC AND BUILD_SHARED_LIBS)
if(WIN32 AND BUILD_SHARED_LIBS)
add_definitions(-DWEBP_DLL)
endif()

Expand Down Expand Up @@ -161,7 +163,20 @@ if(MSVC)
set(CMAKE_STATIC_LIBRARY_PREFIX "${webp_libname_prefix}")
endif()

set(CMAKE_C_VISIBILITY_PRESET hidden)
if(NOT WIN32)
set(CMAKE_C_VISIBILITY_PRESET hidden)
endif()

if(WEBP_ENABLE_WUNUSED_RESULT)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0)
set(CMAKE_C_STANDARD 23)
else()
unset(CMAKE_C_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-std=gnu2x>)
endif()
add_compile_options(-Wunused-result)
add_definitions(-DWEBP_ENABLE_NODISCARD=1)
endif()

# ##############################################################################
# Android only.
Expand Down Expand Up @@ -463,6 +478,7 @@ endif()
if(WEBP_BUILD_ANIM_UTILS
OR WEBP_BUILD_CWEBP
OR WEBP_BUILD_DWEBP
OR WEBP_BUILD_EXTRAS
OR WEBP_BUILD_GIF2WEBP
OR WEBP_BUILD_IMG2WEBP
OR WEBP_BUILD_VWEBP
Expand Down Expand Up @@ -499,6 +515,8 @@ if(WEBP_BUILD_ANIM_UTILS
TARGET exampleutil imageioutil imagedec imageenc
PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/src)
target_include_directories(imagedec PRIVATE ${WEBP_DEP_IMG_INCLUDE_DIRS})
target_include_directories(imageenc PRIVATE ${WEBP_DEP_IMG_INCLUDE_DIRS})
endif()

if(WEBP_BUILD_DWEBP)
Expand Down Expand Up @@ -638,15 +656,30 @@ if(WEBP_BUILD_EXTRAS)
${CMAKE_CURRENT_BINARY_DIR})

# vwebp_sdl
find_package(SDL)
if(WEBP_BUILD_VWEBP AND SDL_FOUND)
find_package(SDL2 QUIET)
if(WEBP_BUILD_VWEBP AND SDL2_FOUND)
add_executable(vwebp_sdl ${VWEBP_SDL_SRCS})
target_link_libraries(vwebp_sdl ${SDL_LIBRARY} imageioutil webp)
target_link_libraries(vwebp_sdl ${SDL2_LIBRARIES} imageioutil webp)
target_include_directories(
vwebp_sdl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/src ${SDL_INCLUDE_DIR})
${CMAKE_CURRENT_BINARY_DIR}/src ${SDL2_INCLUDE_DIRS})
set(WEBP_HAVE_SDL 1)
target_compile_definitions(vwebp_sdl PUBLIC WEBP_HAVE_SDL)

set(CMAKE_REQUIRED_INCLUDES "${SDL2_INCLUDE_DIRS}")
check_c_source_compiles(
"
#define SDL_MAIN_HANDLED
#include \"SDL.h\"
int main(void) {
return 0;
}
"
HAVE_JUST_SDL_H)
set(CMAKE_REQUIRED_INCLUDES)
if(HAVE_JUST_SDL_H)
target_compile_definitions(vwebp_sdl PRIVATE WEBP_HAVE_JUST_SDL_H)
endif()
endif()
endif()

Expand All @@ -661,31 +694,44 @@ if(WEBP_BUILD_WEBP_JS)
else()
set(emscripten_stack_size "-sTOTAL_STACK=5MB")
endif()
find_package(SDL2 REQUIRED)
# wasm2js does not support SIMD.
if(NOT WEBP_ENABLE_SIMD)
# JavaScript version
add_executable(webp_js ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
target_link_libraries(webp_js webpdecoder SDL)
target_link_libraries(webp_js webpdecoder SDL2)
target_include_directories(webp_js PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
set(WEBP_HAVE_SDL 1)
set_target_properties(
webp_js
PROPERTIES LINK_FLAGS "-sWASM=0 ${emscripten_stack_size} \
PROPERTIES
# Emscripten puts -sUSE_SDL2=1 in this variable, though it's needed at
# compile time to ensure the headers are downloaded.
COMPILE_OPTIONS "${SDL2_LIBRARIES}"
LINK_FLAGS
"-sWASM=0 ${emscripten_stack_size} \
-sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \
-sEXPORTED_RUNTIME_METHODS=cwrap")
-sEXPORTED_RUNTIME_METHODS=cwrap ${SDL2_LIBRARIES} \
-sALLOW_MEMORY_GROWTH")
set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp)
target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)
endif()

# WASM version
add_executable(webp_wasm ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
target_link_libraries(webp_wasm webpdecoder SDL)
target_link_libraries(webp_wasm webpdecoder SDL2)
target_include_directories(webp_wasm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(
webp_wasm
PROPERTIES LINK_FLAGS "-sWASM=1 ${emscripten_stack_size} \
PROPERTIES
# Emscripten puts -sUSE_SDL2=1 in this variable, though it's needed at
# compile time to ensure the headers are downloaded.
COMPILE_OPTIONS "${SDL2_LIBRARIES}"
LINK_FLAGS
"-sWASM=1 ${emscripten_stack_size} \
-sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \
-sEXPORTED_RUNTIME_METHODS=cwrap")
-sEXPORTED_RUNTIME_METHODS=cwrap ${SDL2_LIBRARIES} \
-sALLOW_MEMORY_GROWTH")
target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)

target_compile_definitions(webpdspdecode PUBLIC EMSCRIPTEN)
Expand Down
Loading
Loading