GP32 Bmp ,don't Undestand Why It Doesn't Work


falken80

Certified Guru
Joined
Oct 15, 2003
Messages
452
Hi,

Just a little file to load and see a bmp.
I don't undestand why it doesn't work.
The bmp is 16bits, 320*240
but on gp32 it's very strange. ( big pixel, not good color )

Code:
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpfont.h"
#include "gpmm.h"

GPDRAWSURFACE gpDraw[2];

int nflip = 1;
uchar bitmap[320*240];
char load_bmp(char file_name[256], unsigned char * ptr);

void GpMain(void *arg)
{
	unsigned int i;
	for(i = 0; i < 2; ++i) GpLcdSurfaceGet(&gpDraw[i], i);
	GpSurfaceSet(&gpDraw[0]);
	GpFatInit();
	
	load_bmp("gp:\\gpmm\\pic.bmp", bitmap); 
	
	for(;;)
	{
  GpBitBlt16(NULL, &gpDraw[nflip], 0, 0, 320, 240, (uchar *)bitmap, 0, 0, 320, 240);
    GpSurfaceFlip(&gpDraw[nflip++]);
  nflip &= 0x01;
  
	}
}

char load_bmp(char file_name[256], unsigned char * ptr)
{	
	int heigh=240;
	int width=320;
  F_HANDLE img;
  long k2;
  ulong k;
  int x, y;
  unsigned char temp[320*240];
  

  if(GpFileOpen(file_name, OPEN_R, &img) == SM_OK)
  {
  	GpFileSeek(img, FROM_BEGIN, 54, &k2); // 54 = 16 bits
  	GpFileRead(img, &temp, width*heigh, &k);
  	GpFileClose(img);
  	for(y=0; y<heigh; y++)
    for(x=0; x<width; x++)
    	*(ptr+x*heigh+y)=temp[y*width+x];
  	return 1;
  }
  else return 0;
 }
 
Hmm...three things you should keep in mind.

1. I can't recommend starting at 0x36(54). Not all 16-bit BMP's will start there. You should read the Data Offset out of the BMP. It is a 4 Byte DWORD at position 0x0A.

2. Every line in a BMP MUST end in a 4 byte DWORD boudary.

3. You need to shift each color 1 to the left to account for the gp32 storing it's colors differently than Windows.

Let me know if you need any help. I spent the better portion of yesterday writing BMP loading code.
 
thanks...

i'm a real beginner with BMPs :) ( and dev ;) )

I can't recommend starting at 0x36(54). Not all 16-bit BMP's will start there. You should read the Data Offset out of the BMP. It is a 4 Byte DWORD at position 0x0A.
Ok it's just a test.. but if you have an idea..

Every line in a BMP MUST end in a 4 byte DWORD boudary.
Ok .. say me what i must change on the code...

You need to shift each color 1 to the left to account for the gp32 storing it's colors differently than Windows.
How ?

Thanks Dalto.. i need your help..
 
OK,

It's a little hard for me because I am unfamiliar with the gamepark SDK but I looked at you code in more detail and noticed a couple of other things.

Each color in a 16-bit BMP is represented by 2 bytes. You have declared temp as an unsigned char which is one byte. Instead make it a u16 or an unisgned short. Like this:

unsigned short temp[320*240];

You probably need to read twice as many bytes in your GPFileRead like this:
GpFileRead(img, &temp, width*heigh*2, &k);

ptr should probably be defined as unsigned short* as well.

The easiest was to shift something one bit left is to multiply it by 2. So this would make it look like this:
*(ptr+x*heigh+y)=temp[y*width+x]*2;

Does this help at all?
 
falken80 posted on Jul 18 2004 at 12:14 AM said:
Every line in a BMP MUST end in a 4 byte DWORD boudary.
Ok .. say me what i must change on the code...
Being aligned at 4 bytes just means that every line. Must be divisible by 4. So if your line is 40 byes long than it is ok, but if your line ends at byte 39 then you need to skip one byte in the buffer before you keep reading.

However, if all your images have width 320, you should not have to worry about this because each line will be aligned by default.
 
Last edited by a moderator:
thanks dalto. I undesrtand but.
...it doesn't work.

the result :
00000000.jpg
 
I had the same problem with mirko's sdk, I finally fixed it by converting my image with gpconverter and using DMA to load it.. works perfectly now, but I don't think the official SDK has DMA.
 
I have written BMP code into my games. If you still need it, contact me, and I can try to rip out some of the main functions for you.
 
big thanks flavor :) avseth, fagemul, rov, slubman help me and it works :)

thanks to you and all people like you :)
 
Back
Top