Graphics
Download
1 / 38

binary for graphics - PowerPoint PPT Presentation


  • 224 Views
  • Updated On :

Graphics. CSE 500 Summer 1998. Graphics in X. X assumes bitmapped graphics The screen is a rectangular array of pixels Drawing consists of setting the values of pixels the array of pixels may have a depth (planes) X provides primitives to draw figures X provides the means to draw text

Related searches for binary for graphics

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'binary for graphics' - oshin


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Graphics

Graphics

CSE 500

Summer 1998


Graphics in x
Graphics in X

  • X assumes bitmapped graphics

    • The screen is a rectangular array of pixels

    • Drawing consists of setting the values of pixels

    • the array of pixels may have a depth (planes)

  • X provides primitives to draw figures

  • X provides the means to draw text

  • X provides the means to specify images directly.


Drawing
Drawing

  • Drawing is to a connection called a Display.

  • A window is created to hold the drawing

  • An invisible Pixmap can be created and drawn into instead of a window.

    • Drawables are windows or pixmaps.

  • A data structure called a graphics context (GC) specifies the attributed used when drawing.


Steps of drawing
Steps of drawing

  • Select the pixels to draw

  • Apply patterns, color found in GC

  • Clip the picture by rectangles in GC

    (according to a clipping rule and mask in GC)

  • Draw on the screen


The graphics context gc
The Graphics Context (GC)

  • The graphics context is a C struct containing information required to render a drawing

  • There may be several GCs but they should be viewed as limited resources.

  • Common practice is to create several GC as required and use as required

  • A single GC can be used and changed.


Tradeoffs
Tradeoffs

  • 1 GC and values changed with XChangeGC degrades performance

  • 2 or more GC use memory on the server (multiple clients make problem worse)


  • As the workstation draws graphics sent to it by an application program it interprets those primitives using attribute values contained in the specified GC.

  • Thus every application must have at least one GC resourc and load values to it before it can issue a graphic output request.


Widget drawingArea; application program it interprets those primitives using attribute values contained in the specified GC.

Display display;

Window w;

GC gc,newgc;

drawingArea = XmCreateDrawingArea(toplevel,”da”,al,ac);

/* a drawing area comes with a gc */

gc = XtGetGC(drawingArea,mask, &values);

/* a window (or other drawable) must create a gc */

newgc = XCreateGC(display,window, mask, &values); ,

creation or copy of a gc supports changing the GC structure by masking out certain fields of the structureand setting new values


Steps in setting up the values structure
Steps in setting up the values structure. application program it interprets those primitives using attribute values contained in the specified GC.

  • Define an XGCValues structures

  • set members to the desired value

  • set the “mask” to reflect the members you are changing.

  • Create the GC with XCreateGC, XtGetGC

  • Destroy any unwanted GC with

    XFreeGC(gc)

  • Change or copy a GC with XChangeGC or XCopyGC


The xgcvalues structure
The XGCValues structure application program it interprets those primitives using attribute values contained in the specified GC.

  • members of this struct have a name

    • e.g. unsigned long plane_mask;

    • int line_width;

  • a mask name

    • e.g. GCPlaneMask

    • GCLineWidth

  • and a stage in the drawing when it has an effect

    • e.g. at raster output time

    • at pixel selection time


The graphics pipeline
The graphics pipeline application program it interprets those primitives using attribute values contained in the specified GC.

  • Pixel Selection time

    • The pixels that are to be set are defined

  • Patterning stage

    • The pixels set are masked by a pattern

  • GC clip stage

    • Pixels are clipped by gc clipping rectangles

  • Window clip stage

    • Pixels are clipped by the edges of windows

  • Raster output stage

    • Pixels are drawn in the drawable


Pixel selection time
Pixel Selection Time application program it interprets those primitives using attribute values contained in the specified GC.

This stage of the pipeline operates on the output of graphics primitives such as line, arc, polygon, drawing primitives.

These primitives generally generate foreground pixels, some generate background pixels, and some both (e.g. a dashed line)

Attributes in the associated GC object such as line_width, join_style, etc. effect this stage.


Patterning stage
Patterning Stage application program it interprets those primitives using attribute values contained in the specified GC.

This stage applies a pattern of values (colors) to foreground and background pixels. The following gc attributes are used in this stage

  • foreground - “the draw color” sets the color to use for foreground pixels

  • background - the value to apply to background pixls

  • stipple - an X resource identifier to use for effects such as hatch-patterns or screen-door patterning

  • tile - used for repeat patterning

  • fill-style - selects way to apply patterns ( tiling, hatching, solid fill, etc.)


