bool ExecutionGroup::scheduleAreaWhenPossible(ExecutionSystem *graph, rcti *area) { if (this->m_singleThreaded) { return scheduleChunkWhenPossible(graph, 0, 0); } // find all chunks inside the rect // determine minxchunk, minychunk, maxxchunk, maxychunk where x and y are chunknumbers int indexx, indexy; int minx = max_ii(area->xmin - m_viewerBorder.xmin, 0); int maxx = min_ii(area->xmax - m_viewerBorder.xmin, m_viewerBorder.xmax - m_viewerBorder.xmin); int miny = max_ii(area->ymin - m_viewerBorder.ymin, 0); int maxy = min_ii(area->ymax - m_viewerBorder.ymin, m_viewerBorder.ymax - m_viewerBorder.ymin); int minxchunk = minx / (int)m_chunkSize; int maxxchunk = (maxx + (int)m_chunkSize - 1) / (int)m_chunkSize; int minychunk = miny / (int)m_chunkSize; int maxychunk = (maxy + (int)m_chunkSize - 1) / (int)m_chunkSize; minxchunk = max_ii(minxchunk, 0); minychunk = max_ii(minychunk, 0); maxxchunk = min_ii(maxxchunk, (int)m_numberOfXChunks); maxychunk = min_ii(maxychunk, (int)m_numberOfYChunks); bool result = true; for (indexx = minxchunk; indexx < maxxchunk; indexx++) { for (indexy = minychunk; indexy < maxychunk; indexy++) { if (!scheduleChunkWhenPossible(graph, indexx, indexy)) { result = false; } } } return result; }
void GaussianYBlurOperation::executePixel(float output[4], int x, int y, void *data) { float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float multiplier_accum = 0.0f; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); int bufferwidth = inputBuffer->getWidth(); int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; rcti &rect = *inputBuffer->getRect(); int xmin = max_ii(x, rect.xmin); int ymin = max_ii(y - m_filtersize, rect.ymin); int ymax = min_ii(y + m_filtersize + 1, rect.ymax); int index; int step = getStep(); const int bufferIndexx = ((xmin - bufferstartx) * 4); for (int ny = ymin; ny < ymax; ny += step) { index = (ny - y) + this->m_filtersize; int bufferindex = bufferIndexx + ((ny - bufferstarty) * 4 * bufferwidth); const float multiplier = this->m_gausstab[index]; madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier); multiplier_accum += multiplier; } mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum); }
/* uses UI_BTYPE_ROUNDBOX button in block to get the rect */ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect, rcti *newrect) { Render *re; RenderResult rres; char name[32]; int offx = 0; int newx = BLI_rcti_size_x(rect); int newy = BLI_rcti_size_y(rect); bool ok = false; if (!split || first) sprintf(name, "Preview %p", (void *)sa); else sprintf(name, "SecondPreview %p", (void *)sa); if (split) { if (first) { offx = 0; newx = newx / 2; } else { offx = newx / 2; newx = newx - newx / 2; } } /* test if something rendered ok */ re = RE_GetRender(name); /* material preview only needs monoscopy (view 0) */ RE_AcquireResultImage(re, &rres, 0); if (rres.rectf) { if (ABS(rres.rectx - newx) < 2 && ABS(rres.recty - newy) < 2) { newrect->xmax = max_ii(newrect->xmax, rect->xmin + rres.rectx + offx); newrect->ymax = max_ii(newrect->ymax, rect->ymin + rres.recty); if (rres.rectx && rres.recty) { unsigned char *rect_byte = MEM_mallocN(rres.rectx * rres.recty * sizeof(int), "ed_preview_draw_rect"); float fx = rect->xmin + offx; float fy = rect->ymin; /* material preview only needs monoscopy (view 0) */ if (re) RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0); glaDrawPixelsSafe(fx, fy, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect_byte); MEM_freeN(rect_byte); ok = 1; } } } RE_ReleaseResultImage(re); return ok; }
BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int *result) { int j; unsigned int total = 0; BVHTreeOverlap *overlap = NULL, *to = NULL; BVHOverlapData **data; /* check for compatibility of both trees (can't compare 14-DOP with 18-DOP) */ if ((tree1->axis != tree2->axis) && (tree1->axis == 14 || tree2->axis == 14) && (tree1->axis == 18 || tree2->axis == 18)) return NULL; /* fast check root nodes for collision before doing big splitting + traversal */ if (!tree_overlap(tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf], min_axis(tree1->start_axis, tree2->start_axis), min_axis(tree1->stop_axis, tree2->stop_axis))) { return NULL; } data = MEM_callocN(sizeof(BVHOverlapData *) * tree1->tree_type, "BVHOverlapData_star"); for (j = 0; j < tree1->tree_type; j++) { data[j] = (BVHOverlapData *)MEM_callocN(sizeof(BVHOverlapData), "BVHOverlapData"); /* init BVHOverlapData */ data[j]->overlap = (BVHTreeOverlap *)malloc(sizeof(BVHTreeOverlap) * max_ii(tree1->totleaf, tree2->totleaf)); data[j]->tree1 = tree1; data[j]->tree2 = tree2; data[j]->max_overlap = max_ii(tree1->totleaf, tree2->totleaf); data[j]->i = 0; data[j]->start_axis = min_axis(tree1->start_axis, tree2->start_axis); data[j]->stop_axis = min_axis(tree1->stop_axis, tree2->stop_axis); } #pragma omp parallel for private(j) schedule(static) for (j = 0; j < MIN2(tree1->tree_type, tree1->nodes[tree1->totleaf]->totnode); j++) { traverse(data[j], tree1->nodes[tree1->totleaf]->children[j], tree2->nodes[tree2->totleaf]); } for (j = 0; j < tree1->tree_type; j++) total += data[j]->i; to = overlap = (BVHTreeOverlap *)MEM_callocN(sizeof(BVHTreeOverlap) * total, "BVHTreeOverlap"); for (j = 0; j < tree1->tree_type; j++) { memcpy(to, data[j]->overlap, data[j]->i * sizeof(BVHTreeOverlap)); to += data[j]->i; } for (j = 0; j < tree1->tree_type; j++) { free(data[j]->overlap); MEM_freeN(data[j]); } MEM_freeN(data); (*result) = total; return overlap; }
void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, void *data) { const bool do_invert = this->m_do_subtract; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); int bufferwidth = inputBuffer->getWidth(); int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; rcti &rect = *inputBuffer->getRect(); int xmin = max_ii(x - m_filtersize, rect.xmin); int xmax = min_ii(x + m_filtersize + 1, rect.xmax); int ymin = max_ii(y, rect.ymin); /* *** this is the main part which is different to 'GaussianXBlurOperation' *** */ int step = getStep(); int offsetadd = getOffsetAdd(); int bufferindex = ((xmin - bufferstartx) * 4) + ((ymin - bufferstarty) * 4 * bufferwidth); /* gauss */ float alpha_accum = 0.0f; float multiplier_accum = 0.0f; /* dilate */ float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */ float distfacinv_max = 1.0f; /* 0 to 1 */ for (int nx = xmin; nx < xmax; nx += step) { const int index = (nx - x) + this->m_filtersize; float value = finv_test(buffer[bufferindex], do_invert); float multiplier; /* gauss */ { multiplier = this->m_gausstab[index]; alpha_accum += value * multiplier; multiplier_accum += multiplier; } /* dilate - find most extreme color */ if (value > value_max) { multiplier = this->m_distbuf_inv[index]; value *= multiplier; if (value > value_max) { value_max = value; distfacinv_max = multiplier; } } bufferindex += offsetadd; } /* blend between the max value and gauss blue - gives nice feather */ const float value_blur = alpha_accum / multiplier_accum; const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max)); output[0] = finv_test(value_final, do_invert); }
static void render_view3d_do(RenderEngine *engine, const bContext *C) { wmJob *wm_job; RenderPreview *rp; Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); int width = ar->winx, height = ar->winy; int divider = 1; int resolution_threshold = scene->r.preview_start_resolution * scene->r.preview_start_resolution; if (CTX_wm_window(C) == NULL) return; if (!render_view3d_flag_changed(engine, C)) return; wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), CTX_wm_region(C), "Render Preview", WM_JOB_EXCL_RENDER, WM_JOB_TYPE_RENDER_PREVIEW); rp = MEM_callocN(sizeof(RenderPreview), "render preview"); rp->job = wm_job; while (width * height > resolution_threshold) { width = max_ii(1, width / 2); height = max_ii(1, height / 2); divider *= 2; } /* customdata for preview thread */ rp->scene = scene; rp->engine = engine; rp->sa = CTX_wm_area(C); rp->ar = CTX_wm_region(C); rp->v3d = rp->sa->spacedata.first; rp->rv3d = CTX_wm_region_view3d(C); rp->bmain = CTX_data_main(C); rp->resolution_divider = divider; rp->start_resolution_divider = divider; rp->has_freestyle = (scene->r.mode & R_EDGE_FRS) != 0; copy_m4_m4(rp->viewmat, rp->rv3d->viewmat); /* clear info text */ engine->text[0] = '\0'; /* setup job */ WM_jobs_customdata_set(wm_job, rp, render_view3d_free); WM_jobs_timer(wm_job, 0.1, NC_SPACE | ND_SPACE_VIEW3D, NC_SPACE | ND_SPACE_VIEW3D); WM_jobs_callbacks(wm_job, render_view3d_startjob, NULL, NULL, NULL); WM_jobs_start(CTX_wm_manager(C), wm_job); engine->flag &= ~RE_ENGINE_DO_UPDATE; }
static int dopesheet_view_all_exec(bContext *C, wmOperator *UNUSED(op)) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); View2D *v2d = &ar->v2d; MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; MovieTrackingDopesheetChannel *channel; int frame_min = INT_MAX, frame_max = INT_MIN; for (channel = dopesheet->channels.first; channel; channel = channel->next) { frame_min = min_ii(frame_min, channel->segments[0]); frame_max = max_ii(frame_max, channel->segments[channel->tot_segment]); } if (frame_min < frame_max) { float extra; v2d->cur.xmin = frame_min; v2d->cur.xmax = frame_max; /* we need an extra "buffer" factor on either side so that the endpoints are visible */ extra = 0.01f * BLI_rctf_size_x(&v2d->cur); v2d->cur.xmin -= extra; v2d->cur.xmax += extra; ED_region_tag_redraw(ar); } return OPERATOR_FINISHED; }
static void rna_KeyingSet_active_ksPath_index_range(PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax) { KeyingSet *ks = (KeyingSet *)ptr->data; *min = 0; *max = max_ii(0, BLI_countlist(&ks->paths) - 1); }
static void rna_render_slots_active_index_range( PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) { Image *image = (Image *)ptr->id.data; *min = 0; *max = max_ii(0, BLI_listbase_count(&image->renderslots) - 1); }
/* draw the contents of the sequencer strips view */ static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar) { Scene *scene = CTX_data_scene(C); View2D *v2d = &ar->v2d; Sequence *last_seq = BKE_sequencer_active_get(scene); int sel = 0, j; float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); /* loop through twice, first unselected, then selected */ for (j = 0; j < 2; j++) { Sequence *seq; int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */ /* loop through strips, checking for those that are visible */ for (seq = ed->seqbasep->first; seq; seq = seq->next) { /* boundbox and selection tests for NOT drawing the strip... */ if ((seq->flag & SELECT) != sel) continue; else if (seq == last_seq) continue; else if (min_ii(seq->startdisp, seq->start) > v2d->cur.xmax) continue; else if (max_ii(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue; else if (seq->machine + 1.0f < v2d->cur.ymin) continue; else if (seq->machine > v2d->cur.ymax) continue; /* strip passed all tests unscathed... so draw it now */ draw_seq_strip(scene, ar, seq, outline_tint, pixelx); } /* draw selected next time round */ sel = SELECT; } /* draw the last selected last (i.e. 'active' in other parts of Blender), removes some overlapping error */ if (last_seq) draw_seq_strip(scene, ar, last_seq, 120, pixelx); }
static void irradiance_pool_size_get(int visibility_size, int total_samples, int r_size[3]) { /* Compute how many irradiance samples we can store per visibility sample. */ int irr_per_vis = (visibility_size / IRRADIANCE_SAMPLE_SIZE_X) * (visibility_size / IRRADIANCE_SAMPLE_SIZE_Y); /* The irradiance itself take one layer, hence the +1 */ int layer_ct = MIN2(irr_per_vis + 1, IRRADIANCE_MAX_POOL_LAYER); int texel_ct = (int)ceilf((float)total_samples / (float)(layer_ct - 1)); r_size[0] = visibility_size * max_ii(1, min_ii(texel_ct, (IRRADIANCE_MAX_POOL_SIZE / visibility_size))); r_size[1] = visibility_size * max_ii(1, (texel_ct / (IRRADIANCE_MAX_POOL_SIZE / visibility_size))); r_size[2] = layer_ct; }
static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *result, int steps) { ClothSolverResult *sres = clmd->solver_result; if (sres->status) { /* already initialized ? */ /* error only makes sense for successful iterations */ if (result->status == BPH_SOLVER_SUCCESS) { sres->min_error = min_ff(sres->min_error, result->error); sres->max_error = max_ff(sres->max_error, result->error); sres->avg_error += result->error / (float)steps; } sres->min_iterations = min_ii(sres->min_iterations, result->iterations); sres->max_iterations = max_ii(sres->max_iterations, result->iterations); sres->avg_iterations += (float)result->iterations / (float)steps; } else { /* error only makes sense for successful iterations */ if (result->status == BPH_SOLVER_SUCCESS) { sres->min_error = sres->max_error = result->error; sres->avg_error += result->error / (float)steps; } sres->min_iterations = sres->max_iterations = result->iterations; sres->avg_iterations += (float)result->iterations / (float)steps; } sres->status |= result->status; }
static int create_primitive_from_points(bContext *C, wmOperator *op, const float (*points)[2], int num_points, char handle_type) { ScrArea *sa = CTX_wm_area(C); Scene *scene = CTX_data_scene(C); Mask *mask; MaskLayer *mask_layer; MaskSpline *new_spline; float scale, location[2], frame_size[2]; int i, width, height; int size = RNA_float_get(op->ptr, "size"); ED_mask_get_size(sa, &width, &height); scale = (float)size / max_ii(width, height); /* Get location in mask space. */ frame_size[0] = width; frame_size[1] = height; RNA_float_get_array(op->ptr, "location", location); location[0] /= width; location[1] /= height; BKE_mask_coord_from_frame(location, location, frame_size); /* Make it so new primitive is centered to mouse location. */ location[0] -= 0.5f * scale; location[1] -= 0.5f * scale; mask_layer = ED_mask_layer_ensure(C); mask = CTX_data_edit_mask(C); ED_mask_select_toggle_all(mask, SEL_DESELECT); new_spline = BKE_mask_spline_add(mask_layer); new_spline->flag = MASK_SPLINE_CYCLIC | SELECT; new_spline->tot_point = num_points; new_spline->points = MEM_recallocN(new_spline->points, sizeof(MaskSplinePoint) * new_spline->tot_point); mask_layer->act_spline = new_spline; mask_layer->act_point = NULL; for (i = 0; i < num_points; i++) { MaskSplinePoint *new_point = &new_spline->points[i]; copy_v2_v2(new_point->bezt.vec[1], points[i]); mul_v2_fl(new_point->bezt.vec[1], scale); add_v2_v2(new_point->bezt.vec[1], location); new_point->bezt.h1 = handle_type; new_point->bezt.h2 = handle_type; BKE_mask_point_select_set(new_point, true); } WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); /* TODO: only update this spline */ BKE_mask_update_display(mask, CFRA); return OPERATOR_FINISHED; }
static void rna_BoidSettings_active_boid_state_index_range(PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) { BoidSettings *boids = (BoidSettings *)ptr->data; *min = 0; *max = max_ii(0, BLI_countlist(&boids->states) - 1); }
static void rna_BoidState_active_boid_rule_index_range(PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) { BoidState *state = (BoidState *)ptr->data; *min = 0; *max = max_ii(0, BLI_countlist(&state->rules) - 1); }
static void colorband_init_from_table_rgba_simple( ColorBand *coba, const float (*array)[4], const int array_len) { /* No Re-sample, just de-duplicate. */ const float eps = (1.0f / 255.0f) + 1e-6f; BLI_assert(array_len < MAXCOLORBAND); int stops = min_ii(MAXCOLORBAND, array_len); if (stops) { const float step_size = 1.0f / (float)max_ii(stops - 1, 1); int i_curr = -1; for (int i_step = 0; i_step < stops; i_step++) { if ((i_curr != -1) && compare_v4v4(&coba->data[i_curr].r, array[i_step], eps)) { continue; } i_curr += 1; copy_v4_v4(&coba->data[i_curr].r, array[i_step]); coba->data[i_curr].pos = i_step * step_size; coba->data[i_curr].cur = i_curr; } coba->tot = i_curr + 1; coba->cur = 0; } else { /* coba is empty, set 1 black stop */ zero_v3(&coba->data[0].r); coba->data[0].a = 1.0f; coba->cur = 0; coba->tot = 1; } }
static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy) { unsigned char *display_buffer; unsigned int *rect; int dx, dy, sx, sy, x, y; void *cache_handle; /* verify valid values, just leave this a while */ if (ima->xrep < 1) return; if (ima->yrep < 1) return; if (ima->flag & IMA_VIEW_AS_RENDER) display_buffer = IMB_display_buffer_acquire(ibuf, &scene->view_settings, &scene->display_settings, &cache_handle); else display_buffer = IMB_display_buffer_acquire(ibuf, NULL, &scene->display_settings, &cache_handle); if (!display_buffer) return; glPixelZoom(zoomx, zoomy); if (sima->curtile >= ima->xrep * ima->yrep) sima->curtile = ima->xrep * ima->yrep - 1; /* retrieve part of image buffer */ dx = max_ii(ibuf->x / ima->xrep, 1); dy = max_ii(ibuf->y / ima->yrep, 1); sx = (sima->curtile % ima->xrep) * dx; sy = (sima->curtile / ima->xrep) * dy; rect = get_part_from_buffer((unsigned int *)display_buffer, ibuf->x, sx, sy, sx + dx, sy + dy); /* draw repeated */ for (sy = 0; sy + dy <= ibuf->y; sy += dy) { for (sx = 0; sx + dx <= ibuf->x; sx += dx) { UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y); glaDrawPixelsSafe(x, y, dx, dy, dx, GL_RGBA, GL_UNSIGNED_BYTE, rect); } } glPixelZoom(1.0f, 1.0f); IMB_display_buffer_release(cache_handle); MEM_freeN(rect); }
static void rna_Action_active_pose_marker_index_range(PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) { bAction *act = (bAction *)ptr->data; *min = 0; *max = max_ii(0, BLI_countlist(&act->markers) - 1); }
static int console_copy_exec(bContext *C, wmOperator *UNUSED(op)) { SpaceConsole *sc = CTX_wm_space_console(C); DynStr *buf_dyn; char *buf_str; ConsoleLine *cl; int sel[2]; int offset = 0; ConsoleLine cl_dummy = {NULL}; if (sc->sel_start == sc->sel_end) return OPERATOR_CANCELLED; console_scrollback_prompt_begin(sc, &cl_dummy); for (cl = sc->scrollback.first; cl; cl = cl->next) { offset += cl->len + 1; } if (offset == 0) { console_scrollback_prompt_end(sc, &cl_dummy); return OPERATOR_CANCELLED; } buf_dyn = BLI_dynstr_new(); offset -= 1; sel[0] = offset - sc->sel_end; sel[1] = offset - sc->sel_start; for (cl = sc->scrollback.first; cl; cl = cl->next) { if (sel[0] <= cl->len && sel[1] >= 0) { int sta = max_ii(sel[0], 0); int end = min_ii(sel[1], cl->len); if (BLI_dynstr_get_len(buf_dyn)) BLI_dynstr_append(buf_dyn, "\n"); BLI_dynstr_nappend(buf_dyn, cl->line + sta, end - sta); } sel[0] -= cl->len + 1; sel[1] -= cl->len + 1; } buf_str = BLI_dynstr_get_cstring(buf_dyn); BLI_dynstr_free(buf_dyn); WM_clipboard_text_set(buf_str, 0); MEM_freeN(buf_str); console_scrollback_prompt_end(sc, &cl_dummy); return OPERATOR_FINISHED; }
static void rna_GPencil_active_layer_index_range(PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax) { bGPdata *gpd = (bGPdata *)ptr->id.data; *min = 0; *max = max_ii(0, BLI_listbase_count(&gpd->layers) - 1); *softmin = *min; *softmax = *max; }
static void rna_Mask_layer_active_index_range(PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax) { Mask *mask = (Mask *)ptr->id.data; *min = 0; *max = max_ii(0, mask->masklay_tot - 1); *softmin = *min; *softmax = *max; }
MINLINE void blend_color_sub_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]) { if (src2[3] != 0) { /* straight sub operation */ const int t = src2[3]; int tmp[3]; tmp[0] = (src1[0] * 255) - (src2[0] * t); tmp[1] = (src1[1] * 255) - (src2[1] * t); tmp[2] = (src1[2] * 255) - (src2[2] * t); dst[0] = (unsigned char)max_ii(divide_round_i(tmp[0], 255), 0); dst[1] = (unsigned char)max_ii(divide_round_i(tmp[1], 255), 0); dst[2] = (unsigned char)max_ii(divide_round_i(tmp[2], 255), 0); dst[3] = src1[3]; } else { /* no op */ copy_v4_v4_uchar(dst, src1); } }
/* draw backdrop of the sequencer strips view */ static void draw_seq_backdrop(View2D *v2d) { int i; /* darker gray overlay over the view backdrop */ UI_ThemeColorShade(TH_BACK, -20); glRectf(v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); /* Alternating horizontal stripes */ i = max_ii(1, ((int)v2d->cur.ymin) - 1); glBegin(GL_QUADS); while (i < v2d->cur.ymax) { if (((int)i) & 1) UI_ThemeColorShade(TH_BACK, -15); else UI_ThemeColorShade(TH_BACK, -25); glVertex2f(v2d->cur.xmax, i); glVertex2f(v2d->cur.xmin, i); glVertex2f(v2d->cur.xmin, i + 1); glVertex2f(v2d->cur.xmax, i + 1); i += 1.0; } glEnd(); /* Darker lines separating the horizontal bands */ i = max_ii(1, ((int)v2d->cur.ymin) - 1); UI_ThemeColor(TH_GRID); glBegin(GL_LINES); while (i < v2d->cur.ymax) { glVertex2f(v2d->cur.xmax, i); glVertex2f(v2d->cur.xmin, i); i += 1.0; } glEnd(); }
MINLINE void blend_color_lighten_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]) { if (src2[3] != 0) { /* straight lighten operation */ const int t = src2[3]; const int mt = 255 - t; int tmp[3]; tmp[0] = (mt * src1[0]) + (t * max_ii(src1[0], src2[0])); tmp[1] = (mt * src1[1]) + (t * max_ii(src1[1], src2[1])); tmp[2] = (mt * src1[2]) + (t * max_ii(src1[2], src2[2])); dst[0] = (unsigned char)divide_round_i(tmp[0], 255); dst[1] = (unsigned char)divide_round_i(tmp[1], 255); dst[2] = (unsigned char)divide_round_i(tmp[2], 255); dst[3] = src1[3]; } else { /* no op */ copy_v4_v4_uchar(dst, src1); } }
void GaussianXBlurOperation::executePixel(float output[4], int x, int y, void *data) { float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float multiplier_accum = 0.0f; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); int bufferwidth = inputBuffer->getWidth(); int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; rcti &rect = *inputBuffer->getRect(); int xmin = max_ii(x - m_filtersize, rect.xmin); int xmax = min_ii(x + m_filtersize + 1, rect.xmax); int ymin = max_ii(y, rect.ymin); int step = getStep(); int offsetadd = getOffsetAdd(); int bufferindex = ((xmin - bufferstartx) * 4) + ((ymin - bufferstarty) * 4 * bufferwidth); #ifdef __SSE2__ __m128 accum_r = _mm_load_ps(color_accum); for (int nx = xmin, index = (xmin - x) + this->m_filtersize; nx < xmax; nx += step, index += step) { __m128 reg_a = _mm_load_ps(&buffer[bufferindex]); reg_a = _mm_mul_ps(reg_a, this->m_gausstab_sse[index]); accum_r = _mm_add_ps(accum_r, reg_a); multiplier_accum += this->m_gausstab[index]; bufferindex += offsetadd; } _mm_store_ps(color_accum, accum_r); #else for (int nx = xmin, index = (xmin - x) + this->m_filtersize; nx < xmax; nx += step, index += step) { const float multiplier = this->m_gausstab[index]; madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier); multiplier_accum += multiplier; bufferindex += offsetadd; } #endif mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum); }
static void console_draw_sel(const char *str, const int sel[2], const int xy[2], const int str_len_draw, int cwidth, int lheight, const unsigned char bg_sel[4]) { if (sel[0] <= str_len_draw && sel[1] >= 0) { const int sta = txt_utf8_offset_to_column(str, max_ii(sel[0], 0)); const int end = txt_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ubv(bg_sel); glRecti(xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2); glDisable(GL_BLEND); } }
MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]) { if (src2[3] != 0) { /* straight so just modify alpha channel */ const int t = src2[3]; dst[0] = src1[0]; dst[1] = src1[1]; dst[2] = src1[2]; dst[3] = (unsigned char)max_ii(src1[3] - divide_round_i(t * src2[3], 255), 0); } else { /* no op */ copy_v4_v4_uchar(dst, src1); } }
int BKE_render_num_threads(const RenderData *rd) { int threads; /* override set from command line? */ threads = BLI_system_num_threads_override_get(); if (threads > 0) return threads; /* fixed number of threads specified in scene? */ if (rd->mode & R_FIXED_THREADS) threads = rd->threads; else threads = BLI_system_thread_count(); return max_ii(threads, 1); }
static void console_draw_sel(const int sel[2], const int xy[2], const int str_len_draw, int cwidth, int lheight) { if (sel[0] <= str_len_draw && sel[1] >= 0) { const int sta = max_ii(sel[0], 0); const int end = min_ii(sel[1], str_len_draw); glEnable(GL_POLYGON_STIPPLE); glPolygonStipple(stipple_halftone); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255, 255, 255, 48); glRecti(xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2); glDisable(GL_POLYGON_STIPPLE); glDisable(GL_BLEND); } }
static int clip_set_scene_frames_exec(bContext *C, wmOperator *UNUSED(op)) { MovieClip *clip = CTX_data_edit_movieclip(C); Scene *scene = CTX_data_scene(C); int clip_length; if (ELEM(NULL, scene, clip)) return OPERATOR_CANCELLED; clip_length = BKE_movieclip_get_duration(clip); scene->r.sfra = clip->start_frame; scene->r.efra = scene->r.sfra + clip_length - 1; scene->r.efra = max_ii(scene->r.sfra, scene->r.efra); WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; }