Two Krita technical questions

Boudewijn Rempt boud at
Tue Jun 22 15:39:58 CEST 2010

On Tue, 22 Jun 2010, JL VT wrote:

> First of all sorry if the questions had obvious answers, they're not
> so obvious to me!.
> Question(s) one, for the Scratch Off algorithm:
> I have a paintop, and want to store image data in a place where: 1.-
> it is invisible to the user  2.- survives the destruction and
> reinvocation of the paintop.
> std::clog tells me that paintops are created when the user presses
> down the mouse button, and destroyed when he releases it. That leads
> me to think that anything I create inside the paintop won't survive
> till the next creation-destruction cycle, but maybe I'm missing
> something.

Krita was designed to make strokes independent of each other, so that's hard.

I'm not sure what you mean by image data, do you mean the temporary layer
in wash mode?

The only place where you can store data for the paintop is in the preset
settings object. There's no guarantee that the user won't select another
preset before he paints the next stroke, though. You _could_ (conceivably)
put your data in a static object local to the paintop. That's quite
hackish, though. Another option might be to create some data class and add
that to the KisCanvasResourceProvider, then it would be analogous to the
current background or foreground color.

> I want to know: how can I achieve (1) and (2)?. If there's a place in
> the code where someone does something similar, just point me to that
> file, I can learn from it. Or tell me what classes to use or roughly
> what's the principle of what to do with them (i.e.: if you use this,
> it will survive the paintop destruction, just be sure to erase it when
> you stop using it or it will leak memory).
> If there's more than one way to do it(tm), please point me to the most
> "orthodox" or most "desirable" way to do it. I already refactored my
> code and prefer to keep it clean and shiny.

Depending on what you mean by image data, there might actually be no nice way
of doing this right now...

> Question(s) two, for general hatching:
> I have a hatching KisBrushBasedPaintOp. I have a nice BrushTip
> dialogue, that gives me a bitmap with a pre-made dab.
> What I don't have is an idea of how to use that dab as a transparency
> mask for my hatching.
> My idea is to first hatch a little paint device just like I'm doing
> now --let's call it "DabHatch"--, then to access the mask stored in
> m_brush (the one we customize in the BrushTip popup dialogue) --let's
> call it "DabMask"--, and use it to determine the transparency of
> pixels in "DabHatch", creating a new image ready to be potato-stamped
> on the image, let's call it "DabHappiness". The creation of
> DabHappiness should follow these rules:
> --Assume opacity can be represented with a number ranging from 0 to 1,
> where 0 is "transparent" and 1 is "opaque". Then...
> --opacity_of_pixels_in_DabHappiness = opacity_of_pixels_in_DabHatch *
> opacity_of_pixels_in_DabMask
> How can I do that?, is there a command?, an easily accessible method?.
> Please, just like in the last question, point me to a file where it is
> done if it is already done in a file; otherwise show me the principle
> and the classes used to do it, and let me know what's the most
> "orthodox" and "desirable" way to doo it.

Yes, I think you need to combine the two paint devices. Use the hatch as a mask on the
brush tip, setting the brush pixel's transparency channel to the values of the

> Thank you very much for your time.
> PS: I assumed Lukas wouldn't want answers like this to go to waste so
> I went forward and asked here for the answer to be publicly stored  :]
> _______________________________________________
> kimageshop mailing list
> kimageshop at

More information about the kimageshop mailing list