how to change the ordinary picture with only red channel in c++ programming?

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
how do i get use of this code?
wut

Can you please explain more clearly?
Last edited on
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
Apply negative.
Apply greyscale.
Map all non-red components to zero.
can you provide me a code since i am new to c++ :)
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.
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;

Read your documentation. The fourth (or the first, I'm not sure) is the alpha channel. Don't mess with that one.
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
Topic archived. No new replies allowed.