annotate scripts/image/private/imageIO.m @ 16906:bfad37d33435

Connect imfinfo with imformats. * private/core_imfinfo.m: new function. Old code from imfinfo() moved here so that imformats() can create function handle to this part of the code only otherwise imfinfo() would get stuck into an endless loop, calling itself while respecting imformats() configuration. * private/imageIO.m: new function. Responsible for connecting the image IO functions with imformats(), and calling the correct function. Will later also be used by imread and imwrite. * imfinfo.m: reduced to minimum input check, until finding filename. Passes all arguments to new function imageIO(). * imformats.m: change calls to imfinfo() to the new core_imfinfo().
author Carnë Draug <carandraug@octave.org>
date Sat, 06 Jul 2013 04:28:04 +0100
parents
children 1b3b3ee88284
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
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ## This function simply connects the function that call it to all
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
20 ## other imageIO functions. It does it by checking the file extension
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
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25 ## to use if the extensino is not listed by imformats), second argument is
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
26 ## the fieldname in the struct returned by imformats with a function handle
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27 ## for the function to use, and all the others are the input argument mean for
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
28 ## the destination function.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 ##
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30 ## No input checking whatsoever is performed. That is already done by the
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31 ## function calling it.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33 function varargout = imageIO (core_func, fieldname, filename, varargin)
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 [~, ~, ext] = fileparts (filename);
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35 ## remove dot from extension
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36 if (! isempty (ext) && strcmp (ext(1), "."));
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
37 ext(1) = [];
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
38 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
39 fmt = imformats ("ext");
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
40 ## When there is no match, fmt will be a 1x1 structure with no fields,
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
41 ## so we can't just use isempty ().
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 if (isempty (fieldnames (fmt)))
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
43 varargout{1:nargout} = core_func (varargin{:});
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 else
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45 varargout{1:nargout} = fmt.(fieldname) (varargin{:});
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 endfunction