Gc clipping stage
GC clipping stage application program it interprets those primitives using attribute values contained in the specified GC.

  • This stage discards all pixels outside a specified region. This can be a clip mask defined in the gc or the result of an XSetClipRectangles request.

  • The default is no clipping at this stage


Window clipping stage
Window Clipping Stage application program it interprets those primitives using attribute values contained in the specified GC.

  • This stage discards all pixels that lie outside the boundaries of the drawable. The only control the programmer has is to create subwindows and set attributes such as

    • ClipByChildren (default)

    • IncludeInferiors (draw through subwindows)


Raster output stage
Raster Output Stage application program it interprets those primitives using attribute values contained in the specified GC.

  • This final stage combines the generated values with the values already present.

  • Two GC attributes control this behavior

    • function: one of 16 boolean functions of two variables.

    • plane_mask: a value of 1 causes update a value of 0 leaves the pixel alone.


Changing a gc is like creating
Changing a GC is like creating application program it interprets those primitives using attribute values contained in the specified GC.

Display display;

GC gc;

unsigned long mask;

XGCValues values;

Xchange(display,gc,mask,&values);


Important note
Important note application program it interprets those primitives using attribute values contained in the specified GC.

  • If the drawable is a window, a window id must exist.

  • A window id does not exist until a widget is realized.


