Sdl & 24bits Picture Display


JyCet

Member
Joined
Feb 23, 2004
Messages
469
Age
118
Location
France
Website
Visit site
Hi all,
Another pb with sdl on gp2x (i dont know how many pb i've with this api :( )
I use paeryn hw sdl lib
and i've ~110fps to display a 8bits bmp picture on the lcd
and only ~22fps to diplay a 24bits bmp picture on the lcd
I think I do something wrong ... it's not possible to have this big (big) difference ?!
Here my code (it's the same for the 2 picture 8b or 24b)
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL/SDL.h>

#define GP2X_BUTTON_START		   (8)

SDL_Surface *bg;

SDL_Surface *screen;


void drawSprite(SDL_Surface* imageSurface, SDL_Surface* screenSurface, int srcX, int srcY, int dstX, int dstY, int width, int height)
{
	SDL_Rect srcRect;
	srcRect.x = srcX;
	srcRect.y = srcY;
	srcRect.w = width;
	srcRect.h = height;

	SDL_Rect dstRect;
	dstRect.x = dstX;
	dstRect.y = dstY;
	dstRect.w = width;
	dstRect.h = height;

	SDL_BlitSurface(imageSurface, &srcRect, screenSurface, &dstRect);
}

int main(int argc, char *argv[])
{
	int done = 0;
	
	SDL_Event event;
	
	SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);

	screen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE);
	SDL_ShowCursor (0); //desactive souris
	SDL_JoystickOpen(0);

	bg = SDL_LoadBMP("./bg.bmp");
	
	
	while (!done)
	{
		drawSprite(bg, screen, 0, 0, 0, 0, 320, 240);
		SDL_UpdateRect(screen, 0, 0, 0, 0);
		
		SDL_PollEvent(&event);
		if (event.type & SDL_JOYBUTTONDOWN ){
			if (event.jbutton.button==GP2X_BUTTON_START)
					done = 1;
		}
	}
	
	SDL_JoystickClose(0);
	chdir("/usr/gp2x");
	execl("gp2xmenu","gp2xmenu",NULL);
	SDL_Quit();
	return 0;
}

Do I miss something ? :(

Thanks
 
SDL on the GP2X works with a 16bit screen setup.

Why not try a high colour (16bit) image and add those results to the mix. Also worth noting that the SW_Surface you ask for is being converted to a HW_Surface behind the scenes.

Still rather then comment on your code all i'll mention is that you want to put a 24bit BMP (16.7 mil colours) onto a screen that is setup for 16bit (32,000 colours), it's safe to think that some conversion is going to have to take place to do that ;).
The 8bit image with it's 256 unique colous has no problem fitting into any 16bit setup you might want to mess with.
 
I already think about this possibility but my software cant convert to 16bpp bmp :(

I'll seach on and make some test

Thank for your suggession
 
JyCet posted on Aug 31 2006 at 01:52 PM said:
I already think about this possibility but my software cant convert to 16bpp bmp :(

I'll seach on and make some test

Thank for your suggession
SDL can convert them:
Code:
SDL_Surface* LoadImage(const char* Filename)
{
  SDL_Surface* Tmp = IMG_Load(Filename);
  if (Tmp)
  {
	SDL_Surface* Ret = SDL_DisplayFormat(Tmp);
	SDL_SetColorKey(Ret, SDL_SRCCOLORKEY, SDL_MapRGB(Ret->format, 255,0,255));
	SDL_FreeSurface(Tmp);
	return Ret;
  }
  return NULL;
}
http://www.penguin-soft.com/penguin/man/3/...playFormat.html
 
Last edited by a moderator:
Thank you !
It's incredible !
I've follow Daid example and add this code:
Code:
	SDL_Surface* Tmp = SDL_LoadBMP("./bg.bmp");
	bg = SDL_DisplayFormat(Tmp);
	SDL_FreeSurface(Tmp);

and now i've ~125fps !!
better than my 8bits BMP !

Incredible.

Thanks a lot :D
 
Back
Top