annotate libinterp/dldfcn/__magick_read__.cc @ 20704:571508c1ed06

eliminate more uses of error_state * ov.h, ov.cc (octave_value::xall_strings): New extractor. * bitfcns.cc, data.cc, ellipj.cc, fftn.cc, file-io.cc, filter.cc, find.cc, graphics.cc, input.cc, load-path.cc, luinc.cc, matrix_type.cc, oct-stream.cc, ordschur.cc, psi.cc, rand.cc, spparms.cc, strfns.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, utils.cc, variables.cc, __glpk__.cc, __magick_read__.cc, amd.cc, ov-cell.cc, ov-fcn-inline.cc, ov-struct.cc: Eliminate more uses of error_state. * system.tst: Update tests.
author John W. Eaton <jwe@octave.org>
date Sat, 14 Nov 2015 15:18:05 -0500
parents 85e5efae848a
children 131b4af8b5d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
1 /*
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19696
diff changeset
3 Copyright (C) 2013-2015 Carnë Draug
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19696
diff changeset
4 Copyright (C) 2002-2015 Andy Adler
7932
d75586531aac style fixes
John W. Eaton <jwe@octave.org>
parents: 7931
diff changeset
5 Copyright (C) 2008 Thomas L. Scofield
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
6 Copyright (C) 2010 David Grundberg
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
7
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
8 This file is part of Octave.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
9
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
13 option) any later version.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
14
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
18 for more details.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
19
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
21 along with Octave; see the file COPYING. If not, see
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
22 <http://www.gnu.org/licenses/>.
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
23
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
24 */
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
25
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
26 #ifdef HAVE_CONFIG_H
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
27 #include <config.h>
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
28 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
29
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
30 #include "file-stat.h"
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
31 #include "oct-env.h"
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
32 #include "oct-time.h"
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
33
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
34 #include "defun-dld.h"
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
35 #include "error.h"
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
36 #include "ov-struct.h"
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
37
16925
5c25f7ed080c *__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents: 16901
diff changeset
38 #include "gripes.h"
5c25f7ed080c *__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents: 16901
diff changeset
39
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
40 #ifdef HAVE_MAGICK
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
41
9575
55ecaefb7d0f Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents: 9439
diff changeset
42 #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
43 #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
44
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
45 // In theory, it should be enough to check the class:
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
46 // Magick::ClassType
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
47 // PseudoClass:
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
48 // Image is composed of pixels which specify an index in a color palette.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
49 // DirectClass:
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
50 // Image is composed of pixels which represent literal color values.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
51 //
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
52 // GraphicsMagick does not really distinguishes between indexed and
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
53 // normal images. After reading a file, it decides itself the optimal
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
54 // way to store the image in memory, independently of the how the
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
55 // image was stored in the file. That's what ClassType returns. While
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
56 // it seems to match the original file most of the times, this is
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
57 // not necessarily true all the times. See
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
58 // https://sourceforge.net/mailarchive/message.php?msg_id=31180507
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
59 // In addition to the ClassType, there is also ImageType which has a
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
60 // type for indexed images (PaletteType and PaletteMatteType). However,
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
61 // they also don't represent the original image. Not only does DirectClass
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
62 // can have a PaletteType, but also does a PseudoClass have non Palette
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
63 // types.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
64 //
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
65 // We can't do better without having format specific code which is
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
66 // what we are trying to avoid by using a library such as GM. We at
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
67 // least create workarounds for the most common problems.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
68 //
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
69 // 1) A grayscale jpeg image can report being indexed even though the
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
70 // JPEG format has no support for indexed images. We can at least
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
71 // fix this one.
17373
8508b8ae46a8 imread: fix identification of PNG files as indexed.
Carnë Draug <carandraug@octave.org>
parents: 17372
diff changeset
72 // 2) A PNG file is only an indexed image if color type orig is 3 (value comes
8508b8ae46a8 imread: fix identification of PNG files as indexed.
Carnë Draug <carandraug@octave.org>
parents: 17372
diff changeset
73 // from libpng)
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
74 static bool
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
75 is_indexed (const Magick::Image& img)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
76 {
18955
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
77 bool indexed = (img.classType () == Magick::PseudoClass);
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
78 // Our problem until now is non-indexed images, being represented as indexed
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
79 // by GM. The following attempts educated guesses to undo this optimization.
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
80 if (indexed)
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
81 {
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
82 const std::string fmt = img.magick ();
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
83 if (fmt == "JPEG")
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
84 // The JPEG format does not support indexed images, but GM sometimes
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
85 // reports grayscale JPEG as indexed. Always false for JPEG.
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
86 indexed = false;
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
87 else if (fmt == "PNG")
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
88 {
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
89 // Newer versions of GM (at least does not happens with 1.3.16) will
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
90 // store values from the underlying library as image attributes. In
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
91 // the case of PNG files, this is libpng where an indexed image will
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
92 // always have a value of 3 for "color-type-orig". This property
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
93 // always has a value in libpng so if we get nothing, we assume this
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
94 // GM version does not store them and we have to go with whatever
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
95 // GM PseudoClass says.
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
96 const std::string color_type =
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
97 const_cast<Magick::Image&> (img).attribute ("PNG:IHDR.color-type-orig");
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
98 if (! color_type.empty() && color_type != "3")
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
99 indexed = false;
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
100 }
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
101 }
914c3ce73665 __magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents: 18553
diff changeset
102 return indexed;
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
103 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
104
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
105 // The depth from depth() is not always correct for us but seems to be the
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
106 // best value we can get. For example, a grayscale png image with 1 bit
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
107 // per channel should return a depth of 1 but instead we get 8.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
108 // We could check channelDepth() but then, which channel has the data
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
109 // is not straightforward. So we'd have to check all
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
110 // the channels and select the highest value. But then, I also
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
111 // have a 16bit TIFF whose depth returns 16 (correct), but all of the
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
112 // channels gives 8 (wrong). No idea why, maybe a bug in GM?
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
113 // Anyway, using depth() seems that only causes problems for binary
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
114 // images, and the problem with channelDepth() is not making set them
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
115 // all to 1. So we will guess that if all channels have depth of 1,
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
116 // then we must have a binary image.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
117 // Note that we can't use AllChannels it doesn't work for this.
20338
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
118 // We also can't check only one from RGB, one from CMYK, and grayscale
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
119 // and transparency, we really need to check all of the channels (bug #41584).
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
120 static octave_idx_type
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
121 get_depth (Magick::Image& img)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
122 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
123 octave_idx_type depth = img.depth ();
17373
8508b8ae46a8 imread: fix identification of PNG files as indexed.
Carnë Draug <carandraug@octave.org>
parents: 17372
diff changeset
124 if (depth == 8
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
125 && img.channelDepth (Magick::RedChannel) == 1
20338
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
126 && img.channelDepth (Magick::GreenChannel) == 1
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
127 && img.channelDepth (Magick::BlueChannel) == 1
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
128 && img.channelDepth (Magick::CyanChannel) == 1
20338
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
129 && img.channelDepth (Magick::MagentaChannel) == 1
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
130 && img.channelDepth (Magick::YellowChannel) == 1
a7770c66cb3d Saturated red channel on RGB image, makes imread() return logical (bug #41584)
Carnë Draug <carandraug@octave.org>
parents: 20232
diff changeset
131 && img.channelDepth (Magick::BlackChannel) == 1
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
132 && img.channelDepth (Magick::OpacityChannel) == 1
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
133 && img.channelDepth (Magick::GrayChannel) == 1)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
134 depth = 1;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
135
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
136 return depth;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
137 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
138
17335
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
139 // We need this in case one of the sides of the image being read has
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
140 // width 1. In those cases, the type will come as scalar instead of range
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
141 // since that's the behaviour of the colon operator (1:1:1 will be a scalar,
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
142 // not a range).
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
143 static Range
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
144 get_region_range (const octave_value& region)
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
145 {
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
146 Range output;
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
147 if (region.is_range ())
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
148 output = region.range_value ();
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
149 else if (region.is_scalar_type ())
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
150 {
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
151 double value = region.scalar_value ();
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
152 output = Range (value, value);
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
153 }
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
154 else
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
155 error ("__magick_read__: unknow datatype for Region option");
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
156
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
157 return output;
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
158 }
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
159
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
160 static std::map<std::string, octave_idx_type>
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
161 calculate_region (const octave_scalar_map& options)
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
162 {
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
163 std::map<std::string, octave_idx_type> region;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
164 const Cell pixel_region = options.getfield ("region").cell_value ();
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
165
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
166 // Subtract 1 to account for 0 indexing.
17335
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
167 const Range rows = get_region_range (pixel_region (0));
583306fe7e4f Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents: 17334
diff changeset
168 const Range cols = get_region_range (pixel_region (1));
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
169 region["row_start"] = rows.base () -1;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
170 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
171 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
172 region["col_end"] = cols.max () -1;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
173
17138
96526baf7423 Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents: 17134
diff changeset
174 // 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
175 // 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
176 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
177 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
178
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
179 // 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
180 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
181 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
182 (region["row_cache"] + rows.inc () -1) - cols.inc ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
183
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
184 // The actual height and width of the output image
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20219
diff changeset
185 region["row_out"] = rows.numel ();
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20219
diff changeset
186 region["col_out"] = cols.numel ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
187
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
188 return region;
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
189 }
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
190
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
191 static octave_value_list
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
192 read_maps (Magick::Image& img)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
193 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
194 // can't call colorMapSize on const Magick::Image
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
195 const octave_idx_type mapsize = img.colorMapSize ();
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
196 Matrix cmap = Matrix (mapsize, 3); // colormap
17372
63b53ea33a8b imread: fix returning multiple variables.
Carnë Draug <carandraug@octave.org>
parents: 17362
diff changeset
197 ColumnVector amap = ColumnVector (mapsize); // alpha map
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
198 for (octave_idx_type i = 0; i < mapsize; i++)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
199 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
200 const Magick::ColorRGB c = img.colorMap (i);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
201 cmap(i,0) = c.red ();
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
202 cmap(i,1) = c.green ();
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
203 cmap(i,2) = c.blue ();
17372
63b53ea33a8b imread: fix returning multiple variables.
Carnë Draug <carandraug@octave.org>
parents: 17362
diff changeset
204 amap(i) = c.alpha ();
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
205 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
206 octave_value_list maps;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
207 maps(0) = cmap;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
208 maps(1) = amap;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
209 return maps;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
210 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
211
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
212 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
213 static octave_value_list
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
214 read_indexed_images (const 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
215 const Array<octave_idx_type>& frameidx,
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
216 const octave_idx_type& nargout,
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
217 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
218 {
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
219 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
220
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
221 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
222
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
223 std::map<std::string, octave_idx_type> region = calculate_region (options);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
224 const octave_idx_type nFrames = frameidx.numel ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
225 const octave_idx_type nRows = region["row_out"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
226 const octave_idx_type nCols = region["col_out"];
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
227
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
228 // 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
229 // 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
230 // 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
231 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
232
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
233 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
234 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
235
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
236 const octave_idx_type row_start = region["row_start"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
237 const octave_idx_type col_start = region["col_start"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
238 const octave_idx_type row_shift = region["row_shift"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
239 const octave_idx_type col_shift = region["col_shift"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
240 const octave_idx_type row_cache = region["row_cache"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
241 const octave_idx_type col_cache = region["col_cache"];
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
242
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
243 // 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
244 // 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
245 // 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
246 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
247 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
248 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
249 OCTAVE_QUIT;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
250 imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
251 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
252
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
253 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
254 = imvec[frameidx(frame)].getConstIndexes ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
255
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
256 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
257 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
258 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
259 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
260 img_fvec[idx++] = static_cast<P> (*pix);
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
261 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
262 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
263 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
264 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
265 }
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
266 retval(0) = octave_value (img);
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
267
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
268 // Only bother reading the colormap if it was requested as output.
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
269 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
270 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
271 // 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
272 // have different colormaps but for Matlab compatibility, we only
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
273 // return the colormap of the first frame. To obtain the colormaps
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
274 // of different frames, one needs can either use imfinfo or a for
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
275 // loop around imread.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
276 const octave_value_list maps =
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
277 read_maps (const_cast<Magick::Image&> (imvec[frameidx(def_elem)]));
10100
dd4d4b14b340 __magick_read__.cc: no need to explicitly call chop_trailing_singletons now
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
278
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
279 retval(1) = maps(0);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
280
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
281 // only interpret 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
282 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
283 {
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
284 const Matrix amap = maps(1).matrix_value ();
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
285 const double* amap_fvec = amap.fortran_vec ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
286
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
287 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
288 double* alpha_fvec = alpha.fortran_vec ();
7933
54e414cc106b style fixes
John W. Eaton <jwe@octave.org>
parents: 7932
diff changeset
289
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
290 // GraphicsMagick stores the alpha values inverted, i.e.,
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
291 // 1 for transparent and 0 for opaque so we fix that here.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
292 const octave_idx_type nPixels = alpha.numel ();
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
293 for (octave_idx_type pix = 0; pix < nPixels; pix++)
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
294 alpha_fvec[pix] = 1 - amap_fvec[static_cast<int> (img_fvec[3])];
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
295
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
296 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
297 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
298 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
299
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
300 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
301 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
302
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
303 // 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
304 // 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
305 // 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
306 // readability too much.
10193
1a4074e277fe undo unintended change to __magick_read__.cc
John W. Eaton <jwe@octave.org>
parents: 10191
diff changeset
307 template <class T>
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
308 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
309 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
310 const Array<octave_idx_type>& frameidx,
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
311 const octave_idx_type& nargout,
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
312 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
313 {
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
314 typedef typename T::element_type P;
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
315
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
316 octave_value_list retval (3, Matrix ());
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
317
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
318 std::map<std::string, octave_idx_type> region = calculate_region (options);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
319 const octave_idx_type nFrames = frameidx.numel ();
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
320 const octave_idx_type nRows = region["row_out"];
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
321 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
322 T img;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
323
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
324 // 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
325 // 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
326 // 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
327 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
328
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
329 const octave_idx_type row_start = region["row_start"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
330 const octave_idx_type col_start = region["col_start"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
331 const octave_idx_type row_shift = region["row_shift"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
332 const octave_idx_type col_shift = region["col_shift"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
333 const octave_idx_type row_cache = region["row_cache"];
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
334 const octave_idx_type col_cache = region["col_cache"];
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
335
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
336 // 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
337 // 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
338 // 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
339 // 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
340 // 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
341 // 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
342 // 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
343 // 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
344 // 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
345 // See bug #39249).
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
346 // 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
347 // 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
348 // 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
349 // 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
350 // 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
351 // when depth() is 32.
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
352 // 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
353 // 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
354 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
355 if (imvec[def_elem].depth () == 32)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
356 divisor = std::numeric_limits<uint32_t>::max ();
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
357 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
358 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
359
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
360 // 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
361 // new ImageType BilevelMatteType
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
362 // 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
363 // 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
364 // 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
365 // 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
366 // 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
367 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
368 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
369 type = Magick::GrayscaleMatteType;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
370
17149
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
371 // 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
372 // 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
373 // 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
374 // 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
375 // 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
376 // 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
377 // 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
378 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
379 {
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
380 // 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
381 // Grayscale = 0
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
382 // 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
383 // RGB = 2
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
384 // 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
385 // 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
386 // 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
387 // read by the function to read indexed images
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
388 const std::string type_str
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
389 = imvec[0].attribute ("PNG:IHDR.color-type-orig");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
390
17149
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
391 if (type_str == "0")
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
392 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
393 else if (type_str == "2")
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
394 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
395 else if (type_str == "6")
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
396 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
397 else if (type_str == "4")
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
398 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
399 // 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
400 // 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
401 // 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
402 // 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
403 // 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
404 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
405 {
d6467d6dfb83 Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents: 17235
diff changeset
406 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
407 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
408 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
409 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
410 }
17149
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
411 }
73a3c1580974 Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents: 17147
diff changeset
412
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
413 // 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
414 // 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
415 if (nargout < 3)
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
416 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
417 switch (type)
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
418 {
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
419 case Magick::GrayscaleMatteType:
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
420 type = Magick::GrayscaleType;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
421 break;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
422
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
423 case Magick::PaletteMatteType:
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
424 type = Magick::PaletteType;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
425 break;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
426
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
427 case Magick::TrueColorMatteType:
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
428 type = Magick::TrueColorType;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
429 break;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
430
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
431 case Magick::ColorSeparationMatteType:
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
432 type = Magick::ColorSeparationType;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
433 break;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
434
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
435 default:
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
436 // Do nothing other than silencing warnings about enumeration
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
437 // values not being handled in switch.
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
438 ;
17116
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
439 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
440 }
59acfe9209dd Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents: 17110
diff changeset
441
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
442 const octave_idx_type colour_stride = nRows * nCols;
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
443 switch (type)
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
444 {
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
445 case Magick::BilevelType: // Monochrome bi-level image
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
446 case Magick::GrayscaleType: // Grayscale image
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
447 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
448 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
449 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
450
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
451 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
452 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
453 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
454 OCTAVE_QUIT;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
455 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
456 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
457 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
458
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
459 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
460 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
461 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
462 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
463 img_fvec[idx++] = pix->red / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
464 pix += row_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
465 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
466 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
467 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
468 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
469 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
470 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
471
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
472 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
473 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
474 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
475 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
476 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
477 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
478
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
479 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
480 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
481 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
482 OCTAVE_QUIT;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
483 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
484 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
485 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
486
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
487 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
488 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
489 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
490 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
491 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
492 a_fvec[idx] = (MaxRGB - pix->opacity) / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
493 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
494 idx++;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
495 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
496 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
497 }
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
498 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
499 retval(2) = alpha;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
500 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
501 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
502
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
503 case Magick::PaletteType: // Indexed color (palette) image
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
504 case Magick::TrueColorType: // Truecolor image
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
505 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
506 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
507 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
508
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
509 const octave_idx_type frame_stride = colour_stride * 3;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
510 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
511 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
512 OCTAVE_QUIT;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
513 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
514 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
515 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
516
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
517 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
518 P *rbuf = img_fvec;
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
519 P *gbuf = img_fvec + colour_stride;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
520 P *bbuf = img_fvec + colour_stride * 2;
17110
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++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
523 {
17110
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++)
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
525 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
526 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
527 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
528 bbuf[idx] = pix->blue / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
529 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
530 idx++;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
531 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
532 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
533 }
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
534 img_fvec += frame_stride;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
535 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
536 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
537 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
538
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
539 case Magick::PaletteMatteType: // Indexed color image with opacity
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
540 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
541 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
542 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
543 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
544 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
545 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
546
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
547 const octave_idx_type frame_stride = colour_stride * 3;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
548
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
549 // 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
550 // 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
551 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
552 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
553 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
554 OCTAVE_QUIT;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
555 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
556 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
557 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
558
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
559 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
560 P *rbuf = img_fvec;
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
561 P *gbuf = img_fvec + colour_stride;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
562 P *bbuf = img_fvec + colour_stride * 2;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
563
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
564 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
565 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
566 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
567 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
568 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
569 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
570 bbuf[idx] = pix->blue / divisor;
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
571 a_fvec[a_idx++] = (MaxRGB - pix->opacity) / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
572 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
573 idx++;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
574 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
575 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
576 }
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
577 img_fvec += frame_stride;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
578 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
579 retval(2) = alpha;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
580 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
581 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
582
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
583 case Magick::ColorSeparationType: // Cyan/Magenta/Yellow/Black (CMYK) image
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
584 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
585 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
586 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
587
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
588 const octave_idx_type frame_stride = colour_stride * 4;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
589 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
590 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
591 OCTAVE_QUIT;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
592 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
593 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
594 col_cache, row_cache);
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
595
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
596 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
597 P *cbuf = img_fvec;
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
598 P *mbuf = img_fvec + colour_stride;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
599 P *ybuf = img_fvec + colour_stride * 2;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
600 P *kbuf = img_fvec + colour_stride * 3;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
601
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
602 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
603 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
604 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
605 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
606 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
607 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
608 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
609 kbuf[idx] = pix->opacity / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
610 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
611 idx++;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
612 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
613 pix -= col_shift;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
614 }
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
615 img_fvec += frame_stride;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
616 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
617 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
618 }
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
619
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
620 // 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
621 case Magick::ColorSeparationMatteType:
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
622 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
623 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
624 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
625 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
626 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
627
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
628 const octave_idx_type frame_stride = colour_stride * 4;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
629
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
630 // 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
631 // 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
632 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
633 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
634 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
635 OCTAVE_QUIT;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
636 const Magick::PixelPacket *pix
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
637 = imvec[frameidx(frame)].getConstPixels (col_start, row_start,
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
638 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
639 // 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
640 // 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
641 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
642 = imvec[frameidx(frame)].getConstIndexes ();
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
643
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
644 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
645 P *cbuf = img_fvec;
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
646 P *mbuf = img_fvec + colour_stride;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
647 P *ybuf = img_fvec + colour_stride * 2;
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
648 P *kbuf = img_fvec + colour_stride * 3;
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
649
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
650 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
651 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
652 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
653 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
654 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
655 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
656 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
657 kbuf[idx] = pix->opacity / divisor;
17147
35a1bd41aa02 Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17139
diff changeset
658 a_fvec[a_idx++] = (MaxRGB - *apix) / divisor;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
659 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
660 idx++;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
661 }
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
662 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
663 }
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
664 img_fvec += frame_stride;
10295
13d382fc758b imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents: 10193
diff changeset
665 }
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
666 retval(2) = alpha;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
667 break;
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
668 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
669
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
670 default:
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
671 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
672 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
673 }
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
674
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
675 retval(0) = img;
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
676 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
677 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
678
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
679 // Read a file into vector of image objects.
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
680 void static
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
681 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
682 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
683 try
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
684 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
685 Magick::readImages (&imvec, filename);
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
686 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
687 catch (Magick::Warning& w)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
688 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
689 warning ("Magick++ warning: %s", w.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
690 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
691 catch (Magick::Exception& e)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
692 {
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
693 error ("Magick++ exception: %s", e.what ());
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
694 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
695 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
696
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
697 static void
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
698 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
699 {
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
700 static bool initialized = false;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
701
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
702 if (! initialized)
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
703 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
704 // Save locale as GraphicsMagick might change this (fixed in
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
705 // 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
706 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
707 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
708
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
709 const std::string program_name
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
710 = 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
711 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
712
10739
d27bd2f74137 src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents: 10390
diff changeset
713 // 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
714 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
715
11036
169f59f626d3 Add check for QuantumDepth at initialization of *Magick and an associated warning
John Swensen <jpswensen@gmail.com>
parents: 11035
diff changeset
716 if (QuantumDepth < 32)
19885
fa68a3f7dd8a __magick_read__.cc: add warning id for possibly low Magick quantum depth.
Carnë Draug <carandraug@octave.org>
parents: 19864
diff changeset
717 warning_with_id ("Octave:GraphicsMagic-Quantum-Depth",
20219
b39ba1bbb759 Don't print unecessary backtrace for GraphicsMagick warning about pixel depth.
Rik <rik@octave.org>
parents: 20163
diff changeset
718 "your version of %s limits images to %d bits per pixel\n",
19885
fa68a3f7dd8a __magick_read__.cc: add warning id for possibly low Magick quantum depth.
Carnë Draug <carandraug@octave.org>
parents: 19864
diff changeset
719 MagickPackageName, QuantumDepth);
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
720
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
721 initialized = true;
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
722 }
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
723 }
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
724 #endif
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
725
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
726 DEFUN_DLD (__magick_read__, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
727 "-*- texinfo -*-\n\
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
728 @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
729 Read image with GraphicsMagick or ImageMagick.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
730 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20097
diff changeset
731 This is a private internal function not intended for direct use.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20097
diff changeset
732 Use @code{imread} instead.\n\
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
733 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
734 @seealso{imfinfo, imformats, imread, imwrite}\n\
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
735 @end deftypefn")
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
736 {
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
737 octave_value_list output;
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
738
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
739 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
740 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
741 #else
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
742
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
743 maybe_initialize_magick ();
10390
ad0b54ae206a __magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
744
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
745 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
746 {
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
747 print_usage ();
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
748 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
749 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
750
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20703
diff changeset
751 const octave_scalar_map options = args(1).xscalar_map_value ("__magick_read__: OPTIONS must be a struct");
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
752
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
753 std::vector<Magick::Image> imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
754 read_file (args(0).string_value (), imvec);
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
755
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
756 // 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
757 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
758 Array<octave_idx_type> frameidx;
17118
c97a26408ee0 Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents: 17116
diff changeset
759 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
760 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
761 {
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
762 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
763 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
764 frameidx(i) = i;
10778
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
765 }
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
766 else
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
767 {
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
768 frameidx = indexes.xint_vector_value ("__magick_read__: invalid value for Index/Frame");
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
769
16989
7a69ab84b8c9 __magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents: 16988
diff changeset
770 // 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
771 // sure none of the indexes is outside the range of image number.
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20219
diff changeset
772 const octave_idx_type n = frameidx.numel ();
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
773 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
774 {
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
775 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
776 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
777 {
17912
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
778 // We do this check inside the loop because frameidx does not
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
779 // need to be ordered (this is a feature and even allows for
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
780 // some frames to be read multiple times).
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
781 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
782 return output;
6035bf68a755 Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents: 10739
diff changeset
783 }
8053
89a512e8ec43 Replace leading tabs with spaces.
scofield@scofield
parents: 7974
diff changeset
784 }
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
785 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
786
17912
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
787 // Check that all frames have the same size. We don't do this at the same
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
788 // time we decode the image because that's done in many different places,
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
789 // to cover the different types of images which would lead to a lot of
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
790 // copy and paste.
17916
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
791 {
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
792 const unsigned int nRows = imvec[frameidx(0)].rows ();
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
793 const unsigned int nCols = imvec[frameidx(0)].columns ();
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20219
diff changeset
794 const octave_idx_type n = frameidx.numel ();
17916
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
795 for (octave_idx_type frame = 0; frame < n; frame++)
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
796 {
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
797 if (nRows != imvec[frameidx(frame)].rows ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
798 || nCols != imvec[frameidx(frame)].columns ())
17916
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
799 {
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
800 error ("imread: all frames must have the same size but frame %i is different",
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
801 frameidx(frame) +1);
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
802 return output;
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
803 }
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
804 }
c7f089c560cc imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents: 17912
diff changeset
805 }
17912
01496d4811b1 imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents: 17861
diff changeset
806
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
807 const octave_idx_type depth = get_depth (imvec[frameidx(0)]);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
808 if (is_indexed (imvec[frameidx(0)]))
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
809 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
810 if (depth <= 1)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
811 output = read_indexed_images<boolNDArray> (imvec, frameidx,
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
812 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
813 else if (depth <= 8)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
814 output = read_indexed_images<uint8NDArray> (imvec, frameidx,
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
815 nargout, options);
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
816 else if (depth <= 16)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
817 output = read_indexed_images<uint16NDArray> (imvec, frameidx,
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
818 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
819 else
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
820 {
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
821 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
822 return output;
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
823 }
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
824 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
825
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
826 else
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
827 {
17110
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
828 if (depth <= 1)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
829 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
830 else if (depth <= 8)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
831 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
832 else if (depth <= 16)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
833 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
834 else if (depth <= 32)
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
835 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
836 else
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
837 {
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
838 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
839 depth);
95055b814d35 imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents: 16996
diff changeset
840 }
16996
a1d091243d11 Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents: 16989
diff changeset
841 }
7937
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
842
6661387827d6 Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents: 7933
diff changeset
843 #endif
7925
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
844 return output;
9316b59903c9 Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff changeset
845 }
7926
d74f996e005d __magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents: 7925
diff changeset
846
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
847 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
848 ## 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
849 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
850 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
851
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
852 #ifdef HAVE_MAGICK
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
853
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
854 template <class T>
17228
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
855 static uint32NDArray
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
856 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
857 {
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
858 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
859 uint32NDArray out (img.dims ());
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
860
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
861 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
862 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
863
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
864 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
865 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
866 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
867 out_fvec[idx] = img_fvec[idx] * max;
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
868
17228
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
869 return out;
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
870 }
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
871
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
872 // 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
873 // 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
874 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
875 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
876 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
877 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
878 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
879 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
880 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
881 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
882 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
883
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
884 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
885 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
886 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
887 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
888 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
889 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
890 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
891 // 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
892 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
893
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
894 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
895 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
896 // 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
897 // 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
898 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
899 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
900 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
901 case Magick::GrayscaleMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
902 case Magick::TrueColorMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
903 case Magick::ColorSeparationMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
904 case Magick::PaletteMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
905 img.matte (true);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
906 break;
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
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
908 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
909 img.matte (false);
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 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
911
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
912 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
913 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
914
17228
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
915 template <class T>
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
916 static void
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
917 encode_indexed_images (std::vector<Magick::Image>& imvec,
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
918 const T& img,
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
919 const Matrix& cmap)
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
920 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
921 typedef typename T::element_type P;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
922 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
923 const octave_idx_type nRows = img.rows ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
924 const octave_idx_type nCols = img.columns ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
925 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
926 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
927
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
928 // 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
929 // 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
930 std::vector<Magick::ColorRGB> colormap;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
931 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
932 const double* cmap_fvec = cmap.fortran_vec ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
933 const octave_idx_type G_offset = cmap_size;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
934 const octave_idx_type B_offset = cmap_size * 2;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
935 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
936 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
937 cmap_fvec[map_idx + G_offset],
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
938 cmap_fvec[map_idx + B_offset]));
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
939 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
940
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
941 for (octave_idx_type frame = 0; frame < nFrames; frame++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
942 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
943 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
944 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
945 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
946 Magick::PseudoClass);
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
947
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
948 // Insert colormap.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
949 m_img.colorMapSize (cmap_size);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
950 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
951 m_img.colorMap (map_idx, colormap[map_idx]);
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
952
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
953 // 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
954 // 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
955 // 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
956 // 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
957 // 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
958 // 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
959 // 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
960 // 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
961 // over the order of that colormap. And that's why we set both.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
962 Magick::PixelPacket* pix = m_img.getPixels (0, 0, nCols, nRows);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
963 Magick::IndexPacket* ind = m_img.getIndexes ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
964 const P* img_fvec = img.fortran_vec ();
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
965
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
966 octave_idx_type GM_idx = 0;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
967 for (octave_idx_type column = 0; column < nCols; column++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
968 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
969 for (octave_idx_type row = 0; row < nRows; row++)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
970 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
971 ind[GM_idx] = double (*img_fvec);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
972 pix[GM_idx] = m_img.colorMap (double (*img_fvec));
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
973 img_fvec++;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
974 GM_idx += nCols;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
975 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
976 GM_idx -= nCols * nRows - 1;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
977 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
978
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
979 // Save changes to underlying image.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
980 m_img.syncPixels ();
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
981 imvec.push_back (m_img);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
982 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
983 }
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
984
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
985 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
986 encode_bool_image (std::vector<Magick::Image>& imvec, const boolNDArray& img)
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
987 {
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
988 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
989 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
990 const octave_idx_type nCols = img.columns ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
991
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
992 // 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
993 const Magick::Color white ("white");
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
994
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
995 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
996 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
997 for (octave_idx_type frame = 0; frame < nFrames; frame++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
998 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
999 OCTAVE_QUIT;
17333
51c011825bcc __magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents: 17332
diff changeset
1000 // 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
1001 // 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
1002 // 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
1003 // 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
1004 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
1005 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
1006 Magick::DirectClass);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1007
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1008 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows);
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1009 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
1010 for (octave_idx_type col = 0; col < nCols; col++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
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 for (octave_idx_type row = 0; row < nRows; row++)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1013 {
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1014 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
1015 pix[GM_idx] = white;
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1016
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1017 img_idx++;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1018 GM_idx += nCols;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1019 }
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1020 GM_idx -= nCols * nRows - 1;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1021 }
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1022 // 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
1023 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
1024 // 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
1025 // 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
1026 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
1027 imvec.push_back (m_img);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1028 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1029 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1030
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1031 template <class T>
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1032 static void
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1033 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
1034 const T& img, const T& alpha)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1035 {
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1036 typedef typename T::element_type P;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1037 const octave_idx_type channels = img.ndims () < 3 ? 1 : img.dims ()(2);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1038 const octave_idx_type nFrames = img.ndims () < 4 ? 1 : img.dims ()(3);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1039 const octave_idx_type nRows = img.rows ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1040 const octave_idx_type nCols = img.columns ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1041 const octave_idx_type bitdepth = bitdepth_from_class<T> ();
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1042
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1043 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
1044 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
1045 switch (channels)
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1046 {
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1047 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
1048 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
1049 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
1050 else
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1051 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
1052 break;
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 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
1055 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
1056 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
1057 else
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1058 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
1059 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1060
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1061 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
1062 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
1063 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
1064 else
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1065 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
1066 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1067
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1068 default:
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1069 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1070 // __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
1071 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
1072 return;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1073 }
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1074 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1075
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1076 // 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
1077 // 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
1078 // 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
1079 // 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
1080 // 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
1081 // 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
1082 // the range of MaxRGB
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1083 const double divisor = static_cast<double>((uint64_t (1) << bitdepth) - 1)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1084 / MaxRGB;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1085
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1086 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
1087 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
1088 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
1089 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1090 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
1091 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1092 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
1093 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1094 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1095 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
1096 type,
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1097 Magick::DirectClass);
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1098
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1099 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1100 octave_idx_type GM_idx = 0;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1101 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
1102 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1103 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
1104 {
19694
c334e4af3a1b Fix incorrect writing of grayscale JPEG images (bugs #41673, #44118, #42474)
Ilya Kurdyukov <olme8@mail.ru>
parents: 18955
diff changeset
1105 const double grey = double (*img_fvec) / divisor;
c334e4af3a1b Fix incorrect writing of grayscale JPEG images (bugs #41673, #44118, #42474)
Ilya Kurdyukov <olme8@mail.ru>
parents: 18955
diff changeset
1106 Magick::Color c (grey, grey, grey);
c334e4af3a1b Fix incorrect writing of grayscale JPEG images (bugs #41673, #44118, #42474)
Ilya Kurdyukov <olme8@mail.ru>
parents: 18955
diff changeset
1107 pix[GM_idx] = c;
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 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
1109 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
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 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
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 // 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
1114 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
1115 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
1116 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1117 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1118 }
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1119
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1120 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
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 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
1123 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1124 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1125 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
1126 type,
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1127 Magick::DirectClass);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1128
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1129 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1130 octave_idx_type GM_idx = 0;
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 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
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 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
1134 {
18544
e0cc67d5a462 Fix writing of grayscale images when there is an alpha channel.
Carnë Draug <carandraug@octave.org>
parents: 18542
diff changeset
1135 double grey = double (*img_fvec) / divisor;
e0cc67d5a462 Fix writing of grayscale images when there is an alpha channel.
Carnë Draug <carandraug@octave.org>
parents: 18542
diff changeset
1136 Magick::Color c (grey, grey, grey,
e0cc67d5a462 Fix writing of grayscale images when there is an alpha channel.
Carnë Draug <carandraug@octave.org>
parents: 18542
diff changeset
1137 MaxRGB - (double (*a_fvec) / divisor));
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1138 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
1139 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
1140 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
1141 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
1142 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1143 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
1144 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1145 // 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
1146 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
1147 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
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 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1150 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1151
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1152 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
1153 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1154 // 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
1155 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
1156 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
1157 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
1158 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1159 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1160 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
1161 type,
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1162 Magick::DirectClass);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1163
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1164 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1165 octave_idx_type GM_idx = 0;
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 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
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 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
1169 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1170 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
1171 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
1172 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
1173 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
1174 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
1175 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
1176 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1177 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
1178 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1179 // 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
1180 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
1181 imvec.push_back (m_img);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1182 img_fvec += B_offset;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1183 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1184 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1185 }
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1186
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1187 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
1188 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1189 // 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
1190 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
1191 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
1192 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
1193 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1194 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1195 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
1196 type,
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1197 Magick::DirectClass);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1198
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1199 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1200 octave_idx_type GM_idx = 0;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1201 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
1202 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1203 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
1204 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1205 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
1206 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
1207 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
1208 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
1209 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
1210 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
1211 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
1212 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
1213 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1214 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
1215 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1216 // 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
1217 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
1218 imvec.push_back (m_img);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1219 img_fvec += B_offset;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1220 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1221 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1222 }
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1223
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1224 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
1225 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1226 // 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
1227 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
1228 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
1229 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
1230 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
1231 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1232 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1233 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
1234 type,
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1235 Magick::DirectClass);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1236
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1237 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1238 octave_idx_type GM_idx = 0;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1239 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
1240 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1241 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
1242 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1243 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
1244 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
1245 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
1246 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
1247 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
1248 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
1249 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
1250 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1251 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
1252 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1253 // 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
1254 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
1255 imvec.push_back (m_img);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1256 img_fvec += K_offset;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1257 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1258 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1259 }
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1260
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1261 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
1262 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1263 // 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
1264 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
1265 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
1266 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
1267 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
1268 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1269 OCTAVE_QUIT;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1270 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
1271 type,
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1272 Magick::DirectClass);
10979
7f49dc864f32 __magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents: 10978
diff changeset
1273
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1274 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
1275 Magick::IndexPacket *ind = m_img.getIndexes ();
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1276 octave_idx_type GM_idx = 0;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1277 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
1278 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1279 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
1280 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1281 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
1282 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
1283 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
1284 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
1285 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
1286 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
1287 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
1288 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
1289 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
1290 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1291 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
1292 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1293 // 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
1294 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
1295 imvec.push_back (m_img);
18542
30aa4e85f8d5 Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents: 18149
diff changeset
1296 img_fvec += K_offset;
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1297 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1298 break;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1299 }
11034
6589aaf769f6 Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents: 10988
diff changeset
1300
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1301 default:
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1302 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1303 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
1304 return;
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1305 }
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1306 }
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 return;
8054
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1308 }
272eaebbb6ba Various features added to imwrite
scofield@scofield
parents: 8053
diff changeset
1309
17855
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1310 // Meant to be shared with both imfinfo and imwrite.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1311 static std::map<octave_idx_type, std::string>
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1312 init_disposal_methods ()
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1313 {
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1314 // GIF Specifications:
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1315 //
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1316 // Disposal Method - Indicates the way in which the graphic is to
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1317 // be treated after being displayed.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1318 //
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1319 // 0 - No disposal specified. The decoder is
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1320 // not required to take any action.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1321 // 1 - Do not dispose. The graphic is to be left
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1322 // in place.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1323 // 2 - Restore to background color. The area used by the
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1324 // graphic must be restored to the background color.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1325 // 3 - Restore to previous. The decoder is required to
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1326 // restore the area overwritten by the graphic with
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1327 // what was there prior to rendering the graphic.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1328 // 4-7 - To be defined.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1329 static std::map<octave_idx_type, std::string> methods;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1330 if (methods.empty ())
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1331 {
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1332 methods[0] = "doNotSpecify";
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1333 methods[1] = "leaveInPlace";
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1334 methods[2] = "restoreBG";
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1335 methods[3] = "restorePrevious";
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1336 }
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1337 return methods;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1338 }
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1339 static std::map<std::string, octave_idx_type>
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1340 init_reverse_disposal_methods ()
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1341 {
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1342 static std::map<std::string, octave_idx_type> methods;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1343 if (methods.empty ())
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1344 {
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1345 methods["donotspecify"] = 0;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1346 methods["leaveinplace"] = 1;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1347 methods["restorebg"] = 2;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1348 methods["restoreprevious"] = 3;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1349 }
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1350 return methods;
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1351 }
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1352
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1353 void static
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1354 write_file (const std::string& filename,
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1355 const std::string& ext,
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1356 std::vector<Magick::Image>& imvec)
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1357 {
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1358 try
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1359 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1360 Magick::writeImages (imvec.begin (), imvec.end (), ext + ":" + filename);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1361 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1362 catch (Magick::Warning& w)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1363 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1364 warning ("Magick++ warning: %s", w.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1365 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1366 catch (Magick::ErrorCoder& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1367 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1368 warning ("Magick++ coder error: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1369 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1370 catch (Magick::Exception& e)
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1371 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1372 error ("Magick++ exception: %s", e.what ());
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1373 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1374 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1375
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1376 #endif
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1377
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
1378 DEFUN_DLD (__magick_write__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1379 "-*- texinfo -*-\n\
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1380 @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
1381 Write image with GraphicsMagick or ImageMagick.\n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1382 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20097
diff changeset
1383 This is a private internal function not intended for direct use.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20097
diff changeset
1384 Use @code{imwrite} instead.\n\
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1385 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1386 @seealso{imfinfo, imformats, imread, imwrite}\n\
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1387 @end deftypefn")
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1388 {
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1389 octave_value_list retval;
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1390
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1391 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1392 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
1393 #else
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1394
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1395 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1396
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1397 if (args.length () != 5 || ! args(0).is_string () || ! args(1).is_string ())
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1398 {
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1399 print_usage ();
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1400 return retval;
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1401 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1402 const std::string filename = args(0).string_value ();
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20703
diff changeset
1403 const std::string ext = args(1).string_value ();
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1404
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20703
diff changeset
1405 const octave_scalar_map options = args(4).xscalar_map_value ("__magick_write__: OPTIONS must be a struct");
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1406
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1407 const octave_value img = args(2);
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20703
diff changeset
1408 const Matrix cmap = args(3).xmatrix_value ("__magick_write__: invalid MAP");
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1409
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1410 std::vector<Magick::Image> imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1411
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1412 if (cmap.is_empty ())
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1413 {
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1414 const octave_value alpha = options.getfield ("alpha");
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1415 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
1416 encode_bool_image (imvec, img.bool_array_value ());
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1417 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
1418 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
1419 alpha.uint8_array_value ());
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1420 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
1421 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
1422 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
1423 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
1424 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
1425 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
1426 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
1427 {
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
1428 // 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
1429 // 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
1430 // 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
1431 // 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
1432 // 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
1433 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
1434 uint32NDArray clip_alpha;
17228
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
1435 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
1436 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1437 clip_img = img_float2uint<FloatNDArray>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1438 (img.float_array_value ());
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1439 clip_alpha = img_float2uint<FloatNDArray>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1440 (alpha.float_array_value ());
17332
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1441 }
17228
2f1729cae08f Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents: 17226
diff changeset
1442 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
1443 {
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1444 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
1445 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
1446 }
eb7e9a991ffb Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents: 17240
diff changeset
1447 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
1448 }
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1449 else
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1450 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1451 error ("__magick_write__: image type not supported");
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1452 return retval;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1453 }
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1454 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1455 else
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1456 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1457 // 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
1458 // 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
1459 // but it would look much messier.
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1460 if (img.is_uint8_type ())
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1461 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
1462 cmap);
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1463 else if (img.is_uint16_type ())
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1464 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
1465 cmap);
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1466 else
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1467 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1468 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
1469 return retval;
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1470 }
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1471 }
17855
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1472 static std::map<std::string, octave_idx_type> disposal_methods
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1473 = init_reverse_disposal_methods ();
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1474
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1475 const octave_idx_type nFrames = imvec.size ();
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1476
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1477 const octave_idx_type quality = options.getfield ("quality").int_value ();
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1478 const ColumnVector delaytime =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1479 options.getfield ("delaytime").column_vector_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1480 const Array<std::string> disposalmethod =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1481 options.getfield ("disposalmethod").cellstr_value ();
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1482 for (octave_idx_type i = 0; i < nFrames; i++)
17855
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1483 {
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1484 imvec[i].quality (quality);
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1485 imvec[i].animationDelay (delaytime(i));
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1486 imvec[i].gifDisposeMethod (disposal_methods[disposalmethod(i)]);
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1487 }
17854
adb0ba0d0c13 imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents: 17853
diff changeset
1488
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1489 // 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
1490 // 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
1491 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
1492 if (writemode == "append" && file_stat (filename).exists ())
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1493 {
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1494 std::vector<Magick::Image> ini_imvec;
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1495 read_file (filename, ini_imvec);
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1496
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1497 if (ini_imvec.size () > 0)
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1498 {
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1499 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
1500 ini_imvec.swap (imvec);
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1501 }
16988
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1502 }
54b75bed4bc7 imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents: 16984
diff changeset
1503
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17855
diff changeset
1504 // FIXME: LoopCount or animationIterations
17855
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1505 // How it should work:
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1506 //
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1507 // This value is only set for the first image in the sequence. Trying
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1508 // to set this value with the append mode should have no effect, the
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1509 // value used with the first image is the one that counts (that would
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1510 // also be Matlab compatible). Thus, the right way to do this would be
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1511 // to have an else block on the condition above, and set this only
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1512 // when creating a new file. Since Matlab does not interpret a 4D
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1513 // matrix as sequence of images to write, its users need to use a for
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1514 // loop and set LoopCount only on the first iteration (it actually
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1515 // throws warnings otherwise)
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1516 //
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1517 // Why is this not done the right way:
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1518 //
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1519 // When GM saves a single image, it discards the value if there is only
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1520 // a single image and sets it to "no loop". Since our default is an
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1521 // infinite loop, if the user tries to do it the Matlab way (setting
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1522 // LoopCount only on the first image) that value will go nowhere.
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1523 // See https://sourceforge.net/p/graphicsmagick/bugs/248/
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1524 // Because of this, we document to set LoopCount on every iteration
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1525 // (in Matlab will cause a lot of warnings), or pass a 4D matrix with
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1526 // all frames (won't work in Matlab at all).
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1527 // Note that this only needs to be set on the first frame
bfbe5dcc9943 imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents: 17854
diff changeset
1528 imvec[0].animationIterations (options.getfield ("loopcount").uint_value ());
17853
aacb9da13df6 imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1529
20406
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1530 const std::string compression = options.getfield ("compression").string_value ();
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1531 #define COMPRESS_MAGICK_IMAGE_VECTOR(COMPRESSION_STRING, GM_TYPE) \
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1532 if (compression == COMPRESSION_STRING) \
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1533 for (std::vector<Magick::Image>::size_type i = 0; i < imvec.size (); i++) \
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1534 imvec[i].compressType (GM_TYPE);
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1535
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1536 COMPRESS_MAGICK_IMAGE_VECTOR("none", Magick::NoCompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1537 else COMPRESS_MAGICK_IMAGE_VECTOR("bzip", Magick::BZipCompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1538 else COMPRESS_MAGICK_IMAGE_VECTOR("fax3", Magick::FaxCompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1539 else COMPRESS_MAGICK_IMAGE_VECTOR("fax4", Magick::Group4Compression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1540 else COMPRESS_MAGICK_IMAGE_VECTOR("jpeg", Magick::JPEGCompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1541 else COMPRESS_MAGICK_IMAGE_VECTOR("lzw", Magick::LZWCompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1542 else COMPRESS_MAGICK_IMAGE_VECTOR("rle", Magick::RLECompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1543 else COMPRESS_MAGICK_IMAGE_VECTOR("deflate", Magick::ZipCompression)
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1544
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1545 #undef COMPRESS_MAGICK_IMAGE_VECTOR
5b8e4f668c53 Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents: 20338
diff changeset
1546
17226
46805642048f Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents: 17149
diff changeset
1547 write_file (filename, ext, imvec);
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1548
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1549 #endif
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1550 return retval;
7974
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1551 }
fcaddd090f98 imwrite: new function
John W. Eaton <jwe@octave.org>
parents: 7937
diff changeset
1552
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1553 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1554 ## 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
1555 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1556 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
1557
17351
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1558 // Gets the minimum information from images such as its size and format. Much
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1559 // faster than using imfinfo, which slows down a lot since. Note than without
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1560 // this, we need to read the image once for imfinfo to set defaults (which is
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1561 // done in Octave language), and then again for the actual reading.
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1562 DEFUN_DLD (__magick_ping__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1563 "-*- texinfo -*-\n\
17351
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1564 @deftypefn {Loadable Function} {} __magick_ping__ (@var{fname}, @var{idx})\n\
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1565 Ping image information with GraphicsMagick or ImageMagick.\n\
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1566 \n\
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1567 This is a private internal function not intended for direct use.\n\
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1568 \n\
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1569 @seealso{imfinfo}\n\
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1570 @end deftypefn")
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1571 {
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1572 octave_value retval;
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1573 #ifndef HAVE_MAGICK
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1574 gripe_disabled_feature ("imfinfo", "Image IO");
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1575 #else
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1576 maybe_initialize_magick ();
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1577
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1578 if (args.length () < 1 || ! args(0).is_string ())
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1579 {
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1580 print_usage ();
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1581 return retval;
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1582 }
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1583 const std::string filename = args(0).string_value ();
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1584 int idx;
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1585 if (args.length () > 1)
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1586 idx = args(1).int_value () -1;
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1587 else
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1588 idx = 0;
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1589
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1590 Magick::Image img;
17705
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1591 img.subImage (idx); // start ping from this image (in case of multi-page)
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1592 img.subRange (1); // ping only one of them
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1593 try
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1594 {
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1595 img.ping (filename);
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1596 }
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1597 catch (Magick::Warning& w)
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1598 {
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1599 warning ("Magick++ warning: %s", w.what ());
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1600 }
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1601 catch (Magick::Exception& e)
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1602 {
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1603 error ("Magick++ exception: %s", e.what ());
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1604 return retval;
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1605 }
292319fb7fcc Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents: 17561
diff changeset
1606
17351
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1607 static const char *fields[] = {"rows", "columns", "format", 0};
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1608 octave_scalar_map ping = octave_scalar_map (string_vector (fields));
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1609 ping.setfield ("rows", octave_value (img.rows ()));
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1610 ping.setfield ("columns", octave_value (img.columns ()));
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1611 ping.setfield ("format", octave_value (img.magick ()));
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1612 retval = octave_value (ping);
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1613 #endif
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1614 return retval;
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1615 }
80bf005cdf8e New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents: 17350
diff changeset
1616
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
1617 #ifdef HAVE_MAGICK
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1618 static octave_value
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1619 magick_to_octave_value (const Magick::CompressionType& magick)
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1620 {
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1621 switch (magick)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1622 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1623 case Magick::NoCompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1624 return octave_value ("none");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1625 case Magick::BZipCompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1626 return octave_value ("bzip");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1627 case Magick::FaxCompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1628 return octave_value ("fax3");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1629 case Magick::Group4Compression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1630 return octave_value ("fax4");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1631 case Magick::JPEGCompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1632 return octave_value ("jpeg");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1633 case Magick::LZWCompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1634 return octave_value ("lzw");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1635 case Magick::RLECompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1636 // This is named "rle" for the HDF, but the same thing is named
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1637 // "ccitt" and "PackBits" for binary and non-binary images in TIFF.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1638 return octave_value ("rle");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1639 case Magick::ZipCompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1640 return octave_value ("deflate");
17362
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1641
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1642 // The following are present only in recent versions of GraphicsMagick.
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1643 // At the moment the only use of this would be to have imfinfo report
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1644 // the compression method. In the future, someone could implement
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1645 // the Compression option for imwrite in which case a macro in
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1646 // configure.ac will have to check for their presence of this.
6e1a3b8fc312 __magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents: 17359
diff changeset
1647 // See bug #39913
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1648 // case Magick::LZMACompression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1649 // return octave_value ("lzma");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1650 // case Magick::JPEG2000Compression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1651 // return octave_value ("jpeg2000");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1652 // case Magick::JBIG1Compression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1653 // return octave_value ("jbig1");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1654 // case Magick::JBIG2Compression:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1655 // return octave_value ("jbig2");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1656 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1657 return octave_value ("undefined");
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1658 }
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1659 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1660
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1661 static octave_value
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1662 magick_to_octave_value (const Magick::EndianType& magick)
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1663 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1664 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1665 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1666 case Magick::LSBEndian:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1667 return octave_value ("little-endian");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1668 case Magick::MSBEndian:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1669 return octave_value ("big-endian");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1670 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1671 return octave_value ("undefined");
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1672 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1673 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1674
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1675 static octave_value
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1676 magick_to_octave_value (const Magick::OrientationType& magick)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1677 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1678 switch (magick)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1679 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1680 // Values come from the TIFF6 spec
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1681 case Magick::TopLeftOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1682 return octave_value (1);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1683 case Magick::TopRightOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1684 return octave_value (2);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1685 case Magick::BottomRightOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1686 return octave_value (3);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1687 case Magick::BottomLeftOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1688 return octave_value (4);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1689 case Magick::LeftTopOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1690 return octave_value (5);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1691 case Magick::RightTopOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1692 return octave_value (6);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1693 case Magick::RightBottomOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1694 return octave_value (7);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1695 case Magick::LeftBottomOrientation:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1696 return octave_value (8);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1697 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1698 return octave_value (1);
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1699 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1700 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1701
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1702 static octave_value
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1703 magick_to_octave_value (const Magick::ResolutionType& magick)
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1704 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1705 switch (magick)
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1706 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1707 case Magick::PixelsPerInchResolution:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1708 return octave_value ("Inch");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1709 case Magick::PixelsPerCentimeterResolution:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1710 return octave_value ("Centimeter");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1711 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1712 return octave_value ("undefined");
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1713 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1714 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1715
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1716 static bool
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1717 is_valid_exif (const std::string& val)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1718 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1719 // Sometimes GM will return the string "unknown" instead of empty
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1720 // for an empty value.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1721 return (! val.empty () && val != "unknown");
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1722 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1723
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1724 static void
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1725 fill_exif (octave_scalar_map& map, Magick::Image& img,
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1726 const std::string& key)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1727 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1728 const std::string attr = img.attribute ("EXIF:" + key);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1729 if (is_valid_exif (attr))
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1730 map.setfield (key, octave_value (attr));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1731 return;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1732 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1733
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1734 static void
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1735 fill_exif_ints (octave_scalar_map& map, Magick::Image& img,
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1736 const std::string& key)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1737 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1738 const std::string attr = img.attribute ("EXIF:" + key);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1739 if (is_valid_exif (attr))
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1740 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1741 // string of the type "float,float,float....."
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1742 float number;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1743 ColumnVector values (std::count (attr.begin (), attr.end (), ',') +1);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1744 std::string sub;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1745 std::istringstream sstream (attr);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1746 octave_idx_type n = 0;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1747 while (std::getline (sstream, sub, char (',')))
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1748 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1749 sscanf (sub.c_str (), "%f", &number);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1750 values(n++) = number;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1751 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1752 map.setfield (key, octave_value (values));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1753 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1754 return;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1755 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1756
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1757 static void
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1758 fill_exif_floats (octave_scalar_map& map, Magick::Image& img,
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1759 const std::string& key)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1760 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1761 const std::string attr = img.attribute ("EXIF:" + key);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1762 if (is_valid_exif (attr))
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1763 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1764 // string of the type "int/int,int/int,int/int....."
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1765 int numerator;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1766 int denominator;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1767 ColumnVector values (std::count (attr.begin (), attr.end (), ',') +1);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1768 std::string sub;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1769 std::istringstream sstream (attr);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1770 octave_idx_type n = 0;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1771 while (std::getline (sstream, sub, ','))
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1772 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1773 sscanf (sub.c_str (), "%i/%i", &numerator, &denominator);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1774 values(n++) = double (numerator) / double (denominator);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1775 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1776 map.setfield (key, octave_value (values));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1777 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1778 return;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1779 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1780
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
1781 #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
1782
9436
5302df15ad76 __magick_read__.cc: undo unintended change
John W. Eaton <jwe@octave.org>
parents: 9434
diff changeset
1783 DEFUN_DLD (__magick_finfo__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1784 "-*- 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
1785 @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
1786 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
1787 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20097
diff changeset
1788 This is a private internal function not intended for direct use.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20097
diff changeset
1789 Use @code{imfinfo} instead.\n\
16984
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1790 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
1791 @seealso{imfinfo, imformats, imread, imwrite}\n\
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1792 @end deftypefn")
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1793 {
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1794 octave_value retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1795
16983
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1796 #ifndef HAVE_MAGICK
4660d047955e Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 16944
diff changeset
1797 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
1798 #else
10947
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1799 maybe_initialize_magick ();
dc74ce93cfc4 initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
1800
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1801 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
1802 {
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1803 print_usage ();
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1804 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1805 }
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
1806 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
1807
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1808 std::vector<Magick::Image> imvec;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1809 read_file (filename, imvec);
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1810
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1811 const octave_idx_type nFrames = imvec.size ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1812 const std::string format = imvec[0].magick ();
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1813
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1814 // Here's how this function works. We need to return a struct array, one
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1815 // struct for each image in the file (remember, there are image
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1816 // that allow for multiple images in the same file). Now, Matlab seems
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1817 // to have format specific code so the fields on the struct are different
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1818 // for each format. It only has a small subset that is common to all
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1819 // of them, the others are undocumented. Because we try to abstract from
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1820 // the formats we always return the same list of fields (note that with
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1821 // GM we support more than 88 formats. That's way more than Matlab, and
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1822 // I don't want to write specific code for each of them).
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1823 //
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1824 // So what we do is we create an octave_scalar_map, fill it with the
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1825 // information for that image, and then insert it into an octave_map.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1826 // Because in the same file, different images may have values for
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1827 // different fields, we can't create a field only if there's a value.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1828 // Bad things happen if we merge octave_scalar_maps with different
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1829 // fields from the others (suppose for example a TIFF file with 4 images,
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1830 // where only the third image has a colormap.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1831
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1832 static const char *fields[] =
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1833 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1834 // These are fields that must always appear for Matlab.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1835 "Filename",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1836 "FileModDate",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1837 "FileSize",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1838 "Format",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1839 "FormatVersion",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1840 "Width",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1841 "Height",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1842 "BitDepth",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1843 "ColorType",
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1844
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1845 // These are format specific or not existent in Matlab. The most
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1846 // annoying thing is that Matlab may have different names for the
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1847 // same thing in different formats.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1848 "DelayTime",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1849 "DisposalMethod",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1850 "LoopCount",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1851 "ByteOrder",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1852 "Gamma",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1853 "Chromaticities",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1854 "Comment",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1855 "Quality",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1856 "Compression", // same as CompressionType
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1857 "Colormap", // same as ColorTable (in PNG)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1858 "Orientation",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1859 "ResolutionUnit",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1860 "XResolution",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1861 "YResolution",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1862 "Software", // sometimes is an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1863 "Make", // actually an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1864 "Model", // actually an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1865 "DateTime", // actually an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1866 "ImageDescription", // actually an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1867 "Artist", // actually an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1868 "Copyright", // actually an Exif tag
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1869 "DigitalCamera",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1870 "GPSInfo",
20097
1f9ed81bd173 maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents: 19885
diff changeset
1871 // Notes for the future: GM allows one to get many attributes, and even has
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1872 // attribute() to obtain arbitrary ones, that may exist in only some
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1873 // cases. The following is a list of some methods and into what possible
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1874 // Matlab compatible values they may be converted.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1875 //
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1876 // colorSpace() -> PhotometricInterpretation
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1877 // backgroundColor() -> BackgroundColor
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1878 // interlaceType() -> Interlaced, InterlaceType, and PlanarConfiguration
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1879 // label() -> Title
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1880 0
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1881 };
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1882
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1883 // The one we will return at the end
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1884 octave_map info (dim_vector (nFrames, 1), string_vector (fields));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11585
diff changeset
1885
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1886 // Some of the fields in the struct are about file information and will be
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1887 // the same for all images in the file. So we create a template, fill in
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1888 // those values, and make a copy of the template for each image.
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1889 octave_scalar_map template_info = (string_vector (fields));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1890
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1891 template_info.setfield ("Format", octave_value (format));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1892 // We can't actually get FormatVersion but even Matlab sometimes can't.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1893 template_info.setfield ("FormatVersion", octave_value (""));
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1894
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1895 const file_stat fs (filename);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1896 if (fs)
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1897 {
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1898 const octave_localtime mtime (fs.mtime ());
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1899 const std::string filetime = mtime.strftime ("%e-%b-%Y %H:%M:%S");
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1900 template_info.setfield ("Filename", octave_value (filename));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1901 template_info.setfield ("FileModDate", octave_value (filetime));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1902 template_info.setfield ("FileSize", octave_value (fs.size ()));
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1903 }
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1904 else
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1905 {
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1906 error ("imfinfo: error reading '%s': %s",
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1907 filename.c_str (), fs.error ().c_str ());
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
1908 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
1909 }
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1910
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1911 for (octave_idx_type frame = 0; frame < nFrames; frame++)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1912 {
18553
548643c76a88 Use OCTAVE_QUIT between each image frame to allow Control-C during Image IO.
Carnë Draug <carandraug@octave.org>
parents: 18544
diff changeset
1913 OCTAVE_QUIT;
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1914 octave_scalar_map info_frame (template_info);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1915 const Magick::Image img = imvec[frame];
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1916
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1917 info_frame.setfield ("Width", octave_value (img.columns ()));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1918 info_frame.setfield ("Height", octave_value (img.rows ()));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1919 info_frame.setfield ("BitDepth",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1920 octave_value (get_depth (const_cast<Magick::Image&> (img))));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1921
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1922 // Stuff related to colormap, image class and type
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1923 // Because GM is too smart for us... Read the comments in is_indexed()
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1924 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1925 std::string color_type;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1926 Matrix cmap;
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1927 if (is_indexed (img))
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1928 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1929 color_type = "indexed";
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1930 cmap =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1931 read_maps (const_cast<Magick::Image&> (img))(0).matrix_value ();
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1932 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1933 else
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1934 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1935 switch (img.type ())
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1936 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1937 case Magick::BilevelType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1938 case Magick::GrayscaleType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1939 case Magick::GrayscaleMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1940 color_type = "grayscale";
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1941 break;
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1942
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1943 case Magick::TrueColorType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1944 case Magick::TrueColorMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1945 color_type = "truecolor";
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1946 break;
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1947
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1948 case Magick::PaletteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1949 case Magick::PaletteMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1950 // we should never get here or is_indexed needs to be fixed
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1951 color_type = "indexed";
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1952 break;
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1953
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1954 case Magick::ColorSeparationType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1955 case Magick::ColorSeparationMatteType:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1956 color_type = "CMYK";
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1957 break;
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1958
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1959 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1960 color_type = "undefined";
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1961 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1962 }
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1963 info_frame.setfield ("ColorType", octave_value (color_type));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1964 info_frame.setfield ("Colormap", octave_value (cmap));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1965 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1966
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1967 {
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1968 // Not all images have chroma values. In such cases, they'll
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
1969 // be all zeros. So rather than send a matrix of zeros, we will
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1970 // check for that, and send an empty vector instead.
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1971 RowVector chromaticities (8);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1972 double* chroma_fvec = chromaticities.fortran_vec ();
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1973 img.chromaWhitePoint (&chroma_fvec[0], &chroma_fvec[1]);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1974 img.chromaRedPrimary (&chroma_fvec[2], &chroma_fvec[3]);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1975 img.chromaGreenPrimary (&chroma_fvec[4], &chroma_fvec[5]);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1976 img.chromaBluePrimary (&chroma_fvec[6], &chroma_fvec[7]);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1977 if (chromaticities.nnz () == 0)
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1978 chromaticities = RowVector (0);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1979 info_frame.setfield ("Chromaticities", octave_value (chromaticities));
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1980 }
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1981
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1982 info_frame.setfield ("Gamma", octave_value (img.gamma ()));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1983 info_frame.setfield ("XResolution", octave_value (img.xResolution ()));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1984 info_frame.setfield ("YResolution", octave_value (img.yResolution ()));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1985 info_frame.setfield ("DelayTime", octave_value (img.animationDelay ()));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1986 info_frame.setfield ("LoopCount",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1987 octave_value (img.animationIterations ()));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1988 info_frame.setfield ("Quality", octave_value (img.quality ()));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1989 info_frame.setfield ("Comment", octave_value (img.comment ()));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1990
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1991 info_frame.setfield ("Compression",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1992 magick_to_octave_value (img.compressType ()));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1993 info_frame.setfield ("Orientation",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1994 magick_to_octave_value (img.orientation ()));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1995 info_frame.setfield ("ResolutionUnit",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1996 magick_to_octave_value (img.resolutionUnits ()));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1997 info_frame.setfield ("ByteOrder",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1998 magick_to_octave_value (img.endian ()));
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
1999
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2000 // It is not possible to know if there's an Exif field so we just
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2001 // check for the Exif Version value. If it does exists, then we
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2002 // bother about looking for specific fields.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2003 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2004 Magick::Image& cimg = const_cast<Magick::Image&> (img);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2005
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2006 // These will be in Exif tags but must appear as fields in the
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2007 // base struct array, not as another struct in one of its fields.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2008 // This is likely because they belong to the Baseline TIFF specs
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2009 // and may appear out of the Exif tag. So first we check if it
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2010 // exists outside the Exif tag.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2011 // See Section 4.6.4, table 4, page 28 of Exif specs version 2.3
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2012 // (CIPA DC- 008-Translation- 2010)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2013 static const char *base_exif_str_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2014 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2015 "DateTime",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2016 "ImageDescription",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2017 "Make",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2018 "Model",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2019 "Software",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2020 "Artist",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2021 "Copyright",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2022 0,
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2023 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2024 static const string_vector base_exif_str (base_exif_str_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2025 static const octave_idx_type n_base_exif_str = base_exif_str.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2026 for (octave_idx_type field = 0; field < n_base_exif_str; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2027 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2028 info_frame.setfield (base_exif_str[field],
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2029 octave_value (cimg.attribute (base_exif_str[field])));
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2030 fill_exif (info_frame, cimg, base_exif_str[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2031 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2032
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2033 octave_scalar_map camera;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2034 octave_scalar_map gps;
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2035 if (! cimg.attribute ("EXIF:ExifVersion").empty ())
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2036 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2037 // See Section 4.6.5, table 7 and 8, over pages page 42 to 43
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2038 // of Exif specs version 2.3 (CIPA DC- 008-Translation- 2010)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2039
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2040 // Listed on the Exif specs as being of type ASCII.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2041 static const char *exif_str_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2042 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2043 "RelatedSoundFile",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2044 "DateTimeOriginal",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2045 "DateTimeDigitized",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2046 "SubSecTime",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2047 "DateTimeOriginal",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2048 "SubSecTimeOriginal",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2049 "SubSecTimeDigitized",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2050 "ImageUniqueID",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2051 "CameraOwnerName",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2052 "BodySerialNumber",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2053 "LensMake",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2054 "LensModel",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2055 "LensSerialNumber",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2056 "SpectralSensitivity",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2057 // These last two are of type undefined but most likely will
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2058 // be strings. Even if they're not GM returns a string anyway.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2059 "UserComment",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2060 "MakerComment",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2061 0
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2062 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2063 static const string_vector exif_str (exif_str_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2064 static const octave_idx_type n_exif_str = exif_str.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2065 for (octave_idx_type field = 0; field < n_exif_str; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2066 fill_exif (camera, cimg, exif_str[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2067
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2068 // Listed on the Exif specs as being of type SHORT or LONG.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2069 static const char *exif_int_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2070 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2071 "ColorSpace",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2072 "ExifImageWidth", // PixelXDimension (CPixelXDimension in Matlab)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2073 "ExifImageHeight", // PixelYDimension (CPixelYDimension in Matlab)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2074 "PhotographicSensitivity",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2075 "StandardOutputSensitivity",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2076 "RecommendedExposureIndex",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2077 "ISOSpeed",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2078 "ISOSpeedLatitudeyyy",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2079 "ISOSpeedLatitudezzz",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2080 "FocalPlaneResolutionUnit",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2081 "FocalLengthIn35mmFilm",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2082 // Listed as SHORT or LONG but with more than 1 count.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2083 "SubjectArea",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2084 "SubjectLocation",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2085 // While the following are an integer, their value have a meaning
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2086 // that must be represented as a string for Matlab compatibility.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2087 // For example, a 3 on ExposureProgram, would return
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2088 // "Aperture priority" as defined on the Exif specs.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2089 "ExposureProgram",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2090 "SensitivityType",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2091 "MeteringMode",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2092 "LightSource",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2093 "Flash",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2094 "SensingMethod",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2095 "FileSource",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2096 "CustomRendered",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2097 "ExposureMode",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2098 "WhiteBalance",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2099 "SceneCaptureType",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2100 "GainControl",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2101 "Contrast",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2102 "Saturation",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2103 "Sharpness",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2104 "SubjectDistanceRange",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2105 0
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2106 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2107 static const string_vector exif_int (exif_int_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2108 static const octave_idx_type n_exif_int = exif_int.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2109 for (octave_idx_type field = 0; field < n_exif_int; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2110 fill_exif_ints (camera, cimg, exif_int[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2111
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2112 // Listed as RATIONAL or SRATIONAL
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2113 static const char *exif_float_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2114 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2115 "Gamma",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2116 "CompressedBitsPerPixel",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2117 "ExposureTime",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2118 "FNumber",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2119 "ShutterSpeedValue", // SRATIONAL
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2120 "ApertureValue",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2121 "BrightnessValue", // SRATIONAL
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2122 "ExposureBiasValue", // SRATIONAL
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2123 "MaxApertureValue",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2124 "SubjectDistance",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2125 "FocalLength",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2126 "FlashEnergy",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2127 "FocalPlaneXResolution",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2128 "FocalPlaneYResolution",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2129 "ExposureIndex",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2130 "DigitalZoomRatio",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2131 // Listed as RATIONAL or SRATIONAL with more than 1 count.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2132 "LensSpecification",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2133 0
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2134 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2135 static const string_vector exif_float (exif_float_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2136 static const octave_idx_type n_exif_float = exif_float.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2137 for (octave_idx_type field = 0; field < n_exif_float; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2138 fill_exif_floats (camera, cimg, exif_float[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2139
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2140 // Inside a Exif field, it is possible that there is also a
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2141 // GPS field. This is not the same as ExifVersion but seems
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2142 // to be how we have to check for it.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2143 if (cimg.attribute ("EXIF:GPSInfo") != "unknown")
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2144 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2145 // The story here is the same as with Exif.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2146 // See Section 4.6.6, table 15 on page 68 of Exif specs
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2147 // version 2.3 (CIPA DC- 008-Translation- 2010)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2148
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2149 static const char *gps_str_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2150 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2151 "GPSLatitudeRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2152 "GPSLongitudeRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2153 "GPSAltitudeRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2154 "GPSSatellites",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2155 "GPSStatus",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2156 "GPSMeasureMode",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2157 "GPSSpeedRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2158 "GPSTrackRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2159 "GPSImgDirectionRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2160 "GPSMapDatum",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2161 "GPSDestLatitudeRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2162 "GPSDestLongitudeRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2163 "GPSDestBearingRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2164 "GPSDestDistanceRef",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2165 "GPSDateStamp",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2166 0
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2167 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2168 static const string_vector gps_str (gps_str_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2169 static const octave_idx_type n_gps_str = gps_str.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2170 for (octave_idx_type field = 0; field < n_gps_str; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2171 fill_exif (gps, cimg, gps_str[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2172
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2173 static const char *gps_int_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2174 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2175 "GPSDifferential",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2176 0
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2177 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2178 static const string_vector gps_int (gps_int_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2179 static const octave_idx_type n_gps_int = gps_int.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2180 for (octave_idx_type field = 0; field < n_gps_int; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2181 fill_exif_ints (gps, cimg, gps_int[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2182
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2183 static const char *gps_float_fields[] =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2184 {
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2185 "GPSAltitude",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2186 "GPSDOP",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2187 "GPSSpeed",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2188 "GPSTrack",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2189 "GPSImgDirection",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2190 "GPSDestBearing",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2191 "GPSDestDistance",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2192 "GPSHPositioningError",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2193 // Listed as RATIONAL or SRATIONAL with more than 1 count.
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2194 "GPSLatitude",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2195 "GPSLongitude",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2196 "GPSTimeStamp",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2197 "GPSDestLatitude",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2198 "GPSDestLongitude",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2199 0
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2200 };
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2201 static const string_vector gps_float (gps_float_fields);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2202 static const octave_idx_type n_gps_float = gps_float.numel ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2203 for (octave_idx_type field = 0; field < n_gps_float; field++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2204 fill_exif_floats (gps, cimg, gps_float[field]);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2205
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2206 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2207 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2208 info_frame.setfield ("DigitalCamera", octave_value (camera));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2209 info_frame.setfield ("GPSInfo", octave_value (gps));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2210 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2211
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
2212 info.fast_elem_insert (frame, info_frame);
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
2213 }
17359
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2214
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2215 if (format == "GIF")
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2216 {
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2217 static std::map<octave_idx_type, std::string> disposal_methods
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2218 = init_disposal_methods ();
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2219 string_vector methods (nFrames);
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2220 for (octave_idx_type frame = 0; frame < nFrames; frame++)
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2221 methods[frame] = disposal_methods[imvec[frame].gifDisposeMethod ()];
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2222 info.setfield ("DisposalMethod", Cell (methods));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2223 }
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2224 else
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2225 info.setfield ("DisposalMethod",
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2226 Cell (dim_vector (nFrames, 1), octave_value ("")));
cf5d41cc3695 Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents: 17351
diff changeset
2227
17350
ba79ba4e83ab Rewrite of imfinfo.
Carnë Draug <carandraug@octave.org>
parents: 17335
diff changeset
2228 retval = octave_value (info);
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
2229 #endif
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10298
diff changeset
2230 return retval;
8144
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
2231 }
01fac748b680 Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents: 8090
diff changeset
2232
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
2233 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
2234 ## 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
2235 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
2236 */
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
2237
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2238 DEFUN_DLD (__magick_formats__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2239 "-*- texinfo -*-\n\
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2240 @deftypefn {Loadable Function} {} __magick_imformats__ (@var{formats})\n\
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2241 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
2242 \n\
997efb8d0b19 imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents: 16983
diff changeset
2243 @seealso{imfinfo, imformats, imread, imwrite}\n\
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2244 @end deftypefn")
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2245 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2246 octave_value retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2247 #ifndef HAVE_MAGICK
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2248 gripe_disabled_feature ("imformats", "Image IO");
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2249 #else
17235
96a1c132e3c6 __magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents: 17228
diff changeset
2250 if (args.length () != 1 || ! args(0).is_map ())
16901
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2251 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2252 print_usage ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2253 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2254 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2255 octave_map formats = args(0).map_value ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2256
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2257 maybe_initialize_magick ();
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2258 for (octave_idx_type idx = 0; idx < formats.numel (); idx++)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2259 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2260 try
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2261 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2262 octave_scalar_map fmt = formats.checkelem (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2263 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2264
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2265 fmt.setfield ("description", octave_value (coder.description ()));
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2266 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2267 // 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
2268 // read or write them, them set it to an empty value
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2269 if (! coder.isReadable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2270 fmt.setfield ("read", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2271 if (! coder.isWritable ())
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2272 fmt.setfield ("write", Matrix ());
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2273 formats.fast_elem_insert (idx, fmt);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2274 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2275 catch (Magick::Exception& e)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2276 {
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2277 // Exception here are missing formats. So we remove the format
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2278 // from the structure and reduce idx.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2279 formats.delete_elements (idx);
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2280 idx--;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2281 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2282 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2283 retval = formats;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2284 #endif
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2285 return retval;
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2286 }
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2287
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2288 /*
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2289 ## No test needed for internal helper function.
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2290 %!assert (1)
861516dcad19 New function imformats.
Carnë Draug <carandraug@octave.org>
parents: 16871
diff changeset
2291 */