comparison 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
comparison
equal deleted inserted replaced
16905:562301c71bd3 16906:bfad37d33435
1 ## Copyright (C) 2013 Carnë Draug
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## This function simply connects the function that call it to all
20 ## other imageIO functions. It does it by checking the file extension
21 ## of the file and redirecting to the appropriate function after checking
22 ## with imformats.
23 ##
24 ## First argument is a function handle for the default imageIO function (what
25 ## to use if the extensino is not listed by imformats), second argument is
26 ## the fieldname in the struct returned by imformats with a function handle
27 ## for the function to use, and all the others are the input argument mean for
28 ## the destination function.
29 ##
30 ## No input checking whatsoever is performed. That is already done by the
31 ## function calling it.
32
33 function varargout = imageIO (core_func, fieldname, filename, varargin)
34 [~, ~, ext] = fileparts (filename);
35 ## remove dot from extension
36 if (! isempty (ext) && strcmp (ext(1), "."));
37 ext(1) = [];
38 endif
39 fmt = imformats ("ext");
40 ## When there is no match, fmt will be a 1x1 structure with no fields,
41 ## so we can't just use isempty ().
42 if (isempty (fieldnames (fmt)))
43 varargout{1:nargout} = core_func (varargin{:});
44 else
45 varargout{1:nargout} = fmt.(fieldname) (varargin{:});
46 endif
47 endfunction