annotate scripts/image/imformats.m @ 17351:80bf005cdf8e

New function __magick_ping__ to speed reading of images. * __magick_read__.cc (__magick_ping__): New function that only pings one of the images in a file to obtain height, width and format information. This becomes an alternative to imfinfo for internal Octave functions. Because imfinfo requires reading of the whole file and all images, this has a large speed increase, specially for multipage images. * imformats.m: use __magick_ping__() to check image format. * private/__imread__.m: use __magick_ping__() to get rows and columns of an image which is used to set the reading defaults.
author Carnë Draug <carandraug@octave.org>
date Fri, 30 Aug 2013 07:19:13 +0100
parents 1c89599167a6
children 6dbc866379e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
1 ## Copyright (C) 2013 Carnë Draug
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
2 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
4 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
8 ## your option) any later version.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
9 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
18
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
20 ## @deftypefn {Function File} {} imformats ()
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
21 ## @deftypefnx {Function File} {@var{formats} =} imformats (@var{ext})
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{formats} =} imformats (@var{format})
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
23 ## @deftypefnx {Function File} {@var{formats} =} imformats ("add", @var{format})
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
24 ## @deftypefnx {Function File} {@var{formats} =} imformats ("remove", @var{ext})
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25 ## @deftypefnx {Function File} {@var{formats} =} imformats ("update", @var{ext}, @var{format})
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
26 ## @deftypefnx {Function File} {@var{formats} =} imformats ("factory")
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27 ## Manage supported image formats.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
28 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 ## @var{formats} is a structure with information about each supported file
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30 ## format, or from a specific format @var{ext}, the value displayed on the
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31 ## field @code{ext}. It contains the following fields:
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33 ## @table @asis
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 ## @item ext
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35 ## The name of the file format. This may match the file extension but Octave
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36 ## will automatically detect the file format.
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
37 ##
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
38 ## @item description
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
39 ## A long description of the file format.
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
40 ##
16922
bfd119642f6a doc: Fix some spellings in image.texi.
Rik <rik@octave.org>
parents: 16916
diff changeset
41 ## @item @nospell{isa}
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 ## A function handle to confirm if a file is of the specified format.
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
43 ##
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 ## @item write
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45 ## A function handle to write if a file is of the specified format.
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
46 ##
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 ## @item read
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
48 ## A function handle to open files the specified format.
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
49 ##
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
50 ## @item info
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
51 ## A function handle to obtain image information of the specified format.
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
52 ##
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53 ## @item alpha
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54 ## Logical value if format supports alpha channel (transparency or matte).
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17086
diff changeset
55 ##
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 ## @item multipage
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
57 ## Logical value if format supports multipage (multiple images per file).
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 ## @end table
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
60 ## It is possible to change the way Octave manages file formats with the options
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
61 ## @qcode{"add"}, @qcode{"remove"}, and @qcode{"update"}, and supplying a
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
62 ## structure @var{format} with the required fields. The option
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
63 ## @qcode{"factory"} resets the configuration to the default.
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
64 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65 ## This can be used by Octave packages to extend the image reading capabilities
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
66 ## Octave, through use of the PKG_ADD and PKG_DEL commands.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
67 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
68 ## @seealso{imfinfo, imread, imwrite}
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
69 ## @end deftypefn
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
70
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
71 ## Author: Carnë Draug <carandraug@octave.org>
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
72
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
73 function varargout = imformats (arg1, arg2, arg3)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
74 if (nargin > 3)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
75 print_usage ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
76 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
77
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
78 persistent formats = default_formats ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
79
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
80 if (nargin == 0 && nargout == 0)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
81 error ("imformats: pretty print not yet implemented.");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
82 elseif (nargin >= 1)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
83 if (isstruct (arg1))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
84 arrayfun (@is_valid_format, arg1);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
85 ## FIXME: what is the return value in this situation?
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
86 formats = arg1;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
87
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
88 elseif (ischar (arg1))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
89 switch (tolower (arg1))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
90 case "add",
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
91 if (! isstruct (arg2))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
92 error ("imformats: FORMAT to %s must be a structure.", arg1);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
93 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
94 arrayfun (@is_valid_format, arg2);
16949
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
95 formats(end + 1: end + numel (arg2)) = arg2;
16907
04f4f067eb33 imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
96 varargout{1} = formats;
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
97
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
98 case {"remove", "update"},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
99 if (! ischar (arg2))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
100 error ("imformats: EXT to %s must be a string.", arg1);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
101 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
102 ## FIXME: suppose a format with multiple extensions. If one of
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
103 ## them is requested to be removed, should we remove the
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
104 ## whole format, or just that extension from the format?
16907
04f4f067eb33 imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
105 match = find_ext_idx (formats, arg2);
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
106 if (! any (match))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
107 error ("imformats: no EXT `%s' found.", arg2);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
108 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
109 if (strcmpi (arg1, "remove"))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
110 formats(match) = [];
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
111 else
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
112 ## then it's update
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
113 if (! isstruct (arg3))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
114 error ("imformats: FORMAT to update must be a structure.");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
115 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
116 is_valid_format (arg3);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
117 formats(match) = arg3;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
118 endif
16907
04f4f067eb33 imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
119 varargout{1} = formats;
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
120
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
121 case "factory",
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
122 formats = default_formats ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
123 otherwise
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
124 ## then we look for a format with that extension.
16907
04f4f067eb33 imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
125 match = find_ext_idx (formats, arg1);
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
126 ## For matlab compatibility, if we don't find any format we must
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
127 ## return an empty struct with NO fields. We can't use match as mask
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
128 if (any (match))
16907
04f4f067eb33 imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
129 varargout{1} = formats(match);
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
130 else
16907
04f4f067eb33 imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents: 16906
diff changeset
131 varargout{1} = struct ();
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
132 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
133 endswitch
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
134 else
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
135 error ("imformats: first argument must be either a structure or string.");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
136 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
137 else
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
138 varargout{1} = formats;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
139 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
140 endfunction
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
141
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
142 function formats = default_formats ()
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
143
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
144 ## The available formats are dependent on what the user has installed at
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
145 ## a given time, and how GraphicsMagick was built. Checking for
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
146 ## GraphicsMagick features when building Octave is not enough since it
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
147 ## delegates some of them to external programs which can be removed or
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
148 ## installed at any time.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
149 ## The recommended method would be to use CoderInfoList() to get a list of
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
150 ## all available coders and try to write and read back a small test image.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
151 ## But this will not work since some coders are readable or writable only.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
152 ## It will still fail if we test only the ones marked as readable and
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
153 ## writable because some RW coders are not of image formats (NULL, 8BIM,
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
154 ## or EXIF for example).
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
155 ## So we'd need a blacklist (unacceptable because a `bad' coder may be
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
156 ## added later) or a whitelist. A whitelist means that even with a
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
157 ## super-fancy recent build of GraphicsMagick, some formats won't be listed
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
158 ## by imformats but in truth, we will still be able to read and write them
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
159 ## since imread() and imwrite() will give it a try anyway.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
160 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
161 ## For more info and comments from the GraphicsMagick main developer, see
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
162 ## http://sourceforge.net/mailarchive/forum.php?thread_name=alpine.GSO.2.01.1304301916050.2267%40freddy.simplesystems.org&forum_name=graphicsmagick-help
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
163
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
164 persistent formats = struct ( "coder", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
165 "ext", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
166 "isa", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
167 "info", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
168 "read", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
169 "write", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
170 "alpha", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
171 "description", {},
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
172 "multipage", {});
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
173
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
174 ## Image IO abilities won't change during the same Octave session,
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
175 ## there's no need to go and calculate it all over again if we are
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
176 ## requested to reset back to factory.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
177 if (! isempty (formats))
17312
088d014a7fe2 Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents: 17281
diff changeset
178 return;
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
179 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
180
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
181 ## Building the formats info
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
182 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
183 ## As mentioned above we start with a whitelist of coders. Since the
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
184 ## GraphicsMagick build may be missing some coders, we will remove those
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
185 ## from the list. Some info can be obtained directly from GraphicsMagick
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
186 ## through the CoderInfo object. However, some will need to be hardcoded.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
187 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
188 ## The association between file extensions and coders needs to be done
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
189 ## with a manually coded list (file extensions do not define the image
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
190 ## format and GraphicsMagick will not be fooled by changing the extension).
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
191 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
192 ## We can get the read, write, description and multipage fields from
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
193 ## CoderInfo in C++. We should do the same for alpha (GraphicsMagick
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
194 ## calls it matte) but it's not available from CoderInfo. The only way to
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
195 ## check it is to create a sample image with each coder, then try to read
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
196 ## it back with GraphicsMagick and use the matte method on the Image class.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
197 ## But making such test for each Octave session... meh! While technically
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
198 ## it may be possible that the same coder has different support for alpha
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
199 ## channel in different versions and builds, this doesn't seem to happen.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
200 ## So we also hardcode those. In the future, maybe the CoderInfo class will
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
201 ## have a matte method like it does for multipage.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
202 ##
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
203 ## Other notes: some formats have more than one coder that do the same. For
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
204 ## example, for jpeg images there is both the JPG and JPEG coders. However,
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
205 ## it seems that when reading images, GraphicsMagick only uses one of them
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
206 ## and that's the one we list (it's the one reported by imfinfo and that we
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
207 ## can use for isa). However, in some cases GraphicsMagick seems to rely
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
208 ## uniquely on the file extension ((JBIG and JBG at least. Create an image
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
209 ## with each of those coders, swap their extension and it will report the
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
210 ## other coder). We don't have such cases on the whitelist but if we did, we
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
211 ## would need two entries for such cases.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
212
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
213 ## each row: 1st => Coder, 2nd=> file extensions, 3rd=> alpha
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
214 coders = {"BMP", {"bmp"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
215 "CUR", {"cur"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
216 "GIF", {"gif"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
217 "ICO", {"ico"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
218 "JBG", {"jbg"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
219 "JBIG", {"jbig"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
220 "JP2", {"jp2", "jpx"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
221 "JPEG", {"jpg", "jpeg"}, false; # there is also a JPG coder
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
222 "PBM", {"pbm"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
223 "PCX", {"pcx"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
224 "PGM", {"pgm"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
225 "PGM", {"pgm"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
226 "PNG", {"png"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
227 ## PNM is a family of formats supporting portable bitmaps (PBM),
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
228 ## graymaps (PGM), and pixmaps (PPM). There is no file format
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
229 ## associated with pnm itself. If PNM is used as the output format
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
230 ## specifier, then GraphicsMagick automatically selects the most
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
231 ## appropriate format to represent the image.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
232 "PNM", {"pnm"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
233 "PPM", {"ppm"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
234 "SUN", {"ras"}, true; # SUN Rasterfile
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
235 "TGA", {"tga", "tpic"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
236 "TIFF", {"tif", "tiff"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
237 "XBM", {"xbm"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
238 "XPM", {"xpm"}, true;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
239 "XWD", {"xwd"}, false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
240 };
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
241
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
242 for fidx = 1: rows(coders)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
243 formats(fidx).coder = coders{fidx, 1};
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
244 formats(fidx).ext = coders{fidx, 2};
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
245 formats(fidx).alpha = coders{fidx, 3};
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
246 ## default isa is to check if the format returned by imfinfo is the coder
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
247 formats(fidx).isa = @(x) isa_magick (coders{fidx,1}, x);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
248 endfor
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
249
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
250 ## the default info, read, and write functions
17086
3db796f89695 Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents: 16949
diff changeset
251 [formats.info ] = deal (@__imfinfo__);
3db796f89695 Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents: 16949
diff changeset
252 [formats.read ] = deal (@__imread__);
3db796f89695 Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents: 16949
diff changeset
253 [formats.write] = deal (@__imwrite__);
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
254
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
255 ## fills rest of format information by checking with GraphicsMagick
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
256 formats = __magick_formats__ (formats);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
257 endfunction
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
258
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
259 function is_valid_format (format)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
260 ## the minimal list of fields required in the structure. We don't
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
261 ## require multipage because it doesn't exist in matlab
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
262 min_fields = {"ext", "read", "isa", "write", "info", "alpha", "description"};
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
263 fields_mask = cellfun (@(x) isfield (format, x), min_fields);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
264 if (! all (fields_mask))
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
265 error ("imformats: structure has missing field `%s'.", min_fields(! fields_mask){1});
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
266 endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
267 endfunction
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
268
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
269 function match = find_ext_idx (formats, ext)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
270 ## FIXME: is matlab sensitive to file extensions?
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
271 ## XXX: what should we do if there's more than one hit?
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
272 ## Should this function prevent the addition of
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
273 ## duplicated extensions?
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
274 match = cellfun (@(x) any (strcmp (x, ext)), {formats.ext});
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
275 endfunction
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
276
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
277 function bool = isa_magick (coder, filename)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
278 bool = false;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
279 try
17351
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17338
diff changeset
280 info = __magick_ping__ (filename, 1);
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
281 bool = strcmp (coder, info.Format);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
282 end_try_catch
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
283 endfunction
16949
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
284
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17312
diff changeset
285
16949
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
286 ## changing the function to read
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
287 %!testif HAVE_MAGICK
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
288 %! fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
289 %! fmt.read = @(x) size (x, 2);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
290 %! imformats ("update", "jpg", fmt);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
291 %! assert (imread ("this is 30 characters long.jpg"), 30);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
292
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
293 ## adding a new format
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
294 %!testif HAVE_MAGICK
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
295 %! fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
296 %! fmt.ext = "junk";
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
297 %! fmt.read = @(x) true();
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
298 %! imformats ("add", fmt);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
299 %! assert (imread ("some file.junk"), true);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
300
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
301 ## adding multiple formats in one way
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
302 %!testif HAVE_MAGICK
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
303 %! fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
304 %! fmt.ext = "junk1";
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
305 %! fmt.read = @(x) true();
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
306 %! fmt(2) = fmt(1);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
307 %! fmt(2).ext = "junk2";
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
308 %! imformats ("add", fmt);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
309 %! assert (imread ("some file.junk1"), true);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
310 %! assert (imread ("some file.junk2"), true);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
311
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
312 ## changing format
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
313 %!testif HAVE_MAGICK
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
314 %! ori_fmt = mod_fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
315 %! mod_fmt.description = "Another description";
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
316 %! imformats ("update", "jpg", mod_fmt);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
317 %! new_fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
318 %! assert (new_fmt.description, mod_fmt.description);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
319 %! imformats ("factory");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
320 %! new_fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
321 %! assert (new_fmt.description, ori_fmt.description);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
322
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
323 ## FIXME: how to test for error together with testif?
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
324 ## update to an invalid format
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
325 #%!testif HAVE_MAGICK
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
326 #%! fmt = imformats ("jpg");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
327 #%! fmt = rmfield (fmt, "read");
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
328 #%! error imformats ("update", "jpg", fmt);
1eb5e5f0ee13 imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents: 16922
diff changeset
329