I don’t do much with pure SDL (mostly I use it to get cross-platform
input and context for OpenGL), but depending on how the memory is
stored for SDL_Image structures, you might be able to just do a
memcpy() from your array to each R, G, and B channel, assuming that
you want a grayscale image. This assumes that the pixel data in
SDL_Images are arranged with all the similarly colored data together,
and I just don’t know that. It’s entirely possible that they aren’t,
which scraps this paragraph.
More realistically, though, how often do you update the data in the
array? If not that often (or at all) you could likely very easily
just create a new image, copy the data (pixel-by-pixel) to the image,
and then just blit the image as you normally would.
Lastly, if you do need to update, say, every frame, how bad is it
ACTUALLY to just iterate through the array and write pixels to
offscreen memory (an image structure) and then draw the image as
normal? I bet if you tried it you may be surprised. If it’s just a
loop that does some memory copies to an incrementing position in the
image structure, you may find yourself surprised by just how fast 1+
GHz actually is. ~_^
And lastly, if you have already tried it and it IS actually too slow,
feel free to completely ignore the previous paragraph. =D
– ScottOn Mar 21, 2008, at 10:25 AM, Ed Keith wrote:
I have an array of data in memory that I want to
display as an image. I can think of two ways of doing
this, but do not like either one.
I could write the array to the screen pixel by pixel.
I suspect this will be very slow.
I could write the data to a bit map file and read the
file into the display. I do not like all this
unnecessary disk access.
Can anyone suggest a better way?
thank you,
-EdK
Ed Keith
e_d_k at yahoo.com
Blog: edkeith.blogspot.com