time | calls | line |
---|
| | 1 | function varargout = imformats(varargin)
|
| | 2 | %IMFORMATS Manage file format registry.
|
| | 3 | % FORMATS = IMFORMATS returns a structure containing all of the values in
|
| | 4 | % the file format registry. The fields in this structure are:
|
| | 5 | %
|
| | 6 | % ext - A cell array of file extensions for this format
|
| | 7 | % isa - Function to determine if a file "IS A" certain type
|
| | 8 | % info - Function to read information about a file
|
| | 9 | % read - Function to read image data a file
|
| | 10 | % write - Function to write MATLAB data to a file
|
| | 11 | % alpha - 1 if the format has an alpha channel, 0 otherwise
|
| | 12 | % description - A text description of the file format
|
| | 13 | %
|
| | 14 | % The values for the isa, info, read, and write fields must be functions
|
| | 15 | % which are on the MATLAB search path or function handles.
|
| | 16 | %
|
| | 17 | % FORMATS = IMFORMATS(FMT) searches the known formats for a format with
|
| | 18 | % extension given in the string "FMT." If found, a structure is returned
|
| | 19 | % containing the characteristics and function names. Otherwise an empty
|
| | 20 | % structure is returned.
|
| | 21 | %
|
| | 22 | % FORMATS = IMFORMATS(FORMAT_STRUCT) sets the format registry to contain
|
| | 23 | % the values in the "FORMAT_STRUCT" structure. The output structure
|
| | 24 | % FORMATS contains the new registry settings. See the "Warning" statement
|
| | 25 | % below.
|
| | 26 | %
|
| | 27 | % FORMATS = IMFORMATS('add', FORMAT_STRUCT) adds the values in the
|
| | 28 | % "FORMAT_STRUCT" structure to the format registry.
|
| | 29 | %
|
| | 30 | % FORMATS = IMFORMATS('factory') resets the file format registry to the
|
| | 31 | % default format registry values. This removes any user-specified
|
| | 32 | % settings.
|
| | 33 | %
|
| | 34 | % FORMATS = IMFORMATS('remove', FMT) removes the format with extension
|
| | 35 | % FMT from the format registry.
|
| | 36 | %
|
| | 37 | % FORMATS = IMFORMATS('update', FMT, FORMAT_STRUCT) change the format
|
| | 38 | % registry values for the format with extension FMT to have the values
|
| | 39 | % stored in FORMAT_STRUCT.
|
| | 40 | %
|
| | 41 | % IMFORMATS without any input or output arguments prettyprints a table of
|
| | 42 | % file format information for the supported formats.
|
| | 43 | %
|
| | 44 | % Warning:
|
| | 45 | %
|
| | 46 | % Using IMFORMATS to change the format registry is an advanced feature.
|
| | 47 | % Incorrect usage may prevent loading of image files. Use IMFORMATS
|
| | 48 | % with the 'factory' setting to return the format registry to a workable
|
| | 49 | % state.
|
| | 50 | %
|
| | 51 | % Note:
|
| | 52 | %
|
| | 53 | % Changes to the format registry do not persist between MATLAB sessions.
|
| | 54 | % To have a format always available when you start MATLAB, add the
|
| | 55 | % appropriate IMFORMATS commands to the startup.m file in
|
| | 56 | % $MATLAB/toolbox/local.
|
| | 57 | %
|
| | 58 | % See also IMREAD, IMWRITE, IMFINFO, PATH.
|
| | 59 |
|
| | 60 | % Copyright 1984-2013 The MathWorks, Inc.
|
| | 61 |
|
| | 62 | % Verify correct number of arguments
|
| 6 | 63 | narginchk(0, 3);
|
| 6 | 64 | nargoutchk(0, 1);
|
| | 65 |
|
| | 66 | % Declare format structure as persistent variable
|
| 6 | 67 | persistent fmts;
|
| | 68 |
|
| | 69 | % If format structure is empty (first time)
|
| 6 | 70 | if (isempty(fmts))
|
| | 71 |
|
| | 72 | % Build default format structure
|
| | 73 | fmts = build_registry;
|
| | 74 | mlock
|
| | 75 |
|
| | 76 | end
|
| | 77 |
|
| | 78 | % Determine what to do based on number of input arguments
|
| 6 | 79 | switch(nargin)
|
| 6 | 80 | case 0
|
| | 81 | % 0 inputs: Informational only
|
| | 82 |
|
| | 83 | if (nargout == 0)
|
| | 84 |
|
| | 85 | % Pretty-print the registry
|
| | 86 | pretty_print_registry(fmts)
|
| | 87 |
|
| | 88 | else
|
| | 89 |
|
| | 90 | % Return the registry as a struct
|
| | 91 | varargout{1} = fmts;
|
| | 92 |
|
| | 93 | end
|
| | 94 |
|
| 6 | 95 | case 1
|
| | 96 | % 1 input: Look for specific format or modify registry
|
| | 97 |
|
| 6 | 98 | if (isstruct(varargin{1}))
|
| | 99 |
|
| | 100 | % Change the registry to contain the structure
|
| | 101 | fmts = update_registry(varargin{1});
|
| | 102 | varargout{1} = fmts;
|
| | 103 |
|
| 6 | 104 | elseif (isequal(lower(varargin{1}), 'factory'))
|
| | 105 |
|
| | 106 | % Reset the registry to the default values
|
| | 107 | fmts = build_registry;
|
| | 108 | varargout{1} = fmts;
|
| | 109 |
|
| 6 | 110 | elseif (ischar(varargin{1}))
|
| | 111 |
|
| | 112 | % Look for a particular format in the registry
|
| 6 | 113 | varargout{1} = find_in_registry(fmts, varargin{1});
|
| | 114 |
|
| | 115 | else
|
| | 116 |
|
| | 117 | % Error out, wrong input argument type
|
| | 118 | error(message('MATLAB:imagesci:imformats:badInputType'))
|
| | 119 |
|
| | 120 | end
|
| | 121 |
|
| | 122 | otherwise
|
| | 123 | % n inputs: Modify the registry using a command.
|
| | 124 |
|
| | 125 | command = validatestring(varargin{1},{'add','update','remove'});
|
| | 126 |
|
| | 127 | switch (lower(command))
|
| | 128 | case 'add'
|
| | 129 | fmts = add_entry(fmts, varargin{2:end});
|
| | 130 | case 'update'
|
| | 131 | fmts = update_entry(fmts, varargin{2:end});
|
| | 132 | case 'remove'
|
| | 133 | fmts = remove_entry(fmts, varargin{2:end});
|
| | 134 | end
|
| | 135 | varargout{1} = fmts;
|
| | 136 | end
|
| | 137 |
|
| | 138 | % Protect current file's persistent variables from CLEAR
|
| 6 | 139 | mlock;
|
Other subfunctions in this file are not included in this listing.