Mercurial > octave-nkf
annotate libinterp/dldfcn/__magick_read__.cc @ 17334:f8ee0ed7f1b8
Fix reading of binary images.
* __magick_read__.cc (__magick_read__): since depth() seems to not always
give 1 for binary images, check the depth of multiple channels to confirm.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:24:21 +0100 |
parents | 51c011825bcc |
children | 583306fe7e4f |
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 |
17334
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
671 // FIXME: the depth here is not always correct for us but seems to be the best |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
672 // value we can get. For example, a grayscale png image with 1 bit |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
673 // per channel should return a depth of 1 but instead we get 8. |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
674 // We could check channelDepth() but then, which channel has the data |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
675 // is not straightforward. So we'd have to check all |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
676 // the channels and select the highest value. But then, I also |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
677 // have a 16bit TIFF whose depth returns 16 (correct), but all of the |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
678 // channels gives 8 (wrong). No idea why, maybe a bug in GM? |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
679 // Anyway, using depth() seems that only causes problems for binary |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
680 // images, and the problem with channelDepth() is not making set them |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
681 // all to 1. So we will guess that if all channels have depth of 1, |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
682 // then we must have a binary image. |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
683 // Note that we can't use AllChannels it doesn't work for this. |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
684 // Instead of checking all of the individual channels, we check one |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
685 // from RGB, CMYK, grayscale, and transparency. |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
686 octave_idx_type depth = imvec[frameidx(0)].depth (); |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
687 if (depth != 1 |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
688 && imvec[frameidx(0)].channelDepth (Magick::RedChannel) == 1 |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
689 && imvec[frameidx(0)].channelDepth (Magick::CyanChannel) == 1 |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
690 && imvec[frameidx(0)].channelDepth (Magick::OpacityChannel) == 1 |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
691 && imvec[frameidx(0)].channelDepth (Magick::GrayChannel) == 1) |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
692 depth = 1; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
693 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
694 // Magick::ClassType |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
695 // PseudoClass: |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
696 // 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
|
697 // DirectClass: |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
698 // 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
|
699 |
17334
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
700 Magick::ClassType klass = imvec[frameidx(0)].classType (); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
701 // 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
|
702 // 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
|
703 // 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
|
704 // 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
|
705 // 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
|
706 // 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
|
707 // https://sourceforge.net/mailarchive/message.php?msg_id=31180507 |
17334
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
708 // In addition to the ClassType, there is also ImageType which has a |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
709 // type for indexed images (PaletteType and PaletteMatteType). However, |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
710 // they also don't represent the original image. Interestingly, one |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
711 // would at least guess that PseudoClass would include only the Palette |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
712 // types but that does not happen. |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
713 // |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
714 // We can't do better without having format specific code which is |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
715 // what we are trying to avoid by using a library such as GM. We at |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
716 // least create workarounds for the most common problems. |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
717 |
17334
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
718 // 1) A grayscale jpeg image can report being indexed even though the |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
719 // JPEG format has no support for indexed images. We can at least |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
720 // fix this one. |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
721 if (klass == Magick::PseudoClass && imvec[0].magick () == "JPEG") |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
722 klass = Magick::DirectClass; |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
723 |
f8ee0ed7f1b8
Fix reading of binary images.
Carnë Draug <carandraug@octave.org>
parents:
17333
diff
changeset
|
724 if (klass == Magick::PseudoClass) |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
725 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
726 if (depth <= 1) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
727 output = read_indexed_images<boolNDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
728 nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
729 else if (depth <= 8) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
730 output = read_indexed_images<uint8NDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
731 nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
732 else if (depth <= 16) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
733 output = read_indexed_images<uint16NDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
734 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
|
735 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
736 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
737 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
|
738 return output; |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
739 } |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
740 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
741 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
742 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
743 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
744 if (depth <= 1) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
745 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
|
746 else if (depth <= 8) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
747 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
|
748 else if (depth <= 16) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
749 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
|
750 else if (depth <= 32) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
751 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
|
752 else |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
753 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
754 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
|
755 depth); |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
756 } |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
757 } |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
758 |
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
759 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
760 return output; |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
761 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
762 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
763 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
764 ## 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
|
765 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
766 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
767 |
7974 | 768 #ifdef HAVE_MAGICK |
769 | |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
770 template <class T> |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
771 static uint32NDArray |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
772 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
|
773 { |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
774 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
|
775 uint32NDArray out (img.dims ()); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
776 |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
777 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
|
778 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
|
779 |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
780 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
|
781 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
|
782 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
|
783 out_fvec[idx] = img_fvec[idx] * max; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
784 |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
785 return out; |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
786 } |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
787 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
788 // 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
|
789 // 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
|
790 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
|
791 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
|
792 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
|
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 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
|
795 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
|
796 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
|
797 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
|
798 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
799 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
806 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
|
807 // 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
|
808 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
|
809 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
810 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
|
811 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
|
812 // 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
|
813 // 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
|
814 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
|
815 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
|
816 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
823 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
824 default: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
825 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
|
826 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
827 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
828 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
|
829 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
830 |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
831 template <class T> |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
832 static void |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
833 encode_indexed_images (std::vector<Magick::Image>& imvec, |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
834 const T& img, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
835 const Matrix& cmap) |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
836 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
837 typedef typename T::element_type P; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
838 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
|
839 const octave_idx_type nRows = img.rows (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
840 const octave_idx_type nCols = img.columns (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
841 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
|
842 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
|
843 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
844 // 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
|
845 // 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
|
846 std::vector<Magick::ColorRGB> colormap; |
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 const double* cmap_fvec = cmap.fortran_vec (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
849 const octave_idx_type G_offset = cmap_size; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
850 const octave_idx_type B_offset = cmap_size * 2; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
851 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
|
852 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
|
853 cmap_fvec[map_idx + G_offset], |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
854 cmap_fvec[map_idx + B_offset])); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
855 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
856 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
857 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
858 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
859 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
|
860 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
|
861 Magick::PseudoClass); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
862 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
863 // Insert colormap. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
864 m_img.colorMapSize (cmap_size); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
865 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
|
866 m_img.colorMap (map_idx, colormap[map_idx]); |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
867 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
868 // 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
|
869 // 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
|
870 // 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
|
871 // 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
|
872 // 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
|
873 // 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
|
874 // 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
|
875 // 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
|
876 // 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
|
877 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
|
878 Magick::IndexPacket* ind = m_img.getIndexes (); |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
879 const P* img_fvec = img.fortran_vec (); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
880 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
881 octave_idx_type GM_idx = 0; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
882 for (octave_idx_type column = 0; column < nCols; column++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
883 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
884 for (octave_idx_type row = 0; row < nRows; row++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
885 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
886 ind[GM_idx] = double (*img_fvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
887 pix[GM_idx] = m_img.colorMap (double (*img_fvec)); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
888 img_fvec++; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
889 GM_idx += nCols; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
890 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
891 GM_idx -= nCols * nRows - 1; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
892 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
893 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
894 // Save changes to underlying image. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
895 m_img.syncPixels (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
896 imvec.push_back (m_img); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
897 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
898 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
899 |
8054 | 900 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
|
901 encode_bool_image (std::vector<Magick::Image>& imvec, const boolNDArray& img) |
7974 | 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 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
|
904 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
|
905 const octave_idx_type nCols = img.columns (); |
8054 | 906 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
907 // 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
|
908 const Magick::Color white ("white"); |
8054 | 909 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
910 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
|
911 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
|
912 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
8054 | 913 { |
17333
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
914 // 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
|
915 // 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
|
916 // 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
|
917 // 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
|
918 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
|
919 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
|
920 Magick::DirectClass); |
8054 | 921 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
922 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
|
923 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
|
924 for (octave_idx_type col = 0; col < nCols; col++) |
8054 | 925 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
926 for (octave_idx_type row = 0; row < nRows; row++) |
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 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
|
929 pix[GM_idx] = white; |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
930 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
931 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
|
932 GM_idx += nCols; |
8054 | 933 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
934 GM_idx -= nCols * nRows - 1; |
8054 | 935 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
936 // 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
|
937 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
|
938 // 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
|
939 // 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
|
940 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
|
941 imvec.push_back (m_img); |
8054 | 942 } |
943 } | |
944 | |
945 template <class T> | |
946 static void | |
947 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
|
948 const T& img, const T& alpha) |
8054 | 949 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 const octave_idx_type bitdepth = bitdepth_from_class<T> (); |
8054 | 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 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
|
958 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
|
959 switch (channels) |
8054 | 960 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
961 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
|
962 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
|
963 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
|
964 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
965 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
|
966 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
967 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
968 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
|
969 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
|
970 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
|
971 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
972 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
|
973 break; |
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 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
|
976 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
|
977 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
|
978 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
979 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
|
980 break; |
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 default: |
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 // __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
|
985 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
|
986 return; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
987 } |
8054 | 988 } |
989 | |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
990 // 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
|
991 // 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
|
992 // 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
|
993 // 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
|
994 // 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
|
995 // 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
|
996 // 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
|
997 const double divisor = (pow (2, bitdepth) - 1) / MaxRGB; |
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 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
|
1000 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
|
1001 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
|
1002 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1003 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
|
1004 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1005 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
|
1006 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
|
1007 { |
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::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
|
1009 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1010 Magick::DirectClass); |
8054 | 1011 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1012 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
|
1013 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
|
1014 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1015 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
|
1016 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1017 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
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
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 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
|
1024 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1025 // 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
|
1026 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
|
1027 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
|
1028 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1029 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1030 } |
8054 | 1031 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1032 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
|
1033 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1034 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
|
1035 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
|
1036 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1037 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
|
1038 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1039 Magick::DirectClass); |
7974 | 1040 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1041 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
|
1042 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
|
1043 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1044 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
|
1045 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1046 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
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
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 } |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
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::TrueColorType: |
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 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
|
1084 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
|
1085 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
|
1086 } |
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 * 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
|
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 // 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
|
1090 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
|
1091 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
|
1092 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1093 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1094 } |
8054 | 1095 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1096 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
|
1097 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1098 // 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
|
1099 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
|
1100 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
|
1101 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
|
1102 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
|
1103 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1104 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
|
1105 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1106 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1107 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1108 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
|
1109 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
|
1110 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1111 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
|
1112 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 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
|
1119 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
|
1120 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
|
1121 } |
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 * 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
|
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 // 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
|
1125 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
|
1126 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
|
1127 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1128 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1129 } |
8054 | 1130 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1131 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
|
1132 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1133 // 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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 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
|
1139 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1140 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
|
1141 type, |
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::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1143 |
17332
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::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
|
1145 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
|
1146 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1147 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
|
1148 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1149 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
|
1150 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
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1157 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
|
1158 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1159 // 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
|
1160 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
|
1161 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
|
1162 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1163 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1164 } |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1165 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1166 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
|
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 // 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
|
1169 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
|
1170 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
|
1171 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
|
1172 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
|
1173 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
|
1174 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1175 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
|
1176 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1177 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1178 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1179 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
|
1180 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
|
1181 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
|
1182 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1183 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
|
1184 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1185 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
|
1186 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
|
1187 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
|
1188 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
|
1189 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
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1195 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
|
1196 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1197 // 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
|
1198 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
|
1199 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
|
1200 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1201 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1202 } |
11034
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
diff
changeset
|
1203 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1204 default: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1205 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1206 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
|
1207 return; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1208 } |
8054 | 1209 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1210 return; |
8054 | 1211 } |
1212 | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1213 void static |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1214 write_file (const std::string& filename, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1215 const std::string& ext, |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1216 std::vector<Magick::Image>& imvec) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1217 { |
7974 | 1218 try |
1219 { | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1220 Magick::writeImages (imvec.begin (), imvec.end (), ext + ":" + filename); |
7974 | 1221 } |
1222 catch (Magick::Warning& w) | |
1223 { | |
1224 warning ("Magick++ warning: %s", w.what ()); | |
1225 } | |
1226 catch (Magick::ErrorCoder& e) | |
1227 { | |
1228 warning ("Magick++ coder error: %s", e.what ()); | |
1229 } | |
1230 catch (Magick::Exception& e) | |
1231 { | |
1232 error ("Magick++ exception: %s", e.what ()); | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1233 error_state = 1; |
7974 | 1234 } |
1235 } | |
1236 | |
1237 #endif | |
1238 | |
9436
5302df15ad76
__magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents:
9434
diff
changeset
|
1239 DEFUN_DLD (__magick_write__, args, , |
7974 | 1240 "-*- texinfo -*-\n\ |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1241 @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
|
1242 Write image with GraphicsMagick or ImageMagick.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1243 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1244 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
|
1245 use @code{imwrite}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1246 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1247 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
7974 | 1248 @end deftypefn") |
1249 { | |
1250 octave_value_list retval; | |
1251 | |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1252 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1253 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
|
1254 #else |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1255 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1256 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1257 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1258 if (args.length () != 5 || ! args(0).is_string () || ! args(1).is_string ()) |
7974 | 1259 { |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1260 print_usage (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1261 return retval; |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1262 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1263 const std::string filename = args(0).string_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1264 const std::string ext = args(1).string_value (); |
7974 | 1265 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1266 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
|
1267 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1268 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1269 error ("__magick_write__: OPTIONS must be a struct"); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1270 return retval; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1271 } |
7974 | 1272 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1273 const octave_value img = args(2); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1274 const Matrix cmap = args(3).matrix_value (); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1275 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1276 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1277 error ("__magick_write__: invalid IMG or MAP"); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1278 return retval; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1279 } |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1280 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1281 std::vector<Magick::Image> imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1282 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1283 if (cmap.is_empty ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1284 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1285 const octave_value alpha = options.getfield ("alpha"); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1286 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
|
1287 encode_bool_image (imvec, img.bool_array_value ()); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1288 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
|
1289 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
|
1290 alpha.uint8_array_value ()); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 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
|
1298 { |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1299 // 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
|
1300 // 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
|
1301 // 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
|
1302 // 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
|
1303 // 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
|
1304 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
|
1305 uint32NDArray clip_alpha; |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1306 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
|
1307 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1308 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
|
1309 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
|
1310 } |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1311 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
|
1312 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1313 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
|
1314 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
|
1315 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1316 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
|
1317 } |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1318 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1319 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1320 error ("__magick_write__: image type not supported"); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1321 return retval; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1322 } |
7974 | 1323 } |
1324 else | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1325 { |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1326 // 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
|
1327 // 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
|
1328 // but it would look much messier. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1329 if (img.is_uint8_type ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1330 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
|
1331 cmap); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1332 else if (img.is_uint16_type ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1333 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
|
1334 cmap); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1335 else |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1336 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1337 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
|
1338 return retval; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1339 } |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1340 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1341 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1342 const octave_idx_type nFrames = imvec.size (); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1343 |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1344 // 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
|
1345 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
|
1346 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
|
1347 imvec[i].quality (quality); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1348 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1349 // 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
|
1350 // 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
|
1351 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
|
1352 if (writemode == "append" && file_stat (filename).exists ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1353 { |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1354 std::vector<Magick::Image> ini_imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1355 read_file (filename, ini_imvec); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1356 if (error_state) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1357 return retval; |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1358 if (ini_imvec.size () > 0) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1359 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1360 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
|
1361 ini_imvec.swap (imvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1362 } |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1363 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1364 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1365 write_file (filename, ext, imvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1366 if (error_state) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1367 return retval; |
7974 | 1368 |
1369 #endif | |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1370 return retval; |
7974 | 1371 } |
1372 | |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1373 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1374 ## 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
|
1375 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1376 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1377 |
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
|
1378 #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
|
1379 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1380 template<class T> |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1381 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1382 magick_to_octave_value (const T magick) |
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 return octave_value (magick); |
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 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1387 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1388 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
|
1389 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1390 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1391 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1392 case Magick::LSBEndian: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1393 return octave_value ("little-endian"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1394 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1395 case Magick::MSBEndian: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1396 return octave_value ("big-endian"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1397 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1398 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1399 return octave_value ("undefined"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1400 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1401 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1402 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1403 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1404 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
|
1405 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1406 switch (magick) |
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 case Magick::PixelsPerInchResolution: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1409 return octave_value ("pixels per inch"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1410 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1411 case Magick::PixelsPerCentimeterResolution: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1412 return octave_value ("pixels per centimeter"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1413 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1414 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1415 return octave_value ("undefined"); |
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 } |
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 static octave_value |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1420 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
|
1421 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1422 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1423 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1424 case Magick::BilevelType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1425 case Magick::GrayscaleType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1426 case Magick::GrayscaleMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1427 return octave_value ("grayscale"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1428 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1429 case Magick::PaletteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1430 case Magick::PaletteMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1431 return octave_value ("indexed"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1432 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1433 case Magick::TrueColorType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1434 case Magick::TrueColorMatteType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1435 case Magick::ColorSeparationType: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1436 return octave_value ("truecolor"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1437 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1438 default: |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1439 return octave_value ("undefined"); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1440 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1441 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1442 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1443 // 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
|
1444 // 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
|
1445 #define GET_PARAM(NAME, OUTNAME) \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1446 try \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1447 { \ |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1448 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
|
1449 } \ |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1450 catch (Magick::Warning& w) \ |
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 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1453 |
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
|
1454 #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
|
1455 |
9436
5302df15ad76
__magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents:
9434
diff
changeset
|
1456 DEFUN_DLD (__magick_finfo__, args, , |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1457 "-*- 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
|
1458 @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
|
1459 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
|
1460 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1461 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
|
1462 use @code{imfinfo}.\n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1463 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1464 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1465 @end deftypefn") |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1466 { |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1467 octave_value retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1468 |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1469 #ifndef HAVE_MAGICK |
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1470 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
|
1471 #else |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1472 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1473 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1474 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1475 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
|
1476 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1477 print_usage (); |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1478 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1479 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1480 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1481 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
|
1482 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1483 try |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1484 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1485 // Read the file. |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1486 std::vector<Magick::Image> imvec; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1487 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
|
1488 int nframes = imvec.size (); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1489 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1490 // 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
|
1491 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1492 static const char *fields[] = |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1493 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1494 "Filename", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1495 "FileModDate", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1496 "FileSize", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1497 "Height", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1498 "Width", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1499 "BitDepth", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1500 "Format", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1501 "LongFormat", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1502 "XResolution", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1503 "YResolution", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1504 "TotalColors", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1505 "TileName", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1506 "AnimationDelay", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1507 "AnimationIterations", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1508 "ByteOrder", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1509 "Gamma", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1510 "Matte", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1511 "ModulusDepth", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1512 "Quality", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1513 "QuantizeColors", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1514 "ResolutionUnits", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1515 "ColorType", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1516 "View", |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1517 0 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1518 }; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1519 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16543
diff
changeset
|
1520 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
|
1521 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1522 file_stat fs (filename); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1523 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1524 std::string filetime; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1525 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1526 if (fs) |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1527 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1528 octave_localtime mtime = fs.mtime (); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1529 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1530 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
|
1531 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1532 else |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1533 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1534 std::string msg = fs.error (); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1535 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14173
diff
changeset
|
1536 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
|
1537 filename.c_str (), msg.c_str ()); |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1538 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1539 return retval; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1540 } |
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 // 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
|
1543 // 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
|
1544 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
|
1545 { |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1546 Magick::Image im = imvec[frame]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1547 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1548 // Add file name and timestamp. |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1549 info.contents ("Filename")(frame,0) = filename; |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1550 info.contents ("FileModDate")(frame,0) = filetime; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
1551 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1552 // 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
|
1553 GET_PARAM (fileSize, "FileSize") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1554 GET_PARAM (rows, "Height") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1555 GET_PARAM (columns, "Width") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1556 GET_PARAM (depth, "BitDepth") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1557 GET_PARAM (magick, "Format") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1558 GET_PARAM (format, "LongFormat") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1559 GET_PARAM (xResolution, "XResolution") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1560 GET_PARAM (yResolution, "YResolution") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1561 GET_PARAM (totalColors, "TotalColors") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1562 GET_PARAM (tileName, "TileName") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1563 GET_PARAM (animationDelay, "AnimationDelay") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1564 GET_PARAM (animationIterations, "AnimationIterations") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1565 GET_PARAM (endian, "ByteOrder") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1566 GET_PARAM (gamma, "Gamma") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1567 GET_PARAM (matte, "Matte") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1568 GET_PARAM (modulusDepth, "ModulusDepth") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1569 GET_PARAM (quality, "Quality") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1570 GET_PARAM (quantizeColors, "QuantizeColors") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1571 GET_PARAM (resolutionUnits, "ResolutionUnits") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1572 GET_PARAM (type, "ColorType") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1573 GET_PARAM (view, "View") |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1574 } |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1575 |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1576 retval = octave_value (info); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1577 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1578 catch (Magick::Warning& w) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1579 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1580 warning ("Magick++ warning: %s", w.what ()); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1581 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1582 catch (Magick::ErrorCoder& e) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1583 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1584 warning ("Magick++ coder error: %s", e.what ()); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1585 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1586 catch (Magick::Exception& e) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1587 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1588 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
|
1589 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1590 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1591 #endif |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1592 return retval; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1593 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1594 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1595 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1596 ## 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
|
1597 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1598 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1599 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1600 #undef GET_PARAM |
11035
8a6b7947f618
Added support for checking supported image types at runtime.
John Swensen <jpswensen@gmail.com>
parents:
11034
diff
changeset
|
1601 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1602 DEFUN_DLD (__magick_formats__, args, , |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1603 "-*- texinfo -*-\n\ |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1604 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\ |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1605 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
|
1606 \n\ |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
1607 @seealso{imfinfo, imformats, imread, imwrite}\n\ |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1608 @end deftypefn") |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1609 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1610 octave_value retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1611 #ifndef HAVE_MAGICK |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1612 gripe_disabled_feature ("imformats", "Image IO"); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1613 #else |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1614 if (args.length () != 1 || ! args(0).is_map ()) |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1615 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1616 print_usage (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1617 return retval; |
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 octave_map formats = args(0).map_value (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1620 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1621 maybe_initialize_magick (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1622 for (octave_idx_type idx = 0; idx < formats.numel (); idx++) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1623 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1624 try |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1625 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1626 octave_scalar_map fmt = formats.checkelem (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1627 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1628 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1629 fmt.setfield ("description", octave_value (coder.description ())); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1630 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1631 // 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
|
1632 // read or write them, them set it to an empty value |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1633 if (! coder.isReadable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1634 fmt.setfield ("read", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1635 if (! coder.isWritable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1636 fmt.setfield ("write", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1637 formats.fast_elem_insert (idx, fmt); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1638 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1639 catch (Magick::Exception& e) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1640 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1641 // Exception here are missing formats. So we remove the format |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1642 // from the structure and reduce idx. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1643 formats.delete_elements (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1644 idx--; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1645 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1646 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1647 retval = formats; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1648 #endif |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1649 return retval; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1650 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1651 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1652 /* |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1653 ## No test needed for internal helper function. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1654 %!assert (1) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
1655 */ |