From 2833016a20205b1de60fd6b96b09c1b0ccc03f17 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Fri, 29 Apr 2022 14:47:22 +0800 Subject: [PATCH 1/2] support for Gray{Bool} --- src/io.jl | 1 + src/utils.jl | 1 + test/test_images/synth_images.jl | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/io.jl b/src/io.jl index 673a272..4a36af2 100644 --- a/src/io.jl +++ b/src/io.jl @@ -553,6 +553,7 @@ _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:Colorant{<:Normed}} = x _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:UInt8} = reinterpret(Gray{N0f8}, x) _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:UInt16} = reinterpret(Gray{N0f16}, x) _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:Normed} = reinterpret(Gray{T}, x) +_prepare_buffer(x::AbstractMatrix{<:T}) where {T<:Gray{Bool}} = Gray{N0f8}.(x) _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:Gray{<:AbstractFloat}} = Gray{N0f8}.(x) _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:GrayA{<:AbstractFloat}} = GrayA{N0f8}.(x) _prepare_buffer(x::AbstractMatrix{<:T}) where {T<:RGB{<:AbstractFloat}} = RGB{N0f8}.(x) diff --git a/src/utils.jl b/src/utils.jl index bf7d937..8906b09 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -6,6 +6,7 @@ _get_bit_depth(img::AbstractArray{T}) where {T<:Normed} = __get_bit_depth(T) # __get_bit_depth(::Type{Normed{T,1}}) where T = 1 # TODO: write 1 bit-depth images # __get_bit_depth(::Type{Normed{T,2}}) where T = 2 # TODO: write 2 bit-depth images # __get_bit_depth(::Type{Normed{T,4}}) where T = 4 # TODO: write 4 bit-depth images +__get_bit_depth(::Type{Bool}) = 8 # TODO: write 1 bit-depth images __get_bit_depth(::Type{Normed{T,8}}) where T = 8 __get_bit_depth(::Type{Normed{T,16}}) where T = 16 __get_bit_depth(::Type{Normed{T,N}}) where {T,N} = ifelse(N <= 8, 8, 16) diff --git a/test/test_images/synth_images.jl b/test/test_images/synth_images.jl index 3dbe28b..ec61467 100644 --- a/test/test_images/synth_images.jl +++ b/test/test_images/synth_images.jl @@ -34,6 +34,7 @@ synth_imgs = [ "RGB" => rand(RGB, 127, 257), "RGBA" => rand(RGBA, 127, 257), "ARGB32" => reinterpret(ARGB32, rand(UInt32, 127, 257)), + "Gray-Bool" => rand(Gray{Bool}, 127, 257), "Gray-N0f8" => rand(Gray{N0f8}, 127, 257), "GrayA-N0f8" => rand(GrayA{N0f8}, 127, 257), "RGB-N0f8" => rand(RGB{N0f8}, 127, 257), @@ -73,4 +74,4 @@ edge_case_imgs = [ ("ARGB-N0f8", identity, rand(ARGB{N0f8}, 127, 257)), ("ARGB-N0f16", identity, rand(ARGB{N0f16}, 127, 257)), ("ARGB-Float64", identity, ARGB{Float64}.(rand(ARGB{N0f8}, 127, 257))), -] \ No newline at end of file +] From 2671315b3e3361225e0926b36ce97d8d7cb2cebe Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Fri, 29 Apr 2022 14:47:49 +0800 Subject: [PATCH 2/2] PNGFiles v0.3.16 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index dc069e2..63850ea 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PNGFiles" uuid = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883" authors = ["Ian Butterworth", "Tomáš Drvoštěp"] -version = "0.3.15" +version = "0.3.16" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"