ref: a580fff1d14d1dc9e6ca8dccf564fd9ae90cde08
parent: 9f771e906130afd05b120d198779eb7cc27c26b2
author: rodri <rgl@antares-labs.eu>
date: Sat Dec 27 02:55:41 EST 2025
libmemdraw: memaffinewarp() does not need to return anything we used to return an error before adding support for arbitrary channel format conversions, and now it's unnecessary. with this change we also set dst->r.min as the origin of the frame of reference for the destination mapping (sp → dst->r.min), instead of using the clipr.
--- a/sys/include/memdraw.h
+++ b/sys/include/memdraw.h
@@ -150,7 +150,7 @@
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 int memaffinewarp(Memimage*, Rectangle, Memimage*, Point, Warp, int);
+extern void memaffinewarp(Memimage*, Rectangle, Memimage*, Point, Warp, int);
extern Memimage* allocmemimagekernel(double*, int, int, double);
extern int memimagecorrelate(Memimage*, Rectangle, Memimage*, Point, Memimage*);
extern void _memmkcmap(void);
--- a/sys/man/2/memdraw
+++ b/sys/man/2/memdraw
@@ -136,7 +136,7 @@
int end1, int radius, Memimage *src, Point sp, Drawop op)
void memimagedraw(Memimage *dst, Rectangle r, Memimage *src,
Point sp, Memimage *mask, Point mp, Drawop op)
-int memaffinewarp(Memimage *dst, Rectangle r, Memimage *src,
+void memaffinewarp(Memimage *dst, Rectangle r, Memimage *src,
Point sp, Warp w, int smooth)
Memimage* allocmemimagekernel(double *k, int dx, int dy,
double denom)
--- a/sys/src/9/port/devdraw.c
+++ b/sys/src/9/port/devdraw.c
@@ -1375,6 +1375,13 @@
q += sprint(q, " [%d %d]", BGLONG(a), BGLONG(a+4));
a += 8;
break;
+ case 'M':
+ q += sprint(q, " [[%d %d %d][%d %d %d][%d %d %d]]",
+ BGLONG(a), BGLONG(a+ 4), BGLONG(a+ 8),
+ BGLONG(a+12), BGLONG(a+16), BGLONG(a+20),
+ BGLONG(a+24), BGLONG(a+28), BGLONG(a+32));
+ a += 36;
+ break;
case 'b':
q += sprint(q, " %d", *a++);
break;
@@ -1509,7 +1516,7 @@
/* apply affine transform: 'a' dstid[4] R[4*4] srcid[4] P[2*4] M[3*3*4] smooth[1] */
case 'a':
- printmesg(fmt="LRLPM", a, 0);
+ printmesg(fmt="LRLPMb", a, 0);
m = 1+4+4*4+4+2*4+3*3*4+1;
if(n < m)
error(Eshortdraw);
@@ -1519,8 +1526,7 @@
src = drawimage(client, a+21);
drawpoint(&p, a+25);
drawwarp(w, a+33);
- if(memaffinewarp(dst, r, src, p, w, a[33+3*3*4]) < 0)
- error("memaffinewarp failed");+ memaffinewarp(dst, r, src, p, w, a[33+3*3*4]);
dstflush(dstid, dst, r);
continue;
--- a/sys/src/cmd/image/affinewarp.c
+++ b/sys/src/cmd/image/affinewarp.c
@@ -219,8 +219,7 @@
case -1:
sysfatal("rfork: %r");case 0:
- if(memaffinewarp(dst, wr[i], src, src->r.min, w, smooth) < 0)
- fprint(2, "[%d] memaffinewarp: %r\n", getpid());
+ memaffinewarp(dst, wr[i], src, src->r.min, w, smooth);
exits(nil);
}
}
@@ -229,8 +228,7 @@
free(wr);
}else
- if(memaffinewarp(dst, dr, src, src->r.min, w, smooth) < 0)
- sysfatal("memaffinewarp: %r");+ memaffinewarp(dst, dr, src, src->r.min, w, smooth);
ewritememimage(1, dst);
--- a/sys/src/libmemdraw/warp.c
+++ b/sys/src/libmemdraw/warp.c
@@ -713,7 +713,7 @@
return r<<24|g<<16|b<<8|a;
}
-int
+void
memaffinewarp(Memimage *d, Rectangle r, Memimage *s, Point sp0, Warp m, int smooth)
{ulong (*sample)(Sampler*, Point) = sample1;
@@ -726,11 +726,11 @@
dr = d->clipr;
rectclip(&dr, d->r);
if(rectclip(&r, dr) == 0)
- return 0;
+ return;
samp.r = s->clipr;
if(rectclip(&samp.r, s->r) == 0)
- return 0;
+ return;
if(smooth)
sample = bilinear;
@@ -744,7 +744,10 @@
* Lee, S., Lee, GG., Jang, E.S., Kim, WY,
* Intelligent Computing. ICIC 2006. LNCS, vol 4113.
*/
- p2 = p2₀ = xform((Point){int2fix(r.min.x - dr.min.x) + (1<<6), int2fix(r.min.y - dr.min.y) + (1<<6)}, m);+ p2 = p2₀ = xform((Point){+ int2fix(r.min.x - d->r.min.x) + (1<<6),
+ int2fix(r.min.y - d->r.min.y) + (1<<6)
+ }, m);
for(dp.y = r.min.y; dp.y < r.max.y; dp.y++){ for(dp.x = r.min.x; dp.x < r.max.x; dp.x++){samp.Δx = fixfrac(p2.x);
@@ -762,7 +765,6 @@
p2.x = p2₀.x += m[0][1];
p2.y = p2₀.y += m[1][1];
}
- return 0;
}
static double
--- a/sys/src/libmemdraw/warptest.c
+++ b/sys/src/libmemdraw/warptest.c
@@ -45,29 +45,6 @@
}
}
-#define min(a,b) ((a)<(b)?(a):(b))
-#define max(a,b) ((a)>(b)?(a):(b))
-Rectangle
-getbbox(Rectangle *sr, Matrix m)
-{- Point2 p0, p1, p2, p3;
-
- p0 = Pt2(sr->min.x, sr->min.y, 1);
- p0 = xform(p0, m);
- p1 = Pt2(sr->max.x, sr->min.y, 1);
- p1 = xform(p1, m);
- p2 = Pt2(sr->min.x, sr->max.y, 1);
- p2 = xform(p2, m);
- p3 = Pt2(sr->max.x, sr->max.y, 1);
- p3 = xform(p3, m);
-
- p0.x = min(min(min(p0.x, p1.x), p2.x), p3.x);
- p0.y = min(min(min(p0.y, p1.y), p2.y), p3.y);
- p1.x = max(max(max(p1.x, p1.x), p2.x), p3.x);
- p1.y = max(max(max(p1.y, p1.y), p2.y), p3.y);
- return Rect(p0.x, p0.y, p1.x, p1.y);
-}
-
void
initworkrects(Rectangle *wr, int nwr, Rectangle *fbr)
{@@ -157,8 +134,7 @@
mulm(S, R);
mulm(T, S);
-// dr = getbbox(&src->r, T);
- dr = src->r;
+ dr = rectaddpt(src->r, Pt(100, 300));
dst = allocmemimage(dr, src->chan);
memfillcolor(dst, DTransparent);
@@ -179,8 +155,7 @@
case -1:
sysfatal("rfork: %r");case 0:
- if(memaffinewarp(dst, wr[i], src, src->r.min, w, smooth) < 0)
- fprint(2, "[%d] memaffinewarp: %r\n", getpid());
+ memaffinewarp(dst, wr[i], src, src->r.min, w, smooth);
exits(nil);
}
}
@@ -189,24 +164,24 @@
free(wr);
}else{- if(memaffinewarp(dst, dr, src, src->r.min, w, smooth) < 0)
- sysfatal("memaffinewarp: %r");+// memaffinewarp(dst, dr, src, src->r.min, w, smooth);
-// dr = rectaddpt(Rect(0,0,Dx(dst->r)/2,Dy(dst->r)/2), dst->r.min);
-// dst->clipr = dr;
-// if(memaffinewarp(dst, dr, src, src->r.min, w, smooth) < 0)
-// sysfatal("memaffinewarp: %r");-// dr = rectaddpt(Rect(Dx(dst->r)/2+1,0,Dx(dst->r),Dy(dst->r)/2), dst->r.min);
-// dst->clipr = dst->r;
-// if(memaffinewarp(dst, dr, src, src->r.min, w, smooth) < 0)
-// sysfatal("memaffinewarp: %r");-// dr = rectaddpt(Rect(0,Dy(dst->r)/2+1,Dx(dst->r)/2,Dy(dst->r)), dst->r.min);
-// if(memaffinewarp(dst, dr, src, src->r.min, w, smooth) < 0)
-// sysfatal("memaffinewarp: %r");-// dr = rectaddpt(Rect(Dx(dst->r)/2+1,Dy(dst->r)/2+1,Dx(dst->r),Dy(dst->r)), dst->r.min);
-// dst->clipr = dr;
-// if(memaffinewarp(dst, dr, src, src->r.min, w, smooth) < 0)
-// sysfatal("memaffinewarp: %r");+ dr = rectaddpt(Rect(0,0,Dx(dst->r)/2,Dy(dst->r)/2), dst->r.min);
+ memaffinewarp(dst, dr, src, src->r.min, w, smooth);
+ dr = rectaddpt(Rect(Dx(dst->r)/2+1,0,Dx(dst->r),Dy(dst->r)/2), dst->r.min);
+ memaffinewarp(dst, dr, src, src->r.min, w, smooth);
+ dr = rectaddpt(Rect(0,Dy(dst->r)/2+1,Dx(dst->r)/2,Dy(dst->r)), dst->r.min);
+ memaffinewarp(dst, dr, src, src->r.min, w, smooth);
+ dr = Rect(Dx(dst->r)/2+1,Dy(dst->r)/2+1,Dx(dst->r),Dy(dst->r));
+ Matrix T₂ = {+ 1, 0, dr.min.x,
+ 0, 1, dr.min.y,
+ 0, 0, 1,
+ };
+ mulm(T₂, T);
+ mkwarp(w, T₂);
+ dr = rectaddpt(dr, dst->r.min);
+ memaffinewarp(dst, dr, src, src->r.min, w, smooth);
}
profend();
writememimage(1, dst);
--
⑨