annotate libinterp/dldfcn/__magick_read__.cc @ 17149:73a3c1580974

Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689) * __magick_read_.cc (read_images): check original color type from PNG image attribute because GraphicsMagick changes it for optimization.
author Carnë Draug <carandraug@octave.org>
date Fri, 02 Aug 2013 19:05:42 +0100
parents 35a1bd41aa02
children 46805642048f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
1 /*
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
2
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
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
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
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
30 #include <cmath>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
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
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
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
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
47 static std::map<std::string, octave_idx_type>
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
48 calculate_region (const octave_scalar_map& options)
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
49 {
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
50 std::map<std::string, octave_idx_type> region;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
51 const Cell pixel_region = options.getfield ("region").cell_value ();
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
52
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
53 // Subtract 1 to account for 0 indexing.
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
54 const Range rows = pixel_region (0).range_value ();
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
55 const Range cols = pixel_region (1).range_value ();
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
56 region["row_start"] = rows.base () -1;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
57 region["col_start"] = cols.base () -1;
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
58 region["row_end"] = rows.max () -1;
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
59 region["col_end"] = cols.max () -1;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
60
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
61 // Length of the area to load into the Image Pixel Cache. We use max and
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
62 // min to account for cases where last element of range is the range limit.
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
63 region["row_cache"] = region["row_end"] - region["row_start"] +1;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
64 region["col_cache"] = region["col_end"] - region["col_start"] +1;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
65
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
66 // How much we have to shift in the memory when doing the loops.
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
67 region["row_shift"] = region["col_cache"] * rows.inc ();
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
68 region["col_shift"] = region["col_cache"] *
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
69 (region["row_cache"] + rows.inc () -1) - cols.inc ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
70
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
71 // The actual height and width of the output image
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
72 region["row_out"] = rows.nelem ();
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
73 region["col_out"] = cols.nelem ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
74
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
75 return region;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
76 }
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
77
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
78 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
79 static octave_value_list
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
80 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
81 const Array<octave_idx_type>& frameidx,
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
82 const octave_idx_type nargout,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
83 const octave_scalar_map& options)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
84 {
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
85 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
86
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
87 octave_value_list retval (3, Matrix ());
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
88
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
89 std::map<std::string, octave_idx_type> region = calculate_region (options);
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
90 const octave_idx_type nFrames = frameidx.length ();
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
91 const octave_idx_type nRows = region["row_out"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
92 const octave_idx_type nCols = region["col_out"];
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
93
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
94 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
95 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
96
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
97 const octave_idx_type row_start = region["row_start"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
98 const octave_idx_type col_start = region["col_start"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
99 const octave_idx_type row_shift = region["row_shift"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
100 const octave_idx_type col_shift = region["col_shift"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
101 const octave_idx_type row_cache = region["row_cache"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
102 const octave_idx_type col_cache = region["col_cache"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
103
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
104 // 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
105 // 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
106 // 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
107 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
108 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
109 {
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
110 imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
111 col_cache, row_cache);
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
112
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
113 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
114 = imvec[frameidx(frame)].getConstIndexes ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
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 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
117 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
118 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
119 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
120 img_fvec[idx++] = static_cast<P> (*pix);
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
121 pix += row_shift;
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
122 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
123 pix -= col_shift;
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
124 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
125 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
126 retval(0) = octave_value (img);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
127
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
128 // 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
129 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
130 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
131 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
132 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
133
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
134 // 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
135 // 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
136 // 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
137
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
138 // 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
139 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
140 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
141 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
142 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
143 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
144 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
145 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
146 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
147 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
148 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
149 }
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
150
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
151 NDArray alpha (dim_vector (nRows, nCols, 1, nFrames));
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
152 const octave_idx_type nPixels = alpha.numel ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
153
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
154 double* alpha_fvec = alpha.fortran_vec ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
155
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
156 idx = 0;
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
157 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
158 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
159 // 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
160 // 1 for transparent and 0 for opaque so we fix that here.
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
161 alpha_fvec[idx] = 1 - amap(img(idx), 0);
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
162 idx++;
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
163 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
164 retval(2) = alpha;
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
165 }
10100
dd4d4b14b340 __magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
166
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
167 else
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
168 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
169 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
170 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
171 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
172 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
173 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
174 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
175 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
176 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
177
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
178 retval(1) = cmap;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
179 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
180
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
181 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
182 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
183
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
184 // This function is highly repetitive, a bunch of for loops that are
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
185 // very similar to account for different image types. They are different
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
186 // enough that trying to reduce the copy and paste would decrease its
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
187 // readability too much.
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
188 template <class T>
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
189 octave_value_list
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
190 read_images (std::vector<Magick::Image>& imvec,
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
191 const Array<octave_idx_type>& frameidx,
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
192 const octave_idx_type nargout,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
193 const octave_scalar_map& options)
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
194 {
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
195 typedef typename T::element_type P;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
196
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
197 octave_value_list retval (3, Matrix ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
198
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
199 std::map<std::string, octave_idx_type> region = calculate_region (options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
200 const octave_idx_type nFrames = frameidx.length ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
201 const octave_idx_type nRows = region["row_out"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
202 const octave_idx_type nCols = region["col_out"];
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
203 T img;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
204
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
205 const octave_idx_type row_start = region["row_start"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
206 const octave_idx_type col_start = region["col_start"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
207 const octave_idx_type row_shift = region["row_shift"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
208 const octave_idx_type col_shift = region["col_shift"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
209 const octave_idx_type row_cache = region["row_cache"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
210 const octave_idx_type col_cache = region["col_cache"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
211
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
212 // GraphicsMagick (GM) keeps the image values in memory using whatever
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
213 // QuantumDepth it was built with independently of the original image
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
214 // bitdepth. Basically this means that if GM was built with quantum 16
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
215 // all values are scaled in the uint16 range. If the original image
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
216 // had an 8 bit depth, we need to rescale it for that range.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
217 // However, if the image had a bitdepth of 32, then we will be returning
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
218 // a floating point image. In this case, the values need to be rescaled
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
219 // for the range [0 1] (this is what Matlab has documented on the page
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
220 // about image types but in some cases seems to be doing something else.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
221 // See bug #39249).
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
222 // Finally, we must do the division ourselves (set a divisor) instead of
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
223 // using quantumOperator for the cases where we will be returning floating
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
224 // point and want things in the range [0 1]. This is the same reason why
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
225 // the divisor is of type double.
17149
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
226 // uint64_t is used in expression because default 32-bit value overflows
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
227 // when depth() is 32.
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
228 // TODO in the next release of GraphicsMagick, MaxRGB should be replaced
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
229 // with QuantumRange since MaxRGB is already deprecated in ImageMagick.
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
230 const double divisor = imvec[0].depth () == 32 ?
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
231 std::numeric_limits<uint32_t>::max () :
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
232 MaxRGB / ((uint64_t (1) << imvec[0].depth ()) - 1);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
233
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
234 // FIXME: this workaround should probably be fixed in GM by creating a
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
235 // new ImageType BilevelMatteType
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
236 // Despite what GM documentation claims, opacity is not only on the types
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
237 // with Matte on the name. It is possible that an image is completely
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
238 // black (1 color), and have a second channel set for transparency (2nd
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
239 // color). Its type will be bilevel since there is no BilevelMatte. The
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
240 // only way to check for this seems to be by checking matte ().
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
241 Magick::ImageType type = imvec[0].type ();
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
242 if (type == Magick::BilevelType && imvec[0].matte ())
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
243 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
244 type = Magick::GrayscaleMatteType;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
245 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
246
17149
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
247 // FIXME: ImageType is the type being used to represent the image in memory
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
248 // by GM. The real type may be different (see among others bug #36820). For
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
249 // example, a png file where all channels are equal may report being
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
250 // grayscale or even bilevel. But we must always return the real image in
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
251 // file. In some cases, the original image attributes are stored in the
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
252 // attributes but this is undocumented. This should be fixed in GM so that
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
253 // a method such as original_type returns an actual Magick::ImageType
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
254 if (imvec[0].magick () == "PNG")
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
255 {
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
256 // These values come from libpng, not GM:
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
257 // Grayscale = 0
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
258 // Palette = 2 + 1
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
259 // RGB = 2
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
260 // RGB + Alpha = 2 + 4
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
261 // Grayscale + Alpha = 4
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
262 // We won't bother with case 3 (palette) since those should be
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
263 // read by the function to read indexed images
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
264 const std::string type_str = imvec[0].attribute ("PNG:IHDR.color-type-orig");
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
265 if (type_str == "0")
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
266 {
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
267 type = Magick::GrayscaleType;
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
268 }
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
269 else if (type_str == "2")
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
270 {
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
271 type = Magick::TrueColorType;
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
272 }
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
273 else if (type_str == "6")
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
274 {
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
275 type = Magick::TrueColorMatteType;
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
276 }
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
277 else if (type_str == "4")
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
278 {
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
279 type = Magick::GrayscaleMatteType;
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
280 }
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
281 }
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
282
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
283 // If the alpha channel was not requested, treat images as if
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
284 // it doesn't exist.
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
285 if (nargout < 3)
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
286 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
287 switch (type)
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
288 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
289 case Magick::GrayscaleMatteType:
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
290 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
291 type = Magick::GrayscaleType;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
292 break;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
293 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
294 case Magick::PaletteMatteType:
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
295 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
296 type = Magick::PaletteType;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
297 break;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
298 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
299 case Magick::TrueColorMatteType:
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
300 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
301 type = Magick::TrueColorType;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
302 break;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
303 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
304 case Magick::ColorSeparationMatteType:
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
305 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
306 type = Magick::ColorSeparationType;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
307 break;
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
308 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
309 default:
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
310 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
311 // do nothing, other than silencing warnings about enumeration
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
312 // values not being handled in switch.
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
313 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
314 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
315 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
316
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
317 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
318 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
319 case Magick::BilevelType: // Monochrome bi-level image
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
320 case Magick::GrayscaleType: // Grayscale image
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
321 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
322 img = T (dim_vector (nRows, nCols, 1, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
323 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
324
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
325 octave_idx_type idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
326 for (octave_idx_type frame = 0; frame < nFrames; frame++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
327 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
328 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
329 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
330 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
331
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
332 for (octave_idx_type col = 0; col < nCols; col++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
333 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
334 for (octave_idx_type row = 0; row < nRows; row++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
335 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
336 img_fvec[idx++] = pix->red / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
337 pix += row_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
338 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
339 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
340 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
341 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
342 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
343 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
344
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
345 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
346 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
347 img = T (dim_vector (nRows, nCols, 1, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
348 T alpha (dim_vector (nRows, nCols, 1, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
349 P *img_fvec = img.fortran_vec ();
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
350 P *a_fvec = alpha.fortran_vec ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
351
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
352 octave_idx_type idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
353 for (octave_idx_type frame = 0; frame < nFrames; frame++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
354 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
355 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
356 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
357 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
358
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
359 for (octave_idx_type col = 0; col < nCols; col++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
360 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
361 for (octave_idx_type row = 0; row < nRows; row++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
362 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
363 img_fvec[idx] = pix->red / divisor;
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
364 a_fvec[idx] = (MaxRGB - pix->opacity) / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
365 pix += row_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
366 idx++;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
367 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
368 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
369 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
370 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
371 retval(2) = alpha;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
372 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
373 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
374
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
375 case Magick::PaletteType: // Indexed color (palette) image
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
376 case Magick::TrueColorType: // Truecolor image
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
377 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
378 img = T (dim_vector (nRows, nCols, 3, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
379 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
380
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
381 for (octave_idx_type frame = 0; frame < nFrames; frame++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
382 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
383 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
384 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
385 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
386
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
387 octave_idx_type idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
388 img_fvec += nRows * nCols * frame;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
389 P *rbuf = img_fvec;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
390 P *gbuf = img_fvec + nRows * nCols;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
391 P *bbuf = img_fvec + nRows * nCols * 2;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
392
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
393 for (octave_idx_type col = 0; col < nCols; col++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
394 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
395 for (octave_idx_type row = 0; row < nRows; row++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
396 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
397 rbuf[idx] = pix->red / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
398 gbuf[idx] = pix->green / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
399 bbuf[idx] = pix->blue / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
400 pix += row_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
401 idx++;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
402 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
403 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
404 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
405 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
406 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
407 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
408
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
409 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
410 case Magick::TrueColorMatteType: // Truecolor image with opacity
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
411 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
412 img = T (dim_vector (nRows, nCols, 3, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
413 T alpha (dim_vector (nRows, nCols, 1, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
414 P *img_fvec = img.fortran_vec ();
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
415 P *a_fvec = alpha.fortran_vec ();
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
416
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
417 // Unlike the index for the other channels, this one won't need
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
418 // to be reset on each frame since it's a separate matrix.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
419 octave_idx_type a_idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
420 for (octave_idx_type frame = 0; frame < nFrames; frame++)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
421 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
422 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
423 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
424 col_cache, row_cache);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
425
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
426 octave_idx_type idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
427 img_fvec += nRows * nCols * frame;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
428 P *rbuf = img_fvec;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
429 P *gbuf = img_fvec + nRows * nCols;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
430 P *bbuf = img_fvec + nRows * nCols * 2;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
431
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
432 for (octave_idx_type col = 0; col < nCols; col++)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
433 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
434 for (octave_idx_type row = 0; row < nRows; row++)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
435 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
436 rbuf[idx] = pix->red / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
437 gbuf[idx] = pix->green / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
438 bbuf[idx] = pix->blue / divisor;
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
439 a_fvec[a_idx++] = (MaxRGB - pix->opacity) / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
440 pix += row_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
441 idx++;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
442 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
443 pix -= col_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
444 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
445 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
446 retval(2) = alpha;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
447 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
448 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
449
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
450 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
451 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
452 img = T (dim_vector (nRows, nCols, 4, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
453 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
454
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
455 for (octave_idx_type frame = 0; frame < nFrames; frame++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
456 {
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
457 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
458 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
459 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
460
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
461 octave_idx_type idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
462 img_fvec += nRows * nCols * frame;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
463 P *cbuf = img_fvec;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
464 P *mbuf = img_fvec + nRows * nCols;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
465 P *ybuf = img_fvec + nRows * nCols * 2;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
466 P *kbuf = img_fvec + nRows * nCols * 3;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
467
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
468 for (octave_idx_type col = 0; col < nCols; col++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
469 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
470 for (octave_idx_type row = 0; row < nRows; row++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
471 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
472 cbuf[idx] = pix->red / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
473 mbuf[idx] = pix->green / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
474 ybuf[idx] = pix->blue / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
475 kbuf[idx] = pix->opacity / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
476 pix += row_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
477 idx++;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
478 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
479 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
480 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
481 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
482 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
483 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
484
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
485 // Cyan, magenta, yellow, and black with alpha (opacity) channel
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
486 case Magick::ColorSeparationMatteType:
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
487 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
488 img = T (dim_vector (nRows, nCols, 4, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
489 T alpha (dim_vector (nRows, nCols, 1, nFrames));
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
490 P *img_fvec = img.fortran_vec ();
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
491 P *a_fvec = alpha.fortran_vec ();
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
492
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
493 // Unlike the index for the other channels, this one won't need
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
494 // to be reset on each frame since it's a separate matrix.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
495 octave_idx_type a_idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
496 for (octave_idx_type frame = 0; frame < nFrames; frame++)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
497 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
498 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
499 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
500 col_cache, row_cache);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
501 // Note that for CMYKColorspace + matte (CMYKA), the opacity is
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
502 // stored in the assocated IndexPacket.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
503 const Magick::IndexPacket *apix
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
504 = imvec[frameidx(frame)].getConstIndexes ();
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
505
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
506 octave_idx_type idx = 0;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
507 img_fvec += nRows * nCols * frame;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
508 P *cbuf = img_fvec;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
509 P *mbuf = img_fvec + nRows * nCols;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
510 P *ybuf = img_fvec + nRows * nCols * 2;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
511 P *kbuf = img_fvec + nRows * nCols * 3;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
512
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
513 for (octave_idx_type col = 0; col < nCols; col++)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
514 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
515 for (octave_idx_type row = 0; row < nRows; row++)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
516 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
517 cbuf[idx] = pix->red / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
518 mbuf[idx] = pix->green / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
519 ybuf[idx] = pix->blue / divisor;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
520 kbuf[idx] = pix->opacity / divisor;
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
521 a_fvec[a_idx++] = (MaxRGB - *apix) / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
522 pix += row_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
523 idx++;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
524 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
525 pix -= col_shift;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
526 }
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
527 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
528 retval(2) = alpha;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
529 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
530 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
531
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
532 default:
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
533 error ("__magick_read__: unknown Magick++ image type");
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
534 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
535 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
536
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
537 retval(0) = img;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
538 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
539 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
540
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
541
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
542 void static
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
543 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
544 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
545 try
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
546 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
547 // Read a file into vector of image objects
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
548 Magick::readImages (&imvec, filename);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
549 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
550 catch (Magick::Warning& w)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
551 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
552 warning ("Magick++ warning: %s", w.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
553 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
554 catch (Magick::ErrorCoder& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
555 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
556 // FIXME: there's a WarningCoder and ErrorCoder. Shouldn't this
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
557 // exception cause an error?
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
558 warning ("Magick++ coder error: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
559 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
560 catch (Magick::Exception& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
561 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
562 error ("Magick++ exception: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
563 error_state = 1;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
564 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
565 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
566
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
567
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
568 static void
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
569 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
570 {
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
571 static bool initialized = false;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
572
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
573 if (! initialized)
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
574 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
575 // Save locale as GraphicsMagick might change this (fixed in
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
576 // 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
577 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
578 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
579
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
580 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
581 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
582
10739
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
583 // 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
584 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
585
11036
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
586 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
587 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
588 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
589 MagickPackageName, QuantumDepth);
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
590 }
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
591 initialized = true;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
592 }
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
593 }
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
594 #endif
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
595
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
596 DEFUN_DLD (__magick_read__, args, nargout,
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
597 "-*- texinfo -*-\n\
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
598 @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
599 Read image with GraphicsMagick or ImageMagick.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
600 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
601 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
602 use @code{imread}.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
603 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
604 @seealso{imfinfo, imformats, imread, imwrite}\n\
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
605 @end deftypefn")
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
606 {
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
607 octave_value_list output;
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
608
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
609 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
610 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
611 #else
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
612
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
613 maybe_initialize_magick ();
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
614
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
615 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
616 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
617 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
618 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
619 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
620
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
621 const octave_scalar_map options = args(1).scalar_map_value ();
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
622 if (error_state)
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
623 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
624 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
625 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
626
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
627 std::vector<Magick::Image> imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
628 read_file (args(0).string_value (), imvec);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
629 if (error_state)
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
630 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
631 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
632 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
633
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
634 // 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
635 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
636 Array<octave_idx_type> frameidx;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
637 const octave_value indexes = options.getfield ("index");
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
638 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
639 {
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
640 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
641 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
642 {
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
643 frameidx(i) = i;
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
644 }
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
645 }
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
646 else
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
647 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
648 frameidx = indexes.int_vector_value ();
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
649 if (error_state)
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
650 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
651 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
652 }
16989
7a69ab84b8c9 __magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents: 16988
diff changeset
653 // 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
654 // 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
655 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
656 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
657 {
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
658 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
659 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
660 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
661 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
662 return output;
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
663 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
664 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
665 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
666
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
667 const Magick::ClassType klass = imvec[0].classType ();
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
668 const octave_idx_type depth = imvec[0].depth ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
669
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
670 // Magick::ClassType
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
671 // PseudoClass:
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
672 // Image is composed of pixels which specify an index in a color palette.
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
673 // DirectClass:
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
674 // Image is composed of pixels which represent literal color values.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
675
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
676 // FIXME: GraphicsMagick does not really distinguishes between indexed and
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
677 // normal images. After reading a file, it decides itself the optimal
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
678 // way to store the image in memory, independently of the how the
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
679 // image was stored in the file. That's what ClassType returns. While
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
680 // it seems to match the original file most of the times, this is
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
681 // not necessarily true all the times. See
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
682 // https://sourceforge.net/mailarchive/message.php?msg_id=31180507
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
683 // A grayscale jpeg image reports being indexed even though the JPEG
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
684 // format has no support for indexed images. So we can skip at least
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
685 // for that.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
686
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
687 if (klass == Magick::PseudoClass && imvec[0].magick () != "JPEG")
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
688 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
689 if (depth <= 1)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
690 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
691 output = read_indexed_images <boolNDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
692 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
693 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
694 else if (depth <= 8)
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
695 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
696 output = read_indexed_images <uint8NDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
697 nargout, options);
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
698 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
699 else if (depth <= 16)
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
700 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
701 output = read_indexed_images <uint16NDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
702 nargout, options);
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
703 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
704 else
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
705 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
706 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
707 return output;
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
708 }
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
709 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
710
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
711 else
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
712 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
713 if (depth <= 1)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
714 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
715 output = read_images<boolNDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
716 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
717 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
718 else if (depth <= 8)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
719 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
720 output = read_images<uint8NDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
721 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
722 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
723 else if (depth <= 16)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
724 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
725 output = read_images<uint16NDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
726 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
727 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
728 else if (depth <= 32)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
729 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
730 output = read_images<FloatNDArray> (imvec, frameidx,
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
731 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
732 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
733 else
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
734 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
735 error ("imread: reading of images with %i-bit depth is not supported",
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
736 depth);
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
737 }
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
738 }
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
739
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
740 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
741 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
742 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
743
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
744 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
745 ## 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
746 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
747 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
748
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
749 #ifdef HAVE_MAGICK
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
750
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
751 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
752 encode_bool_image (std::vector<Magick::Image>& imvec, const octave_value& img)
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
753 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
754 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
755 boolNDArray m = img.bool_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
756
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
757 dim_vector dsizes = m.dims ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
758 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
759 nframes = dsizes(3);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
760
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
761 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
762
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
763 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
764 octave_idx_type columns = m.columns ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
765
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
766 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
767 {
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
768 Magick::Image im (Magick::Geometry (columns, rows), "black");
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
769 im.classType (Magick::DirectClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
770 im.depth (1);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
771
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
772 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
773 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
774 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
775
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
776 for (int x = 0; x < rows; x++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
777 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
778 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
779 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
780 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
781 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
782 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
783
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
784 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
785
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
786 if (m(idx))
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
787 im.pixelColor (y, x, "white");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
788 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
789 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
790
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
791 im.quantizeColorSpace (Magick::GRAYColorspace);
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
792 im.quantizeColors (2);
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
793 im.quantize ();
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
794
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
795 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
796 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
797 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
798
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
799 template <class T>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
800 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
801 encode_uint_image (std::vector<Magick::Image>& imvec,
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
802 const octave_value& img,
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
803 const bool has_map)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
804 {
8520
715f6cd8d5e7 __magick_read__.cc (encode_uint_image): initialize bitdepth
Soren Hauberg <hauberg@gmail.com>
parents: 8165
diff changeset
805 unsigned int bitdepth = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
806 T m;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
807
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
808 if (img.is_uint8_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
809 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
810 bitdepth = 8;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
811 m = img.uint8_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
812 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
813 else if (img.is_uint16_type ())
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
814 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
815 bitdepth = 16;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
816 m = img.uint16_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
817 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
818 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
819 error ("__magick_write__: invalid image class");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
820
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
821 const dim_vector dsizes = m.dims ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
822 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
823 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
824 nframes = dsizes(3);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
825
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
826 const bool is_color = ((dsizes.length () > 2) && (dsizes(2) > 2));
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
827 const bool has_alpha = (dsizes.length () > 2 && (dsizes(2) == 2 || dsizes(2) == 4));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
828
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
829 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
830 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
831 octave_idx_type columns = m.columns ();
8090
3cc1ca1b1576 MSVC compilation fix
Michael Goffioul
parents: 8054
diff changeset
832
13020
58d704d3283c Fix ambigous call to int pow (int, unsigned int&)
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11590
diff changeset
833 unsigned int div_factor = (1 << bitdepth) - 1;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
834
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
835 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
836 {
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
837 Magick::Image im (Magick::Geometry (columns, rows), "black");
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
838
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
839 im.depth (bitdepth);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
840
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
841 if (has_map)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
842 im.classType (Magick::PseudoClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
843 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
844 im.classType (Magick::DirectClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
845
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
846 if (is_color)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
847 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
848 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
849 im.type (Magick::TrueColorMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
850 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
851 im.type (Magick::TrueColorType);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
852
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
853 Magick::ColorRGB c;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
854
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
855 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
856 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
857 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
858
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
859 for (int x = 0; x < rows; x++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
860 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
861 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
862
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
863 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
864 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
865
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
866 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
867 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
868
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
869 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
870 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
871
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
872 idx(2) = 2;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
873 c.blue (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
874
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
875 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
876 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
877 idx(2) = 3;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
878 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
879 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
880
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
881 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
882 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
883 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
884 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
885 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
886 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
887 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
888 im.type (Magick::GrayscaleMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
889 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
890 im.type (Magick::GrayscaleType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
891
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
892 Magick::ColorGray c;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
893
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
894 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
895 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
896 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
897
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
898 for (int x=0; x < rows; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
899 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
900 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
901
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
902 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
903 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
904 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
905 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
906 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
907
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
908 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
909 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
910 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
911 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
912 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
913 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
914
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
915 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
916
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
917 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
918 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
919 }
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
920
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
921 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
922 im.quantizeColors (1 << bitdepth);
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
923 im.quantize ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
924 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
925
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
926 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
927 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
928 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
929
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
930 // FIXME: this will be needed to write indexed images
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
931 //static void
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
932 //encode_map (std::vector<Magick::Image>& imvec, const NDArray& cmap)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
933 //{
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
934 // unsigned int mapsize = cmap.dim1 ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
935
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
936 // for (size_t fnum = 0; fnum < imvec.size (); fnum++)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
937 // {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
938 // imvec[fnum].colorMapSize (mapsize);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
939 // imvec[fnum].type (Magick::PaletteType);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
940 // }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
941
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
942 // for (unsigned int ii = 0; ii < mapsize; ii++)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
943 // {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
944 // 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
945
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
946 // // FIXME -- is this case needed?
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
947 // if (cmap.dim2 () == 4)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
948 // c.alpha (cmap(ii,3));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
949
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
950 // try
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
951 // {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
952 // for_each (imvec.begin (), imvec.end (),
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
953 // Magick::colorMapImage (ii, c));
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
954 // }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
955 // catch (Magick::Warning& w)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
956 // {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
957 // warning ("Magick++ warning: %s", w.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
958 // }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
959 // catch (Magick::ErrorCoder& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
960 // {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
961 // warning ("Magick++ coder error: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
962 // }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
963 // catch (Magick::Exception& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
964 // {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
965 // error ("Magick++ exception: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
966 // }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
967 // }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
968 //}
9275
86f475d5e7d1 imwrite.m: convert indexed images to RGB before calling __magick_write__
John W. Eaton <jwe@octave.org>
parents: 9274
diff changeset
969
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
970 void static
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
971 write_file (const std::string filename,
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
972 const std::string ext,
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
973 std::vector<Magick::Image>& imvec)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
974 {
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
975 try
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
976 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
977 Magick::writeImages (imvec.begin (), imvec.end (), ext + ":" + filename);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
978 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
979 catch (Magick::Warning& w)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
980 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
981 warning ("Magick++ warning: %s", w.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
982 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
983 catch (Magick::ErrorCoder& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
984 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
985 warning ("Magick++ coder error: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
986 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
987 catch (Magick::Exception& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
988 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
989 error ("Magick++ exception: %s", e.what ());
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
990 error_state = 1;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
991 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
992 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
993
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
994 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
995
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
996 DEFUN_DLD (__magick_write__, args, ,
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
997 "-*- texinfo -*-\n\
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
998 @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
999 Write image with GraphicsMagick or ImageMagick.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1000 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1001 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
1002 use @code{imwrite}.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1003 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1004 @seealso{imfinfo, imformats, imread, imwrite}\n\
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1005 @end deftypefn")
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1006 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1007 octave_value_list retval;
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1008
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1009 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1010 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
1011 #else
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1012
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1013 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1014
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1015 if (args.length () != 5 || ! args(0).is_string () || ! args(1).is_string ())
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1016 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1017 print_usage ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1018 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1019 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1020 const std::string filename = args(0).string_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1021 const std::string ext = args(1).string_value ();
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1022
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1023 const octave_map options = args(4).map_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1024 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1025 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1026 error ("__magick_write__: OPTIONS must be a struct");
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1027 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1028
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1029 const octave_value img = args(2);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1030 const Matrix cmap = args(3).matrix_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1031 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1032 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1033 error ("__magick_write__: invalid IMG or MAP");
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1034 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1035 const bool is_indexed = ! cmap.is_empty ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1036
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1037 // Create vector with the images to write
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1038 std::vector<Magick::Image> imvec;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1039 if (img.is_bool_type ())
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1040 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1041 encode_bool_image (imvec, img);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1042 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1043 else if (img.is_uint8_type ())
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1044 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1045 encode_uint_image<uint8NDArray> (imvec, img, is_indexed);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1046 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1047 else if (img.is_uint16_type ())
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1048 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1049 encode_uint_image<uint16NDArray> (imvec, img, is_indexed);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1050 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1051 else
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1052 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1053 error ("__magick_write__: image type not supported");
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1054 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1055 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1056 const int nframes = imvec.size ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1057
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1058 // Add colormap to image
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1059 if (is_indexed)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1060 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1061 // 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
1062 // conversion in case of indexed images.
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1063 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
1064 // encode_map (imvec, cmap);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1065 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1066 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1067
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1068 // Set quality.
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1069 // 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
1070 const unsigned int quality = options.getfield ("quality")(0).int_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1071 for (int i = 0; i < nframes; i++)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1072 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1073 imvec[i].quality (quality);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1074 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1075
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1076 // Finally, save the file.
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1077 // 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
1078 // 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
1079 // read at all.
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1080 const std::string writemode = options.getfield ("writemode")(0).string_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1081 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
1082 if (writemode == "append" && file_stat (filename).exists ())
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1083 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1084 read_file (filename, ini_imvec);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1085 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1086 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1087 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1088 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1089 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1090
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1091 if (ini_imvec.size () > 0)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1092 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1093 ini_imvec.insert (ini_imvec.end (), imvec.begin (), imvec.end ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1094 write_file (filename, ext, ini_imvec);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1095 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1096 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1097 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1098 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1099 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1100 else
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1101 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1102 write_file (filename, ext, imvec);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1103 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1104 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1105 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1106 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1107 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1108
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1109 #endif
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1110 return retval;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1111 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1112
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1113 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1114 ## 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
1115 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1116 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1117
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
1118 #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
1119
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1120 template<class T>
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1121 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1122 magick_to_octave_value (const T magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1123 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1124 return octave_value (magick);
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1125 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1126
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1127 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1128 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
1129 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1130 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1131 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1132 case Magick::LSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1133 return octave_value ("little-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1134
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1135 case Magick::MSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1136 return octave_value ("big-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1137
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1138 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1139 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1140 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1141 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1142
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1143 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1144 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
1145 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1146 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1147 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1148 case Magick::PixelsPerInchResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1149 return octave_value ("pixels per inch");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1150
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1151 case Magick::PixelsPerCentimeterResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1152 return octave_value ("pixels per centimeter");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1153
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1154 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1155 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1156 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1157 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1158
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1159 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1160 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
1161 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1162 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1163 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1164 case Magick::BilevelType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1165 case Magick::GrayscaleType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1166 case Magick::GrayscaleMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1167 return octave_value ("grayscale");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1168
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1169 case Magick::PaletteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1170 case Magick::PaletteMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1171 return octave_value ("indexed");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1172
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1173 case Magick::TrueColorType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1174 case Magick::TrueColorMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1175 case Magick::ColorSeparationType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1176 return octave_value ("truecolor");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1177
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1178 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1179 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1180 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1181 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1182
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1183 // 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
1184 // 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
1185 #define GET_PARAM(NAME, OUTNAME) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1186 try \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1187 { \
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1188 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
1189 } \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1190 catch (Magick::Warning& w) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1191 { \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1192 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1193
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
1194 #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
1195
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
1196 DEFUN_DLD (__magick_finfo__, args, ,
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1197 "-*- 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
1198 @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
1199 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
1200 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1201 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
1202 use @code{imfinfo}.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1203 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1204 @seealso{imfinfo, imformats, imread, imwrite}\n\
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1205 @end deftypefn")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1206 {
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1207 octave_value retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1208
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1209 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1210 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
1211 #else
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1212
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1213 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1214
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1215 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
1216 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1217 print_usage ();
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1218 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1219 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1220
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1221 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
1222
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1223 try
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1224 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1225 // Read the file.
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1226 std::vector<Magick::Image> imvec;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1227 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
1228 int nframes = imvec.size ();
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1229
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1230 // 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
1231
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1232 static const char *fields[] =
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1233 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1234 "Filename",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1235 "FileModDate",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1236 "FileSize",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1237 "Height",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1238 "Width",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1239 "BitDepth",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1240 "Format",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1241 "LongFormat",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1242 "XResolution",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1243 "YResolution",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1244 "TotalColors",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1245 "TileName",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1246 "AnimationDelay",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1247 "AnimationIterations",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1248 "ByteOrder",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1249 "Gamma",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1250 "Matte",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1251 "ModulusDepth",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1252 "Quality",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1253 "QuantizeColors",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1254 "ResolutionUnits",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1255 "ColorType",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1256 "View",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1257 0
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1258 };
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1259
16871
5e30b1c950b8 Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents: 16543
diff changeset
1260 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
1261
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1262 file_stat fs (filename);
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1263
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1264 std::string filetime;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1265
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1266 if (fs)
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1267 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1268 octave_localtime mtime = fs.mtime ();
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1269
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1270 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
1271 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1272 else
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1273 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1274 std::string msg = fs.error ();
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1275
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14173
diff changeset
1276 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
1277 filename.c_str (), msg.c_str ());
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1278
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1279 return retval;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1280 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1281
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1282 // 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
1283 // 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
1284 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
1285 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1286 Magick::Image im = imvec[frame];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1287
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1288 // Add file name and timestamp.
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1289 info.contents ("Filename")(frame,0) = filename;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1290 info.contents ("FileModDate")(frame,0) = filetime;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1291
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1292 // 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
1293 GET_PARAM (fileSize, "FileSize")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1294 GET_PARAM (rows, "Height")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1295 GET_PARAM (columns, "Width")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1296 GET_PARAM (depth, "BitDepth")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1297 GET_PARAM (magick, "Format")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1298 GET_PARAM (format, "LongFormat")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1299 GET_PARAM (xResolution, "XResolution")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1300 GET_PARAM (yResolution, "YResolution")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1301 GET_PARAM (totalColors, "TotalColors")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1302 GET_PARAM (tileName, "TileName")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1303 GET_PARAM (animationDelay, "AnimationDelay")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1304 GET_PARAM (animationIterations, "AnimationIterations")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1305 GET_PARAM (endian, "ByteOrder")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1306 GET_PARAM (gamma, "Gamma")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1307 GET_PARAM (matte, "Matte")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1308 GET_PARAM (modulusDepth, "ModulusDepth")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1309 GET_PARAM (quality, "Quality")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1310 GET_PARAM (quantizeColors, "QuantizeColors")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1311 GET_PARAM (resolutionUnits, "ResolutionUnits")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1312 GET_PARAM (type, "ColorType")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1313 GET_PARAM (view, "View")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1314 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1315
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1316 retval = octave_value (info);
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1317 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1318 catch (Magick::Warning& w)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1319 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1320 warning ("Magick++ warning: %s", w.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1321 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1322 catch (Magick::ErrorCoder& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1323 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1324 warning ("Magick++ coder error: %s", e.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1325 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1326 catch (Magick::Exception& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1327 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1328 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
1329 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1330 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1331 #endif
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1332 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1333 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1334
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1335 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1336 ## 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
1337 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1338 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1339
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1340 #undef GET_PARAM
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1341
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1342 DEFUN_DLD (__magick_formats__, args, ,
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1343 "-*- texinfo -*-\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1344 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1345 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
1346 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1347 @seealso{imfinfo, imformats, imread, imwrite}\n\
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1348 @end deftypefn")
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1349 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1350 octave_value retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1351 #ifndef HAVE_MAGICK
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1352 gripe_disabled_feature ("imformats", "Image IO");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1353 #else
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1354 if (args.length () != 1 || ! args (0).is_map ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1355 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1356 print_usage ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1357 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1358 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1359 octave_map formats = args(0).map_value ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1360
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1361 maybe_initialize_magick ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1362 for (octave_idx_type idx = 0; idx < formats.numel (); idx++)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1363 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1364 try
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1365 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1366 octave_scalar_map fmt = formats.checkelem (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1367 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1368
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1369 fmt.setfield ("description", octave_value (coder.description ()));
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1370 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1371 // 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
1372 // read or write them, them set it to an empty value
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1373 if (! coder.isReadable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1374 fmt.setfield ("read", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1375 if (! coder.isWritable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1376 fmt.setfield ("write", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1377 formats.fast_elem_insert (idx, fmt);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1378 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1379 catch (Magick::Exception& e)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1380 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1381 // Exception here are missing formats. So we remove the format
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1382 // from the structure and reduce idx.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1383 formats.delete_elements (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1384 idx--;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1385 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1386 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1387 retval = formats;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1388 #endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1389 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1390 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1391
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1392 /*
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1393 ## No test needed for internal helper function.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1394 %!assert (1)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1395 */