use the same rasterizer as the compositor for the sequencer.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 31 Jul 2012 15:45:01 +0000 (15:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 31 Jul 2012 15:45:01 +0000 (15:45 +0000)
source/blender/blenkernel/BKE_mask.h
source/blender/blenkernel/intern/mask_rasterize.c
source/blender/blenkernel/intern/sequencer.c

index a20bd9c20621f2c6f781428a9991b80c44a94917..6c2e2b5d0f3402ecd56f449a913d5d13fe055f70 100644 (file)
@@ -231,6 +231,11 @@ void              BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, str
                                                 const short do_aspect_correct, const short do_mask_aa,
                                                 const short do_feather);
 float             BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]);
+
+void              BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
+                                           const unsigned int width, const unsigned int height,
+                                           float *buffer);
+
 #endif /* USE_RASKTER */
 
 #endif /* __BKE_MASK_H__ */
index da0070f0c09d9e520c68d920ba8dcd5748311d52..6811a6fea1824af2045f518b96564105428e4d66 100644 (file)
@@ -1289,4 +1289,33 @@ float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float x
        return value;
 }
 
+/**
+ * \brief Rasterize a buffer from a single mask
+ *
+ * We could get some speedup by inlining #BKE_maskrasterize_handle_sample
+ * and calcilating each layer then blending buffers, but this function is only
+ * used by the sequencer - so better have the caller thread.
+ *
+ * If we wanted to this function could be threaded with OpenMP easily.
+ */
+void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
+                              const unsigned int width, const unsigned int height,
+                              float *buffer)
+{
+       unsigned int x;
+       unsigned int y;
+       float *fp = buffer;
+
+       float xy[2];
+
+       for (y = 0; y < height; y++) {
+               xy[1] = (float)y / (float)height;
+               for (x = 0; x < width; x++) {
+                       xy[0] = (float)x / (float)width;
+
+                       *fp++ = BKE_maskrasterize_handle_sample(mr_handle, xy);
+               }
+       }
+}
+
 #endif /* USE_RASKTER */
index 545ec0812eef7fd8dc5276676d507e50d9811ea0..2900cb55529669b1e15d9eb520db84e02e4d3b48 100644 (file)
@@ -2072,10 +2072,30 @@ static ImBuf *seq_render_mask_strip(
        if (!seq->mask) {
                return NULL;
        }
+       else {
+               Mask *mask_temp;
+               MaskRasterHandle *mr_handle;
+
+               mask_temp = BKE_mask_copy_nolib(seq->mask);
+
+               BKE_mask_evaluate(mask_temp, seq->mask->sfra + nr, TRUE);
+
+               maskbuf = MEM_mallocN(sizeof(float) * context.rectx * context.recty, __func__);
+
+               mr_handle = BKE_maskrasterize_handle_new();
+
+               BKE_maskrasterize_handle_init(mr_handle, mask_temp,
+                                             context.rectx, context.recty,
+                                             TRUE, TRUE, TRUE);
 
-       BKE_mask_evaluate(seq->mask, seq->mask->sfra + nr, TRUE);
+               BKE_mask_free(mask_temp);
+               MEM_freeN(mask_temp);
+
+               BKE_maskrasterize_buffer(mr_handle, context.rectx, context.recty, maskbuf);
+
+               BKE_maskrasterize_handle_free(mr_handle);
+       }
 
-       maskbuf = MEM_callocN(sizeof(float) * context.rectx * context.recty, __func__);
 
        if (seq->flag & SEQ_MAKE_FLOAT) {
                /* pixels */
@@ -2084,14 +2104,6 @@ static ImBuf *seq_render_mask_strip(
 
                ibuf = IMB_allocImBuf(context.rectx, context.recty, 32, IB_rectfloat);
 
-               BKE_mask_rasterize(seq->mask,
-                                  context.rectx, context.recty,
-                                  maskbuf,
-                                  TRUE,
-                                  FALSE, /*XXX- TODO: make on/off for anti-aliasing */
-                                  TRUE   /*XXX- TODO: make on/off for feather */
-                                  );
-
                fp_src = maskbuf;
                fp_dst = ibuf->rect_float;
                i = context.rectx * context.recty;
@@ -2110,14 +2122,6 @@ static ImBuf *seq_render_mask_strip(
 
                ibuf = IMB_allocImBuf(context.rectx, context.recty, 32, IB_rect);
 
-               BKE_mask_rasterize(seq->mask,
-                                  context.rectx, context.recty,
-                                  maskbuf,
-                                  TRUE,
-                                  FALSE, /*XXX- TODO: make on/off for anti-aliasing */
-                                  TRUE   /*XXX- TODO: make on/off for feather */
-                                  );
-
                fp_src = maskbuf;
                ub_dst = (unsigned char *)ibuf->rect;
                i = context.rectx * context.recty;