How to Grayscale Texture

"ancientcc" <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
Would like to use SDL_Texture widely in code, but SDL_RenderReadPixel is too
low, require grayscale texture directly. How to do?

 

By the way, I use below code to grayscale SDL_Surface.

............

// beg is begin pixel of SDL_Surface.

// end is end pixel of SDL_Surface + 1.

while (beg != end) {

              Uint8 alpha = (*beg) >> 24;

              if (alpha) {

                           Uint8 r, g, b;

                           r = (*beg) >> 16;

                           g = (*beg) >> 8;

                           b = (*beg);

                           // const Uint8 avg = (red+green+blue)/3;

                            // gray=0.299red+0.587green+0.114blue

                           const Uint8 avg = static_cast<Uint8>((

                                         77  * static_cast<Uint16>(r) +

                                         150 * static_cast<Uint16>(g) +

                                         29  * static_cast<Uint16>(b)  ) /
256);

                           *beg = (alpha << 24) | (avg << 16) | (avg << 8) |
avg;

              }

              ++beg;

}

............

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.