Raw pixel buffer

Hi

I’m pretty new to SDL and also moderately new to programming. I have some
unclear things about accessing the raw pixel buffer. My programming
experiences are limited to basic (C64, oh those days…) and since I’ve only
learnt C++ from those “real” languages, I haven’t much experience on C-style
typecasting.

I have quite sufficiently succeeded in creating a simple SetPixel() function
which takes three Uint8s as RGB data, two Uint16s as coordinates and a
surface and then maps the pixel on the screen. It only works on 16-bit
surfaces though, which I want to change. “Works” in this case is quite not
the right word, since I sometimes (very rarely) get a load of segmentation
faults. Messing with raw memory data is not something I master :(.

Now, instead of good ol’ “trial and error” method, I’d like to know the
exact answer. How do I work with raw pixel data? And how do I do it so that
it works on all bit-depths?

Thanx in advance
Petri Latvala

I have quite sufficiently succeeded in creating a simple SetPixel() function
which takes three Uint8s as RGB data, two Uint16s as coordinates and a
surface and then maps the pixel on the screen. It only works on 16-bit
surfaces though, which I want to change. “Works” in this case is quite not
the right word, since I sometimes (very rarely) get a load of segmentation
faults. Messing with raw memory data is not something I master :(.

The SDL Docs (http://sdldoc.csn.ul.ie/) have some examples, in
particular sample implementations of getpixel()/putpixel() functions:

http://sdldoc.csn.ul.ie/guidevideo.php

You may use them directly but they are mostly there to help you understand
direct pixel access, so you can write your own (faster) code for your
particular purpose. Don’t forget locking/unlocking