1 / 20

Computer Graphics Bitmaps & Sprites

Learn about the basics of bitmap graphics, file formats, sprites, blending methods, transparency, and alpha data in computer graphics.

Download Presentation

Computer Graphics Bitmaps & Sprites

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer GraphicsBitmaps & Sprites CO2409 Computer Graphics Week 3

  2. Today’s Lecture • Bitmaps & File Formats • Sprites • Blending Methods • Transparency / Alpha Data • Alpha Blending

  3. Limitations of 2D Geometry • Rendering 2D geometry is simplistic, but can be effective for: • Line drawings • Vector-based work • Simple graphic design • But to render anything complex would need excessive detail • Use another method…

  4. Bitmaps • A bitmap is rectangle of pixels stored off-screen • Bitmaps can come from several sources: • Hand-drawn (e.g. using Photoshop, Maya or even last week’s PixelPlotter) • A single capture from a camera, scanner or video • Other 2D data, e.g. satellite data • An algorithm for generating pixels (procedural textures)

  5. Displaying Bitmaps • The pixels of a bitmap are usually copied into a rectangular region of a viewport • Can be the entire viewport (a background) • If region copied to is same size as the bitmap this is a simple pixel-by-pixel copy • Otherwise the bitmap will must be scaled • Will see details this operation when we look at textures • We can also copy a bitmap to a rotated or distorted region – a more complex process • These operations can be done in hardware

  6. Bitmap File Formats • We usually need to store bitmaps for reuse • There are many possible data formats, each with different benefits and drawbacks: • BMP (Windows bitmap) • JPEG (.jpg) (Joint Photographic Experts Group) • GIF (Graphics Interchange Format) • PNG (Portable Network Graphics) • TGA (Truevision Targa) • DDS (DirectDraw Surface – bitmap for DirectX) • And many more… • One of the example bitmaps earlier would not typically be stored in a file, which one?

  7. General Bitmap Format • Most bitmap formats contain additional data apart from the pixels: • Width and Height • Colour space/range (e.g. RGB 0-255) • Other data can be stored: • E.g. printing size, title, comments, pixel format etc. • Pixel data may be stored in a range of formats: • Raw pixel data (R, G & B values): TGA, BMP • Compressed: GIF (zip), TGA,BMP (RLE) • Lossy Compressed: JPEG

  8. Bitmap Compression • Pixel data can be compressed in most formats • Some compression methods only store an approximation of the pixels for better compression • Called lossy compression • The idea is that the eye does not notice the inaccuracies • Jpeg’s are a notable example • Repeatedly saving in a lossy format will degrade quality • Lossy compression schemes can reduce data size 100x or more PNG format (Non-Lossy Compressed) JPEG (Lossy)

  9. Sprites • A sprite is a name given to a particular use of bitmaps • Sprites are used as distinct elements in a larger scene, e.g: • A character in a 2D game • A mouse cursor • A letter in a font • Sprites may be layered (perhaps with a background image) to create a complex picture. • Example is from Metal Slug 3

  10. Pixel Data for Sprites • Sprites usually represent non-rectangular objects • Cannot just copy data from bitmap to viewport as described above • The bitmap rectangle will obscure any detail below • Need to overlay the sprite with the background in some way: • Using cutout or blending methods

  11. Pixel Blending • Pixel blending are methods to combine the RGB colours in the bitmap with those already on the viewport • We use a blending equation to precisely specify the method used • Different blending equations give different effects • Blending creates various forms of transparency: • Semi-transparent objects: glass, plastic, membranes • Effects that brighten the scene: fire, glow, lens flare • Or obscure (darken) the scene: smoke, dust, shadows • Plus other effects: e.g. user interface elements

  12. Multiplicative Blending • The multiplicative blending equation is: Final.Red = Bitmap.Red * Viewport.Red Similar for green and blue, RGB range is [0-1] • Combine bitmap pixel colour with existing viewport pixel colour • Final colour the new colour written to the viewport • Do seperately for R, G & B • If RGB in range 0-255, result would need to be divided by 255 • This is a darkening effect, suitable for representation of glass, shadows, smoke etc • If source pixel is white, destination colour stays same • As source pixel tends to black, destination is darkened

  13. Multiplicative Blending Example Test Pattern Multiplicative Smoke

  14. Additive Blending and Others • The additive blending equation is: Final.Red = Bitmap.Red + Viewport.Red Similar for green and blue, RGB range is [0-1] or [0-255] • This is a lightening effect, mainly used for the representation of lights • Bitmap black = no effect, brightens as bitmap becomes whiter • Many other blending equations are possible, e.g.: Final.Red = 2 * (Bitmap.Red * Viewport.Red) • Darkens & lightens depending on bitmap colour Final.Red = (Bitmap.Red + Viewport.Red) / 2 • Average of bitmap and viewport colour

  15. Additive Blending Example Test Pattern Additive Flare

  16. Transparency / Alpha Data • The previous examples used RGB data only • For each pixel can store an extra value to identify if the pixel is transparent or not • Can be a single bit: • 1: visible, 0: transparent • Or sometimes the other way round • This is called Alpha data, or the alpha channel • Using this data we can draw a cutout sprite: • Only copy the pixels that have a non-zero alpha value

  17. Blending using Alpha • We can specify a range of alpha values for a pixel (not just 0 or 1) • Allowing us to set a level of transparency for the pixel • Allows semi-transparent pixels • Alpha values are usually in the range 0-255 or 0.0-1.0 and are called A • Treated just like R, G and B • Packed together with RGB to make RGBA colours • Can use this alpha channel in blending methods • Usually only the bitmap alpha value is used • Generally avoid use of viewport alpha

  18. Alpha Blending • The usual alpha blending equation is: Final.Red = Bitmap.Red * Bitmap.Alpha + Destination.Red * (1 – Bitmap.Alpha) Similar for green and blue, RGBA range is [0-1] • [N.B. This formula is a linear interpolation between bitmap and viewport colour – we will see this formula again] • Notice how only the bitmap alpha is used • Alpha blending allows for variable transparency based on the alpha value • Low alpha = very transparent, high alpha = very opaque • It can be used for precise transparency effects

  19. Alpha Blending Example Test Pattern RGB Channel Alpha allows variable transparency Alpha Channel

  20. Packed Pixel Data with Alpha • So we have now identified four channels of data for a typical pixel: • Red, Green, Blue and Alpha • Such data is often called ARGB or RGBA data • If each channel is a byte (0-255) then a single pixel is a double-word (4 bytes) • Efficient for hardware, called ARGB 8888 format • There are other packing schemes: • 1 bit for A, 5 bits for R,G & B: ARGB 1555 format • 4 bits each for A, R, G & B: ARGB 4444 format • 5 bits for R & B, 6 for G, 0 for A: RGB 565 • 32 bit floats for each: ARGB 32F32F32F32F • These will be relevant for GPU-based graphics later…

More Related