annotate libinterp/dldfcn/__magick_read__.cc @ 16925:5c25f7ed080c

*__magick_read__.cc: add missing include of gripes.h
author Torsten <ttl@justmail.de>
date Mon, 08 Jul 2013 21:10:34 +0200
parents 861516dcad19
children 1b3b3ee88284
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
1 /*
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
3 Copyright (C) 2002-2012 Andy Adler
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
4 Copyright (C) 2008 Thomas L. Scofield
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
5 Copyright (C) 2010 David Grundberg
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
6
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
7 This file is part of Octave.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
8
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
12 option) any later version.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
13
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
17 for more details.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
18
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
20 along with Octave; see the file COPYING. If not, see
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
21 <http://www.gnu.org/licenses/>.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
22
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
23 */
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
24
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
25 #ifdef HAVE_CONFIG_H
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
26 #include <config.h>
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
27 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
28
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
29 #include <cmath>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
30
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
31 #include "file-stat.h"
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
32 #include "oct-env.h"
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
33 #include "oct-time.h"
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
34
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
35 #include "defun-dld.h"
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
36 #include "error.h"
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
37 #include "ov-struct.h"
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
38
16925
5c25f7ed080c *__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents: 16901
diff changeset
39 #include "gripes.h"
5c25f7ed080c *__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents: 16901
diff changeset
40
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
41 #ifdef HAVE_MAGICK
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
42
9575
55ecaefb7d0f Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents: 9439
diff changeset
43 #include <Magick++.h>
10739
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
44 #include <clocale>
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
45
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
46 octave_value_list
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
47 read_indexed_images (std::vector<Magick::Image>& imvec,
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
48 const Array<int>& frameidx, bool wantalpha)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
49 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
50 octave_value_list output;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
51
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
52 int rows = imvec[0].baseRows ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
53 int columns = imvec[0].baseColumns ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
54 int nframes = frameidx.length ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
55
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
56 dim_vector idim = dim_vector ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
57 idim.resize (4);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
58 idim(0) = rows;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
59 idim(1) = columns;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
60 idim(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
61 idim(3) = nframes;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
62
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
63 Array<int> idx (dim_vector (4, 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
64
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
65 Magick::ImageType type = imvec[0].type ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
66
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
67 unsigned int mapsize = imvec[0].colorMapSize ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
68 unsigned int i = mapsize;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
69 unsigned int depth = 0;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
70 while (i >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
71 depth++;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
72 i = 0;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
73 depth--;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
74 while (depth >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
75 i++;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
76 depth = 1 << i;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
77
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
78 switch (depth)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
79 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
80 case 1:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
81 case 2:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
82 case 4:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
83 case 8:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
84 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
85 uint8NDArray im = uint8NDArray (idim);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
86
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
87 idx(2) = 0;
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
88 for (int frame = 0; frame < nframes; frame++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
89 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
90 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
91
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
92 const Magick::IndexPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
93 = imvec[frameidx(frame)].getConstIndexes ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
94
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
95 i = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
96 idx(3) = frame;
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
97
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
98 for (int y = 0; y < rows; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
99 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
100 idx(0) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
101 for (int x = 0; x < columns; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
102 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
103 idx(1) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
104 im(idx) = static_cast<octave_uint8> (pix[i++]);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
105 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
106 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
107 }
10100
dd4d4b14b340 __magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
108
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
109 output(0) = octave_value (im);
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
110 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
111 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
112
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
113 case 16:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
114 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
115 uint16NDArray im = uint16NDArray (idim);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
116
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
117 idx(2) = 0;
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
118 for (int frame = 0; frame < nframes; frame++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
119 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
120 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
121
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
122 const Magick::IndexPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
123 = imvec[frameidx(frame)].getConstIndexes ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
124
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
125 i = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
126 idx(3) = frame;
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
127
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
128 for (int y = 0; y < rows; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
129 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
130 idx(0) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
131 for (int x = 0; x < columns; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
132 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
133 idx(1) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
134 im(idx) = static_cast<octave_uint16> (pix[i++]);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
135 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
136 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
137 }
10100
dd4d4b14b340 __magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
138
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
139 output(0) = octave_value (im);
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
140 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
141 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
142
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
143 default:
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
144 error ("__magic_read__: index depths greater than 16-bit are not supported");
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
145 return octave_value_list ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
146 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
147
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
148 Matrix map = Matrix (mapsize, 3);
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
149 Matrix alpha;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
150
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
151 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
152 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
153 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
154 #if 0
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
155 warning ("palettematte");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
156 Matrix map (mapsize, 3);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
157 Matrix alpha (mapsize, 1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
158 for (i = 0; i < mapsize; i++)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
159 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
160 warning ("%d", i);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
161 Magick::ColorRGB c = imvec[0].colorMap (i);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
162 map(i,0) = c.red ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
163 map(i,1) = c.green ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
164 map(i,2) = c.blue ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
165 alpha(i,1) = c.alpha ();
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
166 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
167 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
168 #endif
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
169
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
170 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
171 alpha = Matrix (0, 0);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
172 for (i = 0; i < mapsize; i++)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
173 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
174 Magick::ColorRGB c = imvec[0].colorMap (i);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
175 map(i,0) = c.red ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
176 map(i,1) = c.green ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
177 map(i,2) = c.blue ();
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
178 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
179 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
180
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
181 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
182 error ("__magick_read__: unsupported indexed image type");
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
183 return octave_value_list ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
184 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
185
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
186 if (wantalpha)
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
187 output(2) = alpha;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
188
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
189 output(1) = map;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
190
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
191 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
192 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
193
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
194 template <class T>
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
195 octave_value_list
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
196 read_images (const std::vector<Magick::Image>& imvec,
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
197 const Array<int>& frameidx, unsigned int depth)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
198 {
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
199 typedef typename T::element_type P;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
200
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
201 octave_value_list retval (3, Matrix ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
202
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
203 T im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
204
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
205 int rows = imvec[0].baseRows ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
206 int columns = imvec[0].baseColumns ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
207 int nframes = frameidx.length ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
208
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
209 dim_vector idim = dim_vector ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
210 idim.resize (4);
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
211 idim(0) = rows;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
212 idim(1) = columns;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
213 idim(2) = 1;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
214 idim(3) = nframes;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
215
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
216 Magick::ImageType type = imvec[0].type ();
14173
47a5e29ecc0b Allow QuantumDepth=32 installations of Magick++ (Bug #35229)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
217 const int divisor = ((uint64_t (1) << QuantumDepth) - 1) /
47a5e29ecc0b Allow QuantumDepth=32 installations of Magick++ (Bug #35229)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
218 ((uint64_t (1) << depth) - 1);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
219
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
220 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
221 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
222 case Magick::BilevelType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
223 case Magick::GrayscaleType:
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
224 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
225 im = T (idim);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
226 P *vec = im.fortran_vec ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
227
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
228 for (int frame = 0; frame < nframes; frame++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
229 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
230 const Magick::PixelPacket *pix
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
231 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
232
10298
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
233 P *rbuf = vec;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
234 for (int y = 0; y < rows; y++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
235 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
236 for (int x = 0; x < columns; x++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
237 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
238 *rbuf = pix->red / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
239 pix++;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
240 rbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
241 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
242 rbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
243 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
244
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
245 // Next frame.
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
246 vec += rows * columns * idim(2);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
247 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
248 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
249 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
250
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
251 case Magick::GrayscaleMatteType:
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
252 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
253 idim(2) = 2;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
254 im = T (idim);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
255 P *vec = im.fortran_vec ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
256
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
257 for (int frame = 0; frame < nframes; frame++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
258 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
259 const Magick::PixelPacket *pix
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
260 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
261
10298
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
262 P *rbuf = vec;
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
263 P *obuf = vec + rows * columns;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
264 for (int y = 0; y < rows; y++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
265 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
266 for (int x = 0; x < columns; x++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
267 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
268 *rbuf = pix->red / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
269 *obuf = pix->opacity / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
270 pix++;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
271 rbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
272 obuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
273 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
274 rbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
275 obuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
276 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
277
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
278 // Next frame.
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
279 vec += rows * columns * idim(2);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
280 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
281 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
282 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
283
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
284 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
285 case Magick::TrueColorType:
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
286 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
287 idim(2) = 3;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
288 im = T (idim);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
289 P *vec = im.fortran_vec ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
290
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
291 for (int frame = 0; frame < nframes; frame++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
292 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
293 const Magick::PixelPacket *pix
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
294 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
295
10298
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
296 P *rbuf = vec;
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
297 P *gbuf = vec + rows * columns;
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
298 P *bbuf = vec + rows * columns * 2;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
299 for (int y = 0; y < rows; y++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
300 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
301 for (int x = 0; x < columns; x++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
302 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
303 *rbuf = pix->red / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
304 *gbuf = pix->green / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
305 *bbuf = pix->blue / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
306 pix++;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
307 rbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
308 gbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
309 bbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
310 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
311 rbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
312 gbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
313 bbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
314 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
315
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
316 // Next frame.
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
317 vec += rows * columns * idim(2);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
318 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
319 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
320 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
321
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
322 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
323 case Magick::TrueColorMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
324 case Magick::ColorSeparationType:
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
325 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
326 idim(2) = 4;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
327 im = T (idim);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
328 P *vec = im.fortran_vec ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
329
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
330 for (int frame = 0; frame < nframes; frame++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
331 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
332 const Magick::PixelPacket *pix
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
333 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
334
10298
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
335 P *rbuf = vec;
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
336 P *gbuf = vec + rows * columns;
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
337 P *bbuf = vec + rows * columns * 2;
2be9b7e71f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10295
diff changeset
338 P *obuf = vec + rows * columns * 3;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
339 for (int y = 0; y < rows; y++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
340 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
341 for (int x = 0; x < columns; x++)
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
342 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
343 *rbuf = pix->red / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
344 *gbuf = pix->green / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
345 *bbuf = pix->blue / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
346 *obuf = pix->opacity / divisor;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
347 pix++;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
348 rbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
349 gbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
350 bbuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
351 obuf += rows;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
352 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
353 rbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
354 gbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
355 bbuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
356 obuf -= rows * columns - 1;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
357 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
358
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
359 // Next frame.
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
360 vec += rows * columns * idim(2);
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
361 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
362 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
363 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
364
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
365 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
366 error ("__magick_read__: undefined ImageMagick image type");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
367 return retval;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
368 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
369
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
370 retval(0) = im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
371
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
372 return retval;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
373 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
374
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
375 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
376
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
377 static void
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
378 maybe_initialize_magick (void)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
379 {
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
380 #ifdef HAVE_MAGICK
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
381
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
382 static bool initialized = false;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
383
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
384 if (! initialized)
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
385 {
15452
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
386 // Save locale as GraphicsMagick might change this (depending on version)
10739
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
387 const char *static_locale = setlocale (LC_ALL, NULL);
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
388 const std::string locale (static_locale);
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
389
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
390 std::string program_name = octave_env::get_program_invocation_name ();
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
391
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
392 Magick::InitializeMagick (program_name.c_str ());
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
393
10739
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
394 // Restore locale from before GraphicsMagick initialisation
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
395 setlocale (LC_ALL, locale.c_str ());
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
396
11036
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
397 if (QuantumDepth < 32)
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
398 warning ("your version of %s limits images to %d bits per pixel",
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
399 MagickPackageName, QuantumDepth);
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
400
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
401 initialized = true;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
402 }
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
403 #endif
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
404 }
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
405
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
406 DEFUN_DLD (__magick_read__, args, nargout,
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
407 "-*- texinfo -*-\n\
16543
c58069081439 doc: mark dldfcn as Loadable Functions on deftypen macro
Carnë Draug <carandraug@octave.org>
parents: 15467
diff changeset
408 @deftypefn {Loadable Function} {@var{m} =} __magick_read__ (@var{fname}, @var{index})\n\
c58069081439 doc: mark dldfcn as Loadable Functions on deftypen macro
Carnë Draug <carandraug@octave.org>
parents: 15467
diff changeset
409 @deftypefnx {Loadable Function} {[@var{m}, @var{colormap}] =} __magick_read__ (@var{fname}, @var{index})\n\
c58069081439 doc: mark dldfcn as Loadable Functions on deftypen macro
Carnë Draug <carandraug@octave.org>
parents: 15467
diff changeset
410 @deftypefnx {Loadable Function} {[@var{m}, @var{colormap}, @var{alpha}] =} __magick_read__ (@var{fname}, @var{index})\n\
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
411 Read images with ImageMagick++. In general you should not be using this\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
412 function. Instead use @code{imread}.\n\
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
413 @seealso{imread}\n\
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
414 @end deftypefn")
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
415 {
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
416 octave_value_list output;
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
417
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
418 #ifdef HAVE_MAGICK
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
419
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
420 maybe_initialize_magick ();
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
421
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
422 if (args.length () > 3 || args.length () < 1 || ! args(0).is_string ()
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
423 || nargout > 3)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
424 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
425 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
426 return output;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
427 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
428
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
429 Array<int> frameidx;
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
430 bool all_frames = false;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
431
7931
de26beacb20f imread.m: simplify; loadimage.m: deprecate
John W. Eaton <jwe@octave.org>
parents: 7926
diff changeset
432 if (args.length () == 2 && args(1).is_real_type ())
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
433 frameidx = args(1).int_vector_value ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
434 else if (args.length () == 3 && args(1).is_string ()
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
435 && args(1).string_value () == "frames")
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
436 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
437 if (args(2).is_string () && args(2).string_value () == "all")
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
438 all_frames = true;
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
439 else if (args(2).is_real_type ())
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
440 frameidx = args(2).int_vector_value ();
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
441 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
442 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
443 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
444 frameidx = Array<int> (dim_vector (1, 1));
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
445 frameidx(0) = 1;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
446 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
447
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
448 std::vector<Magick::Image> imvec;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
449
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
450 try
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
451 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
452 // Read a file into vector of image objects
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
453 Magick::readImages (&imvec, args(0).string_value ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
454 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
455 catch (Magick::Warning& w)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
456 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
457 warning ("Magick++ warning: %s", w.what ());
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
458 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
459 catch (Magick::ErrorCoder& e)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
460 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
461 warning ("Magick++ coder error: %s", e.what ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
462 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
463 catch (Magick::Exception& e)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
464 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
465 error ("Magick++ exception: %s", e.what ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
466 return output;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
467 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
468
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
469 int nframes = imvec.size ();
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
470 if (all_frames)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
471 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
472 frameidx = Array<int> (dim_vector (1, nframes));
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
473 for (int i = 0; i < frameidx.length (); i++)
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
474 frameidx(i) = i;
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
475 }
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
476 else
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
477 {
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
478 for (int i = 0; i < frameidx.length (); i++)
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
479 {
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
480 frameidx(i) = frameidx(i) - 1;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
481
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
482 if (frameidx(i) >= nframes || frameidx(i) < 0)
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
483 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
484 error ("__magick_read__: invalid INDEX vector");
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
485 return output;
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
486 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
487 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
488 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
489
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
490 Magick::ClassType klass = imvec[0].classType ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
491
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
492 if (klass == Magick::PseudoClass && nargout > 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
493 output = read_indexed_images (imvec, frameidx, (nargout == 3));
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
494 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
495 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
496 unsigned int depth = imvec[0].modulusDepth ();
9439
0a696f8aa434 determine correct image bitwidth in __magick_read__.cc
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 9436
diff changeset
497 if (depth > 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
498 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
499 --depth;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
500 int i = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
501 while (depth >>= 1)
9439
0a696f8aa434 determine correct image bitwidth in __magick_read__.cc
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 9436
diff changeset
502 i++;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
503 depth = 1 << i;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
504 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
505
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
506 switch (depth)
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
507 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
508 case 1:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
509 output = read_images<boolNDArray> (imvec, frameidx, depth);
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
510 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
511
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
512 case 2:
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
513 case 4:
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
514 case 8:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
515 output = read_images<uint8NDArray> (imvec, frameidx, depth) ;
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
516 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
517
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
518 case 16:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
519 output = read_images<uint16NDArray> (imvec, frameidx, depth);
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
520 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
521
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
522 case 32:
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
523 case 64:
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
524 default:
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
525 error ("__magick_read__: image depths greater than 16-bit are not supported");
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
526 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
527 }
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
528 #else
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
529
11590
4ced6b90fffb style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
530 error ("imread: image reading capabilities were disabled when Octave was compiled");
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
531
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
532 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
533
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
534 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
535 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
536
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
537 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
538 ## No test needed for internal helper function.
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
539 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
540 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
541
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
542 #ifdef HAVE_MAGICK
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
543
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
544 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
545 jpg_settings (std::vector<Magick::Image>& imvec,
16871
5e30b1c950b8 Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents: 16543
diff changeset
546 const octave_map& options,
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
547 bool)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
548 {
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
549 bool something_set = false;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
550
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
551 // Quality setting
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
552 octave_value result;
16871
5e30b1c950b8 Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents: 16543
diff changeset
553 octave_map::const_iterator p;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
554 bool found_it = false;
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
555
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
556 for (p = options.begin (); p != options.end (); p++)
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
557 {
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
558 if (options.key (p) == "Quality")
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
559 {
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
560 found_it = true;
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
561 result = options.contents (p).elem (0);
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
562 break;
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
563 }
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
564 }
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
565
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
566 if (found_it && (! result.is_empty ()))
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
567 {
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
568 something_set = true;
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
569
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
570 if (result.is_real_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
571 {
10978
71f38cba668d __magick_read__.cc: eliminate some casts
John W. Eaton <jwe@octave.org>
parents: 10977
diff changeset
572 int qlev = result.int_value ();
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
573
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
574 if (qlev < 0 || qlev > 100)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
575 warning ("warning: Quality setting invalid--use default of 75");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
576 else
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
577 {
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
578 for (size_t fnum = 0; fnum < imvec.size (); fnum++)
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
579 imvec[fnum].quality (static_cast<unsigned int>(qlev));
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
580 }
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
581 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
582 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
583 warning ("warning: Quality setting invalid--use default of 75");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
584 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
585
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
586 // Other settings go here
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
587
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
588 if (! something_set)
11590
4ced6b90fffb style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
589 warning ("__magick_write__ warning: all write parameters ignored");
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
590 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
591
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
592 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
593 encode_bool_image (std::vector<Magick::Image>& imvec, const octave_value& img)
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
594 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
595 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
596 boolNDArray m = img.bool_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
597
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
598 dim_vector dsizes = m.dims ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
599 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
600 nframes = dsizes(3);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
601
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
602 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
603
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
604 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
605 octave_idx_type columns = m.columns ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
606
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
607 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
608 {
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
609 Magick::Image im (Magick::Geometry (columns, rows), "black");
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
610 im.classType (Magick::DirectClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
611 im.depth (1);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
612
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
613 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
614 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
615 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
616
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
617 for (int x = 0; x < rows; x++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
618 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
619 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
620 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
621 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
622 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
623 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
624
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
625 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
626
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
627 if (m(idx))
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
628 im.pixelColor (y, x, "white");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
629 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
630 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
631
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
632 im.quantizeColorSpace (Magick::GRAYColorspace);
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
633 im.quantizeColors (2);
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
634 im.quantize ();
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
635
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
636 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
637 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
638 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
639
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
640 template <class T>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
641 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
642 encode_uint_image (std::vector<Magick::Image>& imvec,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
643 const octave_value& img,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
644 bool has_map)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
645 {
8520
715f6cd8d5e7 __magick_read__.cc (encode_uint_image): initialize bitdepth
Soren Hauberg <hauberg@gmail.com>
parents: 8165
diff changeset
646 unsigned int bitdepth = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
647 T m;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
648
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
649 if (img.is_uint8_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
650 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
651 bitdepth = 8;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
652 m = img.uint8_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
653 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
654 else if (img.is_uint16_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
655 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
656 bitdepth = 16;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
657 m = img.uint16_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
658 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
659 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
660 error ("__magick_write__: invalid image class");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
661
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
662 dim_vector dsizes = m.dims ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
663 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
664 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
665 nframes = dsizes(3);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
666
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
667 bool is_color = ((dsizes.length () > 2) && (dsizes(2) > 2));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
668 bool has_alpha = (dsizes.length () > 2 && (dsizes(2) == 2 || dsizes(2) == 4));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
669
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
670 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
671 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
672 octave_idx_type columns = m.columns ();
8090
3cc1ca1b1576 MSVC compilation fix
Michael Goffioul
parents: 8054
diff changeset
673
13020
58d704d3283c Fix ambigous call to int pow (int, unsigned int&)
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11590
diff changeset
674 unsigned int div_factor = (1 << bitdepth) - 1;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
675
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
676 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
677 {
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
678 Magick::Image im (Magick::Geometry (columns, rows), "black");
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
679
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
680 im.depth (bitdepth);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
681
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
682 if (has_map)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
683 im.classType (Magick::PseudoClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
684 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
685 im.classType (Magick::DirectClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
686
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
687 if (is_color)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
688 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
689 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
690 im.type (Magick::TrueColorMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
691 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
692 im.type (Magick::TrueColorType);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
693
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
694 Magick::ColorRGB c;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
695
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
696 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
697 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
698 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
699
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
700 for (int x = 0; x < rows; x++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
701 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
702 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
703
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
704 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
705 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
706
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
707 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
708 c.red (static_cast<double>(m(idx)) / div_factor);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
709
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
710 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
711 c.green (static_cast<double>(m(idx)) / div_factor);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
712
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
713 idx(2) = 2;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
714 c.blue (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
715
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
716 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
717 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
718 idx(2) = 3;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
719 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
720 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
721
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
722 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
723 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
724 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
725 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
726 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
727 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
728 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
729 im.type (Magick::GrayscaleMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
730 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
731 im.type (Magick::GrayscaleType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
732
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
733 Magick::ColorGray c;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
734
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
735 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
736 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
737 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
738
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
739 for (int x=0; x < rows; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
740 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
741 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
742
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
743 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
744 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
745 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
746 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
747 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
748
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
749 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
750 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
751 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
752 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
753 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
754 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
755
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
756 c.shade (static_cast<double>(m(idx)) / div_factor);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
757
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
758 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
759 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
760 }
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
761
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
762 im.quantizeColorSpace (Magick::GRAYColorspace);
13020
58d704d3283c Fix ambigous call to int pow (int, unsigned int&)
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11590
diff changeset
763 im.quantizeColors (1 << bitdepth);
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
764 im.quantize ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
765 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
766
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
767 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
768 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
769 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
770
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
771 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
772 encode_map (std::vector<Magick::Image>& imvec, const NDArray& cmap)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
773 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
774 unsigned int mapsize = cmap.dim1 ();
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
775
10978
71f38cba668d __magick_read__.cc: eliminate some casts
John W. Eaton <jwe@octave.org>
parents: 10977
diff changeset
776 for (size_t fnum = 0; fnum < imvec.size (); fnum++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
777 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
778 imvec[fnum].colorMapSize (mapsize);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
779 imvec[fnum].type (Magick::PaletteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
780 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
781
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
782 for (unsigned int ii = 0; ii < mapsize; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
783 {
9274
6e519bd01615 Fix RGB color construction in __magick_read__.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
784 Magick::ColorRGB c (cmap(ii,0), cmap(ii,1), cmap(ii,2));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
785
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
786 // FIXME -- is this case needed?
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
787 if (cmap.dim2 () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
788 c.alpha (cmap(ii,3));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
789
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
790 try
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
791 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
792 for_each (imvec.begin (), imvec.end (),
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
793 Magick::colorMapImage (ii, c));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
794 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
795 catch (Magick::Warning& w)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
796 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
797 warning ("Magick++ warning: %s", w.what ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
798 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
799 catch (Magick::ErrorCoder& e)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
800 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
801 warning ("Magick++ coder error: %s", e.what ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
802 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
803 catch (Magick::Exception& e)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
804 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
805 error ("Magick++ exception: %s", e.what ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
806 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
807 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
808 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
809
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
810 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
811 write_image (const std::string& filename, const std::string& fmt,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
812 const octave_value& img,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
813 const octave_value& map = octave_value (),
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
814 const octave_value& params = octave_value ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
815 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
816 std::vector<Magick::Image> imvec;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
817
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
818 bool has_map = map.is_defined ();
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
819
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
820 if (has_map)
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
821 {
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
822 error ("__magick_write__: direct saving of indexed images not currently supported; use ind2rgb and save converted image");
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
823 return;
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
824 }
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
825
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
826 if (img.is_bool_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
827 encode_bool_image (imvec, img);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
828 else if (img.is_uint8_type ())
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
829 encode_uint_image<uint8NDArray> (imvec, img, has_map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
830 else if (img.is_uint16_type ())
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
831 encode_uint_image<uint16NDArray> (imvec, img, has_map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
832 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
833 error ("__magick_write__: image type not supported");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
834
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
835 if (! error_state && has_map)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
836 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
837 NDArray cmap = map.array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
838
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
839 if (! error_state)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
840 encode_map (imvec, cmap);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
841 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
842
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
843 if (! error_state && params.is_defined ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
844 {
16871
5e30b1c950b8 Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents: 16543
diff changeset
845 octave_map options = params.map_value ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
846
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
847 // Insert calls here to handle parameters for various image formats
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
848 if (fmt == "jpg" || fmt == "jpeg")
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
849 jpg_settings (imvec, options, has_map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
850 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
851 warning ("warning: your parameter(s) currently not supported");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
852 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
853
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
854 try
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
855 {
10985
165e7e79b82c Updated for writing image files via imwrite.
John Swensen <jpswensen@gmail.com>
parents: 10979
diff changeset
856 Magick::writeImages (imvec.begin (), imvec.end (), fmt + ":" + filename);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
857 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
858 catch (Magick::Warning& w)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
859 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
860 warning ("Magick++ warning: %s", w.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
861 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
862 catch (Magick::ErrorCoder& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
863 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
864 warning ("Magick++ coder error: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
865 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
866 catch (Magick::Exception& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
867 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
868 error ("Magick++ exception: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
869 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
870 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
871
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
872 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
873
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
874 DEFUN_DLD (__magick_write__, args, ,
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
875 "-*- texinfo -*-\n\
16543
c58069081439 doc: mark dldfcn as Loadable Functions on deftypen macro
Carnë Draug <carandraug@octave.org>
parents: 15467
diff changeset
876 @deftypefn {Loadable Function} {} __magick_write__ (@var{fname}, @var{fmt}, @var{img})\n\
c58069081439 doc: mark dldfcn as Loadable Functions on deftypen macro
Carnë Draug <carandraug@octave.org>
parents: 15467
diff changeset
877 @deftypefnx {Loadable Function} {} __magick_write__ (@var{fname}, @var{fmt}, @var{img}, @var{map})\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10778
diff changeset
878 Write images with ImageMagick++. In general you should not be using this\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
879 function. Instead use @code{imwrite}.\n\
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
880 @seealso{imread}\n\
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
881 @end deftypefn")
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
882 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
883 octave_value_list retval;
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
884
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
885 #ifdef HAVE_MAGICK
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
886 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
887
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
888 int nargin = args.length ();
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
889
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
890 if (nargin > 2)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
891 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
892 std::string filename = args(0).string_value ();
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
893
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
894 if (! error_state)
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
895 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
896 std::string fmt = args(1).string_value ();
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
897
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
898 if (! error_state)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
899 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
900 if (nargin > 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
901 write_image (filename, fmt, args(2), args(3), args(4));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
902 else if (nargin > 3)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
903 if (args(3).is_real_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
904 write_image (filename, fmt, args(2), args(3));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
905 else
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
906 write_image (filename, fmt, args(2), octave_value (), args(3));
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
907 else
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
908 write_image (filename, fmt, args(2));
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
909 }
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
910 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
911 error ("__magick_write__: FMT must be string");
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
912 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
913 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
914 error ("__magick_write__: FNAME must be a string");
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
915 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
916 else
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
917 print_usage ();
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
918 #else
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
919
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
920 error ("__magick_write__: not available in this version of Octave");
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
921
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
922 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
923
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
924 return retval;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
925 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
926
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
927 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
928 ## No test needed for internal helper function.
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
929 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
930 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
931
8165
75014ec4ac84 __magick_read__.cc: only define magick_to_octave_value functions if HAVE_MAGICK is defined
John W. Eaton <jwe@octave.org>
parents: 8144
diff changeset
932 #ifdef HAVE_MAGICK
75014ec4ac84 __magick_read__.cc: only define magick_to_octave_value functions if HAVE_MAGICK is defined
John W. Eaton <jwe@octave.org>
parents: 8144
diff changeset
933
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
934 template<class T>
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
935 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
936 magick_to_octave_value (const T magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
937 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
938 return octave_value (magick);
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
939 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
940
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
941 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
942 magick_to_octave_value (const Magick::EndianType magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
943 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
944 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
945 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
946 case Magick::LSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
947 return octave_value ("little-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
948
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
949 case Magick::MSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
950 return octave_value ("big-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
951
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
952 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
953 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
954 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
955 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
956
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
957 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
958 magick_to_octave_value (const Magick::ResolutionType magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
959 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
960 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
961 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
962 case Magick::PixelsPerInchResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
963 return octave_value ("pixels per inch");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
964
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
965 case Magick::PixelsPerCentimeterResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
966 return octave_value ("pixels per centimeter");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
967
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
968 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
969 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
970 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
971 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
972
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
973 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
974 magick_to_octave_value (const Magick::ImageType magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
975 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
976 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
977 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
978 case Magick::BilevelType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
979 case Magick::GrayscaleType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
980 case Magick::GrayscaleMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
981 return octave_value ("grayscale");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
982
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
983 case Magick::PaletteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
984 case Magick::PaletteMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
985 return octave_value ("indexed");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
986
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
987 case Magick::TrueColorType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
988 case Magick::TrueColorMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
989 case Magick::ColorSeparationType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
990 return octave_value ("truecolor");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
991
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
992 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
993 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
994 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
995 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
996
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
997 // We put this in a try-block because GraphicsMagick will throw
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
998 // exceptions if a parameter isn't present in the current image.
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
999 #define GET_PARAM(NAME, OUTNAME) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1000 try \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1001 { \
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1002 info.contents (OUTNAME)(frame,0) = magick_to_octave_value (im.NAME ()); \
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1003 } \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1004 catch (Magick::Warning& w) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1005 { \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1006 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1007
8165
75014ec4ac84 __magick_read__.cc: only define magick_to_octave_value functions if HAVE_MAGICK is defined
John W. Eaton <jwe@octave.org>
parents: 8144
diff changeset
1008 #endif
75014ec4ac84 __magick_read__.cc: only define magick_to_octave_value functions if HAVE_MAGICK is defined
John W. Eaton <jwe@octave.org>
parents: 8144
diff changeset
1009
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
1010 DEFUN_DLD (__magick_finfo__, args, ,
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1011 "-*- texinfo -*-\n\
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1012 @deftypefn {Loadable Function} {} __magick_finfo__ (@var{fname})\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
1013 Read image information with GraphicsMagick++. In general you should\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
1014 not be using this function. Instead use @code{imfinfo}.\n\
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1015 @seealso{imfinfo, imread}\n\
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1016 @end deftypefn")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1017 {
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1018 octave_value retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1019
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1020 #ifdef HAVE_MAGICK
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1021
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1022 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1023
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1024 if (args.length () < 1 || ! args (0).is_string ())
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1025 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1026 print_usage ();
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1027 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1028 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1029
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1030 const std::string filename = args (0).string_value ();
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1031
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1032 try
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1033 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1034 // Read the file.
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1035 std::vector<Magick::Image> imvec;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1036 Magick::readImages (&imvec, args(0).string_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1037 int nframes = imvec.size ();
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1038
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1039 // Create the right size for the output.
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1040
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1041 static const char *fields[] =
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1042 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1043 "Filename",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1044 "FileModDate",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1045 "FileSize",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1046 "Height",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1047 "Width",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1048 "BitDepth",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1049 "Format",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1050 "LongFormat",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1051 "XResolution",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1052 "YResolution",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1053 "TotalColors",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1054 "TileName",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1055 "AnimationDelay",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1056 "AnimationIterations",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1057 "ByteOrder",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1058 "Gamma",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1059 "Matte",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1060 "ModulusDepth",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1061 "Quality",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1062 "QuantizeColors",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1063 "ResolutionUnits",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1064 "ColorType",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1065 "View",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1066 0
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1067 };
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1068
16871
5e30b1c950b8 Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents: 16543
diff changeset
1069 octave_map info (dim_vector (nframes, 1), string_vector (fields));
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1070
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1071 file_stat fs (filename);
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1072
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1073 std::string filetime;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1074
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1075 if (fs)
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1076 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1077 octave_localtime mtime = fs.mtime ();
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1078
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1079 filetime = mtime.strftime ("%e-%b-%Y %H:%M:%S");
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1080 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1081 else
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1082 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1083 std::string msg = fs.error ();
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1084
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14173
diff changeset
1085 error ("imfinfo: error reading '%s': %s",
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1086 filename.c_str (), msg.c_str ());
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1087
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1088 return retval;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1089 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1090
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1091 // For each frame in the image (some images contain multiple
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1092 // layers, each to be treated like a separate image).
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1093 for (int frame = 0; frame < nframes; frame++)
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1094 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1095 Magick::Image im = imvec[frame];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1096
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1097 // Add file name and timestamp.
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1098 info.contents ("Filename")(frame,0) = filename;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1099 info.contents ("FileModDate")(frame,0) = filetime;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1100
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1101 // Annoying CamelCase naming is for Matlab compatibility.
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1102 GET_PARAM (fileSize, "FileSize")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1103 GET_PARAM (rows, "Height")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1104 GET_PARAM (columns, "Width")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1105 GET_PARAM (depth, "BitDepth")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1106 GET_PARAM (magick, "Format")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1107 GET_PARAM (format, "LongFormat")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1108 GET_PARAM (xResolution, "XResolution")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1109 GET_PARAM (yResolution, "YResolution")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1110 GET_PARAM (totalColors, "TotalColors")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1111 GET_PARAM (tileName, "TileName")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1112 GET_PARAM (animationDelay, "AnimationDelay")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1113 GET_PARAM (animationIterations, "AnimationIterations")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1114 GET_PARAM (endian, "ByteOrder")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1115 GET_PARAM (gamma, "Gamma")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1116 GET_PARAM (matte, "Matte")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1117 GET_PARAM (modulusDepth, "ModulusDepth")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1118 GET_PARAM (quality, "Quality")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1119 GET_PARAM (quantizeColors, "QuantizeColors")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1120 GET_PARAM (resolutionUnits, "ResolutionUnits")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1121 GET_PARAM (type, "ColorType")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1122 GET_PARAM (view, "View")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1123 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1124
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1125 retval = octave_value (info);
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1126 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1127 catch (Magick::Warning& w)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1128 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1129 warning ("Magick++ warning: %s", w.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1130 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1131 catch (Magick::ErrorCoder& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1132 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1133 warning ("Magick++ coder error: %s", e.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1134 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1135 catch (Magick::Exception& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1136 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1137 error ("Magick++ exception: %s", e.what ());
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1138 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1139 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1140
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1141 #else
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1142
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1143 error ("imfinfo: not available in this version of Octave");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1145 #endif
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1146
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1147 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1148 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1149
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1150 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1151 ## No test needed for internal helper function.
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1152 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1153 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1154
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1155 #undef GET_PARAM
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1156
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1157 DEFUN_DLD (__magick_formats__, args, ,
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1158 "-*- texinfo -*-\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1159 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1160 Fill formats info with GraphicsMagick CoderInfo.\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1161 @end deftypefn")
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1162 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1163 octave_value retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1164 #ifndef HAVE_MAGICK
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1165 gripe_disabled_feature ("imformats", "Image IO");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1166 #else
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1167 if (args.length () != 1 || ! args (0).is_map ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1168 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1169 print_usage ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1170 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1171 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1172 octave_map formats = args(0).map_value ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1173
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1174 maybe_initialize_magick ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1175 for (octave_idx_type idx = 0; idx < formats.numel (); idx++)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1176 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1177 try
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1178 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1179 octave_scalar_map fmt = formats.checkelem (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1180 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1181
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1182 fmt.setfield ("description", octave_value (coder.description ()));
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1183 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1184 // default for read and write is a function handle. If we can't
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1185 // read or write them, them set it to an empty value
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1186 if (! coder.isReadable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1187 fmt.setfield ("read", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1188 if (! coder.isWritable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1189 fmt.setfield ("write", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1190 formats.fast_elem_insert (idx, fmt);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1191 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1192 catch (Magick::Exception& e)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1193 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1194 // Exception here are missing formats. So we remove the format
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1195 // from the structure and reduce idx.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1196 formats.delete_elements (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1197 idx--;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1198 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1199 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1200 retval = formats;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1201 #endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1202 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1203 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1204
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1205 /*
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1206 ## No test needed for internal helper function.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1207 %!assert (1)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1208 */
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1209
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1210 // Determine the file formats supported by GraphicsMagick. This is
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1211 // called once at the beginning of imread or imwrite to determine
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1212 // exactly which file formats are supported, so error messages can be
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1213 // displayed properly.
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1214
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1215 DEFUN_DLD (__magick_format_list__, args, ,
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1216 "-*- texinfo -*-\n\
16543
c58069081439 doc: mark dldfcn as Loadable Functions on deftypen macro
Carnë Draug <carandraug@octave.org>
parents: 15467
diff changeset
1217 @deftypefn {Loadable Function} {} __magick_format_list__ (@var{formats})\n\
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1218 Undocumented internal function.\n\
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1219 @end deftypefn")
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1220 {
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1221 octave_value retval;
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1222
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1223 #ifdef HAVE_MAGICK
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1224 maybe_initialize_magick ();
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1225
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1226 std::list<std::string> accepted_formats;
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1227
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1228 if (args.length () == 1)
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1229 {
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1230 Cell c = args (0).cell_value ();
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1231
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1232 if (! error_state)
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1233 {
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1234 for (octave_idx_type i = 0; i < c.nelem (); i++)
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1235 {
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1236 try
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1237 {
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1238 std::string fmt = c.elem (i).string_value ();
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1239
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1240 Magick::CoderInfo info(fmt);
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1241
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1242 if (info.isReadable () && info.isWritable ())
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1243 accepted_formats.push_back (fmt);
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1244 }
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1245 catch (Magick::Exception& e)
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1246 {
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1247 // Do nothing: exception here are simply missing formats.
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1248 }
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1249 }
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1250 }
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1251 else
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1252 error ("__magick_format_list__: expecting a cell array of image format names");
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1253 }
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1254 else
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1255 print_usage ();
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1256
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1257 retval = Cell (accepted_formats);
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1258
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1259 #else
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1260
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1261 error ("__magick_format_list__: not available in this version of Octave");
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1262
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1263 #endif
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1264
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1265 return retval;
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1266 }
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1267
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1268 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1269 ## No test needed for internal helper function.
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1270 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1271 */