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

Feature/encode kwarg changes #8

Merged
merged 2 commits into from
Apr 21, 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
3 changes: 1 addition & 2 deletions src/encoding.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function encode(
image::AbstractMatrix{TColor}; quality::Union{Int, Nothing} = nothing, transpose = false
image::AbstractMatrix{TColor}; lossy = false, quality::Real = 75, transpose = false
)::Vector{UInt8} where {TColor <: Colorant}
lossy = !isnothing(quality)
if lossy && !(0 ≤ quality ≤ 100)
throw(ArgumentError("Quality $quality is not in the range from 0 to 100."))
end
Expand Down
15 changes: 11 additions & 4 deletions test/encoding_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ using WebP

@testset "Lossy" begin
@testset "encode throws ArgumentError for quality outside range" begin
@test_throws ArgumentError WebP.encode(input_image; quality = -1)
@test_throws ArgumentError WebP.encode(input_image; quality = 101)
@test_throws ArgumentError WebP.encode(
input_image; lossy = true, quality = -1
)
@test_throws ArgumentError WebP.encode(
input_image; lossy = true, quality = 101
)
end
qualities = [1, 10, 50, 100]
for quality in qualities
input_kwargs = merge(kwargs, (quality = quality,))
quality_types = [Int, Float32, Float64]
for quality in qualities, TQuality in quality_types
input_kwargs = merge(
kwargs, (lossy = true, quality = TQuality(quality))
)
@testset "WebP.encode(::Matrix{$TColor}; $input_kwargs)" begin
data = WebP.encode(input_image; input_kwargs...)
output = WebP.decode(data)
Expand Down
Loading