# HG changeset patch # User Carnë Draug # Date 1446574862 0 # Node ID ae83fda9929f4c0a23a4f4bdfae6cda801c7c9be # Parent 3d8aee0b74158db18b235d2ad70c6b11371580c2 ntsc2rgb: remove unreasonable support for integer input (patch #8709) * scripts/image/ntsc2rgb.m: cset 131ce8cfaa80 added support for images of class other than double. However, while this is common for RGB images, it not for YIQ. In addition, the range of values in a YIQ image is a bit more complex. See source comments for details or discussion on the patch. diff -r 3d8aee0b7415 -r ae83fda9929f scripts/image/ntsc2rgb.m --- a/scripts/image/ntsc2rgb.m Sun Nov 01 19:59:12 2015 -0800 +++ b/scripts/image/ntsc2rgb.m Tue Nov 03 18:21:02 2015 +0000 @@ -45,6 +45,21 @@ print_usage (); endif + ## Unlike other colorspace conversion functions, we do not accept + ## integers as valid input. We check this before + ## colorspace_conversion_input_check() which is general and would + ## convert integers to double assuming a [0 1] interval range. + ## The reason for not supporting integers here is that there's no + ## common such conversion. If we were to support a conversion + ## the most reasonable definition would be to convert the YIQ + ## from their integer range into the ranges: + ## Y = [ 0 1.106] + ## I = [-0.797 0.587] + ## Q = [-0.322 0.426] + ## See https://savannah.gnu.org/patch/?8709#comment11 + if (! isfloat (yiq)) + error ("ntsc2rgb: YIQ must be of floating point class"); + endif [yiq, cls, sz, is_im, is_nd] ... = colorspace_conversion_input_check ("ntsc2rgb", "YIQ", yiq); @@ -122,8 +137,11 @@ ## Test input validation %!error ntsc2rgb () %!error ntsc2rgb (1,2) -%!error ntsc2rgb (uint8 (1)) +%!error ntsc2rgb (uint8 (1)) %!error ntsc2rgb (ones (2,2)) +%!error ntsc2rgb (ones ([10 10 3], "uint8")) +%!error ntsc2rgb (ones ([10 10 3], "uint16")) +%!error ntsc2rgb (ones ([10 10 3], "int16")) ## Test ND input %!test @@ -160,21 +178,6 @@ %! assert (size (rgb), [10 10 3]) %!test -%! rgb = ntsc2rgb (randi ([0 255], 10, 10, 3, "uint8")); -%! assert (class (rgb), "double") -%! assert (size (rgb), [10 10 3]) - -%!test -%! rgb = ntsc2rgb (randi ([0 65535], 10, 10, 3, "uint16")); -%! assert (class (rgb), "double") -%! assert (size (rgb), [10 10 3]) - -%!test -%! rgb = ntsc2rgb (randi ([-128 127], 10, 10, 3, "uint16")); -%! assert (class (rgb), "double") -%! assert (size (rgb), [10 10 3]) - -%!test %! ntsc_double = reshape ([.299 .587 .114 0 .596 -.274 -.322 0 .211 -.523 .312 0], %! [2 2 3]); %! expected = reshape ([1 0 0 0 0 1 0 0 0 0 1 0], [2 2 3]);