annotate libinterp/dldfcn/__magick_read__.cc @ 17226:46805642048f

Implement writing of indexed images. * __magick_read__.cc (encode_indexed_images): new function to create a Magick::Image object from an indexed image and colormap. (encode_uint_image): remove section about indexed image which was unfinished and is now completely done by a separate function. (encode_map): remove commented function for dealing with colormap which was never finished. (__magick_write__): implement writing of indexed images (integers only); refactor the actual writing of the file and dealing of the WriteMode option to make flow simpler. * private/__imwrite__.m: remove hack with ind2rgb() since writing of indexed images is now implemented; conversion of floating point indexed images to integer since it looks ugly in C++; also validate size 4 in the 3rd dimension of an image for CMYK images.
author Carnë Draug <carandraug@octave.org>
date Thu, 08 Aug 2013 17:41:50 +0100
parents 73a3c1580974
children 2f1729cae08f
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 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
311 // Do nothing other than silencing warnings about enumeration
17116
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
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
541 void static
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
542 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
543 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
544 try
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
545 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
546 // Read a file into vector of image objects
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
547 Magick::readImages (&imvec, filename);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
548 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
549 catch (Magick::Warning& w)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
550 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
551 warning ("Magick++ warning: %s", w.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
552 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
553 catch (Magick::ErrorCoder& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
554 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
555 // FIXME: there's a WarningCoder and ErrorCoder. Shouldn't this
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
556 // exception cause an error?
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
557 warning ("Magick++ coder error: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
558 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
559 catch (Magick::Exception& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
560 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
561 error ("Magick++ exception: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
562 error_state = 1;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
563 }
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
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
566 static void
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
567 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
568 {
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
569 static bool initialized = false;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
570
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
571 if (! initialized)
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
572 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
573 // Save locale as GraphicsMagick might change this (fixed in
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
574 // 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
575 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
576 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
577
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
578 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
579 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
580
10739
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
581 // 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
582 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
583
11036
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
584 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
585 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
586 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
587 MagickPackageName, QuantumDepth);
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
588 }
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
589 initialized = true;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
590 }
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
591 }
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
592 #endif
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
593
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
594 DEFUN_DLD (__magick_read__, args, nargout,
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
595 "-*- texinfo -*-\n\
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
596 @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
597 Read image with GraphicsMagick or ImageMagick.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
598 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
599 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
600 use @code{imread}.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
601 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
602 @seealso{imfinfo, imformats, imread, imwrite}\n\
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
603 @end deftypefn")
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
604 {
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
605 octave_value_list output;
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
606
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
607 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
608 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
609 #else
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
610
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
611 maybe_initialize_magick ();
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
612
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
613 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
614 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
615 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
616 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
617 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
618
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
619 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
620 if (error_state)
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
621 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
622 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
623 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
624
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
625 std::vector<Magick::Image> imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
626 read_file (args(0).string_value (), imvec);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
627 if (error_state)
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
628 {
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
629 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
630 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
631
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
632 // 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
633 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
634 Array<octave_idx_type> frameidx;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
635 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
636 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
637 {
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
638 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
639 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
640 {
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
641 frameidx(i) = i;
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
642 }
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
643 }
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
644 else
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
645 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
646 frameidx = indexes.int_vector_value ();
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
647 if (error_state)
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
648 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
649 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
650 }
16989
7a69ab84b8c9 __magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents: 16988
diff changeset
651 // 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
652 // 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
653 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
654 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
655 {
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
656 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
657 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
658 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
659 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
660 return output;
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
661 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
662 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
663 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
664
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
665 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
666 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
667
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
668 // Magick::ClassType
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
669 // PseudoClass:
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
670 // 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
671 // DirectClass:
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
672 // 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
673
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
674 // 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
675 // 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
676 // 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
677 // 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
678 // 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
679 // 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
680 // 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
681 // 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
682 // 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
683 // for that.
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
684
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
685 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
686 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
687 if (depth <= 1)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
688 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
689 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
690 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
691 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
692 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
693 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
694 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
695 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
696 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
697 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
698 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
699 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
700 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
701 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
702 else
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 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
705 return output;
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
706 }
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
707 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
708
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
709 else
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
710 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
711 if (depth <= 1)
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
712 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
713 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
714 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
715 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
716 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
717 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
718 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
719 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
720 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
721 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
722 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
723 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
724 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
725 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
726 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
727 {
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
728 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
729 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
730 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
731 else
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 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
734 depth);
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
735 }
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
736 }
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
737
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
738 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
739 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
740 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
741
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
742 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
743 ## 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
744 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
745 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
746
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
747 #ifdef HAVE_MAGICK
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
748
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
749 template <class T>
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
750 static void
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
751 encode_indexed_images (std::vector<Magick::Image>& imvec,
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
752 const T& img,
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
753 const Matrix cmap)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
754 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
755 typedef typename T::element_type P;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
756 const octave_idx_type nFrames = img.ndims () < 4 ? 1 : img.dims ()(3);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
757 const octave_idx_type nRows = img.rows ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
758 const octave_idx_type nCols = img.columns ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
759 const octave_idx_type cmap_size = cmap.rows ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
760 const octave_idx_type bitdepth =
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
761 sizeof (P) * std::numeric_limits<unsigned char>::digits;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
762
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
763 // There is no colormap object, we need to build a new one for each frame,
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
764 // even if it's always the same. We can least get a vector for the Colors.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
765 std::vector<Magick::ColorRGB> colormap;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
766 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
767 const double* cmap_fvec = cmap.fortran_vec ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
768 const octave_idx_type G_offset = cmap_size;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
769 const octave_idx_type B_offset = cmap_size * 2;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
770 for (octave_idx_type map_idx = 0; map_idx < cmap_size; map_idx++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
771 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
772 colormap.push_back (Magick::ColorRGB (cmap_fvec[map_idx],
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
773 cmap_fvec[map_idx + G_offset],
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
774 cmap_fvec[map_idx + B_offset]));
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
775 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
776 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
777
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
778 for (octave_idx_type frame = 0; frame < nFrames; frame++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
779 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
780 Magick::Image m_img (Magick::Geometry (nCols, nRows), "black");
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
781
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
782 // Ensure that there are no other references to this image.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
783 m_img.modifyImage ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
784
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
785 m_img.classType (Magick::PseudoClass);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
786 m_img.type (Magick::PaletteType);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
787 // FIXME: for some reason, setting bitdepth doesn't seem to work for
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
788 // indexed images.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
789 m_img.depth (bitdepth);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
790
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
791 // Insert colormap.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
792 m_img.colorMapSize (cmap_size);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
793 for (octave_idx_type map_idx = 0; map_idx < cmap_size; map_idx++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
794 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
795 m_img.colorMap (map_idx, colormap[map_idx]);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
796 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
797 // Why are we also setting the pixel values instead of only the
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
798 // index values? We don't know if a file format supports indexed
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
799 // images. If we only set the indexes and then try to save the
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
800 // image as JPEG for example, the indexed values get discarded,
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
801 // there is no conversion from the indexes, it's the initial values
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
802 // that get used. An alternative would be to only set the pixel
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
803 // values (no indexes), then set the image as PseudoClass and GM
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
804 // would create a colormap for us. However, we wouldn't have control
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
805 // over the order of that colormap. And that's why we set both.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
806 Magick::PixelPacket* pix = m_img.getPixels (0, 0, nCols, nRows);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
807 Magick::IndexPacket* ind = m_img.getIndexes ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
808 const P* img_fvec = img.fortran_vec ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
809
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
810 octave_idx_type GM_idx = 0;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
811 for (octave_idx_type column = 0; column < nCols; column++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
812 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
813 for (octave_idx_type row = 0; row < nRows; row++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
814 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
815 ind[GM_idx] = double (*img_fvec);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
816 pix[GM_idx] = m_img.colorMap (double (*img_fvec));
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
817 img_fvec++;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
818 GM_idx += nCols;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
819 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
820 GM_idx -= nCols * nRows - 1;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
821 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
822
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
823 // Save changes to underlying image.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
824 m_img.syncPixels ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
825 imvec.push_back (m_img);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
826 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
827 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
828
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
829 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
830 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
831 {
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
832 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
833 boolNDArray m = img.bool_array_value ();
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 dim_vector dsizes = m.dims ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
836 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
837 nframes = dsizes(3);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
838
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
839 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
840
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
841 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
842 octave_idx_type columns = m.columns ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
843
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
844 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
845 {
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
846 Magick::Image im (Magick::Geometry (columns, rows), "black");
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
847 im.classType (Magick::DirectClass);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
848 im.depth (1);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
849
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
850 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
851 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
852 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
853
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
854 for (int x = 0; x < rows; x++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
855 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
856 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
857 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
858 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
859 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
860 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
861
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
862 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
863
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
864 if (m(idx))
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
865 im.pixelColor (y, x, "white");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
866 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
867 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
868
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
869 im.quantizeColorSpace (Magick::GRAYColorspace);
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
870 im.quantizeColors (2);
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
871 im.quantize ();
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
872
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
873 imvec.push_back (im);
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 }
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 template <class T>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
878 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
879 encode_uint_image (std::vector<Magick::Image>& imvec,
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
880 const octave_value& img)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
881 {
8520
715f6cd8d5e7 __magick_read__.cc (encode_uint_image): initialize bitdepth
Soren Hauberg <hauberg@gmail.com>
parents: 8165
diff changeset
882 unsigned int bitdepth = 0;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
883 T m;
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 if (img.is_uint8_type ())
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 bitdepth = 8;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
888 m = img.uint8_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
889 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
890 else if (img.is_uint16_type ())
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 bitdepth = 16;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
893 m = img.uint16_array_value ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
894 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
895 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
896 error ("__magick_write__: invalid image class");
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
897
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
898 const dim_vector dsizes = m.dims ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
899 unsigned int nframes = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
900 if (dsizes.length () == 4)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
901 nframes = dsizes(3);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
902
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
903 const bool is_color = ((dsizes.length () > 2) && (dsizes(2) > 2));
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
904 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
905
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
906 Array<octave_idx_type> idx (dim_vector (dsizes.length (), 1));
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
907 octave_idx_type rows = m.rows ();
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
908 octave_idx_type columns = m.columns ();
8090
3cc1ca1b1576 MSVC compilation fix
Michael Goffioul
parents: 8054
diff changeset
909
13020
58d704d3283c Fix ambigous call to int pow (int, unsigned int&)
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11590
diff changeset
910 unsigned int div_factor = (1 << bitdepth) - 1;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
911
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
912 for (unsigned int ii = 0; ii < nframes; ii++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
913 {
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
914 Magick::Image im (Magick::Geometry (columns, rows), "black");
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
915
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
916 im.depth (bitdepth);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
917
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
918 im.classType (Magick::DirectClass);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
919
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
920 if (is_color)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
921 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
922 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
923 im.type (Magick::TrueColorMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
924 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
925 im.type (Magick::TrueColorType);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
926
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
927 Magick::ColorRGB c;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
928
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
929 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
930 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
931 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
932
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
933 for (int x = 0; x < rows; x++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
934 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
935 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
936
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
937 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
938 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
939
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
940 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
941 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
942
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
943 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
944 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
945
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
946 idx(2) = 2;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
947 c.blue (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
948
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
949 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
950 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
951 idx(2) = 3;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
952 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
953 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
954
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
955 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
956 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
957 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
958 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
959 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
960 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
961 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
962 im.type (Magick::GrayscaleMatteType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
963 else
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
964 im.type (Magick::GrayscaleType);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
965
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
966 Magick::ColorGray c;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
967
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
968 for (int y = 0; y < columns; y++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
969 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
970 idx(1) = y;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
971
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
972 for (int x=0; x < rows; x++)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
973 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
974 idx(0) = x;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
975
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
976 if (nframes > 1)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
977 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
978 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
979 idx(3) = ii;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
980 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
981
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
982 if (has_alpha)
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
983 {
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
984 idx(2) = 1;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
985 c.alpha (static_cast<double>(m(idx)) / div_factor);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
986 idx(2) = 0;
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
987 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
988
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
989 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
990
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
991 im.pixelColor (y, x, c);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
992 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
993 }
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
994
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
995 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
996 im.quantizeColors (1 << bitdepth);
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
997 im.quantize ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
998 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
999
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1000 imvec.push_back (im);
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1001 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1002 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1003
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1004 void static
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1005 write_file (const std::string filename,
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1006 const std::string ext,
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1007 std::vector<Magick::Image>& imvec)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1008 {
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1009 try
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1010 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1011 Magick::writeImages (imvec.begin (), imvec.end (), ext + ":" + filename);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1012 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1013 catch (Magick::Warning& w)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1014 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1015 warning ("Magick++ warning: %s", w.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1016 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1017 catch (Magick::ErrorCoder& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1018 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1019 warning ("Magick++ coder error: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1020 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1021 catch (Magick::Exception& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1022 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1023 error ("Magick++ exception: %s", e.what ());
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1024 error_state = 1;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1025 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1026 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1027
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1028 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1029
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
1030 DEFUN_DLD (__magick_write__, args, ,
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1031 "-*- texinfo -*-\n\
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1032 @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
1033 Write image with GraphicsMagick or ImageMagick.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1034 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1035 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
1036 use @code{imwrite}.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1037 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1038 @seealso{imfinfo, imformats, imread, imwrite}\n\
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1039 @end deftypefn")
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1040 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1041 octave_value_list retval;
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1042
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1043 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1044 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
1045 #else
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1046
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1047 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1048
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1049 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
1050 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1051 print_usage ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1052 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1053 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1054 const std::string filename = args(0).string_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1055 const std::string ext = args(1).string_value ();
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1056
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1057 const octave_scalar_map options = args(4).scalar_map_value ();
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1058 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1059 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1060 error ("__magick_write__: OPTIONS must be a struct");
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1061 return retval;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1062 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1063
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1064 const octave_value img = args(2);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1065 const Matrix cmap = args(3).matrix_value ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1066 if (error_state)
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 error ("__magick_write__: invalid IMG or MAP");
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1069 return retval;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1070 }
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1071 // Create vector for the images to be written.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1072 std::vector<Magick::Image> imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1073
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1074 if (cmap.is_empty ())
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1075 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1076 if (img.is_bool_type ())
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1077 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1078 encode_bool_image (imvec, img);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1079 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1080 else if (img.is_uint8_type ())
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1081 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1082 encode_uint_image<uint8NDArray> (imvec, img);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1083 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1084 else if (img.is_uint16_type ())
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1085 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1086 encode_uint_image<uint16NDArray> (imvec, img);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1087 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1088 else
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1089 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1090 error ("__magick_write__: image type not supported");
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1091 return retval;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1092 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1093 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1094 else
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1095 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1096 // We should not get floating point indexed images here because we
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1097 // converted them in __imwrite__.m. We should probably do it here
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1098 // but it would look much messier.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1099 if (img.is_uint8_type ())
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1100 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1101 encode_indexed_images<uint8NDArray> (imvec, img.uint8_array_value (), cmap);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1102 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1103 else if (img.is_uint16_type ())
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1104 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1105 encode_indexed_images<uint16NDArray> (imvec, img.uint16_array_value (), cmap);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1106 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1107 else
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1108 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1109 error ("__magick_write__: indexed image must be uint8, uint16 or float.");
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1110 return retval;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1111 }
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1112 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1113
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1114 const octave_idx_type nFrames = imvec.size ();
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1115
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1116 // Set quality.
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1117 // FIXME What happens when we try to set with formats that do not support it?
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1118 const octave_idx_type quality = options.getfield ("quality").int_value ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1119 for (octave_idx_type i = 0; i < nFrames; i++)
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1120 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1121 imvec[i].quality (quality);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1122 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1123
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1124 // If writemode is set to append, read the image and append to it. Even
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1125 // if set to append, make sure that something was read at all.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1126 const std::string writemode = options.getfield ("writemode").string_value ();
16989
7a69ab84b8c9 __magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents: 16988
diff changeset
1127 if (writemode == "append" && file_stat (filename).exists ())
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1128 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1129 std::vector<Magick::Image> ini_imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1130 read_file (filename, ini_imvec);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1131 if (error_state)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1132 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1133 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1134 }
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1135 if (ini_imvec.size () > 0)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1136 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1137 ini_imvec.insert (ini_imvec.end (), imvec.begin (), imvec.end ());
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1138 ini_imvec.swap (imvec);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1139 }
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1140 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1141
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1142 // Finally, save the damn thing.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1143 write_file (filename, ext, imvec);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1144 if (error_state)
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1145 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1146 return retval;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1147 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1148
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1149 #endif
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1150 return retval;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1151 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1152
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1153 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1154 ## 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
1155 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1156 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1157
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
1158 #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
1159
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1160 template<class T>
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1161 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1162 magick_to_octave_value (const T 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 return octave_value (magick);
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1165 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1166
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1167 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1168 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
1169 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1170 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1171 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1172 case Magick::LSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1173 return octave_value ("little-endian");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1174
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1175 case Magick::MSBEndian:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1176 return octave_value ("big-endian");
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 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1184 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
1185 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1186 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1187 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1188 case Magick::PixelsPerInchResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1189 return octave_value ("pixels per inch");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1190
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1191 case Magick::PixelsPerCentimeterResolution:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1192 return octave_value ("pixels per centimeter");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1193
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1194 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1195 return octave_value ("undefined");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1196 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1197 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1198
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1199 static octave_value
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1200 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
1201 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1202 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1203 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1204 case Magick::BilevelType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1205 case Magick::GrayscaleType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1206 case Magick::GrayscaleMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1207 return octave_value ("grayscale");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1208
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1209 case Magick::PaletteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1210 case Magick::PaletteMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1211 return octave_value ("indexed");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1212
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1213 case Magick::TrueColorType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1214 case Magick::TrueColorMatteType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1215 case Magick::ColorSeparationType:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1216 return octave_value ("truecolor");
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1217
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1218 default:
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1219 return octave_value ("undefined");
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 }
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 // 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
1224 // 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
1225 #define GET_PARAM(NAME, OUTNAME) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1226 try \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1227 { \
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1228 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
1229 } \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1230 catch (Magick::Warning& w) \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1231 { \
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1232 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1233
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
1234 #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
1235
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
1236 DEFUN_DLD (__magick_finfo__, args, ,
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1237 "-*- 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
1238 @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
1239 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
1240 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1241 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
1242 use @code{imfinfo}.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1243 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1244 @seealso{imfinfo, imformats, imread, imwrite}\n\
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1245 @end deftypefn")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1246 {
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1247 octave_value retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1248
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1249 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1250 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
1251 #else
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1252
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1253 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1254
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1255 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
1256 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1257 print_usage ();
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1258 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1259 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1260
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1261 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
1262
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1263 try
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1264 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1265 // Read the file.
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1266 std::vector<Magick::Image> imvec;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1267 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
1268 int nframes = imvec.size ();
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1269
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1270 // 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
1271
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1272 static const char *fields[] =
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 "Filename",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1275 "FileModDate",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1276 "FileSize",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1277 "Height",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1278 "Width",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1279 "BitDepth",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1280 "Format",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1281 "LongFormat",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1282 "XResolution",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1283 "YResolution",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1284 "TotalColors",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1285 "TileName",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1286 "AnimationDelay",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1287 "AnimationIterations",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1288 "ByteOrder",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1289 "Gamma",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1290 "Matte",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1291 "ModulusDepth",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1292 "Quality",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1293 "QuantizeColors",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1294 "ResolutionUnits",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1295 "ColorType",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1296 "View",
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1297 0
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1298 };
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1299
16871
5e30b1c950b8 Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents: 16543
diff changeset
1300 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
1301
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1302 file_stat fs (filename);
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1303
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1304 std::string filetime;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1305
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1306 if (fs)
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1307 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1308 octave_localtime mtime = fs.mtime ();
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1309
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1310 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
1311 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1312 else
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1313 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1314 std::string msg = fs.error ();
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1315
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14173
diff changeset
1316 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
1317 filename.c_str (), msg.c_str ());
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1318
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1319 return retval;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1320 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1321
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1322 // 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
1323 // 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
1324 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
1325 {
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1326 Magick::Image im = imvec[frame];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1327
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1328 // Add file name and timestamp.
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1329 info.contents ("Filename")(frame,0) = filename;
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1330 info.contents ("FileModDate")(frame,0) = filetime;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1331
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1332 // 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
1333 GET_PARAM (fileSize, "FileSize")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1334 GET_PARAM (rows, "Height")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1335 GET_PARAM (columns, "Width")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1336 GET_PARAM (depth, "BitDepth")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1337 GET_PARAM (magick, "Format")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1338 GET_PARAM (format, "LongFormat")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1339 GET_PARAM (xResolution, "XResolution")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1340 GET_PARAM (yResolution, "YResolution")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1341 GET_PARAM (totalColors, "TotalColors")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1342 GET_PARAM (tileName, "TileName")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1343 GET_PARAM (animationDelay, "AnimationDelay")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1344 GET_PARAM (animationIterations, "AnimationIterations")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1345 GET_PARAM (endian, "ByteOrder")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1346 GET_PARAM (gamma, "Gamma")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1347 GET_PARAM (matte, "Matte")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1348 GET_PARAM (modulusDepth, "ModulusDepth")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1349 GET_PARAM (quality, "Quality")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1350 GET_PARAM (quantizeColors, "QuantizeColors")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1351 GET_PARAM (resolutionUnits, "ResolutionUnits")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1352 GET_PARAM (type, "ColorType")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1353 GET_PARAM (view, "View")
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1354 }
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1355
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1356 retval = octave_value (info);
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1357 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1358 catch (Magick::Warning& w)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1359 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1360 warning ("Magick++ warning: %s", w.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1361 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1362 catch (Magick::ErrorCoder& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1363 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1364 warning ("Magick++ coder error: %s", e.what ());
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1365 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1366 catch (Magick::Exception& e)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1367 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1368 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
1369 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1370 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1371 #endif
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1372 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1373 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1374
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1375 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1376 ## 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
1377 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1378 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1379
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1380 #undef GET_PARAM
11035
8a6b7947f618 Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents: 11034
diff changeset
1381
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1382 DEFUN_DLD (__magick_formats__, args, ,
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1383 "-*- texinfo -*-\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1384 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1385 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
1386 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1387 @seealso{imfinfo, imformats, imread, imwrite}\n\
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1388 @end deftypefn")
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1389 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1390 octave_value retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1391 #ifndef HAVE_MAGICK
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1392 gripe_disabled_feature ("imformats", "Image IO");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1393 #else
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1394 if (args.length () != 1 || ! args (0).is_map ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1395 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1396 print_usage ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1397 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1398 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1399 octave_map formats = args(0).map_value ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1400
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1401 maybe_initialize_magick ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1402 for (octave_idx_type idx = 0; idx < formats.numel (); idx++)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1403 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1404 try
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1405 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1406 octave_scalar_map fmt = formats.checkelem (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1407 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1408
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1409 fmt.setfield ("description", octave_value (coder.description ()));
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1410 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1411 // 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
1412 // read or write them, them set it to an empty value
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1413 if (! coder.isReadable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1414 fmt.setfield ("read", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1415 if (! coder.isWritable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1416 fmt.setfield ("write", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1417 formats.fast_elem_insert (idx, fmt);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1418 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1419 catch (Magick::Exception& e)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1420 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1421 // Exception here are missing formats. So we remove the format
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1422 // from the structure and reduce idx.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1423 formats.delete_elements (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1424 idx--;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1425 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1426 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1427 retval = formats;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1428 #endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1429 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1430 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1431
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1432 /*
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1433 ## No test needed for internal helper function.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1434 %!assert (1)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
1435 */