Displaying data array

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
@Ed_Keith

Blog: edkeith.blogspot.com____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

How about SDL_CreateRGBSurfaceFrom?
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fCreateRGBSurfaceFromOn Fri, Mar 21, 2008 at 4:25 PM, Ed Keith <e_d_k at yahoo.com> 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?

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

You can create a surface (texture) that has a 24 bit format (RGB) and then
lock it. You can then write the data 3 bytes at a time (each triple
representing an RGB value). You will need to account for the actual byte
width of the surface when advancing to the next row since there can be pad
bytes at the end of a row.

Once you have done this you can unlock the surface, then blit it to the
screen or save it to file. This is about as fast as you will get. The only
other thing you can do is if your data doesn’t need 24 bits of color to
represent it and you can display it with 256 colors you can do the same
thing as above, but write out a byte at a type to represent a single pixel.
In that case you would create a 8 bit (paletted) surface.

Ken Rogoway
Homebrew Software
http://www.homebrewsoftware.com/> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Behalf Of Ed Keith
Sent: Friday, March 21, 2008 11:26 AM
To: sdl at lists.libsdl.org
Subject: [SDL] Displaying data array

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



Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.8/1338 - Release Date: 3/21/2008
5:52 PM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.8/1338 - Release Date: 3/21/2008
5:52 PM

I’ll try this.

Thanks,

-EdK

— Brian <brian.ripoff at gmail.com> wrote:

How about SDL_CreateRGBSurfaceFrom?

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fCreateRGBSurfaceFrom

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?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ed Keith
@Ed_Keith

Blog: edkeith.blogspot.com> On Fri, Mar 21, 2008 at 4:25 PM, Ed Keith <@Ed_Keith> wrote:

  ____________________________________________________________________________________

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

256 colors will be fine. the image is two colors fully
saturates. So each pixel will be in one of 4 states;
red, blue, magenta, or black.

I’ll give this a try.

thanks,

-EdK

— Ken Rogoway wrote:>

You can create a surface (texture) that has a 24 bit
format (RGB) and then
lock it. You can then write the data 3 bytes at a
time (each triple
representing an RGB value). You will need to
account for the actual byte
width of the surface when advancing to the next row
since there can be pad
bytes at the end of a row.

Once you have done this you can unlock the surface,
then blit it to the
screen or save it to file. This is about as fast as
you will get. The only
other thing you can do is if your data doesn’t need
24 bits of color to
represent it and you can display it with 256 colors
you can do the same
thing as above, but write out a byte at a type to
represent a single pixel.
In that case you would create a 8 bit (paletted)
surface.

Ken Rogoway
Homebrew Software
http://www.homebrewsoftware.com/

-----Original Message-----
From: sdl-bounces at lists.libsdl.org
[mailto:sdl-bounces at lists.libsdl.org] On
Behalf Of Ed Keith
Sent: Friday, March 21, 2008 11:26 AM
To: sdl at lists.libsdl.org
Subject: [SDL] Displaying data array

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
@Ed_Keith

Blog: edkeith.blogspot.com



Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.

http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.8/1338 -
Release Date: 3/21/2008
5:52 PM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.8/1338 -
Release Date: 3/21/2008
5:52 PM


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ed Keith
@Ed_Keith

Blog: edkeith.blogspot.com

  ____________________________________________________________________________________

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