Mercurial > octave-antonio
comparison scripts/image/imread.m @ 16913:d0558ee259ad
Connect imread with imformats.
* private/core_imread.m: new function. Old code from imread() moved here just
like what happened to imfinfo(). See message on cset bfad37d33435
* imfinfo.m: reduced to minimum input check, until finding filename. Passes
all arguments to imageIO().
* imformats.m: change calls to imread() to the new core_imread().
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sun, 07 Jul 2013 18:26:25 +0100 |
parents | e2de3c8882be |
children | 1b3b3ee88284 |
comparison
equal
deleted
inserted
replaced
16912:6bd74153c3ae | 16913:d0558ee259ad |
---|---|
40 ## | 40 ## |
41 ## @seealso{imwrite, imfinfo} | 41 ## @seealso{imwrite, imfinfo} |
42 ## @end deftypefn | 42 ## @end deftypefn |
43 | 43 |
44 function varargout = imread (filename, varargin) | 44 function varargout = imread (filename, varargin) |
45 | |
46 if (nargin < 1) | 45 if (nargin < 1) |
47 print_usage (); | 46 print_usage (); |
48 endif | 47 elseif (! ischar (filename)) |
49 | |
50 if (! ischar (filename)) | |
51 error ("imread: FILENAME must be a string"); | 48 error ("imread: FILENAME must be a string"); |
52 endif | 49 endif |
53 | 50 varargout{1:nargout} = imageIO (@core_imread, "read", filename, |
54 filename = tilde_expand (filename); | 51 filename, varargin{:}); |
55 | |
56 fn = file_in_path (IMAGE_PATH, filename); | |
57 | |
58 if (isempty (fn)) | |
59 error ("imread: cannot find %s", filename); | |
60 endif | |
61 | |
62 try | |
63 [varargout{1:nargout}] = __magick_read__ (fn, varargin{:}); | |
64 catch | |
65 | |
66 magick_error = lasterr (); | |
67 | |
68 img_field = false; | |
69 x_field = false; | |
70 map_field = false; | |
71 | |
72 try | |
73 vars = load (fn); | |
74 if (isstruct (vars)) | |
75 img_field = isfield (vars, "img"); | |
76 x_field = isfield (vars, "X"); | |
77 map_field = isfield (vars, "map"); | |
78 endif | |
79 catch | |
80 error ("imread: invalid image file: %s", magick_error); | |
81 end_try_catch | |
82 | |
83 if (map_field && (img_field || x_field)) | |
84 varargout{2} = vars.map; | |
85 if (img_field) | |
86 varargout{1} = vars.img; | |
87 else | |
88 varargout{1} = vars.X; | |
89 endif | |
90 else | |
91 error ("imread: invalid Octave image file format"); | |
92 endif | |
93 | |
94 end_try_catch | |
95 | |
96 endfunction | 52 endfunction |
97 | |
98 | 53 |
99 %!testif HAVE_MAGICK | 54 %!testif HAVE_MAGICK |
100 %! vpng = [ ... | 55 %! vpng = [ ... |
101 %! 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, ... | 56 %! 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, ... |
102 %! 0, 13, 73, 72, 68, 82, 0, 0, 0, 3, ... | 57 %! 0, 13, 73, 72, 68, 82, 0, 0, 0, 3, ... |