Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn -> atsign-warn, and fix loading of too-small grayscale images #29

Merged
merged 1 commit into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/NRRD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function load(io::Stream{format"NRRD"}, Tuser::Type=Any; mode="r", mmap=:auto)
do_mmap |= can_mmap && (mmap == true)

if !compressed
szraw = checked_size(Traw, szraw, sz, iodata)
szraw, sz = checked_size(Traw, szraw, sz, iodata)
end

if do_mmap
Expand Down Expand Up @@ -775,7 +775,7 @@ function get_axes(header, nd)
for idx in findall(istime)
labelt = axnames[idx]
if !istimeaxis(Axis{Symbol(labelt)})
warn("label $labelt is not defined as a time axis, define it with `@traitimpl TimeAxis{Axis{:$labelt}}` (see ImageAxes for more information)")
@warn("label $labelt is not defined as a time axis, define it with `@traitimpl TimeAxis{Axis{:$labelt}}` (see ImageAxes for more information)")
end
end
end
Expand Down Expand Up @@ -1188,10 +1188,10 @@ function checked_size(Traw, szraw, sz, iodata)
sznew[k] = div(datalen, strds[k])
end
tsznew = (sznew...,)
warn("header indicates an array size $szraw, but the file size is consistent with at most $tsznew")
szraw = tsznew
@warn("header indicates an array size $szraw, but the file size is consistent with at most $tsznew")
szraw = sz = tsznew
end
szraw
szraw, sz
end

function stream2name(s::IO)
Expand Down
23 changes: 22 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FileIO, FixedPointNumbers, ColorTypes, Unitful, AxisArrays, ImageAxes, ImageMetadata
using Test
using Test, Base.CoreLogging

include("unu-make.jl")

Expand Down Expand Up @@ -159,6 +159,27 @@ include("unu-make.jl")
@test pixelspacing(imgc) == (1.0u"mm", 1.2u"mm")
end

@testset "Size warning" begin
for (T, Traw) in ((N0f8, UInt8), (N0f16, UInt16))
img = rand(T, 5, 7, 3)
outname = joinpath(writedir, "imagetrunc.nhdr")
props = Dict("datafile"=>joinpath(writedir, "imagetrunc.raw"))
save(outname, img, props=props)
# Create a too-small data array
open(props["datafile"], "w") do io
write(io, rand(Traw, 5, 7, 2))
end
# Test that it can be read but produces a warning
logger = Test.TestLogger()
with_logger(logger) do
imgr = load(outname)
@test size(imgr) == (5, 7, 2)
end
record = logger.logs[1]
@test occursin("header indicates an array size (5, 7, 3), but the file size is consistent with at most (5, 7, 2)", record.message)
end
end

GC.gc() # to close any mmapped files
try
rm(workdir, recursive=true)
Expand Down