Skip to content

Commit 328a4b8

Browse files
authored
imresize: handle 0-parameter colorant types (#126)
1 parent b195f34 commit 328a4b8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/resizing.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ end
351351
# changes correspond to integer ratios. We mimic ratio arithmetic
352352
# without actually using Rational (which risks promoting to a
353353
# Rational type, too slow for image processing).
354-
imresize_type(c::Colorant) = base_colorant_type(c){eltype(imresize_type(Gray(c)))}
354+
function imresize_type(c::Colorant)
355+
CT = base_colorant_type(c)
356+
isconcretetype(CT) && return CT # special 0-parameter colorant types: ARGB32, etc
357+
CT{eltype(imresize_type(Gray(c)))}
358+
end
355359
imresize_type(c::Gray) = Gray{imresize_type(gray(c))}
356360
imresize_type(c::FixedPoint) = typeof(c)
357361
imresize_type(c) = typeof((c*1)/1)

test/resizing.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,26 @@ end
181181
@test OffsetArrays.no_offset_view(out) == imresize(img, (128, 128), method=Lanczos4OpenCV())
182182
end
183183
end
184+
185+
@testset "special RGB/Gray types (#97)" begin
186+
ori = repeat(distinguishable_colors(10), inner=(1, 10))
187+
for T in (
188+
RGB, BGR, RGBX, XRGB,
189+
ARGB, RGBA,
190+
RGB24, ARGB32,
191+
)
192+
img = T.(ori)
193+
out = @inferred imresize(img, ratio=2)
194+
@test eltype(out) <: T
195+
ref = imresize(ori, ratio=2)
196+
@test ref RGB.(out)
197+
end
198+
for T in (Gray, AGray, GrayA, Gray24)
199+
img = T.(ori)
200+
out = @inferred imresize(img, ratio=2)
201+
@test eltype(out) <: T
202+
ref = imresize(Gray.(ori), ratio=2)
203+
@test ref Gray.(out)
204+
end
205+
end
184206
end

0 commit comments

Comments
 (0)