annotate scripts/image/getframe.m @ 31225:3eab70385569

sparse-xpow.cc: Use faster multiplication technique, this time for complex
author Arun Giridhar <arungiridhar@gmail.com>
date Sun, 11 Sep 2022 13:53:38 -0400
parents 796f54d4ddbf
children 597f3ee61a48
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30379
diff changeset
3 ## Copyright (C) 2017-2022 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 = [])
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30198
diff changeset
55
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
56 hf = hax = [];
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
57 if (isempty (h))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
58 hf = get (0, "currentfigure");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
59 if (isempty (hf))
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
60 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
61 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
62 hax = get (hf, "currentaxes");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
63 if (isempty (hax))
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
64 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
65 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
66 elseif (isfigure (h))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
67 hf = h;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
68 elseif (isaxes (h))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
69 hf = ancestor (h, "figure");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
70 hax = h;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
71 else
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
72 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
73 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
74
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
75 if (strcmp (get (hf, "__graphics_toolkit__"), "gnuplot"))
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
76 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
77 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
78
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
79 unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
80 htmp = hax;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
81 if (h == hf)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
82 htmp = hf;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
83 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
84 units = get (htmp, "units");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
85 set (htmp, "units", "pixels");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
86 pos = get (htmp, "position");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
87 if (h == hf)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
88 pos(1:2) = 1;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
89 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
90 unwind_protect_cleanup
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
91 set (htmp, "units", units)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
92 end_unwind_protect
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
93
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
94 if (! isempty (rect))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
95 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
96 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
97 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
98 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
99 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
100 if (! all (in))
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
101 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
102 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
103 pos = rect;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
104 endif
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
105
30198
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
106 __check_rendering_capability__ ("getframe", hf);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25920
diff changeset
107
30198
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
108 ## __get_frame__ requires that the figure "units" is "pixels"
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
109 unwind_protect
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
110 units = get (hf, "units");
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
111 set (hf, "units", "pixels");
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
112 cdata = __get_frame__ (hf);
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
113 unwind_protect_cleanup
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
114 set (hf, "units", units)
a87e5f9d5446 improve graphics toolkit rendering failure error message
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
115 end_unwind_protect
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
116
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
117 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
118 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
119 idxx = i1:i2;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
120 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
121 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
122 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
123
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
124 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
125
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
126 endfunction
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
127
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
128
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
129 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
130 %! clf;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
131 %! contourf (rand (5));
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
132 %! drawnow ();
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
133 %! frame = getframe ();
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
134 %! imshow (frame.cdata);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
135
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
136 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
137 %! clf reset;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
138 %! contourf (rand (5));
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
139 %! frame = getframe (gcf ());
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
140 %! imshow (frame.cdata);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
141 %! 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
142
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
143 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
144 %! clf;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
145 %! hax1 = subplot (2,1,1);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
146 %! contourf (rand (5));
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
147 %! title ("Original");
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
148 %! frame = getframe (hax1);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
149 %! hax2 = subplot (2,1,2);
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
150 %! image (frame.cdata);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
151 %! title ("Frame");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
152
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
153 %!demo
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
154 %! clf;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
155 %! hax1 = subplot (2,1,1);
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
156 %! contourf (rand (5));
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
157 %! title ("Original");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
158 %!
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
159 %! ## 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
160 %! set (hax1, "units", "pixels");
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
161 %! pos = get (hax1, "position");
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
162 %! set (hax1, "units", "normalized");
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
163 %! 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
164 %!
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
165 %! frame = getframe (hax1, rect);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
166 %! hax2 = subplot (2,1,2);
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
167 %! image (frame.cdata);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
168 %! 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
169
26637
e2e1aed33f7c getframe.m: run tests with "qt" toolkit only \(bug #55528\)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
170 %!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
171 %! hf = figure ("visible", "off");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
172 %! unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
173 %! pos = get (hf, "position");
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
174 %! 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
175 %! unwind_protect_cleanup
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
176 %! close (hf);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
177 %! end_unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
178
26637
e2e1aed33f7c getframe.m: run tests with "qt" toolkit only \(bug #55528\)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
179 %!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
180 %! hf = figure ("visible", "off");
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
181 %! unwind_protect
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
182 %! 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
183 %! 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
184 %! 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
185 %! 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
186 %! 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
187 %! 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
188 %! 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
189 %! "facecolor", "flat");
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
190 %!
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
191 %! kk = 1;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
192 %! pos = get (hf, "position");
23563
614d71cdf614 maint: Strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents: 23545
diff changeset
193 %!
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
194 %! 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
195 %! 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
196 %! 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
197 %! frame = getframe (hax, rect).cdata;
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
198 %! assert (frame(:,:,1) == fvc(kk,1)*255);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
199 %! assert (frame(:,:,2) == fvc(kk,2)*255);
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
200 %! 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
201 %! kk++;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
202 %! endfor
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
203 %! endfor
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
204 %! unwind_protect_cleanup
23566
91d260dd2df3 getframe.m: Overhaul to use Octave conventions.
Rik <rik@octave.org>
parents: 23563
diff changeset
205 %! close (hf);
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
diff changeset
206 %! end_unwind_protect