About Store Forum Documentation Contact
Donations:
178$/mo



Post Reply 
Greyscale image convertor
Author Message
AndrewBGS Offline
Member

Post: #1
Greyscale image convertor
I'm thinking a function of turning an image to greyscale would be quite useful for a game engine. I did find some code about doing that but I couldn't use it ina function. Guess what, encountered the "no copt constructor" error when I tried to return an image.

Anyway, a greyscale converting function would be really useful; for unavailable buttons, slots, etc; empty slots, locked skills, and so on. Sure you can just use twice the amound of pictures but I'd like to avoid that.

Would it be too much trouble to implement one? I'd love to be able to do this:

Image a=....
Image b=a.toGreyscale();
05-12-2013 05:32 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #2
RE: Greyscale image convertor
Hi, here is some code from my Greyscale Converter which I made about 2 years ago, so I'm not sure if it still works ok, but I hope that it'll help you.

Code:
image.load(name);

   image.copy(c,-1,-1,IMAGE_B8G8R8A8);

   if(c.lock()) // in order to edit the texture we must first lock it
   {
      FREPD(y,c.y()) // iterate through all y's
      FREPD(x,c.x()) // iterate through all x's
      {
          clr=c.color(x,y);
          color=0.3*clr.r+0.5*clr.g+0.2*clr.b;
          c.color(x,y,Color(255,color,color,color));
      }
      c.unlock(); // unlock
   }

   c.updateMipMaps();
   c.copy(image,-1,-1,IMAGE_DXT5);

   image.save(name);
(This post was last modified: 05-14-2013 04:41 PM by Harry.)
05-14-2013 04:40 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Sherincall Offline
Member

Post: #3
RE: Greyscale image convertor
The effect might be better if you use:
Code:
color=0.3*clr.r+0.585*clr.g+0.115*clr.b;

These values are slightly more suited for human eyes.
(This post was last modified: 05-14-2013 04:52 PM by Sherincall.)
05-14-2013 04:50 PM
Find all posts by this user Quote this message in a reply
Post Reply