Blender  V3.3
transform_convert_sequencer_image.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 #include "DNA_space_types.h"
11 
12 #include "BLI_listbase.h"
13 #include "BLI_math.h"
14 
15 #include "BKE_context.h"
16 #include "BKE_report.h"
17 
18 #include "SEQ_channels.h"
19 #include "SEQ_iterator.h"
20 #include "SEQ_relations.h"
21 #include "SEQ_sequencer.h"
22 #include "SEQ_time.h"
23 #include "SEQ_transform.h"
24 #include "SEQ_utils.h"
25 
26 #include "ED_keyframing.h"
27 
28 #include "UI_view2d.h"
29 
30 #include "RNA_access.h"
31 #include "RNA_prototypes.h"
32 
33 #include "transform.h"
34 #include "transform_convert.h"
35 
37 typedef struct TransDataSeq {
38  struct Sequence *seq;
40  float orig_translation[2];
41  float orig_scale[2];
44 
46  Sequence *seq,
47  TransData *td,
48  TransData2D *td2d,
49  TransDataSeq *tdseq,
50  int vert_index)
51 {
52  const StripTransform *transform = seq->strip->transform;
53  float origin[2];
55  float vertex[2] = {origin[0], origin[1]};
56 
57  /* Add control vertex, so rotation and scale can be calculated.
58  * All three vertices will form a "L" shape that is aligned to the local strip axis.
59  */
60  if (vert_index == 1) {
61  vertex[0] += cosf(transform->rotation);
62  vertex[1] += sinf(transform->rotation);
63  }
64  else if (vert_index == 2) {
65  vertex[0] -= sinf(transform->rotation);
66  vertex[1] += cosf(transform->rotation);
67  }
68 
69  td2d->loc[0] = vertex[0];
70  td2d->loc[1] = vertex[1];
71  td2d->loc2d = NULL;
72  td->loc = td2d->loc;
73  copy_v3_v3(td->iloc, td->loc);
74 
75  td->center[0] = origin[0];
76  td->center[1] = origin[1];
77 
78  unit_m3(td->mtx);
79  unit_m3(td->smtx);
80 
81  axis_angle_to_mat3_single(td->axismtx, 'Z', transform->rotation);
82  normalize_m3(td->axismtx);
83 
84  tdseq->seq = seq;
85  copy_v2_v2(tdseq->orig_origin_position, origin);
86  tdseq->orig_translation[0] = transform->xofs;
87  tdseq->orig_translation[1] = transform->yofs;
88  tdseq->orig_scale[0] = transform->scale_x;
89  tdseq->orig_scale[1] = transform->scale_y;
90  tdseq->orig_rotation = transform->rotation;
91 
92  td->extra = (void *)tdseq;
93  td->ext = NULL;
94  td->flag |= TD_SELECTED;
95  td->dist = 0.0;
96 
97  return td;
98 }
99 
101  TransDataContainer *tc,
102  TransCustomData *UNUSED(custom_data))
103 {
104  TransData *td = (TransData *)tc->data;
105  MEM_freeN(td->extra);
106 }
107 
109 {
110  Editing *ed = SEQ_editing_get(t->scene);
111  const SpaceSeq *sseq = t->area->spacedata.first;
112  const ARegion *region = t->region;
113 
114  if (ed == NULL) {
115  return;
116  }
117  if (sseq->mainb != SEQ_DRAW_IMG_IMBUF) {
118  return;
119  }
120  if (region->regiontype == RGN_TYPE_PREVIEW && sseq->view == SEQ_VIEW_SEQUENCE_PREVIEW) {
121  return;
122  }
123 
127  t->scene, channels, seqbase, t->scene->r.cfra, 0);
129 
130  const int count = SEQ_collection_len(strips);
131  if (count == 0) {
132  SEQ_collection_free(strips);
133  return;
134  }
135 
138 
139  tc->data_len = count * 3; /* 3 vertices per sequence are needed. */
140  TransData *td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransSeq TransData");
141  TransData2D *td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D),
142  "TransSeq TransData2D");
143  TransDataSeq *tdseq = MEM_callocN(tc->data_len * sizeof(TransDataSeq), "TransSeq TransDataSeq");
144 
145  Sequence *seq;
146  SEQ_ITERATOR_FOREACH (seq, strips) {
147  /* One `Sequence` needs 3 `TransData` entries - center point placed in image origin, then 2
148  * points offset by 1 in X and Y direction respectively, so rotation and scale can be
149  * calculated from these points. */
150  SeqToTransData(t->scene, seq, td++, td2d++, tdseq++, 0);
151  SeqToTransData(t->scene, seq, td++, td2d++, tdseq++, 1);
152  SeqToTransData(t->scene, seq, td++, td2d++, tdseq++, 2);
153  }
154 
155  SEQ_collection_free(strips);
156 }
157 
159  Scene *scene,
161  const int tmode)
162 {
163  PointerRNA ptr;
164  PropertyRNA *prop;
165  RNA_pointer_create(&scene->id, &RNA_SequenceTransform, transform, &ptr);
166 
167  const bool around_cursor = scene->toolsettings->sequencer_tool_settings->pivot_point ==
169  const bool do_loc = tmode == TFM_TRANSLATION || around_cursor;
170  const bool do_rot = tmode == TFM_ROTATION;
171  const bool do_scale = tmode == TFM_RESIZE;
172 
173  bool changed = false;
174  if (do_rot) {
175  prop = RNA_struct_find_property(&ptr, "rotation");
176  changed |= ED_autokeyframe_property(C, scene, &ptr, prop, -1, scene->r.cfra, false);
177  }
178  if (do_loc) {
179  prop = RNA_struct_find_property(&ptr, "offset_x");
180  changed |= ED_autokeyframe_property(C, scene, &ptr, prop, -1, scene->r.cfra, false);
181  prop = RNA_struct_find_property(&ptr, "offset_y");
182  changed |= ED_autokeyframe_property(C, scene, &ptr, prop, -1, scene->r.cfra, false);
183  }
184  if (do_scale) {
185  prop = RNA_struct_find_property(&ptr, "scale_x");
186  changed |= ED_autokeyframe_property(C, scene, &ptr, prop, -1, scene->r.cfra, false);
187  prop = RNA_struct_find_property(&ptr, "scale_y");
188  changed |= ED_autokeyframe_property(C, scene, &ptr, prop, -1, scene->r.cfra, false);
189  }
190 
191  return changed;
192 }
193 
195 {
197  TransData *td = NULL;
198  TransData2D *td2d = NULL;
199  int i;
200 
201  for (i = 0, td = tc->data, td2d = tc->data_2d; i < tc->data_len; i++, td++, td2d++) {
202  /* Origin. */
203  float origin[2];
204  copy_v2_v2(origin, td2d->loc);
205  i++, td++, td2d++;
206 
207  /* X and Y control points used to read scale and rotation. */
208  float handle_x[2];
209  copy_v2_v2(handle_x, td2d->loc);
210  sub_v2_v2(handle_x, origin);
211  i++, td++, td2d++;
212  float handle_y[2];
213  copy_v2_v2(handle_y, td2d->loc);
214  sub_v2_v2(handle_y, origin);
215 
216  TransDataSeq *tdseq = td->extra;
217  Sequence *seq = tdseq->seq;
219  float mirror[2];
221 
222  /* Calculate translation. */
223  float translation[2];
224  copy_v2_v2(translation, tdseq->orig_origin_position);
225  sub_v2_v2(translation, origin);
226  mul_v2_v2(translation, mirror);
227  translation[0] *= t->scene->r.yasp / t->scene->r.xasp;
228 
229  transform->xofs = tdseq->orig_translation[0] - translation[0];
230  transform->yofs = tdseq->orig_translation[1] - translation[1];
231 
232  /* Scale. */
233  transform->scale_x = tdseq->orig_scale[0] * fabs(len_v2(handle_x));
234  transform->scale_y = tdseq->orig_scale[1] * fabs(len_v2(handle_y));
235 
236  /* Rotation. Scaling can cause negative rotation. */
237  if (t->mode == TFM_ROTATION) {
238  transform->rotation = tdseq->orig_rotation - t->values_final[0];
239  }
240 
241  if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
242  animrecord_check_state(t, &t->scene->id);
243  autokeyframe_sequencer_image(t->context, t->scene, transform, t->mode);
244  }
245 
247  }
248 }
249 
251 {
252 
254  TransData *td = NULL;
255  TransData2D *td2d = NULL;
256  int i;
257 
258  for (i = 0, td = tc->data, td2d = tc->data_2d; i < tc->data_len; i++, td++, td2d++) {
259  TransDataSeq *tdseq = td->extra;
260  Sequence *seq = tdseq->seq;
262  if (t->state == TRANS_CANCEL) {
263  if (t->mode == TFM_ROTATION) {
264  transform->rotation = tdseq->orig_rotation;
265  }
266  continue;
267  }
268 
269  if (IS_AUTOKEY_ON(t->scene)) {
270  autokeyframe_sequencer_image(t->context, t->scene, transform, t->mode);
271  }
272  }
273 }
274 
276  /* flags */ (T_POINTS | T_2D_EDIT),
277  /* createTransData */ createTransSeqImageData,
278  /* recalcData */ recalcData_sequencer_image,
279  /* special_aftertrans_update */ special_aftertrans_update__sequencer_image,
280 };
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1912
void axis_angle_to_mat3_single(float R[3][3], char axis, float angle)
MINLINE void sub_v2_v2(float r[2], const float a[2])
MINLINE void mul_v2_v2(float r[2], const float a[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
#define UNUSED(x)
@ RGN_TYPE_PREVIEW
@ SEQ_VIEW_SEQUENCE_PREVIEW
@ SEQ_DRAW_IMG_IMBUF
@ V3D_AROUND_CURSOR
#define IS_AUTOKEY_ON(scene)
@ TFM_RESIZE
Definition: ED_transform.h:32
@ TFM_ROTATION
Definition: ED_transform.h:31
@ TFM_TRANSLATION
Definition: ED_transform.h:30
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
#define C
Definition: RandGen.cpp:25
#define SEQ_ITERATOR_FOREACH(var, collection)
Definition: SEQ_iterator.h:35
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
ListBase * SEQ_channels_displayed_get(Editing *ed)
Definition: channels.c:23
#define sinf(x)
Definition: cuda/compat.h:102
#define cosf(x)
Definition: cuda/compat.h:101
Scene scene
int count
SeqCollection * SEQ_query_rendered_strips(const Scene *scene, ListBase *channels, ListBase *seqbase, const int timeline_frame, const int displayed_channel)
Definition: iterator.c:309
uint SEQ_collection_len(const SeqCollection *collection)
Definition: iterator.c:95
void SEQ_filter_selected_strips(SeqCollection *collection)
Definition: iterator.c:366
void SEQ_collection_free(SeqCollection *collection)
Definition: iterator.c:81
bool ED_autokeyframe_property(bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra, const bool only_if_property_keyed)
Definition: keyframing.c:3111
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
ListBase * SEQ_active_seqbase_get(const Editing *ed)
Definition: sequencer.c:388
Editing * SEQ_editing_get(const Scene *scene)
Definition: sequencer.c:241
#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t)
void SEQ_relations_invalidate_cache_preprocessed(Scene *scene, Sequence *seq)
void SEQ_image_transform_origin_offset_pixelspace_get(const Scene *scene, const Sequence *seq, float r_origin[2])
void SEQ_image_transform_mirror_factor_get(const Sequence *seq, float r_mirror[2])
short regiontype
struct ToolSettings * toolsettings
struct RenderData r
ListBase seqbase
struct IDProperty * prop
StripTransform * transform
struct SequencerToolSettings * sequencer_tool_settings
void(* free_cb)(struct TransInfo *, struct TransDataContainer *tc, struct TransCustomData *custom_data)
float * loc2d
float loc[3]
struct Sequence * seq
float smtx[3][3]
float axismtx[3][3]
float mtx[3][3]
TransDataExtension * ext
void animrecord_check_state(TransInfo *t, struct ID *id)
conversion and adaptation of different datablocks to a common struct.
struct TransDataSeq TransDataSeq
static void special_aftertrans_update__sequencer_image(bContext *UNUSED(C), TransInfo *t)
static TransData * SeqToTransData(const Scene *scene, Sequence *seq, TransData *td, TransData2D *td2d, TransDataSeq *tdseq, int vert_index)
static bool autokeyframe_sequencer_image(bContext *C, Scene *scene, StripTransform *transform, const int tmode)
static void createTransSeqImageData(bContext *UNUSED(C), TransInfo *t)
static void recalcData_sequencer_image(TransInfo *t)
static void freeSeqData(TransInfo *UNUSED(t), TransDataContainer *tc, TransCustomData *UNUSED(custom_data))
TransConvertTypeInfo TransConvertType_SequencerImage
@ TD_SELECTED
PointerRNA * ptr
Definition: wm_files.c:3480