Gradient mask for images

10 posts / 0 new
Last post
Mikey
Offline
Last seen: 1 hour 42 min ago
Joined: 20 Feb 2009 - 18:36
Gradient mask for images

There must be a way to do this, but so far I'm coming up with blanks. I guess I got whacked with the stupid stick. If anyone's sorted this out, I'd appreciate a comment.
I'd like to apply a gradient mask to an image as I draw it. The gradient mask is a 2-D array, the same size as the image. Alphas in the image are multiplied by alphas in the gradient mask as they're blitted to the screen. Is there a straightforward way to get this done? Many thanks.

TheVinn
Offline
Last seen: 2 months 2 weeks ago
Joined: 29 Aug 2009 - 11:31
Re: Gradient mask for images

You have a solid image (all opaque) and you want to give it an associated alpha mask of your choosing?

If your source image is RGB then just make a new image that is ARGB and for each pixel, take as input the source RGB and alpha value and write a premultiplied PixelARGB to the destination.

Mikey
Offline
Last seen: 1 hour 42 min ago
Joined: 20 Feb 2009 - 18:36
Re: Gradient mask for images

Thanks Vinn. That's not quite what I'm looking for. I've got images that are already ARGB. I'd like to be able to create a gradient--perhaps as a brush, perhaps as a path--and generate a resultant operation with alphas that are the product of both. It would be best if this was only applied during draw. I don't want to mess with the original image: this is something I want to do dynamically. Of course I can multiply pixel-by-pixel, but I was hoping there might be something precooked.

jules
Offline
Last seen: 55 min 29 sec ago
Joined: 29 Apr 2013 - 18:37
Re: Gradient mask for images

Graphics::reduceClipRegion (const Image&) ?

Mikey
Offline
Last seen: 1 hour 42 min ago
Joined: 20 Feb 2009 - 18:36
Re: Gradient mask for images

jules wrote:
Graphics::reduceClipRegion (const Image&) ?

Possibly. I'll give it a try in a little while. Thanks.
Mikey
Offline
Last seen: 1 hour 42 min ago
Joined: 20 Feb 2009 - 18:36
Re: Gradient mask for images

jules wrote:
Graphics::reduceClipRegion (const Image&) ?

Meh. It's a little helpful, but could be more so. I'm using a single-channel image (since all I need is alpha). I don't really need the AffineTransform. I'd love to have a way to draw a grayscale gradient in that image--that's what I'm really after. If you've ever used layer masks in Photoshop, it's exactly the same thing.
TheVinn
Offline
Last seen: 2 months 2 weeks ago
Joined: 29 Aug 2009 - 11:31
Re: Gradient mask for images

Mikey wrote:
I'd love to have a way to draw a grayscale gradient in that image--that's what I'm really after. If you've ever used layer masks in Photoshop, it's exactly the same thing.

You're saying inconsistent things. Now you are saying that you have an Image of type SingleChannel and you want to render a gradient into it? Call Image::createLowLevelContext() and then draw the gradient with suitable starting and ending colours.

I think you want to create a temporary SingleChannel image, draw into it as I mentioned above, then call Graphics::reduceClipRegion() with this temporary image, then draw your ARGB images (as Jules mentioned).

Mikey
Offline
Last seen: 1 hour 42 min ago
Joined: 20 Feb 2009 - 18:36
Re: Gradient mask for images

TheVinn wrote:
Mikey wrote:
I'd love to have a way to draw a grayscale gradient in that image--that's what I'm really after. If you've ever used layer masks in Photoshop, it's exactly the same thing.

You're saying inconsistent things. Now you are saying that you have an Image of type SingleChannel and you want to render a gradient into it? Call Image::createLowLevelContext() and then draw the gradient with suitable starting and ending colours.

I think you want to create a temporary SingleChannel image, draw into it as I mentioned above, then call Graphics::reduceClipRegion() with this temporary image, then draw your ARGB images (as Jules mentioned).


Then I'm not stating myself as clearly as I want. I have an ARGB image that I would like to apply a layer mask to. It's as simple as that. I discovered that the single-channel image works in Graphics::reduceClipRegion(); it's functioning as a layer mask for my ARGB image. But I can't really do the manipulations I want to that single-channel image unless I stand on my head. Being able to draw a gradient in that mask image would allow me to do some nice blending of foreground and background. Bear in mind that I'm doing this dynamically. Otherwise I'd just boot up Photoshop and handle it there.
TheVinn
Offline
Last seen: 2 months 2 weeks ago
Joined: 29 Aug 2009 - 11:31
Re: Gradient mask for images

Mikey wrote:
I can't really do the manipulations I want to that single-channel image unless I stand on my head. Being able to draw a gradient in that mask image would allow me to do some nice blending of foreground and background. Bear in mind that I'm doing this dynamically. Otherwise I'd just boot up Photoshop and handle it there.

Call Image::createGraphicsContext() on your single-channel mask and then draw all you want, and when you're done set it as the clip in the call to Graphics::reduceClipRegion(), then draw your ARGB image and it will use the single-channel image as a mask (as well as respecting the alpha channel of your ARGB image).

Mikey
Offline
Last seen: 1 hour 42 min ago
Joined: 20 Feb 2009 - 18:36
Re: Gradient mask for images

TheVinn wrote:
Mikey wrote:

Call Image::createGraphicsContext() on your single-channel mask and then draw all you want, and when you're done set it as the clip in the call to Graphics::reduceClipRegion(), then draw your ARGB image and it will use the single-channel image as a mask (as well as respecting the alpha channel of your ARGB image).

Now that sounds like it will get me somewhere. I'll give it a try. At some point I'll need to find a decent SVG tool so I can explore the vector world some more, but for now I can't help but think in Photoshoppy ways. Thanks much!