SDL slow load time?

OK, so I’m brand new to SDL, and (hopefully) I’m doing something completely
wrong here. I say hopefully, because it seems to take a very long time to load a
picture onto the screen. This code is running on embedded linux on a 200mhz
ARM, which I would think would be powerful enough to handle this, but like I
said, I’m new to graphics.

Here’s a chunk:
//------------------------------
/* load a new screen */
void new_screen(char *fname){

SDL_Rect src;
SDL_Rect dest;

	
/* get the config info for the page */	
readxml(fname, 0, PAGEXML);

/* build screens in buffer  */
src.x =  0;
src.y =  0;
src.w = SCRN_WIDTH;
src.h = SCRN_HEIGHT - 35;

DrawImage(bgscreen,curpath,page.bgimage, 0, 0);
SDL_BlitSurface ( bgscreen, NULL, tmpscreen, NULL );	
SDL_BlitSurface ( bgscreen, &src, bseltmp, NULL );	
SDL_BlitSurface ( bgscreen, &src, bunseltmp, NULL );
SDL_BlitSurface ( tmpscreen, &src, screen, NULL );	

}

int DrawImage( SDL_Surface *Surface, char *skin_path, char *image_path, int
x_pos, int y_pos )
{
char stmp[200];
SDL_Rect rcDest = { 0, 0, 0, 0 };
SDL_Rect rcSrc = { 0, 0, 0, 0 };
SDL_Surface *image;
SDL_Surface *optimage;
sprintf(stmp,"%s%s",skin_path, image_path);
image = IMG_Load ( stmp );

if ( !image )
{
/handle error/
return 1;
}
optimage = SDL_DisplayFormat(image);
SDL_FreeSurface(image);

rcDest.x = x_pos;
rcDest.y = y_pos;
last_w = image->w;
last_h = image->h;
SDL_BlitSurface ( optimage, NULL, screen, NULL );
if((y_pos > 564) && (image->h > 38))
{
rcSrc.h = 38;
rcSrc.y = (image->h /2) - 19;
rcSrc.w = image->w;
rcSrc.x = 0;
SDL_BlitSurface ( optimage, &rcSrc, Surface, &rcDest );
SDL_FreeSurface ( optimage );
return 0;
}

SDL_BlitSurface ( optimage, NULL, Surface, &rcDest );
SDL_FreeSurface ( optimage );
return 0;
}

//-End code//

This takes about 4 seconds to load a 100KB .png file. Is this to be expected or
am I doing something silly?
Thanks, Mark

OK, so I’m brand new to SDL, and (hopefully) I’m doing something completely
wrong here. I say hopefully, because it seems to take a very long time to load a
picture onto the screen. This code is running on embedded linux on a 200mhz
ARM, which I would think would be powerful enough to handle this, but like I
said, I’m new to graphics.

Here’s a chunk:
//------------------------------
/* load a new screen */
void new_screen(char *fname){

SDL_Rect src;
SDL_Rect dest;

/* get the config info for the page */
readxml(fname, 0, PAGEXML);

/* build screens in buffer */
src.x = 0;
src.y = 0;
src.w = SCRN_WIDTH;
src.h = SCRN_HEIGHT - 35;

DrawImage(bgscreen,curpath,page.bgimage, 0, 0);
SDL_BlitSurface ( bgscreen, NULL, tmpscreen, NULL );
SDL_BlitSurface ( bgscreen, &src, bseltmp, NULL );
SDL_BlitSurface ( bgscreen, &src, bunseltmp, NULL );
SDL_BlitSurface ( tmpscreen, &src, screen, NULL );

}

int DrawImage( SDL_Surface *Surface, char *skin_path, char *image_path, int
x_pos, int y_pos )
{
char stmp[200];
SDL_Rect rcDest = { 0, 0, 0, 0 };
SDL_Rect rcSrc = { 0, 0, 0, 0 };
SDL_Surface *image;
SDL_Surface *optimage;
sprintf(stmp,"%s%s",skin_path, image_path);
image = IMG_Load ( stmp );

if ( !image )
{
/handle error/
return 1;
}
optimage = SDL_DisplayFormat(image);
SDL_FreeSurface(image);

rcDest.x = x_pos;
rcDest.y = y_pos;
last_w = image->w;
last_h = image->h;
SDL_BlitSurface ( optimage, NULL, screen, NULL );
if((y_pos > 564) && (image->h > 38))
{
rcSrc.h = 38;
rcSrc.y = (image->h /2) - 19;
rcSrc.w = image->w;
rcSrc.x = 0;
SDL_BlitSurface ( optimage, &rcSrc, Surface, &rcDest );
SDL_FreeSurface ( optimage );
return 0;
}

SDL_BlitSurface ( optimage, NULL, Surface, &rcDest );
SDL_FreeSurface ( optimage );
return 0;
}

