Bit blit

# Bit blit

Discussion

Encyclopedia
Bit BLIT is a computer graphics
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....

operation in which several bitmap
Bitmap
In computer graphics, a bitmap or pixmap is a type of memory organization or image file format used to store digital images. The term bitmap comes from the computer programming terminology, meaning just a map of bits, a spatially mapped array of bits. Now, along with pixmap, it commonly refers to...

s are combined into one using a raster operator.

The operation involves at least two bitmaps, a source and destination, and possibly a third that is often called the "mask". The pixels of each are combined bitwise according to the specified raster operation (ROP) and the result is then written to the destination. The RasterOp is essentially a boolean
Boolean logic
Boolean algebra is a logical calculus of truth values, developed by George Boole in the 1840s. It resembles the algebra of real numbers, but with the numeric operations of multiplication xy, addition x + y, and negation −x replaced by the respective logical operations of...

formula. The most obvious ROP overwrites the destination with the source. Other ROPs may involve AND
Logical conjunction
In logic and mathematics, a two-place logical operator and, also known as logical conjunction, results in true if both of its operands are true, otherwise the value of false....

, OR
Logical disjunction
In logic and mathematics, a two-place logical connective or, is a logical disjunction, also known as inclusive disjunction or alternation, that results in true whenever one or more of its operands are true. E.g. in this context, "A or B" is true if A is true, or if B is true, or if both A and B are...

, XOR, and NOT
Not
Not is the general declarative form of no, indicating a negation of a related statement which it usually precedes. "Not" may refer to:* Not!, an expression used as a contradiction, especially during the early 1990s...

operations. The Commodore Amiga's graphics chipset could combine three bitmaps according to any of 256 logic functions of three variables.

Modern graphics hardware and software has almost completely replaced bitwise operations with mathematical operations such as alpha compositing
Alpha compositing
In computer graphics, alpha compositing is the process of combining an image with a background to create the appearance of partial or full transparency. It is often useful to render image elements in separate passes, and then combine the resulting multiple 2D images into a single, final image in a...

. This is because bitwise operations on color displays do not produce results that resemble the physical combination of lights or inks. Some software still uses XOR to draw interactive highlight rectangles; when this is done to color images the unusual resulting colors are easily seen.

## Origins

The name derives from the BitBLT routine for the Xerox Alto
Xerox Alto
The Xerox Alto was one of the first computers designed for individual use , making it arguably what is now called a personal computer. It was developed at Xerox PARC in 1973...

computer
Computer
A computer is a programmable machine designed to sequentially and automatically carry out a sequence of arithmetic or logical operations. The particular sequence of operations can be changed readily, allowing the computer to solve more than one kind of problem...

, standing for bit block transfer. This operation was created by Dan Ingalls, Larry Tesler
Larry Tesler
Larry Tesler is a computer scientist working in the field of human-computer interaction. Tesler has worked at Xerox PARC, Apple Computer, Amazon.com, and Yahoo!...

, Bob Sproull
Bob Sproull
Dr Robert F. Sproull is an American computer scientist, who works for Oracle Corporation where he is director of Oracle Labs in Burlington, Massachusetts .- Biography :...

, and Diana Merry
Diana Merry
Diana Merry-Shapiro was a computer programmer for the Learning Research Group of Xerox PARC in the 1970s and 1980s, after having originally been hired as a secretary. As one of the original developers of the Smalltalk programming language, she wrote the first system for overlapping display windows...

at Xerox PARC
Xerox PARC
PARC , formerly Xerox PARC, is a research and co-development company in Palo Alto, California, with a distinguished reputation for its contributions to information technology and hardware systems....

in November 1975 for the Smalltalk-72 system. For the Smalltalk-74 system, Dan Ingalls later implemented a redesigned version in microcode
Microcode
Microcode is a layer of hardware-level instructions and/or data structures involved in the implementation of higher level machine code instructions in many computers and other processors; it resides in special high-speed memory and translates machine instructions into sequences of detailed...

.

The development of fast methods for various bit blit operations was key in the evolution of computer displays from using character graphics
Text mode
Text mode is a kind of computer display mode in which the content of the screen is internally represented in terms of characters rather than individual pixels. Typically, the screen consists of a uniform rectangular grid of character cells, each of which contains one of the characters of a...

