28class IdentityTransformation;
36class AffineTransformation;
38class ProjectiveTransformation;
44Scaling
Scale(
float sx,
float sy);
47AffineTransformation
ScaleAbout(
float sx,
float sy,
const FpPoint& center);
68AffineTransformation
RotateLeftAbout(
float angle,
const FpPoint& center);
71AffineTransformation
Shear(
float sx,
float sy);
74AffineTransformation
Shear(
float sx,
float sy,
const FpPoint& base);
91ProjectiveTransformation
Perspective(
float px,
float py);
97template <
typename RasterType,
typename TransformationType>
98class TransformedRaster;
101template <
typename RasterType,
typename TransformationType>
103 RasterType& original, TransformationType transformation);
132 float dx()
const {
return dx_; }
133 float dy()
const {
return dy_; }
162 float sx()
const {
return sx_; }
163 float sy()
const {
return sy_; }
175 float xMin = sx_ * extents.
xMin();
176 float yMin = sy_ * extents.
yMin();
177 float xMax = sx_ * extents.
xMax();
178 float yMax = sy_ * extents.
yMax();
179 if (xMin > xMax) std::swap(xMin, xMax);
180 if (yMin > yMax) std::swap(yMin, yMax);
196 return FpPoint{
p.x * cos_theta_ -
p.y * sin_theta_,
197 p.x * sin_theta_ +
p.y * cos_theta_};
200 float theta()
const {
return theta_; }
216 float theta_, sin_theta_, cos_theta_;
227 : a11_(1.0), a12_(0), a21_(0), a22_(1.0), tx_(0), ty_(0) {}
230 : a11_(1.0), a12_(0), a21_(0), a22_(1.0), tx_(
t.dx()), ty_(
t.dy()) {}
233 : a11_(
t.sx()), a12_(0), a21_(0), a22_(
t.sy()), tx_(0), ty_(0) {}
236 : a11_(
t.cos_theta()),
237 a12_(-
t.sin_theta()),
244 return FpPoint{
p.x * a11_ +
p.y * a12_ + tx_,
245 p.x * a21_ +
p.y * a22_ + ty_};
248 float a11()
const {
return a11_; }
249 float a12()
const {
return a12_; }
250 float a21()
const {
return a21_; }
251 float a22()
const {
return a22_; }
252 float tx()
const {
return tx_; }
253 float ty()
const {
return ty_; }
263 float inv_det = 1.0f / (a11_ * a22_ - a12_ * a21_);
277 float a11_, a12_, a21_, a22_;
331 : m11_(
t.cos_theta()),
332 m12_(-
t.sin_theta()),
353 float w =
p.x * m31_ +
p.y * m32_ + m33_;
354 return FpPoint{(
p.x * m11_ +
p.y * m12_ + m13_) / w,
355 (
p.x * m21_ +
p.y * m22_ + m23_) / w};
358 float m11()
const {
return m11_; }
359 float m12()
const {
return m12_; }
360 float m13()
const {
return m13_; }
361 float m21()
const {
return m21_; }
362 float m22()
const {
return m22_; }
363 float m23()
const {
return m23_; }
364 float m31()
const {
return m31_; }
365 float m32()
const {
return m32_; }
366 float m33()
const {
return m33_; }
382 float m11_, m12_, m13_;
383 float m21_, m22_, m23_;
384 float m31_, m32_, m33_;
388template <
typename RasterType,
typename TransformationType>
393 inverse_transformation_(transformation.inversion()),
403 result[
i] = color::Transparent;
407 typename RasterType::Reader
reader;
408 const auto ptr = original_.buffer();
420 result[
i] = color::Transparent;
425 if (xMin == xMax && yMin == yMax) {
434 reader(
ptr, offset + w, original_.color_mode()),
443 reader(
ptr, offset + w, original_.color_mode()),
453 reader(
ptr, offset + 1, original_.color_mode()),
462 reader(
ptr, offset + 1, original_.color_mode()),
505 reader(
ptr, offset + 1, original_.color_mode()),
525 reader(
ptr, offset + 1, original_.color_mode()),
535 reader(
ptr, offset + w + 1, original_.color_mode()),
555 reader(
ptr, offset + w, original_.color_mode()),
556 reader(
ptr, offset + w + 1, original_.color_mode()),
569 RasterType& original_;
575template <
typename RasterType,
typename TransformationType>
Axis-aligned integer rectangle.
int16_t xMin() const
Minimum x (inclusive).
int16_t xMax() const
Maximum x (inclusive).
int16_t yMax() const
Maximum y (inclusive).
int16_t yMin() const
Minimum y (inclusive).
ARGB8888 color stored as a 32-bit unsigned integer.
Drawable that can provide a color for any point within its extents.
Rotation by angle in radians (clockwise).
Rotation inversion() const
FpPoint apply(FpPoint p) const
Rotation then(IdentityTransformation t) const
Box transformExtents(Box extents) const
Box transformExtents(Box extents) const
Scaling then(IdentityTransformation t) const
Scaling inversion() const
FpPoint apply(FpPoint p) const
Scaling(float sx, float sy)
FpPoint apply(FpPoint p) const
Translation inversion() const
Translation then(IdentityTransformation t) const
Translation(float dx, float dy)
Box transformExtents(Box extents) const
Defines 140 opaque HTML named colors.
AffineTransformation RotateRightAbout(float angle, const FpPoint ¢er)
Return a clockwise rotation about a point.
AffineTransformation RotateLeftAbout(float angle, const FpPoint ¢er)
Return a 90-degree counter-clockwise rotation about a point.
AffineTransformation ShearVertically(float sy)
Return a vertical shear rooted at the origin.
Scaling Scale(float sx, float sy)
Return a scaling about the origin.
AffineTransformation ShearHorizontallyAbout(float sx, float base_y)
Return a horizontal shear rooted at base_y.
TransformedRaster< RasterType, TransformationType > TransformRaster(RasterType &original, TransformationType transformation)
Return a rasterizable representation of a transformed raster.
Rotation RotateRight()
Return a 90-degree clockwise rotation about the origin.
AffineTransformation ShearVerticallyAbout(float sy, float base_x)
Return a vertical shear rooted at base_x.
ProjectiveTransformation PerspectiveAbout(float px, float py, const FpPoint &base)
Return a perspective transformation rooted at base.
AffineTransformation ShearHorizontally(float sx)
Return a horizontal shear rooted at the origin.
Translation Translate(float dx, float dy)
Return a translation by the specified vector.
Color InterpolateColors(Color c1, Color c2, int16_t fraction)
Interpolate between two colors with fraction in [0, 256].
AffineTransformation ScaleAbout(float sx, float sy, const FpPoint ¢er)
Return a scaling about a given center.
AffineTransformation Shear(float sx, float sy)
Return a shear rooted at the origin.
ProjectiveTransformation Perspective(float px, float py)
Return a perspective transformation rooted at the origin.
Rotation RotateLeft()
Return a 90-degree counter-clockwise rotation about the origin.