annotate src/DLD-FUNCTIONS/__magick_read__.cc @ 10193:1a4074e277fe

undo unintended change to __magick_read__.cc
author John W. Eaton <jwe@octave.org>
date Fri, 22 Jan 2010 16:54:59 -0500
parents a552859b009a
children 13d382fc758b
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
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8520
diff changeset
3 Copyright (C) 2002, 2009 Andy Adler
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
4 Copyright (C) 2008 Thomas L. Scofield
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
5
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
6 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
7
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
8 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
9 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
10 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
11 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
12
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
13 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
14 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
15 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
16 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
17
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
18 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
19 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
20 <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
21
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
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
24 #ifdef HAVE_CONFIG_H
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
25 #include <config.h>
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
26 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
27
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
28 #include <cmath>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
29
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
30 #include "defun-dld.h"
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
31 #include "error.h"
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
32 #include "ov-struct.h"
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
33
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
34 #ifdef HAVE_MAGICK
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
35
9575
55ecaefb7d0f Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents: 9439
diff changeset
36 #include <Magick++.h>
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
37
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
38 unsigned int
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
39 scale_quantum_to_depth (const Magick::Quantum& quantum, 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
40 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
41 return (static_cast<unsigned int> (static_cast<double> (quantum)
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
42 / MaxRGB * ((1 << depth) - 1)));
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
43 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
44
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
45 octave_value_list
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
46 read_indexed_images (std::vector<Magick::Image>& imvec,
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
47 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
48 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
49 octave_value_list output;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
50
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
51 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
52 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
53 int nframes = frameidx.length ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
54
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
55 dim_vector idim = dim_vector ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
56 idim.resize (4);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
57 idim(0) = rows;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
58 idim(1) = columns;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
59 idim(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
60 idim(3) = nframes;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
61
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
62 Array<int> idx (dim_vector (4));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
63
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
64 Magick::ImageType type = imvec[0].type ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
65
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
66 unsigned int mapsize = imvec[0].colorMapSize ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
67 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
68 unsigned int depth = 0;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
69 while (i >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
70 depth++;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
71 i = 0;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
72 depth--;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
73 while (depth >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
74 i++;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
75 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
76
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
77 switch (depth)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
78 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
79 case 1:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
80 case 2:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
81 case 4:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
82 case 8:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
83 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
84 uint8NDArray im = uint8NDArray (idim);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
85
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
86 idx(2) = 0;
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
87 for (int frame = 0; frame < nframes; frame++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
88 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
89 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
90
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
91 const Magick::IndexPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
92 = imvec[frameidx(frame)].getConstIndexes ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
93
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
94 i = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
95 idx(3) = frame;
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
96
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
97 for (int y = 0; y < rows; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
98 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
99 idx(0) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
100 for (int x = 0; x < columns; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
101 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
102 idx(1) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
103 im(idx) = static_cast<octave_uint8> (pix[i++]);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
104 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
105 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
106 }
10100
dd4d4b14b340 __magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
107
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
108 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
109 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
110 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
111
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
112 case 16:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
113 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
114 uint16NDArray im = uint16NDArray (idim);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
115
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
116 idx(2) = 0;
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
117 for (int frame = 0; frame < nframes; frame++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
118 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
119 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
120
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
121 const Magick::IndexPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
122 = imvec[frameidx(frame)].getConstIndexes ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
123
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
124 i = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
125 idx(3) = frame;
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
126
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
127 for (int y = 0; y < rows; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
128 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
129 idx(0) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
130 for (int x = 0; x < columns; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
131 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
132 idx(1) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
133 im(idx) = static_cast<octave_uint16> (pix[i++]);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
134 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
135 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
136 }
10100
dd4d4b14b340 __magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
137
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
138 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
139 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
140 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
141
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
142 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
143 error ("__magic_read__: index depths bigger than 16-bit 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
144 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
145 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
146
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
147 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
148 Matrix alpha;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
149
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
150 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
151 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
152 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
153 #if 0
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
154 warning ("palettematte");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
155 Matrix map (mapsize, 3);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
156 Matrix alpha (mapsize, 1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
157 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
158 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
159 warning ("%d", i);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
160 Magick::ColorRGB c = imvec[0].colorMap (i);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
161 map(i,0) = c.red ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
162 map(i,1) = c.green ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
163 map(i,2) = c.blue ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
164 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
165 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
166 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
167 #endif
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
168
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
169 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
170 alpha = Matrix (0, 0);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
171 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
172 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
173 Magick::ColorRGB c = imvec[0].colorMap (i);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
174 map(i,0) = c.red ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
175 map(i,1) = c.green ();
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
176 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
177 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
178 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
179
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
180 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
181 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
182 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
183 }
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 if (wantalpha)
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
186 output(2) = alpha;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
187
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
188 output(1) = map;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
189
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
190 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
191 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
192
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
193 template <class T>
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
194 octave_value_list
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
195 read_images (const std::vector<Magick::Image>& imvec,
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
196 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
197 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
198 octave_value_list retval (3, Matrix ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
199
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
200 T im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
201
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
202 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
203 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
204 int nframes = frameidx.length ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
205
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
206 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
207 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
208 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
209 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
210 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
211 idim(3) = nframes;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
212
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
213 Array<int> idx (dim_vector (4));
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
214
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
215 Magick::ImageType type = imvec[0].type ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
216
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
217 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
218 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
219 case Magick::BilevelType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
220 case Magick::GrayscaleType:
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
221 im = T (idim);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
222 for (int frame = 0; frame < nframes; frame++)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
223 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
224 const Magick::PixelPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
225 = 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
226
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
227 int i = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
228 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
229 idx(3) = frame;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
230
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
231 for (int y = 0; y < rows; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
232 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
233 idx(0) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
234 for (int x = 0; x < columns; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
235 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
236 idx(1) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
237 im(idx) = scale_quantum_to_depth (pix[i++].red, depth);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
238 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
239 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
240 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
241 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
242
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
243 case Magick::GrayscaleMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
244 idim(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
245 im = T (idim);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
246 for (int frame = 0; frame < nframes; frame++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
247 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
248 const Magick::PixelPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
249 = 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
250
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
251 int i = 0;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
252 idx(3) = frame;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
253
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
254 for (int y = 0; y < rows; y++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
255 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
256 idx(0) = y;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
257 for (int x = 0; x < columns; x++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
258 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
259 idx(1) = x;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
260 idx(2) = 0;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
261 im(idx) = scale_quantum_to_depth (pix[i].red, depth);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
262 idx(2) = 1;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
263 im(idx) = scale_quantum_to_depth (pix[i].opacity, depth);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
264 i++;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
265 }
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
266 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
267 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
268 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
269
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
270 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
271 case Magick::TrueColorType:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
272 idim(2) = 3;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
273 im = T (idim);
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
274 for (int frame = 0; frame < nframes; frame++)
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
275 {
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
276 const Magick::PixelPacket *pix
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
277 = 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
278
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
279 int i = 0;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
280 idx(3) = frame;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
281
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
282 for (int y = 0; y < rows; y++)
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
283 {
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
284 idx(0) = y;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
285 for (int x = 0; x < columns; x++)
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
286 {
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
287 idx(1) = x;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
288 idx(2) = 0;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
289 im(idx) = scale_quantum_to_depth (pix[i].red, depth);
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
290 idx(2) = 1;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
291 im(idx) = scale_quantum_to_depth (pix[i].green, depth);
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
292 idx(2) = 2;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
293 im(idx) = scale_quantum_to_depth (pix[i].blue, depth);
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
294 i++;
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
295 }
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
296 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
297 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
298 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
299
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
300 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
301 case Magick::TrueColorMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
302 case Magick::ColorSeparationType:
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
303 idim(2) = 4;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
304 im = T (idim);
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
305 for (int frame = 0; frame < nframes; frame++)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
306 {
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
307 const Magick::PixelPacket *pix
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
308 = 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
309
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
310 int i = 0;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
311 idx(3) = frame;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
312
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
313 for (int y = 0; y < rows; y++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
314 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
315 idx(0) = y;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
316 for (int x = 0; x < columns; x++)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
317 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
318 idx(1) = x;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
319 idx(2) = 0;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
320 im(idx) = scale_quantum_to_depth (pix[i].red, depth);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
321 idx(2) = 1;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
322 im(idx) = scale_quantum_to_depth (pix[i].green, depth);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
323 idx(2) = 2;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
324 im(idx) = scale_quantum_to_depth (pix[i].blue, depth);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
325 idx(2) = 3;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
326 im(idx) = scale_quantum_to_depth (pix[i].opacity, depth);
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
327 i++;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
328 }
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
329 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
330 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
331 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
332
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
333 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
334 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
335 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
336 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
337
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
338 retval(0) = im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
339
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
340 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
341 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
342
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
343 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
344
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
345 DEFUN_DLD (__magick_read__, args, nargout,
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
346 "-*- texinfo -*-\n\
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
347 @deftypefn {Function File} {@var{m} =} __magick_read__(@var{fname}, @var{index})\n\
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
348 @deftypefnx{Function File} {[@var{m}, @var{colormap}] =} __magick_read__(@var{fname}, @var{index})\n\
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
349 @deftypefnx{Function File} {[@var{m}, @var{colormap}, @var{alpha}] =} __magick_read__(@var{fname}, @var{index})\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
350 Read images with ImageMagick++. In general you should not be using this function.\n\
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
351 Instead you should use @code{imread}.\n\
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
352 @seealso{imread}\n\
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
353 @end deftypefn")
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
354 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
355 octave_value_list output;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
356
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
357 #ifdef HAVE_MAGICK
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
358
7931
de26beacb20f imread.m: simplify; loadimage.m: deprecate
John W. Eaton <jwe@octave.org>
parents: 7926
diff changeset
359 if (args.length () > 2 || 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
360 || 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
361 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
362 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
363 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
364 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
365
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
366 Array<int> frameidx;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
367
7931
de26beacb20f imread.m: simplify; loadimage.m: deprecate
John W. Eaton <jwe@octave.org>
parents: 7926
diff changeset
368 if (args.length () == 2 && args(1).is_real_type ())
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
369 frameidx = args(1).int_vector_value();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
370 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
371 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
372 frameidx = Array<int> (1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
373 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
374 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
375
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
376 std::vector<Magick::Image> imvec;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
377
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
378 try
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
379 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
380 // 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
381 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
382 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
383 catch (Magick::Warning& w)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
384 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
385 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
386 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
387 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
388 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
389 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
390 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
391 catch (Magick::Exception& e)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
392 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
393 error ("Magick++ exception: %s", e.what ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
394 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
395 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
396
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
397 for (int i = 0; i < frameidx.length(); i++)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
398 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
399 frameidx(i) = frameidx(i) - 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
400
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
401 int nframes = imvec.size ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
402
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
403 if (frameidx(i) >= nframes || frameidx(i) < 0)
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
404 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
405 error ("__magick_read__: invalid index vector");
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
406 return output;
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
407 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
408 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
409
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
410 Magick::ClassType klass = imvec[0].classType ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
411
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
412 if (klass == Magick::PseudoClass && nargout > 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
413 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
414 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
415 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
416 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
417 if (depth > 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
418 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
419 --depth;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
420 int i = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
421 while (depth >>= 1)
9439
0a696f8aa434 determine correct image bitwidth in __magick_read__.cc
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 9436
diff changeset
422 i++;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
423 depth = 1 << i;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10100
diff changeset
424 }
9439
0a696f8aa434 determine correct image bitwidth in __magick_read__.cc
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 9436
diff changeset
425
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
426 switch (depth)
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
427 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
428 case 1:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
429 output = read_images<boolNDArray> (imvec, frameidx, depth);
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
430 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
431
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
432 case 2:
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
433 case 4:
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
434 case 8:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
435 output = read_images<uint8NDArray> (imvec, frameidx, depth) ;
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
436 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
437
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
438 case 16:
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
439 output = read_images<uint16NDArray> (imvec, frameidx, depth);
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
440 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
441
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
442 case 32:
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
443 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
444 default:
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
445 error ("__magick_read__: image depths bigger than 16-bit not supported");
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
446 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
447 }
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
448 #else
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
449
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
450 error ("__magick_read__: not available in this version of Octave");
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
451
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
452 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
453
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
454 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
455 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
456
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
457 #ifdef HAVE_MAGICK
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
458
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
459 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
460 jpg_settings (std::vector<Magick::Image>& imvec,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
461 const Octave_map& options,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
462 bool)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
463 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
464 int nframes = static_cast<int>(imvec.size ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
465 bool something_set = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
466
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
467 // Quality setting
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
468 octave_value result;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
469 Octave_map::const_iterator p;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
470 bool found_it = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
471 for (p = options.begin (); p != options.end (); p++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
472 if (options.key (p) == "Quality")
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
473 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
474 found_it = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
475 result = options.contents (p).elem (0);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
476 break;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
477 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
478 if (found_it && (! result.is_empty ()))
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
479 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
480 something_set = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
481 if (result.is_real_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
482 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
483 int qlev = static_cast<int>(result.int_value ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
484 if (qlev < 0 || qlev > 100)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
485 warning ("warning: Quality setting invalid--use default of 75");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
486 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
487 for (int fnum = 0; fnum < nframes; fnum++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
488 imvec[fnum].quality (static_cast<unsigned int>(qlev));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
489 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
490 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
491 warning ("warning: Quality setting invalid--use default of 75");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
492 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
493
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
494 // Other settings go here
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
495
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
496 if (! something_set)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
497 warning ("__magick_write__ warning: All write parameters ignored.");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
498 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
499
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
500 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
501 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
502 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
503 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
504 boolNDArray m = img.bool_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
505
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
506 dim_vector dsizes = m.dims ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
507 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
508 nframes = dsizes(3);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
509
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
510 Array<octave_idx_type> idx (dsizes.length ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
511
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
512 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
513 octave_idx_type columns = m.columns ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
514
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
515 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
516 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
517 Magick::Image im(Magick::Geometry (columns, rows), "black");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
518 im.classType (Magick::DirectClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
519 im.depth (1);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
520
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
521 for (int y=0; y < columns; y++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
522 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
523 idx(1) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
524 for (int x=0; x < rows; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
525 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
526 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
527 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
528 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
529 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
530 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
531 idx(0) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
532 if (m(idx))
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
533 im.pixelColor (y, x, "white");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
534 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
535 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
536 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
537 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
538 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
539
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
540 template <class T>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
541 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
542 encode_uint_image (std::vector<Magick::Image>& imvec,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
543 const octave_value& img,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
544 bool has_map)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
545 {
8520
715f6cd8d5e7 __magick_read__.cc (encode_uint_image): initialize bitdepth
Soren Hauberg <hauberg@gmail.com>
parents: 8165
diff changeset
546 unsigned int bitdepth = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
547 T m;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
548
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
549 if (img.is_uint8_type ())
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 bitdepth = 8;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
552 m = img.uint8_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
553 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
554 else if (img.is_uint16_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
555 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
556 bitdepth = 16;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
557 m = img.uint16_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
558 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
559 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
560 error ("__magick_write__: invalid image class");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
561
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
562 dim_vector dsizes = m.dims ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
563 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
564 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
565 nframes = dsizes(3);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
566 bool is_color = ((dsizes.length () > 2) && (dsizes(2) > 2));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
567 bool has_alpha = (dsizes.length () > 2 && (dsizes(2) == 2 || dsizes(2) == 4));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
568
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
569 Array<octave_idx_type> idx (dsizes.length ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
570 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
571 octave_idx_type columns = m.columns ();
8090
3cc1ca1b1576 MSVC compilation fix
Michael Goffioul
parents: 8054
diff changeset
572
3cc1ca1b1576 MSVC compilation fix
Michael Goffioul
parents: 8054
diff changeset
573 // FIXME -- maybe simply using bit shifting would be better?
3cc1ca1b1576 MSVC compilation fix
Michael Goffioul
parents: 8054
diff changeset
574 unsigned int div_factor = pow (2.0, static_cast<int> (bitdepth)) - 1;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
575
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
576 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
577 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
578 Magick::Image im(Magick::Geometry (columns, rows), "black");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
579 im.depth (bitdepth);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
580 if (has_map)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
581 im.classType (Magick::PseudoClass);
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 im.classType (Magick::DirectClass);
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 if (is_color)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
586 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
587 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
588 im.type (Magick::TrueColorMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
589 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
590 im.type (Magick::TrueColorType);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
591
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
592 Magick::ColorRGB c;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
593 for (int y=0; y < columns; y++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
594 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
595 idx(1) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
596 for (int x=0; x < rows; x++)
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 idx(0) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
599 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
600 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
601
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
602 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
603 c.red (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
604 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
605 c.green (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
606 idx(2) = 2;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
607 c.blue (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
608
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
609 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
610 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
611 idx(2) = 3;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
612 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
613 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
614 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
615 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
616 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
617 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
618 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
619 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
620 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
621 im.type (Magick::GrayscaleMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
622 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
623 im.type (Magick::GrayscaleType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
624
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
625 Magick::ColorGray c;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
626
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
627 for (int y=0; y < columns; y++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
628 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
629 idx(1) = y;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
630 for (int x=0; x < rows; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
631 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
632 idx(0) = x;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
633 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
634 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
635 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
636 idx(3) = ii;
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 if (has_alpha)
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 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
641 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
642 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
643 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
644
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
645 c.shade (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
646 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
647 }
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 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
650 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
651 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
652 }
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 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
655 encode_map (std::vector<Magick::Image>& imvec, const NDArray& cmap)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
656 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
657 unsigned int mapsize = cmap.dim1 ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
658 int nframes = static_cast<int>(imvec.size ());
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
659
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
660 for (int fnum = 0; fnum < nframes; fnum++)
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 imvec[fnum].colorMapSize (mapsize);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
663 imvec[fnum].type (Magick::PaletteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
664 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
665
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
666 for (unsigned int ii = 0; ii < mapsize; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
667 {
9274
6e519bd01615 Fix RGB color construction in __magick_read__.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
668 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
669
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
670 // FIXME -- is this case needed?
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
671 if (cmap.dim2 () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
672 c.alpha (cmap(ii,3));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
673
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
674 try
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_each (imvec.begin (), imvec.end (),
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
677 Magick::colorMapImage (ii, c));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
678 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
679 catch (Magick::Warning& w)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
680 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
681 warning ("Magick++ warning: %s", w.what ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
682 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
683 catch (Magick::ErrorCoder& e)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
684 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
685 warning ("Magick++ coder error: %s", e.what ());
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 catch (Magick::Exception& e)
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 error ("Magick++ exception: %s", e.what ());
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
690 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
691 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
692 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
693
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
694 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
695 write_image (const std::string& filename, const std::string& fmt,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
696 const octave_value& img,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
697 const octave_value& map = octave_value (),
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
698 const octave_value& params = octave_value ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
699 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
700 std::vector<Magick::Image> imvec;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
701
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
702 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
703
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
704 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
705 {
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
706 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
707 return;
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
708 }
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
709
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
710 if (img.is_bool_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
711 encode_bool_image (imvec, img);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
712 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
713 encode_uint_image<uint8NDArray> (imvec, img, has_map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
714 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
715 encode_uint_image<uint16NDArray> (imvec, img, has_map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
716 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
717 error ("__magick_write__: image type not supported");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
718
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
719 if (! error_state && has_map)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
720 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
721 NDArray cmap = map.array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
722
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
723 if (! error_state)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
724 encode_map (imvec, cmap);
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
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
727 if (! error_state && params.is_defined ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
728 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
729 Octave_map options = params.map_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
730
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
731 // Insert calls here to handle parameters for various image formats
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
732 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
733 jpg_settings (imvec, options, has_map);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
734 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
735 warning ("warning: your parameter(s) currently not supported");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
736 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
737
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
738 try
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
739 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
740 Magick::writeImages (imvec.begin (), imvec.end (), filename);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
741 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
742 catch (Magick::Warning& w)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
743 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
744 warning ("Magick++ warning: %s", w.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
745 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
746 catch (Magick::ErrorCoder& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
747 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
748 warning ("Magick++ coder error: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
749 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
750 catch (Magick::Exception& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
751 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
752 error ("Magick++ exception: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
753 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
754 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
755
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
756 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
757
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
758 DEFUN_DLD (__magick_write__, args, ,
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
759 "-*- texinfo -*-\n\
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
760 @deftypefn {Function File} {} __magick_write__(@var{fname}, @var{fmt}, @var{img})\n\
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
761 @deftypefnx {Function File} {} __magick_write__(@var{fname}, @var{fmt}, @var{img}, @var{map})\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
762 Write images with ImageMagick++. In general you should not be using this function.\n\
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
763 Instead you should use @code{imwrite}.\n\
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
764 @seealso{imread}\n\
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
765 @end deftypefn")
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
766 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
767 octave_value_list retval;
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
768
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
769 #ifdef HAVE_MAGICK
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
770 int nargin = args.length ();
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
771
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
772 if (nargin > 2)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
773 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
774 std::string filename = args(0).string_value ();
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
775
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
776 if (! error_state)
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
777 {
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
778 std::string fmt = args(1).string_value ();
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
779
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
780 if (! error_state)
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
781 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
782 if (nargin > 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
783 write_image (filename, fmt, args(2), args(3), args(4));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
784 else if (nargin > 3)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
785 if (args(3).is_real_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
786 write_image (filename, fmt, args(2), args(3));
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
787 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
788 write_image (filename, fmt, args(2), octave_value(), args(3));
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
789 else
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
790 write_image (filename, fmt, args(2));
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
791 }
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
792 else
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
793 error ("__magick_write__: expecting format as second argument");
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
794 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
795 else
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
796 error ("__magick_write__: expecting filename as first argument");
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
797 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
798 else
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
799 print_usage ();
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
800 #else
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
801
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
802 error ("__magick_write__: not available in this version of Octave");
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
803
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
804 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
805
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
806 return retval;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
807 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
808
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
809 #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
810
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
811 template<class T>
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
812 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
813 magick_to_octave_value (const T magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
814 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
815 return octave_value (magick);
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
816 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
817
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
818 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
819 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
820 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
821 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
822 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
823 case Magick::LSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
824 return octave_value ("little-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
825
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
826 case Magick::MSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
827 return octave_value ("big-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
828
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
829 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
830 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
831 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
832 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
833
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
834 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
835 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
836 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
837 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
838 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
839 case Magick::PixelsPerInchResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
840 return octave_value ("pixels per inch");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
841
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
842 case Magick::PixelsPerCentimeterResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
843 return octave_value ("pixels per centimeter");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
844
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
845 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
846 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
847 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
848 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
849
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
850 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
851 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
852 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
853 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
854 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
855 case Magick::BilevelType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
856 case Magick::GrayscaleType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
857 case Magick::GrayscaleMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
858 return octave_value ("grayscale");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
859
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
860 case Magick::PaletteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
861 case Magick::PaletteMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
862 return octave_value ("indexed");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
863
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
864 case Magick::TrueColorType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
865 case Magick::TrueColorMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
866 case Magick::ColorSeparationType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
867 return octave_value ("truecolor");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
868
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
869 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
870 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
871 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
872 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
873
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
874 // 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
875 // 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
876 #define GET_PARAM(NAME, OUTNAME) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
877 try \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
878 { \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
879 st.assign (OUTNAME, magick_to_octave_value (im.NAME ())); \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
880 } \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
881 catch (Magick::Warning& w) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
882 { \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
883 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
884
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
885 #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
886
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
887 DEFUN_DLD (__magick_finfo__, args, ,
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
888 "-*- texinfo -*-\n\
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
889 @deftypefn {Loadable File} {} __magick_finfo__(@var{fname})\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
890 Read image information with GraphicsMagick++. In general you should\n\
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
891 not be using this function. Instead you should use @code{imfinfo}.\n\
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
892 @seealso{imfinfo, imread}\n\
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
893 @end deftypefn")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
894 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
895 octave_value_list output;
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
896
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
897 #ifdef HAVE_MAGICK
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
898
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
899 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
900 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
901 print_usage ();
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
902 return output;
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
903 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
904
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
905 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
906
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
907 try
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
908 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
909 // Read the file.
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
910 Magick::Image im;
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
911 im.read (filename);
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
912
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
913 // Read properties.
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
914 Octave_map st;
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
915 st.assign ("Filename", filename);
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
916
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
917 // Annoying CamelCase naming is for Matlab compatibility.
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
918 GET_PARAM (fileSize, "FileSize")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
919 GET_PARAM (rows, "Height")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
920 GET_PARAM (columns, "Width")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
921 GET_PARAM (depth, "BitDepth")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
922 GET_PARAM (magick, "Format")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
923 GET_PARAM (format, "LongFormat")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
924 GET_PARAM (xResolution, "XResolution")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
925 GET_PARAM (yResolution, "YResolution")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
926 GET_PARAM (totalColors, "TotalColors")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
927 GET_PARAM (tileName, "TileName")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
928 GET_PARAM (animationDelay, "AnimationDelay")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
929 GET_PARAM (animationIterations, "AnimationIterations")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
930 GET_PARAM (endian, "ByteOrder")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
931 GET_PARAM (gamma, "Gamma")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
932 GET_PARAM (matte, "Matte")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
933 GET_PARAM (modulusDepth, "ModulusDepth")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
934 GET_PARAM (quality, "Quality")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
935 GET_PARAM (quantizeColors, "QuantizeColors")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
936 GET_PARAM (resolutionUnits, "ResolutionUnits")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
937 GET_PARAM (type, "ColorType")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
938 GET_PARAM (view, "View")
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 output (0) = st;
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
941 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
942 catch (Magick::Warning& w)
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 warning ("Magick++ warning: %s", w.what ());
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 catch (Magick::ErrorCoder& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
947 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
948 warning ("Magick++ coder error: %s", e.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
949 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
950 catch (Magick::Exception& e)
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 error ("Magick++ exception: %s", e.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
953 return output;
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 #else
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
957
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
958 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
959
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
960 #endif
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 return output;
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
963 }
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 #undef GET_PARAM