Skip to content

Conversation

@stnKrisna
Copy link
Contributor

The idea is to use external raster mask to mask out areas parametric & drawn mask that we don't want them to take effect (i.e. background exposure).

Screenshot 2025-11-25 at 11 56 38 pm

Changes to pixel pipeline is not implemented yet

@ralfbrown
Copy link
Collaborator

I've had thoughts about adding raster masks to the conditional blending, but never got around to implementing anything. My idea was to treat the raster mask as just another "shape" in drawn masks (which would also allow multiple rasters to be combined with AND/OR/XOR/ANDNOT). Internally, darktable generates a raster mask for each drawn shape and then merges those layers into the final drawn mask. Adding a raster as another layer would take very little code beyond the GUI stuff to select the raster.

@TurboGit TurboGit added this to the 5.6 milestone Nov 25, 2025
@stnKrisna
Copy link
Contributor Author

@ralfbrown Sounds good! What I've been thinking is to multiply the raster mask with the mask generated by drawn and/or parametric mask.

Can you point me to the function that merges layers into the final drawn mask?

@ralfbrown
Copy link
Collaborator

Not an expert on that part of the codebase, but I'd start in files src/develop/masks.h and src/develop/masks/masks.c. My suggestion after a quick scan of those files: Add a new value to dt_masks_type_t and update dt_masks_create() to setup the config for copying a raster mask as a "shape". This involves writing several (but not all) of the functions that a dt_masks_functions_t struct points at; look in src/develop/masks/circle.c for probably the simplest model for those functions. My first impression is you'll need set_form_name, get_mask, get_mask_roi, and possibly get_area/get_source_area; sanitize_config is probably a good idea but not strictly required.

After that, there's a good chance that the existing machinery will just work, letting you use the mask manager module to specify combination methods (union/intersection/diff/sum).

@TurboGit
Copy link
Member

@stnKrisna : Please do not merge origin/master into your topic branch. If needed do a rebase. TIA.

@stnKrisna
Copy link
Contributor Author

@ralfbrown It took me a while to implement this. But I got a working prototype.
Screenshot 2025-11-26 at 11 33 20 pm

Also, as of now, I don't think any of the mask operations are working. The only way to invert the raster mask is to invert it in another module (or original module) before using it.
Screenshot 2025-11-26 at 11 29 33 pm

As of now, to load the raster mask into the drawn mask, you'd need to configure the raster map and switching back to the drawn & parametric mask. I need suggestion how to best load the raster mask into the raster shape.
Screenshot 2025-11-26 at 11 30 01 pm

Also, it's currently not possible to select the raster "shape" in the viewport, as I think this would block selection of other drawn masks. When updating shape of the raster mask, it will not update the mask value when used in the parametric "shape".

@stnKrisna
Copy link
Contributor Author

Implementing the _raster_get_mask_roi fixed some of the issues. Raster "shape" and drawn mask is now intersecting as expected.
Screenshot 2025-11-27 at 12 10 12 am

@ralfbrown
Copy link
Collaborator

currently not possible to select the raster "shape" in the viewport, as I think this would block selection of other drawn masks.

Yeah, that might be tricky. The obvious idea is to treat raster as being "behind" all drawn shapes, i.e. selected whenever the mouse is not over or near-enough a drawn shape. You can probably achieve that by returning a fixed distance equal to the maximum distance at which a shape gets selected. Won't help when multiple raster masks are enabled, though, and I'm not sure how to indicate that the raster is currently selected (beyond the hinter message) since there's no outline to emphasize.

@RawConvert
Copy link

If you're expanding mask functionality, I offer up this -
https://discuss.pixls.us/t/strategies-for-masking-fragmented-areas/42601/24?u=rawconvert

@RawConvert
Copy link

@stnKrisna , what do you think of the link I posted above? If you're going to do appreciable work in this area, it would be good to make it as generally useful as reasonably possible.

@stnKrisna
Copy link
Contributor Author

stnKrisna commented Jan 10, 2026 via email

@stnKrisna
Copy link
Contributor Author

@RawConvert I like the idea of the Mask Manipulator Module as currently the bug that I still cannot solve revolves around reading the raster mask when the same shape group with a raster shape is used by multiple modules. I'll see how this can be done as im not 100% familiar with the codebase

@RawConvert
Copy link

@stnKrisna , I'm pleased you like the idea. If and when you get something working, I will try to support with some testing, if that helps.
My thoughts on this development, having read above, and bearing in mind I'm a user not a developer -
I suggest steer clear of the Mask Manager. I believe few people use it, and I think that's partly because it's fiddly and not intuitive. I suggest build something that works with raster masks and only raster masks, and is a new Module. And build the combination functions such as And / Or / etc into the new module. Seeing "treat raster as being "behind" all drawn shapes" is setting alarm bells off in my head!

@wpferguson
Copy link
Member

wpferguson commented Jan 20, 2026

@stnKrisna If you decide to pursue the suggested new module, I suggest you open an RFC first to inform everyone what you're planning and get some feedback since you'll be replacing the current mask manager module. I would also suggest you not add it on to this PR. If you can't do this PR without it, then I would close this PR and open a new one.

EDIT: You might want to look at #20123.

@TurboGit
Copy link
Member

I would like to not see a new module. If the mask manager must be extended or changed deeply no problem as the libs modules are not versioned so won't break anything. I'm also not convinced that adding a raster mask section is a good move. Why? Because the raster masks are kind of temporary solution that will be replaced when we have a way to vectorize them and so handle them as all other masks. At this stage I don't think we want to have the raster mask more visible and certainly not a first class citizen in the UI.

@stnKrisna
Copy link
Contributor Author

@TurboGit Do you recommend me continuing what I've been doing for now or pause work until vectorisation of the raster mask is implemented?

From what I've gathered, implementing a new module will require me to reimplement all of the logic for the masking, since the module will have to output a new raster mask.

@TurboGit
Copy link
Member

@stnKrisna : I will recommend to pause this until we have a clear view/design for the long run about raster masks, vectorisation and how to deal with them.

@RawConvert
Copy link

@TurboGit , re. "I don't think we want to have the raster mask more visible and certainly not a first class citizen in the UI." Why do you say this? - is it because they use lots of memory?

@stnKrisna stnKrisna closed this Jan 24, 2026
@TurboGit
Copy link
Member

Why do you say this? - is it because they use lots of memory?

No because a raster mask is not saved into the XMP. It is an external resource that can't be easily shared. To avoid that we need to vectorize the raster masks and in this case the mask will be saved into the XMP. That's the goal of #20198. Last but not least this will be the base for AI masking is someone what to work on this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants