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

imresize: handle 0-parameter colorant types #126

Merged
merged 1 commit into from
May 22, 2021
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
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