diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6ed2371..e3c45df 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 diff --git a/Project.toml b/Project.toml index 2fd28cf..7761113 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TiffImages" uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69" authors = ["Tamas Nagy "] -version = "1.0.0" +version = "0.10.0" [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" @@ -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" diff --git a/README.md b/README.md index 69ca7f1..0dd432a 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/src/compression.jl b/src/compression.jl index d22ad7a..1630d6a 100644 --- a/src/compression.jl +++ b/src/compression.jl @@ -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 diff --git a/src/files.jl b/src/files.jl index 2b4b701..2504979 100644 --- a/src/files.jl +++ b/src/files.jl @@ -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 @@ -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) @@ -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} diff --git a/src/ifds.jl b/src/ifds.jl index cf6afa8..c142a29 100644 --- a/src/ifds.jl +++ b/src/ifds.jl @@ -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) @@ -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 diff --git a/src/layout.jl b/src/layout.jl index 7ee4399..6737fee 100644 --- a/src/layout.jl +++ b/src/layout.jl @@ -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 diff --git a/src/load.jl b/src/load.jl index 31b0f47..694cf54 100644 --- a/src/load.jl +++ b/src/load.jl @@ -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 diff --git a/src/utils.jl b/src/utils.jl index f2958f7..517a38c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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/ diff --git a/test/Aqua.jl b/test/Aqua.jl new file mode 100644 index 0000000..ebda1d8 --- /dev/null +++ b/test/Aqua.jl @@ -0,0 +1,5 @@ +using Aqua + +@testset "Aqua.jl tests" begin + Aqua.test_all(TiffImages) +end \ No newline at end of file diff --git a/test/Project.toml b/test/Project.toml index 63a85ed..852f911 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [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" @@ -6,7 +7,10 @@ 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" diff --git a/test/runtests.jl b/test/runtests.jl index bdb7299..135d6d3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,8 @@ using Statistics using Test using TiffImages +include("Aqua.jl") + DocMeta.setdocmeta!(TiffImages, :DocTestSetup, :(using TiffImages); recursive=true) doctest(TiffImages) @@ -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)