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