Mercurial > octave
annotate libinterp/corefcn/__magick_read__.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 32d2b6604a9f |
children | aac27ad79be6 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30390
diff
changeset
|
3 // Copyright (C) 2002-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
7926
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" |
28473
04ee5e8694cb
__magick_read__.cc: Correctly read images from non-ASCII paths on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
31 #include "lo-sysdep.h" |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
32 #include "oct-env.h" |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
33 #include "oct-time.h" |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
34 |
21679
44f7664689f2
make __magick_read__ a built-in function (bug #41699)
John W. Eaton <jwe@octave.org>
parents:
21142
diff
changeset
|
35 #include "defun.h" |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
36 #include "error.h" |
8054 | 37 #include "ov-struct.h" |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
38 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21033
diff
changeset
|
39 #include "errwarn.h" |
16925
5c25f7ed080c
*__magick_read__.cc: add missing include of gripes.h
Torsten <ttl@justmail.de>
parents:
16901
diff
changeset
|
40 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
41 #if defined (HAVE_MAGICK) |
29969
7a4f16bff8fd
use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents:
29964
diff
changeset
|
42 # include <Magick++.h> |
7a4f16bff8fd
use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents:
29964
diff
changeset
|
43 # include <clocale> |
30283
b7bce52e4500
allow building with ImageMagick++ to work again (bug #49653)
Markus Mützel <markus.muetzel@gmx.de>
parents:
29969
diff
changeset
|
44 // FIXME: The following using declaration may be needed to build with |
b7bce52e4500
allow building with ImageMagick++ to work again (bug #49653)
Markus Mützel <markus.muetzel@gmx.de>
parents:
29969
diff
changeset
|
45 // ImageMagick. It doesn't appear to be needed for GraphicsMagick but |
b7bce52e4500
allow building with ImageMagick++ to work again (bug #49653)
Markus Mützel <markus.muetzel@gmx.de>
parents:
29969
diff
changeset
|
46 // it also doesn't seem to cause trouble. A configure test would be |
b7bce52e4500
allow building with ImageMagick++ to work again (bug #49653)
Markus Mützel <markus.muetzel@gmx.de>
parents:
29969
diff
changeset
|
47 // helpful. |
b7bce52e4500
allow building with ImageMagick++ to work again (bug #49653)
Markus Mützel <markus.muetzel@gmx.de>
parents:
29969
diff
changeset
|
48 using Magick::Quantum; |
29969
7a4f16bff8fd
use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents:
29964
diff
changeset
|
49 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
50 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
51 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29931
diff
changeset
|
52 |
29969
7a4f16bff8fd
use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents:
29964
diff
changeset
|
53 #if defined (HAVE_MAGICK) |
7a4f16bff8fd
use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents:
29964
diff
changeset
|
54 |
17350 | 55 // In theory, it should be enough to check the class: |
56 // Magick::ClassType | |
57 // PseudoClass: | |
58 // Image is composed of pixels which specify an index in a color palette. | |
59 // DirectClass: | |
60 // Image is composed of pixels which represent literal color values. | |
61 // | |
62 // GraphicsMagick does not really distinguishes between indexed and | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
63 // normal images. After reading a file, it decides itself the optimal |
17350 | 64 // way to store the image in memory, independently of the how the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
65 // image was stored in the file. That's what ClassType returns. While |
17350 | 66 // it seems to match the original file most of the times, this is |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
67 // not necessarily true all the times. See |
17350 | 68 // https://sourceforge.net/mailarchive/message.php?msg_id=31180507 |
69 // In addition to the ClassType, there is also ImageType which has a | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
70 // type for indexed images (PaletteType and PaletteMatteType). However, |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
71 // they also don't represent the original image. Not only does DirectClass |
17350 | 72 // can have a PaletteType, but also does a PseudoClass have non Palette |
73 // types. | |
74 // | |
75 // We can't do better without having format specific code which is | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
76 // what we are trying to avoid by using a library such as GM. We at |
17350 | 77 // least create workarounds for the most common problems. |
78 // | |
79 // 1) A grayscale jpeg image can report being indexed even though the | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
80 // JPEG format has no support for indexed images. We can at least |
17350 | 81 // fix this one. |
17373
8508b8ae46a8
imread: fix identification of PNG files as indexed.
Carnë Draug <carandraug@octave.org>
parents:
17372
diff
changeset
|
82 // 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
|
83 // from libpng) |
17350 | 84 static bool |
85 is_indexed (const Magick::Image& img) | |
86 { | |
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
|
87 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
|
88 // Our problem until now is non-indexed images, being represented as indexed |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
89 // by GM. The following attempts educated guesses to undo this optimization. |
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
|
90 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
|
91 { |
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 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
|
93 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
|
94 // The JPEG format does not support indexed images, but GM sometimes |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
95 // reports grayscale JPEG as indexed. Always false for JPEG. |
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
|
96 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
|
97 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
|
98 { |
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 // Newer versions of GM (at least does not happens with 1.3.16) will |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
100 // store values from the underlying library as image attributes. In |
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
|
101 // the case of PNG files, this is libpng where an indexed image will |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
102 // always have a value of 3 for "color-type-orig". This property |
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
|
103 // 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
|
104 // 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
|
105 // GM PseudoClass says. |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
106 const std::string color_type |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
107 = const_cast<Magick::Image&> (img).attribute ("PNG:IHDR.color-type-orig"); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
108 if (! color_type.empty () && color_type != "3") |
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
|
109 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
|
110 } |
914c3ce73665
__magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents:
18553
diff
changeset
|
111 } |
914c3ce73665
__magick_read__.cc: fix png check for image class in older GM (bug #42834).
Carnë Draug <carandraug@octave.org>
parents:
18553
diff
changeset
|
112 return indexed; |
17350 | 113 } |
114 | |
115 // The depth from depth() is not always correct for us but seems to be the | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
116 // best value we can get. For example, a grayscale png image with 1 bit |
17350 | 117 // per channel should return a depth of 1 but instead we get 8. |
118 // We could check channelDepth() but then, which channel has the data | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
119 // is not straightforward. So we'd have to check all |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
120 // the channels and select the highest value. But then, I also |
17350 | 121 // have a 16bit TIFF whose depth returns 16 (correct), but all of the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
122 // channels gives 8 (wrong). No idea why, maybe a bug in GM? |
17350 | 123 // Anyway, using depth() seems that only causes problems for binary |
124 // images, and the problem with channelDepth() is not making set them | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
125 // all to 1. So we will guess that if all channels have depth of 1, |
17350 | 126 // then we must have a binary image. |
127 // 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
|
128 // 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
|
129 // and transparency, we really need to check all of the channels (bug #41584). |
17350 | 130 static octave_idx_type |
131 get_depth (Magick::Image& img) | |
132 { | |
133 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
|
134 if (depth == 8 |
17350 | 135 && 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
|
136 && 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
|
137 && img.channelDepth (Magick::BlueChannel) == 1 |
17350 | 138 && 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
|
139 && 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
|
140 && 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
|
141 && img.channelDepth (Magick::BlackChannel) == 1 |
17350 | 142 && img.channelDepth (Magick::OpacityChannel) == 1 |
143 && img.channelDepth (Magick::GrayChannel) == 1) | |
144 depth = 1; | |
145 | |
146 return depth; | |
147 } | |
148 | |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
149 // We need this in case one of the sides of the image being read has |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
150 // width 1. In those cases, the type will come as scalar instead of range |
21308
c53bfd6d8e08
maint: Use American spelling for "behavior".
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
151 // since that's the behavior of the colon operator (1:1:1 will be a scalar, |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
152 // not a range). |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
153 static range<double> |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
154 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
|
155 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
156 range<double> output; |
27906
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
157 |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 { |
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
162 double value = region.scalar_value (); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
163 output = range<double> (value, value); |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
164 } |
27906
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
165 else if (region.is_matrix_type ()) |
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
166 { |
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
167 NDArray array = region.array_value (); |
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
168 double base = array(0); |
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
169 double limit = array(array.numel () - 1); |
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
170 double incr = array(1) - base; |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
171 output = range<double> (base, incr, limit); |
27906
1a06fa2fe13a
Don't error out in __magick_read__ if disable_range is true (bug #57528).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
172 } |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
173 else |
21142
a3362dd2dd52
doc: fix spelling of "unknown".
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20163
diff
changeset
|
174 error ("__magick_read__: unknown datatype for Region option"); |
17335
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
175 |
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
176 return output; |
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
177 } |
583306fe7e4f
Fix reading of images with height or width of 1 pixel.
Carnë Draug <carandraug@octave.org>
parents:
17334
diff
changeset
|
178 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
179 class |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
180 image_region |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
181 { |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
182 public: |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
183 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
184 image_region (const octave_scalar_map& options) |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
185 { |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
186 // FIXME: should we have better checking on the input map and values |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
187 // or is that expected to be done elsewhere? |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
188 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
189 const Cell pixel_region = options.getfield ("region").cell_value (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
190 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
191 // Subtract 1 to account for 0 indexing. |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
192 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
193 const range<double> rows = get_region_range (pixel_region (0)); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
194 const range<double> cols = get_region_range (pixel_region (1)); |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
195 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
196 m_row_start = rows.base () - 1; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
197 m_col_start = cols.base () - 1; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
198 m_row_end = rows.max () - 1; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
199 m_col_end = cols.max () - 1; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
200 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
201 m_row_cache = m_row_end - m_row_start + 1; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
202 m_col_cache = m_col_end - m_col_start + 1; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
203 |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
28535
diff
changeset
|
204 m_row_shift = m_col_cache * rows.increment (); |
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
28535
diff
changeset
|
205 m_col_shift = m_col_cache * (m_row_cache + rows.increment () - 1) - cols.increment (); |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
206 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
207 m_row_out = rows.numel (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
208 m_col_out = cols.numel (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
209 } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
210 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
211 // Default copy, move, and delete methods are all OK for this class. |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
212 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
213 image_region (const image_region&) = default; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
214 image_region (image_region&&) = default; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
215 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
216 image_region& operator = (const image_region&) = default; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
217 image_region& operator = (image_region&&) = default; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
218 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
219 ~image_region (void) = default; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
220 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
221 octave_idx_type row_start (void) const { return m_row_start; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
222 octave_idx_type col_start (void) const { return m_col_start; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
223 octave_idx_type row_end (void) const { return m_row_end; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
224 octave_idx_type col_end (void) const { return m_col_end; } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
225 |
17138
96526baf7423
Fix reading of images using PixelRegion with ranges ending before the limit.
Carnë Draug <carandraug@octave.org>
parents:
17134
diff
changeset
|
226 // 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
|
227 // min to account for cases where last element of range is the range limit. |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
228 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
229 octave_idx_type row_cache (void) const { return m_row_cache; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
230 octave_idx_type col_cache (void) const { return m_col_cache; } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
231 |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
232 // How much we have to shift in the memory when doing the loops. |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
233 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
234 octave_idx_type row_shift (void) const { return m_row_shift; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
235 octave_idx_type col_shift (void) const { return m_col_shift; } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
236 |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
237 // The actual height and width of the output image |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
238 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
239 octave_idx_type row_out (void) const { return m_row_out; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
240 octave_idx_type col_out (void) const { return m_col_out; } |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
241 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
242 private: |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
243 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
244 octave_idx_type m_row_start; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
245 octave_idx_type m_col_start; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
246 octave_idx_type m_row_end; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
247 octave_idx_type m_col_end; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
248 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
249 // Length of the area to load into the Image Pixel Cache. We use max and |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
250 // 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
|
251 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
252 octave_idx_type m_row_cache; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
253 octave_idx_type m_col_cache; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
254 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
255 // How much we have to shift in the memory when doing the loops. |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
256 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
257 octave_idx_type m_row_shift; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
258 octave_idx_type m_col_shift; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
259 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
260 // The actual height and width of the output image |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
261 |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
262 octave_idx_type m_row_out; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
263 octave_idx_type m_col_out; |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
264 }; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
265 |
17350 | 266 static octave_value_list |
267 read_maps (Magick::Image& img) | |
268 { | |
269 // can't call colorMapSize on const Magick::Image | |
270 const octave_idx_type mapsize = img.colorMapSize (); | |
271 Matrix cmap = Matrix (mapsize, 3); // colormap | |
17372
63b53ea33a8b
imread: fix returning multiple variables.
Carnë Draug <carandraug@octave.org>
parents:
17362
diff
changeset
|
272 ColumnVector amap = ColumnVector (mapsize); // alpha map |
17350 | 273 for (octave_idx_type i = 0; i < mapsize; i++) |
274 { | |
275 const Magick::ColorRGB c = img.colorMap (i); | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30283
diff
changeset
|
276 cmap(i, 0) = c.red (); |
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30283
diff
changeset
|
277 cmap(i, 1) = c.green (); |
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30283
diff
changeset
|
278 cmap(i, 2) = c.blue (); |
17372
63b53ea33a8b
imread: fix returning multiple variables.
Carnë Draug <carandraug@octave.org>
parents:
17362
diff
changeset
|
279 amap(i) = c.alpha (); |
17350 | 280 } |
281 octave_value_list maps; | |
282 maps(0) = cmap; | |
283 maps(1) = amap; | |
284 return maps; | |
285 } | |
286 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
287 template <typename T> |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
288 static octave_value_list |
17350 | 289 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
|
290 const Array<octave_idx_type>& frameidx, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
291 const octave_idx_type& nargout, |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
292 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
|
293 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
294 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
|
295 |
21358
f2ae78f5827f
Resolve compile time issues, when octave_idx_type is long.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
21308
diff
changeset
|
296 octave_value_list retval (1); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
297 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
298 image_region region (options); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
299 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
300 const octave_idx_type nFrames = frameidx.numel (); |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
301 const octave_idx_type nRows = region.row_out (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
302 const octave_idx_type nCols = region.col_out (); |
8054 | 303 |
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
|
304 // imvec has all of the pages of a file, even the ones we are not |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
305 // interested in. We will use the first image that we will be actually |
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
|
306 // 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
|
307 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
|
308 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
309 T img = T (dim_vector (nRows, nCols, 1, nFrames)); |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23416
diff
changeset
|
310 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
|
311 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
312 const octave_idx_type row_start = region.row_start (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
313 const octave_idx_type col_start = region.col_start (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
314 const octave_idx_type row_shift = region.row_shift (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
315 const octave_idx_type col_shift = region.col_shift (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
316 const octave_idx_type row_cache = region.row_cache (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
317 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
|
318 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
319 // When reading PixelPackets from the Image Pixel Cache, they come in |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
320 // row major order. So we keep moving back and forth there so we can |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
321 // 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
|
322 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
|
323 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
|
324 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
325 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
326 |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
327 imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
328 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
|
329 |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
330 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
|
331 = imvec[frameidx(frame)].getConstIndexes (); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
332 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
333 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
|
334 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
335 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
|
336 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
337 img_fvec[idx++] = static_cast<P> (*pix); |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
338 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
|
339 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
340 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
|
341 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
342 } |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
343 retval(0) = octave_value (img); |
7933 | 344 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
345 // 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
|
346 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
|
347 { |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
348 // 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
|
349 // have different colormaps but for Matlab compatibility, we only |
17350 | 350 // return the colormap of the first frame. To obtain the colormaps |
351 // of different frames, one needs can either use imfinfo or a for | |
352 // loop around imread. | |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
353 const octave_value_list maps |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
354 = 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
|
355 |
17350 | 356 retval(1) = maps(0); |
357 | |
358 // 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
|
359 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
|
360 { |
17350 | 361 const Matrix amap = maps(1).matrix_value (); |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
362 const double *amap_fvec = amap.data (); |
7933 | 363 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
364 NDArray alpha (dim_vector (nRows, nCols, 1, nFrames)); |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23416
diff
changeset
|
365 double *alpha_fvec = alpha.fortran_vec (); |
7933 | 366 |
17350 | 367 // GraphicsMagick stores the alpha values inverted, i.e., |
368 // 1 for transparent and 0 for opaque so we fix that here. | |
369 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
|
370 for (octave_idx_type pix = 0; pix < nPixels; pix++) |
17350 | 371 alpha_fvec[pix] = 1 - amap_fvec[static_cast<int> (img_fvec[3])]; |
372 | |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
373 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
|
374 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
375 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
376 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
377 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
|
378 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
379 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
380 // This function is highly repetitive, a bunch of for loops that are |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
381 // very similar to account for different image types. They are different |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
382 // 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
|
383 // readability too much. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
384 template <typename T> |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
385 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
|
386 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
|
387 const Array<octave_idx_type>& frameidx, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
388 const octave_idx_type& nargout, |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
389 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
|
390 { |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
391 typedef typename T::element_type P; |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
392 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
393 octave_value_list retval (3, Matrix ()); |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
394 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
395 image_region region (options); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
396 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
397 const octave_idx_type nFrames = frameidx.numel (); |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
398 const octave_idx_type nRows = region.row_out (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
399 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
|
400 T img; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
401 |
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
|
402 // imvec has all of the pages of a file, even the ones we are not |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
403 // interested in. We will use the first image that we will be actually |
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
|
404 // 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
|
405 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
|
406 |
22863
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
407 const octave_idx_type row_start = region.row_start (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
408 const octave_idx_type col_start = region.col_start (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
409 const octave_idx_type row_shift = region.row_shift (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
410 const octave_idx_type col_shift = region.col_shift (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
411 const octave_idx_type row_cache = region.row_cache (); |
f28e1f5d33a4
use simple class instead of std::set
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
412 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
|
413 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
414 // 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
|
415 // QuantumDepth it was built with independently of the original image |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
416 // bitdepth. Basically this means that if GM was built with quantum 16 |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
417 // all values are scaled in the uint16 range. If the original image |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
418 // 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
|
419 // However, if the image had a bitdepth of 32, then we will be returning |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
420 // a floating point image. In this case, the values need to be rescaled |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
421 // 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
|
422 // 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
|
423 // See bug #39249). |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
424 // 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
|
425 // using quantumOperator for the cases where we will be returning floating |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
426 // point and want things in the range [0 1]. This is the same reason why |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
427 // 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
|
428 // 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
|
429 // when depth() is 32. |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
430 // FIXME: in the next release of GraphicsMagick, MaxRGB should be replaced |
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
431 // 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
|
432 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
|
433 if (imvec[def_elem].depth () == 32) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
434 divisor = std::numeric_limits<uint32_t>::max (); |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
435 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
|
436 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
|
437 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
438 // 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
|
439 // new ImageType BilevelMatteType |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
440 // Despite what GM documentation claims, opacity is not only on the types |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
441 // with Matte on the name. It is possible that an image is completely |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
442 // black (1 color), and have a second channel set for transparency (2nd |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
443 // color). Its type will be bilevel since there is no BilevelMatte. The |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
444 // 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
|
445 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
|
446 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
|
447 type = Magick::GrayscaleMatteType; |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
448 |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
449 // FIXME: ImageType is the type being used to represent the image in memory |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
450 // by GM. The real type may be different (see among others bug #36820). For |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
451 // example, a png file where all channels are equal may report being |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
452 // grayscale or even bilevel. But we must always return the real image in |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
453 // file. In some cases, the original image attributes are stored in the |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
454 // attributes but this is undocumented. This should be fixed in GM so that |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
455 // 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
|
456 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
|
457 { |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
458 // 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
|
459 // Grayscale = 0 |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
460 // 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
|
461 // RGB = 2 |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
462 // 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
|
463 // 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
|
464 // 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
|
465 // 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
|
466 const std::string type_str |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
467 = 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
|
468 |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
469 if (type_str == "0") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
470 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
|
471 else if (type_str == "2") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
472 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
|
473 else if (type_str == "6") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
474 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
|
475 else if (type_str == "4") |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
476 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
|
477 // 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
|
478 // 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
|
479 // binary transparency, while 3 can have any level of alpha per |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
480 // palette entry. We thus must check matte() to see if the image |
17239
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
481 // 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
|
482 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
|
483 { |
d6467d6dfb83
Fix reading of alpha channel stored as tRNS chunk in PNG files.
Carnë Draug <carandraug@octave.org>
parents:
17235
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 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
|
488 } |
17149
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
489 } |
73a3c1580974
Correctly identify PNG image types (bug #32986, bug #36820 and bug #37689)
Carnë Draug <carandraug@octave.org>
parents:
17147
diff
changeset
|
490 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
491 // 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
|
492 // 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
|
493 if (nargout < 3) |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
494 { |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
495 switch (type) |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
496 { |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
497 case Magick::GrayscaleMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
498 type = Magick::GrayscaleType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
499 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
500 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
501 case Magick::PaletteMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
502 type = Magick::PaletteType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
503 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
504 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
505 case Magick::TrueColorMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
506 type = Magick::TrueColorType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
507 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
508 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
509 case Magick::ColorSeparationMatteType: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
510 type = Magick::ColorSeparationType; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
511 break; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
512 |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
513 default: |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
514 // Do nothing other than silencing warnings about enumeration |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
515 // values not being handled in switch. |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
516 ; |
17116
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
517 } |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
518 } |
59acfe9209dd
Do not read alpha channel from image if output not requested.
Carnë Draug <carandraug@octave.org>
parents:
17110
diff
changeset
|
519 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
520 const octave_idx_type color_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
|
521 switch (type) |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
522 { |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
523 case Magick::BilevelType: // Monochrome bi-level image |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
524 case Magick::GrayscaleType: // Grayscale image |
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 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
|
527 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
|
528 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
529 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
|
530 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
|
531 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
532 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
533 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
534 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
535 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
536 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
537 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
538 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
|
539 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
540 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
|
541 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
542 img_fvec[idx++] = pix->red / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
543 pix += row_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
544 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
545 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
546 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
547 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
548 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
549 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
550 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
551 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
|
552 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
553 img = T (dim_vector (nRows, nCols, 1, nFrames)); |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
554 T alpha (dim_vector (nRows, nCols, 1, nFrames)); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
555 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
|
556 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
|
557 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
558 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
|
559 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
|
560 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
561 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
562 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
563 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
564 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
565 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
566 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
567 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
|
568 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
569 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
|
570 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
571 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
|
572 a_fvec[idx] = (MaxRGB - pix->opacity) / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
573 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
|
574 idx++; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
575 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
576 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
577 } |
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
578 } |
17110
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 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
582 |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
583 case Magick::PaletteType: // Indexed color (palette) image |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
584 case Magick::TrueColorType: // Truecolor image |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
585 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
586 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
|
587 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
|
588 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
589 const octave_idx_type frame_stride = color_stride * 3; |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
590 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
|
591 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
592 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
593 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
594 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
595 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
596 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
597 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
598 octave_idx_type idx = 0; |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
599 P *rbuf = img_fvec; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
600 P *gbuf = img_fvec + color_stride; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
601 P *bbuf = img_fvec + color_stride * 2; |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
602 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
603 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
|
604 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
605 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
|
606 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
607 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
|
608 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
|
609 bbuf[idx] = pix->blue / 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; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
616 } |
17110
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 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
619 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
620 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
|
621 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
|
622 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
623 img = T (dim_vector (nRows, nCols, 3, nFrames)); |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
624 T alpha (dim_vector (nRows, nCols, 1, nFrames)); |
17110
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 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
628 const octave_idx_type frame_stride = color_stride * 3; |
18542
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 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
635 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
636 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
637 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
638 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
639 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
|
640 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
641 octave_idx_type idx = 0; |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
642 P *rbuf = img_fvec; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
643 P *gbuf = img_fvec + color_stride; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
644 P *bbuf = img_fvec + color_stride * 2; |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
645 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
646 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
|
647 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
648 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
|
649 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
650 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
|
651 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
|
652 bbuf[idx] = pix->blue / divisor; |
17147
35a1bd41aa02
Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17139
diff
changeset
|
653 a_fvec[a_idx++] = (MaxRGB - pix->opacity) / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
654 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
|
655 idx++; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
656 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
657 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
|
658 } |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
659 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
|
660 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
661 retval(2) = alpha; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
662 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
663 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
664 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 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
|
666 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
667 img = T (dim_vector (nRows, nCols, 4, nFrames)); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
668 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
|
669 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
670 const octave_idx_type frame_stride = color_stride * 4; |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
671 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
|
672 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
673 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
674 |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
675 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
676 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
677 col_cache, row_cache); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
678 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
679 octave_idx_type idx = 0; |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
680 P *cbuf = img_fvec; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
681 P *mbuf = img_fvec + color_stride; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
682 P *ybuf = img_fvec + color_stride * 2; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
683 P *kbuf = img_fvec + color_stride * 3; |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
684 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
685 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
|
686 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
687 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
|
688 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 kbuf[idx] = pix->opacity / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
693 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
|
694 idx++; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
695 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
696 pix -= col_shift; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
697 } |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
698 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
|
699 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
700 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
701 } |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
702 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
703 // 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
|
704 case Magick::ColorSeparationMatteType: |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
705 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
706 img = T (dim_vector (nRows, nCols, 4, nFrames)); |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
707 T alpha (dim_vector (nRows, nCols, 1, nFrames)); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
708 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
|
709 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
|
710 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
711 const octave_idx_type frame_stride = color_stride * 4; |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
712 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
713 // 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
|
714 // 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
|
715 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
|
716 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
|
717 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
718 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
719 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
720 const Magick::PixelPacket *pix |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
721 = imvec[frameidx(frame)].getConstPixels (col_start, row_start, |
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
722 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
|
723 // Note that for CMYKColorspace + matte (CMYKA), the opacity is |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
724 // stored in the associated IndexPacket. |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
725 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
|
726 = imvec[frameidx(frame)].getConstIndexes (); |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
727 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
728 octave_idx_type idx = 0; |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
729 P *cbuf = img_fvec; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
730 P *mbuf = img_fvec + color_stride; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
731 P *ybuf = img_fvec + color_stride * 2; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
732 P *kbuf = img_fvec + color_stride * 3; |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
733 |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
734 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
|
735 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
736 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
|
737 { |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
738 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
|
739 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
|
740 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
|
741 kbuf[idx] = pix->opacity / divisor; |
17147
35a1bd41aa02
Fix reading of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17139
diff
changeset
|
742 a_fvec[a_idx++] = (MaxRGB - *apix) / divisor; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
743 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
|
744 idx++; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
745 } |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
746 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
|
747 } |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
748 img_fvec += frame_stride; |
10295
13d382fc758b
imread: Make reading non-indexed images faster
David Grundberg <davidg@cs.umu.se>
parents:
10193
diff
changeset
|
749 } |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
750 retval(2) = alpha; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
751 break; |
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
752 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
753 |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
754 default: |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
755 error ("__magick_read__: unknown Magick++ image type"); |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
756 } |
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
757 |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
758 retval(0) = img; |
20869
69b37757030c
2015 Code Sprint: __magick_read__.cc: use ovl ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
759 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
760 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
|
761 } |
7974 | 762 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
763 // Read a file into vector of image objects. |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
764 void static |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
765 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
|
766 { |
28535
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
767 // FIXME: We need this on Windows because GraphicsMagick uses the ANSI API |
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
768 // to open files on disc. In contrast, the API of ImageMagick uses UTF-8 |
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
769 // encoded strings. Should we somehow detect which is used on runtime and |
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
770 // pass the file names accordingly? (See also bug #58493.) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
771 std::string ascii_fname = sys::get_ASCII_filename (filename, true); |
28473
04ee5e8694cb
__magick_read__.cc: Correctly read images from non-ASCII paths on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
772 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
773 try |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
774 { |
28535
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
775 Magick::readImages (&imvec, ascii_fname); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
776 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
777 catch (const Magick::Warning& w) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
778 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
779 warning ("Magick++ warning: %s", w.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
780 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
781 catch (const Magick::Exception& e) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
782 { |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
783 error ("Magick++ exception: %s", e.what ()); |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
784 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
785 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
786 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
787 static void |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
788 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
|
789 { |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
790 static bool initialized = false; |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
791 |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
792 if (! initialized) |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
793 { |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
794 // Save locale as GraphicsMagick might change this (fixed in |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
795 // GraphicsMagick since version 1.3.13 released on December 24, 2011) |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
796 const char *static_locale = setlocale (LC_ALL, nullptr); |
26488
72e0a106d956
__magick_read__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
797 const std::string locale = (static_locale ? static_locale : ""); |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
798 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
799 const std::string program_name |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
800 = sys::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
|
801 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
|
802 |
10739
d27bd2f74137
src/DLD_FUNCTIONS/__magick_read__.cc: restore locale after GraphicsMagick initialisation
Soren Hauberg <hauberg@gmail.com>
parents:
10390
diff
changeset
|
803 // 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
|
804 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
|
805 |
20729
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
806 // Why should we give a warning? |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
807 // Magick does not tell us the real bitdepth of the image in file. |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
808 // The best we can have is the minimum between the bitdepth of the |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
809 // file and the quantum depth. So we never know if the file will |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
810 // actually be read correctly so we warn the user that it might |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
811 // be limited. |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
812 // |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
813 // Why we warn if < 16 instead of < 32 ? |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
814 // The reasons for < 32 is simply that it's the maximum quantum |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
815 // depth they support. However, very few people would actually |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
816 // need such support while being a major inconvenience to anyone |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
817 // else (8 bit images suddenly taking 4x more space will be |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
818 // critical for multi page images). It would also suggests that |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
819 // it covers all images which does not (it still does not support |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
820 // float point and signed integer images). |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
821 // On the other hand, 16bit images are much more common. If quantum |
20729
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
822 // depth is 8, there's a good chance that we will be limited. It |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
823 // is also the GraphicsMagick recommended setting and the default |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
824 // for ImageMagick. |
131b4af8b5d8
Only warn of Magick quantum depth if less than 16 instead of 32.
Carnë Draug <carandraug@octave.org>
parents:
20704
diff
changeset
|
825 if (QuantumDepth < 16) |
23416
a40434df6f54
Rename warning ID GraphicsMagic-Quantum-Depth GraphicsMagick-Quantum-Depth.
Carnë Draug <carandraug@octave.org>
parents:
23220
diff
changeset
|
826 warning_with_id ("Octave:GraphicsMagick-Quantum-Depth", |
20219
b39ba1bbb759
Don't print unecessary backtrace for GraphicsMagick warning about pixel depth.
Rik <rik@octave.org>
parents:
20163
diff
changeset
|
827 "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
|
828 MagickPackageName, QuantumDepth); |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
829 |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
830 initialized = true; |
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
831 } |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
832 } |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
833 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
834 #endif |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
835 |
21679
44f7664689f2
make __magick_read__ a built-in function (bug #41699)
John W. Eaton <jwe@octave.org>
parents:
21142
diff
changeset
|
836 DEFUN (__magick_read__, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
837 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
838 @deftypefn {} {[@var{img}, @var{map}, @var{alpha}] =} __magick_read__ (@var{fname}, @var{options}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
839 Read image with GraphicsMagick or ImageMagick. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
840 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
841 This is a private internal function not intended for direct use. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
842 Use @code{imread} instead. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
843 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
844 @seealso{imfinfo, imformats, imread, imwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
845 @end deftypefn */) |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
846 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
847 #if defined (HAVE_MAGICK) |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
848 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
849 if (args.length () != 2 || ! args(0).is_string ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
850 print_usage (); |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
851 |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
852 maybe_initialize_magick (); |
10390
ad0b54ae206a
__magick_read__ (F__magick_read__): call Magick::InitializeMagick
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
853 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
854 const octave_scalar_map options |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
855 = args(1).xscalar_map_value ("__magick_read__: OPTIONS must be a struct"); |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
856 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
857 octave_value_list output; |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
858 |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
859 std::vector<Magick::Image> imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
860 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
|
861 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
862 // 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
|
863 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
|
864 Array<octave_idx_type> frameidx; |
17118
c97a26408ee0
Implement PixelRegion option for imread().
Carnë Draug <carandraug@octave.org>
parents:
17116
diff
changeset
|
865 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
|
866 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
|
867 { |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
868 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
|
869 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
|
870 frameidx(i) = i; |
10778
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
871 } |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
872 else |
6035bf68a755
Support imread('file', 'frames', 'all') (Feature Request #30365)
David Bateman <dbateman@free.fr>
parents:
10739
diff
changeset
|
873 { |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
874 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
|
875 |
16989
7a69ab84b8c9
__magick_write__: confirm file exists before reading to append.
Carnë Draug <carandraug@octave.org>
parents:
16988
diff
changeset
|
876 // 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
|
877 // 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
|
878 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
|
879 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
|
880 { |
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
881 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
|
882 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
|
883 { |
17912
01496d4811b1
imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents:
17861
diff
changeset
|
884 // 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
|
885 // 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
|
886 // 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
|
887 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
|
888 } |
8053 | 889 } |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
890 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
891 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
892 // Check that all frames have the same size. We don't do this at the same |
17912
01496d4811b1
imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents:
17861
diff
changeset
|
893 // 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
|
894 // 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
|
895 // 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
|
896 { |
c7f089c560cc
imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents:
17912
diff
changeset
|
897 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
|
898 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
|
899 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
|
900 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
|
901 { |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
902 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
|
903 || 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
|
904 { |
26164
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25688
diff
changeset
|
905 error ("imread: all frames must have the same size but frame " |
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25688
diff
changeset
|
906 "%" OCTAVE_IDX_TYPE_FORMAT " is different", |
17916
c7f089c560cc
imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents:
17912
diff
changeset
|
907 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
|
908 } |
c7f089c560cc
imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents:
17912
diff
changeset
|
909 } |
c7f089c560cc
imread: avoid out of bounds error when reading part of multipage image file.
Carnë Draug <carandraug@octave.org>
parents:
17912
diff
changeset
|
910 } |
17912
01496d4811b1
imread: deal elegantly with multiples frames of different sizes.
Carnë Draug <carandraug@octave.org>
parents:
17861
diff
changeset
|
911 |
17350 | 912 const octave_idx_type depth = get_depth (imvec[frameidx(0)]); |
913 if (is_indexed (imvec[frameidx(0)])) | |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
914 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
915 if (depth <= 1) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
916 output = read_indexed_images<boolNDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
917 nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
918 else if (depth <= 8) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
919 output = read_indexed_images<uint8NDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
920 nargout, options); |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
921 else if (depth <= 16) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
922 output = read_indexed_images<uint16NDArray> (imvec, frameidx, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
923 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
|
924 else |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
925 error ("imread: indexed images with depths greater than 16-bit are not supported"); |
16984
997efb8d0b19
imread: implement options Index, Frames, and Info.
Carnë Draug <carandraug@octave.org>
parents:
16983
diff
changeset
|
926 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11585
diff
changeset
|
927 |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
928 else |
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
929 { |
17110
95055b814d35
imread: implement reading of images with 32 bitdepth and alpha channels.
Carnë Draug <carandraug@octave.org>
parents:
16996
diff
changeset
|
930 if (depth <= 1) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
931 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
|
932 else if (depth <= 8) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
933 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
|
934 else if (depth <= 16) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
935 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
|
936 else if (depth <= 32) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
937 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
|
938 else |
26164
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25688
diff
changeset
|
939 error ("imread: reading of images with %" OCTAVE_IDX_TYPE_FORMAT |
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25688
diff
changeset
|
940 "-bit depth is not supported", depth); |
16996
a1d091243d11
Read alpha values from indexed images. Always read indexes from indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16989
diff
changeset
|
941 } |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
942 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
943 return output; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
944 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
945 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
946 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
947 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
948 octave_unused_parameter (nargout); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
949 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21033
diff
changeset
|
950 err_disabled_feature ("imread", "Image IO"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
951 |
7937
6661387827d6
Allow build without GraphicsMagick installed
David Bateman <dbateman@free.fr>
parents:
7933
diff
changeset
|
952 #endif |
7925
9316b59903c9
Add original imread() files (from octave-forge) to core octave.
Thomas L. Scofield <scofield AT calvin DOT edu>
parents:
diff
changeset
|
953 } |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7925
diff
changeset
|
954 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
955 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
956 ## 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
|
957 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
958 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
959 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
960 #if defined (HAVE_MAGICK) |
7974 | 961 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
962 template <typename T> |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
963 static uint32NDArray |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
964 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
|
965 { |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
966 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
|
967 uint32NDArray out (img.dims ()); |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
968 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23416
diff
changeset
|
969 octave_uint32 *out_fvec = out.fortran_vec (); |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
970 const P *img_fvec = img.data (); |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
971 |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
972 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
|
973 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
|
974 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
|
975 out_fvec[idx] = img_fvec[idx] * max; |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
976 |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
977 return out; |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
978 } |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
979 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
980 // 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
|
981 // uint8, 16 for uint16, and 32 for uint32 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
982 template <typename T> |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
983 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
|
984 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
|
985 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
986 typedef typename T::element_type P; |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
987 const octave_idx_type bitdepth |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
988 = sizeof (P) * std::numeric_limits<unsigned char>::digits; |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
989 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
|
990 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
991 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
992 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
998 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
|
999 // 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
|
1000 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
|
1001 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1002 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
|
1003 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
|
1004 // 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
|
1005 // 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
|
1006 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
|
1007 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
|
1008 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1009 case Magick::GrayscaleMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1010 case Magick::TrueColorMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1011 case Magick::ColorSeparationMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1012 case Magick::PaletteMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1013 img.matte (true); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1014 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
|
1015 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1016 default: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1017 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
|
1018 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1019 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1020 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
|
1021 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1022 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
1023 template <typename T> |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1024 static void |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1025 encode_indexed_images (std::vector<Magick::Image>& imvec, |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1026 const T& img, |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1027 const Matrix& cmap) |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1028 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1029 typedef typename T::element_type P; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
1030 const octave_idx_type nFrames = (img.ndims () < 4 ? 1 : img.dims ()(3)); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1031 const octave_idx_type nRows = img.rows (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1032 const octave_idx_type nCols = img.columns (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1033 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
|
1034 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
|
1035 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1036 // There is no colormap object, we need to build a new one for each frame, |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1037 // even if it's always the same. We can least get a vector for the Colors. |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1038 std::vector<Magick::ColorRGB> colormap; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1039 { |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1040 const double *cmap_fvec = cmap.data (); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1041 const octave_idx_type G_offset = cmap_size; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1042 const octave_idx_type B_offset = cmap_size * 2; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1043 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
|
1044 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
|
1045 cmap_fvec[map_idx + G_offset], |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1046 cmap_fvec[map_idx + B_offset])); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1047 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1048 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1049 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1050 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1051 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1052 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1053 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
|
1054 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
|
1055 Magick::PseudoClass); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1056 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1057 // Insert colormap. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1058 m_img.colorMapSize (cmap_size); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1059 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
|
1060 m_img.colorMap (map_idx, colormap[map_idx]); |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1061 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1062 // 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
|
1063 // index values? We don't know if a file format supports indexed |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1064 // images. If we only set the indexes and then try to save the |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1065 // 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
|
1066 // there is no conversion from the indexes, it's the initial values |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1067 // that get used. An alternative would be to only set the pixel |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1068 // values (no indexes), then set the image as PseudoClass and GM |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1069 // would create a colormap for us. However, we wouldn't have control |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1070 // over the order of that colormap. And that's why we set both. |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23416
diff
changeset
|
1071 Magick::PixelPacket *pix = m_img.getPixels (0, 0, nCols, nRows); |
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23416
diff
changeset
|
1072 Magick::IndexPacket *ind = m_img.getIndexes (); |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1073 const P *img_fvec = img.data (); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1074 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1075 octave_idx_type GM_idx = 0; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1076 for (octave_idx_type column = 0; column < nCols; column++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1077 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1078 for (octave_idx_type row = 0; row < nRows; row++) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1079 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1080 ind[GM_idx] = double (*img_fvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1081 pix[GM_idx] = m_img.colorMap (double (*img_fvec)); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1082 img_fvec++; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1083 GM_idx += nCols; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1084 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1085 GM_idx -= nCols * nRows - 1; |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1086 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1087 |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1088 // Save changes to underlying image. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1089 m_img.syncPixels (); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1090 imvec.push_back (m_img); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1091 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1092 } |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1093 |
8054 | 1094 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
|
1095 encode_bool_image (std::vector<Magick::Image>& imvec, const boolNDArray& img) |
7974 | 1096 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
1097 const octave_idx_type nFrames = (img.ndims () < 4 ? 1 : img.dims ()(3)); |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
1098 const octave_idx_type nRows = img.rows (); |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21567
diff
changeset
|
1099 const octave_idx_type nCols = img.columns (); |
8054 | 1100 |
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 // 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
|
1102 const Magick::Color white ("white"); |
8054 | 1103 |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1104 const bool *img_fvec = img.data (); |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1105 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
|
1106 for (octave_idx_type frame = 0; frame < nFrames; frame++) |
8054 | 1107 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1108 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1109 |
17333
51c011825bcc
__magick_write__: make sure binary images are saved as bilevel for some coders.
Carnë Draug <carandraug@octave.org>
parents:
17332
diff
changeset
|
1110 // 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
|
1111 // 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
|
1112 // 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
|
1113 // 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
|
1114 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
|
1115 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
|
1116 Magick::DirectClass); |
8054 | 1117 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1118 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
|
1119 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
|
1120 for (octave_idx_type col = 0; col < nCols; col++) |
8054 | 1121 { |
17332
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 row = 0; row < nRows; row++) |
8054 | 1123 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1124 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
|
1125 pix[GM_idx] = white; |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1126 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1127 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
|
1128 GM_idx += nCols; |
8054 | 1129 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1130 GM_idx -= nCols * nRows - 1; |
8054 | 1131 } |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1132 // 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
|
1133 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
|
1134 // 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
|
1135 // 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
|
1136 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
|
1137 imvec.push_back (m_img); |
8054 | 1138 } |
1139 } | |
1140 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
1141 template <typename T> |
8054 | 1142 static void |
1143 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
|
1144 const T& img, const T& alpha) |
8054 | 1145 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1146 typedef typename T::element_type P; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
1147 const octave_idx_type channels = (img.ndims () < 3 ? 1 : img.dims ()(2)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
1148 const octave_idx_type nFrames = (img.ndims () < 4 ? 1 : img.dims ()(3)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1149 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
|
1150 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
|
1151 const octave_idx_type bitdepth = bitdepth_from_class<T> (); |
8054 | 1152 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1153 Magick::ImageType type; |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
1154 const bool has_alpha = ! alpha.isempty (); |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1155 switch (channels) |
8054 | 1156 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1157 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
|
1158 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
|
1159 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
|
1160 else |
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 = 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
|
1162 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1163 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1168 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
|
1169 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1170 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1171 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
|
1172 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
|
1173 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
|
1174 else |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1175 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
|
1176 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1177 |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1178 default: |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1179 // __imwrite should have already filtered this cases |
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1180 error ("__magick_write__: wrong size on 3rd dimension"); |
8054 | 1181 } |
1182 | |
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 // We will be passing the values as integers with depth as specified |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1184 // by QuantumDepth (maximum value specified by MaxRGB). This is independent |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1185 // of the actual depth of the image. GM will then convert the values but |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1186 // 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
|
1187 // 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
|
1188 // 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
|
1189 // the range of MaxRGB |
25688
b2917b7858ba
maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1190 const double divisor = static_cast<double> ((uint64_t (1) << bitdepth) - 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1191 / MaxRGB; |
8054 | 1192 |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1193 const P *img_fvec = img.data (); |
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1194 const P *a_fvec = alpha.data (); |
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 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
|
1196 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1197 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
|
1198 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1199 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
|
1200 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1201 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1202 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1203 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
|
1204 type, |
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::DirectClass); |
8054 | 1206 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1207 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
|
1208 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
|
1209 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
|
1210 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1211 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
|
1212 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1213 const double grey = math::round (double (*img_fvec) / divisor); |
19694
c334e4af3a1b
Fix incorrect writing of grayscale JPEG images (bugs #41673, #44118, #42474)
Ilya Kurdyukov <olme8@mail.ru>
parents:
18955
diff
changeset
|
1214 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
|
1215 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
|
1216 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
|
1217 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
|
1218 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1219 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
|
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 // 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
|
1222 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
|
1223 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
|
1224 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1225 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1226 } |
8054 | 1227 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1228 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
|
1229 { |
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 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1232 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1233 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1234 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
|
1235 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1236 Magick::DirectClass); |
7974 | 1237 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1238 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
|
1239 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
|
1240 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
|
1241 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1242 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
|
1243 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1244 double grey = math::round (double (*img_fvec) / divisor); |
18544
e0cc67d5a462
Fix writing of grayscale images when there is an alpha channel.
Carnë Draug <carandraug@octave.org>
parents:
18542
diff
changeset
|
1245 Magick::Color c (grey, grey, grey, |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1246 MaxRGB - math::round (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
|
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 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
|
1250 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
|
1251 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1252 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
|
1253 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1254 // 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
|
1255 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
|
1256 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
|
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::TrueColorType: |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1262 { |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1263 // The data offset for the green and blue channels |
17332
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 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
|
1265 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
|
1266 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
|
1267 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1268 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1269 |
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); |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
1275 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
|
1276 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
|
1277 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1278 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
|
1279 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1280 Magick::Color c (math::round (double (*img_fvec) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1281 math::round (double (img_fvec[G_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1282 math::round (double (img_fvec[B_offset]) / 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
|
1283 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
|
1284 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
|
1285 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
|
1286 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1287 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
|
1288 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1289 // 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
|
1290 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
|
1291 imvec.push_back (m_img); |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
1292 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
|
1293 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1294 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1295 } |
8054 | 1296 |
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 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
|
1298 { |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1299 // The data offset for the green and blue channels |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1300 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
|
1301 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
|
1302 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
|
1303 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1304 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1305 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1306 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
|
1307 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1308 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1309 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1310 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
|
1311 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
|
1312 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
|
1313 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1314 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
|
1315 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1316 Magick::Color c (math::round (double (*img_fvec) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1317 math::round (double (img_fvec[G_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1318 math::round (double (img_fvec[B_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1319 MaxRGB - math::round (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
|
1320 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
|
1321 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
|
1322 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
|
1323 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
|
1324 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1325 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
|
1326 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1327 // 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
|
1328 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
|
1329 imvec.push_back (m_img); |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
1330 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
|
1331 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1332 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1333 } |
8054 | 1334 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1335 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
|
1336 { |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1337 // The data offset for the Magenta, Yellow, and blacK channels |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1338 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
|
1339 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
|
1340 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
|
1341 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
|
1342 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1343 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1344 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1345 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
|
1346 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1347 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1348 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1349 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
|
1350 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
|
1351 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
|
1352 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1353 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
|
1354 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1355 Magick::Color c (math::round (double (*img_fvec) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1356 math::round (double (img_fvec[M_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1357 math::round (double (img_fvec[Y_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1358 math::round (double (img_fvec[K_offset]) / 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
|
1359 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
|
1360 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
|
1361 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
|
1362 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1363 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
|
1364 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1365 // 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
|
1366 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
|
1367 imvec.push_back (m_img); |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
1368 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
|
1369 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1370 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1371 } |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1372 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1373 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
|
1374 { |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1375 // The data offset for the Magenta, Yellow, and blacK channels |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1376 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
|
1377 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
|
1378 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
|
1379 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
|
1380 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1381 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1382 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1383 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
|
1384 type, |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1385 Magick::DirectClass); |
10979
7f49dc864f32
__magick_read__.cc: style fixes
John W. Eaton <jwe@octave.org>
parents:
10978
diff
changeset
|
1386 |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1387 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
|
1388 Magick::IndexPacket *ind = m_img.getIndexes (); |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
1389 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
|
1390 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
|
1391 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1392 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
|
1393 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1394 Magick::Color c (math::round (double (*img_fvec) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1395 math::round (double (img_fvec[M_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1396 math::round (double (img_fvec[Y_offset]) / divisor), |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1397 math::round (double (img_fvec[K_offset]) / 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
|
1398 pix[GM_idx] = c; |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1399 ind[GM_idx] = MaxRGB - math::round (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
|
1400 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
|
1401 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
|
1402 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
|
1403 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1404 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
|
1405 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1406 // 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
|
1407 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
|
1408 imvec.push_back (m_img); |
18542
30aa4e85f8d5
Fix writing and reading of multipage images.
Carnë Draug <carandraug@octave.org>
parents:
18149
diff
changeset
|
1409 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
|
1410 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1411 break; |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1412 } |
11034
6589aaf769f6
Correctly handle logical and integer bit depths
John Swensen <jpswensen@gmail.com>
parents:
10988
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 default: |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1415 error ("__magick_write__: unrecognized Magick::ImageType"); |
8054 | 1416 } |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1417 |
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 return; |
8054 | 1419 } |
1420 | |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1421 // Meant to be shared with both imfinfo and imwrite. |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1422 static std::map<octave_idx_type, std::string> |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1423 init_disposal_methods () |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1424 { |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1425 // GIF Specifications: |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1426 // |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1427 // 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
|
1428 // be treated after being displayed. |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1429 // |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1430 // 0 - No disposal specified. The decoder is |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1431 // not required to take any action. |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1432 // 1 - Do not dispose. The graphic is to be left |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1433 // in place. |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1434 // 2 - Restore to background color. The area used by the |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1435 // graphic must be restored to the background color. |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1436 // 3 - Restore to previous. The decoder is required to |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1437 // restore the area overwritten by the graphic with |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1438 // what was there prior to rendering the graphic. |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1439 // 4-7 - To be defined. |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1440 static std::map<octave_idx_type, std::string> methods; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1441 if (methods.empty ()) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1442 { |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1443 methods[0] = "doNotSpecify"; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1444 methods[1] = "leaveInPlace"; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1445 methods[2] = "restoreBG"; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1446 methods[3] = "restorePrevious"; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1447 } |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1448 return methods; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1449 } |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1450 static std::map<std::string, octave_idx_type> |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1451 init_reverse_disposal_methods () |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1452 { |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1453 static std::map<std::string, octave_idx_type> methods; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1454 if (methods.empty ()) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1455 { |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1456 methods["donotspecify"] = 0; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1457 methods["leaveinplace"] = 1; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1458 methods["restorebg"] = 2; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1459 methods["restoreprevious"] = 3; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1460 } |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1461 return methods; |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1462 } |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1463 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1464 void static |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1465 write_file (const std::string& filename, |
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1466 const std::string& ext, |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1467 std::vector<Magick::Image>& imvec) |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1468 { |
7974 | 1469 try |
1470 { | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1471 Magick::writeImages (imvec.begin (), imvec.end (), ext + ':' + filename); |
7974 | 1472 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
1473 catch (const Magick::Warning& w) |
7974 | 1474 { |
1475 warning ("Magick++ warning: %s", w.what ()); | |
1476 } | |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
1477 catch (const Magick::ErrorCoder& e) |
7974 | 1478 { |
1479 warning ("Magick++ coder error: %s", e.what ()); | |
1480 } | |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
1481 catch (const Magick::Exception& e) |
7974 | 1482 { |
1483 error ("Magick++ exception: %s", e.what ()); | |
1484 } | |
1485 } | |
1486 | |
1487 #endif | |
1488 | |
21679
44f7664689f2
make __magick_read__ a built-in function (bug #41699)
John W. Eaton <jwe@octave.org>
parents:
21142
diff
changeset
|
1489 DEFUN (__magick_write__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1490 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1491 @deftypefn {} {} __magick_write__ (@var{fname}, @var{fmt}, @var{img}, @var{map}, @var{options}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1492 Write image with GraphicsMagick or ImageMagick. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1493 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1494 This is a private internal function not intended for direct use. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1495 Use @code{imwrite} instead. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1496 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1497 @seealso{imfinfo, imformats, imread, imwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1498 @end deftypefn */) |
7974 | 1499 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1500 #if defined (HAVE_MAGICK) |
7974 | 1501 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1502 if (args.length () != 5 || ! args(0).is_string () || ! args(1).is_string ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1503 print_usage (); |
16983
4660d047955e
Make use of gripe_disabled_feature() for image IO functions.
Carnë Draug <carandraug+dev@gmail.com>
parents:
16944
diff
changeset
|
1504 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1505 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1506 |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1507 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
|
1508 const std::string ext = args(1).string_value (); |
7974 | 1509 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1510 const octave_scalar_map options |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1511 = args(4).xscalar_map_value ("__magick_write__: OPTIONS must be a struct"); |
7974 | 1512 |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21489
diff
changeset
|
1513 const octave_value img = args(2); |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20703
diff
changeset
|
1514 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
|
1515 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1516 std::vector<Magick::Image> imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1517 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
1518 if (cmap.isempty ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1519 { |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1520 const octave_value alpha = options.getfield ("alpha"); |
23579
c20a0fa91c0c
maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1521 if (img.islogical ()) |
17332
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1522 encode_bool_image (imvec, img.bool_array_value ()); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1523 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
|
1524 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
|
1525 alpha.uint8_array_value ()); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1526 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
|
1527 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
|
1528 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
|
1529 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
|
1530 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
|
1531 alpha.uint32_array_value ()); |
23585
570170b6eb09
maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
1532 else if (img.isfloat ()) |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1533 { |
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1534 // For image formats that support floating point values, we write |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1535 // the actual values. For those who don't, we only use the values |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1536 // 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
|
1537 // 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
|
1538 // 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
|
1539 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
|
1540 uint32NDArray clip_alpha; |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1541 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
|
1542 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1543 clip_img = img_float2uint<FloatNDArray> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1544 (img.float_array_value ()); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1545 clip_alpha = img_float2uint<FloatNDArray> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1546 (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
|
1547 } |
17228
2f1729cae08f
Initial support for writing of floating point and uint32 images.
Carnë Draug <carandraug@octave.org>
parents:
17226
diff
changeset
|
1548 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
|
1549 { |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1550 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
|
1551 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
|
1552 } |
eb7e9a991ffb
Implement writing of CMYK and fix writing of image alpha channel (bug #32986).
Carnë Draug <carandraug@octave.org>
parents:
17240
diff
changeset
|
1553 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
|
1554 } |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1555 else |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1556 error ("__magick_write__: image type not supported"); |
7974 | 1557 } |
1558 else | |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1559 { |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1560 // We should not get floating point indexed images here because we |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1561 // converted them in __imwrite__.m. We should probably do it here |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1562 // but it would look much messier. |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1563 if (img.is_uint8_type ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1564 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
|
1565 cmap); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1566 else if (img.is_uint16_type ()) |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1567 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
|
1568 cmap); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1569 else |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28638
diff
changeset
|
1570 error ("__magick_write__: indexed image must be uint8, uint16 or float"); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1571 } |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1572 static std::map<std::string, octave_idx_type> disposal_methods |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1573 = init_reverse_disposal_methods (); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1574 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1575 const octave_idx_type nFrames = imvec.size (); |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1576 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1577 const octave_idx_type quality = options.getfield ("quality").int_value (); |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
1578 const ColumnVector delaytime |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
1579 = options.getfield ("delaytime").column_vector_value (); |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
1580 const Array<std::string> disposalmethod |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
1581 = options.getfield ("disposalmethod").cellstr_value (); |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1582 for (octave_idx_type i = 0; i < nFrames; i++) |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1583 { |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1584 imvec[i].quality (quality); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1585 imvec[i].animationDelay (delaytime(i)); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1586 imvec[i].gifDisposeMethod (disposal_methods[disposalmethod(i)]); |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1587 } |
17854
adb0ba0d0c13
imwrite: implement DelayTime option.
Carnë Draug <carandraug@octave.org>
parents:
17853
diff
changeset
|
1588 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1589 // If writemode is set to append, read the image and append to it. Even |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1590 // 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
|
1591 const std::string writemode = options.getfield ("writemode").string_value (); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1592 if (writemode == "append" && sys::file_stat (filename).exists ()) |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1593 { |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1594 std::vector<Magick::Image> ini_imvec; |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1595 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
|
1596 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1597 if (ini_imvec.size () > 0) |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1598 { |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1599 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
|
1600 ini_imvec.swap (imvec); |
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1601 } |
16988
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1602 } |
54b75bed4bc7
imwrite: implement WriteMode option.
Carnë Draug <carandraug@octave.org>
parents:
16984
diff
changeset
|
1603 |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17855
diff
changeset
|
1604 // FIXME: LoopCount or animationIterations |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1605 // How it should work: |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1606 // |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1607 // This value is only set for the first image in the sequence. Trying |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1608 // 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
|
1609 // value used with the first image is the one that counts (that would |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1610 // also be Matlab compatible). Thus, the right way to do this would be |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1611 // to have an else block on the condition above, and set this only |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1612 // when creating a new file. Since Matlab does not interpret a 4D |
17855
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1613 // 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
|
1614 // 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
|
1615 // throws warnings otherwise) |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1616 // |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1617 // Why is this not done the right way: |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1618 // |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1619 // 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
|
1620 // 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
|
1621 // 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
|
1622 // 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
|
1623 // See https://sourceforge.net/p/graphicsmagick/bugs/248/ |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1624 // 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
|
1625 // (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
|
1626 // all frames (won't work in Matlab at all). |
bfbe5dcc9943
imwrite: implement DisposalMethod option.
Carnë Draug <carandraug@octave.org>
parents:
17854
diff
changeset
|
1627 // 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
|
1628 imvec[0].animationIterations (options.getfield ("loopcount").uint_value ()); |
17853
aacb9da13df6
imwrite: implement LoopCount option.
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1629 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1630 const std::string compression |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1631 = options.getfield ("compression").string_value (); |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1632 |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1633 #define COMPRESS_MAGICK_IMAGE_VECTOR(GM_TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1634 for (std::vector<Magick::Image>::size_type i = 0; i < imvec.size (); i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1635 imvec[i].compressType (GM_TYPE) |
20406
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
20338
diff
changeset
|
1636 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1637 if (compression == "none") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1638 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::NoCompression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1639 else if (compression == "bzip") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1640 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::BZipCompression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1641 else if (compression == "fax3") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1642 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::FaxCompression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1643 else if (compression == "fax4") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1644 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::Group4Compression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1645 else if (compression == "jpeg") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1646 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::JPEGCompression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1647 else if (compression == "lzw") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1648 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::LZWCompression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1649 else if (compression == "rle") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1650 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::RLECompression); |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1651 else if (compression == "deflate") |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
1652 COMPRESS_MAGICK_IMAGE_VECTOR (Magick::ZipCompression); |
20406
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
20338
diff
changeset
|
1653 |
5b8e4f668c53
Add compression option to imwrite and default to "none" (bug #45565)
Carnë Draug <carandraug@octave.org>
parents:
20338
diff
changeset
|
1654 #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
|
1655 |
17226
46805642048f
Implement writing of indexed images.
Carnë Draug <carandraug@octave.org>
parents:
17149
diff
changeset
|
1656 write_file (filename, ext, imvec); |
7974 | 1657 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
1658 return ovl (); |
7974 | 1659 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1660 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1661 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1662 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1663 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21033
diff
changeset
|
1664 err_disabled_feature ("imwrite", "Image IO"); |
7974 | 1665 |
1666 #endif | |
1667 } | |
1668 | |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1669 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1670 ## 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
|
1671 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1672 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1673 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1674 // Gets the minimum information from images such as its size and format. Much |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1675 // faster than using imfinfo, which slows down a lot since. Note than without |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1676 // 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
|
1677 // done in Octave language), and then again for the actual reading. |
21679
44f7664689f2
make __magick_read__ a built-in function (bug #41699)
John W. Eaton <jwe@octave.org>
parents:
21142
diff
changeset
|
1678 DEFUN (__magick_ping__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1679 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
1680 @deftypefn {} {@var{fmt} =} __magick_ping__ (@var{fname}, @var{idx}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1681 Ping image information with GraphicsMagick or ImageMagick. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1682 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1683 This is a private internal function not intended for direct use. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1684 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1685 @seealso{imfinfo} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1686 @end deftypefn */) |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1687 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1688 #if defined (HAVE_MAGICK) |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1689 |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1690 if (args.length () < 1 || ! args(0).is_string ()) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20729
diff
changeset
|
1691 print_usage (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20729
diff
changeset
|
1692 |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1693 maybe_initialize_magick (); |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1694 |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1695 const std::string filename = args(0).string_value (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1696 |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1697 int idx; |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1698 if (args.length () > 1) |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1699 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
|
1700 else |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1701 idx = 0; |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1702 |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1703 Magick::Image img; |
17705
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1704 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
|
1705 img.subRange (1); // ping only one of them |
28473
04ee5e8694cb
__magick_read__.cc: Correctly read images from non-ASCII paths on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
1706 |
28535
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
1707 // FIXME: We need this on Windows because GraphicsMagick uses the ANSI API |
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
1708 // to open files on disc. In contrast, the API of ImageMagick uses UTF-8 |
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
1709 // encoded strings. Should we somehow detect which is used on runtime and |
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
1710 // pass the file names accordingly? (See also bug #58493.) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1711 std::string ascii_fname = sys::get_ASCII_filename (filename, true); |
28473
04ee5e8694cb
__magick_read__.cc: Correctly read images from non-ASCII paths on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
1712 |
17705
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1713 try |
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1714 { |
28535
09b60b423e6f
Re-do fix for reading images with non-ASCII filenames on Windows (bug #58493).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28473
diff
changeset
|
1715 img.ping (ascii_fname); |
17705
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1716 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
1717 catch (const Magick::Warning& w) |
17705
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1718 { |
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1719 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
|
1720 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
1721 catch (const Magick::Exception& e) |
17705
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1722 { |
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1723 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
|
1724 } |
292319fb7fcc
Catch Magick++ errors and warnings when pinging image (bug #40267)
Carnë Draug <carandraug@octave.org>
parents:
17561
diff
changeset
|
1725 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
1726 static const char *fields[] = {"rows", "columns", "format", nullptr}; |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1727 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
|
1728 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
|
1729 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
|
1730 ping.setfield ("format", octave_value (img.magick ())); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1731 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1732 return ovl (ping); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1733 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
1734 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1735 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1736 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1737 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21033
diff
changeset
|
1738 err_disabled_feature ("imfinfo", "Image IO"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1739 |
17351
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1740 #endif |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1741 } |
80bf005cdf8e
New function __magick_ping__ to speed reading of images.
Carnë Draug <carandraug@octave.org>
parents:
17350
diff
changeset
|
1742 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1743 #if defined (HAVE_MAGICK) |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
1744 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1745 static octave_value |
17350 | 1746 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
|
1747 { |
17350 | 1748 switch (magick) |
1749 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1750 case Magick::NoCompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1751 return octave_value ("none"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1752 case Magick::BZipCompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1753 return octave_value ("bzip"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1754 case Magick::FaxCompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1755 return octave_value ("fax3"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1756 case Magick::Group4Compression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1757 return octave_value ("fax4"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1758 case Magick::JPEGCompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1759 return octave_value ("jpeg"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1760 case Magick::LZWCompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1761 return octave_value ("lzw"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1762 case Magick::RLECompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1763 // 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
|
1764 // "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
|
1765 return octave_value ("rle"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1766 case Magick::ZipCompression: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1767 return octave_value ("deflate"); |
17362
6e1a3b8fc312
__magick_finfo__: remove recent Magick compression types (bug #39913)
Carnë Draug <carandraug@octave.org>
parents:
17359
diff
changeset
|
1768 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1769 // The following are present only in recent versions of GraphicsMagick. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1770 // At the moment the only use of this would be to have imfinfo report |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1771 // the compression method. In the future, someone could implement |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1772 // the Compression option for imwrite in which case a macro in |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1773 // configure.ac will have to check for their presence of this. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1774 // See bug #39913 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1775 // case Magick::LZMACompression: |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1776 // return octave_value ("lzma"); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1777 // case Magick::JPEG2000Compression: |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1778 // return octave_value ("jpeg2000"); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1779 // case Magick::JBIG1Compression: |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1780 // return octave_value ("jbig1"); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1781 // case Magick::JBIG2Compression: |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1782 // return octave_value ("jbig2"); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1783 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1784 default: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1785 return octave_value ("undefined"); |
17350 | 1786 } |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1787 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1788 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1789 static octave_value |
17350 | 1790 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
|
1791 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1792 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1793 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1794 case Magick::LSBEndian: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1795 return octave_value ("little-endian"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1796 case Magick::MSBEndian: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1797 return octave_value ("big-endian"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1798 default: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1799 return octave_value ("undefined"); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1800 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1801 } |
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 static octave_value |
17350 | 1804 magick_to_octave_value (const Magick::OrientationType& magick) |
1805 { | |
1806 switch (magick) | |
1807 { | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1808 // 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
|
1809 case Magick::TopLeftOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1810 return octave_value (1); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1811 case Magick::TopRightOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1812 return octave_value (2); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1813 case Magick::BottomRightOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1814 return octave_value (3); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1815 case Magick::BottomLeftOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1816 return octave_value (4); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1817 case Magick::LeftTopOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1818 return octave_value (5); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1819 case Magick::RightTopOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1820 return octave_value (6); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1821 case Magick::RightBottomOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1822 return octave_value (7); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1823 case Magick::LeftBottomOrientation: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1824 return octave_value (8); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1825 default: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1826 return octave_value (1); |
17350 | 1827 } |
1828 } | |
1829 | |
1830 static octave_value | |
1831 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
|
1832 { |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1833 switch (magick) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1834 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1835 case Magick::PixelsPerInchResolution: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1836 return octave_value ("Inch"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1837 case Magick::PixelsPerCentimeterResolution: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1838 return octave_value ("Centimeter"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1839 default: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1840 return octave_value ("undefined"); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1841 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1842 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1843 |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1844 static bool |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1845 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
|
1846 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1847 // 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
|
1848 // for an empty value. |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1849 return (! val.empty () && val != "unknown"); |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1850 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1851 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1852 static void |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1853 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
|
1854 const std::string& key) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1855 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1856 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
|
1857 if (is_valid_exif (attr)) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1858 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
|
1859 return; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1860 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1861 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1862 static void |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1863 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
|
1864 const std::string& key) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1865 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1866 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
|
1867 if (is_valid_exif (attr)) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1868 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1869 // 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
|
1870 float number; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1871 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
|
1872 std::string sub; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1873 std::istringstream sstream (attr); |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1874 octave_idx_type n = 0; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1875 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
|
1876 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1877 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
|
1878 values(n++) = number; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1879 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1880 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
|
1881 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1882 return; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1883 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1884 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1885 static void |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1886 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
|
1887 const std::string& key) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1888 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1889 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
|
1890 if (is_valid_exif (attr)) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1891 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1892 // 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
|
1893 int numerator; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1894 int denominator; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1895 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
|
1896 std::string sub; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1897 std::istringstream sstream (attr); |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1898 octave_idx_type n = 0; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1899 while (std::getline (sstream, sub, ',')) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1900 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1901 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
|
1902 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
|
1903 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1904 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
|
1905 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1906 return; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1907 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1908 |
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
|
1909 #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
|
1910 |
21679
44f7664689f2
make __magick_read__ a built-in function (bug #41699)
John W. Eaton <jwe@octave.org>
parents:
21142
diff
changeset
|
1911 DEFUN (__magick_finfo__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1912 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
1913 @deftypefn {} {@var{infostruct} =} __magick_finfo__ (@var{fname}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1914 Read image information with GraphicsMagick or ImageMagick. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1915 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1916 This is a private internal function not intended for direct use. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1917 Use @code{imfinfo} instead. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1918 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1919 @seealso{imfinfo, imformats, imread, imwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1920 @end deftypefn */) |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1921 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1922 #if defined (HAVE_MAGICK) |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1923 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1924 if (args.length () < 1 || ! args(0).is_string ()) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20729
diff
changeset
|
1925 print_usage (); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
1926 |
10947
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1927 maybe_initialize_magick (); |
dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
1928 |
17235
96a1c132e3c6
__magick_read__.cc: follow coding guidelines.
Carnë Draug <carandraug@octave.org>
parents:
17228
diff
changeset
|
1929 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
|
1930 |
17350 | 1931 std::vector<Magick::Image> imvec; |
1932 read_file (filename, imvec); | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1933 |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1934 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
|
1935 const std::string format = imvec[0].magick (); |
17350 | 1936 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1937 // Here's how this function works. We need to return a struct array, one |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1938 // struct for each image in the file (remember, there are image |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1939 // that allow for multiple images in the same file). Now, Matlab seems |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1940 // to have format specific code so the fields on the struct are different |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1941 // for each format. It only has a small subset that is common to all |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1942 // of them, the others are undocumented. Because we try to abstract from |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1943 // the formats we always return the same list of fields (note that with |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1944 // GM we support more than 88 formats. That's way more than Matlab, and |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1945 // 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
|
1946 // |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
1947 // 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
|
1948 // 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
|
1949 // 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
|
1950 // 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
|
1951 // 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
|
1952 // 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
|
1953 // 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
|
1954 |
17350 | 1955 static const char *fields[] = |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1956 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1957 // 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
|
1958 "Filename", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1959 "FileModDate", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1960 "FileSize", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1961 "Format", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1962 "FormatVersion", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1963 "Width", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1964 "Height", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1965 "BitDepth", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1966 "ColorType", |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
1967 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1968 // These are format specific or not existent in Matlab. The most |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1969 // 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
|
1970 // same thing in different formats. |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1971 "DelayTime", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1972 "DisposalMethod", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1973 "LoopCount", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1974 "ByteOrder", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1975 "Gamma", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1976 "Chromaticities", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1977 "Comment", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1978 "Quality", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1979 "Compression", // same as CompressionType |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1980 "Colormap", // same as ColorTable (in PNG) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1981 "Orientation", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1982 "ResolutionUnit", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1983 "XResolution", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1984 "YResolution", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1985 "Software", // sometimes is an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1986 "Make", // actually an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1987 "Model", // actually an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1988 "DateTime", // actually an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1989 "ImageDescription", // actually an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1990 "Artist", // actually an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1991 "Copyright", // actually an Exif tag |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1992 "DigitalCamera", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1993 "GPSInfo", |
20097
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
19885
diff
changeset
|
1994 // 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
|
1995 // attribute() to obtain arbitrary ones, that may exist in only some |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
1996 // cases. The following is a list of some methods and into what possible |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1997 // 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
|
1998 // |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1999 // colorSpace() -> PhotometricInterpretation |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2000 // backgroundColor() -> BackgroundColor |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2001 // interlaceType() -> Interlaced, InterlaceType, and PlanarConfiguration |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2002 // label() -> Title |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2003 nullptr |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2004 }; |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10298
diff
changeset
|
2005 |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2006 // The one we will return at the end |
17350 | 2007 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
|
2008 |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2009 // Some of the fields in the struct are about file information and will be |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2010 // the same for all images in the file. So we create a template, fill in |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2011 // those values, and make a copy of the template for each image. |
17350 | 2012 octave_scalar_map template_info = (string_vector (fields)); |
2013 | |
2014 template_info.setfield ("Format", octave_value (format)); | |
2015 // We can't actually get FormatVersion but even Matlab sometimes can't. | |
2016 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
|
2017 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2018 const sys::file_stat fs (filename); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2019 if (! fs) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
2020 error ("imfinfo: error reading '%s': %s", filename.c_str (), |
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
2021 fs.error ().c_str ()); |
17350 | 2022 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2023 const sys::localtime mtime (fs.mtime ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2024 const std::string filetime = mtime.strftime ("%e-%b-%Y %H:%M:%S"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2025 template_info.setfield ("Filename", octave_value (filename)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2026 template_info.setfield ("FileModDate", octave_value (filetime)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2027 template_info.setfield ("FileSize", octave_value (fs.size ())); |
17350 | 2028 |
2029 for (octave_idx_type frame = 0; frame < nFrames; frame++) | |
2030 { | |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
2031 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
2032 |
17350 | 2033 octave_scalar_map info_frame (template_info); |
2034 const Magick::Image img = imvec[frame]; | |
2035 | |
2036 info_frame.setfield ("Width", octave_value (img.columns ())); | |
2037 info_frame.setfield ("Height", octave_value (img.rows ())); | |
2038 info_frame.setfield ("BitDepth", | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2039 octave_value (get_depth (const_cast<Magick::Image&> (img)))); |
17350 | 2040 |
2041 // Stuff related to colormap, image class and type | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2042 // Because GM is too smart for us... Read the comments in is_indexed() |
17350 | 2043 { |
2044 std::string color_type; | |
2045 Matrix cmap; | |
2046 if (is_indexed (img)) | |
2047 { | |
2048 color_type = "indexed"; | |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26488
diff
changeset
|
2049 cmap = read_maps (const_cast<Magick::Image&> (img))(0).matrix_value (); |
17350 | 2050 } |
2051 else | |
2052 { | |
2053 switch (img.type ()) | |
2054 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2055 case Magick::BilevelType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2056 case Magick::GrayscaleType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2057 case Magick::GrayscaleMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2058 color_type = "grayscale"; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2059 break; |
17350 | 2060 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2061 case Magick::TrueColorType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2062 case Magick::TrueColorMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2063 color_type = "truecolor"; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2064 break; |
17350 | 2065 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2066 case Magick::PaletteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2067 case Magick::PaletteMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2068 // 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
|
2069 color_type = "indexed"; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2070 break; |
17350 | 2071 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2072 case Magick::ColorSeparationType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2073 case Magick::ColorSeparationMatteType: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2074 color_type = "CMYK"; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2075 break; |
17350 | 2076 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2077 default: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2078 color_type = "undefined"; |
17350 | 2079 } |
2080 } | |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2081 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
|
2082 info_frame.setfield ("Colormap", octave_value (cmap)); |
17350 | 2083 } |
2084 | |
2085 { | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2086 // Not all images have chroma values. In such cases, they'll |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2087 // be all zeros. So rather than send a matrix of zeros, we will |
17350 | 2088 // check for that, and send an empty vector instead. |
2089 RowVector chromaticities (8); | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23416
diff
changeset
|
2090 double *chroma_fvec = chromaticities.fortran_vec (); |
17350 | 2091 img.chromaWhitePoint (&chroma_fvec[0], &chroma_fvec[1]); |
2092 img.chromaRedPrimary (&chroma_fvec[2], &chroma_fvec[3]); | |
2093 img.chromaGreenPrimary (&chroma_fvec[4], &chroma_fvec[5]); | |
2094 img.chromaBluePrimary (&chroma_fvec[6], &chroma_fvec[7]); | |
2095 if (chromaticities.nnz () == 0) | |
2096 chromaticities = RowVector (0); | |
2097 info_frame.setfield ("Chromaticities", octave_value (chromaticities)); | |
2098 } | |
2099 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2100 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
|
2101 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
|
2102 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
|
2103 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
|
2104 info_frame.setfield ("LoopCount", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2105 octave_value (img.animationIterations ())); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2106 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
|
2107 info_frame.setfield ("Comment", octave_value (img.comment ())); |
17350 | 2108 |
2109 info_frame.setfield ("Compression", | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2110 magick_to_octave_value (img.compressType ())); |
17350 | 2111 info_frame.setfield ("Orientation", |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2112 magick_to_octave_value (img.orientation ())); |
17350 | 2113 info_frame.setfield ("ResolutionUnit", |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2114 magick_to_octave_value (img.resolutionUnits ())); |
17350 | 2115 info_frame.setfield ("ByteOrder", |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2116 magick_to_octave_value (img.endian ())); |
17350 | 2117 |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2118 // It is not possible to know if there's an Exif field so we just |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2119 // check for the Exif Version value. If it does exists, then we |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2120 // 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
|
2121 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2122 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
|
2123 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2124 // 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
|
2125 // 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
|
2126 // This is likely because they belong to the Baseline TIFF specs |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2127 // and may appear out of the Exif tag. So first we check if it |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2128 // exists outside the Exif tag. |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2129 // 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
|
2130 // (CIPA DC- 008-Translation- 2010) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2131 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
|
2132 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2133 "DateTime", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2134 "ImageDescription", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2135 "Make", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2136 "Model", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2137 "Software", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2138 "Artist", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2139 "Copyright", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2140 nullptr, |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2141 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2142 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
|
2143 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
|
2144 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
|
2145 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2146 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
|
2147 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
|
2148 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
|
2149 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2150 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2151 octave_scalar_map camera; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2152 octave_scalar_map gps; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2153 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
|
2154 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2155 // 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
|
2156 // 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
|
2157 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2158 // 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
|
2159 static const char *exif_str_fields[] = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2160 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2161 "RelatedSoundFile", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2162 "DateTimeOriginal", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2163 "DateTimeDigitized", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2164 "SubSecTime", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2165 "DateTimeOriginal", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2166 "SubSecTimeOriginal", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2167 "SubSecTimeDigitized", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2168 "ImageUniqueID", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2169 "CameraOwnerName", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2170 "BodySerialNumber", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2171 "LensMake", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2172 "LensModel", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2173 "LensSerialNumber", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2174 "SpectralSensitivity", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2175 // These last two are of type undefined but most likely will |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2176 // be strings. Even if they're not GM returns a string anyway. |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2177 "UserComment", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2178 "MakerComment", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2179 nullptr |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2180 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2181 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
|
2182 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
|
2183 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
|
2184 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
|
2185 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2186 // 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
|
2187 static const char *exif_int_fields[] = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2188 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2189 "ColorSpace", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2190 "ExifImageWidth", // PixelXDimension (CPixelXDimension in Matlab) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2191 "ExifImageHeight", // PixelYDimension (CPixelYDimension in Matlab) |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2192 "PhotographicSensitivity", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2193 "StandardOutputSensitivity", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2194 "RecommendedExposureIndex", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2195 "ISOSpeed", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2196 "ISOSpeedLatitudeyyy", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2197 "ISOSpeedLatitudezzz", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2198 "FocalPlaneResolutionUnit", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2199 "FocalLengthIn35mmFilm", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2200 // 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
|
2201 "SubjectArea", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2202 "SubjectLocation", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2203 // 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
|
2204 // 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
|
2205 // 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
|
2206 // "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
|
2207 "ExposureProgram", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2208 "SensitivityType", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2209 "MeteringMode", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2210 "LightSource", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2211 "Flash", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2212 "SensingMethod", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2213 "FileSource", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2214 "CustomRendered", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2215 "ExposureMode", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2216 "WhiteBalance", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2217 "SceneCaptureType", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2218 "GainControl", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2219 "Contrast", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2220 "Saturation", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2221 "Sharpness", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2222 "SubjectDistanceRange", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2223 nullptr |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2224 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2225 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
|
2226 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
|
2227 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
|
2228 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
|
2229 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2230 // Listed as RATIONAL or SRATIONAL |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2231 static const char *exif_float_fields[] = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2232 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2233 "Gamma", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2234 "CompressedBitsPerPixel", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2235 "ExposureTime", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2236 "FNumber", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2237 "ShutterSpeedValue", // SRATIONAL |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2238 "ApertureValue", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2239 "BrightnessValue", // SRATIONAL |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2240 "ExposureBiasValue", // SRATIONAL |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2241 "MaxApertureValue", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2242 "SubjectDistance", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2243 "FocalLength", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2244 "FlashEnergy", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2245 "FocalPlaneXResolution", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2246 "FocalPlaneYResolution", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2247 "ExposureIndex", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2248 "DigitalZoomRatio", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2249 // 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
|
2250 "LensSpecification", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2251 nullptr |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2252 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2253 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
|
2254 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
|
2255 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
|
2256 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
|
2257 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2258 // Inside a Exif field, it is possible that there is also a |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2259 // GPS field. This is not the same as ExifVersion but seems |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2260 // 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
|
2261 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
|
2262 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2263 // 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
|
2264 // 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
|
2265 // 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
|
2266 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2267 static const char *gps_str_fields[] = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2268 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2269 "GPSLatitudeRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2270 "GPSLongitudeRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2271 "GPSAltitudeRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2272 "GPSSatellites", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2273 "GPSStatus", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2274 "GPSMeasureMode", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2275 "GPSSpeedRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2276 "GPSTrackRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2277 "GPSImgDirectionRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2278 "GPSMapDatum", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2279 "GPSDestLatitudeRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2280 "GPSDestLongitudeRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2281 "GPSDestBearingRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2282 "GPSDestDistanceRef", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2283 "GPSDateStamp", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2284 nullptr |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2285 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2286 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
|
2287 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
|
2288 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
|
2289 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
|
2290 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2291 static const char *gps_int_fields[] = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2292 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2293 "GPSDifferential", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2294 nullptr |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2295 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2296 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
|
2297 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
|
2298 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
|
2299 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
|
2300 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2301 static const char *gps_float_fields[] = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2302 { |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2303 "GPSAltitude", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2304 "GPSDOP", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2305 "GPSSpeed", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2306 "GPSTrack", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2307 "GPSImgDirection", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2308 "GPSDestBearing", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2309 "GPSDestDistance", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2310 "GPSHPositioningError", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2311 // 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
|
2312 "GPSLatitude", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2313 "GPSLongitude", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2314 "GPSTimeStamp", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2315 "GPSDestLatitude", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2316 "GPSDestLongitude", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23585
diff
changeset
|
2317 nullptr |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2318 }; |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2319 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
|
2320 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
|
2321 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
|
2322 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
|
2323 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2324 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2325 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2326 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
|
2327 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
|
2328 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2329 |
17350 | 2330 info.fast_elem_insert (frame, info_frame); |
2331 } | |
17359
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2332 |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2333 if (format == "GIF") |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2334 { |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2335 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
|
2336 = init_disposal_methods (); |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2337 string_vector methods (nFrames); |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2338 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
|
2339 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
|
2340 info.setfield ("DisposalMethod", Cell (methods)); |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2341 } |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2342 else |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2343 info.setfield ("DisposalMethod", |
cf5d41cc3695
Expand imfinfo to read Exif tags and GPS information.
Carnë Draug <carandraug@octave.org>
parents:
17351
diff
changeset
|
2344 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
|
2345 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2346 return ovl (info); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2347 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2348 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2349 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2350 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2351 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21033
diff
changeset
|
2352 err_disabled_feature ("imfinfo", "Image IO"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2353 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
2354 #endif |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
2355 } |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
8090
diff
changeset
|
2356 |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
2357 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
2358 ## 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
|
2359 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
2360 */ |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
2361 |
21679
44f7664689f2
make __magick_read__ a built-in function (bug #41699)
John W. Eaton <jwe@octave.org>
parents:
21142
diff
changeset
|
2362 DEFUN (__magick_formats__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
2363 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
2364 @deftypefn {} {@var{fmt_struct} =} __magick_imformats__ (@var{formats}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
2365 Fill formats info with GraphicsMagick CoderInfo. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
2366 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
2367 @seealso{imfinfo, imformats, imread, imwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
2368 @end deftypefn */) |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2369 { |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23579
diff
changeset
|
2370 if (args.length () != 1 || ! args(0).isstruct ()) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20729
diff
changeset
|
2371 print_usage (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20729
diff
changeset
|
2372 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2373 octave_map formats = args(0).map_value (); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2374 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
2375 #if defined (HAVE_MAGICK) |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2376 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2377 maybe_initialize_magick (); |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
21358
diff
changeset
|
2378 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2379 for (octave_idx_type idx = 0; idx < formats.numel (); idx++) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2380 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2381 try |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2382 { |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2383 octave_scalar_map fmt = formats.checkelem (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2384 Magick::CoderInfo coder (fmt.getfield ("coder").string_value ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2385 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2386 fmt.setfield ("description", octave_value (coder.description ())); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2387 fmt.setfield ("multipage", coder.isMultiFrame () ? true : false); |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2388 // default for read and write is a function handle. If we can't |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2389 // read or write them, them set it to an empty value |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2390 if (! coder.isReadable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2391 fmt.setfield ("read", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2392 if (! coder.isWritable ()) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2393 fmt.setfield ("write", Matrix ()); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2394 formats.fast_elem_insert (idx, fmt); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2395 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2396 catch (const Magick::Exception&) |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2397 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21736
diff
changeset
|
2398 // Exception here are missing formats. So we remove the format |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2399 // from the structure and reduce idx. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2400 formats.delete_elements (idx); |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2401 idx--; |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2402 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2403 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2404 |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
21358
diff
changeset
|
2405 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2406 |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
21358
diff
changeset
|
2407 formats = octave_map (dim_vector (1, 0), formats.fieldnames ()); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21680
diff
changeset
|
2408 |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2409 #endif |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20869
diff
changeset
|
2410 |
21489
ea81c2fdd568
imformats: return empty instead of error if there's no support for image IO.
Carnë Draug <carandraug@octave.org>
parents:
21358
diff
changeset
|
2411 return ovl (formats); |
16901
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2412 } |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2413 |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2414 /* |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2415 ## No test needed for internal helper function. |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2416 %!assert (1) |
861516dcad19
New function imformats.
Carnë Draug <carandraug@octave.org>
parents:
16871
diff
changeset
|
2417 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29931
diff
changeset
|
2418 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
2419 OCTAVE_END_NAMESPACE(octave) |