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

Author Topic: Color Palette Manipulation  (Read 27426 times)

0 Members and 1 Guest are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Color Palette Manipulation
« on: October 07, 2008, 02:57:57 pm »
Hi!

Is there a way to use images with 256 indexed colours, which palette is accessible?
I wish to change image specific colours without having to access all the pixels with these colours.

If it's just not possible, please move the topic to the feature requests.
Thanks

btw, very good lib :)
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Color Palette Manipulation
« Reply #1 on: October 07, 2008, 07:25:02 pm »
It's not possible. What's the problem with replacing pixels directly ?
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Color Palette Manipulation
« Reply #2 on: October 07, 2008, 08:07:26 pm »
If I think on use the same image for different sprites which changes only in some colours, that would be heavy to create copies of the original image and change the pixels. Sending a color table pointer to the sprite before draw it would be better, I think.
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Color Palette Manipulation
« Reply #3 on: October 07, 2008, 08:51:56 pm »
It would be more efficient (*) if all APIs and hardware in the chain support palettes natively; I doubt it's the case (in fact I don't know, I've never really tried).

Depending on what you want to achieve, playing with the global color might be enough.

(*) The concept of efficiency with today's hardware is relative...
And thinking about a new feature for a possible future optimization is not a good thing. Do it simple and clean first, and come back if you encounter any performances issue with that.
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Color Palette Manipulation
« Reply #4 on: October 07, 2008, 09:45:57 pm »
Quote from: "Laurent"
It would be more efficient (*) if all APIs and hardware in the chain support palettes natively; I doubt it's the case (in fact I don't know, I've never really tried).

Hm, ok. I don't know also :roll: . As gif, bmp, png etc supports indexed colour, jpg doesn't... a subclass for indexed color images... don't know.

I'm thinking on a game where enemies of the same kind are distinguished by it's colours (mainly the clothes, and specially to mark strength differences). As they will have a set of animations, each animation needing a set of images, with pixel manip I'm only seeing all these amount of images (probably a unique strip image) multiplication as solution (a copy for each colour differentiation).
Or maybe using shaders.. I'm not  familiarized with shaders yet :oops:

Ok, I'll see what I can achieve. I'm not doing this yet, just planning..
Pluma - Plug-in Management Framework

coral

  • Newbie
  • *
  • Posts: 37
    • View Profile
Color Palette Manipulation
« Reply #5 on: October 08, 2008, 05:39:56 pm »
gsauras: GLSL/Shaders is the way for you to go, achieved exact the same effect by using shaders in my project. It is a bit pain to learn, but once you got it, you will find a lot of nice uses for it!

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Color Palette Manipulation
« Reply #6 on: October 08, 2008, 05:51:44 pm »
Thanks for the tip coral :)
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Color Palette Manipulation
« Reply #7 on: October 08, 2008, 09:20:31 pm »
But keep in mind that it won't be compatible with all configurations.
Laurent Gomila - SFML developer

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Color Palette Manipulation
« Reply #8 on: October 08, 2008, 10:51:11 pm »
Once the image is loaded by SOIL, it's stored locally and handed off to OpenGL's internal format.  The original image format is irrelevant.  You may think of what you're trying to do as optimization, but it's not.  In the way-back days, graphics were displayed with pallets that could be edited.  Now they're not.  So you'd literally have to iterate through the pixels looking for ones to swap out.  A shader would be the a way to do this, but perhaps not the best one for speed and compatibility purposes...
Now if you're doing this as a feature that you actually want, the way to do it would be (probably) to create multiple images at load time.  Load the original, then in C++ code, make whatever mods you want and save each mod as a new image.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Color Palette Manipulation
« Reply #9 on: October 08, 2008, 10:57:39 pm »
Thank you, that was a good explanation
Pluma - Plug-in Management Framework