Mercurial > octave
changeset 21489:ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
* __magick_read__.cc (__magick_formats__): if Octave was built without
support for image IO, return an empty struct instead of error. If we
have no support for image format, it doesn't matter if that's because
of limited configuration on the GraphicsMagick build or Octave.
Remember we can't even promise support for all formats at the same time,
that's dependent on the configuration of GraphicsMagick.
* imformats.m: add simple test for even when we were built without
support for image IO.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Fri, 18 Mar 2016 22:52:28 +0000 |
parents | 9dbc8f8bc2d7 |
children | 243b04c97b56 |
files | libinterp/dldfcn/__magick_read__.cc scripts/image/imformats.m |
diffstat | 2 files changed, 21 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc Fri Mar 18 17:52:30 2016 -0400 +++ b/libinterp/dldfcn/__magick_read__.cc Fri Mar 18 22:52:28 2016 +0000 @@ -2226,14 +2226,14 @@ @seealso{imfinfo, imformats, imread, imwrite}\n\ @end deftypefn") { -#ifdef HAVE_MAGICK - maybe_initialize_magick (); - if (args.length () != 1 || ! args(0).is_map ()) print_usage (); octave_map formats = args(0).map_value (); +#ifdef HAVE_MAGICK + maybe_initialize_magick (); + for (octave_idx_type idx = 0; idx < formats.numel (); idx++) { try @@ -2260,11 +2260,11 @@ } } - return ovl (formats); +#else + formats = octave_map (dim_vector (1, 0), formats.fieldnames ()); +#endif -#else - err_disabled_feature ("imformats", "Image IO"); -#endif + return ovl (formats); } /*
--- a/scripts/image/imformats.m Fri Mar 18 17:52:30 2016 -0400 +++ b/scripts/image/imformats.m Fri Mar 18 22:52:28 2016 +0000 @@ -315,6 +315,20 @@ endfunction +## This must work, even without support for image IO +%!test +%! formats = imformats (); +%! assert (isstruct (formats)) +%! +%! min_fields = {"ext", "read", "isa", "write", "info", "alpha", "description"}; +%! assert (all (ismember (min_fields, fieldnames (formats)))) +%! +%! if (__have_feature__ ("MAGICK")) +%! assert (numel (formats) > 0) +%! else +%! assert (numel (formats), 0) +%! endif + ## When imread or imfinfo are called, the file must exist or the ## function defined by imformats will never be called. Because ## of this, we must create a file for the tests to work.