Blender  V3.3
frame_accessor.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2014 Blender Foundation. All rights reserved. */
3 
5 #include "intern/image.h"
6 #include "intern/utildefines.h"
9 #include "libmv/image/image.h"
10 
11 namespace {
12 
13 using libmv::FloatImage;
14 using mv::FrameAccessor;
15 using mv::Region;
16 
17 struct LibmvFrameAccessor : public FrameAccessor {
18  LibmvFrameAccessor(libmv_FrameAccessorUserData* user_data,
19  libmv_GetImageCallback get_image_callback,
20  libmv_ReleaseImageCallback release_image_callback,
21  libmv_GetMaskForTrackCallback get_mask_for_track_callback,
22  libmv_ReleaseMaskCallback release_mask_callback)
23  : user_data_(user_data),
24  get_image_callback_(get_image_callback),
25  release_image_callback_(release_image_callback),
26  get_mask_for_track_callback_(get_mask_for_track_callback),
27  release_mask_callback_(release_mask_callback) {}
28 
29  virtual ~LibmvFrameAccessor() {}
30 
31  libmv_InputMode get_libmv_input_mode(InputMode input_mode) {
32  switch (input_mode) {
33 #define CHECK_INPUT_MODE(mode) \
34  case mode: return LIBMV_IMAGE_MODE_##mode;
35  CHECK_INPUT_MODE(MONO)
36  CHECK_INPUT_MODE(RGBA)
37 #undef CHECK_INPUT_MODE
38  }
39  assert(!"unknown input mode passed from Libmv.");
40  // TODO(sergey): Proper error handling here in the future.
41  return LIBMV_IMAGE_MODE_MONO;
42  }
43 
44  void get_libmv_region(const Region& region, libmv_Region* libmv_region) {
45  libmv_region->min[0] = region.min(0);
46  libmv_region->min[1] = region.min(1);
47  libmv_region->max[0] = region.max(0);
48  libmv_region->max[1] = region.max(1);
49  }
50 
51  Key GetImage(int clip,
52  int frame,
53  InputMode input_mode,
54  int downscale,
55  const Region* region,
56  const Transform* transform,
57  FloatImage* destination) {
58  float* float_buffer;
59  int width, height, channels;
60  libmv_Region libmv_region;
61  if (region) {
62  get_libmv_region(*region, &libmv_region);
63  }
64  Key cache_key = get_image_callback_(user_data_,
65  clip,
66  frame,
67  get_libmv_input_mode(input_mode),
68  downscale,
69  region != NULL ? &libmv_region : NULL,
71  &float_buffer,
72  &width,
73  &height,
74  &channels);
75 
76  // TODO(sergey): Dumb code for until we can set data directly.
77  FloatImage temp_image(float_buffer, height, width, channels);
78  destination->CopyFrom(temp_image);
79 
80  return cache_key;
81  }
82 
83  void ReleaseImage(Key cache_key) { release_image_callback_(cache_key); }
84 
85  Key GetMaskForTrack(int clip,
86  int frame,
87  int track,
88  const Region* region,
89  FloatImage* destination) {
90  float* float_buffer;
91  int width, height;
92  libmv_Region libmv_region;
93  if (region) {
94  get_libmv_region(*region, &libmv_region);
95  }
96  Key cache_key =
97  get_mask_for_track_callback_(user_data_,
98  clip,
99  frame,
100  track,
101  region != NULL ? &libmv_region : NULL,
102  &float_buffer,
103  &width,
104  &height);
105 
106  if (cache_key == NULL) {
107  // No mask for the given track.
108  return NULL;
109  }
110 
111  // TODO(sergey): Dumb code for until we can set data directly.
112  FloatImage temp_image(float_buffer, height, width, 1);
113  destination->CopyFrom(temp_image);
114 
115  return cache_key;
116  }
117 
118  void ReleaseMask(Key key) { release_mask_callback_(key); }
119 
120  bool GetClipDimensions(int /*clip*/, int* /*width*/, int* /*height*/) {
121  return false;
122  }
123 
124  int NumClips() { return 1; }
125 
126  int NumFrames(int /*clip*/) { return 0; }
127 
128  libmv_FrameAccessorUserData* user_data_;
129  libmv_GetImageCallback get_image_callback_;
130  libmv_ReleaseImageCallback release_image_callback_;
131  libmv_GetMaskForTrackCallback get_mask_for_track_callback_;
132  libmv_ReleaseMaskCallback release_mask_callback_;
133 };
134 
135 } // namespace
136 
139  libmv_GetImageCallback get_image_callback,
140  libmv_ReleaseImageCallback release_image_callback,
141  libmv_GetMaskForTrackCallback get_mask_for_track_callback,
142  libmv_ReleaseMaskCallback release_mask_callback) {
143  return (libmv_FrameAccessor*)LIBMV_OBJECT_NEW(LibmvFrameAccessor,
144  user_data,
145  get_image_callback,
146  release_image_callback,
147  get_mask_for_track_callback,
148  release_mask_callback);
149 }
150 
152  LIBMV_OBJECT_DELETE(frame_accessor, LibmvFrameAccessor);
153 }
154 
157  return ((FrameAccessor::Transform*)transform)->key();
158 }
159 
161  const libmv_FloatImage* input_image,
162  libmv_FloatImage* output_image) {
163  const FloatImage input(input_image->buffer,
164  input_image->height,
165  input_image->width,
166  input_image->channels);
167 
170 
171  int num_pixels = output.Width() * output.Height() * output.Depth();
172  output_image->buffer = new float[num_pixels];
173  memcpy(output_image->buffer, output.Data(), num_pixels * sizeof(float));
174  output_image->width = output.Width();
175  output_image->height = output.Height();
176  output_image->channels = output.Depth();
177 }
long input_mode
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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 width
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
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
void * user_data
void libmv_FrameAccessorDestroy(libmv_FrameAccessor *frame_accessor)
#define CHECK_INPUT_MODE(mode)
void libmv_frameAccessorgetTransformRun(const libmv_FrameTransform *transform, const libmv_FloatImage *input_image, libmv_FloatImage *output_image)
libmv_FrameAccessor * libmv_FrameAccessorNew(libmv_FrameAccessorUserData *user_data, libmv_GetImageCallback get_image_callback, libmv_ReleaseImageCallback release_image_callback, libmv_GetMaskForTrackCallback get_mask_for_track_callback, libmv_ReleaseMaskCallback release_mask_callback)
int64_t libmv_frameAccessorgetTransformKey(const libmv_FrameTransform *transform)
CCL_NAMESPACE_BEGIN struct Transform Transform
struct libmv_FrameTransform libmv_FrameTransform
libmv_CacheKey(* libmv_GetImageCallback)(libmv_FrameAccessorUserData *user_data, int clip, int frame, libmv_InputMode input_mode, int downscale, const libmv_Region *region, const libmv_FrameTransform *transform, float **destination, int *width, int *height, int *channels)
struct libmv_FrameAccessorUserData libmv_FrameAccessorUserData
libmv_CacheKey(* libmv_GetMaskForTrackCallback)(libmv_FrameAccessorUserData *user_data, int clip, int frame, int track, const libmv_Region *region, float **destination, int *width, int *height)
void(* libmv_ReleaseImageCallback)(libmv_CacheKey cache_key)
@ LIBMV_IMAGE_MODE_MONO
void(* libmv_ReleaseMaskCallback)(libmv_CacheKey cache_key)
struct libmv_FrameAccessor libmv_FrameAccessor
ccl_gpu_kernel_postfix ccl_global float int num_pixels
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
Array3Df FloatImage
__int64 int64_t
Definition: stdint.h:89
float min[2]
Definition: intern/region.h:12
float max[2]
Definition: intern/region.h:13
#define LIBMV_OBJECT_NEW(type,...)
Definition: utildefines.h:38
#define LIBMV_OBJECT_DELETE(what, type)
Definition: utildefines.h:41