Mercurial > octave
annotate scripts/image/imformats.m @ 20169:cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
author | Hartmut Gimpel <hg_code@gmx.de> |
---|---|
date | Wed, 04 Feb 2015 22:49:04 +0100 |
parents | 4197fc428c7d |
children | c0f64bc26eee |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19653
diff
changeset
|
1 ## Copyright (C) 2013-2015 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 | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} imformats () | |
21 ## @deftypefnx {Function File} {@var{formats} =} imformats (@var{ext}) | |
22 ## @deftypefnx {Function File} {@var{formats} =} imformats (@var{format}) | |
23 ## @deftypefnx {Function File} {@var{formats} =} imformats ("add", @var{format}) | |
24 ## @deftypefnx {Function File} {@var{formats} =} imformats ("remove", @var{ext}) | |
25 ## @deftypefnx {Function File} {@var{formats} =} imformats ("update", @var{ext}, @var{format}) | |
26 ## @deftypefnx {Function File} {@var{formats} =} imformats ("factory") | |
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 ## | |
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 | 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 | 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) | |
74 if (nargin > 3) | |
75 print_usage (); | |
76 endif | |
77 | |
19653
b95aab49b6be
imformats: memory lock function to prevent "registry" of imageIO to be cleared
Carnë Draug <carandraug@octave.org>
parents:
19278
diff
changeset
|
78 mlock (); # prevent formats to be removed by "clear all" |
16901 | 79 persistent formats = default_formats (); |
80 | |
81 if (nargin == 0 && nargout == 0) | |
20169
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
82 pretty_print_formats(formats); |
16901 | 83 elseif (nargin >= 1) |
84 if (isstruct (arg1)) | |
85 arrayfun (@is_valid_format, arg1); | |
86 ## FIXME: what is the return value in this situation? | |
87 formats = arg1; | |
88 | |
89 elseif (ischar (arg1)) | |
90 switch (tolower (arg1)) | |
91 case "add", | |
92 if (! isstruct (arg2)) | |
93 error ("imformats: FORMAT to %s must be a structure.", arg1); | |
94 endif | |
95 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
|
96 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
|
97 varargout{1} = formats; |
16901 | 98 |
99 case {"remove", "update"}, | |
100 if (! ischar (arg2)) | |
101 error ("imformats: EXT to %s must be a string.", arg1); | |
102 endif | |
103 ## FIXME: suppose a format with multiple extensions. If one of | |
104 ## them is requested to be removed, should we remove the | |
105 ## 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
|
106 match = find_ext_idx (formats, arg2); |
16901 | 107 if (! any (match)) |
108 error ("imformats: no EXT `%s' found.", arg2); | |
109 endif | |
110 if (strcmpi (arg1, "remove")) | |
111 formats(match) = []; | |
112 else | |
113 ## then it's update | |
114 if (! isstruct (arg3)) | |
115 error ("imformats: FORMAT to update must be a structure."); | |
116 endif | |
117 is_valid_format (arg3); | |
118 formats(match) = arg3; | |
119 endif | |
16907
04f4f067eb33
imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents:
16906
diff
changeset
|
120 varargout{1} = formats; |
16901 | 121 |
122 case "factory", | |
123 formats = default_formats (); | |
124 otherwise | |
125 ## 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
|
126 match = find_ext_idx (formats, arg1); |
16901 | 127 ## For matlab compatibility, if we don't find any format we must |
128 ## return an empty struct with NO fields. We can't use match as mask | |
129 if (any (match)) | |
16907
04f4f067eb33
imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents:
16906
diff
changeset
|
130 varargout{1} = formats(match); |
16901 | 131 else |
16907
04f4f067eb33
imformats: fix typos and silence some statements.
Carnë Draug <carandraug@octave.org>
parents:
16906
diff
changeset
|
132 varargout{1} = struct (); |
16901 | 133 endif |
134 endswitch | |
135 else | |
136 error ("imformats: first argument must be either a structure or string."); | |
137 endif | |
138 else | |
139 varargout{1} = formats; | |
140 endif | |
141 endfunction | |
142 | |
143 function formats = default_formats () | |
144 | |
145 ## The available formats are dependent on what the user has installed at | |
146 ## a given time, and how GraphicsMagick was built. Checking for | |
147 ## GraphicsMagick features when building Octave is not enough since it | |
148 ## delegates some of them to external programs which can be removed or | |
149 ## installed at any time. | |
150 ## The recommended method would be to use CoderInfoList() to get a list of | |
151 ## all available coders and try to write and read back a small test image. | |
152 ## But this will not work since some coders are readable or writable only. | |
153 ## It will still fail if we test only the ones marked as readable and | |
154 ## writable because some RW coders are not of image formats (NULL, 8BIM, | |
155 ## or EXIF for example). | |
156 ## So we'd need a blacklist (unacceptable because a `bad' coder may be | |
157 ## added later) or a whitelist. A whitelist means that even with a | |
158 ## super-fancy recent build of GraphicsMagick, some formats won't be listed | |
159 ## by imformats but in truth, we will still be able to read and write them | |
160 ## since imread() and imwrite() will give it a try anyway. | |
161 ## | |
162 ## For more info and comments from the GraphicsMagick main developer, see | |
163 ## http://sourceforge.net/mailarchive/forum.php?thread_name=alpine.GSO.2.01.1304301916050.2267%40freddy.simplesystems.org&forum_name=graphicsmagick-help | |
164 | |
165 persistent formats = struct ( "coder", {}, | |
166 "ext", {}, | |
167 "isa", {}, | |
168 "info", {}, | |
169 "read", {}, | |
170 "write", {}, | |
171 "alpha", {}, | |
172 "description", {}, | |
173 "multipage", {}); | |
174 | |
175 ## Image IO abilities won't change during the same Octave session, | |
176 ## there's no need to go and calculate it all over again if we are | |
177 ## requested to reset back to factory. | |
178 if (! isempty (formats)) | |
17312
088d014a7fe2
Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
179 return; |
16901 | 180 endif |
181 | |
182 ## Building the formats info | |
183 ## | |
184 ## As mentioned above we start with a whitelist of coders. Since the | |
185 ## GraphicsMagick build may be missing some coders, we will remove those | |
186 ## from the list. Some info can be obtained directly from GraphicsMagick | |
187 ## through the CoderInfo object. However, some will need to be hardcoded. | |
188 ## | |
189 ## The association between file extensions and coders needs to be done | |
190 ## with a manually coded list (file extensions do not define the image | |
191 ## format and GraphicsMagick will not be fooled by changing the extension). | |
192 ## | |
193 ## We can get the read, write, description and multipage fields from | |
194 ## CoderInfo in C++. We should do the same for alpha (GraphicsMagick | |
195 ## calls it matte) but it's not available from CoderInfo. The only way to | |
196 ## check it is to create a sample image with each coder, then try to read | |
197 ## it back with GraphicsMagick and use the matte method on the Image class. | |
198 ## But making such test for each Octave session... meh! While technically | |
199 ## it may be possible that the same coder has different support for alpha | |
200 ## channel in different versions and builds, this doesn't seem to happen. | |
201 ## So we also hardcode those. In the future, maybe the CoderInfo class will | |
202 ## have a matte method like it does for multipage. | |
203 ## | |
204 ## Other notes: some formats have more than one coder that do the same. For | |
205 ## example, for jpeg images there is both the JPG and JPEG coders. However, | |
206 ## it seems that when reading images, GraphicsMagick only uses one of them | |
207 ## and that's the one we list (it's the one reported by imfinfo and that we | |
208 ## can use for isa). However, in some cases GraphicsMagick seems to rely | |
209 ## uniquely on the file extension ((JBIG and JBG at least. Create an image | |
210 ## with each of those coders, swap their extension and it will report the | |
211 ## other coder). We don't have such cases on the whitelist but if we did, we | |
212 ## would need two entries for such cases. | |
213 | |
214 ## each row: 1st => Coder, 2nd=> file extensions, 3rd=> alpha | |
215 coders = {"BMP", {"bmp"}, true; | |
216 "CUR", {"cur"}, false; | |
217 "GIF", {"gif"}, true; | |
218 "ICO", {"ico"}, true; | |
219 "JBG", {"jbg"}, false; | |
220 "JBIG", {"jbig"}, false; | |
221 "JP2", {"jp2", "jpx"}, true; | |
222 "JPEG", {"jpg", "jpeg"}, false; # there is also a JPG coder | |
223 "PBM", {"pbm"}, false; | |
224 "PCX", {"pcx"}, true; | |
225 "PGM", {"pgm"}, false; | |
226 "PNG", {"png"}, true; | |
227 ## PNM is a family of formats supporting portable bitmaps (PBM), | |
228 ## graymaps (PGM), and pixmaps (PPM). There is no file format | |
229 ## associated with pnm itself. If PNM is used as the output format | |
230 ## specifier, then GraphicsMagick automatically selects the most | |
231 ## appropriate format to represent the image. | |
232 "PNM", {"pnm"}, true; | |
233 "PPM", {"ppm"}, false; | |
234 "SUN", {"ras"}, true; # SUN Rasterfile | |
235 "TGA", {"tga", "tpic"}, true; | |
236 "TIFF", {"tif", "tiff"}, true; | |
237 "XBM", {"xbm"}, false; | |
238 "XPM", {"xpm"}, true; | |
239 "XWD", {"xwd"}, false; | |
240 }; | |
241 | |
242 for fidx = 1: rows(coders) | |
243 formats(fidx).coder = coders{fidx, 1}; | |
244 formats(fidx).ext = coders{fidx, 2}; | |
245 formats(fidx).alpha = coders{fidx, 3}; | |
246 ## default isa is to check if the format returned by imfinfo is the coder | |
247 formats(fidx).isa = @(x) isa_magick (coders{fidx,1}, x); | |
248 endfor | |
249 | |
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 | 254 |
255 ## fills rest of format information by checking with GraphicsMagick | |
256 formats = __magick_formats__ (formats); | |
257 endfunction | |
258 | |
259 function is_valid_format (format) | |
260 ## the minimal list of fields required in the structure. We don't | |
261 ## require multipage because it doesn't exist in matlab | |
262 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
|
263 fields_mask = isfield (format, min_fields); |
16901 | 264 if (! all (fields_mask)) |
265 error ("imformats: structure has missing field `%s'.", min_fields(! fields_mask){1}); | |
266 endif | |
267 endfunction | |
268 | |
269 function match = find_ext_idx (formats, ext) | |
270 ## XXX: what should we do if there's more than one hit? | |
271 ## Should this function prevent the addition of | |
272 ## duplicated extensions? | |
18292
4718af222d9d
image/imformats.m: be case insensitive about file extension.
Carnë Draug <carandraug@octave.org>
parents:
17580
diff
changeset
|
273 match = cellfun (@(x) any (strcmpi (x, ext)), {formats.ext}); |
16901 | 274 endfunction |
275 | |
276 function bool = isa_magick (coder, filename) | |
277 bool = false; | |
278 try | |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17338
diff
changeset
|
279 info = __magick_ping__ (filename, 1); |
16901 | 280 bool = strcmp (coder, info.Format); |
281 end_try_catch | |
282 endfunction | |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
283 |
20169
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
284 function pretty_print_formats(forms) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
285 |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
286 ## Compute the maximal length of the extensions column |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
287 h1 = "Extension"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
288 ext_seperator = ", "; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
289 max_ext_length = length (h1); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
290 for m = 1:length (forms) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
291 num_ext = length (forms(m).ext); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
292 length_ext = sum (cellfun (@length, forms(m).ext)); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
293 ext_length = length_ext + (num_ext -1) * length(ext_seperator); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
294 if ext_length > max_ext_length |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
295 max_ext_length = ext_length; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
296 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
297 endfor |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
298 h1 = postpad(h1, max_ext_length, " "); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
299 |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
300 ## define header names (none should be shorter than 3 characters) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
301 h2 = "isa"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
302 h3 = "Info"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
303 h4 = "Read"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
304 h5 = "Write"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
305 h6 = "Alpha"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
306 h7 = "Description"; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
307 |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
308 ## print a header |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
309 header = [h1, " | ", h2, " | ", h3, " | ", h4, " | ", h5, " | ", h6, " | ", h7, " "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
310 disp(header); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
311 lineunder = [repmat("-", 1, length(h1)), "-+-", repmat("-", 1, length(h2)), "-+-", ... |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
312 repmat("-", 1, length(h3)), "-+-", repmat("-", 1, length(h4)), "-+-", ... |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
313 repmat("-", 1, length(h5)), "-+-", repmat("-", 1, length(h6)), "-+-", ... |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
314 repmat("-", 1, length(h7)), "-"]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
315 disp(lineunder); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
316 |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
317 ## print the formats |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
318 # ext (h1) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
319 for m = 1:length(forms) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
320 thisline = ""; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
321 num_exts = length(forms(m).ext); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
322 ext_string = ""; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
323 for n = 1:num_exts |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
324 ext_string = [ext_string, forms(m).ext{n}]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
325 if n < num_exts |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
326 ext_string = [ext_string, ext_seperator]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
327 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
328 endfor |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
329 ext_string = postpad(ext_string, length(h1), " "); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
330 thisline = [thisline, ext_string, " | "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
331 # isa (h2) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
332 if isempty(forms(m).isa) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
333 thisline = [thisline, postpad(" no", length(h2), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
334 else |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
335 thisline = [thisline, postpad("yes", length(h2), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
336 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
337 thisline = [thisline, " | "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
338 # info (h3) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
339 if isempty(forms(m).info) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
340 thisline = [thisline, postpad(" no", length(h3), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
341 else |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
342 thisline = [thisline, postpad("yes", length(h3), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
343 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
344 thisline = [thisline, " | "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
345 # read (h4) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
346 if isempty(forms(m).read) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
347 thisline = [thisline, postpad(" no", length(h4), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
348 else |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
349 thisline = [thisline, postpad("yes", length(h4), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
350 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
351 thisline = [thisline, " | "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
352 # write (h5) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
353 if isempty(forms(m).write) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
354 thisline = [thisline, postpad(" no", length(h5), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
355 else |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
356 thisline = [thisline, postpad("yes", length(h5), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
357 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
358 thisline = [thisline, " | "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
359 # alpha (h6) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
360 if isempty(forms(m).write) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
361 thisline = [thisline, postpad(" no", length(h6), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
362 else |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
363 thisline = [thisline, postpad("yes", length(h6), " ")]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
364 endif |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
365 thisline = [thisline, " | "]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
366 # description (h7) |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
367 thisline = [thisline, forms(m).description]; |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
368 # print this format line |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
369 disp(thisline); |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
370 endfor |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
371 endfunction |
cf96961effdb
imformats.m: implement pretty print when nargout is zero (bug #44119)
Hartmut Gimpel <hg_code@gmx.de>
parents:
19697
diff
changeset
|
372 |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
373 ## 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
|
374 ## 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
|
375 ## 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
|
376 |
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
377 ## 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
|
378 %!testif HAVE_MAGICK |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
379 %! 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
|
380 %! 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
|
381 %! 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
|
382 %! 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
|
383 %! 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
|
384 %! 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
|
385 %! 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
|
386 %! 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
|
387 %! 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
|
388 %! 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
|
389 %! 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
|
390 %! 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
|
391 %! 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
|
392 |
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
393 ## 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
|
394 %!testif HAVE_MAGICK |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
395 %! 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
|
396 %! 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
|
397 %! 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
|
398 %! 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
|
399 %! 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
|
400 %! 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
|
401 %! 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
|
402 %! 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
|
403 %! 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
|
404 %! 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
|
405 %! 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
|
406 %! 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
|
407 %! 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
|
408 %! 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
|
409 |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
410 ## 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
|
411 %!testif HAVE_MAGICK |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
412 %! 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
|
413 %! fid1 = fopen (fname1, "w"); |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18298
diff
changeset
|
414 %! 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
|
415 %! 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
|
416 %! 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
|
417 %! 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
|
418 %! 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
|
419 %! 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
|
420 %! 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
|
421 %! 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
|
422 %! 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
|
423 %! 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
|
424 %! 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
|
425 %! 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
|
426 %! 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
|
427 %! 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
|
428 %! 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
|
429 %! 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
|
430 %! 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
|
431 %! 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
|
432 %! 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
|
433 |
18298
15db54c4a572
Fix input parsing for imageIO functions and make imread accept URL (bug #41234)
Carnë Draug <carandraug@octave.org>
parents:
18297
diff
changeset
|
434 ## 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
|
435 %!testif HAVE_MAGICK |
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
436 %! 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
|
437 %! 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
|
438 %! 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
|
439 %! 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
|
440 %! 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
|
441 %! imformats ("factory"); |
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
442 %! 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
|
443 %! 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
|
444 |
18297
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
445 ## 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
|
446 %!testif HAVE_MAGICK |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
447 %! fmt = imformats ("jpg"); |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
448 %! 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
|
449 %! error_thrown = false; |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
450 %! try |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
451 %! 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
|
452 %! catch |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
453 %! error_thrown = true; |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
454 %! end_try_catch |
1589b2fc74ae
imformats.m: add test for updating a format with invalid struct.
Carnë Draug <carandraug@octave.org>
parents:
18292
diff
changeset
|
455 %! assert (error_thrown, true); |
16949
1eb5e5f0ee13
imformats.m: add tests and fix bug when adding new formats.
Carnë Draug <carandraug@octave.org>
parents:
16922
diff
changeset
|
456 |