Open Hagb opened 1 year ago
Hmm I think paint.setColorFilter() with an appropiate filter matrix might provide the same functionality like bitwise XOR:
private ColorMatrix getColorMatrix() {
return new ColorMatrix(new float[] {
-1, 0, 0, 0, 255,
0, -1, 0, 0, 255,
0, 0, -1, 0, 255,
0, 0, 0, 1, 0
});
}
// ...
// ...
_paint.setColorFilter(new ColorMatrixColorFilter(getColorMatrix()));
Hmm I think paint.setColorFilter() with an appropiate filter matrix might provide the same functionality like bitwise XOR:
private ColorMatrix getColorMatrix() { return new ColorMatrix(new float[] { -1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255, 0, 0, 0, 1, 0 }); } // ... // ... _paint.setColorFilter(new ColorMatrixColorFilter(getColorMatrix()));
if I was not mistaken, color filters is only applied to source but not destination, and the above matrix is bitwise NOT
. (And any linear matrix operations can not simulate XOR
, AND
or OR
.)
When plane-mask is 0xffffff, with ColorMatrix
, we can implement CopyInverted (NOT src), but not some other functions includingXOR
, AND
and OR
.
For example, with the above _paint
, _canvas.drawLines(points, paint)
means drawing a line with CopyInverted (NOT src).
Refer to https://www.x.org/releases/current/doc/xproto/x11protocol.html#requests:CreateGC . With
function
andplane-mask
onCreateGC
, client can tell server to draw with bitwise operations:I failed to find an efficient way to implement these bitwise operation after spending many hours. I think it might be difficult to implement a paint with bitwise Xfermode. As a result, it is hard to draw via methods of canvas.
TL;DR:
Android doesn't have bitwise
Xfermode
now.PixelXorXfermode
has been removed, andXfermode
has only one subclassPorterDuffXfermode
now, which has no bitwise operation, andPorterDuff.Mode.XOR
is xor operation for area but not for color, which is misused inhttps://github.com/nwrkbiz/android-xserver/blob/51e907880d4295ee3c381a593c738ca365c066fb/library/src/main/java/au/com/darkside/xserver/GContext.java#L406
I tried to write our own
Xfermode
subclass, so that we can still use methods of canvas to draw. But finally found thatPaint
uses native code and hardcodesPorterDuffXfermode
, even ifPaint.setXfermode
acceptsXfermode
.ColorMatrixColorFilter
can be used to implement bitwiseNOT
onsrc
but notdst
.