[SDL] SDL slow load time?

Mark Buster mbuster at mchsi.com
Thu Mar 15 12:17:51 PDT 2007


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



More information about the SDL mailing list