Docsity

Manipulating Raster Graphics: Pixmaps, Scaling, Rotating, and Combining, Slides of Computer Graphics

Partial preview of the text

Download Manipulating Raster Graphics: Pixmaps, Scaling, Rotating, and Combining and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics Raster Graphics: Manipulating Images

Manipulating Pixmaps

n Pixmap = rectangular array of numerical values n Pixmap copied to frame buffer = rendered n Change frame buffer entry = onscreen picture changes n Each pixel location has fixed number of bits (color depth) n Example: if color depth is b bits, can store up to 2b^ values

Manipulating Pixmaps

n Data types for pixmaps n Bitmap: 1 bit, on or off n Gray scale: one byte, values 0- n RGB: 3 bytes (red, green, blue) n RGBA: 4 byte (red, green, blue, alpha) n Declaration of RGB triple:

class RGB{ public: unsigned char r, g, b; };

RGBpixmap Class

n OpenGL convention: pixmap (bottom to top, left to right) n Add draw, read and copy methods (which use openGL)

Class RGB{ public: unsigned char r, g, b;

RGBpixmap( ); // constructor void setPixel(int x, int y, RGB color); RGB getPixel(int x, y); void draw( ){ glDrawPixels(nCols, nRows, GL_RGB, GL_UNSIGNED_BYTE, pixel); void read( ){glReadPixels(x, y, nCols, nRows, GL_RGB, GL_UNSIGNED_BYTE, pixel);

Scaling and Rotating Images

n Scaling: want a pixmap that has s times more pixels in x, y n s > 1: enlargement n s < 1: reduction (information is lost!)

n openGL scaling: n glPixelZoom(float sx, float sy) n Sets scale factors for drawing pixmaps n Note: pixmaps not scaled, pictures drawn are scaled

Original Pixmap element s > 1^ s < 1

Original Pixmap element

Scaling and Rotating Images

n glPixelZoom(float sx, float sy)

n Sets scale factors for subsequent glDrawPixels command n Scaling is about current raster position, pt. n Pixel row r and column c of pixmap n Drawn as rectangle with bottom left current screen coordinates n Draws (pt.x + sx*r, pt.y + sy.c)

n 90, 180 and 270 degree rotations:

n Copy one pixmap to another doing matrix transposes

n General rotations:

n affine transform of pixmap points to get new pixmap

Combining Pixmaps

n Generalized weighting: n C[i][j] = (1-f).A[i][j] + f.B[i][j] n Example: n A = (14, 246, 97), B = (82, 12, 190), f = 0. n C = (27, 199, 115) = 0.8 A + 0.2 B n Question: How to dissolve image A into B? n Raster demo!!

Alpha Channel and Image Blending

n Even more generalized weighting = blending/compositing n Blending: n draw partially transparent image over another n Add 4th^ component, alpha value (A) to RGB n Interpretation: alpha specifies how opaque each pixel is n Transparent (A = 0), Total opacity (A = 255) n Alpha most frequently used in scaling colors n Alpha channel: series of alpha values in a pixmap

class RGB{ public: unsigned char r, g, b,a; };