Skip to content

Commit

Permalink
Merge branch 'master' into tln/bump-version
Browse files Browse the repository at this point in the history
  • Loading branch information
tlnagy authored Jan 10, 2024
2 parents ec8326f + 531eb14 commit cd5e640
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/ifds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,13 @@ function reverse_prediction!(ifd::IFD, arr::AbstractArray{T,N}) where {T, N}
pred::Int = predictor(ifd)
# for planar data, each "pixel" in the strip is actually a single channel
spp::Int = isplanar(ifd) ? 1 : nsamples(ifd)
if pred == 2
@debug "reversing horizontal differencing"
columns = istiled(ifd) ? tilecols(ifd) : ncols(ifd)
rows = istiled(ifd) ? tilerows(ifd) : cld(length(arr), columns * spp)

columns = istiled(ifd) ? tilecols(ifd) : ncols(ifd)
rows = istiled(ifd) ? tilerows(ifd) : cld(length(arr), columns * spp)
GC.@preserve arr begin
if pred == 2
@debug "reversing horizontal differencing"

# horizontal differencing
GC.@preserve arr begin
temp::Ptr{T} = pointer(arr)
for row in 1:rows
start = (row - 1) * columns * spp
Expand All @@ -410,6 +409,27 @@ function reverse_prediction!(ifd::IFD, arr::AbstractArray{T,N}) where {T, N}
end
end
end
elseif pred == 3
@debug "reversing float differencing"

columns = columns * spp * sizeof(T)

temp2::Ptr{UInt8} = pointer(reinterpret(UInt8, arr))
for row in 1:rows
start = (row - 1) * columns
for plane in 1:spp
prev::UInt8 = unsafe_load(temp2, start + plane)
for i in (spp + plane):spp:(columns - 1) + plane
curr = unsafe_load(temp2, start + i) + prev
unsafe_store!(temp2, curr, start + i)
prev = curr
end
end
vw = view(reinterpret(UInt8, arr), start+1:start+columns)
vw .= deplane(vw, sizeof(T))
end

arr .= bswap.(arr)
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,9 @@ end

@test xs == recoded
end

@testset "predictor == 3" begin
original = get_example("shapes_uncompressed.tif")
encoded = get_example("shapes_lzw_predictor3.tif")
@test TiffImages.load(original) == TiffImages.load(encoded)
end

0 comments on commit cd5e640

Please sign in to comment.