annotate scripts/image/getframe.m @ 29358:0a5b15007766 stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 09:52:15 -0500
parents bd51beb6205e
children a87e5f9d5446
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 ## Copyright (C) 2017-2021 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26637
diff changeset
4 ##
27923
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/>.
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
7 ##
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23570
diff changeset
8 ## This file is part of Octave.
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23570
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24007
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24007
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
13 ## (at your option) any later version.
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
14 ##
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23570
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23570
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
18 ## GNU General Public License for more details.
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
19 ##
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23570
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24007
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
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 ########################################################################
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
25
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
26 ## -*- texinfo -*-
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
27 ## @deftypefn {} {@var{frame} =} getframe ()
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
28 ## @deftypefnx {} {@var{frame} =} getframe (@var{hax})
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
29 ## @deftypefnx {} {@var{frame} =} getframe (@var{hfig})
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
30 ## @deftypefnx {} {@var{frame} =} getframe (@dots{}, @var{rect})
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
31 ##
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
32 ## Capture a figure or axes as a movie frame structure.
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
33 ##
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
34 ## Without an argument, capture the current axes excluding ticklabels, title,
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
35 ## and x/y/zlabels. The returned structure @var{frame} has a field
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
36 ## @code{cdata}, which contains the actual image data in the form of an
23567
71bfd507663c doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents: 23566
diff changeset
37 ## @nospell{NxMx3} (RGB) uint8 matrix, and a field @code{colormap} which is
71bfd507663c doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents: 23566
diff changeset
38 ## provided for @sc{matlab} compatibility but is always empty.
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
39 ##
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
40 ## If the first argument @var{hax} is an axes handle, then capture this axes,
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
41 ## rather than the current axes returned by @code{gca}.
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
42 ##
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
43 ## If the first argument @var{hfig} is a figure handle then the entire
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
44 ## corresponding figure canvas is captured.
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
45 ##
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
46 ## Finally, if a second argument @var{rect} is provided it must be a
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
47 ## four-element vector ([left bottom width height]) defining the region inside
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
48 ## the figure to be captured. Regardless of the figure @qcode{"units"}
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
49 ## property, @var{rect} must be defined in @strong{pixels}.
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
50 ##
26212
2be1833a93a5 movie.m: New function (patch #9363)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25948
diff changeset
51 ## @seealso{im2frame, frame2im, movie}
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
52 ## @end deftypefn
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
53
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
54 function frame = getframe (h = [], rect = [])
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
55 hf = hax = [];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
56 if (isempty (h))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
57 hf = get (0, "currentfigure");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
58 if (isempty (hf))
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
59 error ("getframe: no figure to capture");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
60 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
61 hax = get (hf, "currentaxes");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
62 if (isempty (hax))
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
63 error ("getframe: no axes to capture");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
64 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
65 elseif (isfigure (h))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
66 hf = h;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
67 elseif (isaxes (h))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
68 hf = ancestor (h, "figure");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
69 hax = h;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
70 else
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
71 error ("getframe: H must be a figure or axes handle");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
72 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
73
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
74 if (strcmp (get (hf, "__graphics_toolkit__"), "gnuplot"))
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
75 error ("getframe: not implemented for gnuplot graphics toolkit");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
76 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
77
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
78 unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
79 htmp = hax;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
80 if (h == hf)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
81 htmp = hf;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
82 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
83 units = get (htmp, "units");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
84 set (htmp, "units", "pixels");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
85 pos = get (htmp, "position");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
86 if (h == hf)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
87 pos(1:2) = 1;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
88 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
89 unwind_protect_cleanup
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
90 set (htmp, "units", units)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
91 end_unwind_protect
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
92
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
93 if (! isempty (rect))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
94 xv = [pos(1); pos(1)+pos(3); pos(1)+pos(3); pos(1)];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
95 yv = [pos(2); pos(2); pos(2)+pos(4); pos(2)+pos(4)];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
96 x = [rect(1); rect(1)+rect(3); rect(1)+rect(3); rect(1)];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
97 y = [rect(2); rect(2); rect(2)+rect(4); rect(2)+rect(4)];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
98 in = inpolygon (x, y, xv, yv);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
99 if (! all (in))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
100 error ("getframe: RECT must define a region inside the figure");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
101 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
102 pos = rect;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
103 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
104
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24534
diff changeset
105 if (strcmp (get (hf, "visible"), "on")
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24534
diff changeset
106 || (strcmp (get (hf, "__graphics_toolkit__"), "qt")
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24534
diff changeset
107 && (strcmp (get (hf, "__gl_window__"), "on")
24837
ae6679369a80 Rely on QOffscreenSurface functionality rather than its presence (bug #53278)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24820
diff changeset
108 || __have_feature__ ("QT_OFFSCREEN"))))
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25920
diff changeset
109
25920
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
110 ## __get_frame__ requires that the figure "units" is "pixels"
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
111 unwind_protect
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
112 units = get (hf, "units");
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
113 set (hf, "units", "pixels");
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
114 cdata = __get_frame__ (hf);
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
115 unwind_protect_cleanup
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
116 set (hf, "units", units)
bb9fcc452580 Fix OpenGL errors when using getframe with non "pixels" figure units.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25589
diff changeset
117 end_unwind_protect
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25920
diff changeset
118
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
119 else
25589
c21edcb90cbf support for osmesa removed (bug #50479)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
120 error ("getframe: figure must be visible or qt toolkit must be used with __gl_window__ property 'on' or QT_OFFSCREEN feature available");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
121 endif
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
122
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
123 i1 = max (floor (pos(1)), 1);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
124 i2 = min (ceil (pos(1)+pos(3)-1), columns (cdata));
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
125 idxx = i1:i2;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
126 i1 = max (floor (pos(2)), 1);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
127 i2 = min (ceil (pos(2)+pos(4)-1), rows (cdata));
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
128 idxy = fliplr (rows (cdata) - (i1:i2) + 1);
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
129
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
130 frame = struct ("cdata", cdata(idxy,idxx,:), "colormap", []);
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
131
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
132 endfunction
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
133
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
134
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
135 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
136 %! clf;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
137 %! contourf (rand (5));
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
138 %! drawnow ();
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
139 %! frame = getframe ();
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
140 %! imshow (frame.cdata);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
141
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
142 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
143 %! clf reset;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
144 %! contourf (rand (5));
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
145 %! frame = getframe (gcf ());
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
146 %! imshow (frame.cdata);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
147 %! set (gca, "position", [0 0 1 1]);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
148
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
149 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
150 %! clf;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
151 %! hax1 = subplot (2,1,1);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
152 %! contourf (rand (5));
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
153 %! title ("Original");
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
154 %! frame = getframe (hax1);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
155 %! hax2 = subplot (2,1,2);
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
156 %! image (frame.cdata);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
157 %! title ("Frame");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
158
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
159 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
160 %! clf;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
161 %! hax1 = subplot (2,1,1);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
162 %! contourf (rand (5));
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
163 %! title ("Original");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
164 %!
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
165 %! ## Get the coordinates of the lower-left hand corner in pixels
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
166 %! set (hax1, "units", "pixels");
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
167 %! pos = get (hax1, "position");
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
168 %! set (hax1, "units", "normalized");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
169 %! rect = [pos(1:2) pos(3:4)/2];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
170 %!
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
171 %! frame = getframe (hax1, rect);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
172 %! hax2 = subplot (2,1,2);
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
173 %! image (frame.cdata);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
174 %! title ("Lower left hand corner");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
175
26637
e2e1aed33f7c getframe.m: run tests with "qt" toolkit only \(bug #55528\)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
176 %!testif HAVE_QT_OFFSCREEN; have_window_system () && strcmp ("qt", graphics_toolkit ())
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
177 %! hf = figure ("visible", "off");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
178 %! unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
179 %! pos = get (hf, "position");
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
180 %! assert (size (getframe (hf).cdata)(1:2), pos(4:-1:3));
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
181 %! unwind_protect_cleanup
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
182 %! close (hf);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
183 %! end_unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
184
26637
e2e1aed33f7c getframe.m: run tests with "qt" toolkit only \(bug #55528\)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
185 %!testif HAVE_QT_OFFSCREEN; have_window_system () && strcmp ("qt", graphics_toolkit ())
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
186 %! hf = figure ("visible", "off");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
187 %! unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
188 %! hax = axes ("visible", "off", "position", [0 0 1 1]);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
189 %! verts = [0 0; .5 0; 1 0; ...
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
190 %! 0 .5; .5 .5; 1 .5; ...
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
191 %! 0 1; .5 1; 1 1];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
192 %! faces = [1 2 5 4; 2 3 6 5; 4 5 8 7; 5 6 9 8];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
193 %! fvc = [1 0 0; 0 1 0; 0 0 1; 1 0 1];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
194 %! patch ("vertices", verts, "faces", faces, "facevertexcdata", fvc, ...
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
195 %! "facecolor", "flat");
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
196 %!
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
197 %! kk = 1;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
198 %! pos = get (hf, "position");
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
199 %!
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
200 %! for jj = [0.05 0.55]
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
201 %! for ii = [0.05 0.55]
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
202 %! rect = [ii jj .4 .4].*[pos(3:4) pos(3:4)];
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
203 %! frame = getframe (hax, rect).cdata;
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
204 %! assert (frame(:,:,1) == fvc(kk,1)*255);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
205 %! assert (frame(:,:,2) == fvc(kk,2)*255);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
206 %! assert (frame(:,:,3) == fvc(kk,3)*255);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
207 %! kk++;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
208 %! endfor
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
209 %! endfor
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
210 %! unwind_protect_cleanup
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
211 %! close (hf);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
212 %! end_unwind_protect