Skip to content

Commit

Permalink
support Gray{Bool} array (#58)
Browse files Browse the repository at this point in the history
* support for Gray{Bool}

* PNGFiles v0.3.16
  • Loading branch information
johnnychen94 authored Apr 29, 2022
1 parent ad8f026 commit b00dace
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/test_images/synth_images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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))),
]
]

2 comments on commit b00dace

@johnnychen94
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/59358

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.16 -m "<description of version>" b00dacecaf260a716e17b1bea333bcf1f217e6c1
git push origin v0.3.16

Please sign in to comment.