void BKE_texture_get_value_ex( const Scene *scene, Tex *texture, float *tex_co, TexResult *texres, struct ImagePool *pool, bool use_color_management) { int result_type; bool do_color_manage = false; if (scene && use_color_management) { do_color_manage = BKE_scene_check_color_management_enabled(scene); } /* no node textures for now */ result_type = multitex_ext_safe(texture, tex_co, texres, pool, do_color_manage, false); /* if the texture gave an RGB value, we assume it didn't give a valid * intensity, since this is in the context of modifiers don't use perceptual color conversion. * if the texture didn't give an RGB value, copy the intensity across */ if (result_type & TEX_RGB) { texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); } else { copy_v3_fl(&texres->tr, texres->tin); } }
static void ApplySnapResize(TransInfo *t, float vec[3]) { float point[3]; getSnapPoint(t, point); float dist = ResizeBetween(t, t->tsnap.snapTarget, point); copy_v3_fl(vec, dist); }
void initNumInput(NumInput *n) { n->unit_sys = USER_UNIT_NONE; n->unit_type[0] = n->unit_type[1] = n->unit_type[2] = B_UNIT_NONE; n->idx = 0; n->idx_max = 0; n->flag = 0; n->val_flag[0] = n->val_flag[1] = n->val_flag[2] = 0; zero_v3(n->val_org); zero_v3(n->val); n->str[0] = '\0'; n->str_cur = 0; copy_v3_fl(n->val_inc, 1.0f); }
void get_texture_value(Tex *texture, float *tex_co, TexResult *texres) { int result_type; /* no node textures for now */ result_type = multitex_ext_safe(texture, tex_co, texres, NULL); /* if the texture gave an RGB value, we assume it didn't give a valid * intensity, since this is in the context of modifiers don't use perceptual color conversion. * if the texture didn't give an RGB value, copy the intensity across */ if (result_type & TEX_RGB) { texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); } else { copy_v3_fl(&texres->tr, texres->tin); } }
void ColorBalanceNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const { bNode *node = this->getbNode(); NodeColorBalance *n = (NodeColorBalance *)node->storage; NodeInput *inputSocket = this->getInputSocket(0); NodeInput *inputImageSocket = this->getInputSocket(1); NodeOutput *outputSocket = this->getOutputSocket(0); NodeOperation *operation; if (node->custom1 == 0) { ColorBalanceLGGOperation *operationLGG = new ColorBalanceLGGOperation(); float lift_lgg[3], gamma_inv[3]; for (int c = 0; c < 3; c++) { lift_lgg[c] = 2.0f - n->lift[c]; gamma_inv[c] = (n->gamma[c] != 0.0f) ? 1.0f / n->gamma[c] : 1000000.0f; } operationLGG->setGain(n->gain); operationLGG->setLift(lift_lgg); operationLGG->setGammaInv(gamma_inv); operation = operationLGG; } else { ColorBalanceASCCDLOperation *operationCDL = new ColorBalanceASCCDLOperation(); float offset[3]; copy_v3_fl(offset, n->offset_basis); add_v3_v3(offset, n->offset); operationCDL->setOffset(offset); operationCDL->setPower(n->power); operationCDL->setSlope(n->slope); operation = operationCDL; } converter.addOperation(operation); converter.mapInputSocket(inputSocket, operation->getInputSocket(0)); converter.mapInputSocket(inputImageSocket, operation->getInputSocket(1)); converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0)); }
static void gizmo_primitive_draw_intern(wmGizmo *gz, const bool UNUSED(select), const bool highlight) { float color_inner[4], color_outer[4]; float matrix_final[4][4]; const int draw_style = RNA_enum_get(gz->ptr, "draw_style"); gizmo_color_get(gz, highlight, color_outer); copy_v4_v4(color_inner, color_outer); color_inner[3] *= 0.5f; WM_gizmo_calc_matrix_final(gz, matrix_final); GPU_matrix_push(); GPU_matrix_mul(matrix_final); GPU_blend(true); gizmo_primitive_draw_geom(color_inner, color_outer, draw_style); GPU_blend(false); GPU_matrix_pop(); if (gz->interaction_data) { GizmoInteraction *inter = gz->interaction_data; copy_v4_fl(color_inner, 0.5f); copy_v3_fl(color_outer, 0.5f); color_outer[3] = 0.8f; GPU_matrix_push(); GPU_matrix_mul(inter->init_matrix_final); GPU_blend(true); gizmo_primitive_draw_geom(color_inner, color_outer, draw_style); GPU_blend(false); GPU_matrix_pop(); } }
static void whiteBalance_init_data(SequenceModifierData *smd) { WhiteBalanceModifierData *cbmd = (WhiteBalanceModifierData *) smd; copy_v3_fl(cbmd->white_value, 1.0f); }
static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(quad), int x, int y, float UNUSED(u), float UNUSED(v), float *tvn, float *ttang) { BakeShade *bs = handle; ShadeSample *ssamp = &bs->ssamp; ShadeResult shr; VlakRen *vlr = shi->vlr; shade_input_init_material(shi); if (bs->type == RE_BAKE_AO) { ambient_occlusion(shi); if (R.r.bake_flag & R_BAKE_NORMALIZE) { copy_v3_v3(shr.combined, shi->ao); } else { zero_v3(shr.combined); environment_lighting_apply(shi, &shr); } } else { if (bs->type == RE_BAKE_SHADOW) /* Why do shadows set the color anyhow?, ignore material color for baking */ shi->r = shi->g = shi->b = 1.0f; shade_input_set_shade_texco(shi); /* only do AO for a full bake (and obviously AO bakes) * AO for light bakes is a leftover and might not be needed */ if (ELEM3(bs->type, RE_BAKE_ALL, RE_BAKE_AO, RE_BAKE_LIGHT)) shade_samples_do_AO(ssamp); if (shi->mat->nodetree && shi->mat->use_nodes) { ntreeShaderExecTree(shi->mat->nodetree, shi, &shr); shi->mat = vlr->mat; /* shi->mat is being set in nodetree */ } else shade_material_loop(shi, &shr); if (bs->type == RE_BAKE_NORMALS) { float nor[3]; copy_v3_v3(nor, shi->vn); if (R.r.bake_normal_space == R_BAKE_SPACE_CAMERA) { /* pass */ } else if (R.r.bake_normal_space == R_BAKE_SPACE_TANGENT) { float mat[3][3], imat[3][3]; /* bitangent */ if (tvn && ttang) { copy_v3_v3(mat[0], ttang); cross_v3_v3v3(mat[1], tvn, ttang); mul_v3_fl(mat[1], ttang[3]); copy_v3_v3(mat[2], tvn); } else { copy_v3_v3(mat[0], shi->nmaptang); cross_v3_v3v3(mat[1], shi->nmapnorm, shi->nmaptang); mul_v3_fl(mat[1], shi->nmaptang[3]); copy_v3_v3(mat[2], shi->nmapnorm); } invert_m3_m3(imat, mat); mul_m3_v3(imat, nor); } else if (R.r.bake_normal_space == R_BAKE_SPACE_OBJECT) mul_mat3_m4_v3(ob->imat_ren, nor); /* ob->imat_ren includes viewinv! */ else if (R.r.bake_normal_space == R_BAKE_SPACE_WORLD) mul_mat3_m4_v3(R.viewinv, nor); normalize_v3(nor); /* in case object has scaling */ /* The invert of the red channel is to make * the normal map compliant with the outside world. * It needs to be done because in Blender * the normal used in the renderer points inward. It is generated * this way in calc_vertexnormals(). Should this ever change * this negate must be removed. */ shr.combined[0] = (-nor[0]) / 2.0f + 0.5f; shr.combined[1] = nor[1] / 2.0f + 0.5f; shr.combined[2] = nor[2] / 2.0f + 0.5f; } else if (bs->type == RE_BAKE_TEXTURE) { copy_v3_v3(shr.combined, &shi->r); shr.alpha = shi->alpha; } else if (bs->type == RE_BAKE_SHADOW) { copy_v3_v3(shr.combined, shr.shad); shr.alpha = shi->alpha; } else if (bs->type == RE_BAKE_SPEC_COLOR) { copy_v3_v3(shr.combined, &shi->specr); shr.alpha = 1.0f; } else if (bs->type == RE_BAKE_SPEC_INTENSITY) { copy_v3_fl(shr.combined, shi->spec); shr.alpha = 1.0f; } else if (bs->type == RE_BAKE_MIRROR_COLOR) { copy_v3_v3(shr.combined, &shi->mirr); shr.alpha = 1.0f; } else if (bs->type == RE_BAKE_MIRROR_INTENSITY) { copy_v3_fl(shr.combined, shi->ray_mirror); shr.alpha = 1.0f; } else if (bs->type == RE_BAKE_ALPHA) { copy_v3_fl(shr.combined, shi->alpha); shr.alpha = 1.0f; } else if (bs->type == RE_BAKE_EMIT) { copy_v3_fl(shr.combined, shi->emit); shr.alpha = 1.0f; } else if (bs->type == RE_BAKE_VERTEX_COLORS) { copy_v3_v3(shr.combined, shi->vcol); shr.alpha = shi->vcol[3]; } } if (bs->rect_float && !bs->vcol) { float *col = bs->rect_float + 4 * (bs->rectx * y + x); copy_v3_v3(col, shr.combined); if (bs->type == RE_BAKE_ALL || bs->type == RE_BAKE_TEXTURE || bs->type == RE_BAKE_VERTEX_COLORS) { col[3] = shr.alpha; } else { col[3] = 1.0; } } else { /* Target is char (LDR). */ unsigned char col[4]; if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) { float rgb[3]; copy_v3_v3(rgb, shr.combined); if (R.scene_color_manage) { /* Vertex colors have no way to specify color space, so they * default to sRGB. */ if (!bs->vcol) IMB_colormanagement_scene_linear_to_colorspace_v3(rgb, bs->rect_colorspace); else linearrgb_to_srgb_v3_v3(rgb, rgb); } rgb_float_to_uchar(col, rgb); } else { rgb_float_to_uchar(col, shr.combined); } if (ELEM3(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE, RE_BAKE_VERTEX_COLORS)) { col[3] = FTOCHAR(shr.alpha); } else { col[3] = 255; } if (bs->vcol) { /* Vertex color baking. Vcol has no useful alpha channel (it exists * but is used only for vertex painting). */ bs->vcol->r = col[0]; bs->vcol->g = col[1]; bs->vcol->b = col[2]; } else { unsigned char *imcol = (unsigned char *)(bs->rect + bs->rectx * y + x); copy_v4_v4_char((char *)imcol, (char *)col); } } if (bs->rect_mask) { bs->rect_mask[bs->rectx * y + x] = FILTER_MASK_USED; } if (bs->do_update) { *bs->do_update = true; } }
/** * Update defaults in startup.blend, without having to save and embed the file. * This function can be emptied each time the startup.blend is updated. */ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) { /* For all builtin templates shipped with Blender. */ const bool builtin_template = (!app_template || STR_ELEM(app_template, "2D_Animation", "Sculpting", "VFX", "Video_Editing")); /* For all startup.blend files. */ for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { /* Remove all stored panels, we want to use defaults * (order, open/closed) as defined by UI code here! */ BKE_area_region_panels_free(&ar->panels); /* some toolbars have been saved as initialized, * we don't want them to have odd zoom-level or scrolling set, see: T47047 */ if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) { ar->v2d.flag &= ~V2D_IS_INITIALISED; } } for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { switch (sl->spacetype) { case SPACE_VIEW3D: { View3D *v3d = (View3D *)sl; v3d->overlay.texture_paint_mode_opacity = 1.0f; v3d->overlay.weight_paint_mode_opacity = 1.0f; v3d->overlay.vertex_paint_mode_opacity = 1.0f; /* grease pencil settings */ v3d->vertex_opacity = 1.0f; v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES; /* Skip startups that use the viewport color by default. */ if (v3d->shading.background_type != V3D_SHADING_BACKGROUND_VIEWPORT) { copy_v3_fl(v3d->shading.background_color, 0.05f); } break; } case SPACE_FILE: { SpaceFile *sfile = (SpaceFile *)sl; if (sfile->params) { const char *dir_default = BKE_appdir_folder_default(); if (dir_default) { STRNCPY(sfile->params->dir, dir_default); sfile->params->file[0] = '\0'; } } break; } } } } } if (builtin_template) { /* Name all screens by their workspaces (avoids 'Default.###' names). */ /* Default only has one window. */ wmWindow *win = ((wmWindowManager *)bmain->wm.first)->windows.first; for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook, workspace); bScreen *screen = layout->screen; BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2); BLI_libblock_ensure_unique_name(bmain, screen->id.name); } } if (app_template == NULL) { /* 'UV Editing' should use UV mode. */ bScreen *screen = BLI_findstring(&bmain->screens, "UV Editing", offsetof(ID, name) + 2); for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; if (sima->mode == SI_MODE_VIEW) { sima->mode = SI_MODE_UV; } } } } } /* For 2D animation template. */ if (app_template && STREQ(app_template, "2D_Animation")) { for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { const char *name = workspace->id.name + 2; if (STREQ(name, "Drawing")) { workspace->object_mode = OB_MODE_PAINT_GPENCIL; } } /* set object in drawing mode */ for (Object *object = bmain->objects.first; object; object = object->id.next) { if (object->type == OB_GPENCIL) { bGPdata *gpd = (bGPdata *)object->data; object->mode = OB_MODE_PAINT_GPENCIL; gpd->flag |= GP_DATA_STROKE_PAINTMODE; break; } } /* Be sure curfalloff and primitive are initializated */ for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; if (ts->gp_sculpt.cur_falloff == NULL) { ts->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff; curvemapping_initialize(gp_falloff_curve); curvemap_reset(gp_falloff_curve->cm, &gp_falloff_curve->clipr, CURVE_PRESET_GAUSS, CURVEMAP_SLOPE_POSITIVE); } if (ts->gp_sculpt.cur_primitive == NULL) { ts->gp_sculpt.cur_primitive = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive; curvemapping_initialize(gp_primitive_curve); curvemap_reset(gp_primitive_curve->cm, &gp_primitive_curve->clipr, CURVE_PRESET_BELL, CURVEMAP_SLOPE_POSITIVE); } } } if (builtin_template) { /* Clear all tools to use default options instead, ignore the tool saved in the file. */ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { while (!BLI_listbase_is_empty(&workspace->tools)) { BKE_workspace_tool_remove(workspace, workspace->tools.first); } } for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { if (sa->spacetype == SPACE_ACTION) { /* Show marker lines, hide channels and collapse summary in timelines. */ SpaceAction *saction = sa->spacedata.first; saction->flag |= SACTION_SHOW_MARKER_LINES; if (saction->mode == SACTCONT_TIMELINE) { saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED; for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_CHANNELS) { ar->flag |= RGN_FLAG_HIDDEN; } } } } else if (sa->spacetype == SPACE_GRAPH) { SpaceGraph *sipo = sa->spacedata.first; sipo->flag |= SIPO_MARKER_LINES; } else if (sa->spacetype == SPACE_NLA) { SpaceNla *snla = sa->spacedata.first; snla->flag |= SNLA_SHOW_MARKER_LINES; } else if (sa->spacetype == SPACE_TEXT) { /* Show syntax and line numbers in Script workspace text editor. */ SpaceText *stext = sa->spacedata.first; stext->showsyntax = true; stext->showlinenrs = true; } else if (sa->spacetype == SPACE_VIEW3D) { /* Screen space cavity by default for faster performance. */ View3D *v3d = sa->spacedata.first; v3d->shading.cavity_type = V3D_SHADING_CAVITY_CURVATURE; } else if (sa->spacetype == SPACE_CLIP) { SpaceClip *sclip = sa->spacedata.first; sclip->around = V3D_AROUND_CENTER_MEDIAN; } } } /* Show toopbar for sculpt/paint modes. */ for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { bool show_tool_header = false; if (app_template == NULL) { if (STR_ELEM(screen->id.name + 2, "Sculpting", "Texture Paint")) { show_tool_header = true; } } else if (STREQ(app_template, "2D_Animation")) { if (STR_ELEM(screen->id.name + 2, "2D Animation", "2D Full Canvas")) { show_tool_header = true; } } else if (STREQ(app_template, "Sculpting")) { if (STR_ELEM(screen->id.name + 2, "Sculpting")) { show_tool_header = true; } } if (show_tool_header) { for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; for (ARegion *ar = regionbase->first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_TOOL_HEADER) { ar->flag &= ~(RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER); } } } } } } for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine)); scene->r.cfra = 1.0f; scene->r.displaymode = R_OUTPUT_WINDOW; if (app_template && STREQ(app_template, "Video_Editing")) { /* Filmic is too slow, use default until it is optimized. */ STRNCPY(scene->view_settings.view_transform, "Default"); STRNCPY(scene->view_settings.look, "None"); } else { /* AV Sync break physics sim caching, disable until that is fixed. */ scene->audio.flag &= ~AUDIO_SYNC; scene->flag &= ~SCE_FRAME_DROP; } /* Don't enable compositing nodes. */ if (scene->nodetree) { ntreeFreeNestedTree(scene->nodetree); MEM_freeN(scene->nodetree); scene->nodetree = NULL; scene->use_nodes = false; } /* Rename render layers. */ BKE_view_layer_rename(bmain, scene, scene->view_layers.first, "View Layer"); /* New EEVEE defaults. */ scene->eevee.bloom_intensity = 0.05f; scene->eevee.bloom_clamp = 0.0f; scene->eevee.motion_blur_shutter = 0.5f; } /* Rename light objects. */ rename_id_for_versioning(bmain, ID_OB, "Lamp", "Light"); rename_id_for_versioning(bmain, ID_LA, "Lamp", "Light"); for (Mesh *mesh = bmain->meshes.first; mesh; mesh = mesh->id.next) { /* Match default for new meshes. */ mesh->smoothresh = DEG2RADF(30); } } for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT; } } } } for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { copy_v3_v3(scene->display.light_direction, (float[3]){M_SQRT1_3, M_SQRT1_3, M_SQRT1_3}); copy_v2_fl2(scene->safe_areas.title, 0.1f, 0.05f); copy_v2_fl2(scene->safe_areas.action, 0.035f, 0.035f); }
static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { if (data && node->id) { ShadeInput *shi = ((ShaderCallData *)data)->shi; TexResult texres; bNodeSocket *sock_vector = node->inputs.first; float vec[3], nor[3] = {0.0f, 0.0f, 0.0f}; int retval; short which_output = node->custom1; short thread = shi->thread; /* out: value, color, normal */ /* we should find out if a normal as output is needed, for now we do all */ texres.nor = nor; texres.tr = texres.tg = texres.tb = 0.0f; /* don't use in[0]->hasinput, see material node for explanation */ if (sock_vector->link) { nodestack_get_vec(vec, SOCK_VECTOR, in[0]); if (in[0]->datatype == NS_OSA_VECTORS) { float *fp = in[0]->data; retval = multitex_nodes((Tex *)node->id, vec, fp, fp + 3, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); } else if (in[0]->datatype == NS_OSA_VALUES) { const float *fp = in[0]->data; float dxt[3], dyt[3]; dxt[0] = fp[0]; dxt[1] = dxt[2] = 0.0f; dyt[0] = fp[1]; dyt[1] = dyt[2] = 0.0f; retval = multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); } else retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); } else { copy_v3_v3(vec, shi->lo); retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); } /* stupid exception */ if ( ((Tex *)node->id)->type == TEX_STUCCI) { texres.tin = 0.5f + 0.7f * texres.nor[0]; CLAMP(texres.tin, 0.0f, 1.0f); } /* intensity and color need some handling */ if (texres.talpha) out[0]->vec[0] = texres.ta; else out[0]->vec[0] = texres.tin; if ((retval & TEX_RGB) == 0) { copy_v3_fl(out[1]->vec, out[0]->vec[0]); out[1]->vec[3] = 1.0f; } else { copy_v3_v3(out[1]->vec, &texres.tr); out[1]->vec[3] = 1.0f; } copy_v3_v3(out[2]->vec, nor); if (shi->do_preview) { BKE_node_preview_set_pixel(execdata->preview, out[1]->vec, shi->xs, shi->ys, shi->do_manage); } } }
static void scopes_update_cb(void *userdata, void *userdata_chunk, const int y, const int UNUSED(threadid)) { const ScopesUpdateData *data = userdata; Scopes *scopes = data->scopes; const ImBuf *ibuf = data->ibuf; struct ColormanageProcessor *cm_processor = data->cm_processor; const unsigned char *display_buffer = data->display_buffer; const int ycc_mode = data->ycc_mode; ScopesUpdateDataChunk *data_chunk = userdata_chunk; unsigned int *bin_lum = data_chunk->bin_lum; unsigned int *bin_r = data_chunk->bin_r; unsigned int *bin_g = data_chunk->bin_g; unsigned int *bin_b = data_chunk->bin_b; unsigned int *bin_a = data_chunk->bin_a; float *min = data_chunk->min; float *max = data_chunk->max; const float *rf = NULL; const unsigned char *rc = NULL; const int rows_per_sample_line = ibuf->y / scopes->sample_lines; const int savedlines = y / rows_per_sample_line; const bool do_sample_line = (savedlines < scopes->sample_lines) && (y % rows_per_sample_line) == 0; const bool is_float = (ibuf->rect_float != NULL); if (is_float) rf = ibuf->rect_float + ((size_t)y) * ibuf->x * ibuf->channels; else { rc = display_buffer + ((size_t)y) * ibuf->x * ibuf->channels; } for (int x = 0; x < ibuf->x; x++) { float rgba[4], ycc[3], luma; if (is_float) { switch (ibuf->channels) { case 4: copy_v4_v4(rgba, rf); IMB_colormanagement_processor_apply_v4(cm_processor, rgba); break; case 3: copy_v3_v3(rgba, rf); IMB_colormanagement_processor_apply_v3(cm_processor, rgba); rgba[3] = 1.0f; break; case 2: copy_v3_fl(rgba, rf[0]); rgba[3] = rf[1]; break; case 1: copy_v3_fl(rgba, rf[0]); rgba[3] = 1.0f; break; default: BLI_assert(0); } } else { for (int c = 4; c--;) rgba[c] = rc[c] * INV_255; } /* we still need luma for histogram */ luma = IMB_colormanagement_get_luminance(rgba); /* check for min max */ if (ycc_mode == -1) { minmax_v3v3_v3(min, max, rgba); } else { rgb_to_ycc(rgba[0], rgba[1], rgba[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode); mul_v3_fl(ycc, INV_255); minmax_v3v3_v3(min, max, ycc); } /* increment count for histo*/ bin_lum[get_bin_float(luma)]++; bin_r[get_bin_float(rgba[0])]++; bin_g[get_bin_float(rgba[1])]++; bin_b[get_bin_float(rgba[2])]++; bin_a[get_bin_float(rgba[3])]++; /* save sample if needed */ if (do_sample_line) { const float fx = (float)x / (float)ibuf->x; const int idx = 2 * (ibuf->x * savedlines + x); save_sample_line(scopes, idx, fx, rgba, ycc); } rf += ibuf->channels; rc += ibuf->channels; } }
void BKE_histogram_update_sample_line(Histogram *hist, ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings) { int i, x, y; const float *fp; unsigned char *cp; int x1 = 0.5f + hist->co[0][0] * ibuf->x; int x2 = 0.5f + hist->co[1][0] * ibuf->x; int y1 = 0.5f + hist->co[0][1] * ibuf->y; int y2 = 0.5f + hist->co[1][1] * ibuf->y; struct ColormanageProcessor *cm_processor = NULL; hist->channels = 3; hist->x_resolution = 256; hist->xmax = 1.0f; /* hist->ymax = 1.0f; */ /* now do this on the operator _only_ */ if (ibuf->rect == NULL && ibuf->rect_float == NULL) return; if (ibuf->rect_float) cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings); for (i = 0; i < 256; i++) { x = (int)(0.5f + x1 + (float)i * (x2 - x1) / 255.0f); y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f); if (x < 0 || y < 0 || x >= ibuf->x || y >= ibuf->y) { hist->data_luma[i] = hist->data_r[i] = hist->data_g[i] = hist->data_b[i] = hist->data_a[i] = 0.0f; } else { if (ibuf->rect_float) { float rgba[4]; fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); switch (ibuf->channels) { case 4: copy_v4_v4(rgba, fp); IMB_colormanagement_processor_apply_v4(cm_processor, rgba); break; case 3: copy_v3_v3(rgba, fp); IMB_colormanagement_processor_apply_v3(cm_processor, rgba); rgba[3] = 1.0f; break; case 2: copy_v3_fl(rgba, fp[0]); rgba[3] = fp[1]; break; case 1: copy_v3_fl(rgba, fp[0]); rgba[3] = 1.0f; break; default: BLI_assert(0); } hist->data_luma[i] = IMB_colormanagement_get_luminance(rgba); hist->data_r[i] = rgba[0]; hist->data_g[i] = rgba[1]; hist->data_b[i] = rgba[2]; hist->data_a[i] = rgba[3]; } else if (ibuf->rect) { cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); hist->data_luma[i] = (float)IMB_colormanagement_get_luminance_byte(cp) / 255.0f; hist->data_r[i] = (float)cp[0] / 255.0f; hist->data_g[i] = (float)cp[1] / 255.0f; hist->data_b[i] = (float)cp[2] / 255.0f; hist->data_a[i] = (float)cp[3] / 255.0f; } } } if (cm_processor) IMB_colormanagement_processor_free(cm_processor); }