annotate scripts/image/private/core_imfinfo.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) 2008-2012 Soren Hauberg
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 does al the work of imfinfo. It exists here as private
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
20 ## function so that imfinfo can use other functions if imformats is
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
21 ## configured to. It is also needed so that imformats can create a
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22 ## function handle for it.
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 ## Author: Soren Hauberg <hauberg@gmail.com>
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
26 function info = core_imfinfo (filename)
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
28 if (nargin < 1)
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 print_usage ("imfinfo");
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 if (! ischar (filename))
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33 error ("imfinfo: FILENAME must be a string");
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35 filename = tilde_expand (filename);
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
37 delete_file = false;
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
38 unwind_protect
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
39
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
40 fn = file_in_path (IMAGE_PATH, filename);
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
41
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 if (isempty (fn))
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
43 ## Couldn't find file. See if it's an URL.
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 [fn, status, msg] = urlwrite (filename, tmpnam ());
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45 if (! status)
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 error ("imfinfo: cannot find %s", filename);
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
48
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
49 if (! isempty (fn))
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
50 delete_file = true;
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
51 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
52 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53 info = __magick_finfo__ (fn);
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
55 unwind_protect_cleanup
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 if (delete_file)
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
57 unlink (fn);
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 endif
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59 end_unwind_protect
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
60
bfad37d33435 Connect imfinfo with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
61 endfunction