Turn off the anti-aliasing or pixel averaging

Request a new command, feature, or improvement

Moderators: MSandro, MSandro, MSandro

Post Reply
mr-dave
Posts: 7
Joined: Dec 3rd, '17, 04:02

Turn off the anti-aliasing or pixel averaging

Post by mr-dave » Dec 4th, '17, 23:39

I was trying to set some pixels to be transparent and then realized that GP is changing what I set. Could it be told to leave pixels alone and not try and 'fix' the image or just leave the transparent pixels alone? Otherwise I end up with a halo around the image.

JohnM
Posts: 314
Joined: Sep 11th, '15, 14:42

Re: Turn off the anti-aliasing or pixel averaging

Post by JohnM » Dec 5th, '17, 17:35

GP uses the hardware GPU (graphics processing unit), which does anti-aliasing automatically when scaling and rotating costumes. You can sort of avoid that if your instance isn't rotated or scaled and you use the "normal stage size" command to make sure that the stage itself isn't scaled. But, in general, you can't disable anti-aliasing.

That said, from the phrase "halo around the image", you could be running into a related, but different problem. If you are drawing your own costume programmatically, then you can get a halo as an artifact of drawing onto a transparent canvas. The reason that happens is that RGB values of the pixels of the transparent canvas get "mixed" with the color you are drawing along the edges, since that's what anti-aliasing does. The resulting translucent pixels along the edges become partly visible, but rather the being purely the color you used for drawing, they have some of the previously invisible transparent color -- usually white -- mixed in.

You can avoid this in some cases by pre-filling your costume with a transparent version of the color you draw with.

For example, these scripts:
Screen Shot 2017-12-05 at 12.31.56 PM.png
both produce black circles:
Screen Shot 2017-12-05 at 12.39.19 PM.png
Screen Shot 2017-12-05 at 12.39.19 PM.png (8.85 KiB) Viewed 39 times
However, if we change stage background to black, we can see the the circle on the left, produced by the top script, has a halo of white pixels:
Screen Shot 2017-12-05 at 12.40.50 PM.png
Screen Shot 2017-12-05 at 12.40.50 PM.png (7.53 KiB) Viewed 38 times
The circle on the right avoided that by filling the costume with "transparent black" before drawing the circle.

BTW, one trick to see what's going on at the pixel level is to use the "scale" block to scale up your costume to, say, 8x. At that point, each pixel is big enough that you can really tell what is going on. Another trick is to switch background colors to reveal potential fringing artifacts.

I hope this helps.

mr-dave
Posts: 7
Joined: Dec 3rd, '17, 04:02

Re: Turn off the anti-aliasing or pixel averaging

Post by mr-dave » Dec 6th, '17, 15:24

Thanks for the reply. It must have taken you some time to write and explain all of that and I appreciate it.

JohnM
Posts: 314
Joined: Sep 11th, '15, 14:42

Re: Turn off the anti-aliasing or pixel averaging

Post by JohnM » Dec 8th, '17, 13:28

You're welcome! The great thing about the forums is that answers to questions like this are shared with everyone, so it's worth spending the time to write a good answer.

Post Reply