GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
base-text-renderer.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2009-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "base-text-renderer.h"
31
33
34void
36{
37 switch (rot_mode)
38 {
39 case ROTATION_0:
40 break;
41
42 case ROTATION_90:
43 {
45 perm(0) = 0;
46 perm(1) = 2;
47 perm(2) = 1;
48 pixels = pixels.permute (perm);
49
50 Array<idx_vector> idx (dim_vector (3, 1));
51 idx(0) = idx_vector (':');
52 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1);
53 idx(2) = idx_vector (':');
54 pixels = uint8NDArray (pixels.index (idx));
55 }
56 break;
57
58 case ROTATION_180:
59 {
60 Array<idx_vector> idx (dim_vector (3, 1));
61 idx(0) = idx_vector (':');
62 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1);
63 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1);
64 pixels = uint8NDArray (pixels.index (idx));
65 }
66 break;
67
68 case ROTATION_270:
69 {
71 perm(0) = 0;
72 perm(1) = 2;
73 perm(2) = 1;
74 pixels = pixels.permute (perm);
75
76 Array<idx_vector> idx (dim_vector (3, 1));
77 idx(0) = idx_vector (':');
78 idx(1) = idx_vector (':');
79 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1);
80 pixels = uint8NDArray (pixels.index (idx));
81 }
82 break;
83
84 }
85}
86
87int
89{
90 // Wrap rotation to range [0, 360]
91 while (rotation < 0)
92 rotation += 360.0;
93 while (rotation > 360.0)
94 rotation -= 360.0;
95
96 if (rotation == 0.0)
97 return ROTATION_0;
98 else if (rotation == 90.0)
99 return ROTATION_90;
100 else if (rotation == 180.0)
101 return ROTATION_180;
102 else if (rotation == 270.0)
103 return ROTATION_270;
104 else
105 return ROTATION_0;
106}
107
108void
110 int valign, int rot_mode,
111 bool handle_rotation) const
112{
113 switch (halign)
114 {
115 case 1:
116 bbox(0) = -bbox(2)/2;
117 break;
118
119 case 2:
120 bbox(0) = -bbox(2);
121 break;
122
123 default:
124 bbox(0) = 0;
125 break;
126 }
127
128 switch (valign)
129 {
130 case 1:
131 bbox(1) = -bbox(3)/2;
132 break;
133
134 case 2:
135 bbox(1) = -bbox(3);
136 break;
137
138 case 3:
139 break;
140
141 case 4:
142 bbox(1) = -bbox(3)-bbox(1);
143 break;
144
145 default:
146 bbox(1) = 0;
147 break;
148 }
149
150 if (handle_rotation)
151 {
152 switch (rot_mode)
153 {
154 case ROTATION_90:
155 std::swap (bbox(0), bbox(1));
156 std::swap (bbox(2), bbox(3));
157 bbox(0) = -bbox(0)-bbox(2);
158 break;
159
160 case ROTATION_180:
161 bbox(0) = -bbox(0)-bbox(2);
162 bbox(1) = -bbox(1)-bbox(3);
163 break;
164
165 case ROTATION_270:
166 std::swap (bbox(0), bbox(1));
167 std::swap (bbox(2), bbox(3));
168 bbox(1) = -bbox(1)-bbox(3);
169 break;
170 }
171 }
172}
173
174OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
octave_idx_type dim3() const
Size of the specified dimension.
Definition Array.h:483
octave_idx_type dim2() const
Definition Array.h:471
MArray< T > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Definition MArray.h:88
void fix_bbox_anchor(Matrix &bbox, int halign, int valign, int rot_mode, bool handle_rotation) const
void rotate_pixels(uint8NDArray &pixels, int rot_mode) const
int rotation_to_mode(double rotation) const
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
intNDArray< octave_uint8 > uint8NDArray