annotate scripts/image/private/colorspace_conversion_input_check.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 0a5b15007766
children e1788b1a315f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
3 ## Copyright (C) 2016-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ##
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
8 ## This file is part of Octave.
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ##
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ##
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
26 ## Private function the functions that convert between color spaces, i.e.,
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27 ## rgb2ntsc, rgb2hsv, hsv2rgb, and ntsc2rgb. All of these functions need to
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
28 ## handle input in the same way. The returned flags are meant to be handled
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 ## by the complementary private function colorspace_conversion_revert()
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30
20676
1672bb8882dd Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents: 20665
diff changeset
31 function [in_arg, sz, is_im, is_nd] ...
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 = colorspace_conversion_input_check (func, arg_name, in_arg)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 cls = class (in_arg);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35 sz = size (in_arg);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
37 ## If we have an image convert it into a color map.
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
38 if (! iscolormap (in_arg))
20665
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
39 if (! any (strcmp (cls, {"uint8", "int8", "int16", "uint16", ...
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
40 "single", "double"})))
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
41 error ("%s: %s of invalid data type '%s'", func, arg_name, cls);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 elseif (size (in_arg, 3) != 3)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
43 error ("%s: %s must be a colormap or %s image", func, arg_name, arg_name);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 elseif (! isreal (in_arg) || ! isnumeric (in_arg))
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45 error ("%s: %s must be numeric and real", func, arg_name);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 is_im = true;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
48
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
49 ## For floating point values, R, G and B should be in the [0 1] range,
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 20676
diff changeset
50 ## otherwise they don't make any sense. We accept those values
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
51 ## anyways because we must return something for Matlab compatibility.
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
52 ## User case is when a function returns an RGB image just slightly outside
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53 ## the range due to floating point rounding errors.
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
55 ## Allow for ND images, i.e., multiple images on the 4th dimension.
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 nd = ndims (in_arg);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
57 if (nd == 3)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 is_nd = false;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59 elseif (nd == 4)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
60 is_nd = true;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
61 in_arg = permute (in_arg, [1 2 4 3]);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
62 elseif (nd > 4)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
63 error ("%s: invalid %s with more than 4 dimensions", func, arg_name);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
64 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65 in_arg = reshape (in_arg, [numel(in_arg)/3 3]);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
66 else
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
67 is_im = false;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
68 is_nd = false;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
69 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
70
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
71 ## Convert to floating point (remember to leave class single alone)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
72 if (isinteger (in_arg))
20665
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
73 int_max = double (intmax (cls));
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
74 int_min = double (intmin (cls));
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
75 if (int_min < 0)
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
76 in_arg = (double (in_arg) - int_min) / (int_max - int_min);
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
77 else
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
78 in_arg = double (in_arg) / int_max;
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
79 endif
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
80 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
81
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
82 endfunction