//-End code//

This takes about 4 seconds to load a 100KB .png file. Is this to be expected or
am I doing something silly?
Thanks, Mark


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
On Thu, 15 Mar 2007, Mark Buster wrote:

Sorry for my empty respons erarlier…

OK, so I’m brand new to SDL, and (hopefully) I’m doing something completely
wrong here. I say hopefully, because it seems to take a very long time to load a
picture onto the screen. This code is running on embedded linux on a 200mhz
ARM, which I would think would be powerful enough to handle this, but like I
said, I’m new to graphics.

Rule 1: Profile. Add some SDL_GetTicks() to the code and see where it is
spending most of it’s time. Is it reading the XML (readxml), loading the
png (IMG_Load) och copying data back and forth (all SDL_BlitSurface
calls)?

Here’s a chunk:
//------------------------------
/* load a new screen */
void new_screen(char *fname){

SDL_Rect src;
SDL_Rect dest;

/* get the config info for the page */
readxml(fname, 0, PAGEXML);

See, this is your problem right here! :wink:

In my experience most XML libraries is quite bloated if all you need is a
simple config reader, and I prefer fscanf or flex/bison for such tasks. Of
course it may be because I was using flex/bison since before I ever heard
of XML…

DrawImage(bgscreen,curpath,page.bgimage, 0, 0);
SDL_BlitSurface ( bgscreen, NULL, tmpscreen, NULL );
SDL_BlitSurface ( bgscreen, &src, bseltmp, NULL );
SDL_BlitSurface ( bgscreen, &src, bunseltmp, NULL );
SDL_BlitSurface ( tmpscreen, &src, screen, NULL );

What is the difference between bgscreen and tmpscreen? Most likely one of
them is not nececary.

Are you using alpha/transparency?

char stmp[200];
sprintf(stmp,"%s%s",skin_path, image_path);
image = IMG_Load ( stmp );

Security tip of the day: This is a buffer overrun vulnerability! And since
image_path comes from your skin descriptor, you are unknowingly aiding in
the creation of virus/worms/SPAM botnets. Beware!

Make a habit of ALWAYS use code like this instead:

char *stmp = malloc(strlen(skin_path) + strlen(image_path) + 1));
sprintf(stmp,"%s%s",skin_path, image_path);
image = IMG_Load( stmp );
free(stmp);

Also beware that some str*n functions add the terminating \0 byte and some
don’t.

optimage = SDL_DisplayFormat(image);

This is totaly unnececary, since SDL_BlitSurface can perform this
transformation on the fly.

Simple performance guideline: SDL_DisplayFormat is only useful for
surfaces that are drawn to the screen each frame.

SDL_BlitSurface ( optimage, NULL, screen, NULL );

This is not nececary, since it is also done by new_screen() that calls
this function. Do it in one of the functions, but not both.

This takes about 4 seconds to load a 100KB .png file. Is this to be expected or
am I doing something silly?

How large is the screen/image? How fast is the I/O you are reading it
from?On Thu, 15 Mar 2007, Mark Buster wrote:

Mattias Karlsson <betasoft acc.umu.se> writes:
Thanks for the help Mattias (though I haven’t fixed it yet). I’m still learning,
and you definitely taught me a couple of things.
The buffer overrun thing looks like a sound practice to me.
I’ll be applying this one quite a bit.
I did start placing some GetTicks around, and have gotten a good picture of
what’s going on. Here’s a quick breakdown:

readxml() - 4ms

image = IMG_Load ( stmp ); - about 1100ms

each BlitSurface() - about 60-80ms

So it looks like a cumulative effect, with IMG_Load being the worst culprit.
By the way, we’re drawing to a 16bit 800x600 screen.

Thanks for the input, any further insight?

200 MHz?! O_O

I’d try it on another comp and see if it runs faster. :wink:

Mark Buster wrote:> OK, so I’m brand new to SDL, and (hopefully) I’m doing something completely

