annotate scripts/image/private/colorspace_conversion_input_check.m @ 27918:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents 00f796120a6d
children 1891570abac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1 ## Copyright (C) 2016-2019 The Octave Project Developers
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
5 ##
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
6 ##
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ## 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
8 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
9 ## 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
10 ## 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
11 ## 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
12 ## (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
13 ##
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ## 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
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## 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
18 ##
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ## 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
20 ## 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
21 ## <https://www.gnu.org/licenses/>.
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
23 ## 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
24 ## 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
25 ## 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
26 ## 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
27
20676
1672bb8882dd Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents: 20665
diff changeset
28 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
29 = 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
30
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31 cls = class (in_arg);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 sz = size (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 ## 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
35 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
36 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
37 "single", "double"})))
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
38 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
39 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
40 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
41 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
42 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
43 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 is_im = true;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 ## 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
47 ## 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
48 ## 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
49 ## 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
50 ## 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
51
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
52 ## 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
53 nd = ndims (in_arg);
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54 if (nd == 3)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
55 is_nd = false;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 elseif (nd == 4)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
57 is_nd = true;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 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
59 elseif (nd > 4)
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
60 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
61 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
62 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
63 else
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
64 is_im = false;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65 is_nd = false;
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
66 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
67
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
68 ## 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
69 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
70 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
71 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
72 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
73 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
74 else
67e6343cd29a Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
75 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
76 endif
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
77 endif
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
78
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
79 endfunction