Aug 29, 2013 at 1:06am UTC
URGENT
with using SDL_Maprgb and SDL_GetRgb.
I am new to programming. can someone help me to solve this problem?
void put_pixel32 (SDL_Surface *surf, int x, int y, Uint32 pixel)
{
Uint32 *pixels = (Uint32 *)surf->pixels;
pixels[(y * surf->w ) + x] = pixel;
}
how do i get use of this code?
Uint32 SDL_MapRGB(SDL_PixelFormat* format, Uint8 r, Uint8 g,Uint8 b);
void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat* format, Uint8*r, Uint8 *g,Uint8 *b)
I am using the existing picture.
note: the function is just like Photoshop, can change the color only in red channel.
Last edited on Aug 29, 2013 at 1:07am UTC
Aug 29, 2013 at 1:08am UTC
how do i get use of this code?
wut
Can you please explain more clearly?
Last edited on Aug 29, 2013 at 1:09am UTC
Aug 29, 2013 at 6:16am UTC
i need to create the effect on a picture which only shows color red which similar like negative effect but i wanna to change it to only red channel
RGB(255,0,0)
Last edited on Aug 29, 2013 at 6:19am UTC
Aug 29, 2013 at 7:56am UTC
Apply negative.
Apply greyscale.
Map all non-red components to zero.
Aug 29, 2013 at 11:12am UTC
can you provide me a code since i am new to c++ :)
Aug 29, 2013 at 4:18pm UTC
I can't provide code, you have to do that.
Negate an image by subtracting each color channel from 255. For example, (97,53,112) --> (158,202,143).
Greyscale with the following formula: V = 0.299*R + 0.587*G + 0.114*B. For example:
(158,202,143) --> (182,182,182)
Zero all non-red components:
(182,182,182) --> (182,0,0)
Do this for each pixel to get what you want.
Aug 29, 2013 at 6:16pm UTC
void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b);
Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b);
i wonder how to use this 2 function~
can you tell me what is the four(x,x,x,x) represent~ i really not understand
i need to use this 2 to change to red channel i.e. the picture only shows red color;
Aug 30, 2013 at 12:51am UTC
Read your documentation. The fourth (or the first, I'm not sure) is the alpha channel. Don't mess with that one.
Aug 30, 2013 at 3:46am UTC
SDL_Surface *Redchannel (SDL_Surface *surface)
{
SDL_Surface *temp = surface;
int width = temp->w;
int height = temp->h;
int a, b;
Uint32 current_pixel;
if (SDL_MUSTLOCK (temp))
SDL_LockSurface (temp);
for (a=0; a<width;a++) {
for (b=0; b<height; b++) {
current_pixel = get_pixel32 (temp, a, b);
put_pixel32 (temp, a, b, current_pixel);
}
}
if (SDL_MUSTLOCK (temp))
SDL_UnlockSurface (temp);
return temp;
}
how i implement inside this function?
Last edited on Aug 30, 2013 at 3:49am UTC