Click here to Skip to main content
13,449,155 members (46,741 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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////////////////
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;


    for(int u=0;u<N_TIMES;u++)
        D3DCOLOR Sprite_Car[ Car_Width * Car_Height ];
        Car[u].surface = Sprite_Car ;

/////////////////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(,, );
			fseek( bmpFile,nPaddingBytesPerRow,SEEK_CUR );
	fclose( bmpFile );
In main or ComposeFrame() func.  
for(int i=N_TIMES-1;i>=0;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,[^]
and the orgional image was[^]
I am taking patches of pixel in 6 different Car[i].surface but the same pixel loads again and again

Any help plz.............
Posted 24-Jan-13 4:09am
Updated 24-Jan-13 4:15am
Sergey Alexandrovich Kryukov 24-Jan-13 14:47pm
What "doesn't load" means? Insufficient memory exception, something else?
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 ?
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?
saad_lah 4-Mar-13 0:05am
yea,... and I have done the step a for loop
D3DCOLOR Sprite_Car[ Car_Width * Car_Height ];
Car[u].surface = Sprite_Car ;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180318.3 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100