annotate scripts/image/imwrite.m @ 15714:b1cd65881592

Clean up scripts in image directory. Use Octave coding conventions. Redo docstrings. Add %!tests. * brighten.m: Put input validation first. Use iscolormap to simplify input checking. * cmunique.m: Use faster method of validating input class. * colormap.m: Tweak docstring. Improve input validation. * contrast.m: Tweak docstring. Use cmap instead of map as variable name for clarity. * gray2ind.m: Wrap long lines. Use faster method of validating input class. Delete unreachable code for n>65536. * hsv2rgb.m: Use faster method of validating input class. * imwrite.m: Tweak FIXME notes. * ind2gray.m: Use correct caller name for ind2x. Update %!tests with new 2-input calling convention. * ind2rgb.m: Tweak docstring. Update %!tests with new 2-input calling convention. * iscolormap.m: Tweak docstring. Re-order validation tests. * ntsc2rgb.m: Use faster method of validating input class. Better input validation. Add %!tests. * private/ind2x.m: Use more descriptive variable names. * rgb2hsv.m: Tweak docstring. Use faster method of validating input class. * rgb2ind.m: Tweak docstring. Wrap long lines. * rgb2ntsc.m: Use faster method of validating input class. Improve input validation. Add %!tests. * rgbplot.m: Match variable names in docstring to those in function prototype.
author Rik <rik@octave.org>
date Sun, 02 Dec 2012 10:02:57 -0800
parents 4beb3a4bd440
children 59f575e504dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11591
diff changeset
1 ## Copyright (C) 2008-2012 John W. Eaton
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
20 ## @deftypefn {Function File} {} imwrite (@var{img}, @var{filename})
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
21 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{filename}, @var{fmt})
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
22 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{filename}, @var{fmt}, @var{p1}, @var{v1}, @dots{})
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
23 ## @deftypefnx {Function File} {} imwrite (@var{img}, @var{map}, @var{filename}, @dots{})
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ## Write images in various file formats.
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 ##
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
26 ## If @var{fmt} is not supplied, the file extension of @var{filename} is used
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
27 ## to determine the format.
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
29 ## The parameter-value pairs (@var{p1}, @var{v1}, @dots{}) are optional.
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
30 ## Currently the following options are supported for @t{JPEG} images:
8148
213dd524f96b Improve documentation for image I/O.
sh@sh-laptop
parents: 8054
diff changeset
31 ##
213dd524f96b Improve documentation for image I/O.
sh@sh-laptop
parents: 8054
diff changeset
32 ## @table @samp
213dd524f96b Improve documentation for image I/O.
sh@sh-laptop
parents: 8054
diff changeset
33 ## @item Quality
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
34 ## Set the quality of the compression. The value should be an
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
35 ## integer between 0 and 100, with larger values indicating higher visual
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
36 ## quality and lower compression.
8148
213dd524f96b Improve documentation for image I/O.
sh@sh-laptop
parents: 8054
diff changeset
37 ## @end table
213dd524f96b Improve documentation for image I/O.
sh@sh-laptop
parents: 8054
diff changeset
38 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
39 ## @strong{Supported Formats}
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
40 ## @multitable @columnfractions .33 .66
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
41 ## @headitem Extension @tab Format
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
42 ## @item bmp @tab Windows Bitmap
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
43 ## @item gif @tab Graphics Interchange Format
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
44 ## @item jpg and jpeg @tab Joint Photographic Experts Group
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
45 ## @item pbm @tab Portable Bitmap
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
46 ## @item pcx @tab
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
47 ## @item pgm @tab Portable Graymap
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
48 ## @item png @tab Portable Network Graphics
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
49 ## @item pnm @tab Portable Anymap
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
50 ## @item ppm @tab Portable Pixmap
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
51 ## @item ras @tab Sun Raster
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
52 ## @item tif and tiff @tab Tagged Image File Format
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
53 ## @item xwd @tab X11 Dump
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
54 ## @end multitable
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
55 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
56 ## @strong{Unsupported Formats}
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
57 ## @multitable @columnfractions .33 .66
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
58 ## @headitem Extension @tab Format
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
59 ## @item hdf @tab Hierarchical Data Format V4
11591
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
60 ## @item @nospell{jp2} and jpx @tab Joint Photographic Experts Group 2000
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
61 ## @end multitable
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10891
diff changeset
62 ##
8148
213dd524f96b Improve documentation for image I/O.
sh@sh-laptop
parents: 8054
diff changeset
63 ## @seealso{imread, imfinfo}
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 ## @end deftypefn
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
66 function imwrite (img, varargin)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
67
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 10985
diff changeset
68 persistent imwrite_possible_formats = {
11038
35416c9baf76 missing semicolon in last imwrite changeset
John W. Eaton <jwe@octave.org>
parents: 11035
diff changeset
69 "bmp"; "gif"; "jp2"; "jpg"; "jpx"; "jpeg"; "hdf"; "pbm"; "pcx";
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 10985
diff changeset
70 "pgm"; "png"; "pnm"; "ppm"; "ras"; "tif"; "tiff"; "xwd" };
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 10985
diff changeset
72 persistent accepted_formats = __magick_format_list__ (imwrite_possible_formats);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
73
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
74 if (nargin < 2 || ! (isnumeric (img) || islogical (img)))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
75 print_usage ();
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
76 endif
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
77
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 map = [];
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 fmt = "";
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
81 offset = 1;
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
82 if (isnumeric (varargin{1}))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
83 map = varargin{1};
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
84 if (isempty (map))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
85 error ("imwrite: colormap must not be empty");
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
86 endif
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 offset = 2;
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
88 endif
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
89 if (offset <= length (varargin) && ischar (varargin{offset}))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
90 filename = varargin{offset};
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
91 offset++;
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
92 if (rem (length (varargin) - offset, 2) == 0 && ischar (varargin{offset}))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
93 fmt = varargin{offset};
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 offset++;
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 else
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 print_usage ();
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 endif
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
99 if (offset < length (varargin))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
100 has_param_list = 1;
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
101 for ii = offset:2:(length (varargin) - 1)
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
102 options.(varargin{ii}) = varargin{ii + 1};
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
103 endfor
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
104 else
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
105 has_param_list = 0;
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
106 endif
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 filename = tilde_expand (filename);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 if (isempty (fmt))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 [d, n, fmt] = fileparts (filename);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 if (! isempty (fmt))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 fmt = fmt(2:end);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
117 if (isempty (img))
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
118 error ("imwrite: invalid empty image");
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
119 endif
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
120
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 if (issparse (img) || issparse (map))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 error ("imwrite: sparse images not supported");
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 if (! strcmp (fmt, accepted_formats))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 error ("imwrite: %s: unsupported or invalid image format", fmt);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 img_class = class (img);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 map_class = class (map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
131 nd = ndims (img);
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 if (isempty (map))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 if (any (strcmp (img_class, {"logical", "uint8", "uint16", "double"})))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 if ((nd == 2 || nd == 3) && strcmp (img_class, "double"))
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
136 img = uint8 (img * 255);
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 endif
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15515
diff changeset
138 ## FIXME: should we handle color images with alpha channel here?
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
139 if (nd == 3 && size (img, 3) < 3)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
140 error ("imwrite: invalid dimensions for truecolor image");
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 if (nd > 5)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
143 error ("imwrite: invalid %d-dimensional image data", nd);
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 else
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 error ("imwrite: %s: invalid class for truecolor image", img_class);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 endif
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
148 if (has_param_list)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
149 __magick_write__ (filename, fmt, img, options);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
150 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
151 __magick_write__ (filename, fmt, img);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
152 endif
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 else
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 if (any (strcmp (img_class, {"uint8", "uint16", "double"})))
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 if (strcmp (img_class, "double"))
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
156 img = uint8 (img - 1);
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 endif
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
158 if (nd != 2 && nd != 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
159 error ("imwrite: invalid size for indexed image");
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 else
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 error ("imwrite: %s: invalid class for indexed image data", img_class);
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 endif
15515
4beb3a4bd440 rgbplot.m, cmpermute.m, cmunique.m, ind2rgb.m, imwrite.m: use core iscolormap function
Carnë Draug <carandraug+dev@gmail.com>
parents: 14872
diff changeset
164 if (! iscolormap (map))
4beb3a4bd440 rgbplot.m, cmpermute.m, cmunique.m, ind2rgb.m, imwrite.m: use core iscolormap function
Carnë Draug <carandraug+dev@gmail.com>
parents: 14872
diff changeset
165 error ("imwrite: invalid indexed image colormap");
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 endif
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
167
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15515
diff changeset
168 ## FIXME: we should really be writing indexed images here but
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15515
diff changeset
169 ## __magick_write__ needs to be fixed to handle them.
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
170
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
171 [r, g, b] = ind2rgb (img, map);
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
172 tmp = uint8 (cat (3, r, g, b) * 255);
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
173
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
174 if (has_param_list)
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
175 __magick_write__ (filename, fmt, tmp, options);
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
176 ## __magick_write__ (filename, fmt, img, map, options);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
177 else
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
178 __magick_write__ (filename, fmt, tmp);
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
179 ## __magick_write__ (filename, fmt, img, map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 7987
diff changeset
180 endif
7987
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 endif
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182
4a423a042971 add imwrite.m
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 endfunction
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
184
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
185
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
186 %% Test input validation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
187 %!error imwrite () # Wrong # of args
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
188 %!error imwrite (1) # Wrong # of args
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
189 %!error imwrite ({"cell"}, "filename.jpg") # Wrong class for img
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
190 %!error imwrite (1, [], "filename.jpg") # Empty image map
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
191 %!error imwrite (1, 2, 3) # No filename specified
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
192 %!error imwrite (1, "filename") # No fmt specified
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
193 %!error imwrite (1, "filename", "junk") # Invalid fmt specified
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
194 %!error imwrite ([], "filename.jpg") # Empty img matrix
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
195 %!error imwrite (spones (2), "filename.jpg") # Invalid sparse img
10891
ff94219746bd imwrite.m: Allow writing of 1-bit (B&W) images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
196