changeset 23484:3ace16b8f062

Support uint32 and uint64 on image conversion functions (bug #47115) * image/private/ind2x.n: check for any unsigned integer type instead of limit to uint16 and uint8. This affects ind2rgb and ind2gray. * ind2rgb.m: add tests.
author Carnë Draug <carandraug@octave.org>
date Wed, 10 May 2017 20:05:23 +0100
parents 6d5a646ede0c
children fec7e5b14fb2
files scripts/image/ind2rgb.m scripts/image/private/ind2x.m
diffstat 2 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/ind2rgb.m	Wed May 10 13:53:22 2017 -0400
+++ b/scripts/image/ind2rgb.m	Wed May 10 20:05:23 2017 +0100
@@ -117,3 +117,24 @@
 %!warning <contains colors outside of colormap> ind2rgb ([0 1 2], gray (5));
 %!warning <contains colors outside of colormap> ind2rgb ([1 2 6], gray (5));
 %!warning <contains colors outside of colormap> ind2rgb (uint8 ([1 2 5]), gray (5));
+
+## We support any unsigned integer type which Matlab does not.  See
+## bug #47115.
+%!test
+%! cmap = repmat (linspace (0, 1, 9)(:), [1 3]);
+%! ind = [0 3 6; 1 4 7; 2 5 8];
+%! rgb = repmat (reshape (linspace (0, 1, 9), [3 3]), [1 1 3]);
+%! assert (ind2rgb (uint8  (ind), cmap), rgb)
+%! assert (ind2rgb (uint16 (ind), cmap), rgb)
+%! assert (ind2rgb (uint32 (ind), cmap), rgb)
+%! assert (ind2rgb (uint64 (ind), cmap), rgb)
+%! fail ("ind2rgb (int8  (ind), cmap)", "X must be an indexed image")
+%! fail ("ind2rgb (int16 (ind), cmap)", "X must be an indexed image")
+%! fail ("ind2rgb (int32 (ind), cmap)", "X must be an indexed image")
+%! fail ("ind2rgb (int64 (ind), cmap)", "X must be an indexed image")
+%!
+%! cmap(65541,:) = cmap(9,:); # index outside the uint16 range
+%! cmap(9,:) = 0;
+%! ind(3,3) = 65540;
+%! assert (ind2rgb (uint32 (ind), cmap), rgb)
+%! assert (ind2rgb (uint64 (ind), cmap), rgb)
--- a/scripts/image/private/ind2x.m	Wed May 10 13:53:22 2017 -0400
+++ b/scripts/image/private/ind2x.m	Wed May 10 20:05:23 2017 +0100
@@ -27,8 +27,8 @@
   ## and check that the 3rd dimension is a singleton.
   if (all (ndims (x) != [2 4]) || size (x, 3) != 1
       || iscomplex (x) || issparse (x)
-      || (isfloat (x) && x != fix (x))
-      || ! any (strcmp (class (x), {"uint8", "uint16", "single", "double"})))
+      || ! (isfloat (x) && all (x(:) == fix (x(:)))
+            || (isinteger (x) && intmin (class (x)) == 0)))
     error ("%s: X must be an indexed image", caller);
   endif