diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2023-02-06 18:35:02 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2023-02-06 18:35:02 +0000 |
commit | bf1dca5be2fda19dc84765ddbf39ae99376b8864 (patch) | |
tree | d2de8db4793edaa102f71defed14eacd009ff117 /sys/src/libmemdraw | |
parent | 74cc358c2cfb4c50954a35cbcbeec4e67889f030 (diff) |
libmemdraw: don't return Buffer copy from calc functions
The calc functions get their buffers passed by value.
This is convenient as the code usually modifies the
buffers during iteration.
However, making ANOTHER copy (odst) and returning it
at the end is a bit silly. We already made a copy
when passing the arguments, and the caller of the
calc function can just reuse the copy it already has.
So changing the return type from Buffer to void.
Diffstat (limited to 'sys/src/libmemdraw')
-rw-r--r-- | sys/src/libmemdraw/draw.c | 102 |
1 files changed, 32 insertions, 70 deletions
diff --git a/sys/src/libmemdraw/draw.c b/sys/src/libmemdraw/draw.c index 4b6f09d12..9ab517029 100644 --- a/sys/src/libmemdraw/draw.c +++ b/sys/src/libmemdraw/draw.c @@ -388,7 +388,7 @@ struct Buffer { typedef struct Param Param; typedef Buffer Readfn(Param*, uchar*, int); typedef void Writefn(Param*, uchar*, Buffer); -typedef Buffer Calcfn(Buffer, Buffer, Buffer, int, int, int); +typedef void Calcfn(Buffer, Buffer, Buffer, int, int, int); enum { MAXBCACHE = 16 @@ -727,7 +727,7 @@ alphadraw(Memdrawparam *par) bsrc = rdsrc(&z->spar, z->spar.bufbase, srcy); bmask = rdmask(&z->mpar, z->mpar.bufbase, masky); bdst = rddst(&z->dpar, z->dpar.bufbase, dsty); - bdst = calc(bdst, bsrc, bmask, dx, isgrey, op); + calc(bdst, bsrc, bmask, dx, isgrey, op); wrdst(&z->dpar, z->dpar.bytermin+dsty*z->dpar.bwidth, bdst); } @@ -735,15 +735,14 @@ alphadraw(Memdrawparam *par) return 1; } -static Buffer +static void alphacalc0(Buffer bdst, Buffer b1, Buffer b2, int dx, int grey, int op) { - USED(grey); - USED(op); USED(b1); USED(b2); + USED(grey); + USED(op); memset(bdst.rgba, 0, dx*bdst.delta); - return bdst; } /* @@ -790,15 +789,13 @@ chanmatch(Buffer *bdst, Buffer *bsrc) return 1; } -static Buffer +static void alphacalc14(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int fd, sadelta; int i, sa, ma, q; ulong t, t1; - obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; q = bsrc.delta == 4 && bdst.delta == 4 && chanmatch(&bdst, &bsrc); @@ -839,18 +836,15 @@ alphacalc14(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bmask.alpha += bmask.delta; bsrc.alpha += sadelta; } - return obdst; } -static Buffer +static void alphacalc2810(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int fs, sadelta; int i, ma, da, q; ulong t, t1; - obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; q = bsrc.delta == 4 && bdst.delta == 4 && chanmatch(&bdst, &bsrc); @@ -893,18 +887,15 @@ alphacalc2810(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bmask.alpha += bmask.delta; bsrc.alpha += sadelta; } - return obdst; } -static Buffer +static void alphacalc3679(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int fs, fd, sadelta; int i, sa, ma, da, q; ulong t, t1; - obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; q = bsrc.delta == 4 && bdst.delta == 4 && chanmatch(&bdst, &bsrc); @@ -955,30 +946,27 @@ alphacalc3679(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bmask.alpha += bmask.delta; bsrc.alpha += sadelta; } - return obdst; } -static Buffer +static void alphacalc5(Buffer bdst, Buffer b1, Buffer b2, int dx, int grey, int op) { + USED(bdst); + USED(b1); + USED(b2); USED(dx); USED(grey); USED(op); - USED(b1); - USED(b2); - return bdst; } -static Buffer +static void alphacalc11(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int fd, sadelta; int i, sa, ma, q; ulong t, t1; USED(op); - obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; q = bsrc.delta == 4 && bdst.delta == 4 && chanmatch(&bdst, &bsrc); @@ -1017,23 +1005,20 @@ alphacalc11(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bmask.alpha += bmask.delta; bsrc.alpha += sadelta; } - return obdst; } /* not used yet source and mask alpha 1 -static Buffer +static void alphacalcS0(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int i; USED(op); - obdst = bdst; if(bsrc.delta == bdst.delta){ memmove(bdst.rgba, bsrc.rgba, dx*bdst.delta); - return obdst; + return; } for(i=0; i<dx; i++){ if(grey){ @@ -1056,22 +1041,18 @@ alphacalcS0(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bdst.alpha += bdst.delta; } } - return obdst; } */ /* source alpha 1 */ -static Buffer +static void alphacalcS(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int fd; int i, ma; ulong t; USED(op); - obdst = bdst; - for(i=0; i<dx; i++){ ma = *bmask.alpha; fd = 255-ma; @@ -1097,19 +1078,15 @@ alphacalcS(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) } bmask.alpha += bmask.delta; } - return obdst; } -static Buffer +static void boolcalc14(Buffer bdst, Buffer b1, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int i, ma, zero; USED(b1); - obdst = bdst; - for(i=0; i<dx; i++){ ma = *bmask.alpha; zero = ma ? op == DoutS : op == DinS; @@ -1132,18 +1109,15 @@ boolcalc14(Buffer bdst, Buffer b1, Buffer bmask, int dx, int grey, int op) bdst.alpha += bdst.delta; } } - return obdst; } -static Buffer +static void boolcalc236789(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int fs, fd; int i, ma, da, zero; ulong t; - obdst = bdst; zero = !(op&1); for(i=0; i<dx; i++){ @@ -1187,16 +1161,13 @@ boolcalc236789(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bdst.alpha += bdst.delta; } } - return obdst; } -static Buffer +static void boolcalc1011(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) { - Buffer obdst; int i, ma, zero; - obdst = bdst; zero = !(op&1); for(i=0; i<dx; i++){ @@ -1233,7 +1204,6 @@ boolcalc1011(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) bdst.alpha += bdst.delta; } } - return obdst; } /* * Replicated cached scan line read. Call the function listed in the Param, @@ -1311,7 +1281,7 @@ readnbit(Param *p, uchar *buf, int y) } dx -= n; if(dx == 0) - return b; + goto done; assert(x+i == p->img->r.max.x); @@ -1338,15 +1308,13 @@ readnbit(Param *p, uchar *buf, int y) nbits -= depth; } dx -= n; - if(dx == 0) - return b; - - assert(dx > 0); - /* now we have exactly one full scan line: just replicate the buffer itself until we are done */ - ow = buf; - while(dx--) - *w++ = *ow++; - + if(dx > 0){ + /* now we have exactly one full scan line: just replicate the buffer itself until we are done */ + ow = buf; + while(dx--) + *w++ = *ow++; + } +done: return b; } @@ -1723,18 +1691,16 @@ readptr(Param *p, uchar *s, int y) return b; } -static Buffer +static void boolmemmove(Buffer bdst, Buffer bsrc, Buffer b1, int dx, int i, int o) { USED(i); USED(o); USED(b1); - USED(bsrc); memmove(bdst.red, bsrc.red, dx*bdst.delta); - return bdst; } -static Buffer +static void boolcopy8(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) { uchar *m, *r, *w, *ew; @@ -1748,10 +1714,9 @@ boolcopy8(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) for(; w < ew; w++,r++) if(*m++) *w = *r; - return bdst; /* not used */ } -static Buffer +static void boolcopy16(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) { uchar *m; @@ -1766,10 +1731,9 @@ boolcopy16(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) for(; w < ew; w++,r++) if(*m++) *w = *r; - return bdst; /* not used */ } -static Buffer +static void boolcopy24(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) { uchar *m; @@ -1791,10 +1755,9 @@ boolcopy24(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) r += 3; } } - return bdst; /* not used */ } -static Buffer +static void boolcopy32(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) { uchar *m; @@ -1809,7 +1772,6 @@ boolcopy32(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) for(; w < ew; w++,r++) if(*m++) *w = *r; - return bdst; /* not used */ } static Buffer |