Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / SetImageMask - trying to cut a hole in an image

Author
Message
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 18th Apr 2014 21:42
OK, so I've not used SetImageMask much and it's not working as I'd expect it. I have used it to paste a texture onto images, but I want to take a square image and cut shapes out of it.
In the below example "bar.png" is a simple white square PNG.
"circle.png" is a simple white circle PNG.
I'd like to use the circle's rgb values to create an alpha transparency in the square. I can't get it to work.
Can someone help?



Images and code attached for easy access.
Thanks!!

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Apr 2014 22:07
I didn't even know about this command, but after reading the description, I would think all you need to do is copy just the alpha channel.

Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 18th Apr 2014 23:02
Thats true, if you want the alpha channel from the source. I don't. I want to put the rgb channels from the source onto the alpha of the destination.

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 01:38 Edited at: 19th Apr 2014 01:40
Quote: "Can someone help?"

Sure, you need to invert the circle (so that the bit you want to cut out is black) and remove two of the setimagemask lines (the last one is just replacing the the other two in the original code)

then you get;

Attachments

Login to view attachments
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Apr 2014 08:44
I see... because the image is white the R,G,B values are all 255 so when I copy any of them to an alpha channel of an image that destination image's alpha is 255.
I should have been able to figure that out, but nope! lol
Thanks for the clues.

Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Apr 2014 20:01
So still having issues. I inverted to black and found that there must be some partial RGB value in the transparent area of the circle image. I manually deleted any pixels in that area and was finally able to get the transparency to mask onto the square. However, the edges are now choppy. It's like AppGameKit cannot deal with the partial alpha values and it's either all or nothing.
I give up, in 10821 this seems either broken or worthless.

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 20:27 Edited at: 19th Apr 2014 20:28
Choppier than the example I posted ? (which was using your code and graphics an compiled on 108.21)

I've attached the Inverted circle image I used


Attachments

Login to view attachments
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Apr 2014 20:50 Edited at: 19th Apr 2014 20:50
Yours looks great.
But it doesn't have an alpha channel.
This seems to be where the problem lies.
If I have an image with a black circle and white background, like yours it is fine. Looks great.
If I have an image with a black circle and transparency the alpha channel is ignored by AGK.
Surely if I tell AppGameKit to copy only the R channel to the alpha of the square sprite it shouldn't be copying the alpha channel as a solid color... clunky!

EDIT:
Attached inverted color with alpha background around circle.

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 21:02 Edited at: 19th Apr 2014 21:04
Quote: "But it doesn't have an alpha channel."

Perhaps I'm missing what you are trying to achieve, but it's a white square with a circular hole in it.

It can't NOT have an alpha channel

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 21:07 Edited at: 19th Apr 2014 21:09
By adding the line

SetSpriteColorAlpha(bgImage , 127 )

you can even make the square (with the hole) semi transparent.



Which demonstrates partial alpha transparency (of the main colours) and the alpha channel (which is fully transparent)

Attachments

Login to view attachments
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Apr 2014 21:09
That's what I'm trying to achieve.
What I'm saying is that the image you've created (circleneg.png) does not have an alpha channel.
It is black and white.
So this is a solution, but I think AppGameKit is wrong in how it does masking.
If you have a image1 with alpha and black circle
then you copy the red channel from image1 to image2
then image2 has the alpha channel from image1 copied as a solid color.

It doesn't make much sense because I can copy alpha from an image to another image, but if I want to apply a color channel from an image to another image's alpha channel then the alpha channel of the source image is copied as a solid color.

So your solution is fine, I just expect the AppGameKit function to work differently and not copy the alpha channel of an image when I'm telling it to copy the R channel.

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 21:18 Edited at: 19th Apr 2014 21:24
Quote: " if I want to apply a color channel from an image to another image's alpha channel then the alpha channel of the source image is copied as a solid color."

It's actually copied as a grey scale image, with black being the most transparent and White being the least.

The red Channel of an image is not actually red, it's a grey-scale map of the degrees of redness of the whole image. It only becomes red when it's in the red channel.

If you were copy the red channel of any image to the green channel AND the blue channel, the image would show as grey because the red, green and blue are the same for each pixel.

So if you copy the red channel to the alpha channel, the least red parts of the image would be the most transparent.

Edit:

Quote: "the image you've created (circleneg.png) does not have an alpha channel."

Correct, which is why we need to copy the red channel. In the example, the image is white (it's actually grey scale due to the anti-aliasing) which means that the red, green and blue channels are all the same, so copying any channel will work the same.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Apr 2014 21:20
I see, that sort of makes sense, but the alpha in the source image should have 0 in the red channel at the transparent pixels, right?

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 21:34 Edited at: 19th Apr 2014 21:37
The source has no alpha channel, so it is the equivalent of being solid white in all the pixels - i.e. not transparent.

As another example, Take a look at the image below;

It is something I created for a set of tiles I was working on.

Notice the pure red, green and blue sections, these are used to make multiple tile sets with the same image, by copying the channels around.

* If I want the walls transparent, I copy the red channel from the top section to the bottom - the walls are green so will be zero in the red channel.
* If I want the floor transparent, I copy the green channel from the top part to the bottom - the floors are red so will be zero in the green channel
* If I don't copy any channels, the floor will be blue and the walls orange, with no transparency anywhere.

Attachments

Login to view attachments
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Apr 2014 21:40
Your explanation makes sense, however:

Quote: "The source has no alpha channel, so it is the equivalent of being solid white in all the pixels - i.e. not transparent."


My source does have an alpha channel.

Yours doesn't so it works.

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 19th Apr 2014 21:46
I also have a small project to apply alpha channels;

It loads an image and a grey-scale mask, combines them and saves them.
(I'm better at programming than using art packages so for me this is a quicker way to get the alpha channel in there ).

Login to post a reply

Server time is: 2024-04-25 08:05:13
Your offset time is: 2024-04-25 08:05:13