ok, i think i am close, but i can go no further. here's what i did:

- view all images through ppm instead of png. what that means is that
i can do toppm $i > $i.ppm in 9vx and then see them on the hosting
Linux. since ppm is rather simple (doesn't do any draw ops but just
dumps the bytes) it is good for viewing both inside Plan9 and outside
(eog, in this case, which apparently stands for "eye of gnome")

- use libmemdraw with the default drawop (SoverD) with no libdraw
conversions, i.e. don't display anything on screen. as soon as it was
established that libmemdraw-ed images exhibit the same issue it was
obvious that libmemdraw is the culprit

- confirm that rgba2img and img2rgba are not the culprits (that's
accomplished by testing that memimagefill(), which uses only
rgba2img() works fine.

then i dug deep into libmemdraw/draw.c, especially alphadraw(). it
turned out after a lot of looking that the offending code is in
alphacalc11(). with debugging turned on and a few extra print()
statements it turned out that writebyte() was getting completely
messed destination values. it turned out that a source 0xFFFFFFFF with
mask 0xFF/0xFF will be turned by alphacalc11() into: 0xFEFEFFFF, or,
in memdraw debugging terms (the last debugging statement is right
underneath "calc()" in alphadraw()):

src  rFF gFF bFF αFF
mask  kFF αFF
dst  r00 g00 b00 αFF
dst after calc  rFE gFE bFF αFF

what's worse, the error is much more pronounced when drawing single
colors (here "red" is turned into yellow):

src  rFF g00 b00 αFF
mask  kFF αFF
dst  r00 g00 b00 αFF
dst after calc  rFE gFE b00 α00

things become weird down the road:

src  rCC g00 b00 αCC
mask  kFF αFF
dst  r00 g00 b00 αFF
dst after calc  rCB gCB b00 α33


the change below _seems_ to avoid the problem and results in correct
images being generated, although those familiar with the code should
be able to better figure out what breaks when q=1.

% diff draw.c /n/sources/plan9/sys/src/libmemdraw/draw.c
996c996
<       q = 0;//bsrc.delta == 4 && bdst.delta == 4;
---
>       q = bsrc.delta == 4 && bdst.delta == 4;
%

Reply via email to