Hi all!
I want to in effect do a getpixel from a SDL software surface.
I got the following code from the SDL docs to directly access the very fi=
rst=20
top left pixel in a surface:
fmt =3D source_img->format;
SDL_LockSurface(source_img);
pixel = ((Uint32)source_img->pixels);
SDL_UnlockSurface(source_img);
(I got the shifting and stuff to get actual RGB values down - also from t=
he=20
docs)
My question - how do I access all the rest of the pixels? I. e. by how mu=
ch=20
(or how?) do I increment ->pixels to get to the rest of the surface pixel=
=20
data?
What I tried was
pixel =3D ((Uint32)source_img->pixels + number_of_pixel_i_want *
fmt->BytesPerPixel)
But this does NOT work - I have a “red” surface (RGBA 234,23,23) and no m=
atter=20
what value I put in number_of_pixel_i_want I keep getting back stuff like=
=20
234,23,48 234,23,58 etc. - as if I am trying to index “between” pixels an=
d=20
getting back the “tail” of one pixel with a byte or more of the “head” of=
=20
another. The surface is 16 bpp “deep” in color depth, is a software surfa=
ce,=20
and BytesPerPixel has a value of 3.
How do I directly read any pixel I want from a SDL_Surface? Anybody got a
getpixel() for a SDL_Surface?
Thanks!–
Stefan Viljoen
Polar Design Solutions
Software Support Technician