Mercurial > octave-nkf
annotate libinterp/dldfcn/__magick_read__.cc @ 17333:51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 27 Aug 2013 09:24:15 +0100 |
parents | eb7e9a991ffb |
children | f8ee0ed7f1b8 |
rev | line source |
---|---|
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
1 /* |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
2 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
3 Copyright (C) 2013 Carnë Draug |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
4 Copyright (C) 2002-2012 Andy Adler |
7932 | 5 Copyright (C) 2008 Thomas L. Scofield |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
6 Copyright (C) 2010 David Grundberg |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
7 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
8 This file is part of Octave. |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
9 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
10 Octave is free software; you can redistribute it and/or modify it |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
11 under the terms of the GNU General Public License as published by the |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
12 Free Software Foundation; either version 3 of the License, or (at your |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
13 option) any later version. |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
14 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
15 Octave is distributed in the hope that it will be useful, but WITHOUT |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
18 for more details. |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
19 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
20 You should have received a copy of the GNU General Public License |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
21 along with Octave; see the file COPYING. If not, see |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
22 <http://www.gnu.org/licenses/>. |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
23 |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
24 */ |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
25 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
26 #ifdef HAVE_CONFIG_H |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
27 #include <config.h> |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
28 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
29 |
8054 | 30 #include <cmath> |
31 | |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
32 #include "file-stat.h" |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
33 #include "oct-env.h" |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
34 #include "oct-time.h" |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
35 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
36 #include "defun-dld.h" |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
37 #include "error.h" |
8054 | 38 #include "ov-struct.h" |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
39 |
16925
5c25f7ed080c
*__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents:
16901
diff
changeset
|
40 #include "gripes.h" |
5c25f7ed080c
*__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents:
16901
diff
changeset
|
41 |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
42 #ifdef HAVE_MAGICK |
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
43 |
9575
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9439
diff
changeset
|
44 #include <Magick++.h> |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
45 #include <clocale> |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
46 |
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, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
82 const octave_idx_type& nargout, |
17118
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 | 93 |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
94 // imvec has all of the pages of a file, even the ones we are not |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
95 // interested in. We will use the first image that we will be actually |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
96 // reading to get information about the image. |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
97 const octave_idx_type def_elem = frameidx(0); |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
98 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
99 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
|
100 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
|
101 |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
102 const octave_idx_type row_start = region["row_start"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
103 const octave_idx_type col_start = region["col_start"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
104 const octave_idx_type row_shift = region["row_shift"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
105 const octave_idx_type col_shift = region["col_shift"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
106 const octave_idx_type row_cache = region["row_cache"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
107 const octave_idx_type col_cache = region["col_cache"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
108 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
109 // 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
|
110 // 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
|
111 // 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
|
112 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
|
113 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
|
114 { |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
115 imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
116 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
|
117 |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
118 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
|
119 = imvec[frameidx(frame)].getConstIndexes (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
120 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
121 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
|
122 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
123 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
|
124 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
125 img_fvec[idx++] = static_cast<P> (*pix); |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
126 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
|
127 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
128 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
|
129 } |
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 retval(0) = octave_value (img); |
7933 | 132 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
133 // 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
|
134 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
|
135 { |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
136 const octave_idx_type mapsize = imvec[def_elem].colorMapSize (); |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
137 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
|
138 |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
139 // 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
|
140 // 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
|
141 // 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
|
142 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
143 // only get alpha channel if it exists and was requested as output |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
144 if (imvec[def_elem].matte () && nargout >= 3) |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
145 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
146 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
|
147 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
|
148 { |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
149 const Magick::ColorRGB c = imvec[def_elem].colorMap (i); |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 } |
7933 | 155 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
156 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
|
157 const octave_idx_type nPixels = alpha.numel (); |
7933 | 158 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
159 double* alpha_fvec = alpha.fortran_vec (); |
7933 | 160 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
161 idx = 0; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
162 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
|
163 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
164 // 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
|
165 // 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
|
166 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
|
167 idx++; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
168 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
169 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
|
170 } |
10100
dd4d4b14b340
__magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents:
9575
diff
changeset
|
171 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
172 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
173 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
174 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
|
175 { |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
176 const Magick::ColorRGB c = imvec[def_elem].colorMap (i); |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
181 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
182 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
183 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
|
184 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
185 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
186 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
|
187 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
188 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
189 // 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
|
190 // 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
|
191 // 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
|
192 // readability too much. |
10193
1a4074e277fe
undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
193 template <class T> |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
194 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
|
195 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
|
196 const Array<octave_idx_type>& frameidx, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
197 const octave_idx_type& nargout, |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
198 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
|
199 { |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
200 typedef typename T::element_type P; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
201 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
202 octave_value_list retval (3, Matrix ()); |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
203 |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
204 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
|
205 const octave_idx_type nFrames = frameidx.length (); |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
206 const octave_idx_type nRows = region["row_out"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
207 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
|
208 T img; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
209 |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
210 // imvec has all of the pages of a file, even the ones we are not |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
211 // interested in. We will use the first image that we will be actually |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
212 // reading to get information about the image. |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
213 const octave_idx_type def_elem = frameidx(0); |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
214 |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
215 const octave_idx_type row_start = region["row_start"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
216 const octave_idx_type col_start = region["col_start"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
217 const octave_idx_type row_shift = region["row_shift"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
218 const octave_idx_type col_shift = region["col_shift"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
219 const octave_idx_type row_cache = region["row_cache"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
220 const octave_idx_type col_cache = region["col_cache"]; |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
221 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
222 // 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
|
223 // 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
|
224 // 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
|
225 // 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
|
226 // 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
|
227 // 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
|
228 // 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
|
229 // 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
|
230 // 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
|
231 // See bug #39249). |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
232 // 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
|
233 // 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
|
234 // 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
|
235 // 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
|
236 // 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
|
237 // when depth() is 32. |
17147
35a1bd41aa02
Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17139
diff
changeset
|
238 // 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
|
239 // with QuantumRange since MaxRGB is already deprecated in ImageMagick. |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
240 double divisor; |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
241 if (imvec[def_elem].depth () == 32) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
242 divisor = std::numeric_limits<uint32_t>::max (); |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
243 else |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
244 divisor = MaxRGB / ((uint64_t (1) << imvec[def_elem].depth ()) - 1); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
245 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
246 // 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
|
247 // new ImageType BilevelMatteType |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
248 // 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
|
249 // 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
|
250 // 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
|
251 // 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
|
252 // only way to check for this seems to be by checking matte (). |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
253 Magick::ImageType type = imvec[def_elem].type (); |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
254 if (type == Magick::BilevelType && imvec[def_elem].matte ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
255 type = Magick::GrayscaleMatteType; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
256 |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
257 // 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
|
258 // 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
|
259 // 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
|
260 // 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
|
261 // 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
|
262 // 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
|
263 // 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
|
264 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
|
265 { |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
266 // 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
|
267 // Grayscale = 0 |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
268 // 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
|
269 // RGB = 2 |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
270 // 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
|
271 // 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
|
272 // 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
|
273 // 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
|
274 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
|
275 if (type_str == "0") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
276 type = Magick::GrayscaleType; |
17149
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 == "2") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
278 type = Magick::TrueColorType; |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
279 else if (type_str == "6") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
280 type = Magick::TrueColorMatteType; |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
281 else if (type_str == "4") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
282 type = Magick::GrayscaleMatteType; |
17239
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
283 // Color types 0, 2, and 3 can also have alpha channel, conveyed |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
284 // via the "tRNS" chunk. For 0 and 2, it's limited to GIF-style |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
285 // binary transparency, while 3 can have any level of alpha per |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
286 // palette entry. We thus must check matte() to see if the image |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
287 // really doesn't have an alpha channel. |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
288 if (imvec[0].matte ()) |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
289 { |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
290 if (type == Magick::GrayscaleType) |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
291 type = Magick::GrayscaleMatteType; |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
292 else if (type == Magick::TrueColorType) |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
293 type = Magick::TrueColorMatteType; |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
294 } |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
295 } |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
296 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
297 // 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
|
298 // 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
|
299 if (nargout < 3) |
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 switch (type) |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
302 { |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
303 case Magick::GrayscaleMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
304 type = Magick::GrayscaleType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
305 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
306 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
307 case Magick::PaletteMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
308 type = Magick::PaletteType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
309 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
310 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
311 case Magick::TrueColorMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
312 type = Magick::TrueColorType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
313 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
314 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
315 case Magick::ColorSeparationMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
316 type = Magick::ColorSeparationType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
317 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
318 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
319 default: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
320 // Do nothing other than silencing warnings about enumeration |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
321 // values not being handled in switch. |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
322 ; |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
323 } |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
324 } |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
325 |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
326 switch (type) |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
327 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
328 case Magick::BilevelType: // Monochrome bi-level image |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
329 case Magick::GrayscaleType: // Grayscale image |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
330 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
331 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
|
332 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
|
333 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
334 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
|
335 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
|
336 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
337 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
338 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
339 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
340 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
341 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
|
342 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
343 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
|
344 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
345 img_fvec[idx++] = pix->red / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
346 pix += row_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
347 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
348 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
349 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
350 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
351 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
352 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
353 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
354 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
|
355 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
360 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
361 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
|
362 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
|
363 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
364 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
365 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
366 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
367 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
368 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
|
369 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
370 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
|
371 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
372 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
|
373 a_fvec[idx] = (MaxRGB - pix->opacity) / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
374 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
|
375 idx++; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
376 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
377 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
378 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
379 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
380 retval(2) = alpha; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
381 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
382 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
383 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
384 case Magick::PaletteType: // Indexed color (palette) image |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
385 case Magick::TrueColorType: // Truecolor image |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
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 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
|
388 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
|
389 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
390 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
|
391 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
392 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
393 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
394 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
395 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
402 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
|
403 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
404 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
|
405 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
406 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
|
407 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
|
408 bbuf[idx] = pix->blue / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
409 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
|
410 idx++; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
411 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
412 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
413 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
414 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
415 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
416 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
417 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
418 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
|
419 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
|
420 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
421 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
|
422 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
|
423 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
|
424 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
|
425 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
426 // 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
|
427 // 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
|
428 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
|
429 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
|
430 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
431 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
432 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
433 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
|
434 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
441 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
|
442 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
443 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
|
444 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
445 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
|
446 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
|
447 bbuf[idx] = pix->blue / divisor; |
17147
35a1bd41aa02
Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17139
diff
changeset
|
448 a_fvec[a_idx++] = (MaxRGB - pix->opacity) / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
449 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
|
450 idx++; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
451 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
452 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
|
453 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
454 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
455 retval(2) = alpha; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
456 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
457 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
458 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
459 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
|
460 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
461 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
|
462 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
|
463 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
464 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
|
465 { |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
466 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
467 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
468 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
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 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
477 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
|
478 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
479 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
|
480 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 kbuf[idx] = pix->opacity / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
485 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
|
486 idx++; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
487 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
488 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
489 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
490 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
491 break; |
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 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
494 // 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
|
495 case Magick::ColorSeparationMatteType: |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
496 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
497 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
|
498 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
|
499 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
|
500 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
|
501 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
502 // 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
|
503 // 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
|
504 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
|
505 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
|
506 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
507 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
508 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
509 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
|
510 // 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
|
511 // 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
|
512 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
|
513 = imvec[frameidx(frame)].getConstIndexes (); |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
514 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
515 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
522 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
|
523 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
524 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
|
525 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 kbuf[idx] = pix->opacity / divisor; |
17147
35a1bd41aa02
Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17139
diff
changeset
|
530 a_fvec[a_idx++] = (MaxRGB - *apix) / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
531 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
|
532 idx++; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
533 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
534 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
|
535 } |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
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(2) = alpha; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
538 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
539 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
540 |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
541 default: |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
542 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
|
543 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
|
544 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
545 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
546 retval(0) = img; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
547 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
|
548 } |
7974 | 549 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
550 // Read a file into vector of image objects. |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
551 void static |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
552 read_file (const std::string& filename, std::vector<Magick::Image>& imvec) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
553 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
554 try |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
555 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
556 Magick::readImages (&imvec, filename); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
557 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
558 catch (Magick::Warning& w) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
559 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
560 warning ("Magick++ warning: %s", w.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
561 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
562 catch (Magick::ErrorCoder& e) |
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 // FIXME: there's a WarningCoder and ErrorCoder. Shouldn't this |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
565 // exception cause an error? |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
566 warning ("Magick++ coder error: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
567 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
568 catch (Magick::Exception& e) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
569 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
570 error ("Magick++ exception: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
571 error_state = 1; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
572 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
573 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
574 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
575 static void |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
576 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
|
577 { |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
578 static bool initialized = false; |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
579 |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
580 if (! initialized) |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
581 { |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
582 // Save locale as GraphicsMagick might change this (fixed in |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
583 // 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
|
584 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
|
585 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
|
586 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
587 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
|
588 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
|
589 |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
590 // 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
|
591 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
|
592 |
11036
169f59f626d3
Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents:
11035
diff
changeset
|
593 if (QuantumDepth < 32) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
594 warning ("your version of %s limits images to %d bits per pixel", |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
595 MagickPackageName, QuantumDepth); |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
596 |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
597 initialized = true; |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
598 } |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
599 } |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
600 #endif |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
601 |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
602 DEFUN_DLD (__magick_read__, args, nargout, |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
603 "-*- texinfo -*-\n\ |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
604 @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
|
605 Read image with GraphicsMagick or ImageMagick.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
606 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
607 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
|
608 use @code{imread}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
609 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
610 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
611 @end deftypefn") |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
612 { |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
613 octave_value_list output; |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
614 |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
615 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
616 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
|
617 #else |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
618 |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
619 maybe_initialize_magick (); |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
620 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
621 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
|
622 { |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
623 print_usage (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
624 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
|
625 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
626 |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
627 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
|
628 if (error_state) |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
629 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
630 error ("__magick_read__: OPTIONS must be a struct"); |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
631 return output; |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
632 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
633 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
634 std::vector<Magick::Image> imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
635 read_file (args(0).string_value (), imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
636 if (error_state) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
637 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
|
638 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
639 // 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
|
640 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
|
641 Array<octave_idx_type> frameidx; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
642 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
|
643 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
|
644 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
645 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
|
646 for (octave_idx_type i = 0; i < nFrames; i++) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
647 frameidx(i) = i; |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
648 } |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
649 else |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
650 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
651 frameidx = indexes.int_vector_value (); |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
652 if (error_state) |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
653 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
654 error ("__magick_read__: invalid value for Index/Frame"); |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
655 return output; |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
656 } |
16989
7a69ab84b8c9
__magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents:
16988
diff
changeset
|
657 // 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
|
658 // 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
|
659 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
|
660 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
|
661 { |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
662 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
|
663 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
|
664 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
665 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
|
666 return output; |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
667 } |
8053 | 668 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
669 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
670 |
17240
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
671 const Magick::ClassType klass = imvec[frameidx(0)].classType (); |
d757c98636d8
Use first image to be read rather than first image in file to set defaults.
Carnë Draug <carandraug@octave.org>
parents:
17239
diff
changeset
|
672 const octave_idx_type depth = imvec[frameidx(0)].depth (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
673 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
674 // Magick::ClassType |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
675 // PseudoClass: |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
676 // 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
|
677 // DirectClass: |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
678 // 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
|
679 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
680 // 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
|
681 // 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
|
682 // 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
|
683 // 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
|
684 // 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
|
685 // 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
|
686 // 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
|
687 // 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
|
688 // 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
|
689 // for that. |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
690 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
691 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
|
692 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
693 if (depth <= 1) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
694 output = read_indexed_images<boolNDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
695 nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
696 else if (depth <= 8) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
697 output = read_indexed_images<uint8NDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
698 nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
699 else if (depth <= 16) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
700 output = read_indexed_images<uint16NDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
701 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
|
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) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
712 output = read_images<boolNDArray> (imvec, frameidx, nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
713 else if (depth <= 8) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
714 output = read_images<uint8NDArray> (imvec, frameidx, 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 else if (depth <= 16) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
716 output = read_images<uint16NDArray> (imvec, frameidx, nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
717 else if (depth <= 32) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
718 output = read_images<FloatNDArray> (imvec, frameidx, nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
719 else |
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 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
|
722 depth); |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
723 } |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
724 } |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
725 |
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
726 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
727 return output; |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
728 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
729 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
730 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
731 ## 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
|
732 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
733 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
734 |
7974 | 735 #ifdef HAVE_MAGICK |
736 | |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
737 template <class T> |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
738 static uint32NDArray |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
739 img_float2uint (const T& img) |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
740 { |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
741 typedef typename T::element_type P; |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
742 uint32NDArray out (img.dims ()); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
743 |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
744 octave_uint32* out_fvec = out.fortran_vec (); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
745 const P* img_fvec = img.fortran_vec (); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
746 |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
747 const octave_uint32 max = octave_uint32::max (); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
748 const octave_idx_type numel = img.numel (); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
749 for (octave_idx_type idx = 0; idx < numel; idx++) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
750 out_fvec[idx] = img_fvec[idx] * max; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
751 |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
752 return out; |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
753 } |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
754 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
755 // Gets the bitdepth to be used for an Octave class, i.e, returns 8 for |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
756 // uint8, 16 for uint16, and 32 for uint32 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
757 template <class T> |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
758 static octave_idx_type |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
759 bitdepth_from_class () |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
760 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
761 typedef typename T::element_type P; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
762 const octave_idx_type bitdepth = |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
763 sizeof (P) * std::numeric_limits<unsigned char>::digits; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
764 return bitdepth; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
765 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
766 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
767 static Magick::Image |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
768 init_enconde_image (const octave_idx_type& nCols, const octave_idx_type& nRows, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
769 const octave_idx_type& bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
770 const Magick::ImageType& type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
771 const Magick::ClassType& klass) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
772 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
773 Magick::Image img (Magick::Geometry (nCols, nRows), "black"); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
774 // Ensure that there are no other references to this image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
775 img.modifyImage (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
776 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
777 img.classType (klass); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
778 img.type (type); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
779 // FIXME: for some reason, setting bitdepth doesn't seem to work for |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
780 // indexed images. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
781 img.depth (bitdepth); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
782 switch (type) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
783 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
784 case Magick::GrayscaleMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
785 case Magick::TrueColorMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
786 case Magick::ColorSeparationMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
787 case Magick::PaletteMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
788 img.matte (true); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
789 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
790 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
791 default: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
792 img.matte (false); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
793 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
794 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
795 return img; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
796 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
797 |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
798 template <class T> |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
799 static void |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
800 encode_indexed_images (std::vector<Magick::Image>& imvec, |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
801 const T& img, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
802 const Matrix& cmap) |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
803 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
804 typedef typename T::element_type P; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
805 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
|
806 const octave_idx_type nRows = img.rows (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
807 const octave_idx_type nCols = img.columns (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
808 const octave_idx_type cmap_size = cmap.rows (); |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
809 const octave_idx_type bitdepth = bitdepth_from_class<T> (); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
810 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
811 // 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
|
812 // 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
|
813 std::vector<Magick::ColorRGB> colormap; |
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 const double* cmap_fvec = cmap.fortran_vec (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
816 const octave_idx_type G_offset = cmap_size; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
817 const octave_idx_type B_offset = cmap_size * 2; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
818 for (octave_idx_type map_idx = 0; map_idx < cmap_size; map_idx++) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
819 colormap.push_back (Magick::ColorRGB (cmap_fvec[map_idx], |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
820 cmap_fvec[map_idx + G_offset], |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
821 cmap_fvec[map_idx + B_offset])); |
17226
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 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
824 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
825 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
826 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
827 Magick::PaletteType, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
828 Magick::PseudoClass); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
829 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
830 // Insert colormap. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
831 m_img.colorMapSize (cmap_size); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
832 for (octave_idx_type map_idx = 0; map_idx < cmap_size; map_idx++) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
833 m_img.colorMap (map_idx, colormap[map_idx]); |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
834 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
835 // 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
|
836 // 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
|
837 // 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
|
838 // 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
|
839 // 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
|
840 // 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
|
841 // 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
|
842 // 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
|
843 // 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
|
844 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
|
845 Magick::IndexPacket* ind = m_img.getIndexes (); |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
846 const P* img_fvec = img.fortran_vec (); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
847 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
848 octave_idx_type GM_idx = 0; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
849 for (octave_idx_type column = 0; column < nCols; column++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
850 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
851 for (octave_idx_type row = 0; row < nRows; row++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
852 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
853 ind[GM_idx] = double (*img_fvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
854 pix[GM_idx] = m_img.colorMap (double (*img_fvec)); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
855 img_fvec++; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
856 GM_idx += nCols; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
857 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
858 GM_idx -= nCols * nRows - 1; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
859 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
860 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
861 // Save changes to underlying image. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
862 m_img.syncPixels (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
863 imvec.push_back (m_img); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
864 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
865 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
866 |
8054 | 867 static void |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
868 encode_bool_image (std::vector<Magick::Image>& imvec, const boolNDArray& img) |
7974 | 869 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
870 const octave_idx_type nFrames = img.ndims () < 4 ? 1 : img.dims ()(3); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
871 const octave_idx_type nRows = img.rows (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
872 const octave_idx_type nCols = img.columns (); |
8054 | 873 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
874 // The initialized image will be black, this is for the other pixels |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
875 const Magick::Color white ("white"); |
8054 | 876 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
877 const bool *img_fvec = img.fortran_vec (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
878 octave_idx_type img_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
879 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
8054 | 880 { |
17333
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
881 // For some reason, we can't set the type to Magick::BilevelType or |
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
882 // the output image will be black, changing to white has no effect. |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
883 // However, this will still work fine and a binary image will be |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
884 // saved because we are setting the bitdepth to 1. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
885 Magick::Image m_img = init_enconde_image (nCols, nRows, 1, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
886 Magick::GrayscaleType, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
887 Magick::DirectClass); |
8054 | 888 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
889 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
890 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
891 for (octave_idx_type col = 0; col < nCols; col++) |
8054 | 892 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
893 for (octave_idx_type row = 0; row < nRows; row++) |
8054 | 894 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
895 if (img_fvec[img_idx]) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
896 pix[GM_idx] = white; |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
897 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
898 img_idx++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
899 GM_idx += nCols; |
8054 | 900 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
901 GM_idx -= nCols * nRows - 1; |
8054 | 902 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
903 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
904 m_img.syncPixels (); |
17333
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
905 // While we could not set it to Bilevel at the start, we can do it |
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
906 // here otherwise some coders won't save it as binary. |
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
907 m_img.type (Magick::BilevelType); |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
908 imvec.push_back (m_img); |
8054 | 909 } |
910 } | |
911 | |
912 template <class T> | |
913 static void | |
914 encode_uint_image (std::vector<Magick::Image>& imvec, | |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
915 const T& img, const T& alpha) |
8054 | 916 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
917 typedef typename T::element_type P; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
918 const octave_idx_type channels = img.ndims () < 3 ? 1 : img.dims ()(2); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
919 const octave_idx_type nFrames = img.ndims () < 4 ? 1 : img.dims ()(3); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
920 const octave_idx_type nRows = img.rows (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
921 const octave_idx_type nCols = img.columns (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
922 const octave_idx_type bitdepth = bitdepth_from_class<T> (); |
8054 | 923 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
924 Magick::ImageType type; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
925 const bool has_alpha = ! alpha.is_empty (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
926 switch (channels) |
8054 | 927 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
928 case 1: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
929 if (has_alpha) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
930 type = Magick::GrayscaleMatteType; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
931 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
932 type = Magick::GrayscaleType; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
933 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
934 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
935 case 3: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
936 if (has_alpha) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
937 type = Magick::TrueColorMatteType; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
938 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
939 type = Magick::TrueColorType; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
940 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
941 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
942 case 4: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
943 if (has_alpha) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
944 type = Magick::ColorSeparationMatteType; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
945 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
946 type = Magick::ColorSeparationType; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
947 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
948 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
949 default: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
950 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
951 // __imwrite should have already filtered this cases |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
952 error ("__magick_write__: wrong size on 3rd dimension"); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
953 return; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
954 } |
8054 | 955 } |
956 | |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
957 // We will be passing the values as integers with depth as specified |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
958 // by QuantumDepth (maximum value specified by MaxRGB). This is independent |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
959 // of the actual depth of the image. GM will then convert the values but |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
960 // while in memory, it always keeps the values as specified by QuantumDepth. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
961 // From GM documentation: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
962 // Color arguments are must be scaled to fit the Quantum size according to |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
963 // the range of MaxRGB |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
964 const double divisor = (pow (2, bitdepth) - 1) / MaxRGB; |
8054 | 965 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
966 const P *img_fvec = img.fortran_vec (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
967 const P *a_fvec = alpha.fortran_vec (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
968 switch (type) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
969 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
970 case Magick::GrayscaleType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
971 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
972 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
973 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
974 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
975 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
976 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
977 Magick::DirectClass); |
8054 | 978 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
979 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
980 for (octave_idx_type col = 0; col < nCols; col++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
981 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
982 for (octave_idx_type row = 0; row < nRows; row++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
983 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
984 Magick::Color c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
985 c.redQuantum (double (*img_fvec) / divisor); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
986 pix[GM_idx] = c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
987 img_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
988 GM_idx += nCols; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
989 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
990 GM_idx -= nCols * nRows - 1; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
991 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
992 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
993 m_img.syncPixels (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
994 imvec.push_back (m_img); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
995 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
996 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
997 } |
8054 | 998 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
999 case Magick::GrayscaleMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1000 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1001 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1002 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1003 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1004 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1005 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1006 Magick::DirectClass); |
7974 | 1007 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1008 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1009 for (octave_idx_type col = 0; col < nCols; col++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1010 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1011 for (octave_idx_type row = 0; row < nRows; row++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1012 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1013 Magick::Color c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1014 c.redQuantum (double (*img_fvec) / divisor); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1015 c.alphaQuantum (MaxRGB - (double (*a_fvec) / divisor)); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1016 pix[GM_idx] = c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1017 img_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1018 a_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1019 GM_idx += nCols; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1020 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1021 GM_idx -= nCols * nRows - 1; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1022 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1023 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1024 m_img.syncPixels (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1025 imvec.push_back (m_img); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1026 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1027 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1028 } |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1029 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1030 case Magick::TrueColorType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1031 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1032 // The fortran_vec offset for the green and blue channels |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1033 const octave_idx_type G_offset = nCols * nRows; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1034 const octave_idx_type B_offset = nCols * nRows * 2; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1035 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1036 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1037 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1038 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1039 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1040 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1041 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1042 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1043 for (octave_idx_type col = 0; col < nCols; col++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1044 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1045 for (octave_idx_type row = 0; row < nRows; row++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1046 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1047 Magick::Color c (double (*img_fvec) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1048 double (img_fvec[G_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1049 double (img_fvec[B_offset]) / divisor); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1050 pix[GM_idx] = c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1051 img_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1052 GM_idx += nCols; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1053 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1054 GM_idx -= nCols * nRows - 1; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1055 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1056 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1057 m_img.syncPixels (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1058 imvec.push_back (m_img); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1059 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1060 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1061 } |
8054 | 1062 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1063 case Magick::TrueColorMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1064 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1065 // The fortran_vec offset for the green and blue channels |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1066 const octave_idx_type G_offset = nCols * nRows; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1067 const octave_idx_type B_offset = nCols * nRows * 2; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1068 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1069 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1070 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1071 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1072 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1073 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1074 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1075 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1076 for (octave_idx_type col = 0; col < nCols; col++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1077 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1078 for (octave_idx_type row = 0; row < nRows; row++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1079 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1080 Magick::Color c (double (*img_fvec) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1081 double (img_fvec[G_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1082 double (img_fvec[B_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1083 MaxRGB - (double (*a_fvec) / divisor)); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1084 pix[GM_idx] = c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1085 img_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1086 a_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1087 GM_idx += nCols; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1088 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1089 GM_idx -= nCols * nRows - 1; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1090 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1091 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1092 m_img.syncPixels (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1093 imvec.push_back (m_img); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1094 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1095 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1096 } |
8054 | 1097 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1098 case Magick::ColorSeparationType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1099 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1100 // The fortran_vec offset for the Magenta, Yellow, and blacK channels |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1101 const octave_idx_type M_offset = nCols * nRows; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1102 const octave_idx_type Y_offset = nCols * nRows * 2; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1103 const octave_idx_type K_offset = nCols * nRows * 3; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1104 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1105 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1106 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1107 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1108 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1109 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1110 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1111 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1112 for (octave_idx_type col = 0; col < nCols; col++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1113 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1114 for (octave_idx_type row = 0; row < nRows; row++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1115 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1116 Magick::Color c (double (*img_fvec) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1117 double (img_fvec[M_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1118 double (img_fvec[Y_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1119 double (img_fvec[K_offset]) / divisor); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1120 pix[GM_idx] = c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1121 img_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1122 GM_idx += nCols; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1123 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1124 GM_idx -= nCols * nRows - 1; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1125 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1126 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1127 m_img.syncPixels (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1128 imvec.push_back (m_img); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1129 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1130 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1131 } |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1132 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1133 case Magick::ColorSeparationMatteType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1134 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1135 // The fortran_vec offset for the Magenta, Yellow, and blacK channels |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1136 const octave_idx_type M_offset = nCols * nRows; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1137 const octave_idx_type Y_offset = nCols * nRows * 2; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1138 const octave_idx_type K_offset = nCols * nRows * 3; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1139 octave_idx_type GM_idx = 0; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1140 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1141 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1142 Magick::Image m_img = init_enconde_image (nCols, nRows, bitdepth, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1143 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1144 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1145 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1146 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1147 Magick::IndexPacket *ind = m_img.getIndexes (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1148 for (octave_idx_type col = 0; col < nCols; col++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1149 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1150 for (octave_idx_type row = 0; row < nRows; row++) |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1151 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1152 Magick::Color c (double (*img_fvec) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1153 double (img_fvec[M_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1154 double (img_fvec[Y_offset]) / divisor, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1155 double (img_fvec[K_offset]) / divisor); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1156 pix[GM_idx] = c; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1157 ind[GM_idx] = MaxRGB - (double (*a_fvec) / divisor); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1158 img_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1159 a_fvec++; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1160 GM_idx += nCols; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1161 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1162 GM_idx -= nCols * nRows - 1; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1163 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1164 // Save changes to underlying image. |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1165 m_img.syncPixels (); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1166 imvec.push_back (m_img); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1167 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1168 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1169 } |
11034
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
1170 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1171 default: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1172 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1173 error ("__magick_write__: unrecognized Magick::ImageType"); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1174 return; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1175 } |
8054 | 1176 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1177 return; |
8054 | 1178 } |
1179 | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1180 void static |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1181 write_file (const std::string& filename, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1182 const std::string& ext, |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1183 std::vector<Magick::Image>& imvec) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1184 { |
7974 | 1185 try |
1186 { | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1187 Magick::writeImages (imvec.begin (), imvec.end (), ext + ":" + filename); |
7974 | 1188 } |
1189 catch (Magick::Warning& w) | |
1190 { | |
1191 warning ("Magick++ warning: %s", w.what ()); | |
1192 } | |
1193 catch (Magick::ErrorCoder& e) | |
1194 { | |
1195 warning ("Magick++ coder error: %s", e.what ()); | |
1196 } | |
1197 catch (Magick::Exception& e) | |
1198 { | |
1199 error ("Magick++ exception: %s", e.what ()); | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1200 error_state = 1; |
7974 | 1201 } |
1202 } | |
1203 | |
1204 #endif | |
1205 | |
9436
5302df15ad76
__magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents:
9434
diff
changeset
|
1206 DEFUN_DLD (__magick_write__, args, , |
7974 | 1207 "-*- texinfo -*-\n\ |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1208 @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
|
1209 Write image with GraphicsMagick or ImageMagick.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1210 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1211 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
|
1212 use @code{imwrite}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1213 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1214 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
7974 | 1215 @end deftypefn") |
1216 { | |
1217 octave_value_list retval; | |
1218 | |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1219 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1220 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
|
1221 #else |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1222 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1223 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1224 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1225 if (args.length () != 5 || ! args(0).is_string () || ! args(1).is_string ()) |
7974 | 1226 { |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1227 print_usage (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1228 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1229 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1230 const std::string filename = args(0).string_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1231 const std::string ext = args(1).string_value (); |
7974 | 1232 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1233 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
|
1234 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1235 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1236 error ("__magick_write__: OPTIONS must be a struct"); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1237 return retval; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1238 } |
7974 | 1239 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1240 const octave_value img = args(2); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1241 const Matrix cmap = args(3).matrix_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1242 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1243 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1244 error ("__magick_write__: invalid IMG or MAP"); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1245 return retval; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1246 } |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1247 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1248 std::vector<Magick::Image> imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1249 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1250 if (cmap.is_empty ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1251 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1252 const octave_value alpha = options.getfield ("alpha"); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1253 if (img.is_bool_type ()) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1254 encode_bool_image (imvec, img.bool_array_value ()); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1255 else if (img.is_uint8_type ()) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1256 encode_uint_image<uint8NDArray> (imvec, img.uint8_array_value (), |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1257 alpha.uint8_array_value ()); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1258 else if (img.is_uint16_type ()) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1259 encode_uint_image<uint16NDArray> (imvec, img.uint16_array_value (), |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1260 alpha.uint16_array_value ()); |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1261 else if (img.is_uint32_type ()) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1262 encode_uint_image<uint32NDArray> (imvec, img.uint32_array_value (), |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1263 alpha.uint32_array_value ()); |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1264 else if (img.is_float_type ()) |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1265 { |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1266 // For image formats that support floating point values, we write |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1267 // the actual values. For those who don't, we only use the values |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1268 // on the range [0 1] and save integer values. |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1269 // But here, even for formats that would support floating point |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1270 // values, GM seems unable to do that so we at least make them uint32. |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1271 uint32NDArray clip_img; |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1272 uint32NDArray clip_alpha; |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1273 if (img.is_single_type ()) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1274 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1275 clip_img = img_float2uint<FloatNDArray> (img.float_array_value ()); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1276 clip_alpha = img_float2uint<FloatNDArray> (alpha.float_array_value ()); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1277 } |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1278 else |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1279 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1280 clip_img = img_float2uint<NDArray> (img.array_value ()); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1281 clip_alpha = img_float2uint<NDArray> (alpha.array_value ()); |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1282 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1283 encode_uint_image<uint32NDArray> (imvec, clip_img, clip_alpha); |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1284 } |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1285 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1286 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1287 error ("__magick_write__: image type not supported"); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1288 return retval; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1289 } |
7974 | 1290 } |
1291 else | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1292 { |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1293 // 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
|
1294 // 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
|
1295 // but it would look much messier. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1296 if (img.is_uint8_type ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1297 encode_indexed_images<uint8NDArray> (imvec, img.uint8_array_value (), |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1298 cmap); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1299 else if (img.is_uint16_type ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1300 encode_indexed_images<uint16NDArray> (imvec, img.uint16_array_value (), |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1301 cmap); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1302 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1303 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1304 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
|
1305 return retval; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1306 } |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1307 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1308 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1309 const octave_idx_type nFrames = imvec.size (); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1310 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1311 // 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
|
1312 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
|
1313 for (octave_idx_type i = 0; i < nFrames; i++) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1314 imvec[i].quality (quality); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1315 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1316 // 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
|
1317 // 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
|
1318 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
|
1319 if (writemode == "append" && file_stat (filename).exists ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1320 { |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1321 std::vector<Magick::Image> ini_imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1322 read_file (filename, ini_imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1323 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1324 return retval; |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1325 if (ini_imvec.size () > 0) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1326 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1327 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
|
1328 ini_imvec.swap (imvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1329 } |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1330 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1331 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1332 write_file (filename, ext, imvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1333 if (error_state) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1334 return retval; |
7974 | 1335 |
1336 #endif | |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1337 return retval; |
7974 | 1338 } |
1339 | |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1340 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1341 ## 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
|
1342 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1343 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1344 |
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
|
1345 #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
|
1346 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1347 template<class T> |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1348 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1349 magick_to_octave_value (const T magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1350 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1351 return octave_value (magick); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1352 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1353 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1354 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1355 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
|
1356 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1357 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1358 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1359 case Magick::LSBEndian: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1360 return octave_value ("little-endian"); |
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 case Magick::MSBEndian: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1363 return octave_value ("big-endian"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1364 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1365 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1366 return octave_value ("undefined"); |
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 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1369 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1370 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1371 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
|
1372 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1373 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1374 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1375 case Magick::PixelsPerInchResolution: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1376 return octave_value ("pixels per inch"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1377 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1378 case Magick::PixelsPerCentimeterResolution: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1379 return octave_value ("pixels per centimeter"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1380 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1381 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1382 return octave_value ("undefined"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1383 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1384 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1385 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1386 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1387 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
|
1388 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1389 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1390 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1391 case Magick::BilevelType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1392 case Magick::GrayscaleType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1393 case Magick::GrayscaleMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1394 return octave_value ("grayscale"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1395 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1396 case Magick::PaletteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1397 case Magick::PaletteMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1398 return octave_value ("indexed"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1399 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1400 case Magick::TrueColorType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1401 case Magick::TrueColorMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1402 case Magick::ColorSeparationType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1403 return octave_value ("truecolor"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1404 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1405 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1406 return octave_value ("undefined"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1407 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1408 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1409 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1410 // 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
|
1411 // 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
|
1412 #define GET_PARAM(NAME, OUTNAME) \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1413 try \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1414 { \ |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1415 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
|
1416 } \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1417 catch (Magick::Warning& w) \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1418 { \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1419 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1420 |
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
|
1421 #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
|
1422 |
9436
5302df15ad76
__magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents:
9434
diff
changeset
|
1423 DEFUN_DLD (__magick_finfo__, args, , |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1424 "-*- 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
|
1425 @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
|
1426 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
|
1427 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1428 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
|
1429 use @code{imfinfo}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1430 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1431 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1432 @end deftypefn") |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1433 { |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1434 octave_value retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1435 |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1436 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1437 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
|
1438 #else |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1439 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1440 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1441 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1442 if (args.length () < 1 || ! args(0).is_string ()) |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1443 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1444 print_usage (); |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1445 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1446 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1447 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1448 const std::string filename = args(0).string_value (); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1449 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1450 try |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1451 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1452 // Read the file. |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1453 std::vector<Magick::Image> imvec; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1454 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
|
1455 int nframes = imvec.size (); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1456 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1457 // 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
|
1458 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1459 static const char *fields[] = |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1460 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1461 "Filename", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1462 "FileModDate", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1463 "FileSize", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1464 "Height", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1465 "Width", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1466 "BitDepth", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1467 "Format", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1468 "LongFormat", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1469 "XResolution", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1470 "YResolution", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1471 "TotalColors", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1472 "TileName", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1473 "AnimationDelay", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1474 "AnimationIterations", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1475 "ByteOrder", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1476 "Gamma", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1477 "Matte", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1478 "ModulusDepth", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1479 "Quality", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1480 "QuantizeColors", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1481 "ResolutionUnits", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1482 "ColorType", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1483 "View", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1484 0 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1485 }; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1486 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16543
diff
changeset
|
1487 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
|
1488 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1489 file_stat fs (filename); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1490 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1491 std::string filetime; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1492 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1493 if (fs) |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1494 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1495 octave_localtime mtime = fs.mtime (); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1496 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1497 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
|
1498 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1499 else |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1500 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1501 std::string msg = fs.error (); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1502 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14173
diff
changeset
|
1503 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
|
1504 filename.c_str (), msg.c_str ()); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1505 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1506 return retval; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1507 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1508 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1509 // 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
|
1510 // 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
|
1511 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
|
1512 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1513 Magick::Image im = imvec[frame]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1514 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1515 // Add file name and timestamp. |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1516 info.contents ("Filename")(frame,0) = filename; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1517 info.contents ("FileModDate")(frame,0) = filetime; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1518 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1519 // 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
|
1520 GET_PARAM (fileSize, "FileSize") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1521 GET_PARAM (rows, "Height") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1522 GET_PARAM (columns, "Width") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1523 GET_PARAM (depth, "BitDepth") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1524 GET_PARAM (magick, "Format") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1525 GET_PARAM (format, "LongFormat") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1526 GET_PARAM (xResolution, "XResolution") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1527 GET_PARAM (yResolution, "YResolution") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1528 GET_PARAM (totalColors, "TotalColors") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1529 GET_PARAM (tileName, "TileName") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1530 GET_PARAM (animationDelay, "AnimationDelay") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1531 GET_PARAM (animationIterations, "AnimationIterations") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1532 GET_PARAM (endian, "ByteOrder") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1533 GET_PARAM (gamma, "Gamma") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1534 GET_PARAM (matte, "Matte") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1535 GET_PARAM (modulusDepth, "ModulusDepth") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1536 GET_PARAM (quality, "Quality") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1537 GET_PARAM (quantizeColors, "QuantizeColors") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1538 GET_PARAM (resolutionUnits, "ResolutionUnits") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1539 GET_PARAM (type, "ColorType") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1540 GET_PARAM (view, "View") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1541 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1542 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1543 retval = octave_value (info); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1544 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1545 catch (Magick::Warning& w) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1546 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1547 warning ("Magick++ warning: %s", w.what ()); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1548 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1549 catch (Magick::ErrorCoder& e) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1550 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1551 warning ("Magick++ coder error: %s", e.what ()); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1552 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1553 catch (Magick::Exception& e) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1554 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1555 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
|
1556 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1557 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1558 #endif |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1559 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1560 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1561 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1562 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1563 ## 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
|
1564 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1565 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1566 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1567 #undef GET_PARAM |
11035
8a6b7947f618
Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents:
11034
diff
changeset
|
1568 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1569 DEFUN_DLD (__magick_formats__, args, , |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1570 "-*- texinfo -*-\n\ |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1571 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\ |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1572 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
|
1573 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1574 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1575 @end deftypefn") |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1576 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1577 octave_value retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1578 #ifndef HAVE_MAGICK |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1579 gripe_disabled_feature ("imformats", "Image IO"); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1580 #else |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1581 if (args.length () != 1 || ! args(0).is_map ()) |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1582 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1583 print_usage (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1584 return retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1585 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1586 octave_map formats = args(0).map_value (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1587 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1588 maybe_initialize_magick (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1589 for (octave_idx_type idx = 0; idx < formats.numel (); idx++) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1590 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1591 try |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1592 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1593 octave_scalar_map fmt = formats.checkelem (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1594 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1595 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1596 fmt.setfield ("description", octave_value (coder.description ())); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1597 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1598 // 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
|
1599 // read or write them, them set it to an empty value |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1600 if (! coder.isReadable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1601 fmt.setfield ("read", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1602 if (! coder.isWritable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1603 fmt.setfield ("write", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1604 formats.fast_elem_insert (idx, fmt); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1605 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1606 catch (Magick::Exception& e) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1607 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1608 // Exception here are missing formats. So we remove the format |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1609 // from the structure and reduce idx. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1610 formats.delete_elements (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1611 idx--; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1612 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1613 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1614 retval = formats; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1615 #endif |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1616 return retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1617 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1618 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1619 /* |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1620 ## No test needed for internal helper function. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1621 %!assert (1) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1622 */ |