9fans.net/go@v0.0.5/draw/memdraw/memdraw.h.go (about)

     1  package memdraw
     2  
     3  import "9fans.net/go/draw"
     4  
     5  /*
     6   * Memdata is allocated from main pool, but .data from the image pool.
     7   * Memdata is allocated separately to permit patching its pointer after
     8   * compaction when windows share the image data.
     9   * The first word of data is a back pointer to the Memdata, to find
    10   * The word to patch.
    11   */
    12  
    13  type _Memdata struct {
    14  	Bdata []uint8 /* pointer to first byte of actual data; word-aligned */
    15  	ref   int     /* number of Memimages using this data */
    16  	imref *Image
    17  }
    18  
    19  const (
    20  	Frepl   = 1 << 0 /* is replicated */
    21  	Fsimple = 1 << 1 /* is 1x1 */
    22  	Fgrey   = 1 << 2 /* is grey */
    23  	Falpha  = 1 << 3 /* has explicit alpha */
    24  	Fcmap   = 1 << 4 /* has cmap channel */
    25  	Fbytes  = 1 << 5 /* has only 8-bit channels */
    26  )
    27  
    28  type Image struct {
    29  	R     draw.Rectangle /* rectangle in data area, local coords */
    30  	Clipr draw.Rectangle /* clipping region */
    31  	Depth int            /* number of bits of storage per pixel */
    32  	nchan int            /* number of channels */
    33  	Pix   draw.Pix       /* channel descriptions */
    34  	cmap  *_CMap
    35  
    36  	Data      *_Memdata /* pointer to data; shared by windows in this image */
    37  	zero      int       /* data->bdata+zero==&byte containing (0,0) */
    38  	Width     uint32    /* width in words of a single scan line */
    39  	Layer     *Layer    /* nil if not a layer*/
    40  	Flags     uint32
    41  	X         interface{}
    42  	ScreenRef int /* reference count if this is a screen */
    43  
    44  	shift [draw.NChan]uint
    45  	mask  [draw.NChan]uint32
    46  	nbits [draw.NChan]uint
    47  }
    48  
    49  type _CMap struct {
    50  	Cmap2rgb [3 * 256]uint8
    51  	Rgb2cmap [16 * 16 * 16]uint8
    52  }
    53  
    54  /*
    55   * Subfonts
    56   *
    57   * given char c, Subfont *f, Fontchar *i, and Point p, one says
    58   *	i = f->info+c;
    59   *	draw(b, Rect(p.x+i->left, p.y+i->top,
    60   *		p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
    61   *		color, f->bits, Pt(i->x, i->top));
    62   *	p.x += i->width;
    63   * to draw characters in the specified color (itself a Memimage) in Memimage b.
    64   */
    65  
    66  type subfont struct {
    67  	name   string
    68  	n      int             /* number of chars in font */
    69  	height uint8           /* height of bitmap */
    70  	ascent int8            /* top of bitmap to baseline */
    71  	info   []draw.Fontchar /* n+1 character descriptors */
    72  	bits   *Image          /* of font */
    73  }
    74  
    75  /*
    76   * Encapsulated parameters and information for sub-draw routines.
    77   */
    78  
    79  const (
    80  	_Simplesrc  = 1 << 0
    81  	_Simplemask = 1 << 1
    82  	_Replsrc    = 1 << 2
    83  	_Replmask   = 1 << 3
    84  	_Fullsrc    = 1 << 4
    85  	_Fullmask   = 1 << 5
    86  )
    87  
    88  type memDrawParam struct {
    89  	dst   *Image
    90  	r     draw.Rectangle
    91  	src   *Image
    92  	sr    draw.Rectangle
    93  	mask  *Image
    94  	mr    draw.Rectangle
    95  	op    draw.Op
    96  	state uint32
    97  	mval  uint32     /* if Simplemask, the mask pixel in mask format */
    98  	mrgba draw.Color /* mval in rgba */
    99  	sval  uint32     /* if Simplesrc, the source pixel in src format */
   100  	srgba draw.Color /* sval in rgba */
   101  	sdval uint32     /* sval in dst format */
   102  }