comparison scripts/image/imwrite.m @ 16944:1b3b3ee88284

Add optional extension argument to image IO functions. * imfinfo.m, private/core_imfinfo.m, imread.m, private/core_imread.m, imwrite.m: added support for optional EXT argument. * imwrite.m: in addition to support the extra EXT argument, removed list of supported image formats from help text, and suggested to use imformats() instead. * private/core_imwrite.m: remove usage of __magick_format_list__() which is being replaced by imformats(). Check validity of colormap earlier on. Removed tests that are repeated in imwrite.m (leftovers from copying the file). * private/imageIO.m: deal with separate filename and extension and ignore file existence checking if we are writing. * __magic_read__.cc: remove private function __magick_format_list__() that was only being used by core_imwrite.m and is being replaced by imformats().
author Carnë Draug <carandraug@octave.org>
date Wed, 10 Jul 2013 18:18:21 +0100
parents 59f575e504dc
children ee2166121a28
comparison
equal deleted inserted replaced
16943:0dab17e69a55 16944:1b3b3ee88284
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} imwrite (@var{img}, @var{filename}) 20 ## @deftypefn {Function File} {} imwrite (@var{img}, @var{filename})
21 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{filename}, @var{fmt}) 21 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{filename}, @var{ext})
22 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{filename}, @var{fmt}, @var{p1}, @var{v1}, @dots{}) 22 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{filename}, @var{ext}, @var{p1}, @var{v1}, @dots{})
23 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{map}, @var{filename}, @dots{}) 23 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{map}, @var{filename}, @dots{})
24 ## Write images in various file formats. 24 ## Write images in various file formats.
25 ## 25 ##
26 ## If @var{fmt} is not supplied, the file extension of @var{filename} is used 26 ## If @var{ext} is not supplied, the file extension of @var{filename} is used
27 ## to determine the format. 27 ## to determine the format. The actual supported formats are dependent on
28 ## options made during the build of Octave. Use @code{imformats} to check
29 ## the support of the different image formats.
28 ## 30 ##
29 ## The parameter-value pairs (@var{p1}, @var{v1}, @dots{}) are optional. 31 ## The parameter-value pairs (@var{p1}, @var{v1}, @dots{}) are optional.
30 ## Currently the following options are supported for @t{JPEG} images: 32 ## Currently the following options are supported for @t{JPEG} images:
31 ## 33 ##
32 ## @table @samp 34 ## @table @samp
34 ## Set the quality of the compression. The value should be an 36 ## Set the quality of the compression. The value should be an
35 ## integer between 0 and 100, with larger values indicating higher visual 37 ## integer between 0 and 100, with larger values indicating higher visual
36 ## quality and lower compression. 38 ## quality and lower compression.
37 ## @end table 39 ## @end table
38 ## 40 ##
39 ## @strong{Supported Formats} 41 ## @seealso{imread, imfinfo, imformats}
40 ## @multitable @columnfractions .33 .66
41 ## @headitem Extension @tab Format
42 ## @item bmp @tab Windows Bitmap
43 ## @item gif @tab Graphics Interchange Format
44 ## @item jpg and jpeg @tab Joint Photographic Experts Group
45 ## @item pbm @tab Portable Bitmap
46 ## @item pcx @tab
47 ## @item pgm @tab Portable Graymap
48 ## @item png @tab Portable Network Graphics
49 ## @item pnm @tab Portable Anymap
50 ## @item ppm @tab Portable Pixmap
51 ## @item ras @tab Sun Raster
52 ## @item tif and tiff @tab Tagged Image File Format
53 ## @item xwd @tab X11 Dump
54 ## @end multitable
55 ##
56 ## @strong{Unsupported Formats}
57 ## @multitable @columnfractions .33 .66
58 ## @headitem Extension @tab Format
59 ## @item hdf @tab Hierarchical Data Format V4
60 ## @item @nospell{jp2} and jpx @tab Joint Photographic Experts Group 2000
61 ## @end multitable
62 ##
63 ## @seealso{imread, imfinfo}
64 ## @end deftypefn 42 ## @end deftypefn
65 43
66 function imwrite (varargin) 44 function imwrite (varargin)
67 if (nargin < 2) 45 if (nargin < 2)
68 print_usage (); 46 print_usage ();
69 endif 47 endif
70 48
49 ## This input checking is a bit convoluted to support the multiple
50 ## ways the function can be called. Basically, after the image we
51 ## can have the filename or a colormap. If we have a colormap, then
52 ## the filename becomes the third argument. After that, we may have
53 ## the optional file extension.
71 if (ischar (varargin{2})) 54 if (ischar (varargin{2}))
72 filename = varargin{2}; 55 filename_idx = 2;
73 elseif (nargin >= 3 && iscolormap (varargin{2}) && ! ischar (varargin{3})) 56 elseif (nargin >= 3 && iscolormap (varargin{2}) && ! ischar (varargin{3}))
74 filename = varargin{3}' 57 filename_idx = 3;
75 else 58 else
76 error ("imwrite: no FILENAME specified"); 59 error ("imwrite: no FILENAME specified");
77 endif 60 endif
78 varargout{1:nargout} = imageIO (@core_imwrite, "write", filename, varargin{:}); 61 filename = {varargin{filename_idx}};
62 if (nargin > filename_idx + 1 && ischar (varargin {filename_idx + 1}))
63 filename{2} = varargin{filename_idx + 1};
64 endif
79 65
66 imageIO (@core_imwrite, "write", filename, varargin{:});
80 endfunction 67 endfunction
81 68
82 %% Test input validation 69 %% Test input validation
83 %!error imwrite () # Wrong # of args 70 %!error imwrite () # Wrong # of args
84 %!error imwrite (1) # Wrong # of args 71 %!error imwrite (1) # Wrong # of args