Mercurial > octave-nkf
annotate scripts/image/private/__imwrite__.m @ 19899:e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
* accumarray.m, validateattributes.m, iscolormap.m, __imread__.m,
__imwrite__.m, imwrite_filename.m, strread.m, getappdata.m,
appearance/annotation.m, shrinkfaces.m, rundemos.m, runtests.m,
datenum.m, datestr.m: Break long lines before && and ||.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 26 Feb 2015 13:13:40 -0500 |
parents | 9fc020886ae9 |
children | 5b8e4f668c53 |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17855
diff
changeset
|
1 ## Copyright (C) 2008-2015 John W. Eaton |
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17855
diff
changeset
|
2 ## Copyright (C) 2013-2015 Carnë Draug |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
3 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
4 ## This file is part of Octave. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
5 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
6 ## Octave is free software; you can redistribute it and/or modify it |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
9 ## your option) any later version. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
10 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
11 ## Octave is distributed in the hope that it will be useful, but |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
14 ## General Public License for more details. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
15 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public License |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
17 ## along with Octave; see the file COPYING. If not, see |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
19 |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
20 ## This function does all the work of imwrite. It exists here as private |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
21 ## function so that imwrite can use other functions if imformats is |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
22 ## configured to. It is also needed so that imformats can create a |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
23 ## function handle for it. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
24 |
17086
3db796f89695
Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents:
16988
diff
changeset
|
25 function __imwrite__ (img, varargin) |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
26 |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
27 if (nargin < 2 || ! (isnumeric (img) || islogical (img))) |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
28 print_usage ("imwrite"); |
17266
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
29 endif |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
30 |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
31 [filename, ext, map, param_list] = imwrite_filename (varargin{:}); |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
32 |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
33 if (isempty (img)) |
17234
0b8f78cdc5cd
imwrite: give error if image is an empty or sparse matrix.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
34 error ("imwrite: invalid empty image"); |
0b8f78cdc5cd
imwrite: give error if image is an empty or sparse matrix.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
35 elseif (issparse (img) || issparse (map)) |
0b8f78cdc5cd
imwrite: give error if image is an empty or sparse matrix.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
36 error ("imwrite: sparse images are not supported"); |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
37 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
38 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
39 if (rem (numel (param_list), 2) != 0) |
17176
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
17086
diff
changeset
|
40 error ("imwrite: no pair for all arguments (odd number left)"); |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
41 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
42 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
43 ## set default for options |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
44 options = struct ("writemode", "overwrite", |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
45 "disposalmethod", {repmat({"doNotSpecify"}, 1, size (img, 4))}, |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
46 "quality", 75, |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
47 "delaytime", ones (1, size (img, 4)) *500, # 0.5 seconds |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
48 "loopcount", 0, ## this is actually Inf |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
49 "alpha", cast ([], class (img))); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
50 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
51 for idx = 1:2:numel (param_list) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
52 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
53 switch (tolower (param_list{idx})) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
54 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
55 case "alpha" |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
56 options.alpha = param_list{idx+1}; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
57 if (! isnumeric (options.alpha)) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
58 error ("imwrite: value for %s option must be a numeric matrix", |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
59 param_list{idx}); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
60 elseif (size (options.alpha, 3) != 1) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
61 error ("imwrite: 3rd dimension of matrix for %s must be singleton", |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
62 param_list{idx}); |
19899
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
63 elseif (ndims (options.alpha) > 4 |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
64 || any (size (options.alpha)([1 2]) != size (img)([1 2])) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
65 || size (options.alpha, 4) != size (img, 4)) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
66 error ("imwrite: matrix for %s must have same dimension as image", |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
67 param_list{idx}); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
68 endif |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
69 |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
70 case "delaytime" |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
71 options.delaytime = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
72 if (! isnumeric (options.delaytime)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
73 error ("imwrite: value for %s option must be numeric", |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
74 param_list{idx}); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
75 endif |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
76 options.delaytime *= 100; # convert to 1/100ths of second |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
77 if (isscalar (options.delaytime)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
78 options.delaytime(1:size (img, 4)) = options.delaytime; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
79 elseif (size (img, 4) != numel (options.delaytime)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
80 error ("imwrite: value for %s must either be a scalar or the number of frames", |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
81 param_list{idx}); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
82 endif |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
83 if (any (options.delaytime(:) < 0) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
84 || any (options.delaytime(:) > 65535)) |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
85 error ("imwrite: value for %s must be between 0 and 655.35 seconds", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
86 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
87 endif |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
88 |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
89 case "disposalmethod" |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
90 options.disposalmethod = param_list{idx+1}; |
19899
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
91 if (! ischar (options.disposalmethod) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
92 && ! iscellstr (options.disposalmethod)) |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
93 error ("imwrite: value for %s must be a string or cell array of strings", |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
94 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
95 elseif (! iscell (options.disposalmethod)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
96 options.disposalmethod = {options.disposalmethod}; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
97 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
98 options.disposalmethod = tolower (options.disposalmethod); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
99 matches = ismember (options.disposalmethod, |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
100 {"donotspecify", "leaveinplace", ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
101 "restorebg", "restoreprevious"}); |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
102 if (any (! matches)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
103 error ("imwrite: unknow method %s for option %s", |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
104 options.disposalmethod{find (! matches, 1)}, |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
105 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
106 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
107 if (isscalar (options.disposalmethod)) |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
108 options.disposalmethod = repmat (options.disposalmethod, ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
109 1, size (img, 4)); |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
110 elseif (numel (options.disposalmethod) != size (img, 4)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
111 error ("imwrite: if value %s is a cell array must have same length as number of frames", |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
112 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
113 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
114 |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
115 case "loopcount" |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
116 options.loopcount = param_list{idx+1}; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
117 if (! isscalar (options.loopcount) || ! isnumeric (options.loopcount) |
19899
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
118 || (! isinf (options.loopcount) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19867
diff
changeset
|
119 && (options.loopcount < 0 || options.loopcount > 65535))) |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
120 error ("imwrite: value for %s must be Inf or between 0 and 65535", |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
121 param_list{idx}); |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
122 endif |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
123 ## Graphics Magick is a bit weird here. A value of 0 will be an |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
124 ## infinite loop, a value of 1, will really be no loop, while a |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
125 ## value of 2 or more will be that number of loops (checked |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
126 ## with GNOME image viewer). This means that there is no way |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
127 ## to make it loop only once. See |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
128 ## https://sourceforge.net/p/graphicsmagick/bugs/249/ |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
129 ## There is also the problem of setting this when there is only |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
130 ## a single frame. See |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
131 ## https://sourceforge.net/p/graphicsmagick/bugs/248/ |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
132 if (isinf (options.loopcount)) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
133 options.loopcount = 0; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
134 elseif (options.loopcount == 0 || options.loopcount == 1) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
135 options.loopcount++; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
136 endif |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
137 options.loopcount = floor (options.loopcount); |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
138 |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
139 case "quality", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
140 options.quality = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
141 if (! isnumeric (options.quality) || ! isscalar (options.quality) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
142 || options.quality < 0 || options.quality > 100) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
143 error ("imwrite: value for %s option must be a scalar between 0 and 100", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
144 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
145 endif |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
146 options.quality = round (options.quality); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
147 |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
148 case "writemode", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
149 options.writemode = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
150 if (! ischar (options.writemode) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
151 || ! any (strcmpi (options.writemode, {"append", "overwrite"}))) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
152 error ('imwrite: value for %s option must be "append" or "overwrite"', |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
153 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
154 endif |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
155 options.writemode = tolower (options.writemode); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
156 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
157 otherwise |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
158 error ("imwrite: invalid PARAMETER `%s'", param_list{idx}); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
159 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
160 endswitch |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
161 endfor |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
162 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
163 if (! isempty (map)) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
164 if (! iscolormap (map)) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
165 error ("imwrite: invalid MAP for indexed image"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
166 elseif (ndims (img) != 2 && ndims (img) != 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
167 error ("imwrite: indexed image must have 2 or 4 dimensions (found %i)", ndims (img)); |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
168 endif |
17850
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
169 |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
170 ## Fill in the colormap as required with rgb (0, 0, 0) (bug #33615) |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
171 nColors = rows (map); |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
172 if (any (strcmp (class (img), {"uint8", "uint16", "logical"}))) |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
173 required_colors = max (img(:)) +1; |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
174 else |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
175 required_colors = max (img(:)); |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
176 endif |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
177 if (nColors < required_colors) |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
178 warning ("imwrite: MAP has not enough colors. Filling with black"); |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
179 map(nColors+1:required_colors,:) = 0; |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
180 endif |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
181 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
182 ## If the image is floating point, then we convert it to integer (makes |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
183 ## it easier in __magick_write__ since it only handles integers. Also, |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
184 ## if it's floating point, it has an offset of 1 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
185 if (isfloat (img)) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
186 if (rows (map) <= 256) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
187 img = uint8 (img - 1); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
188 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
189 img = uint16 (img - 1); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
190 endif |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
191 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
192 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
193 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
194 if (ndims (img) > 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
195 error ("imwrite: invalid %d-dimensional image data", ndims (img)); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
196 elseif (all (size (img, 3) != [1 3 4])) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
197 ## 1, 3, or 4 for grayscle, RGB, and CMYK respectively |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
198 error ("imwrite: IMG 3rd dimension must be 1, 3, or 4"); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
199 endif |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
200 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
201 __magick_write__ (filename, ext, img, map, options); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
202 |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
203 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17332
diff
changeset
|
204 |