Mercurial > hg > octave-jordi
changeset 20674:ae83fda9929f
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.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 03 Nov 2015 18:21:02 +0000 |
parents | 3d8aee0b7415 |
children | 1672bb8882dd |
files | scripts/image/ntsc2rgb.m |
diffstat | 1 files changed, 19 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/ntsc2rgb.m +++ b/scripts/image/ntsc2rgb.m @@ -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 <YIQ must be a colormap or YIQ image> ntsc2rgb (uint8 (1)) +%!error <YIQ must be of floating point class> ntsc2rgb (uint8 (1)) %!error <YIQ must be a colormap or YIQ image> ntsc2rgb (ones (2,2)) +%!error <YIQ must be of floating point class> ntsc2rgb (ones ([10 10 3], "uint8")) +%!error <YIQ must be of floating point class> ntsc2rgb (ones ([10 10 3], "uint16")) +%!error <YIQ must be of floating point class> 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]);