Skip to content

Commit f9b2eb5

Browse files
timholyDrvi
andauthoredNov 5, 2021
Support ARGB32 images (#45)
Fixes JuliaIO/FileIO.jl#352 Co-authored-by: Drvi <tomas.drvostep@gmail.com>
1 parent 424a0b3 commit f9b2eb5

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed
 

‎Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PNGFiles"
22
uuid = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
33
authors = ["Ian Butterworth", "Tomáš Drvoštěp"]
4-
version = "0.3.11"
4+
version = "0.3.12"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

‎src/io.jl

+6-9
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ function _save(png_ptr, info_ptr, image::S;
367367
end
368368
else
369369
image_eltype = eltype(image)
370-
if (image_eltype <: BGR || image_eltype <: BGRA || image_eltype <: ABGR)
370+
if (image_eltype <: BGR || image_eltype <: BGRA || image_eltype <: ABGR || image_eltype <: ARGB32)
371371
png_set_bgr(png_ptr)
372372
end
373373

@@ -515,14 +515,11 @@ _get_bit_depth(img::AbstractArray{<:Bool}) = 8 # TODO: write 1 bit-depth images
515515
_get_bit_depth(img::AbstractArray{<:UInt8}) = 8
516516
_get_bit_depth(img::AbstractArray{<:UInt16}) = 16
517517

518-
_get_color_type(x::AbstractArray{<:Gray{T}}) where {T} = PNG_COLOR_TYPE_GRAY
519-
_get_color_type(x::AbstractArray{<:GrayA{T}}) where {T} = PNG_COLOR_TYPE_GRAY_ALPHA
520-
_get_color_type(x::AbstractArray{<:RGB{T}}) where {T} = PNG_COLOR_TYPE_RGB
521-
_get_color_type(x::AbstractArray{<:RGBA{T}}) where {T} = PNG_COLOR_TYPE_RGBA
522-
_get_color_type(x::AbstractArray{<:BGR{T}}) where {T} = PNG_COLOR_TYPE_RGB
523-
_get_color_type(x::AbstractArray{<:BGRA{T}}) where {T} = PNG_COLOR_TYPE_RGBA
524-
_get_color_type(x::AbstractArray{<:ARGB{T}}) where {T} = PNG_COLOR_TYPE_RGBA
525-
_get_color_type(x::AbstractArray{<:ABGR{T}}) where {T} = PNG_COLOR_TYPE_RGBA
518+
_get_color_type(x::AbstractArray{<:Gray}) = PNG_COLOR_TYPE_GRAY
519+
_get_color_type(x::AbstractArray{<:GrayA}) = PNG_COLOR_TYPE_GRAY_ALPHA
520+
_get_color_type(x::AbstractArray{<:AbstractRGB}) = PNG_COLOR_TYPE_RGB
521+
_get_color_type(x::AbstractArray{<:AbstractARGB}) = PNG_COLOR_TYPE_RGBA
522+
_get_color_type(x::AbstractArray{<:AbstractRGBA}) = PNG_COLOR_TYPE_RGBA
526523
_get_color_type(x::IndirectArray) = PNG_COLOR_TYPE_PALETTE
527524
function _get_color_type(
528525
x::AbstractArray{T, N}

‎test/test_synthetic_images.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ synth_imgs = [
3333
"GrayA" => rand(GrayA, 127, 257),
3434
"RGB" => rand(RGB, 127, 257),
3535
"RGBA" => rand(RGBA, 127, 257),
36+
"ARGB32" => reinterpret(ARGB32, rand(UInt32, 127, 257)),
3637
"Gray-N0f8" => rand(Gray{N0f8}, 127, 257),
3738
"GrayA-N0f8" => rand(GrayA{N0f8}, 127, 257),
3839
"RGB-N0f8" => rand(RGB{N0f8}, 127, 257),
@@ -88,7 +89,7 @@ edge_case_imgs = [
8889
@test typeof(read_in_pngf) <: AbstractMatrix
8990
end
9091
@testset "compare" begin
91-
@test all(expected .≈ read_in_pngf)
92+
@test eltype(eltype(expected)) <: N0f8 ? expected == read_in_pngf : all(expected .≈ read_in_pngf)
9293
end
9394
global read_in_immag = _standardize_grayness(ImageMagick.load(fpath))
9495
@testset "$(case): ImageMagick read type equality" begin

2 commit comments

Comments
 (2)

timholy commented on Nov 5, 2021

@timholy
MemberAuthor

JuliaRegistrator commented on Nov 5, 2021

@JuliaRegistrator

Registration pull request created: JuliaRegistries/General/48235

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.12 -m "<description of version>" f9b2eb5239432c387fea2d0b490874854b664723
git push origin v0.3.12
Please sign in to comment.