annotate src/DLD-FUNCTIONS/__magick_read__.cc @ 7926:d74f996e005d

__magick_read__.cc: configuration and style fixes
author John W. Eaton <jwe@octave.org>
date Mon, 14 Jul 2008 16:00:09 -0400
parents 9316b59903c9
children de26beacb20f
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
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
3 Copyright (C) 2002 Andy Adler
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
4 2008 Thomas L. Scofield
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
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
28 #include "defun-dld.h"
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
29 #include "error.h"
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
30
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
31 #include <GraphicsMagick/Magick++.h>
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
32
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
33 unsigned int
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
34 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
35 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
36 return (static_cast<unsigned int> (static_cast<double> (quantum)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
37 / 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
38 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
39
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
40 octave_value_list
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
41 read_indexed_images (std::vector<Magick::Image>& imvec,
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
42 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
43 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
44 octave_value_list output;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
45
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
46 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
47 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
48 int nframes = frameidx.length ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
49
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
50 Magick::ImageType type = imvec[0].type ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
51
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
52 unsigned int mapsize = imvec[0].colorMapSize ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
53 int i = mapsize;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
54 unsigned int depth = 0;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
55 while (i >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
56 depth++;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
57 i = 0;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
58 depth--;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
59 while (depth >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
60 i++;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
61 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
62
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
63 switch (depth)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
64 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
65 case 1:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
66 case 2:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
67 case 4:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
68 case 8:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
69 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
70 uint8NDArray im = uint8NDArray (dim_vector (rows, columns, nframes));
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
71
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
72 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
73 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
74 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
75 const Magick::IndexPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
76 = imvec[frameidx(frame)].getConstIndexes ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
77 i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
78 for (int y = 0; y < rows; y++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
79 for (int x = 0; x < columns; x++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
80 im(y,x,frame) = static_cast<octave_uint8> (pix[i++]);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
81 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
82 im.chop_trailing_singletons ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
83 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
84 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
85 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
86
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
87 case 16:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
88 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
89 uint16NDArray im = uint16NDArray (dim_vector(rows, columns, nframes));
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
90 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
91 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
92 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
93 const Magick::IndexPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
94 = imvec[frameidx(frame)].getConstIndexes ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
95 i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
96 for (int y = 0; y < rows; y++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
97 for (int x = 0; x < columns; x++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
98 im(y,x,frame) = static_cast<octave_uint16> (pix[i++]);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
99 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
100 im.chop_trailing_singletons ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
101 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
102 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
103 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
104
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
105 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
106 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
107 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
108 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
109
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
110 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
111 Matrix alpha;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
112
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
113 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
114 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
115 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
116 #if 0
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
117 warning ("palettematte");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
118 Matrix map (mapsize, 3);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
119 Matrix alpha (mapsize, 1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
120 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
121 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
122 warning ("%d", i);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
123 Magick::ColorRGB c = imvec[0].colorMap (i);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
124 map(i,0) = c.red ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
125 map(i,1) = c.green ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
126 map(i,2) = c.blue ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
127 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
128 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
129 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
130 #endif
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
131
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
132 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
133 alpha = Matrix (0, 0);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
134 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
135 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
136 Magick::ColorRGB c = imvec[0].colorMap (i);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
137 map(i,0) = c.red ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
138 map(i,1) = c.green ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
139 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
140 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
141 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
142
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
143 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
144 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
145 return octave_value_list ();
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
146 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
147
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
148 if (wantalpha)
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
149 output(2) = alpha;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
150
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
151 output(1) = map;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
152
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
153 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
154 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
155
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
156 template <class T>
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
157 octave_value_list
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
158 read_images (const std::vector<Magick::Image>& imvec,
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
159 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
160 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
161 octave_value_list retval (3, Matrix ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
162
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
163 T im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
164
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
165 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
166 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
167 int nframes = frameidx.length ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
168
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
169 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
170 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
171 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
172 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
173 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
174 idim(3) = nframes;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
175
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
176 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
177
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
178 Magick::ImageType type = imvec[0].type ();
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 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
181 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
182 case Magick::BilevelType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
183 case Magick::GrayscaleType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
184 im = T(dim_vector (rows, columns, nframes));
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
185 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
186 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
187 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
188 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
189
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
190 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
191
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
192 for (int y = 0; y < rows; y++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
193 for (int x = 0; x < columns; x++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
194 im(y, x, frame) = scale_quantum_to_depth (pix[i++].red, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
195 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
196 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
197
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
198 case Magick::GrayscaleMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
199 idim(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
200 im = T (idim);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
201 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
202 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
203 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
204 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
205
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
206 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
207 idx(3) = frame;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
208
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
209 for (int y = 0; y < rows; y++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
210 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
211 idx(0) = y;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
212 for (int x = 0; x < columns; x++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
213 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
214 idx(1) = x;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
215 idx(2) = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
216 im(idx) = scale_quantum_to_depth (pix[i].red, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
217 idx(2) = 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
218 im(idx) = scale_quantum_to_depth (pix[i].opacity, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
219 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
220 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
221 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
222 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
223 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
224
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
225 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
226 case Magick::TrueColorType:
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
227 idim(2) = 3;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
228 im = T (idim);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
229 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
230 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
231 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
232 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
233
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
234 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
235 idx(3) = frame;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
236
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
237 for (int y = 0; y < rows; y++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
238 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
239 idx(0) = y;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
240 for (int x = 0; x < columns; x++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
241 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
242 idx(1) = x;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
243 idx(2) = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
244 im(idx) = scale_quantum_to_depth (pix[i].red, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
245 idx(2) = 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
246 im(idx) = scale_quantum_to_depth (pix[i].green, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
247 idx(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
248 im(idx) = scale_quantum_to_depth (pix[i].blue, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
249 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
250 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
251 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
252 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
253 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
254
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
255 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
256 case Magick::TrueColorMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
257 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
258 idim(2) = 4;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
259 im = T (idim);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
260 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
261 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
262 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
263 = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
264
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
265 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
266 idx(3) = frame;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
267
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
268 for (int y = 0; y < rows; y++)
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 idx(0) = y;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
271 for (int x = 0; x < columns; x++)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
272 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
273 idx(1) = x;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
274 idx(2) = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
275 im(idx) = scale_quantum_to_depth (pix[i].red, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
276 idx(2) = 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
277 im(idx) = scale_quantum_to_depth (pix[i].green, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
278 idx(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
279 im(idx) = scale_quantum_to_depth (pix[i].blue, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
280 idx(2) = 3;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
281 im(idx) = scale_quantum_to_depth (pix[i].opacity, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
282 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
283 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
284 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
285 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
286 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
287
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
288 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
289 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
290 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
291 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
292
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
293 im.chop_trailing_singletons ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
294
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
295 retval(0) = im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
296
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
297 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
298 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
299
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
300 DEFUN_DLD (__magick_read__, args, nargout,
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
301 "-*- texinfo -*-\n\
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
302 @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
303 @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
304 @deftypefnx{Function File} {[@var{m}, @var{colormap}, @var{alpha}] =} __magick_read__(@var{fname}, @var{index})\n\
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
305 Read images with ImageMagick++. In general you should not be using this function.\n\
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
306 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
307 @seealso{imread}\n\
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
308 @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
309 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
310 octave_value_list output;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
311
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
312 if (args.length() > 2 || args.length() < 1 || ! args(0).is_string ()
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
313 || 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
314 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
315 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
316 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
317 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
318
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
319 Array<int> frameidx;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
320
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
321 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
322 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
323 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
324 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
325 frameidx = Array<int> (1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
326 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
327 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
328
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
329 std::vector<Magick::Image> imvec;
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 try
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
332 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
333 // 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
334 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
335 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
336 catch (Magick::Warning& w)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
337 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
338 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
339 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
340 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
341 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
342 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
343 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
344 catch (Magick::Exception& e)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
345 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
346 error ("Magick++ exception: %s", e.what ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
347 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
348 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
349
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
350 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
351 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
352 frameidx(i) = frameidx(i) - 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
353
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
354 int nframes = imvec.size ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
355
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
356 if (frameidx(i) >= nframes || frameidx(i) < 0)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
357 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
358 error ("__magick_read__: invalid index vector");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
359 return output;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
360 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
361 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
362
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
363 Magick::ClassType klass = imvec[0].classType ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
364
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
365 if (klass == Magick::PseudoClass && nargout > 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
366 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
367 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
368 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
369 unsigned int depth = imvec[0].modulusDepth ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
370 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
371 while (depth >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
372 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
373 depth = 1 << i;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
374
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
375 switch (depth)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
376 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
377 case 1:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
378 output = read_images<boolNDArray> (imvec, frameidx, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
379 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
380
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
381 case 2:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
382 case 4:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
383 case 8:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
384 output = read_images<uint8NDArray> (imvec, frameidx, depth) ;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
385 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
386
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
387 case 16:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
388 output = read_images<uint16NDArray> (imvec, frameidx, depth);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
389 break;
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 case 32:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
392 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
393 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
394 error ("__magick_read__: image depths bigger than 16-bit not supported");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
395 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
396 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
397
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
398 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
399 }
7926
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 /*
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
402 ;;; Local Variables: ***
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
403 ;;; mode: C++ ***
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
404 ;;; End: ***
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
405 */