bpy.ops.paint.image_paint with a texture requires initialization with manual paint stroke otherwise color not quite right #54554

Closed
opened 2018-04-09 16:47:21 +02:00 by Rob Hughes · 8 comments

System Information
Win 10 5820K GTX 970

Blender Version
2.79b and latest daily build

Short description of error
bpy.ops.paint.image_paint with slightly wrong colors when painting on object with texture on brush before a manual paint stroke applied

Exact steps for others to reproduce the error

  1. Load attached file
  2. Run script
  3. With mouse over the cube - press space and type Simple Modal Operator to activate modal paint operator
  4. move mouse about to paint.
  5. left click to stop modal paint operator
  6. now paint on the cube normally by holding mouse button down
  7. you will see this is a slightly different color
  8. press space and type Simple Modal Operator to activate modal paint operator again
  9. move mouse around
  10. you should now see modal operator painting correctly

This seems to happen each time I change the texture on the brush to a new one (with obviously different colors on it)

Image is attached showing this.

Possibly something not being initialized properly?

Thanks you in advance for any work on this.

modal_paint.blend

PaintColorBug.JPG

**System Information** Win 10 5820K GTX 970 **Blender Version** 2.79b and latest daily build **Short description of error** bpy.ops.paint.image_paint with slightly wrong colors when painting on object with texture on brush before a manual paint stroke applied **Exact steps for others to reproduce the error** 1. Load attached file 2. Run script 3. With mouse over the cube - press space and type Simple Modal Operator to activate modal paint operator 4. move mouse about to paint. 5. left click to stop modal paint operator 6. now paint on the cube normally by holding mouse button down 7. you will see this is a slightly different color 8. press space and type Simple Modal Operator to activate modal paint operator again 9. move mouse around 10. you should now see modal operator painting correctly This seems to happen each time I change the texture on the brush to a new one (with obviously different colors on it) Image is attached showing this. Possibly something not being initialized properly? Thanks you in advance for any work on this. [modal_paint.blend](https://archive.blender.org/developer/F2643981/modal_paint.blend) ![PaintColorBug.JPG](https://archive.blender.org/developer/F2644001/PaintColorBug.JPG)
Author

Added subscriber: @RevDr

Added subscriber: @RevDr
Author

I have done a little further investigation.

It seems what is happening is this: bpy.ops.paint.image_paint does not use color space of the brush texture until after a stroke has been 'manually' done. Therefore the texture is being used as if it is in the raw texture space until a manual stroke overides this.

I have done a little further investigation. It seems what is happening is this: bpy.ops.paint.image_paint does not use color space of the brush texture until after a stroke has been 'manually' done. Therefore the texture is being used as if it is in the raw texture space until a manual stroke overides this.
Author

Having looked at the code it appears that the color space initialization for the texture is done in
paint_stroke.c
function: paint_brush_update (particualy lines 239->261)

However this is never called from the python code image_paint function.

As a workaround I tried adding the following (adapted from paint_brush update function) lines of code to
function: paint_stroke_new

      
   if (!stroke->brush_init) {
	ups->do_linear_conversion = false;
	ups->colorspace = NULL;

	/* 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 (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->rect_float == NULL) {
			ups->do_linear_conversion = true;
			ups->colorspace = tex_ibuf->rect_colorspace;
		}
		BKE_image_pool_release_ibuf(br->mtex.tex->ima, tex_ibuf, NULL);
	}

	stroke->brush_init = true;
}

Which seems to fix the problem - however - I have no idea if there are serious knock on consequences to this change which would break things (is stroke->brush_init needed here?)

I am sure there is a much more elegant solution.

Having looked at the code it appears that the color space initialization for the texture is done in paint_stroke.c function: paint_brush_update (particualy lines 239->261) However this is never called from the python code image_paint function. As a workaround I tried adding the following (adapted from paint_brush update function) lines of code to function: paint_stroke_new ``` ``` ``` if (!stroke->brush_init) { ``` ups->do_linear_conversion = false; ups->colorspace = NULL; /* 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 (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->rect_float == NULL) { ups->do_linear_conversion = true; ups->colorspace = tex_ibuf->rect_colorspace; } BKE_image_pool_release_ibuf(br->mtex.tex->ima, tex_ibuf, NULL); } stroke->brush_init = true; } ``` Which seems to fix the problem - however - I have no idea if there are serious knock on consequences to this change which would break things (is stroke->brush_init needed here?) I am sure there is a much more elegant solution.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Hi @RevDr and thx for the report,
as a first note: I can confirm the issue and also that your code fixes it (I tested without stroke->brush_init -- but needs more research...)

Hi @RevDr and thx for the report, as a first note: I can confirm the issue and also that your code fixes it (I tested without stroke->brush_init -- but needs more research...)
Philipp Oeser removed the
Interest
Sculpt, Paint & Texture
label 2023-02-10 09:12:52 +01:00

After 6 years, still there.

After 6 years, still there.
Member

Nowadays it even seems to crash:

1 colorspace_to_scene_linear_cpu_processor                colormanagement.cc  909  0x5f18daf 
2 IMB_colormanagement_colorspace_to_scene_linear_v3       colormanagement.cc  2154 0x5f22950 
3 BKE_brush_sample_tex_3d                                 brush.cc            2179 0x861762  
4 do_projectpaint_thread(TaskPool * __restrict__, void *) paint_image_proj.cc 5430 0xa65ae34 
5 Task::operator()                                        task_pool.cc        166  0x4344a9f 
6 tbb::internal::function_task<Task>::execute             task.h              1059 0x43498d7 
Nowadays it even seems to crash: ``` 1 colorspace_to_scene_linear_cpu_processor colormanagement.cc 909 0x5f18daf 2 IMB_colormanagement_colorspace_to_scene_linear_v3 colormanagement.cc 2154 0x5f22950 3 BKE_brush_sample_tex_3d brush.cc 2179 0x861762 4 do_projectpaint_thread(TaskPool * __restrict__, void *) paint_image_proj.cc 5430 0xa65ae34 5 Task::operator() task_pool.cc 166 0x4344a9f 6 tbb::internal::function_task<Task>::execute task.h 1059 0x43498d7 ```
Member

Tweaking the solution from @RevDr a bit (I think we should only do this in paint_stroke_new and not in paint_brush_update [which would do this per step]), but yes, since this also crashes nowadays, will put a PR up shortly (or next week, depending on how much testing is needed).

So will put on my desk

Tweaking the solution from @RevDr a bit (I think we should only do this in `paint_stroke_new` and not in `paint_brush_update` [which would do this per step]), but yes, since this also crashes nowadays, will put a PR up shortly (or next week, depending on how much testing is needed). So will put on my desk
Philipp Oeser self-assigned this 2024-02-02 16:39:46 +01:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-02-02 19:44:35 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#54554
No description provided.