Mercurial > octave-nkf
annotate libinterp/dldfcn/__magick_read__.cc @ 16996:a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
* __magick_read__.cc (read_indexed_images): turn function into template to
remove duplicated loop. Create alpha channel from alpha values colormap.
Skip reading of colormap unless requested. Use fortran_vec to fill the
image instead of indexing the Array<T> with a dim_vector which requires
multiple calls to dim_vector::operator() per iteration.
(__magick_read__): Always read the indexes of an indexed image and not the
RGB or grayscale values when no colormap is requested for output (Matlab
compatibility).
* imread.m: document that an indexed image is always read as such,
independently of the colormap having been requested or not.
* NEWS: add note on the change for reading indexed images.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 18 Jul 2013 01:52:09 +0100 |
parents | 7a69ab84b8c9 |
children | 95055b814d35 |
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 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
3 Copyright (C) 2013 Carnë Draug |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
4 Copyright (C) 2002-2012 Andy Adler |
7932 | 5 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
|
6 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
|
7 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
8 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
|
9 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 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
|
14 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
15 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
|
16 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
|
17 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
|
18 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
|
19 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
20 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
|
21 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
|
22 <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
|
23 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
24 */ |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
25 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
26 #ifdef HAVE_CONFIG_H |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
27 #include <config.h> |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
28 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
29 |
8054 | 30 #include <cmath> |
31 | |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
32 #include "file-stat.h" |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
33 #include "oct-env.h" |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
34 #include "oct-time.h" |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
35 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
36 #include "defun-dld.h" |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
37 #include "error.h" |
8054 | 38 #include "ov-struct.h" |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
39 |
16925
5c25f7ed080c
*__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents:
16901
diff
changeset
|
40 #include "gripes.h" |
5c25f7ed080c
*__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents:
16901
diff
changeset
|
41 |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
42 #ifdef HAVE_MAGICK |
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
43 |
9575
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9439
diff
changeset
|
44 #include <Magick++.h> |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
45 #include <clocale> |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
46 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
47 template <class T> |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
48 static octave_value_list |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
49 read_indexed_images (std::vector<Magick::Image>& imvec, |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
50 const Array<octave_idx_type>& frameidx, |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
51 const octave_idx_type nargout) |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
52 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
53 typedef typename T::element_type P; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
54 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
55 octave_value_list retval; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
56 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
57 const octave_idx_type nRows = imvec[0].baseRows (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
58 const octave_idx_type nCols = imvec[0].baseColumns (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
59 const octave_idx_type nFrames = frameidx.length (); |
8054 | 60 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
61 T img = T (dim_vector (nRows, nCols, 1, nFrames)); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
62 P* img_fvec = img.fortran_vec (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
63 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
64 // When reading PixelPackets from the Image Pixel Cache, they come in |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
65 // row major order. So we keep moving back and forth there so we can |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
66 // write the image in column major order. |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
67 octave_idx_type idx = 0; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
68 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
69 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
70 imvec[frameidx(frame)].getConstPixels (0, 0, nCols, nRows); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
71 |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
72 const Magick::IndexPacket *pix |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
73 = imvec[frameidx(frame)].getConstIndexes (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
74 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
75 for (octave_idx_type col = 0; col < nCols; col++) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
76 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
77 for (octave_idx_type row = 0; row < nRows; row++) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
78 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
79 img_fvec[idx++] = static_cast<P> (*pix); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
80 pix += nCols; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
81 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
82 pix -= nCols * nRows -1; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
83 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
84 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
85 retval(0) = octave_value (img); |
7933 | 86 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
87 // Do we need to get the colormap to interpret the image and alpha channel? |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
88 if (nargout > 1) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
89 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
90 const octave_idx_type mapsize = imvec[0].colorMapSize (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
91 Matrix cmap = Matrix (mapsize, 3); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
92 NDArray alpha; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
93 |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
94 // In theory, it should be possible for each frame of an image to |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
95 // have different colormaps but for Matlab compatibility, we only |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
96 // return the colormap of the first frame. |
10100
dd4d4b14b340
__magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents:
9575
diff
changeset
|
97 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
98 // only get alpha channel if it exists and was requested as output |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
99 if (imvec[0].matte () && nargout >= 3) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
100 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
101 Matrix amap = Matrix (mapsize, 1); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
102 for (octave_idx_type i = 0; i < mapsize; i++) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
103 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
104 const Magick::ColorRGB c = imvec[0].colorMap (i); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
105 cmap(i,0) = c.red (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
106 cmap(i,1) = c.green (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
107 cmap(i,2) = c.blue (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
108 amap(i,0) = c.alpha (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
109 } |
7933 | 110 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
111 alpha.resize (dim_vector (nRows, nCols, 1, nFrames)); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
112 const octave_idx_type nPixels = alpha.numel (); |
7933 | 113 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
114 double* alpha_fvec = alpha.fortran_vec (); |
7933 | 115 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
116 idx = 0; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
117 for (octave_idx_type pix = 0; pix < nPixels; pix++) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
118 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
119 // GraphicsMagick stores the alpha values inverted, i.e., |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
120 // 1 for transparent and 0 for opaque so we fix that here. |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
121 alpha_fvec[idx] = abs (amap(img(idx), 0) - 1); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
122 idx++; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
123 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
124 } |
10100
dd4d4b14b340
__magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents:
9575
diff
changeset
|
125 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
126 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
127 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
128 for (octave_idx_type i = 0; i < mapsize; i++) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
129 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
130 const Magick::ColorRGB c = imvec[0].colorMap (i); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
131 cmap(i,0) = c.red (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
132 cmap(i,1) = c.green (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
133 cmap(i,2) = c.blue (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
134 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
135 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
136 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
137 retval(1) = cmap; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
138 retval(2) = alpha; |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
139 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
140 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
141 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
|
142 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
143 |
10193
1a4074e277fe
undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
144 template <class T> |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
145 octave_value_list |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
146 read_images (const std::vector<Magick::Image>& imvec, |
8053 | 147 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
|
148 { |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
149 typedef typename T::element_type P; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
150 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
151 octave_value_list retval (3, Matrix ()); |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
152 |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
153 T im; |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
154 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
155 const int rows = imvec[0].baseRows (); |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
156 const int columns = imvec[0].baseColumns (); |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
157 const int nframes = frameidx.length (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
158 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
159 dim_vector idim = dim_vector (rows, columns, 1, nframes); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
160 |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
161 Magick::ImageType type = imvec[0].type (); |
14173
47a5e29ecc0b
Allow QuantumDepth=32 installations of Magick++ (Bug #35229)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
162 const int divisor = ((uint64_t (1) << QuantumDepth) - 1) / |
47a5e29ecc0b
Allow QuantumDepth=32 installations of Magick++ (Bug #35229)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
163 ((uint64_t (1) << depth) - 1); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
164 |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
165 switch (type) |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
166 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
167 case Magick::BilevelType: // Monochrome bi-level image |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
168 case Magick::GrayscaleType: // Grayscale image |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
169 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
170 im = T (idim); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
171 P *vec = im.fortran_vec (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
172 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
173 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
|
174 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
175 const Magick::PixelPacket *pix |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
176 = 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
|
177 |
10298
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
178 P *rbuf = vec; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
179 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
|
180 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
181 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
|
182 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
183 *rbuf = pix->red / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
184 pix++; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
185 rbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
186 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
187 rbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
188 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
189 |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
190 // Next frame. |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
191 vec += rows * columns * idim(2); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
192 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
193 } |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
194 break; |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
195 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
196 case Magick::GrayscaleMatteType: // Grayscale image with opacity |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
197 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
198 idim(2) = 2; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
199 im = T (idim); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
200 P *vec = im.fortran_vec (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
201 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
202 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
|
203 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
204 const Magick::PixelPacket *pix |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
205 = 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
|
206 |
10298
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
207 P *rbuf = vec; |
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
208 P *obuf = vec + rows * columns; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
209 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
|
210 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
211 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
|
212 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
213 *rbuf = pix->red / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
214 *obuf = pix->opacity / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
215 pix++; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
216 rbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
217 obuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
218 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
219 rbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
220 obuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
221 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
222 |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
223 // Next frame. |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
224 vec += rows * columns * idim(2); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
225 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
226 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
227 break; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
228 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
229 case Magick::PaletteType: // Indexed color (palette) image |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
230 case Magick::TrueColorType: // Truecolor image |
10295
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 idim(2) = 3; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
233 im = T (idim); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
234 P *vec = im.fortran_vec (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
235 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
236 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
|
237 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
238 const Magick::PixelPacket *pix |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
239 = 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
|
240 |
10298
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
241 P *rbuf = vec; |
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
242 P *gbuf = vec + rows * columns; |
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
243 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
|
244 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
|
245 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
246 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
|
247 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
248 *rbuf = pix->red / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
249 *gbuf = pix->green / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
250 *bbuf = pix->blue / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
251 pix++; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
252 rbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
253 gbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
254 bbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
255 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
256 rbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
257 gbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
258 bbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
259 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
260 |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
261 // Next frame. |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
262 vec += rows * columns * idim(2); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
263 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
264 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
265 break; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
266 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
267 case Magick::PaletteMatteType: // Indexed color (palette) image with opacity |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
268 case Magick::TrueColorMatteType: // Truecolor image with opacity |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
269 case Magick::ColorSeparationType: // Cyan/Yellow/Magenta/Black (CYMK) image |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
270 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
271 idim(2) = 4; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
272 im = T (idim); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
273 P *vec = im.fortran_vec (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
274 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
275 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
|
276 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
277 const Magick::PixelPacket *pix |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
278 = 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
|
279 |
10298
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
280 P *rbuf = vec; |
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
281 P *gbuf = vec + rows * columns; |
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
282 P *bbuf = vec + rows * columns * 2; |
2be9b7e71f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10295
diff
changeset
|
283 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
|
284 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
|
285 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
286 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
|
287 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
288 *rbuf = pix->red / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
289 *gbuf = pix->green / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
290 *bbuf = pix->blue / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
291 *obuf = pix->opacity / divisor; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
292 pix++; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
293 rbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
294 gbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
295 bbuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
296 obuf += rows; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
297 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
298 rbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
299 gbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
300 bbuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
301 obuf -= rows * columns - 1; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
302 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
303 |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
304 // Next frame. |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
305 vec += rows * columns * idim(2); |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
306 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
307 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
308 break; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
309 |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
310 default: |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
311 error ("__magick_read__: undefined Magick++ image type"); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
312 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
|
313 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
314 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
315 retval(0) = im; |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
316 |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
317 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
|
318 } |
7974 | 319 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
320 void static |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
321 read_file (const std::string filename, std::vector<Magick::Image>& imvec) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
322 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
323 try |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
324 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
325 // Read a file into vector of image objects |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
326 Magick::readImages (&imvec, filename); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
327 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
328 catch (Magick::Warning& w) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
329 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
330 warning ("Magick++ warning: %s", w.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
331 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
332 catch (Magick::ErrorCoder& e) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
333 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
334 // FIXME: there's a WarningCoder and ErrorCoder. Shouldn't this |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
335 // exception cause an error? |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
336 warning ("Magick++ coder error: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
337 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
338 catch (Magick::Exception& e) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
339 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
340 error ("Magick++ exception: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
341 error_state = 1; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
342 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
343 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
344 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
345 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
346 static void |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
347 maybe_initialize_magick (void) |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
348 { |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
349 static bool initialized = false; |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
350 |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
351 if (! initialized) |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
352 { |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
353 // Save locale as GraphicsMagick might change this (fixed in |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
354 // GraphicsMagick since version 1.3.13 released on December 24, 2011) |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
355 const char *static_locale = setlocale (LC_ALL, NULL); |
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
356 const std::string locale (static_locale); |
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
357 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
358 const std::string program_name = octave_env::get_program_invocation_name (); |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
359 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
|
360 |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
361 // Restore locale from before GraphicsMagick initialisation |
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
362 setlocale (LC_ALL, locale.c_str ()); |
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
363 |
11036
169f59f626d3
Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents:
11035
diff
changeset
|
364 if (QuantumDepth < 32) |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
365 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
366 warning ("your version of %s limits images to %d bits per pixel", |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
367 MagickPackageName, QuantumDepth); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
368 } |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
369 initialized = true; |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
370 } |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
371 } |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
372 #endif |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
373 |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
374 DEFUN_DLD (__magick_read__, args, nargout, |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
375 "-*- texinfo -*-\n\ |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
376 @deftypefn {Loadable Function} {[@var{img}, @var{map}, @var{alpha}] =} __magick_read__ (@var{fname}, @var{options})\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
377 Read image with GraphicsMagick or ImageMagick.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
378 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
379 This is a private internal function not intended for direct use. Instead\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
380 use @code{imread}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
381 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
382 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
383 @end deftypefn") |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
384 { |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
385 octave_value_list output; |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
386 |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
387 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
388 gripe_disabled_feature ("imread", "Image IO"); |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
389 #else |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
390 |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
391 maybe_initialize_magick (); |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
392 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
393 if (args.length () != 2 || ! args(0).is_string ()) |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
394 { |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
395 print_usage (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
396 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
|
397 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
398 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
399 const octave_map options = args(1).map_value (); |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
400 if (error_state) |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
401 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
402 error ("__magick_read__: OPTIONS must be a struct"); |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
403 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
404 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
405 std::vector<Magick::Image> imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
406 read_file (args(0).string_value (), imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
407 if (error_state) |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
408 { |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
409 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
|
410 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
411 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
412 // Prepare an Array with the indexes for the requested frames. |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
413 const octave_idx_type nFrames = imvec.size (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
414 Array<octave_idx_type> frameidx; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
415 const octave_value indexes = options.getfield ("index")(0); |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
416 if (indexes.is_string () && indexes.string_value () == "all") |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
417 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
418 frameidx.resize (dim_vector (1, nFrames)); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
419 for (octave_idx_type i = 0; i < nFrames; i++) |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
420 { |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
421 frameidx(i) = i; |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
422 } |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
423 } |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
424 else |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
425 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
426 frameidx = indexes.int_vector_value (); |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
427 if (error_state) |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
428 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
429 error ("__magick_read__: invalid value for Index/Frame"); |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
430 } |
16989
7a69ab84b8c9
__magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents:
16988
diff
changeset
|
431 // Fix indexes from base 1 to base 0, and at the same time, make |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
432 // sure none of the indexes is outside the range of image number. |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
433 const octave_idx_type n = frameidx.nelem (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
434 for (octave_idx_type i = 0; i < n; i++) |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
435 { |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
436 frameidx(i)--; |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
437 if (frameidx(i) < 0 || frameidx(i) > nFrames - 1) |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
438 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
439 error ("imread: index/frames specified are outside the number of images"); |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
440 return output; |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
441 } |
8053 | 442 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
443 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
444 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
445 const Magick::ClassType klass = imvec[0].classType (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
446 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
447 // PseudoClass: |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
448 // Image is composed of pixels which specify an index in a color palette. |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
449 if (klass == Magick::PseudoClass) |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
450 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
451 const octave_idx_type mapsize = imvec[0].colorMapSize (); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
452 if (mapsize <= 256) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
453 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
454 output = read_indexed_images <uint8NDArray> (imvec, frameidx, nargout); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
455 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
456 else if (mapsize <= 65536) |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
457 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
458 output = read_indexed_images <uint16NDArray> (imvec, frameidx, nargout); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
459 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
460 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
461 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
462 error ("imread: indexed images with depths greater than 16-bit are not supported"); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
463 return output; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
464 } |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
465 } |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
466 // DirectClass: |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
467 // Image is composed of pixels which represent literal color values. |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
468 else if (klass == Magick::DirectClass) |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
469 { |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
470 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
|
471 if (depth > 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10100
diff
changeset
|
472 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10100
diff
changeset
|
473 --depth; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10100
diff
changeset
|
474 int i = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10100
diff
changeset
|
475 while (depth >>= 1) |
9439
0a696f8aa434
determine correct image bitwidth in __magick_read__.cc
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
9436
diff
changeset
|
476 i++; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10100
diff
changeset
|
477 depth = 1 << i; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10100
diff
changeset
|
478 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
479 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
480 switch (depth) |
8053 | 481 { |
482 case 1: | |
10193
1a4074e277fe
undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
483 output = read_images<boolNDArray> (imvec, frameidx, depth); |
8053 | 484 break; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
485 |
8053 | 486 case 2: |
487 case 4: | |
488 case 8: | |
10193
1a4074e277fe
undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
489 output = read_images<uint8NDArray> (imvec, frameidx, depth) ; |
8053 | 490 break; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
491 |
8053 | 492 case 16: |
10193
1a4074e277fe
undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
493 output = read_images<uint16NDArray> (imvec, frameidx, depth); |
8053 | 494 break; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
495 |
8053 | 496 case 32: |
497 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
|
498 default: |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
499 error ("__magick_read__: image depths greater than 16-bit are not supported"); |
8053 | 500 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
501 } |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
502 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
503 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
504 error ("imread: unsupported image class type"); |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
505 } |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
506 |
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
507 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
508 return output; |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
509 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
510 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
511 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
512 ## No test needed for internal helper function. |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
513 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
514 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
515 |
7974 | 516 #ifdef HAVE_MAGICK |
517 | |
8054 | 518 static void |
519 encode_bool_image (std::vector<Magick::Image>& imvec, const octave_value& img) | |
7974 | 520 { |
8054 | 521 unsigned int nframes = 1; |
522 boolNDArray m = img.bool_array_value (); | |
523 | |
524 dim_vector dsizes = m.dims (); | |
525 if (dsizes.length () == 4) | |
526 nframes = dsizes(3); | |
527 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
528 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1)); |
8054 | 529 |
530 octave_idx_type rows = m.rows (); | |
531 octave_idx_type columns = m.columns (); | |
532 | |
533 for (unsigned int ii = 0; ii < nframes; ii++) | |
534 { | |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
535 Magick::Image im (Magick::Geometry (columns, rows), "black"); |
8054 | 536 im.classType (Magick::DirectClass); |
537 im.depth (1); | |
538 | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
539 for (int y = 0; y < columns; y++) |
8054 | 540 { |
541 idx(1) = y; | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
542 |
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
543 for (int x = 0; x < rows; x++) |
8054 | 544 { |
545 if (nframes > 1) | |
546 { | |
547 idx(2) = 0; | |
548 idx(3) = ii; | |
549 } | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
550 |
8054 | 551 idx(0) = x; |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
552 |
8054 | 553 if (m(idx)) |
554 im.pixelColor (y, x, "white"); | |
555 } | |
556 } | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
557 |
11034
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
558 im.quantizeColorSpace (Magick::GRAYColorspace); |
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
559 im.quantizeColors (2); |
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
560 im.quantize (); |
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
561 |
8054 | 562 imvec.push_back (im); |
563 } | |
564 } | |
565 | |
566 template <class T> | |
567 static void | |
568 encode_uint_image (std::vector<Magick::Image>& imvec, | |
569 const octave_value& img, | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
570 const bool has_map) |
8054 | 571 { |
8520
715f6cd8d5e7
__magick_read__.cc (encode_uint_image): initialize bitdepth
Soren Hauberg <hauberg@gmail.com>
parents:
8165
diff
changeset
|
572 unsigned int bitdepth = 0; |
8054 | 573 T m; |
574 | |
575 if (img.is_uint8_type ()) | |
576 { | |
577 bitdepth = 8; | |
578 m = img.uint8_array_value (); | |
579 } | |
580 else if (img.is_uint16_type ()) | |
581 { | |
582 bitdepth = 16; | |
583 m = img.uint16_array_value (); | |
584 } | |
585 else | |
586 error ("__magick_write__: invalid image class"); | |
587 | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
588 const dim_vector dsizes = m.dims (); |
8054 | 589 unsigned int nframes = 1; |
590 if (dsizes.length () == 4) | |
591 nframes = dsizes(3); | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
592 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
593 const bool is_color = ((dsizes.length () > 2) && (dsizes(2) > 2)); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
594 const bool has_alpha = (dsizes.length () > 2 && (dsizes(2) == 2 || dsizes(2) == 4)); |
8054 | 595 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
596 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1)); |
8054 | 597 octave_idx_type rows = m.rows (); |
598 octave_idx_type columns = m.columns (); | |
8090 | 599 |
13020
58d704d3283c
Fix ambigous call to int pow (int, unsigned int&)
Carlo de Falco <kingcrimson@tiscali.it>
parents:
11590
diff
changeset
|
600 unsigned int div_factor = (1 << bitdepth) - 1; |
8054 | 601 |
602 for (unsigned int ii = 0; ii < nframes; ii++) | |
603 { | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
604 Magick::Image im (Magick::Geometry (columns, rows), "black"); |
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
605 |
8054 | 606 im.depth (bitdepth); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
607 |
8054 | 608 if (has_map) |
609 im.classType (Magick::PseudoClass); | |
610 else | |
611 im.classType (Magick::DirectClass); | |
612 | |
613 if (is_color) | |
614 { | |
615 if (has_alpha) | |
616 im.type (Magick::TrueColorMatteType); | |
617 else | |
618 im.type (Magick::TrueColorType); | |
7974 | 619 |
8054 | 620 Magick::ColorRGB c; |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
621 |
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
622 for (int y = 0; y < columns; y++) |
8054 | 623 { |
624 idx(1) = y; | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
625 |
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
626 for (int x = 0; x < rows; x++) |
8054 | 627 { |
628 idx(0) = x; | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
629 |
8054 | 630 if (nframes > 1) |
631 idx(3) = ii; | |
632 | |
633 idx(2) = 0; | |
634 c.red (static_cast<double>(m(idx)) / div_factor); | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
635 |
8054 | 636 idx(2) = 1; |
637 c.green (static_cast<double>(m(idx)) / div_factor); | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
638 |
8054 | 639 idx(2) = 2; |
640 c.blue (static_cast<double>(m(idx)) / div_factor); | |
641 | |
642 if (has_alpha) | |
643 { | |
644 idx(2) = 3; | |
645 c.alpha (static_cast<double>(m(idx)) / div_factor); | |
646 } | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
647 |
8054 | 648 im.pixelColor (y, x, c); |
649 } | |
650 } | |
651 } | |
652 else | |
653 { | |
654 if (has_alpha) | |
655 im.type (Magick::GrayscaleMatteType); | |
656 else | |
657 im.type (Magick::GrayscaleType); | |
658 | |
659 Magick::ColorGray c; | |
660 | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
661 for (int y = 0; y < columns; y++) |
8054 | 662 { |
663 idx(1) = y; | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
664 |
8054 | 665 for (int x=0; x < rows; x++) |
666 { | |
667 idx(0) = x; | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
668 |
8054 | 669 if (nframes > 1) |
670 { | |
671 idx(2) = 0; | |
672 idx(3) = ii; | |
673 } | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
674 |
8054 | 675 if (has_alpha) |
676 { | |
677 idx(2) = 1; | |
678 c.alpha (static_cast<double>(m(idx)) / div_factor); | |
679 idx(2) = 0; | |
680 } | |
681 | |
682 c.shade (static_cast<double>(m(idx)) / div_factor); | |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
683 |
8054 | 684 im.pixelColor (y, x, c); |
685 } | |
686 } | |
11034
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
687 |
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
688 im.quantizeColorSpace (Magick::GRAYColorspace); |
13020
58d704d3283c
Fix ambigous call to int pow (int, unsigned int&)
Carlo de Falco <kingcrimson@tiscali.it>
parents:
11590
diff
changeset
|
689 im.quantizeColors (1 << bitdepth); |
11034
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
690 im.quantize (); |
8054 | 691 } |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
692 |
8054 | 693 imvec.push_back (im); |
694 } | |
695 } | |
696 | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
697 // FIXME: this will be needed to write indexed images |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
698 //static void |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
699 //encode_map (std::vector<Magick::Image>& imvec, const NDArray& cmap) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
700 //{ |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
701 // unsigned int mapsize = cmap.dim1 (); |
8054 | 702 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
703 // for (size_t fnum = 0; fnum < imvec.size (); fnum++) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
704 // { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
705 // imvec[fnum].colorMapSize (mapsize); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
706 // imvec[fnum].type (Magick::PaletteType); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
707 // } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
708 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
709 // for (unsigned int ii = 0; ii < mapsize; ii++) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
710 // { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
711 // Magick::ColorRGB c (cmap(ii,0), cmap(ii,1), cmap(ii,2)); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
712 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
713 // // FIXME -- is this case needed? |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
714 // if (cmap.dim2 () == 4) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
715 // c.alpha (cmap(ii,3)); |
8054 | 716 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
717 // try |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
718 // { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
719 // for_each (imvec.begin (), imvec.end (), |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
720 // Magick::colorMapImage (ii, c)); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
721 // } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
722 // catch (Magick::Warning& w) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
723 // { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
724 // warning ("Magick++ warning: %s", w.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
725 // } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
726 // catch (Magick::ErrorCoder& e) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
727 // { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
728 // warning ("Magick++ coder error: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
729 // } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
730 // catch (Magick::Exception& e) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
731 // { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
732 // error ("Magick++ exception: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
733 // } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
734 // } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
735 //} |
9275
86f475d5e7d1
imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents:
9274
diff
changeset
|
736 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
737 void static |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
738 write_file (const std::string filename, |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
739 const std::string ext, |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
740 std::vector<Magick::Image>& imvec) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
741 { |
7974 | 742 try |
743 { | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
744 Magick::writeImages (imvec.begin (), imvec.end (), ext + ":" + filename); |
7974 | 745 } |
746 catch (Magick::Warning& w) | |
747 { | |
748 warning ("Magick++ warning: %s", w.what ()); | |
749 } | |
750 catch (Magick::ErrorCoder& e) | |
751 { | |
752 warning ("Magick++ coder error: %s", e.what ()); | |
753 } | |
754 catch (Magick::Exception& e) | |
755 { | |
756 error ("Magick++ exception: %s", e.what ()); | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
757 error_state = 1; |
7974 | 758 } |
759 } | |
760 | |
761 #endif | |
762 | |
9436
5302df15ad76
__magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents:
9434
diff
changeset
|
763 DEFUN_DLD (__magick_write__, args, , |
7974 | 764 "-*- texinfo -*-\n\ |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
765 @deftypefn {Loadable Function} {} __magick_write__ (@var{fname}, @var{fmt}, @var{img}, @var{map}, @var{options})\n\ |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
766 Write image with GraphicsMagick or ImageMagick.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
767 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
768 This is a private internal function not intended for direct use. Instead\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
769 use @code{imwrite}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
770 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
771 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
7974 | 772 @end deftypefn") |
773 { | |
774 octave_value_list retval; | |
775 | |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
776 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
777 gripe_disabled_feature ("imwrite", "Image IO"); |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
778 #else |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
779 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
780 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
781 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
782 if (args.length () != 5 || ! args(0).is_string () || ! args(1).is_string ()) |
7974 | 783 { |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
784 print_usage (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
785 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
786 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
787 const std::string filename = args(0).string_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
788 const std::string ext = args(1).string_value (); |
7974 | 789 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
790 const octave_map options = args(4).map_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
791 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
792 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
793 error ("__magick_write__: OPTIONS must be a struct"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
794 } |
7974 | 795 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
796 const octave_value img = args(2); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
797 const Matrix cmap = args(3).matrix_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
798 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
799 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
800 error ("__magick_write__: invalid IMG or MAP"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
801 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
802 const bool is_indexed = ! cmap.is_empty (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
803 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
804 // Create vector with the images to write |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
805 std::vector<Magick::Image> imvec; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
806 if (img.is_bool_type ()) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
807 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
808 encode_bool_image (imvec, img); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
809 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
810 else if (img.is_uint8_type ()) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
811 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
812 encode_uint_image<uint8NDArray> (imvec, img, is_indexed); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
813 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
814 else if (img.is_uint16_type ()) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
815 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
816 encode_uint_image<uint16NDArray> (imvec, img, is_indexed); |
7974 | 817 } |
818 else | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
819 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
820 error ("__magick_write__: image type not supported"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
821 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
822 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
823 const int nframes = imvec.size (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
824 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
825 // Add colormap to image |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
826 if (is_indexed) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
827 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
828 // FIXME: this should be implemented. At the moment, imwrite is doing the |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
829 // conversion in case of indexed images. |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
830 error ("__magick_write__: direct saving of indexed images not currently supported; use ind2rgb and save converted image"); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
831 // encode_map (imvec, cmap); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
832 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
833 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
834 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
835 // Set quality. |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
836 // FIXME What happens when we try to set with formats that do not support it? |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
837 const unsigned int quality = options.getfield ("quality")(0).int_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
838 for (int i = 0; i < nframes; i++) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
839 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
840 imvec[i].quality (quality); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
841 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
842 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
843 // Finally, save the file. |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
844 // If writemode is set to append, read the image first, append to it, |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
845 // and then save it. But even if set to append, make sure anything was |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
846 // read at all. |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
847 const std::string writemode = options.getfield ("writemode")(0).string_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
848 std::vector<Magick::Image> ini_imvec; |
16989
7a69ab84b8c9
__magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents:
16988
diff
changeset
|
849 if (writemode == "append" && file_stat (filename).exists ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
850 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
851 read_file (filename, ini_imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
852 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
853 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
854 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
855 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
856 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
857 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
858 if (ini_imvec.size () > 0) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
859 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
860 ini_imvec.insert (ini_imvec.end (), imvec.begin (), imvec.end ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
861 write_file (filename, ext, ini_imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
862 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
863 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
864 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
865 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
866 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
867 else |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
868 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
869 write_file (filename, ext, imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
870 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
871 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
872 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
873 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
874 } |
7974 | 875 |
876 #endif | |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
877 return retval; |
7974 | 878 } |
879 | |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
880 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
881 ## No test needed for internal helper function. |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
882 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
883 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
884 |
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
|
885 #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
|
886 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
887 template<class T> |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
888 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
889 magick_to_octave_value (const T magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
890 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
891 return octave_value (magick); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
892 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
893 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
894 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
895 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
|
896 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
897 switch (magick) |
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::LSBEndian: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
900 return octave_value ("little-endian"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
901 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
902 case Magick::MSBEndian: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
903 return octave_value ("big-endian"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
904 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
905 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
906 return octave_value ("undefined"); |
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 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
909 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
910 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
911 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
|
912 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
913 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
914 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
915 case Magick::PixelsPerInchResolution: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
916 return octave_value ("pixels per inch"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
917 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
918 case Magick::PixelsPerCentimeterResolution: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
919 return octave_value ("pixels per centimeter"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
920 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
921 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
922 return octave_value ("undefined"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
923 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
924 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
925 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
926 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
927 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
|
928 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
929 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
930 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
931 case Magick::BilevelType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
932 case Magick::GrayscaleType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
933 case Magick::GrayscaleMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
934 return octave_value ("grayscale"); |
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 case Magick::PaletteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
937 case Magick::PaletteMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
938 return octave_value ("indexed"); |
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 case Magick::TrueColorType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
941 case Magick::TrueColorMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
942 case Magick::ColorSeparationType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
943 return octave_value ("truecolor"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
944 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
945 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
946 return octave_value ("undefined"); |
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 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
949 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
950 // 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
|
951 // 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
|
952 #define GET_PARAM(NAME, OUTNAME) \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
953 try \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
954 { \ |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
955 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
|
956 } \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
957 catch (Magick::Warning& w) \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
958 { \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
959 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
960 |
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
|
961 #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
|
962 |
9436
5302df15ad76
__magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents:
9434
diff
changeset
|
963 DEFUN_DLD (__magick_finfo__, args, , |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
964 "-*- texinfo -*-\n\ |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
965 @deftypefn {Loadable Function} {} __magick_finfo__ (@var{fname})\n\ |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
966 Read image information with GraphicsMagick or ImageMagick.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
967 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
968 This is a private internal function not intended for direct use. Instead\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
969 use @code{imfinfo}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
970 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
971 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
972 @end deftypefn") |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
973 { |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
974 octave_value retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
975 |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
976 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
977 gripe_disabled_feature ("imfinfo", "Image IO"); |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
978 #else |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
979 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
980 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
981 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
982 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
|
983 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
984 print_usage (); |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
985 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
986 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
987 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
988 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
|
989 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
990 try |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
991 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
992 // Read the file. |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
993 std::vector<Magick::Image> imvec; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
994 Magick::readImages (&imvec, args(0).string_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
995 int nframes = imvec.size (); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
996 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
997 // 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
|
998 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
999 static const char *fields[] = |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1000 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1001 "Filename", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1002 "FileModDate", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1003 "FileSize", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1004 "Height", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1005 "Width", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1006 "BitDepth", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1007 "Format", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1008 "LongFormat", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1009 "XResolution", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1010 "YResolution", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1011 "TotalColors", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1012 "TileName", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1013 "AnimationDelay", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1014 "AnimationIterations", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1015 "ByteOrder", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1016 "Gamma", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1017 "Matte", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1018 "ModulusDepth", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1019 "Quality", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1020 "QuantizeColors", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1021 "ResolutionUnits", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1022 "ColorType", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1023 "View", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1024 0 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1025 }; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1026 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16543
diff
changeset
|
1027 octave_map info (dim_vector (nframes, 1), string_vector (fields)); |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1028 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1029 file_stat fs (filename); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1030 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1031 std::string filetime; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1032 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1033 if (fs) |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1034 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1035 octave_localtime mtime = fs.mtime (); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1036 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1037 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
|
1038 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1039 else |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1040 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1041 std::string msg = fs.error (); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1042 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14173
diff
changeset
|
1043 error ("imfinfo: error reading '%s': %s", |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1044 filename.c_str (), msg.c_str ()); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1045 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1046 return retval; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1047 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1048 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1049 // 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
|
1050 // 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
|
1051 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
|
1052 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1053 Magick::Image im = imvec[frame]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1054 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1055 // Add file name and timestamp. |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1056 info.contents ("Filename")(frame,0) = filename; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1057 info.contents ("FileModDate")(frame,0) = filetime; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1058 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1059 // 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
|
1060 GET_PARAM (fileSize, "FileSize") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1061 GET_PARAM (rows, "Height") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1062 GET_PARAM (columns, "Width") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1063 GET_PARAM (depth, "BitDepth") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1064 GET_PARAM (magick, "Format") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1065 GET_PARAM (format, "LongFormat") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1066 GET_PARAM (xResolution, "XResolution") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1067 GET_PARAM (yResolution, "YResolution") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1068 GET_PARAM (totalColors, "TotalColors") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1069 GET_PARAM (tileName, "TileName") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1070 GET_PARAM (animationDelay, "AnimationDelay") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1071 GET_PARAM (animationIterations, "AnimationIterations") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1072 GET_PARAM (endian, "ByteOrder") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1073 GET_PARAM (gamma, "Gamma") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1074 GET_PARAM (matte, "Matte") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1075 GET_PARAM (modulusDepth, "ModulusDepth") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1076 GET_PARAM (quality, "Quality") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1077 GET_PARAM (quantizeColors, "QuantizeColors") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1078 GET_PARAM (resolutionUnits, "ResolutionUnits") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1079 GET_PARAM (type, "ColorType") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1080 GET_PARAM (view, "View") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1081 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1082 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1083 retval = octave_value (info); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1084 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1085 catch (Magick::Warning& w) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1086 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1087 warning ("Magick++ warning: %s", w.what ()); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1088 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1089 catch (Magick::ErrorCoder& e) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1090 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1091 warning ("Magick++ coder error: %s", e.what ()); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1092 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1093 catch (Magick::Exception& e) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1094 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1095 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
|
1096 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1097 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1098 #endif |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1099 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1100 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1101 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1102 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1103 ## No test needed for internal helper function. |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1104 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1105 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1106 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1107 #undef GET_PARAM |
11035
8a6b7947f618
Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents:
11034
diff
changeset
|
1108 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1109 DEFUN_DLD (__magick_formats__, args, , |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1110 "-*- texinfo -*-\n\ |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1111 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\ |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1112 Fill formats info with GraphicsMagick CoderInfo.\n\ |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1113 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1114 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1115 @end deftypefn") |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1116 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1117 octave_value retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1118 #ifndef HAVE_MAGICK |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1119 gripe_disabled_feature ("imformats", "Image IO"); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1120 #else |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1121 if (args.length () != 1 || ! args (0).is_map ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1122 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1123 print_usage (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1124 return retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1125 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1126 octave_map formats = args(0).map_value (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1127 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1128 maybe_initialize_magick (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1129 for (octave_idx_type idx = 0; idx < formats.numel (); idx++) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1130 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1131 try |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1132 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1133 octave_scalar_map fmt = formats.checkelem (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1134 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1135 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1136 fmt.setfield ("description", octave_value (coder.description ())); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1137 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1138 // default for read and write is a function handle. If we can't |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1139 // read or write them, them set it to an empty value |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1140 if (! coder.isReadable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1141 fmt.setfield ("read", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1142 if (! coder.isWritable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1143 fmt.setfield ("write", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1144 formats.fast_elem_insert (idx, fmt); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1145 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1146 catch (Magick::Exception& e) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1147 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1148 // Exception here are missing formats. So we remove the format |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1149 // from the structure and reduce idx. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1150 formats.delete_elements (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1151 idx--; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1152 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1153 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1154 retval = formats; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1155 #endif |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1156 return retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1157 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1158 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1159 /* |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1160 ## No test needed for internal helper function. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1161 %!assert (1) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1162 */ |