Using AND OR to do blitting is a waste unless you are in GDI or something. This technique requires two blits and is wasteful.
Without MMX the most you can blit at one time is:
8 bits per pixel - 4 pixels
16 bits per pixel - 2 pixels
32 bit per pixel - 1 pixel
A stosd is the most you can blit without using SIMD instructions.
Code:
void Blit(DWORD *pScreen,RGBA *pImage,int x,int y,int image_width,int image_height,int buffer_pitch)
{
unsigned long buffer_offset = y * buffer_pitch + x;
unsigned long actual_buffer_offset = buffer_offset;
unsigned long image_offset = 0;
int y_counter = 0;
int x_counter = 0;
while (y_counter < image_height)
{
pScreen[actual_buffer_offset] = pImage[image_offset];
actual_buffer_offset++;
image_offset++;
x_counter++;
if (x_counter > image_width)
{
x_counter = 0;
y_counter++;
buffer_offset += buffer_pitch;
actual_buffer_offset = buffer_offset;
}
}
}
This blit does not take into account the edges of the screen. It also does not take into account transparent pixels or alpha.