annotate scripts/image/private/imageIO.m @ 16984:997efb8d0b19

imread: implement options Index, Frames, and Info. * imread.m: write documentation about options of param/key style. * private/core_imread.m: write parsing of options in the param/key style. Implement the option for Index, Frames, and Info. Also write parsing for PixelRegion but comment out the code until it's implemented in __magick_read__(). Add comments about, and deprecate, Octave's native image format which is completely undocumented. Remove tests since they are duplicated from the ones in imread.m. * __magick_read__.cc: move input check to the m file calling it. Rewrite parsing of options which are now in a non-optional struct (default values are now set on the m function). * private/imageIO.m: fix call to other functions with varargout with multiple output values.
author Carnë Draug <carandraug@octave.org>
date Sat, 13 Jul 2013 12:41:59 +0100
parents ee2166121a28
children 1c89599167a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
1 ## Copyright (C) 2013 Carnë Draug
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
2 ##
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
4 ##
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
8 ## your option) any later version.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
9 ##
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ##
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
18
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents: 16944
diff changeset
19 ## This function simply connects imread and imfinfo() to the function
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents: 16944
diff changeset
20 ## to be used based on their format. It does it by checking the file extension
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
21 ## of the file and redirecting to the appropriate function after checking
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22 ## with imformats.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
23 ##
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
24 ## First argument is a function handle for the default imageIO function (what
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
25 ## to use if the file extension for the image file is not listed by imformats).
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
26 ## Second argument is the fieldname in the struct returned by imformats with a
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
27 ## function handle for the function to use. Third argument is a cell array, its
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
28 ## first element the filename, and the second, an optional file extension to
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
29 ## add to filename, if filename alone does not exist. All the others are the
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
30 ## original input arguments passed to the original imageIO function which will
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
31 ## be passed on to the destination function.
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 ##
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
33 ## No input checking whatsoever is performed. That should be performed by the
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 ## function calling it.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36 function varargout = imageIO (core_func, fieldname, filename, varargin)
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
37
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
38 ## It should not be this function job to check if the file exists or not.
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
39 ## However, we need to know the file extension to use with imformats and
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
40 ## that means we need to know the actual filename that will be used which
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
41 ## is dependent on whether a file exists.
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
42 ##
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
43 ## If a file named filename{1} exists, then that's it, we will use that
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
44 ## wether it has an extension or not. If it does not exist and we have
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
45 ## something in filename{2}, then we will consider it the file extension.
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
46 ## Note the detail that if we find a file using filename{1} only, then we
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
47 ## should completely ignore filename{2}. It won't even be used by
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
48 ## imformats() at all, even if filename{1} has no extension to use with
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
49 ## imformats().
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents: 16944
diff changeset
50 if (isscalar (filename) || ! isempty (file_in_path (IMAGE_PATH, filename{1})))
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
51 [~, ~, ext] = fileparts (filename{1});
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
52 if (! isempty (ext))
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
53 ## remove dot from extension
16948
ee2166121a28 imwrite: clean up finding of filename and its connection to imformats.
Carnë Draug <carandraug@octave.org>
parents: 16944
diff changeset
54 ext = ext(2:end);
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
55 endif
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
56 else
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
57 ext = filename{2};
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 endif
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
59
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
60 fmt = imformats (ext);
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
61 ## When there is no match, fmt will be a 1x1 structure with no fields,
16944
1b3b3ee88284 Add optional extension argument to image IO functions.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
62 ## so we can't just use `isempty (fmt)'.
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
63 if (isempty (fieldnames (fmt)))
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16948
diff changeset
64 [varargout{1:nargout}] = core_func (varargin{:});
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65 else
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16948
diff changeset
66 [varargout{1:nargout}] = fmt.(fieldname) (varargin{:});
16906
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
67 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
68 endfunction