Setting and manipulating the gc
Setting and manipulating the GC application program it interprets those primitives using attribute values contained in the specified GC.

  • Setting and manipulating the GC really means dealing with the XGCValues structure, a struct with over 20 fields.

    typedef struct {

    int function; /* GCFunction */

    unsigned long plane_mask;/*GCPlaneMask */

    unsigned long foreground /*GCForeground*/


The xgcvalues structure1
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • function:

    as previously noted, this applies to raster output and can be one of 16 boolean values that indicate the logical meaning of new applied to old bits

    GXClear - the new value is 0

    GXSet - the new value is 1

    GXxor - xor the new and old values

    Gxor - or the new and old values

    GXcopy - (default) overwrite old with new


The xgcvalues structure2
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • function:

    a convenience function can be used to alter this without using XChangeGC or creating a new GC

    XSetFunction(display,gc, GXxor);


The xgcvalues structure3
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • plane_mask

    the bits set can be set in different planes. The default value is AllPlanes but one can set bits in planes indicated by a 1 in the mask

    XSetPlaneMask(display, 0x0a);

  • foreground

  • background

    foreground and background are pixel values for the draw color. Default foreground is 0, background in 1


The xgcvalues structure4
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • foreground

  • background

    Safest black and white and using a convenience function

    Display *display

    GC mygc;

    XSetForeground(display, mygc, BlackPixel(display), DefaultScreen(display))

    XSetBackground(display, mygc, WhitePixel(display), DefaultScreen(display))


The xgcvalues structure5
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

The next group of entries in the struct effect line attributes,

  • int line_width;

  • int line_style;

    line styles such as LineSolid, LineOnOffDash, LineDoubleDash are provided

    line styles such as LineOnOffDash allow one to set 3 pixels on and 3 pixels off, or with LineDoubleDash 3 on 2 off 4 on 2 off, values can be set with the XSetDashes function.


The xgcvalues structure6
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • int cap_style,determines how drawing ends a line. CapNotLast, CapButt,CapRound CapProjecting are values.

  • int join_style;

    defines how lines are joined together. JoinMiter, JoinBevel,JoinRound.

  • and a convenience function XSetLineAttributes(display,gc,line_width,line_style, cap_style,join_style);


The xgcvalues structure7
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • int fill_style;

    has constants such as FillSolid, FillTiled, FillStippled

    FillTiled uses the associated field Pixmap tile;

    FillStippled uses the associated field Pixmap stipple;

  • int fill_rule

    addresses the issue of what is the inside of a drawn polygonal figure. Rules such as EvenOddRule, say that if a line from the point to the outside crosses an odd number of lines it is inside. A WindingRule considers a line from test point to each vertex in both counter clockwise and clockwise directions to determine fill.


The xgcvalues structure8
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • int arc_mode;

    supports filling of arcs drawn as either a

    ArcPieSlice or ArcChord

  • Pixmap tile,stipple

    have been mentioned already as associated with the fill rules.

  • int ts_x_orgin, ts_y_origin

    x,y specify the relationship between the picture and the stipple mask or tile mask.. i.e shift the resulting design up or down, right or left.


The xgcvalues structure9
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • Font font;

    is the default text font to be used.

  • int subwindow_mode;

  • Bool graphics_exposures;.

    are concerned with window clipping and whether exposure events should be generated

  • int ts_x_orgin, ts_y_origin

    x,y specify the relationship between the picture and the stipple mask or tile mask.. i.e shift the resulting design up or down, right or left.


The xgcvalues structure10
The XGCValues Structure application program it interprets those primitives using attribute values contained in the specified GC.

  • int clip_x_origin, clip_y_origin;

    are used to define the region for a clipping mask.

  • Pixmap clipMask;

    defines the clipping mask

  • int dash_offset;

    defines dash behavior, and

  • char dashes;

    defines dash appearance


It s time to draw
It’s time to draw application program it interprets those primitives using attribute values contained in the specified GC.

  • Having defined how the graphics pipeline is to behave, X routines provide input to the pipeline.

  • A Classification of routines is:

Points

Lines

Arc and Circle Outlines

Filled Arcs and Circles

Rectangle Outlines

Filled Rectangles

Polygons


Points
Points application program it interprets those primitives using attribute values contained in the specified GC.

  • XDrawPoint

    XDrawPoint(display,window,gc,x,y);

  • XDrawPoints

    XPoint points[1000];

    int npts=1000;

    for(..) { points[i].x = ; ..}

    XDrawPoints(display,window,points,npts,CoordModeOrigin);/* relative to window origin */


Lines
Lines application program it interprets those primitives using attribute values contained in the specified GC.

  • XDrawLine

    XDrawLine(display, window,gc,x1,y1,x2,y2);

  • XDrawLines

    XDrawLines(display,window,points,npts, CoordModeOrigin);

  • XDrawSegment

    XSegment segments[2]= { {x1,y1,x2,y2},

    {u1,v1,u2,v2}};

    XDrawSegments(display,window,segments,2);


Arcs and circle outlines
Arcs and Circle Outlines application program it interprets those primitives using attribute values contained in the specified GC.

  • Defining an arc:

    • x,y position of the upper left corner of bounding rectangle

    • width, height of bounding rectangle

    • angle1 is the starting angle (in 64th of degrees) of the arc to be drawn

    • angle 2 is the angle to draw the arc beginning at angle1. (angle1 = 0 and angle2=23040 (64*360) is a closed arc)

  • XDrawArc

    XDrawArc(display, window,gc,x,y,width,height angle1,angle2);


Arcs and circle outlines1
Arcs and Circle Outlines application program it interprets those primitives using attribute values contained in the specified GC.

  • using the Xtypedef struct { short x,y;

    unsigned short width,height;

    short angle1,angle2 } XArc;

  • XDrawArcs

    XArc arcs[];

    XDrawArc(display, window,gc,arcs,narcs);


Filled arcs
Filled Arcs application program it interprets those primitives using attribute values contained in the specified GC.

  • Important to set the mode

    • ArcPieSlice specifies that the filled arc is to be drawn as a pie slice (default value)

    • ArcChord fills the arc that is closed b drawing a line from start to end of arc

  • XSetArcMode(display,gc,ArcChord);

    XFillArc(display,window,gc,x,y,width, height,angle1,angle2);


Filled arcs1
Filled Arcs application program it interprets those primitives using attribute values contained in the specified GC.

  • XFillArcs corresponds to XDrawArcs


Rectangles
Rectangles application program it interprets those primitives using attribute values contained in the specified GC.

XDrawRectangle(display,window,gc,x,y,

width,height);

XDrawFillRectangle(display,window,gc,x,y,

width,height);

XRectangle r[]

XDrawRectangles(display,window,gc,r,nrec);

XDrawFillRectangles( . . .)


Polygons
Polygons application program it interprets those primitives using attribute values contained in the specified GC.

  • A polygon is defined by lines connecting vertices. XDrawLines can be used to draw polygons. XFillPolygon looks like the XDrawLines call, but it fills the polygon acording to a rule specified in the GC.

    XSetFillRule(display,gc,WindingRule);

    XFillPolygon(display,window,gc,points, npoints,shape,mode);

  • Shape is Convex,NonConvex,Complex, and allows a speedup of filling.


ad