forked from bartvdbraak/blender
some code refactors in raskter.c to sync it with build where mask tiling is being developed. Also adds a bit more mask tiling code.
This commit is contained in:
parent
1f9adff26f
commit
492d9aabe0
File diff suppressed because it is too large
Load Diff
@ -80,11 +80,21 @@ struct r_fill_context {
|
||||
int bounds_length;
|
||||
};
|
||||
|
||||
struct layer_init_data {
|
||||
struct poly_vert *imask;
|
||||
struct poly_vert *omask;
|
||||
struct scan_line *bounds;
|
||||
int *bound_indexes;
|
||||
int bounds_length;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void preprocess_all_edges(struct r_fill_context *ctx, struct poly_vert *verts, int num_verts, struct e_status *open_edge);
|
||||
int PLX_init_base_data(struct layer_init_data *mlayer_data, float(*base_verts)[2], int num_base_verts,
|
||||
float *buf, int buf_x, int buf_y);
|
||||
int PLX_raskterize(float (*base_verts)[2], int num_base_verts,
|
||||
float *buf, int buf_x, int buf_y, int do_mask_AA);
|
||||
int PLX_raskterize_feather(float (*base_verts)[2], int num_base_verts,
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "raskter.h"
|
||||
static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, int num_verts) {
|
||||
static int rast_scan_init(struct layer_init_data *mlayer_data, struct r_fill_context *ctx, struct poly_vert *verts, int num_verts) {
|
||||
int x_curr; /* current pixel position in X */
|
||||
int y_curr; /* current scan line being drawn */
|
||||
int yp; /* y-pixel's position in frame buffer */
|
||||
@ -54,7 +54,7 @@ static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, i
|
||||
}
|
||||
|
||||
/* set initial bounds length to 0 */
|
||||
ctx->bounds_length=0;
|
||||
mlayer_data->bounds_length=0;
|
||||
|
||||
/* round 1, count up all the possible spans in the base buffer */
|
||||
preprocess_all_edges(ctx, verts, num_verts, edgbuf);
|
||||
@ -96,7 +96,7 @@ static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, i
|
||||
mpxl = spxl + MIN2(e_curr->x, ctx->rb.sizex) - 1;
|
||||
|
||||
if((y_curr >= 0) && (y_curr < ctx->rb.sizey)) {
|
||||
ctx->bounds_length++;
|
||||
mlayer_data->bounds_length++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,16 +152,16 @@ static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, i
|
||||
|
||||
/*initialize index buffer and bounds buffers*/
|
||||
//gets the +1 for dummy at the end
|
||||
if((ctx->bound_indexes = (int *)(malloc(sizeof(int) * ctx->rb.sizey+1)))==NULL) {
|
||||
if((mlayer_data->bound_indexes = (int *)(malloc(sizeof(int) * ctx->rb.sizey+1)))==NULL) {
|
||||
return(0);
|
||||
}
|
||||
//gets the +1 for dummy at the start
|
||||
if((ctx->bounds = (struct scan_line *)(malloc(sizeof(struct scan_line) * ctx->bounds_length+1)))==NULL){
|
||||
if((mlayer_data->bounds = (struct scan_line *)(malloc(sizeof(struct scan_line) * mlayer_data->bounds_length+1)))==NULL){
|
||||
return(0);
|
||||
}
|
||||
//init all the indexes to zero (are they already zeroed from malloc???)
|
||||
for(i=0;i<ctx->rb.sizey+1;i++){
|
||||
ctx->bound_indexes[i]=0;
|
||||
mlayer_data->bound_indexes[i]=0;
|
||||
}
|
||||
/* round 2, fill in the full list of bounds, and create indexes to the list... */
|
||||
preprocess_all_edges(ctx, verts, num_verts, edgbuf);
|
||||
@ -207,8 +207,8 @@ static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, i
|
||||
mpxl = spxl + MIN2(e_curr->x, ctx->rb.sizex) - 1;
|
||||
|
||||
if((y_curr >= 0) && (y_curr < ctx->rb.sizey)) {
|
||||
ctx->bounds[i].xstart=cpxl-spxl;
|
||||
ctx->bounds[i].xend=mpxl-spxl;
|
||||
mlayer_data->bounds[i].xstart=cpxl-spxl;
|
||||
mlayer_data->bounds[i].xend=mpxl-spxl;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -266,7 +266,7 @@ static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, i
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* static */ int init_base_data(float(*base_verts)[2], int num_base_verts,
|
||||
/* static */ int PLX_init_base_data(struct layer_init_data *mlayer_data, float(*base_verts)[2], int num_base_verts,
|
||||
float *buf, int buf_x, int buf_y) {
|
||||
int i; /* i: Loop counter. */
|
||||
struct poly_vert *ply; /* ply: Pointer to a list of integer buffer-space vertex coordinates. */
|
||||
@ -283,7 +283,7 @@ static int rast_scan_init(struct r_fill_context *ctx, struct poly_vert *verts, i
|
||||
ply[i].x = (int)((base_verts[i][0] * buf_x_f) + 0.5f); /* Range expand normalized X to integer buffer-space X. */
|
||||
ply[i].y = (int)((base_verts[i][1] * buf_y_f) + 0.5f); /* Range expand normalized Y to integer buffer-space Y. */
|
||||
}
|
||||
i = rast_scan_init(&ctx, ply, num_base_verts); /* Call our rasterizer, passing in the integer coords for each vert. */
|
||||
i = rast_scan_init(mlayer_data, &ctx, ply, num_base_verts); /* Call our rasterizer, passing in the integer coords for each vert. */
|
||||
free(ply); /* Free the memory allocated for the integer coordinate table. */
|
||||
return(i); /* Return the value returned by the rasterizer. */
|
||||
}
|
||||
|
@ -184,6 +184,12 @@ void BKE_mask_rasterize(struct Mask *mask, int width, int height, float *buffer,
|
||||
const short do_aspect_correct, const short do_mask_aa,
|
||||
const short do_feather);
|
||||
|
||||
/* initialization for tiling */
|
||||
#ifdef __PLX_RASKTER_MT__
|
||||
void BKE_mask_init_layers(Mask *mask, struct layer_init_data *mlayer_data, int width, int height,
|
||||
const short do_aspect_correct);
|
||||
#endif
|
||||
|
||||
#define MASKPOINT_ISSEL_ANY(p) ( ((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f2) & SELECT)
|
||||
#define MASKPOINT_ISSEL_KNOT(p) ( (p)->bezt.f2 & SELECT)
|
||||
#define MASKPOINT_ISSEL_HANDLE_ONLY(p) ( (((p)->bezt.f1 | (p)->bezt.f2) & SELECT) && (((p)->bezt.f2 & SELECT) == 0) )
|
||||
|
@ -2282,6 +2282,77 @@ void BKE_mask_rasterize_layers(ListBase *masklayers, int width, int height, floa
|
||||
MEM_freeN(buffer_tmp);
|
||||
}
|
||||
|
||||
#ifdef __PLX_RASKTER_MT__
|
||||
void BKE_mask_init_layers(Mask *mask, struct layer_init_data *mlayer_data, int width, int height, const short do_aspect_correct){
|
||||
MaskLayer *masklay;
|
||||
int numLayers=0;
|
||||
int currLayer=0;
|
||||
for (masklay = mask->masklayers->first; masklay; masklay = masklay->next) {
|
||||
numLayers++;
|
||||
}
|
||||
mlayer_data = MEM_mallocN(sizeof(struct layer_init_data) * numLayers, __func__); //size correct?
|
||||
|
||||
|
||||
for (masklay = mask->masklayers->first; masklay; masklay = masklay->next) {
|
||||
MaskSpline *spline;
|
||||
for (spline = masklay->splines.first; spline; spline = spline->next) {
|
||||
float (*diff_points)[2];
|
||||
int tot_diff_point;
|
||||
|
||||
float (*diff_feather_points)[2];
|
||||
int tot_diff_feather_points;
|
||||
|
||||
diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height,
|
||||
&tot_diff_point);
|
||||
|
||||
if (tot_diff_point) {
|
||||
if (do_feather) {
|
||||
diff_feather_points =
|
||||
BKE_mask_spline_feather_differentiated_points_with_resolution(spline, width, height,
|
||||
&tot_diff_feather_points);
|
||||
}
|
||||
else {
|
||||
tot_diff_feather_points = 0;
|
||||
diff_feather_points = NULL;
|
||||
}
|
||||
|
||||
if (do_aspect_correct) {
|
||||
if (width != height) {
|
||||
float *fp;
|
||||
float *ffp;
|
||||
int i;
|
||||
float asp;
|
||||
|
||||
if (width < height) {
|
||||
fp = &diff_points[0][0];
|
||||
ffp = tot_diff_feather_points ? &diff_feather_points[0][0] : NULL;
|
||||
asp = (float)width / (float)height;
|
||||
}
|
||||
else {
|
||||
fp = &diff_points[0][1];
|
||||
ffp = tot_diff_feather_points ? &diff_feather_points[0][1] : NULL;
|
||||
asp = (float)height / (float)width;
|
||||
}
|
||||
|
||||
for (i = 0; i < tot_diff_point; i++, fp += 2) {
|
||||
(*fp) = (((*fp) - 0.5f) / asp) + 0.5f;
|
||||
}
|
||||
|
||||
if (tot_diff_feather_points) {
|
||||
for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) {
|
||||
(*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PLX_init_base_data(mlayer_data[currLayer], diff_points, tot_diff_points, width, height);
|
||||
currLayer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer,
|
||||
const short do_aspect_correct, const short do_mask_aa,
|
||||
const short do_feather)
|
||||
|
@ -31,6 +31,10 @@
|
||||
#include "BLI_listbase.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#ifdef __PLX_RASKTER_MT__
|
||||
#include "../../../../intern/raskter/raskter.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Class with implementation of mask rasterization
|
||||
*/
|
||||
@ -43,6 +47,7 @@ protected:
|
||||
bool m_do_smooth;
|
||||
bool m_do_feather;
|
||||
float *m_rasterizedMask;
|
||||
|
||||
ListBase m_maskLayers;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user