Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,
I am facing unknown problem with the below code. Although, I tried debug to find the bug, but all in vain..
So, here is my code
///////////N_TIMES = 6 Global Variable,D3DCOLOR Sprite_Car [ Car_Width * Car_Height ],Car_Width = 1376,Car_Height = 768////////////////
C#
struct Sprite
{
	int width;
	int height;
	D3DCOLOR key;
	D3DCOLOR* surface;
};
struct BitmapFileHeader
{             
   unsigned int fileSize;                   
   unsigned short reserved1, reserved2;
   unsigned int offsetToPixelData;                 
};

struct BitmapInfoHeader
{
   unsigned int headerSize;            
   int width,height;
   unsigned short planes;    
   unsigned short bits;      
   unsigned int compression;     
   unsigned int imageSize;       
   int xResolution,yResolution;  
   unsigned int nColors;        
   unsigned int importantColours;
};

struct Pixel24
{
	unsigned char blue;
	unsigned char green;
	unsigned char red;
};

for(int j=0;j<N_TIMES;j++)
    {
        Car[j].width = Car_Width;
        Car[j].height = Car_Height;
        Car[j].key=D3DCOLOR_XRGB(255,0,0);

    }

    for(int u=0;u<N_TIMES;u++)
    {
        D3DCOLOR Sprite_Car[ Car_Width * Car_Height ];
        Car[u].surface = Sprite_Car ;
        LoadImageBmp("Shapes\\img3.bmp",Car[u].surface,u);
    }

/////////////////LoadImageBmp- Function//////////////////////
void LoadImageBmp( const char* filename,D3DCOLOR* surface ,int ImgPart)
{
	FILE* bmpFile = fopen( filename,"rb" );

	char signature[ 2 ];
	fread( signature,sizeof( char ),2,bmpFile );
	assert(signature[ 0 ] == 'B' && signature[ 1 ] == 'M');

	BitmapFileHeader fileHeader;
	fread( &fileHeader,sizeof( fileHeader ),1,bmpFile );

	BitmapInfoHeader infoHeader;
	fread( &infoHeader,sizeof( infoHeader ),1,bmpFile );

	fseek( bmpFile,fileHeader.offsetToPixelData,SEEK_SET );

	int nPaddingBytesPerRow = (4 - ((infoHeader.width * 3) % 4)) % 4;
	for(int i=0;i<N_TIMES;i++)
	{
		for( int y = ((infoHeader.height)/N_TIMES)-1; y >= 0; y-- )
		{
			for( int x = 0; x < infoHeader.width; x++ )
			{
				Pixel24 pixel;
				fread( &pixel,sizeof( pixel ),1,bmpFile );
				if( i == ImgPart )
				{
					surface[ (x + y * (infoHeader.width)) ] = D3DCOLOR_XRGB( pixel.red,pixel.green,pixel.blue );
				}
			}
			fseek( bmpFile,nPaddingBytesPerRow,SEEK_CUR );
		}
	}
	fclose( bmpFile );
}
In main or ComposeFrame() func.  
for(int i=N_TIMES-1;i>=0;i--)
		{
			gfx.DrawSprite(0,sum,&Car[i]);
			sum +=128;
		} 

The function above load images pixel in D3DCOLOR Sruface [Car_Width*Car_Height], the DWORD D3DCOLOR Surface doesnot load pixel of higher resolution images, so, I convert the Image into patches and then tried to load the same image in 6 different Car[i].surface.

Check the result after compiling the code, https://www.dropbox.com/s/y706vqbghpga6zx/img.jpg[^]
and the orgional image was https://www.dropbox.com/s/mtrgww3sf85f0xd/Img2.bmp?m[^]
I am taking patches of pixel in 6 different Car[i].surface but the same pixel loads again and again

Any help plz.............
Posted
Updated 24-Jan-13 4:15am
v2
Comments
Sergey Alexandrovich Kryukov 24-Jan-13 14:47pm    
What "doesn't load" means? Insufficient memory exception, something else?
—SA
saad_lah 24-Jan-13 14:55pm    
Load or you can to initialize data(pixels) in surface[car_width*car_height].
but the limit exceeds as the size(car_width*car_height) or resolution of image increase and I am unable to store pixel data in surface, So I tried to store image in patches of N_TIMES(6) in array of Sprite Car. Everything works fine when i try to display image individually, but when i try to make it general just like above, it keeps on print or displaying same patch of image again and again :(
merano 24-Jan-13 18:50pm    
Is there a reason why you dont use the MSDN declarations ?

http://msdn.microsoft.com/en-us/library/windows/desktop/dd318229(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
saad_lah 25-Jan-13 2:30am    
@merano:: No, the struct BitmapInfoHeader and BitmapFileHeader is working fine..the porblem is with surface[...] which doesnot stores large number of pixels in it :(
Michael Haephrati 3-Mar-13 14:00pm    
Don't you need to allocate memory for Car[u].surface first?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900