1 RGBpixm ap Class RGBpixm ap Class OpenGL convention: pixm ap - - PDF document

1
SMART_READER_LITE
LIVE PREVIEW

1 RGBpixm ap Class RGBpixm ap Class OpenGL convention: pixm ap - - PDF document

Manipulating Pixm aps CS 4 7 3 1 : Com put e r Gr a phics Pixm ap = rectangular array of num erical values Le ct ur e 2 1 : Ra st e r Gr a phics Pa r t 2 Pixm ap copied to fram e buffer = rendered Change fram e buffer entry =


slide-1
SLIDE 1

1

CS 4 7 3 1 : Com put e r Gr a phics Le ct ur e 2 1 : Ra st e r Gr a phics Pa r t 2 Em m anuel Agu

Manipulating Pixm aps

  • Pixm ap = rectangular array of num erical values
  • Pixm ap copied to fram e buffer = rendered
  • Change fram e buffer entry = onscreen picture changes
  • Each pixel location has fixed num ber of bits (color depth)
  • Exam ple: if color depth is b bits, can store up to 2b values

Manipulating Pixm aps

  • Operations of interest:
Copying pixm aps
  • glReadPixels: frame buffer to off-screen memory
  • glCopyPixels: frame buffer to frame buffer
  • glDrawPixels: pixmap to frame buffer
  • memCopy: off-screen to off-screen
Com paring pixm aps Represent ing and coloring regions in pixm ap

Manipulating Pixm aps

  • Data types for pixm aps
Bitm ap: 1 bit, on or off Gray scale: one byt e, values 0 - 255 RGB: 3 byt es ( red, green, blue) RGBA: 4 byte ( red, green, blue, alpha)
  • Declaration of RGB triple:

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

slide-2
SLIDE 2

2

RGBpixm ap Class

  • OpenGL convention: pixm ap (bottom to top, left to right)
  • Add draw, read and copy m ethods (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);

RGBpixm ap Class

/ / … .. contd. void copy( ){ glCopyPixels(.. Parameters..); int readBMPFile(char *fname); void writeBMPFile(char *fname); }; Note: refer to Hill fig. 10.3 for full RGBPixm ap declaration

Scaling and Rotating I m ages

  • Scaling: want a pixm ap that has s tim es m ore pixels in x, y
s > 1: enlargem ent s < 1: reduct ion ( inform at ion is lost ! )
  • penGL scaling:

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

Original Pixm ap elem ent s > 1 s < 1 Original Pixm ap elem ent

Scaling and Rotating I m ages

glPixelZoom(float sx, float sy)

Sets scale factors for subsequent glDrawPixels com m and Scaling is about current raster position, pt. Pixel row r and colum n c of pixm ap Drawn as rectangle with bottom left current screen

coordinates

Draws (pt.x + sx * r, pt.y + sy.c)

90, 180 and 270 degree rotations:

Copy one pixm ap to another doing m atrix transposes

General rotations:

affine transform of pixm ap points to get new pixm ap

slide-3
SLIDE 3

3

Com bining Pixm aps

  • Two pixmaps A and B combined pixelwise to form third

pixel C

  • i.e. C[ i] [ j] = A[ i] [ j] ⊗ B[ i] [ j]
  • Averaging:

C[ i] [ j] = ½ * (A[ i] [ j] + B[ i] [ j] )

  • Subtraction:

C[ i] [ j ] = A[ i] [ j ] - B[ i] [ j]

  • Generalized weighting:

C[ i] [ j ] = ( 1- f).A[ i] [ j] + f.B[ i] [ j]

Com bining Pixm aps

  • Generalized weighting:

C[ i] [ j ] = ( 1- f).A[ i] [ j] + f.B[ i] [ j]

  • Exam ple:

A = (14, 246, 97), B = (82, 12, 190), f = 0.2 C = (27, 199, 115) = 0.8 A + 0.2 B

  • Question: How to dissolve image A into B?

Alpha Channel and I m age Blending

  • Even m ore generalized weighting = blending/ com positing
  • Blending:
draw part ially t ransparent im age over anot her Add 4th com ponent , alpha value ( A) t o RGB I nt erpret at ion: alpha specifies how opaque each pixel is Transparent ( A = 0) , Tot al opacit y ( A = 255) Alpha m ost frequent ly used in scaling colors

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

Alpha Channel and I m age Blending

  • Alpha channel: series of alpha values in a pixm ap
  • penGL alpha blending: glBlendFunc( )
  • Other alpha blending applications:
Sim ulat ing Chr om ak ey: forcing cert ain colors t o be

transparent

Applying paint wit h a paint brush: apply percent age of new

color wit h each m ouse st roke

slide-4
SLIDE 4

4

References

  • Hill, chapter 10