Mercurial > octave
annotate scripts/image/imformats.m @ 24458:516437d2194d
don't allow function parameters (in or out) to be persistent
* symrec.h (symbol_record::symbol_record_rep::mark_persistent):
Also error if this object is a function argument.
* __unimplemented__.m, imformats.m, odedefaults.m:
Don't make function parameters persistent.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 23 Dec 2017 14:58:27 -0500 |
parents | 092078913d54 |
children | 194eb4bd202b |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
1 ## Copyright (C) 2013-2017 Carnë Draug |
16901 | 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 ## (at your option) any later version. |
16901 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## GNU General Public License for more details. |
16901 | 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 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
20 ## @deftypefn {} {} imformats () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
21 ## @deftypefnx {} {@var{formats} =} imformats (@var{ext}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
22 ## @deftypefnx {} {@var{formats} =} imformats (@var{format}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
23 ## @deftypefnx {} {@var{formats} =} imformats ("add", @var{format}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
24 ## @deftypefnx {} {@var{formats} =} imformats ("remove", @var{ext}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
25 ## @deftypefnx {} {@var{formats} =} imformats ("update", @var{ext}, @var{format}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20176
diff
changeset
|
26 ## @deftypefnx {} {@var{formats} =} imformats ("factory") |
16901 | 27 ## Manage supported image formats. |
28 ## | |
29 ## @var{formats} is a structure with information about each supported file | |
30 ## format, or from a specific format @var{ext}, the value displayed on the | |
31 ## field @code{ext}. It contains the following fields: | |
32 ## | |
33 ## @table @asis | |
34 ## @item ext | |
35 ## The name of the file format. This may match the file extension but Octave | |
36 ## will automatically detect the file format. | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
17086
diff
changeset
|
37 ## |
16901 | 38 ## @item description |
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 | 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 | 44 ## @item write |
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 | 47 ## @item read |
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 | 50 ## @item info |
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 | 53 ## @item alpha |
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 | 56 ## @item multipage |
57 ## Logical value if format supports multipage (multiple images per file). | |
58 ## @end table | |
59 ## | |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
60 ## It is possible to change the way Octave manages file formats with the |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
61 ## options @qcode{"add"}, @qcode{"remove"}, and @qcode{"update"}, and supplying |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
62 ## a 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 | 64 ## |
65 ## This can be used by Octave packages to extend the image reading capabilities | |
66 ## Octave, through use of the PKG_ADD and PKG_DEL commands. | |
67 ## | |
68 ## @seealso{imfinfo, imread, imwrite} | |
69 ## @end deftypefn | |
70 | |
71 ## Author: Carnë Draug <carandraug@octave.org> | |
72 | |
73 function varargout = imformats (arg1, arg2, arg3) | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
74 |
16901 | 75 if (nargin > 3) |
76 print_usage (); | |
77 endif | |
78 | |
19653
b95aab49b6be
imformats: memory lock function to prevent "registry" of imageIO to be cleared
Carnë Draug <carandraug@octave.org>
parents:
19278
diff
changeset
|
79 mlock (); # prevent formats to be removed by "clear all" |
16901 | 80 persistent formats = default_formats (); |
81 | |
82 if (nargin == 0 && nargout == 0) | |
20170
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
83 pretty_print_formats (formats); |
16901 | 84 elseif (nargin >= 1) |
85 if (isstruct (arg1)) | |
86 arrayfun (@is_valid_format, arg1); | |
87 ## FIXME: what is the return value in this situation? | |
88 formats = arg1; | |
89 | |
90 elseif (ischar (arg1)) | |
91 switch (tolower (arg1)) | |
92 case "add", | |
93 if (! isstruct (arg2)) | |
94 error ("imformats: FORMAT to %s must be a structure.", arg1); | |
95 endif | |
96 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
|
97 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
|
98 varargout{1} = formats; |
16901 | 99 |
100 case {"remove", "update"}, | |
101 if (! ischar (arg2)) | |
102 error ("imformats: EXT to %s must be a string.", arg1); | |
103 endif | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
104 ## FIXME: suppose a format with multiple extensions. If one of |
16901 | 105 ## them is requested to be removed, should we remove the |
106 ## 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
|
107 match = find_ext_idx (formats, arg2); |
16901 | 108 if (! any (match)) |
109 error ("imformats: no EXT `%s' found.", arg2); | |
110 endif | |
111 if (strcmpi (arg1, "remove")) | |
112 formats(match) = []; | |
113 else | |
114 ## then it's update | |
115 if (! isstruct (arg3)) | |
116 error ("imformats: FORMAT to update must be a structure."); | |
117 endif | |
118 is_valid_format (arg3); | |
119 formats(match) = arg3; | |
120 endif | |
16907
04f4f067eb33
imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents:
16906
diff
changeset
|
121 varargout{1} = formats; |
16901 | 122 |
123 case "factory", | |
124 formats = default_formats (); | |
125 otherwise | |
126 ## 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
|
127 match = find_ext_idx (formats, arg1); |
16901 | 128 ## For matlab compatibility, if we don't find any format we must |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
129 ## return an empty struct with NO fields. We can't use match as mask |
16901 | 130 if (any (match)) |
16907
04f4f067eb33
imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents:
16906
diff
changeset
|
131 varargout{1} = formats(match); |
16901 | 132 else |
16907
04f4f067eb33
imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents:
16906
diff
changeset
|
133 varargout{1} = struct (); |
16901 | 134 endif |
135 endswitch | |
136 else | |
137 error ("imformats: first argument must be either a structure or string."); | |
138 endif | |
139 else | |
140 varargout{1} = formats; | |
141 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
142 |
16901 | 143 endfunction |
144 | |
24458
516437d2194d
don't allow function parameters (in or out) to be persistent
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
145 function rformats = default_formats () |
16901 | 146 |
147 ## The available formats are dependent on what the user has installed at | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
148 ## a given time, and how GraphicsMagick was built. Checking for |
16901 | 149 ## GraphicsMagick features when building Octave is not enough since it |
150 ## delegates some of them to external programs which can be removed or | |
151 ## installed at any time. | |
152 ## The recommended method would be to use CoderInfoList() to get a list of | |
153 ## all available coders and try to write and read back a small test image. | |
154 ## But this will not work since some coders are readable or writable only. | |
155 ## It will still fail if we test only the ones marked as readable and | |
156 ## writable because some RW coders are not of image formats (NULL, 8BIM, | |
157 ## or EXIF for example). | |
158 ## So we'd need a blacklist (unacceptable because a `bad' coder may be | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
159 ## added later) or a whitelist. A whitelist means that even with a |
16901 | 160 ## super-fancy recent build of GraphicsMagick, some formats won't be listed |
161 ## by imformats but in truth, we will still be able to read and write them | |
162 ## since imread() and imwrite() will give it a try anyway. | |
163 ## | |
164 ## For more info and comments from the GraphicsMagick main developer, see | |
165 ## http://sourceforge.net/mailarchive/forum.php?thread_name=alpine.GSO.2.01.1304301916050.2267%40freddy.simplesystems.org&forum_name=graphicsmagick-help | |
166 | |
167 persistent formats = struct ( "coder", {}, | |
168 "ext", {}, | |
169 "isa", {}, | |
170 "info", {}, | |
171 "read", {}, | |
172 "write", {}, | |
173 "alpha", {}, | |
174 "description", {}, | |
175 "multipage", {}); | |
176 | |
177 ## Image IO abilities won't change during the same Octave session, | |
178 ## there's no need to go and calculate it all over again if we are | |
179 ## requested to reset back to factory. | |
180 if (! isempty (formats)) | |
24458
516437d2194d
don't allow function parameters (in or out) to be persistent
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
181 rformats = formats; |
17312
088d014a7fe2
Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
182 return; |
16901 | 183 endif |
184 | |
185 ## Building the formats info | |
186 ## | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
187 ## As mentioned above we start with a whitelist of coders. Since the |
16901 | 188 ## GraphicsMagick build may be missing some coders, we will remove those |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
189 ## from the list. Some info can be obtained directly from GraphicsMagick |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
190 ## through the CoderInfo object. However, some will need to be hardcoded. |
16901 | 191 ## |
192 ## The association between file extensions and coders needs to be done | |
193 ## with a manually coded list (file extensions do not define the image | |
194 ## format and GraphicsMagick will not be fooled by changing the extension). | |
195 ## | |
196 ## We can get the read, write, description and multipage fields from | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
197 ## CoderInfo in C++. We should do the same for alpha (GraphicsMagick |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
198 ## calls it matte) but it's not available from CoderInfo. The only way to |
16901 | 199 ## check it is to create a sample image with each coder, then try to read |
200 ## it back with GraphicsMagick and use the matte method on the Image class. | |
201 ## But making such test for each Octave session... meh! While technically | |
202 ## it may be possible that the same coder has different support for alpha | |
203 ## channel in different versions and builds, this doesn't seem to happen. | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
204 ## So we also hardcode those. In the future, maybe the CoderInfo class will |
16901 | 205 ## have a matte method like it does for multipage. |
206 ## | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
207 ## Other notes: some formats have more than one coder that do the same. For |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
208 ## example, for jpeg images there is both the JPG and JPEG coders. However, |
16901 | 209 ## it seems that when reading images, GraphicsMagick only uses one of them |
210 ## and that's the one we list (it's the one reported by imfinfo and that we | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
211 ## can use for isa). However, in some cases GraphicsMagick seems to rely |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
212 ## uniquely on the file extension (JBIG and JBG at least. Create an image |
16901 | 213 ## with each of those coders, swap their extension and it will report the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
214 ## other coder). We don't have such cases on the whitelist but if we did, we |
16901 | 215 ## would need two entries for such cases. |
216 | |
217 ## each row: 1st => Coder, 2nd=> file extensions, 3rd=> alpha | |
218 coders = {"BMP", {"bmp"}, true; | |
219 "CUR", {"cur"}, false; | |
220 "GIF", {"gif"}, true; | |
221 "ICO", {"ico"}, true; | |
222 "JBG", {"jbg"}, false; | |
223 "JBIG", {"jbig"}, false; | |
224 "JP2", {"jp2", "jpx"}, true; | |
225 "JPEG", {"jpg", "jpeg"}, false; # there is also a JPG coder | |
226 "PBM", {"pbm"}, false; | |
227 "PCX", {"pcx"}, true; | |
228 "PGM", {"pgm"}, false; | |
229 "PNG", {"png"}, true; | |
230 ## PNM is a family of formats supporting portable bitmaps (PBM), | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
231 ## graymaps (PGM), and pixmaps (PPM). There is no file format |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
232 ## associated with pnm itself. If PNM is used as the output format |
16901 | 233 ## specifier, then GraphicsMagick automatically selects the most |
234 ## appropriate format to represent the image. | |
235 "PNM", {"pnm"}, true; | |
236 "PPM", {"ppm"}, false; | |
237 "SUN", {"ras"}, true; # SUN Rasterfile | |
238 "TGA", {"tga", "tpic"}, true; | |
239 "TIFF", {"tif", "tiff"}, true; | |
240 "XBM", {"xbm"}, false; | |
241 "XPM", {"xpm"}, true; | |
242 "XWD", {"xwd"}, false; | |
243 }; | |
244 | |
245 for fidx = 1: rows(coders) | |
246 formats(fidx).coder = coders{fidx, 1}; | |
247 formats(fidx).ext = coders{fidx, 2}; | |
248 formats(fidx).alpha = coders{fidx, 3}; | |
249 ## default isa is to check if the format returned by imfinfo is the coder | |
250 formats(fidx).isa = @(x) isa_magick (coders{fidx,1}, x); | |
251 endfor | |
252 | |
253 ## 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
|
254 [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
|
255 [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
|
256 [formats.write] = deal (@__imwrite__); |
16901 | 257 |
258 ## fills rest of format information by checking with GraphicsMagick | |
259 formats = __magick_formats__ (formats); | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
260 |
24458
516437d2194d
don't allow function parameters (in or out) to be persistent
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
261 rformats = formats; |
516437d2194d
don't allow function parameters (in or out) to be persistent
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
262 |
16901 | 263 endfunction |
264 | |
265 function is_valid_format (format) | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
266 ## the minimal list of fields required in the structure. We don't |
16901 | 267 ## require multipage because it doesn't exist in matlab |
268 min_fields = {"ext", "read", "isa", "write", "info", "alpha", "description"}; | |
17386
6dbc866379e2
Replace cellfun() occurrences with faster code where possible.
Rik <rik@octave.org>
parents:
17351
diff
changeset
|
269 fields_mask = isfield (format, min_fields); |
16901 | 270 if (! all (fields_mask)) |
271 error ("imformats: structure has missing field `%s'.", min_fields(! fields_mask){1}); | |
272 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
273 |
16901 | 274 endfunction |
275 | |
276 function match = find_ext_idx (formats, ext) | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
277 ## FIXME: what should we do if there's more than one hit? |
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
278 ## Should this function prevent the addition of |
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
279 ## duplicated extensions? |
18292
4718af222d9d
image/imformats.m: be case insensitive about file extension.
Carnë Draug <carandraug@octave.org>
parents:
17580
diff
changeset
|
280 match = cellfun (@(x) any (strcmpi (x, ext)), {formats.ext}); |
16901 | 281 endfunction |
282 | |
283 function bool = isa_magick (coder, filename) | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
284 |
16901 | 285 bool = false; |
286 try | |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17338
diff
changeset
|
287 info = __magick_ping__ (filename, 1); |
16901 | 288 bool = strcmp (coder, info.Format); |
289 end_try_catch | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
290 |
16901 | 291 endfunction |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
292 |
20170
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
293 function pretty_print_formats (formats) |
20169
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
294 ## define header names (none should be shorter than 3 characters) |
20170
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
295 headers = {"Extension", "isa", "Info", "Read", "Write", "Alpha", "Description"}; |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
296 cols_length = cellfun (@numel, headers); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
297 |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
298 ## Adjust the maximal length of the extensions column |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
299 extensions = cellfun (@strjoin, {formats.ext}, {", "}, |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
300 "UniformOutput", false); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
301 cols_length(1) = max (max (cellfun (@numel, extensions)), cols_length(1)); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
302 headers{1} = postpad (headers{1}, cols_length(1), " "); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
303 |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
304 ## Print the headers |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
305 disp (strjoin (headers, " | ")); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
306 under_headers = cellfun (@(x) repmat ("-", 1, numel (x)), headers, |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
307 "UniformOutput", false); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
308 disp (strjoin (under_headers, "-+-")); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
309 |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
310 template = strjoin (arrayfun (@(x) sprintf ("%%-%is", x), cols_length, |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
311 "UniformOutput", false), " | "); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
312 |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
313 ## Print the function handle for this things won't be a pretty table. So |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
314 ## instead we replace them with "yes" or "no", based on the support it has. |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
315 yes_no_cols = cat (2, {formats.isa}(:), {formats.info}(:), {formats.read}(:), |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
316 {formats.write}(:), {formats.alpha}(:)); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
317 empty = cellfun (@isempty, yes_no_cols); |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
318 yes_no_cols(empty) = "no"; |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
319 yes_no_cols(! empty) = "yes"; |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
320 |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
321 descriptions = {formats.description}; |
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
322 table = cat (2, extensions(:), yes_no_cols, descriptions(:)); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
323 printf ([template "\n"], table'{:}); |
20170
c0f64bc26eee
imformats.m: rewrite pretty print of format table.
Carnë Draug <carandraug@octave.org>
parents:
20169
diff
changeset
|
324 |
20169
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
325 endfunction |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
326 |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
327 |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
328 ## This must work, even without support for image IO |
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
329 %!test |
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
330 %! formats = imformats (); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
331 %! assert (isstruct (formats)); |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
332 %! |
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
333 %! min_fields = {"ext", "read", "isa", "write", "info", "alpha", "description"}; |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
334 %! assert (all (ismember (min_fields, fieldnames (formats)))); |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
335 %! |
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
336 %! if (__have_feature__ ("MAGICK")) |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
337 %! assert (numel (formats) > 0); |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
338 %! else |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
339 %! assert (numel (formats), 0); |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
340 %! endif |
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
20852
diff
changeset
|
341 |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
342 ## When imread or imfinfo are called, the file must exist or the |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
343 ## function defined by imformats will never be called. Because |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
344 ## of this, we must create a file for the tests to work. |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
345 |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
346 ## changing the function that does the reading |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
347 %!testif HAVE_MAGICK |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
348 %! fname = [tempname() ".jpg"]; |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
349 %! def_fmt = imformats (); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
350 %! fid = fopen (fname, "w"); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
351 %! unwind_protect |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
352 %! fmt = imformats ("jpg"); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
353 %! fmt.read = @numel; |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
354 %! imformats ("update", "jpg", fmt); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
355 %! assert (imread (fname), numel (fname)); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
356 %! unwind_protect_cleanup |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
357 %! fclose (fid); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
358 %! unlink (fname); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
359 %! imformats (def_fmt); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
360 %! end_unwind_protect |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
361 |
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
362 ## 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
|
363 %!testif HAVE_MAGICK |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
364 %! fname = [tempname() ".new_fmt"]; |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
365 %! def_fmt = imformats (); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
366 %! fid = fopen (fname, "w"); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
367 %! unwind_protect |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
368 %! fmt = imformats ("jpg"); # take jpg as template |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
369 %! fmt.ext = "new_fmt"; |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
370 %! fmt.read = @() true (); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
371 %! imformats ("add", fmt); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
372 %! assert (imread (fname), true); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
373 %! unwind_protect_cleanup |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
374 %! fclose (fid); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
375 %! unlink (fname); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
376 %! imformats (def_fmt); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
377 %! end_unwind_protect |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
378 |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
379 ## adding multiple formats at the same time |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
380 %!testif HAVE_MAGICK |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
381 %! fname1 = [tempname() ".new_fmt1"]; |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
382 %! fid1 = fopen (fname1, "w"); |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
383 %! fname2 = [tempname() ".new_fmt2"]; |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
384 %! fid2 = fopen (fname2, "w"); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
385 %! def_fmt = imformats (); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
386 %! unwind_protect |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
387 %! fmt = imformats ("jpg"); # take jpg as template |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
388 %! fmt.ext = "new_fmt1"; |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
389 %! fmt.read = @() true(); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
390 %! fmt(2) = fmt(1); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
391 %! fmt(2).ext = "new_fmt2"; |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
392 %! imformats ("add", fmt); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
393 %! assert (imread (fname1), true); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
394 %! assert (imread (fname2), true); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
395 %! unwind_protect_cleanup |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
396 %! fclose (fid1); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
397 %! fclose (fid2); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
398 %! unlink (fname1); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
399 %! unlink (fname2); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
400 %! imformats (def_fmt); |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
401 %! end_unwind_protect |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
402 |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
403 ## changing format and resetting back to default |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
404 %!testif HAVE_MAGICK |
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
405 %! 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
|
406 %! 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
|
407 %! 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
|
408 %! 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
|
409 %! 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
|
410 %! imformats ("factory"); |
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
411 %! 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
|
412 %! 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
|
413 |
18297
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
414 ## updating to an invalid format should cause an error |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
415 %!testif HAVE_MAGICK |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
416 %! fmt = imformats ("jpg"); |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
417 %! fmt = rmfield (fmt, "read"); |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
418 %! error_thrown = false; |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
419 %! try |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
420 %! imformats ("update", "jpg", fmt); |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
421 %! catch |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
422 %! error_thrown = true; |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
423 %! end_try_catch |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
424 %! assert (error_thrown, true); |