Archived

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

Bad_Maniac

I am really stuck. help me figure this out.

Recommended Posts

This is my basic 50 / 50 alpha blending blitter, but it produces non working result. What happens is, before calling this, both source and dest surfaces are locked, and WORD pointers are passed, then cast to DWORD pointers inside the function. it should be fairly straight forward... but for some reason, it blits garbage to the destination surface, but it's alpha blended garbage. so the function works, it's somewhere reading from the source image it gets screwed up. And I cannot figure this one out, so please give me a hand.
    
//---------------------------------------------------------------

//

//This is my 50/50 alpha blending routine, make DAMN sure the two surfaces are locked before calling this!

//

//---------------------------------------------------------------


void Fast_Alpha_Blit(WORD *src_surface, WORD *dest_surface, WORD src_pitch, WORD dest_pitch, RECT src_rect, int x, int y)
{
	int			i, j;
	int			dest_offset;
	int		        height, width;
	WORD*			src_temp = (WORD *)src_surface;
	WORD*			dest_temp = (WORD *)dest_surface;
	DWORD			stemp, dtemp;
	DWORD			result;


	//Set height and width

	height = src_rect.bottom - src_rect.top;
	width = src_rect.right - src_rect.left;

	dest_offset = x + (y * dest_pitch);
	//Process the surfaces, and write to the destinations

	width = width / 2;  //Process 2 pixels at a time, do NOT allow odd width sprites!!! 

		
	for (i = 0; i < height; i++)
	{
		for (j = 0; j < width; j += 2)
		{
			stemp = (DWORD)src_temp[(src_rect.left + j) + ((src_rect.top + i) * src_pitch)];
			dtemp = (DWORD)dest_temp[(j + (i * dest_pitch)) + dest_offset];

			result = dtemp;
			
			if ((stemp & 0xFFFF) != 0)
			{
				result &= 0xFFFF0000;
				result |= ((stemp & 0xF7DE) >> 1) + ((dtemp & 0xF7DE) >> 1);
			}
			
			if ((stemp >> 16) != 0)
			{
				result &= 0xFFFF;
				result |= ((stemp & 0xF7DE0000) >> 1) + ((dtemp & 0xF7DE0000) >> 1);
			}

			dest_temp[(j + (i * dest_pitch)) + dest_offset] = result;
		}
	}
}
    
Thanks for your time. //Martin [edited by - Bad_Maniac on November 7, 2002 3:14:20 PM]

Share this post


Link to post
Share on other sites
Okay, The line that plots the result has me interested.

dest_temp[(j + (i * dest_pitch)) + dest_offset] = result;

result is a DWORD but dest_temp is a WORD pointer!!

**shouldn't the complier generate a warning or error for that line**

Try this:

*(DWORD)&dest_temp[(j + (i * dest_pitch)) + dest_offset] = result;

Hope that helps.

[EDIT]
*(DWORD *)&dest_temp[(j + (i * dest_pitch)) + dest_offset] = result;

forgot the * in (DWORD *), sorry

[edited by - CodeJunkie on November 7, 2002 7:53:37 PM]

Share this post


Link to post
Share on other sites