Mercurial > octave
annotate scripts/image/private/__imwrite__.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2008-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
5 ## |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
6 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
7 ## This file is part of Octave. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
8 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
13 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
14 ## 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
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
18 ## |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
19 ## 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
|
20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
22 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
23 ## This function does all the work of imwrite. It exists here as private |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
24 ## function so that imwrite can use other functions if imformats is |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
25 ## configured to. It is also needed so that imformats can create a |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
26 ## function handle for it. |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
27 |
17086
3db796f89695
Rename private core_imfnc functions to follow the __fnc__ convention style.
Carnë Draug <carandraug@octave.org>
parents:
16988
diff
changeset
|
28 function __imwrite__ (img, varargin) |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
29 |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
30 if (nargin < 2 || ! (isnumeric (img) || islogical (img))) |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
31 print_usage ("imwrite"); |
17266
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
32 endif |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
33 |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
34 [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
|
35 |
b1a09f72a520
imwrite: fix input checking for colormap (bug #39791)
Carnë Draug <carandraug@octave.org>
parents:
17234
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 error ("imwrite: sparse images are not supported"); |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
40 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
41 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
42 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
|
43 error ("imwrite: no pair for all arguments (odd number left)"); |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
44 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
45 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
46 ## set default for options |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
47 options = struct ("writemode", "overwrite", |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
48 "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
|
49 "quality", 75, |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
50 "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
|
51 "loopcount", 0, ## this is actually Inf |
20406
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
52 "alpha", cast ([], class (img)), |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
53 "compression", "none"); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
54 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
55 for idx = 1:2:numel (param_list) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
56 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
57 switch (tolower (param_list{idx})) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
58 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 param_list{idx}); |
19865
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
67 elseif (ndims (options.alpha) > 4 |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
68 || 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:
19833
diff
changeset
|
69 || 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
|
70 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
|
71 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
|
72 endif |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17266
diff
changeset
|
73 |
20406
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
74 case "compression" |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
75 options.compression = param_list{idx+1}; |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
76 if (! ischar (options.compression)) |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
77 error ("imwrite: value for %s option must be a string", |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
78 param_list{idx}); |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
79 endif |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
80 options.compression = tolower (options.compression); |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
81 if (! any (strcmp (options.compression, {"none", "bzip", "fax3", ... |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
82 "fax4", "jpeg", "lzw", ... |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
83 "rle", "deflate"}))) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
84 error ("imwrite: invalid compression '%s'", options.compression); |
20406
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
85 endif |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
19865
diff
changeset
|
86 |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
87 case "delaytime" |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
88 options.delaytime = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
89 if (! isnumeric (options.delaytime)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
90 error ("imwrite: value for %s option must be numeric", |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
91 param_list{idx}); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
92 endif |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
93 options.delaytime *= 100; # convert to 1/100ths of second |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
94 if (isscalar (options.delaytime)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
95 options.delaytime(1:size (img, 4)) = options.delaytime; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
96 elseif (size (img, 4) != numel (options.delaytime)) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
97 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
|
98 param_list{idx}); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
99 endif |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
100 if (any (options.delaytime(:) < 0) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
101 || any (options.delaytime(:) > 65535)) |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
102 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
|
103 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
104 endif |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
105 |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
106 case "disposalmethod" |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
107 options.disposalmethod = param_list{idx+1}; |
19865
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
108 if (! ischar (options.disposalmethod) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
109 && ! iscellstr (options.disposalmethod)) |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
110 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
|
111 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
112 elseif (! iscell (options.disposalmethod)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
113 options.disposalmethod = {options.disposalmethod}; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
114 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
115 options.disposalmethod = tolower (options.disposalmethod); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
116 matches = ismember (options.disposalmethod, |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
117 {"donotspecify", "leaveinplace", ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
118 "restorebg", "restoreprevious"}); |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
119 if (any (! matches)) |
21142
a3362dd2dd52
doc: fix spelling of "unknown".
Rafael Laboissiere <rafael@laboissiere.net>
parents:
19865
diff
changeset
|
120 error ("imwrite: unknown method %s for option %s", |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
121 options.disposalmethod{find (! matches, 1)}, |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
122 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
123 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
124 if (isscalar (options.disposalmethod)) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
125 options.disposalmethod = repmat (options.disposalmethod, ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
126 1, size (img, 4)); |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
127 elseif (numel (options.disposalmethod) != size (img, 4)) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
128 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
|
129 param_list{idx}); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
130 endif |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
131 |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
132 case "loopcount" |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
133 options.loopcount = param_list{idx+1}; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
134 if (! isscalar (options.loopcount) || ! isnumeric (options.loopcount) |
19865
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
135 || (! isinf (options.loopcount) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
136 && (options.loopcount < 0 || options.loopcount > 65535))) |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
137 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
|
138 param_list{idx}); |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
139 endif |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
140 ## Graphics Magick is a bit weird here. A value of 0 will be an |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
141 ## 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
|
142 ## value of 2 or more will be that number of loops (checked |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
143 ## with GNOME image viewer). This means that there is no way |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
144 ## to make it loop only once. See |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
145 ## https://sourceforge.net/p/graphicsmagick/bugs/249/ |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
146 ## There is also the problem of setting this when there is only |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
147 ## a single frame. See |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
148 ## https://sourceforge.net/p/graphicsmagick/bugs/248/ |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
149 if (isinf (options.loopcount)) |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
150 options.loopcount = 0; |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
151 elseif (options.loopcount == 0 || options.loopcount == 1) |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20406
diff
changeset
|
152 options.loopcount += 1; |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
153 endif |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
154 options.loopcount = floor (options.loopcount); |
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17850
diff
changeset
|
155 |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
156 case "quality", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
157 options.quality = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
158 if (! isnumeric (options.quality) || ! isscalar (options.quality) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
159 || options.quality < 0 || options.quality > 100) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
160 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
|
161 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
162 endif |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
163 options.quality = round (options.quality); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
164 |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
165 case "writemode", |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
166 options.writemode = param_list{idx+1}; |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
167 if (! ischar (options.writemode) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
168 || ! any (strcmpi (options.writemode, {"append", "overwrite"}))) |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
169 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
|
170 param_list{idx}); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
171 endif |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
172 options.writemode = tolower (options.writemode); |
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
173 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
174 otherwise |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
175 error ("imwrite: invalid PARAMETER '%s'", param_list{idx}); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
176 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
177 endswitch |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
178 endfor |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
179 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
180 if (! isempty (map)) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
181 if (! iscolormap (map)) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
182 error ("imwrite: invalid MAP for indexed image"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
183 elseif (ndims (img) != 2 && ndims (img) != 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
184 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
|
185 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
|
186 |
45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
Carnë Draug <carandraug@octave.org>
parents:
17744
diff
changeset
|
187 ## 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 if (nColors < required_colors) |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
195 warning ("imwrite: MAP has not enough colors. Filling with black"); |
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
|
196 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
|
197 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
|
198 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
199 ## If the image is floating point, then we convert it to integer (makes |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21144
diff
changeset
|
200 ## it easier in __magick_write__ since it only handles integers. Also, |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
201 ## 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
|
202 if (isfloat (img)) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
203 if (rows (map) <= 256) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
204 img = uint8 (img - 1); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
205 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
206 img = uint16 (img - 1); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
207 endif |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
208 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
209 endif |
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
210 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
211 if (ndims (img) > 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
212 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
|
213 elseif (all (size (img, 3) != [1 3 4])) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17176
diff
changeset
|
214 ## 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
|
215 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
|
216 endif |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
217 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
218 __magick_write__ (filename, ext, img, map, options); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16965
diff
changeset
|
219 |
16916
59f575e504dc
Connect imwrite with imformats.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
220 endfunction |