18
Tools for Raster Displays CVGLab

Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Embed Size (px)

Citation preview

Page 1: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Tools for Raster Displays

CVGLab

Page 2: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Goals of the Chapter

To describe pixmaps and useful operations on them.

To develop tools for copying, scaling, and rotating pixmaps.

To discuss different drawing modes, such as XOR mode.

To develop tools for compositing images.

To develop ways to define and and manipulate regions.

To develop Bresenham’s line-drawing algorithm.

To build tools for filling regions-particularly polygon-defined ones.

To discuss aliasing and to develop antialiasing methods.

To develop dithering and error-diffusion tools for creating more gray levels.

Page 3: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Introduction

Showing ways to draw lines and to fill polygons with colors and textures.

The rasterization step in the graphics pipeline.

Page 4: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Manipulating Pixmaps

1. Operations of Interest for PixmapsDrawing a Picture

Copying a Pixmap from One Place to Another

-. read operation

-. draw operation

• glRead Pixels( ) ; ← reads a region of the frame buffer into off-screen memory

• glCopyPixels( ) ; ← copies a region of the frame buffer into another part of the frame buffer

• glDrawPixels( ) ; ← draws a given pixmap into the frame buffer

Page 5: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Manipulating Pixmaps

2. Useful Data Types for Pixmaps -. The bitmap: Each pixel is stored in a single bit, so each pixel is either

“on” or “off.” -. The gray-scale pixmap: Each pixel is stored in a single byte, representing

levels of gray from 0 for black up to 255 for white. -. LUT indices: Each pixel contains a number that represents an index into a

color lookup table(LUT). Very often, the LUT contains 256 entries, so an index value can be stored in a single byte.

-. The RGB pixmap: Each pixel consists of three bytes, one each for the red, green, and blue components of the pixel. Such pixels are considered to represent “true color.”

-. The RGBA pixel: Each pixel consists of four bytes: the same three as n the RGB pixmap and a fourth byte that contains an “alpha value,” which represents opacity.

Page 6: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Manipulating Pixmaps

3. Scaling and Rotating Images

-. In scaling a pixmap by some factor, s: when s is larger than unity, the pixmap is enlarged; otherwise it is reduced.

-. glPixelZoom (sx, 1);

glutPostRedisplay ( );

Multiple versions of a pixmap formed by scaling in x.

Page 7: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Manipulating Pixmaps

More General Scaling and Rotations

Computing the transformed image

Page 8: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Combining Pixmaps

• Combining pix maps is useful for such things as moving cursors around a screen, comparing two images, and morphing one image into another.

• Tow pixmaps A and B are combined to form a third pixmap C

].][[]][[]][[

].][[]][[]][[

]).][[]][[(2

1]][[

,],][[]][[]][[

jiBjiAjiC

jiBjiAjiC

jiBjiAjiC

jieachforjiBjiAjiC

Page 9: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Combining Pixmaps

1. The Read-Modify-Write CycleFirst the pixels in D are read from memory, then they are modified by combining them with the pixels of S, and finally, the result is written back into D.

A read-modify-write cycle applied to the frame buffer.

2. The Alpha Channel and Image Blending

255

].][[

,].][[)1(].][[].][[

ajiSa

frationthewhere

gjiDagjiaSgjiD

Page 10: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Combining Pixmaps

glblendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

3. Logical Combinations of Pixmaps -. Other way of combining pixmap.

-. The pixmaps are combined pixel by pixel as before, but the bits in a pixel are combined logically, bit by bit.

Page 11: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Combining Pixmaps

-. OR-ed, AND-ed, EXCLUSIVE OR-ed…

ex) A RGB (21, 127, 0) → (00010101, 01111111, 00000000)

B → (01010101, 11110000, 10000101)

C = (01010101, 11111111, 10000101) ← the OR of A and B.

C = (01000000, 10001111, 10000101) ← the XOR of A and B.

Possible logical operations in OpenGL.

Effect of various logical operations..

Page 12: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Combining Pixmaps

Page 13: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Combining Pixmaps

4. The BitBLT Operation -. Stands for bit boundary block transfer.

Definition of the BitBLT Operation

-. The BitBLT copies source pixels S to the destination rectangle D using the logical combination method described earlier:

Various choices for are available.

-. Most BitBLT processors: clipping rectangle.

SDD

Page 14: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Do-It-Yourself Line Erawing:Fresenham’s Algorithm

Bresenham’s line-drawing algorithm – present a much faster method.

-. the ideal line satisfies the equation

xx

yy

xx

yx

ab

abm

andbandabetweeniesxwhere

aaxmy

var

)(

float y = a.y; // initial valuefor (int x = a.x; x<=b.x; x++, +=m)setpixel(x, round(y));

Page 15: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Do-It-Yourself Line Erawing:Fresenham’s Algorithm

1. Bresenham’s Line-Drawing Algorithm -. Offers a significant advantage over the method just set out, as it

avoids floating-point arithmetic and rounding.

-. midpoint algorithm: produces the same pixels as bresenham’s

algorithm for straight lines, and its approach can be extended directly

to the drawing of more complex shapes such as circles and ellipses.

)(2)(2),(

0)()(

xy

xy

axHayWyxf

axHayW

Page 16: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Do-It-Yourself Line Erawing:Fresenham’s Algorithm

-. The important property of F(x, y) is that its sign tells whether (x, y) lies above or below the ideal line:

if F(x, y) < 0 then (x, y) lies above the line;

if F(x, y) > 0 then (x, y) lies below the line;

Page 17: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Do-It-Yourself Line Erawing:Fresenham’s Algorithm

Removing the Restrictions on Bresenham’s Algorithm

-. To Get the Same Line when ax > bx.

-. Lines Having Slope Greater than Unity.

-. Lines with Negative Slopes.

-. Horizontal and Vertical Lines.

Summary of Properties a Drawn Line Should Have

-. Straight, pass both of the given endpoints.

-. Smooth and have uniform brightness along its length.

-. Repeatable.

-. (bx, by) to (ax, ay) = (ax, ay) to (bx, by).

Page 18: Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating

Do-It-Yourself Line Erawing:Fresenham’s Algorithm

Drawing Lines in Patterns

-. It is simple to incorporate such patterns into Bresenham’s algorithm.