Skip to content

Commit

Permalink
fixup encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
stemann committed Apr 10, 2024
1 parent 030180f commit b717f27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/encoding.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function encode(
image::Matrix{TColor}; lossy = false, quality = 70, transpose = false
image::Matrix{TColor}; quality::Union{Int, Nothing} = nothing, transpose = false
)::Vector{UInt8} where {TColor <: Colorant}
lossy = !isnothing(quality)
if TColor == RGB{N0f8}
webp_encode_fn = lossy ? Wrapper.WebPEncodeRGB : Wrapper.WebPEncodeLosslessRGB
elseif TColor == BGR{N0f8}
Expand All @@ -13,7 +14,6 @@ function encode(
throw(ArgumentError("Unsupported color type: $TColor"))
end

quality_factor = quality / 100.0f0
if !transpose # TODO the kwarg transpose is quite confusing/misleading
image = permutedims(image, (2, 1))
end
Expand All @@ -22,6 +22,7 @@ function encode(
stride = width * sizeof(TColor)
output_ptr = Ref{Ptr{UInt8}}()
if lossy
quality_factor = quality / 100.0f0
output_length = webp_encode_fn(
pointer(image), width, height, stride, quality_factor, output_ptr
)
Expand Down
2 changes: 1 addition & 1 deletion test/encoding_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using WebP
@testset "Lossy" begin
qualities = [1, 10, 50, 100]
for quality in qualities
input_kwargs = merge(kwargs, (lossy = true, quality = quality))
input_kwargs = merge(kwargs, (quality = quality,))
@testset "WebP.encode(::Matrix{$TColor}; $input_kwargs)" begin
data = WebP.encode(input_image; input_kwargs...)
output = WebP.decode(data)
Expand Down

0 comments on commit b717f27

Please sign in to comment.