Bliting ....

Programming, for all ages and all languages.
Post Reply
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Bliting ....

Post by Perica »

..
Last edited by Perica on Tue Dec 05, 2006 9:25 pm, edited 1 time in total.
Tim

Re:Blit-ing ....

Post by Tim »

Bit blt is short for Bit BLock Transfer (the I in blit is sometimes added for pronunciation). It's just a funny term for copying bytes. Something as simple as memcpy can do blts.

A graphics blt routine could implement transparency; there are many ways to do this. The most intuitive to me is:

Code: Select all

void transparent_copy(pixel *dest, const pixel *src, int num_pixels, pixel transparent)
{
    int i;
    for (i = 0; i < num_pixels; i++)
        if (src[i] != transparent)
            dest[i] = src[i];
}
The point of this is, you don't bother touching pixels that don't need to be modified. Also, this doesn't read from anywhere other than src. Typically dest will point to video memory and src will point to a bitmap of the mouse pointer in system memory. (Reads from video memory are really slow.)

Searching for sprite routines in graphics libraries (e.g. SDL or Allegro) should reveal some more techniques.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Blit-ing ....

Post by Candy »

Tim Robinson wrote: Typically dest will point to video memory and src will point to a bitmap of the mouse pointer in system memory. (Reads from video memory are really slow.)
Then how would you suggest making a translucent mouse cursor? By copying the entire block from the video memory at once using some sort of proprietary bitblt or by reading each byte at a time? Which would be faster?
Tim

Re:Blit-ing ....

Post by Tim »

I would read the whole lot into system memory and then work from that copy, this being simpler.

I could only guess at which way would be faster; as always, write functions to do it both ways and profile them to see which works best.
Schol-R-LEA

Re:Blit-ing ....

Post by Schol-R-LEA »

Graphics are not a strong area of mine, but it occurs to me that, unless you are using video acceleration, it may be both faster and easier to do all of the drawing in in system memory, and move the image (or the changes to it) to an off-screen page of video memory only after completion, then after that switch screen pages.

Perhaps you could even two levels in system memory, one of the last drawn version and a 'mask' with the changes. The changes calculated from the complete image, but written to the mask, then written to video memory as above, then the mask would be written to the complete version in system memory as well to update it for the next cycle. I seem to recall hearing of techniques like this before; is this something actually used in graphics programming already? Does it make sense?
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Blit-ing ....

Post by df »

bit blitting i remember as an old term from amiga days when youd blit chunks in and out of amiga gfx memory and stuff...

the amiga had a coprocessor called the blitter chip, and using that to copy memory was 2 or 3 times more faster than using the 68k cpu to copy memory.. hence doing a bit blit was copying memory..
-- Stu --
Post Reply