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 6f153046e0 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
This commit is contained in:
Philipp Oeser
2024-02-02 19:43:19 +01:00
committed by Philipp Oeser
parent 2e02c0c515
commit 9aa20a0979
@@ -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);