jehanne/sys/include/memdraw.h
Giacomo Tesio c7d0f621c9 Clarify Forsyth's and 9front's copyrights
I'm very grateful to Charles Forsyth for creating most of Jehanne's kernel
and to 9front's guys for all the code and ideas they freely share.

Here I make their copyrights explicit as they had been erroneusly omitted
or messed up before. Sorry.
2018-01-05 02:30:45 +01:00

209 lines
6.2 KiB
C

/*
* This file is part of the UCB release of Plan 9. It is subject to the license
* terms in the LICENSE file found in the top-level directory of this
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
* part of the UCB release of Plan 9, including this file, may be copied,
* modified, propagated, or distributed except according to the terms contained
* in the LICENSE file.
*/
/* Portions of this file are Copyright (C) 9front's team.
* See /doc/license/9front-mit for details about the licensing.
* See http://code.9front.org/hg/plan9front/ for a list of authors.
*/
#pragma src "/sys/src/lib/memdraw"
#pragma lib "libmemdraw.a"
typedef struct Memimage Memimage;
typedef struct Memdata Memdata;
typedef struct Memsubfont Memsubfont;
typedef struct Memlayer Memlayer;
typedef struct Memcmap Memcmap;
typedef struct Memdrawparam Memdrawparam;
#pragma incomplete Memlayer
/*
* Memdata is allocated from main pool, but .data from the image pool.
* Memdata is allocated separately to permit patching its pointer after
* compaction when windows share the image data.
* The first word of data is a back pointer to the Memdata, to find
* The word to patch.
*/
struct Memdata
{
uint32_t *base; /* allocated data pointer */
uint8_t *bdata; /* pointer to first byte of actual data; word-aligned */
int ref; /* number of Memimages using this data */
void* imref;
int allocd; /* is this malloc'd? */
};
enum {
Frepl = 1<<0, /* is replicated */
Fsimple = 1<<1, /* is 1x1 */
Fgrey = 1<<2, /* is grey */
Falpha = 1<<3, /* has explicit alpha */
Fcmap = 1<<4, /* has cmap channel */
Fbytes = 1<<5, /* has only 8-bit channels */
};
struct Memimage
{
Rectangle r; /* rectangle in data area, local coords */
Rectangle clipr; /* clipping region */
int depth; /* number of bits of storage per pixel */
int nchan; /* number of channels */
uint32_t chan; /* channel descriptions */
Memcmap *cmap;
Memdata *data; /* pointer to data; shared by windows in this image */
int zero; /* data->bdata+zero==&byte containing (0,0) */
uint32_t width; /* width in words of a single scan line */
Memlayer *layer; /* nil if not a layer*/
uint32_t flags;
int shift[NChan];
int mask[NChan];
int nbits[NChan];
};
struct Memcmap
{
uint8_t cmap2rgb[3*256];
uint8_t rgb2cmap[16*16*16];
};
/*
* Subfonts
*
* given char c, Subfont *f, Fontchar *i, and Point p, one says
* i = f->info+c;
* draw(b, Rect(p.x+i->left, p.y+i->top,
* p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
* color, f->bits, Pt(i->x, i->top));
* p.x += i->width;
* to draw characters in the specified color (itself a Memimage) in Memimage b.
*/
struct Memsubfont
{
char *name;
int16_t n; /* number of chars in font */
uint8_t height; /* height of bitmap */
char ascent; /* top of bitmap to baseline */
Fontchar *info; /* n+1 character descriptors */
Memimage *bits; /* of font */
};
/*
* Encapsulated parameters and information for sub-draw routines.
*/
enum {
Simplesrc=1<<0,
Simplemask=1<<1,
Replsrc=1<<2,
Replmask=1<<3,
Fullmask=1<<4,
};
struct Memdrawparam
{
Memimage *dst;
Rectangle r;
Memimage *src;
Rectangle sr;
Memimage *mask;
Rectangle mr;
int op;
uint32_t state;
uint32_t mval; /* if Simplemask, the mask pixel in mask format */
uint32_t mrgba; /* mval in rgba */
uint32_t sval; /* if Simplesrc, the source pixel in src format */
uint32_t srgba; /* sval in rgba */
uint32_t sdval; /* sval in dst format */
};
/*
* Memimage management
*/
extern Memimage* allocmemimage(Rectangle, uint32_t);
extern Memimage* allocmemimaged(Rectangle, uint32_t, Memdata*);
extern Memimage* readmemimage(int);
extern Memimage* creadmemimage(int);
extern int writememimage(int, Memimage*);
extern void freememimage(Memimage*);
extern int loadmemimage(Memimage*, Rectangle, uint8_t*, int);
extern int cloadmemimage(Memimage*, Rectangle, uint8_t*, int);
extern int unloadmemimage(Memimage*, Rectangle, uint8_t*, int);
extern uint32_t* wordaddr(Memimage*, Point);
extern uint8_t* byteaddr(Memimage*, Point);
extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*);
extern void memfillcolor(Memimage*, uint32_t);
extern int memsetchan(Memimage*, uint32_t);
/*
* Graphics
*/
extern void memdraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
extern void memline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
extern void mempoly(Memimage*, Point*, int, int, int, int, Memimage*, Point, int);
extern void memfillpoly(Memimage*, Point*, int, int, Memimage*, Point, int);
extern void _memfillpolysc(Memimage*, Point*, int, int, Memimage*, Point, int, int, int, int);
extern void memimagedraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
extern int hwdraw(Memdrawparam*);
extern void memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
extern void _memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, Rectangle, int);
extern Point memimagestring(Memimage*, Point, Memimage*, Point, Memsubfont*,
char*);
extern void memellipse(Memimage*, Point, int, int, int, Memimage*, Point, int);
extern void memarc(Memimage*, Point, int, int, int, Memimage*, Point, int, int, int);
extern Rectangle memlinebbox(Point, Point, int, int, int);
extern int memlineendsize(int);
extern void _memmkcmap(void);
extern int memimageinit(void);
/*
* Subfont management
*/
extern Memsubfont* allocmemsubfont(char*, int, int, int,
Fontchar*, Memimage*);
extern Memsubfont* openmemsubfont(char*);
extern void freememsubfont(Memsubfont*);
extern Point memsubfontwidth(Memsubfont*, char*);
extern Memsubfont* getmemdefont(void);
/*
* Predefined
*/
extern Memimage* memwhite;
extern Memimage* memblack;
extern Memimage* memopaque;
extern Memimage* memtransparent;
extern Memcmap *memdefcmap;
/*
* Kernel interface
*/
void memimagemove(void*, void*);
/*
* Kernel cruft
*/
extern void rdb(void);
extern int iprint(char*, ...);
#pragma varargck argpos iprint 1
extern int drawdebug;
/*
* doprint interface: numbconv bit strings
*/
#pragma varargck type "llb" vlong
#pragma varargck type "llb" uvlong
#pragma varargck type "lb" long
#pragma varargck type "lb" ulong
#pragma varargck type "b" int
#pragma varargck type "b" uint32_t