BITBLT(2G)                                             BITBLT(2G)

     NAME
          bitblt, bitbltclip, clipline, point, segment, arc, circle,
          disc, ellipse, texture, border, string, strsize, strwidth,
          Fcode - graphics functions

     SYNOPSIS
          #include <u.h>
          #include <libg.h>

          void  bitblt(Bitmap *db, Point dp, Bitmap *sb,
                    Rectangle sr, Fcode f)

          void  bitbltclip(void *)

          int   clipline(Rectangle r, Point *p0, Point *p1)

          void  point(Bitmap *b, Point p, int v, Fcode f)

          void  segment(Bitmap *b, Point p, Point q, int v, Fcode f)

          void  circle(Bitmap *b, Point p, int r, int v, Fcode f)

          void  disc(Bitmap *b, Point p, int r, int v, Fcode)

          void  arc(Bitmap *b, Point p0, Point p1, Point p2, int v, Fcode f)

          void  ellipse(Bitmap *b, Point p, int a, int b, int v, Fcode f)

          void  texture(Bitmap *b, Rectangle r, Bitmap *t, Fcode f)

          void  border(Bitmap *b, Rectangle r, int w, Fcode f)

          Point string(Bitmap *b, Point p, Font *ft, char *s, Fcode f)

          Point strsize(Font *ft, char *s)

          long  strwidth(Font *ft, char *s)

          enum Fcode {
                  Zero,     DnorS,    DandnotS, notS,
                  notDandS, notD,     DxorS,    DnandS,
                  DandS,    DxnorS,   D,        DornotS,
                  S,        notDorS,  DorS,     F,
          } Fcode;

     DESCRIPTION
          Bitblt (bit-block transfer) takes bits from rectangle sr in
          the source Bitmap sb and overlays them on a congruent rect-
          angle with the min corner at point dp in the destination
          bitmap, db. The f parameter defines each destination pixel

     Page 1                       Plan 9             (printed 3/28/24)

     BITBLT(2G)                                             BITBLT(2G)

          as a function of the source and destination pixels.  The
          sixteen codes in Fcode give all possible boolean operations
          on the source S and destination D.  The code values may be
          expressed as boolean operations on the values S and D.  For
          example, D|S computes the result as the logical or of the
          destination pixel's old value and the overlaying source
          pixel's value.  If pixels are more than one bit deep, the
          operations are bitwise.  The Zero and F codes result in new
          pixel values that are all zeros or all ones, respectively.

          If the source and destination bitmaps have different depths,
          the source rectangle is first converted to have the same
          depth as the destination, as follows: conversion to a
          smaller number of bits per pixel is accomplished by taking
          the desired number of high order bits; conversion to a
          larger number of bits per pixel is accomplished by putting
          the small value into the high order bits, and replicating it
          as many times as necessary to fill the lower order bits.

          All of the drawing graphics functions clip the rectangle
          against the source and destination bitmaps, so that only
          pixels within the destination bitmap are changed and none
          are changed that would have come from areas outside the
          source bitmap.  Bitbltclip takes a pointer to the first
          argument of a bitblt argument list and clips dp and sr so
          the resulting bitblt is confined to the source and destina-
          tion bitmaps.

          Point changes the value of the destination point p in bitmap
          b according to function code f. The source is a pixel with
          value v. The constant ~0 represents the maximum pixel value.

          Segment, circle, disc, and ellipse all draw in bitmap b with
          function code f and a source pixel with value v. Arc draws a
          circular arc centered on p0, traveling clockwise from p1 to
          p2 or a point on the circle near p2. Segment draws a line
          segment in bitmap b from point p to q. The segment is half-
          open: p is the first point of the segment and q is the first
          point beyond the segment, so adjacent segments sharing end-
          points abut.  Clipline clips the line segment from *p0 to
          *p1 (p0 is closed, p1 is open) to rectangle r, adjusting p0
          and p1 so that the segment is within the rectangle and *p1
          is closed.  It returns 0 if none of the segment is in the
          rectangle, 1 otherwise.

          Circle draws a circle with radius r and center at point p.
          Disc is the same except that it fills the circle.  Ellipse
          draws an ellipse with horizontal semi-axis a and vertical
          semi-axis b.

          Border draws, with function f in bitmap b, the rectangular
          outline with lines of width w fitting just inside rectangle

     Page 2                       Plan 9             (printed 3/28/24)

     BITBLT(2G)                                             BITBLT(2G)

          r.

          Texture draws, with function f in bitmap b, a texture using
          the bitmap specified by t. The texture bitmap is aligned on
          b's coordinate system so that (0,0) in both coordinate sys-
          tems coincide, and then t is replicated to form a tiling of
          b. The tiling is clipped to rectangle r in b, and then
          transferred to b using the specified function.

          String draws the text characters given by the null-
          terminated UTF string s into bitmap b, using font ft. The
          upper left corner of the first character (i.e., a point that
          is ft->ascent above the baseline) is placed at point p, and
          subsequent characters are placed on the same baseline, dis-
          placed to the right by the previous character's width.  The
          individual characters are bitblt'ed into the destination,
          using drawing function f. String returns the point after the
          final character of s; this can be outside b if the string
          was clipped.

          The bounding box for text to be drawn with string in font ft
          can be found with strsize; it returns the max point of the
          bounding box, assuming a min point of (0,0).  Strwidth
          returns the x-component of the max point.

     SEE ALSO
          graphics(2), utf(6)

     DIAGNOSTICS
          These routines call the graphics error function on fatal
          errors.

     Page 3                       Plan 9             (printed 3/28/24)