Archived

This topic is now archived and is closed to further replies.

emileej

>>Paradigm 2000: Problems with your bitmapdrawing rutine

Recommended Posts

emileej    130
Please write me - in that way it''ll be much less complicated - solving problems in your WinBitmap class. This code draws the bitmap data, but all messed up - not eaven the colors match:
  
LPDIRECTDRAWSURFACE CWINBitmap::DrawToSurface(IDirectDraw *pdd){
	DDSURFACEDESC ddsd;
	LPDIRECTDRAWSURFACE lpddsurface=CreateOffScreenSurface(pdd, GetWidth(), abs(GetHeight()));
	ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
	ddsd.dwSize = sizeof(DDSURFACEDESC);
	unsigned char * videobuffer = NULL;
	unsigned char * filebuffer = GetImagePtr();
	lpddsurface->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	videobuffer = (unsigned char *)(ddsd.lpSurface);
	int pointerscale = (GetColorDepth())>>3;
	unsigned int padding = 4 - ((GetWidth()*pointerscale) % 4);
	if(padding == 4)
		padding = 0;
	unsigned long linesize = (GetWidth()*pointerscale) + padding;
	int j = 0;
	if(GetHeight() > 0){
		for(int i = GetHeight() - 1; i >= 0; i--){
			memcpy(&videobuffer[j*ddsd.lPitch],&filebuffer[i*linesize],GetWidth()*pointerscale);
			j++;
		}
	}else{
		unsigned long height = -GetHeight();
		for(int i = 0; i < GetHeight(); i++){
			memcpy(&videobuffer[i*ddsd.lPitch],&filebuffer[i*linesize],GetWidth()*pointerscale);
		}
	}
	lpddsurface->Unlock(videobuffer);
	return lpddsurface;
}
  
------------- E-)mil http://eej.dk - Just another crazy dane

Share this post


Link to post
Share on other sites