Mercurial > octave
annotate scripts/image/private/__imwrite__.m @ 19697:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | bfbe5dcc9943 |
children | 9fc020886ae9 |
rev | line source |
---|---|
19697
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}); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
63 elseif (ndims (options.alpha) > 4 || |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
64 any (size (options.alpha)([1 2]) != size (img)([1 2])) || |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
65 size (options.alpha, 4) != size (img, 4)) |
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 |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
83 if (any (options.delaytime(:) < 0) || any (options.delaytime(:) > 65535)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
84 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
|
85 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
86 endif |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
87 |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
88 case "disposalmethod" |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
89 options.disposalmethod = param_list{idx+1}; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
90 if (! ischar (options.disposalmethod) && |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
91 ! iscellstr (options.disposalmethod)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
92 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
|
93 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
94 elseif (! iscell (options.disposalmethod)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
95 options.disposalmethod = {options.disposalmethod}; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
96 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
97 options.disposalmethod = tolower (options.disposalmethod); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
98 matches = ismember (options.disposalmethod, |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
99 {"donotspecify", "leaveinplace", "restorebg", "restoreprevious"}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
100 if (any (! matches)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
101 error ("imwrite: unknow method %s for option %s", |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
102 options.disposalmethod{find (! matches, 1)}, |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
103 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
104 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
105 if (isscalar (options.disposalmethod)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
106 options.disposalmethod = repmat (options.disposalmethod, 1, size (img, 4)); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
107 elseif (numel (options.disposalmethod) != size (img, 4)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
108 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
|
109 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
110 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
111 |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
112 case "loopcount" |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
113 options.loopcount = param_list{idx+1}; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
114 if (! isscalar (options.loopcount) || ! isnumeric (options.loopcount) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
115 || (! isinf (options.loopcount) && (options.loopcount < 0 || |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
116 options.loopcount > 65535))) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
117 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
|
118 param_list{idx}); |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
119 endif |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
120 ## 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
|
121 ## 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
|
122 ## 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
|
123 ## 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
|
124 ## to make it loop only once. See |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
125 ## https://sourceforge.net/p/graphicsmagick/bugs/249/ |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
126 ## 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
|
127 ## a single frame. See |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
128 ## https://sourceforge.net/p/graphicsmagick/bugs/248/ |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
129 if (isinf (options.loopcount)) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
130 options.loopcount = 0; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
131 elseif (options.loopcount == 0 || options.loopcount == 1) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
132 options.loopcount++; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
133 endif |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
134 options.loopcount = floor (options.loopcount); |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
135 |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
136 case "quality", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
137 options.quality = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
138 if (! isnumeric (options.quality) || ! isscalar (options.quality) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
139 || options.quality < 0 || options.quality > 100) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
140 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
|
141 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
142 endif |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
143 options.quality = round (options.quality); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
144 |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
145 case "writemode", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
146 options.writemode = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
147 if (! ischar (options.writemode) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
148 || ! any (strcmpi (options.writemode, {"append", "overwrite"}))) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
149 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
|
150 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
151 endif |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
152 options.writemode = tolower (options.writemode); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
153 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
154 otherwise |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
155 error ("imwrite: invalid PARAMETER `%s'", param_list{idx}); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
156 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
157 endswitch |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
158 endfor |
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 if (! isempty (map)) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
161 if (! iscolormap (map)) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
162 error ("imwrite: invalid MAP for indexed image"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
163 elseif (ndims (img) != 2 && ndims (img) != 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
164 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
|
165 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
|
166 |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
167 ## 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
179 ## 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
|
180 ## 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
|
181 ## 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
|
182 if (isfloat (img)) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
183 if (rows (map) <= 256) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
184 img = uint8 (img - 1); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
185 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
186 img = uint16 (img - 1); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
187 endif |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
188 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
189 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
190 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
191 if (ndims (img) > 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
192 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
|
193 elseif (all (size (img, 3) != [1 3 4])) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
194 ## 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
|
195 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
|
196 endif |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
197 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
198 __magick_write__ (filename, ext, img, map, options); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
199 |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
200 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17332
diff
changeset
|
201 |