From 9aa20a09798652ffb410479ae0b05dd382acf386 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 2 Feb 2024 19:43:19 +0100 Subject: [PATCH] Fix #54554: missing colorspace calling paint.image_paint() from python Without doing a stroke "manually", colorspace initialization on UnifiedPaintSettings was never done. This lead to wrong colors in the past, since modern CS code with OIIO this also crashes. Colorspace was added into UnifiedPaintSettings in 6f153046e0ff to avoid doing this when sampling the brush texture images [which is good], but the initalization was done in `paint_brush_update`. We dont need to have this called for every step (it was skipped anyways after one run), so it seems we can move this out of `paint_brush_update` and put this into `paint_stroke_new`. Thx @RevDr for initial findings. Pull Request: https://projects.blender.org/blender/blender/pulls/117756 --- .../editors/sculpt_paint/paint_stroke.cc | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_stroke.cc b/source/blender/editors/sculpt_paint/paint_stroke.cc index b21619613f5..fe824955375 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.cc +++ b/source/blender/editors/sculpt_paint/paint_stroke.cc @@ -315,21 +315,6 @@ static bool paint_brush_update(bContext *C, copy_v2_v2(ups->mask_tex_mouse, mouse); stroke->cached_size_pressure = pressure; - ups->do_linear_conversion = false; - ups->colorspace = nullptr; - - /* check here if color sampling the main brush should do color conversion. This is done here - * to avoid locking up to get the image buffer during sampling */ - if (brush->mtex.tex && brush->mtex.tex->type == TEX_IMAGE && brush->mtex.tex->ima) { - ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf( - brush->mtex.tex->ima, &brush->mtex.tex->iuser, nullptr); - if (tex_ibuf && tex_ibuf->float_buffer.data == nullptr) { - ups->do_linear_conversion = true; - ups->colorspace = tex_ibuf->byte_buffer.colorspace; - } - BKE_image_pool_release_ibuf(brush->mtex.tex->ima, tex_ibuf, nullptr); - } - stroke->brush_init = true; } @@ -929,6 +914,20 @@ PaintStroke *paint_stroke_new(bContext *C, get_imapaint_zoom(C, &zoomx, &zoomy); stroke->zoom_2d = max_ff(zoomx, zoomy); + /* Check here if color sampling the main brush should do color conversion. This is done here + * to avoid locking up to get the image buffer during sampling. */ + ups->do_linear_conversion = false; + ups->colorspace = nullptr; + + if (br->mtex.tex && br->mtex.tex->type == TEX_IMAGE && br->mtex.tex->ima) { + ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf(br->mtex.tex->ima, &br->mtex.tex->iuser, NULL); + if (tex_ibuf && tex_ibuf->float_buffer.data == nullptr) { + ups->do_linear_conversion = true; + ups->colorspace = tex_ibuf->byte_buffer.colorspace; + } + BKE_image_pool_release_ibuf(br->mtex.tex->ima, tex_ibuf, nullptr); + } + if (stroke->stroke_mode == BRUSH_STROKE_INVERT) { if (br->flag & BRUSH_CURVE) { RNA_enum_set(op->ptr, "mode", BRUSH_STROKE_NORMAL);