annotate scripts/image/private/imwrite_filename.m @ 19865:e9f89866074c

maint: Cleanup some .m files to follow Octave coding conventions. * accumarray.m, validateattributes.m, iscolormap.m, __imread__.m, __imwrite__.m, imwrite_filename.m, strread.m, getappdata.m, appearance/annotation.m, shrinkfaces.m, rundemos.m, runtests.m, datenum.m, datestr.m: Break long lines before && and ||.
author John W. Eaton <jwe@octave.org>
date Thu, 26 Feb 2015 13:13:40 -0500
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17848
diff changeset
1 ## Copyright (C) 2013-2015 Carnë Draug
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
2 ##
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
4 ##
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
8 ## your option) any later version.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
9 ##
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ##
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
18
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ## The input check for imwrite needs to be done twice, once when imwrite
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
20 ## is called the first time to find where the filename is, and a second
17086
3db796f89695 Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents: 16948
diff changeset
21 ## time by __imwrite__ after imformats decides what function to use.
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22 ## Because a user can, and is encouraged to, get a function handle to
17086
3db796f89695 Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents: 16948
diff changeset
23 ## __imwrite__, the input check is also done there.
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
24 ## In addition, the input check for imwrite is not that straightforward
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25 ## in order to support the multiple ways the function can be called,
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
26 ## and interpretations of Matlab documentation.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27 ##
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
28 ## Anyway, this will only do the input check until it finds the filename
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 ## to be used, the only part that imwrite actually needs.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31 function [filename, ext, cmap, options] = imwrite_filename (varargin)
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33 ## First, we check if the first argument is a colormap or a filename.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 cmap = [];
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35 if (ischar (varargin{1}))
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36 filename_idx = 1;
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
37 elseif (numel (varargin) >= 2
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
38 && iscolormap (varargin{1}) && ischar (varargin{2}))
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
39 filename_idx = 2;
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
40 cmap = varargin{1};
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
41 else
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 error ("imwrite: no FILENAME specified");
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
43 endif
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 filename = tilde_expand (varargin{filename_idx});
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 ## Next, we get the file extension.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 ## if we have an odd number of leftover arguments, and the next argument
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
48 ## is a string, we consider it the file extension. Otherwise we will
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
49 ## extract what we can from the previously found filename.
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
50 options_idx = filename_idx + 1;
19865
e9f89866074c maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19833
diff changeset
51 if (numel (varargin) > filename_idx
e9f89866074c maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19833
diff changeset
52 && rem (length (varargin) - filename_idx, 2) != 0
e9f89866074c maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19833
diff changeset
53 && ischar (varargin{filename_idx + 1}))
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54 ext = varargin{filename_idx + 1};
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
55 options_idx++;
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 else
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
57 [~, ~, ext] = fileparts (filename);
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 if (! isempty (ext))
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59 ## remove dot from extension
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
60 ext = ext(2:end);
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
61 endif
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
62 endif
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
63
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
64 ## After all the work finding where the filename was, we might as well
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65 ## send the leftovers list (they should be in key value pairs)
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
66 options = varargin(options_idx:end);
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
67
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
68 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17086
diff changeset
69