static void draw_filled_lasso(wmWindow *win, wmGesture *gt) { const short *lasso = (short *)gt->customdata; const int tot = gt->points; int (*moves)[2] = MEM_mallocN(sizeof(*moves) * (tot + 1), __func__); int i; rcti rect; rcti rect_win; for (i = 0; i < tot; i++, lasso += 2) { moves[i][0] = lasso[0]; moves[i][1] = lasso[1]; } BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot); wm_subwindow_rect_get(win, gt->swinid, &rect_win); BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin); BLI_rcti_isect(&rect_win, &rect, &rect); BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin); /* highly unlikely this will fail, but could crash if (tot == 0) */ if (BLI_rcti_is_empty(&rect) == false) { const int w = BLI_rcti_size_x(&rect); const int h = BLI_rcti_size_y(&rect); unsigned int *pixel_buf = MEM_callocN(sizeof(*pixel_buf) * w * h, __func__); struct LassoFillData lasso_fill_data = {pixel_buf, w}; fill_poly_v2i_n( rect.xmin, rect.ymin, rect.xmax, rect.ymax, (const int (*)[2])moves, tot, draw_filled_lasso_px_cb, &lasso_fill_data); glEnable(GL_BLEND); // glColor4f(1.0, 1.0, 1.0, 0.05); glRasterPos2f(rect.xmin, rect.ymin); glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buf); glDisable(GL_BLEND); MEM_freeN(pixel_buf); } MEM_freeN(moves); }
float MemoryBuffer::getMaximumValue(rcti *rect) { rcti rect_clamp; /* first clamp the rect by the bounds or we get un-initialized values */ BLI_rcti_isect(rect, &this->m_rect, &rect_clamp); if (!BLI_rcti_is_empty(&rect_clamp)) { MemoryBuffer *temp = new MemoryBuffer(NULL, &rect_clamp); temp->copyContentFrom(this); float result = temp->getMaximumValue(); delete temp; return result; } else { BLI_assert(0); return 0.0f; } }