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