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