From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <14ec7b180903041807q58ae6a8fh31350709edd0c0c@mail.gmail.com> Date: Thu, 5 Mar 2009 20:21:57 -0700 Message-ID: <14ec7b180903051921u10524f16naad654b297a67de3@mail.gmail.com> From: andrey mirtchovski To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] Porter-Duff alpha blending Topicbox-Message-UUID: b4bdcd60-ead4-11e9-9d60-3106f5b1d025 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 =CE=B1FF mask kFF =CE=B1FF dst r00 g00 b00 =CE=B1FF dst after calc rFE gFE bFF =CE=B1FF what's worse, the error is much more pronounced when drawing single colors (here "red" is turned into yellow): src rFF g00 b00 =CE=B1FF mask kFF =CE=B1FF dst r00 g00 b00 =CE=B1FF dst after calc rFE gFE b00 =CE=B100 things become weird down the road: src rCC g00 b00 =CE=B1CC mask kFF =CE=B1FF dst r00 g00 b00 =CE=B1FF dst after calc rCB gCB b00 =CE=B133 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=3D1. % diff draw.c /n/sources/plan9/sys/src/libmemdraw/draw.c 996c996 < q =3D 0;//bsrc.delta =3D=3D 4 && bdst.delta =3D=3D 4; --- > q =3D bsrc.delta =3D=3D 4 && bdst.delta =3D=3D 4; %