Skip to content

Commit

Permalink
Add Aqua testing and minimum compat testing (#157)
Browse files Browse the repository at this point in the history
* test minimum compat entries

* add aqua and fix type piracy/ambiguities

* bump minimum compatible progressmeter version
  • Loading branch information
tlnagy authored Apr 2, 2024
1 parent b7dbc88 commit ee4852f
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-downgrade-compat@v1 # downgrade packages to minimum compatible version on 1.6
if: ${{ matrix.version == '1.6' }}
with:
skip: Mmap, UUIDs, Test
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
Expand Down
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TiffImages"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
authors = ["Tamas Nagy <[email protected]>"]
version = "1.0.0"
version = "0.10.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand All @@ -26,8 +26,10 @@ FileIO = "1"
FixedPointNumbers = "0.8"
IndirectArrays = "0.5.1, 1"
Inflate = "0.1.4"
Mmap = "1"
OffsetArrays = "1"
PkgVersion = "0.1.1, 0.3"
ProgressMeter = "1"
ProgressMeter = "1.3.3"
SIMD = "3.4.5"
UUIDs = "1"
julia = "1.6"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _"Don't get into a tiff with your images"_

| **Stable release** | **Documentation** | **Build Status** |
|:------------------------------------------------------|:-------------------------------------------------------------------------|:--------------------------------------------------------------|
| ![](https://juliahub.com/docs/TiffImages/version.svg) | [![][docs-stable-img]][docs-stable-url][![][docs-dev-img]][docs-dev-url] | [![][status-img]][status-url] [![][ci-img]][ci-url] [![][codecov-img]][codecov-url] |
| ![](https://juliahub.com/docs/TiffImages/version.svg) | [![][docs-stable-img]][docs-stable-url][![][docs-dev-img]][docs-dev-url] | [![][status-img]][status-url] [![][ci-img]][ci-url] [![][codecov-img]][codecov-url] [![][aqua-img]][aqua-url] |

This package aims to be a fast, minimal, and correct TIFF reader and writer
written in Julia.
Expand Down Expand Up @@ -45,3 +45,6 @@ Please see the documentation above for usage details and examples

[status-img]: https://www.repostatus.org/badges/latest/active.svg
[status-url]: https://www.repostatus.org/#active

[aqua-img]: https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg
[aqua-url]: https://github.com/JuliaTesting/Aqua.jl
2 changes: 1 addition & 1 deletion src/compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ function Base.read!(tfs::TiffFileStrip{S}, arr::AbstractVector{UInt8}, ::Val{COM
lzw_decode!(tfs, arr)
end

function Base.read!(T, A, ::Val{C}) where C
function Base.read!(::Union{TiffFile, TiffFileStrip}, ::AbstractVector{UInt8}, ::Val{C}) where C
error("Compression $C is not implemented. Please open an issue against TiffImages.jl.")
end
8 changes: 4 additions & 4 deletions src/files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Base.read(io::Stream, ::Type{TiffFile})
bs = need_bswap(io)
offset_size = offsetsize(io)
first_offset_raw = read(io, offset_size)
first_offset = Int(bs ? bswap(first_offset_raw) : first_offset_raw)
first_offset = Int(bs ? _bswap(first_offset_raw) : first_offset_raw)
TiffFile{offset_size, typeof(io)}(nothing, filepath, io, first_offset, bs)
end

Expand Down Expand Up @@ -82,12 +82,12 @@ offset(file::TiffFile{O}) where {O} = O

function Base.read(file::TiffFile{O}, ::Type{T}) where {O, T}
value = read(file.io, T)
file.need_bswap ? bswap(value) : value
file.need_bswap ? _bswap(value) : value
end

function Base.read(file::TiffFile{O}, ::Type{String}) where O
value = read(file.io, O)
file.need_bswap ? bswap(value) : value
file.need_bswap ? _bswap(value) : value
end

function Base.read!(file::TiffFile, arr::AbstractArray)
Expand All @@ -100,7 +100,7 @@ Base.write(file::TiffFile, arr::AbstractVector{Any}) = write(file.io.io, Array{U
Base.seek(file::TiffFile, n::Integer) = seek(file.io, n)
FileIO.stream(file::TiffFile) = stream(file.io)

Base.bswap(x::Rational{T}) where {T} = Rational(bswap(x.num), bswap(x.den))
_bswap(x::Rational{T}) where {T} = Rational(_bswap(x.num), _bswap(x.den))

Base.IteratorSize(::TiffFile) = Base.SizeUnknown()
Base.eltype(::TiffFile{O}) where {O} = IFD{O}
6 changes: 3 additions & 3 deletions src/ifds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ Advances the iterator to the next IFD.
IFD
- `Int`: Offset of the next IFD
"""
function Base.iterate(file::TiffFile, state::Tuple{Union{IFD{O}, Nothing}, Int}) where {O}
function Base.iterate(file::TiffFile, state::Tuple{Union{<: IFD, Nothing}, Int})
curr_ifd, next_ifd_offset = state
# if current element doesn't exist, exit
(curr_ifd == nothing) && return nothing
(curr_ifd === nothing) && return nothing
(next_ifd_offset <= 0) && return (curr_ifd, (nothing, 0))

seek(file.io, next_ifd_offset)
Expand Down Expand Up @@ -618,7 +618,7 @@ const nice_n = filter(x -> !(max(nextpow(2, x), 8) - x in [0,1,2,3,5]), 1:31)
# arrange bytes so that each TT-sized lane contains a single code (+ extra bits)
$(sym("b", i)) = shufflevector($(sym("a", i)), shuffle)
# shift out extra low-order bits
$(sym("c", i)) = bswap(reinterpret(Vec{$count, $TT}, $(sym("b", i)))) >> shift
$(sym("c", i)) = _bswap(reinterpret(Vec{$count, $TT}, $(sym("b", i)))) >> shift
# mask out extra high-order bits
$(sym("d", i)) = $(sym("c", i)) & mask
in_ptr += $m
Expand Down
1 change: 0 additions & 1 deletion src/layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ end
struct Palette{T} <: Colorant{T, 1}
i::T
end
Base.reinterpret(::Type{Palette{T}}, arr::A) where {T, N, S, A <: AbstractArray{S, N}} = arr

interpretation(p::PhotometricInterpretations) = interpretation(Val(p))
interpretation(::Val{PHOTOMETRIC_RGB}) = RGB
Expand Down
4 changes: 2 additions & 2 deletions src/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function load(tf::TiffFile; verbose=true, mmap = false, lazyio = false)
@debug "bswap'ing data"
if !homogeneous
for sub in loaded
sub .= bswap.(sub)
sub .= _bswap.(sub)
end
else
loaded .= bswap.(loaded)
loaded .= _bswap.(loaded)
end
end

Expand Down
3 changes: 2 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ const julian_to_tiff = Dict(
Int64 => 0x0011, # SLONG8
)

Base.bswap(c::Colorant{T, N}) where {T, N} = mapc(bswap, c)
_bswap(a) = bswap(a)
_bswap(c::Colorant{T, N}) where {T, N} = mapc(bswap, c)

function getstream(fmt, io, name)
# adapted from https://github.com/JuliaStats/RDatasets.jl/pull/119/
Expand Down
5 changes: 5 additions & 0 deletions test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Aqua

@testset "Aqua.jl tests" begin
Aqua.test_all(TiffImages)
end
6 changes: 5 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
SIMD = "fdea26ae-647d-5447-a871-4b548cad5224"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
SIMD = "fdea26ae-647d-5447-a871-4b548cad5224"

[compat]
Aqua = "0.8"
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ using Statistics
using Test
using TiffImages

include("Aqua.jl")

DocMeta.setdocmeta!(TiffImages, :DocTestSetup, :(using TiffImages); recursive=true)
doctest(TiffImages)

Expand Down Expand Up @@ -268,7 +270,7 @@ end
m = sum(ref.data .- other.data) ./ length(ref)
@test m.r < 0.001 && m.g < 0.001 && m.b < 0.001

@test other.ifds[1][TiffImages.BITSPERSAMPLE].data == UInt16[12,12,12]
@test ifds(other)[TiffImages.BITSPERSAMPLE].data == UInt16[12,12,12]

other = TiffImages.load(get_example("shapes_lzw_14bps.tif"))
m = sum(ref.data .- other.data) ./ length(ref)
Expand Down

2 comments on commit ee4852f

@tlnagy
Copy link
Owner Author

@tlnagy tlnagy commented on ee4852f Apr 15, 2024

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/104956

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.10.0 -m "<description of version>" ee4852f0ab17412ee643f7c7d18c51989ad10898
git push origin v0.10.0

Please sign in to comment.