Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Undoing Color to Alpha.  (Read 1515 times)

0 Members and 1 Guest are viewing this topic.

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Undoing Color to Alpha.
« on: December 16, 2014, 01:38:10 am »
I want to change color in image to alpha. I can do this with sf::image's createMaskFromColor however what's the best way to reverse this? Do I need to store two copies? or do I loop through all the pixels? or is there a better way?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Undoing Color to Alpha.
« Reply #1 on: December 16, 2014, 01:48:35 am »
It's not clear what you're trying to ask.  Do you have a texture that you want to draw on the window semi-transparently? Are you actually editing images within your program?  When you say "image", are you talking about a .png file, an sf::Image, an sf::Texture, an sf::Sprite, an array of Uint8s or something else entirely?

For the typical use case of a game that draws a texture to the window with some transparency, you shouldn't be using sf::Image at all.  Use an sf::Texture so the pixels live on the GPU, and draw() an sf::Sprite with that texture.  The sprite has a color (which includes alpha) which the GPU will efficiently apply to the pixels at draw() time.  The relevant tutorial is: http://www.sfml-dev.org/tutorials/2.1/graphics-sprite.php
« Last Edit: December 16, 2014, 01:52:26 am by Ixrec »

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Undoing Color to Alpha.
« Reply #2 on: December 16, 2014, 05:26:51 am »
I think (Correct me if I'm wrong), he knows that he can create a color mask with a sprite, but he wants to know if he can create a mask from alpha. I'm not sure how to go about it though.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Undoing Color to Alpha.
« Reply #3 on: December 16, 2014, 08:00:42 am »
If your image initially had no alpha at all, then you know that every pixel with alpha == 0 was originally of the masked color. So reverting is easy, just go through all pixels and do the replacement.
Laurent Gomila - SFML developer