# HG changeset patch # User Carnë Draug # Date 1376362251 -3600 # Node ID 35abfa2e5a275d406fb616c473228d8300eab2e2 # Parent 46805642048f4329314a6be6dd8871a9b88417b6 Fix reading of the deprecated Octave native image format. * private/__imread__.m: enclose everything under a try statement instead of only the call to __magick_read__() since we now need imfinfo to set read defaults and it fails with Octave's native image format. diff -r 46805642048f -r 35abfa2e5a27 scripts/image/private/__imread__.m --- a/scripts/image/private/__imread__.m Thu Aug 08 17:41:50 2013 +0100 +++ b/scripts/image/private/__imread__.m Tue Aug 13 03:50:51 2013 +0100 @@ -56,74 +56,74 @@ error ("imread: cannot find %s", filename); endif - info = imfinfo (fn)(1); - ## set default for options - options = struct ("index", 1, - "region", {{1:1:info.Height 1:1:info.Width}}); + try + info = imfinfo (fn)(1); + ## set default for options + options = struct ("index", 1, + "region", {{1:1:info.Height 1:1:info.Width}}); - ## Index is the only option that can be defined without the parameter/value - ## pair style. When defining it here, the string "all" is invalid though. - if (nargin >= offset + 1 && ! ischar (varargin{offset})) - if (! is_valid_index_option (options.index)) - error ("imread: IDX must be a numeric vector"); + ## Index is the only option that can be defined without the parameter/value + ## pair style. When defining it here, the string "all" is invalid though. + if (nargin >= offset + 1 && ! ischar (varargin{offset})) + if (! is_valid_index_option (options.index)) + error ("imread: IDX must be a numeric vector"); + endif + options.index = varargin{offset}; + offset++; endif - options.index = varargin{offset}; - offset++; - endif - - if (rem (numel (varargin) - offset + 1, 2) != 0) - error ("imread: no pair for all arguments (even number left)"); - endif - - for idx = offset:2:(numel (varargin) - offset + 1) - switch (tolower (varargin{idx})) + if (rem (numel (varargin) - offset + 1, 2) != 0) + error ("imread: no pair for all arguments (even number left)"); + endif - case {"frames", "index"}, - options.index = varargin{idx+1}; - if (! (is_valid_index_option (options.index)) && - ! (ischar (options.index) && strcmpi (options.index, "all"))) - error ("imread: value for %s must be a vector or the string `all'"); - endif + for idx = offset:2:(numel (varargin) - offset + 1) + + switch (tolower (varargin{idx})) - case "pixelregion", - options.region = varargin{idx+1}; - if (! iscell (options.region) || numel (options.region) != 2) - error ("imread: value for %s must be a 2 element cell array", - varargin{idx}); - endif - for reg_idx = 1:2 - if (numel (options.region{reg_idx}) == 3) - ## do nothing - elseif (numel (options.region{reg_idx}) == 2) - options.region{reg_idx}(3) = options.region{reg_idx}(2); - options.region{reg_idx}(2) = 1; - else - error ("imread: range for %s must be a 2 or 3 element vector", + case {"frames", "index"}, + options.index = varargin{idx+1}; + if (! (is_valid_index_option (options.index)) && + ! (ischar (options.index) && strcmpi (options.index, "all"))) + error ("imread: value for %s must be a vector or the string `all'"); + endif + + case "pixelregion", + options.region = varargin{idx+1}; + if (! iscell (options.region) || numel (options.region) != 2) + error ("imread: value for %s must be a 2 element cell array", varargin{idx}); endif - options.region{reg_idx} = floor (options.region{reg_idx}(1)): ... - floor (options.region{reg_idx}(2)): ... - floor (options.region{reg_idx}(3)); - endfor - if (options.region{1}(end) > info.Height) - error ("imread: end ROWS for PixelRegions option is larger than image height"); - elseif (options.region{2}(end) > info.Width) - error ("imread: end COLS for PixelRegions option is larger than image width"); - endif + for reg_idx = 1:2 + if (numel (options.region{reg_idx}) == 3) + ## do nothing + elseif (numel (options.region{reg_idx}) == 2) + options.region{reg_idx}(3) = options.region{reg_idx}(2); + options.region{reg_idx}(2) = 1; + else + error ("imread: range for %s must be a 2 or 3 element vector", + varargin{idx}); + endif + options.region{reg_idx} = floor (options.region{reg_idx}(1)): ... + floor (options.region{reg_idx}(2)): ... + floor (options.region{reg_idx}(3)); + endfor + if (options.region{1}(end) > info.Height) + error ("imread: end ROWS for PixelRegions option is larger than image height"); + elseif (options.region{2}(end) > info.Width) + error ("imread: end COLS for PixelRegions option is larger than image width"); + endif - case "info", - ## We ignore this option. This parameter exists in Matlab to - ## speed up the reading of multipage TIFF. It makes no difference - ## for us since we're already quite efficient. + case "info", + ## We ignore this option. This parameter exists in Matlab to + ## speed up the reading of multipage TIFF. It makes no difference + ## for us since we're already quite efficient. - otherwise - error ("imread: invalid PARAMETER `%s'", varargin{idx}); + otherwise + error ("imread: invalid PARAMETER `%s'", varargin{idx}); - endswitch - endfor + endswitch + endfor - try [varargout{1:nargout}] = __magick_read__ (fn, options); catch