wrong here. I say hopefully, because it seems to take a very long time to load a
picture onto the screen. This code is running on embedded linux on a 200mhz
ARM, which I would think would be powerful enough to handle this, but like I
said, I’m new to graphics.

Here’s a chunk:
//------------------------------
/* load a new screen */
void new_screen(char *fname){

SDL_Rect src;
SDL_Rect dest;

/* get the config info for the page */
readxml(fname, 0, PAGEXML);

/* build screens in buffer */
src.x = 0;
src.y = 0;
src.w = SCRN_WIDTH;
src.h = SCRN_HEIGHT - 35;

DrawImage(bgscreen,curpath,page.bgimage, 0, 0);
SDL_BlitSurface ( bgscreen, NULL, tmpscreen, NULL );
SDL_BlitSurface ( bgscreen, &src, bseltmp, NULL );
SDL_BlitSurface ( bgscreen, &src, bunseltmp, NULL );
SDL_BlitSurface ( tmpscreen, &src, screen, NULL );

}

int DrawImage( SDL_Surface *Surface, char *skin_path, char *image_path, int
x_pos, int y_pos )
{
char stmp[200];
SDL_Rect rcDest = { 0, 0, 0, 0 };
SDL_Rect rcSrc = { 0, 0, 0, 0 };
SDL_Surface *image;
SDL_Surface *optimage;
sprintf(stmp,"%s%s",skin_path, image_path);
image = IMG_Load ( stmp );

if ( !image )
{
/handle error/
return 1;
}
optimage = SDL_DisplayFormat(image);
SDL_FreeSurface(image);

rcDest.x = x_pos;
rcDest.y = y_pos;
last_w = image->w;
last_h = image->h;
SDL_BlitSurface ( optimage, NULL, screen, NULL );
if((y_pos > 564) && (image->h > 38))
{
rcSrc.h = 38;
rcSrc.y = (image->h /2) - 19;
rcSrc.w = image->w;
rcSrc.x = 0;
SDL_BlitSurface ( optimage, &rcSrc, Surface, &rcDest );
SDL_FreeSurface ( optimage );
return 0;
}

SDL_BlitSurface ( optimage, NULL, Surface, &rcDest );
SDL_FreeSurface ( optimage );
return 0;
}

//-End code//

This takes about 4 seconds to load a 100KB .png file. Is this to be expected or
am I doing something silly?
Thanks, Mark

L-28C <kixdemp gmail.com> writes:

200 MHz?! O_O

I’d try it on another comp and see if it runs faster.

Well, the only thing this code is ever going to run on is this embedded 200mhz
ARM processor. It’s for a hardware specific application. I was hoping to find
out if this was all the performance one could expect from this chip, or if I was
using SDL improperly (or inefficiently).

Quoting Mark Buster :

*->
*-> L-28C <kixdemp gmail.com> writes:
*->
*-> >
*-> > 200 MHz?! O_O
*-> >
*-> > I’d try it on another comp and see if it runs faster.
*->

some idiots wont be happy until there computers are the temprature of the sun

ARM Proccesor buddy! not some monkey nuts and selotape cisc pile of smoulder!

anyways

*-> >
*-> Well, the only thing this code is ever going to run on is this embedded
*-> 200mhz
*-> ARM processor. It’s for a hardware specific application. I was hoping to
*-> find
*-> out if this was all the performance one could expect from this chip, or if
*-> I was
*-> using SDL improperly (or inefficiently).
*->

I’m not sure if you are talking about loading a png or creating then displaying
a png, what’s the screen size? what is the code for?

having written and proted alot of stuff for a RISC PC with a 233ish mhz i can
quite safly say that a load of SDL games are very badly written i rember a
remake of a spectrum game that should have run ok but the code was so bloates

anyways

we dont know whats driving your graphics either

maybe you should try compiling some other SDL code ( google crazeeman i wrote it
its easy compile )

perhaps the SDL sources may be needeed to be tuned into your chip and distro

not enough information really

i guess

i’ll shut up now–

Nice.


This message was sent using IMP, the Internet Messaging Program.

This code is running on embedded linux on a 200mhz
ARM, which I would think would be powerful enough to handle this, but like I
said, I’m new to graphics.

yea well, my webmail has decided to put away the sane posts for this post

just to say that when i actually did a real game running on an 200mhzish ARM
i made sure that the screen was only ever updated where it needed to be updated
rather than redrawing the entire screen surface every time.

but you may have a better gfx chip.

ok i’ll shut up now.----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.