, to using bitmap graphics
Raster graphics
In computer graphics, a raster graphics image, or bitmap, is a data structure representing a generally rectangular grid of pixels, or points of color, viewable via a monitor, paper, or other display medium...

for everything. Machines that rely heavily on the performance of 2D graphics
2D computer graphics
2D computer graphics is the computer-based generation of digital images—mostly from two-dimensional models and by techniques specific to them...

(such as video game console
Video game console
A video game console is an interactive entertainment computer or customized computer system that produces a video display signal which can be used with a display device to display a video game...

s) often have special-purpose circuitry called a blitter
Blitter
In a computer system, a blitter is a circuit, sometimes as a coprocessor or a logic block on a microprocessor, that is dedicated to the rapid movement and modification of data within that computer's memory...

.

## Example of a Masked blit implementation

A classic use for blitting is to render
Rendering (computer graphics)
Rendering is the process of generating an image from a model , by means of computer programs. A scene file contains objects in a strictly defined language or data structure; it would contain geometry, viewpoint, texture, lighting, and shading information as a description of the virtual scene...

transparent sprite
Sprite (computer graphics)
In computer graphics, a sprite is a two-dimensional image or animation that is integrated into a larger scene...

s onto a background. In this example a background image, a sprite, and a 1-bit mask are used. As the mask is 1-bit, there is no possibility for partial transparency via alpha blending.

A loop that examines each bit in the mask and copies the pixel
Pixel
In digital imaging, a pixel, or pel, is a single point in a raster image, or the smallest addressable screen element in a display device; it is the smallest unit of picture that can be represented or controlled....

from the sprite only if the mask is set will be much slower than hardware that can apply exactly the same operation to every pixel. Instead a masked blit can be implemented with two regular BitBlit operations using the AND and OR raster operations.
Background image Sprite (left) and mask (right)

The sprite is drawn in various positions over the image to produce this:
Intended Result

### Technique

When preparing the sprite and mask, the colors are very important. The mask pixels are 0 (black) wherever the corresponding sprite pixel is to be displayed, and 1 (white) wherever the background needs to be preserved. The sprite must be 0 (black) anywhere where it is supposed to be transparent, but note that black can be used in the non-transparent regions.

In the first blit, the mask is blitted onto the background using the raster operator of AND. Because any value ANDed with 0 equals 0, and any value ANDed with 1 is unchanged, black areas are created where the actual sprites will appear, while leaving the rest of the background alone.
Result of the first blit

In the second blit, the sprite is blitted onto the newly altered background using the raster operator of OR. Because any value ORed with 0 is unchanged, the background is unaffected and the black areas are filled with the actual sprite image.
Final result

It is also possible to achieve the same effect using a sprite with a white background and a white-on-black mask. In this case, the mask would be ORed first, and the sprite ANDed next.

## Blitting vs hardware sprites

Blitting is similar to hardware-sprite
Sprite (computer graphics)
In computer graphics, a sprite is a two-dimensional image or animation that is integrated into a larger scene...

drawing, in that both systems reproduce a pattern, typically a square area, at different locations on the screen. Hardware sprites have the advantage of being stored in separate memory, and therefore don't disturb the main display memory. This allows them to be moved about the display, covering the "background", with no effect on it.

Blitting moves the same types of patterns about the screen, but does so by writing into the same memory as the rest of the display. This means every time the pattern is placed on the screen, the display "under" it is overwritten, or "damaged". It is up to the software to clean this damage up by blitting twice, once to remove the damage, and then again to place the bit in its new location. However, there are several ways to optimize this. If large areas of the screen are taken over by the patterns, it may be more efficient to blit the background to the screen instead of erasing each pattern individually. A variation involves dividing the screen into segments and erasing only the segments where patterns have been drawn on. This technique is known as dirty rectangles.

As one might imagine, this makes blitting significantly slower than sprite manipulation. However blitting has one very big advantage: there's no physical limit to the number of patterns you can blit, or to the size of the patterns. Thus you can use blitting to display anything on the screen, including simulating sprites (through the double-write pattern noted above), or even text.