Skip to content

Commit

Permalink
imresize: handle 0-parameter colorant types
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed May 22, 2021
1 parent b195f34 commit fa9cdfe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/resizing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ end
# changes correspond to integer ratios. We mimic ratio arithmetic
# without actually using Rational (which risks promoting to a
# Rational type, too slow for image processing).
imresize_type(c::Colorant) = base_colorant_type(c){eltype(imresize_type(Gray(c)))}
function imresize_type(c::Colorant)
CT = base_colorant_type(c)
isconcretetype(CT) && return CT # special 0-parameter colorant types: ARGB32, etc
CT{eltype(imresize_type(Gray(c)))}
end
imresize_type(c::Gray) = Gray{imresize_type(gray(c))}
imresize_type(c::FixedPoint) = typeof(c)
imresize_type(c) = typeof((c*1)/1)
Expand Down
22 changes: 22 additions & 0 deletions test/resizing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,26 @@ end
@test OffsetArrays.no_offset_view(out) == imresize(img, (128, 128), method=Lanczos4OpenCV())
end
end

@testset "special RGB/Gray types (#97)" begin
ori = repeat(distinguishable_colors(10), inner=(1, 10))
for T in (
RGB, BGR, RGBX, XRGB,
ARGB, RGBA,
RGB24, ARGB32,
)
img = T.(ori)
out = @inferred imresize(img, ratio=2)
@test eltype(out) <: T
ref = imresize(ori, ratio=2)
@test ref RGB.(out)
end
for T in (Gray, AGray, GrayA, Gray24)
img = T.(ori)
out = @inferred imresize(img, ratio=2)
@test eltype(out) <: T
ref = imresize(Gray.(ori), ratio=2)
@test ref Gray.(out)
end
end
end

0 comments on commit fa9cdfe

Please sign in to comment.