2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
|
|
|
|
|
#include "COM_RotateOperation.h"
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2020-08-07 15:58:58 +02:00
|
|
|
RotateOperation::RotateOperation()
|
2012-05-17 22:55:28 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
this->add_input_socket(DataType::Color, ResizeMode::None);
|
|
|
|
|
this->add_input_socket(DataType::Value, ResizeMode::None);
|
|
|
|
|
this->add_output_socket(DataType::Color);
|
2021-09-28 19:32:49 +02:00
|
|
|
this->set_canvas_input_index(0);
|
2021-10-13 23:01:15 +02:00
|
|
|
do_degree2_rad_conversion_ = false;
|
|
|
|
|
is_degree_set_ = false;
|
2021-08-23 15:30:01 +02:00
|
|
|
sampler_ = PixelSampler::Bilinear;
|
2023-11-26 12:14:35 +01:00
|
|
|
flags_.can_be_constant = true;
|
2021-08-23 15:30:01 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 19:33:06 +02:00
|
|
|
void RotateOperation::get_rotation_center(const rcti &area, float &r_x, float &r_y)
|
|
|
|
|
{
|
|
|
|
|
r_x = (BLI_rcti_size_x(&area) - 1) / 2.0;
|
|
|
|
|
r_y = (BLI_rcti_size_y(&area) - 1) / 2.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RotateOperation::get_rotation_offset(const rcti &input_canvas,
|
|
|
|
|
const rcti &rotate_canvas,
|
|
|
|
|
float &r_offset_x,
|
|
|
|
|
float &r_offset_y)
|
|
|
|
|
{
|
|
|
|
|
r_offset_x = (BLI_rcti_size_x(&input_canvas) - BLI_rcti_size_x(&rotate_canvas)) / 2.0f;
|
|
|
|
|
r_offset_y = (BLI_rcti_size_y(&input_canvas) - BLI_rcti_size_y(&rotate_canvas)) / 2.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 15:30:01 +02:00
|
|
|
void RotateOperation::get_area_rotation_bounds(const rcti &area,
|
|
|
|
|
const float center_x,
|
|
|
|
|
const float center_y,
|
|
|
|
|
const float sine,
|
|
|
|
|
const float cosine,
|
|
|
|
|
rcti &r_bounds)
|
|
|
|
|
{
|
|
|
|
|
const float dxmin = area.xmin - center_x;
|
|
|
|
|
const float dymin = area.ymin - center_y;
|
|
|
|
|
const float dxmax = area.xmax - center_x;
|
|
|
|
|
const float dymax = area.ymax - center_y;
|
|
|
|
|
|
2021-09-28 19:33:06 +02:00
|
|
|
const float x1 = center_x + (cosine * dxmin + (-sine) * dymin);
|
|
|
|
|
const float x2 = center_x + (cosine * dxmax + (-sine) * dymin);
|
|
|
|
|
const float x3 = center_x + (cosine * dxmin + (-sine) * dymax);
|
|
|
|
|
const float x4 = center_x + (cosine * dxmax + (-sine) * dymax);
|
|
|
|
|
const float y1 = center_y + (sine * dxmin + cosine * dymin);
|
|
|
|
|
const float y2 = center_y + (sine * dxmax + cosine * dymin);
|
|
|
|
|
const float y3 = center_y + (sine * dxmin + cosine * dymax);
|
|
|
|
|
const float y4 = center_y + (sine * dxmax + cosine * dymax);
|
2024-01-22 15:58:18 +01:00
|
|
|
const float minx = std::min(x1, std::min(x2, std::min(x3, x4)));
|
|
|
|
|
const float maxx = std::max(x1, std::max(x2, std::max(x3, x4)));
|
|
|
|
|
const float miny = std::min(y1, std::min(y2, std::min(y3, y4)));
|
|
|
|
|
const float maxy = std::max(y1, std::max(y2, std::max(y3, y4)));
|
2021-08-23 15:30:01 +02:00
|
|
|
|
|
|
|
|
r_bounds.xmin = floor(minx);
|
|
|
|
|
r_bounds.xmax = ceil(maxx);
|
|
|
|
|
r_bounds.ymin = floor(miny);
|
|
|
|
|
r_bounds.ymax = ceil(maxy);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 19:33:06 +02:00
|
|
|
void RotateOperation::get_area_rotation_bounds_inverted(const rcti &area,
|
|
|
|
|
const float center_x,
|
|
|
|
|
const float center_y,
|
|
|
|
|
const float sine,
|
|
|
|
|
const float cosine,
|
|
|
|
|
rcti &r_bounds)
|
|
|
|
|
{
|
|
|
|
|
get_area_rotation_bounds(area, center_x, center_y, -sine, cosine, r_bounds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RotateOperation::get_rotation_area_of_interest(const rcti &input_canvas,
|
|
|
|
|
const rcti &rotate_canvas,
|
|
|
|
|
const float sine,
|
|
|
|
|
const float cosine,
|
|
|
|
|
const rcti &output_area,
|
|
|
|
|
rcti &r_input_area)
|
|
|
|
|
{
|
|
|
|
|
float center_x, center_y;
|
|
|
|
|
get_rotation_center(input_canvas, center_x, center_y);
|
|
|
|
|
|
|
|
|
|
float rotate_offset_x, rotate_offset_y;
|
|
|
|
|
get_rotation_offset(input_canvas, rotate_canvas, rotate_offset_x, rotate_offset_y);
|
|
|
|
|
|
|
|
|
|
r_input_area = output_area;
|
|
|
|
|
BLI_rcti_translate(&r_input_area, rotate_offset_x, rotate_offset_y);
|
|
|
|
|
get_area_rotation_bounds_inverted(r_input_area, center_x, center_y, sine, cosine, r_input_area);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RotateOperation::get_rotation_canvas(const rcti &input_canvas,
|
|
|
|
|
const float sine,
|
|
|
|
|
const float cosine,
|
|
|
|
|
rcti &r_canvas)
|
|
|
|
|
{
|
|
|
|
|
float center_x, center_y;
|
|
|
|
|
get_rotation_center(input_canvas, center_x, center_y);
|
|
|
|
|
|
|
|
|
|
rcti rot_bounds;
|
|
|
|
|
get_area_rotation_bounds(input_canvas, center_x, center_y, sine, cosine, rot_bounds);
|
|
|
|
|
|
|
|
|
|
float offset_x, offset_y;
|
|
|
|
|
get_rotation_offset(input_canvas, rot_bounds, offset_x, offset_y);
|
|
|
|
|
r_canvas = rot_bounds;
|
|
|
|
|
BLI_rcti_translate(&r_canvas, -offset_x, -offset_y);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 16:59:16 +01:00
|
|
|
void RotateOperation::init_data() {}
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
inline void RotateOperation::ensure_degree()
|
2012-06-20 17:35:51 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
if (!is_degree_set_) {
|
2024-02-28 16:59:16 +01:00
|
|
|
float degree = get_input_operation(DEGREE_INPUT_INDEX)->get_constant_value_default(0.0f);
|
2021-08-23 15:30:01 +02:00
|
|
|
|
2012-06-12 04:23:21 +00:00
|
|
|
double rad;
|
2021-10-13 23:01:15 +02:00
|
|
|
if (do_degree2_rad_conversion_) {
|
2024-02-28 16:59:16 +01:00
|
|
|
rad = DEG2RAD(double(degree));
|
2012-06-12 04:23:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2024-02-28 16:59:16 +01:00
|
|
|
rad = degree;
|
2012-06-12 04:23:21 +00:00
|
|
|
}
|
2021-10-13 23:01:04 +02:00
|
|
|
cosine_ = cos(rad);
|
|
|
|
|
sine_ = sin(rad);
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
is_degree_set_ = true;
|
2012-06-12 04:23:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 19:33:06 +02:00
|
|
|
void RotateOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
|
|
|
|
|
{
|
|
|
|
|
const bool image_determined =
|
2021-10-13 23:01:15 +02:00
|
|
|
get_input_socket(IMAGE_INPUT_INDEX)->determine_canvas(preferred_area, r_area);
|
2021-09-28 19:33:06 +02:00
|
|
|
if (image_determined) {
|
|
|
|
|
rcti input_canvas = r_area;
|
2021-11-29 19:23:43 +01:00
|
|
|
rcti unused = COM_AREA_NONE;
|
2021-10-13 23:01:15 +02:00
|
|
|
get_input_socket(DEGREE_INPUT_INDEX)->determine_canvas(input_canvas, unused);
|
2021-09-28 19:33:06 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
ensure_degree();
|
2021-09-28 19:33:06 +02:00
|
|
|
|
2021-10-13 23:01:04 +02:00
|
|
|
get_rotation_canvas(input_canvas, sine_, cosine_, r_area);
|
2021-09-28 19:33:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 15:30:01 +02:00
|
|
|
void RotateOperation::get_area_of_interest(const int input_idx,
|
|
|
|
|
const rcti &output_area,
|
|
|
|
|
rcti &r_input_area)
|
|
|
|
|
{
|
|
|
|
|
if (input_idx == DEGREE_INPUT_INDEX) {
|
2021-09-28 19:32:49 +02:00
|
|
|
r_input_area = COM_CONSTANT_INPUT_AREA_OF_INTEREST;
|
2021-08-23 15:30:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
ensure_degree();
|
2021-09-28 19:33:06 +02:00
|
|
|
|
|
|
|
|
const rcti &input_image_canvas = get_input_operation(IMAGE_INPUT_INDEX)->get_canvas();
|
|
|
|
|
get_rotation_area_of_interest(
|
2021-10-13 23:01:04 +02:00
|
|
|
input_image_canvas, this->get_canvas(), sine_, cosine_, output_area, r_input_area);
|
2021-08-23 15:30:01 +02:00
|
|
|
expand_area_for_sampler(r_input_area, sampler_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RotateOperation::update_memory_buffer_partial(MemoryBuffer *output,
|
|
|
|
|
const rcti &area,
|
|
|
|
|
Span<MemoryBuffer *> inputs)
|
|
|
|
|
{
|
|
|
|
|
const MemoryBuffer *input_img = inputs[IMAGE_INPUT_INDEX];
|
2021-09-28 19:33:06 +02:00
|
|
|
|
|
|
|
|
NodeOperation *image_op = get_input_operation(IMAGE_INPUT_INDEX);
|
|
|
|
|
float center_x, center_y;
|
|
|
|
|
get_rotation_center(image_op->get_canvas(), center_x, center_y);
|
|
|
|
|
float rotate_offset_x, rotate_offset_y;
|
|
|
|
|
get_rotation_offset(
|
|
|
|
|
image_op->get_canvas(), this->get_canvas(), rotate_offset_x, rotate_offset_y);
|
|
|
|
|
|
2021-08-23 15:30:01 +02:00
|
|
|
for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
|
2021-09-28 19:33:06 +02:00
|
|
|
float x = rotate_offset_x + it.x + canvas_.xmin;
|
|
|
|
|
float y = rotate_offset_y + it.y + canvas_.ymin;
|
2021-10-13 23:01:04 +02:00
|
|
|
rotate_coords(x, y, center_x, center_y, sine_, cosine_);
|
2021-09-28 19:33:06 +02:00
|
|
|
input_img->read_elem_sampled(x - canvas_.xmin, y - canvas_.ymin, sampler_, it.out);
|
2021-08-23 15:30:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
} // namespace blender::compositor
|