annotate src/DLD-FUNCTIONS/__magick_read__.cc @ 7933:54e414cc106b

style fixes
author John W. Eaton <jwe@octave.org>
date Wed, 16 Jul 2008 14:21:24 -0400
parents d75586531aac
children 6661387827d6
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
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
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);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
75
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
76 const Magick::IndexPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
77 = imvec[frameidx(frame)].getConstIndexes ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
78
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
79 i = 0;
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
80
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
81 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
82 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
83 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
84 }
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
85 im.chop_trailing_singletons ();
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
86 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
87 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
88 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
89
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
90 case 16:
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
91 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
92 uint16NDArray im = uint16NDArray (dim_vector(rows, columns, nframes));
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
93
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
94 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
95 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
96 imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
97
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
98 const Magick::IndexPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
99 = imvec[frameidx(frame)].getConstIndexes ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
100
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
101 i = 0;
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
102
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
103 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
104 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
105 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
106 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
107 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
108 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
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 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
113 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
114 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
115 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
116
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
117 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
118 Matrix alpha;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
119
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
120 switch (type)
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 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
123 #if 0
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
124 warning ("palettematte");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
125 Matrix map (mapsize, 3);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
126 Matrix alpha (mapsize, 1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
127 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
128 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
129 warning ("%d", i);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
130 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
131 map(i,0) = c.red ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
132 map(i,1) = c.green ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
133 map(i,2) = c.blue ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
134 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
135 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
136 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
137 #endif
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
138
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
139 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
140 alpha = Matrix (0, 0);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
141 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
142 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
143 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
144 map(i,0) = c.red ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
145 map(i,1) = c.green ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
146 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
147 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
148 break;
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 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
151 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
152 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
153 }
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 if (wantalpha)
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
156 output(2) = alpha;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
157
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
158 output(1) = map;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
159
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
160 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
161 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
162
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
163 template <class T>
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
164 octave_value_list
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
165 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
166 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
167 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
168 octave_value_list retval (3, Matrix ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
169
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
170 T im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
171
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
172 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
173 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
174 int nframes = frameidx.length ();
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 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
177 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
178 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
179 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
180 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
181 idim(3) = nframes;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
182
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
183 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
184
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
185 Magick::ImageType type = imvec[0].type ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
186
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
187 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
188 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
189 case Magick::BilevelType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
190 case Magick::GrayscaleType:
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
191 im = T (dim_vector (rows, columns, nframes));
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
192 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
193 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
194 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
195 = 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
196
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
197 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
198
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
199 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
200 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
201 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
202 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
203 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
204
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
205 case Magick::GrayscaleMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
206 idim(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
207 im = T (idim);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
208 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
209 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
210 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
211 = 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
212
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
213 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
214 idx(3) = frame;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
215
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
216 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
217 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
218 idx(0) = y;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
219 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
220 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
221 idx(1) = x;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
222 idx(2) = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
223 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
224 idx(2) = 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
225 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
226 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
227 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
228 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
229 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
230 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
231
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
232 case Magick::PaletteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
233 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
234 idim(2) = 3;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
235 im = T (idim);
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
236 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
237 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
238 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
239 = 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
240
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
241 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
242 idx(3) = frame;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
243
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
244 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
245 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
246 idx(0) = y;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
247 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
248 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
249 idx(1) = x;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
250 idx(2) = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
251 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
252 idx(2) = 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
253 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
254 idx(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
255 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
256 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
257 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
258 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
259 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
260 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
261
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
262 case Magick::PaletteMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
263 case Magick::TrueColorMatteType:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
264 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
265 idim(2) = 4;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
266 im = T (idim);
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
267 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
268 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
269 const Magick::PixelPacket *pix
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
270 = 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
271
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
272 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
273 idx(3) = frame;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
274
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
275 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
276 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
277 idx(0) = y;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
278 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
279 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
280 idx(1) = x;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
281 idx(2) = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
282 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
283 idx(2) = 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
284 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
285 idx(2) = 2;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
286 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
287 idx(2) = 3;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
288 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
289 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
290 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
291 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
292 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
293 break;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
294
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
295 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
296 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
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
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
300 im.chop_trailing_singletons ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
301
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
302 retval(0) = im;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
303
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
304 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
305 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
306
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
307 DEFUN_DLD (__magick_read__, args, nargout,
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
308 "-*- texinfo -*-\n\
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
309 @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
310 @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
311 @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
312 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
313 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
314 @seealso{imread}\n\
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
315 @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
316 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
317 octave_value_list output;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
318
7931
de26beacb20f imread.m: simplify; loadimage.m: deprecate
John W. Eaton <jwe@octave.org>
parents: 7926
diff changeset
319 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
320 || 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
321 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
322 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
323 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
324 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
325
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
326 Array<int> frameidx;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
327
7931
de26beacb20f imread.m: simplify; loadimage.m: deprecate
John W. Eaton <jwe@octave.org>
parents: 7926
diff changeset
328 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
329 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
330 else
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
331 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
332 frameidx = Array<int> (1);
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
333 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
334 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
335
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
336 std::vector<Magick::Image> imvec;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
337
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
338 try
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 // 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
341 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
342 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
343 catch (Magick::Warning& w)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
344 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
345 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
346 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
347 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
348 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
349 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
350 }
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
351 catch (Magick::Exception& e)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
352 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
353 error ("Magick++ exception: %s", e.what ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
354 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
355 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
356
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
357 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
358 {
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
359 frameidx(i) = frameidx(i) - 1;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
360
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
361 int nframes = imvec.size ();
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 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
364 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
365 error ("__magick_read__: invalid index vector");
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
366 return output;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
367 }
7925
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
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
370 Magick::ClassType klass = imvec[0].classType ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
371
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
372 if (klass == Magick::PseudoClass && nargout > 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
373 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
374 else
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 unsigned int depth = imvec[0].modulusDepth ();
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
377 int i = 0;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
378 while (depth >>= 1)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
379 i++;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
380 depth = 1 << i;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
381
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
382 switch (depth)
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
383 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
384 case 1:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
385 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
386 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
387
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
388 case 2:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
389 case 4:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
390 case 8:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
391 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
392 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
393
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
394 case 16:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
395 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
396 break;
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
397
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
398 case 32:
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
399 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
400 default:
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
401 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
402 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
403 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
404
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
405 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
406 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
407
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
408 /*
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
409 ;;; Local Variables: ***
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
410 ;;; mode: C++ ***
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
411 ;;; End: ***
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
412 */