shithub: blie

ref: a3477b9d29227db6e78cede76fdd9d6b83f5ea76
dir: /util.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <event.h>
#include "blie.h"

Memimage*
dupmemimage(Memimage *i)
{
	Memimage *d;
	d = gencanvas(i);
	
	memimagedraw(d, i->r, i, ZP, nil, ZP, SoverD);
	return d;
}

Memimage*
gencanvas(Memimage *i)
{
	return allocmemimage(i->r, RGBA32);
}

Memimage*
gencomposite(Memimage *A, Memimage *B, Memimage *M, Drawop op)
{
	Memimage *d;
	
	d = dupmemimage(A);
	memimagedraw(d, B->r, B, ZP, M, ZP, op);
	return d;
}

Memimage*
ecomposite(Layer *l, Memimage *img)
{
	Memimage *s;
	Memimage *m;
	
	s = l->editor->raw(l);
	m = l->editor->mask(l);
	
	if (!img) {
		if (bliedebug > 1)
			fprint(2, "  c: raw image\n");
		return dupmemimage(s);
	}
	if (bliedebug > 1)
		fprint(2, "  c: combine images\n");
	return gencomposite(img, s, m, l->op);
}

Point
scalepos(Point xy)
{
	xy = addpt(xy, vstate.offset);
	xy.x = xy.x / vstate.zoom;
	xy.y = xy.y / vstate.zoom;
	return xy;
}