The Java 2D group at Sun would like to get your opinion on an issue
concerning the java.awt.AlphaComposite class. We have had a bug report
filed against the behavior of instances of AlphaComposite obtained via
the AlphaComposite.getInstance(int rule, float alpha) factory method.
The issue is how the extra alpha value is interpreted. We currently
interpret this value as an additional alpha value to multiply by the
source alpha as each source pixel is being composited to the destination.
The submitter of the bug report was expecting that the extra alpha value
would be used as a blending factor between a) the result of applying the
compositing rule to the current source and destination pixels and b) the
current destination pixel. When the extra alpha value is 1.0 (or when
using an AlphaComposite instance obtained without specifying an extra alpha
value), the result of the compositing operation would be just a. When
the extra alpha value is 0.0, the result of the compositing operation would
be just b. Otherwise, the result would be linearly interpolated between
a and b.
At the end of this message is a detailed tabulation of the results for all
the rules we support, under both interpretations. It is important to note
that when the extra alpha value is 1.0 (or when no extra alpha value is
used), there is no difference between the interpretations. In addition,
for the most common rule, SrcOver, and for the DstOver and DstOut rules,
results are identical for any extra alpha value. For the other rules, there
are differences when the extra alpha value is not 1.0.
For the Clear rule, the current interpretation clears the destination
source and alpha to 0, no matter what the extra alpha value is. In the
alternate interpretation, the extra alpha value acts as a fade factor
on the destination.
For the Src rule, the current interpretation multiplies the source
alpha by the extra alpha value before overwriting the destination.
In the alternate interpretation, the extra alpha value acts as an
interpolation factor between the source and destination.
For the SrcIn, DstIn, and SrcOut rules, the current interpretation uses
the extra alpha value as an additional fading factor on what gets written
to the destination. The alternate interpretation adds some of the
destination pixel to the result, depending on the extra alpha value.
So, in all three cases decreasing the extra alpha value causes the result
to tend toward transparency under the current interpretation, while
under the alternate interpretation, decreasing the extra alpha value causes
the result to tend toward no effect.
So some things that there is no way to do in one step with the
current interpretation, such as fading the destination or interpolating
between source and destination, can be done in one compositing operation
with the alternate interpretation. However, some operations that take
only one step with the current interpretation require two steps in
the alternate interpretation. For example, to get the current effect
of the SrcIn rule under the alternate interpretation requires first
fading the source, e.g. by using Clear with an appropriate extra alpha
value, then compositing the source to the destination using SrcIn with
the extra alpha value set to 1.0.
We would like to hear from anyone who is using any of the compositing
rules other than SrcOver, DstOver, and DstOut with extra alpha values.
In addition, we would like to hear any comments anyone may have on the
utility of our current interpretation or of the alternate interpretation.
What do you think about the following options:
1) change the implementation to adopt the alternate interpretation
2) add methods to allow the alternate interpretation to be used in
addition to the current one (but not together)
3) add a new parameter to AlphaComposite so there are two extra
alpha values, one with the current interpretation and one with
the alternate interpretation, which can be used together
4) don't change anything
RESULTS TABLE
=============
Below is a table of the compositing results under both interpretations.
Results are stated in both premultiplied form and non-premultiplied form.
Premultiplied form means that each color component is premultiplied by
the alpha component for each source and destination pixel, both before
and after the compositing operation. The two forms are equivalent.
Note that in the premultiplied form, the equations for alpha and
color components are symmetric.
The following notation is used:
Sc Source Color components, non-premultiplied
Scp Source Color components, premultiplied
Sa Source Alpha component
Dc Destination Color components, non-premultiplied,
before compositing
Dc' Destination Color components, non-premultiplied,
after compositing
Dcp Destination Color components, premultiplied,
before compositing
Dcp' Destination Color components, premultiplied,
after compositing
Da Destination Alpha component before compositing
Da' Destination Alpha component after compositing
Ea Extra Alpha Value passed to getInstance(int, float) or
1.0 if getInstance(int) was used
AlphaComposite extra alpha value interpretation in
Java 2 Runtime Environment, Standard Edition, v1.2
==================================================
Premultiplied Form
==================
Clear: Da' = 0
Dcp' = 0
Src: Da' = Sa * Ea
Dcp' = Scp * Ea
SrcOver: Da' = Sa * Ea + Da * (1 - Sa * Ea)
Dcp' = Scp * Ea + Dcp * (1 - Sa * Ea)
DstOver: Da' = Sa * Ea * (1 - Da) + Da
Dcp' = Scp * Ea * (1 - Da) + Dcp
SrcIn: Da' = Sa * Ea * Da
Dcp' = Scp * Ea * Da
DstIn: Da' = Da * Sa * Ea
Dcp' = Dcp * Sa * Ea
SrcOut: Da' = Sa * Ea * (1 - Da)
Dcp' = Scp * Ea * (1 - Da)
DstOut: Da' = Da * (1 - Sa * Ea)
Dcp' = Dcp * (1 - Sa * Ea)
Non-Premultiplied Form
======================
Clear: Da' = 0
Dc' = 0
Src: Da' = Sa * Ea
Dc' = (Sc * Sa * Ea) / Da' , Da' != 0
= Sc
Dc' = 0 , Da' == 0
SrcOver: Da' = Sa * Ea + Da * (1 - Sa * Ea)
Dc' = (Sc * Sa * Ea + Dc * Da * (1 - Sa * Ea)) / Da' , Da' != 0
Dc' = 0 , Da' == 0
DstOver: Da' = Sa * Ea * (1 - Da) + Da
Dc' = (Sc * Sa * Ea * (1 - Da) + Dc * Da) / Da' , Da' != 0
Dc' = 0 , Da' == 0
SrcIn: Da' = Sa * Ea * Da
Dc' = (Sc * Sa * Ea * Da) / Da' , Da' != 0
= Sc
Dc' = 0 , Da' == 0
DstIn: Da' = Da * Sa * Ea
Dc' = (Dc * Da * Sa * Ea) / Da' , Da' != 0
= Dc
Dc' = 0 , Da' == 0
SrcOut: Da' = Sa * Ea * (1 - Da)
Dc' = (Sc * Sa * Ea * (1 - Da)) / Da' , Da' != 0
= Sc
Dc' = 0 , Da' == 0
DstOut: Da' = Da * (1 - Sa * Ea)
Dc' = (Dc * Da * (1 - Sa * Ea)) / Da' , Da' != 0
= Dc
Dc' = 0 , Da' == 0
Alternate extra alpha value interpretation
==========================================
Premultiplied Form
==================
Clear: Da' = (0) * Ea + Da * (1 - Ea)
= Da * (1 - Ea)
Dcp' = (0) * Ea + Dcp * (1 - Ea)
= Dcp * (1 - Ea)
Src: Da' = Sa * Ea + Da * (1 - Ea)
Dcp' = Scp * Ea + Dcp * (1 - Ea)
SrcOver: Da' = (Sa + Da * (1 - Sa)) * Ea + Da * (1 - Ea)
= Sa * Ea + Da * ((Ea - Sa * Ea) + (1 - Ea))
= Sa * Ea + Da * (1 - Sa * Ea)
Dcp' = (Scp + Dcp * (1 - Sa)) * Ea + Dcp * (1 - Ea)
= Scp * Ea + Dcp * (Ea - Sa * Ea + 1 - Ea)
= Scp * Ea + Dcp * (1 - Sa * Ea)
DstOver: Da' = (Sa * (1 - Da) + Da) * Ea + Da * (1 - Ea)
= Sa * Ea * (1 - Da) + Da * (Ea + (1 - Ea))
= Sa * Ea * (1 - Da) + Da
Dcp' = (Scp * (1 - Da) + Dcp) * Ea + Dcp * (1 - Ea)
= Scp * Ea * (1 - Da) + Dcp * (Ea + 1 - Ea)
= Scp * Ea * (1 - Da) + Dcp
SrcIn: Da' = Sa * Da * Ea + Da * (1 - Ea)
Dcp' = Scp * Da * Ea + Dcp * (1 - Ea)
DstIn: Da' = Da * Sa * Ea + Da * (1 - Ea)
= Da * (Sa * Ea + 1 - Ea)
= Da * (1 + Sa * Ea - Ea)
Dcp' = Dcp * Sa * Ea + Dcp * (1 - Ea)
= Dcp * (Sa * Ea + 1 - Ea)
= Dcp * (1 + Sa * Ea - Ea)
SrcOut: Da' = Sa * (1 - Da) * Ea + Da * (1 - Ea)
Dcp' = Scp * (1 - Da) * Ea + Dcp * (1 - Ea)
DstOut: Da' = Da * (1 - Sa) * Ea + Da * (1 - Ea)
= Da * (Ea - Sa * Ea + 1 - Ea)
= Da * (1 - Sa * Ea)
Dcp' = Dcp * (1 - Sa) * Ea + Dcp * (1 - Ea)
= Dcp * (Ea - Sa * Ea + 1 - Ea)
= Dcp * (1 - Sa * Ea)
Non-Premultiplied Form
======================
Clear: Da' = (0) * Ea + Da * (1 - Ea)
= Da * (1 - Ea)
Dc' = ((0) * Ea + (Dc * Da) * (1 - Ea)) / Da' , Da' != 0
= (Dc * Da * (1 - Ea)) / Da'
= Dc
Dc' = 0 , Da' == 0
Src: Da' = Sa * Ea + Da * (1 - Ea)
Dc' = ((Sc * Sa) * Ea + (Dc * Da) * (1 - Ea)) / Da' , Da' != 0
= (Sc * Sa * Ea + Dc * Da * (1 - Ea)) / Da'
Dc' = 0 , Da' == 0
SrcOver: Da' = (Sa + Da * (1 - Sa)) * Ea + Da * (1 - Ea)
= Sa * Ea + Da * ((Ea - Sa * Ea) + (1 - Ea))
= Sa * Ea + Da * (1 - Sa * Ea)
Dc' = ((Sc * Sa + Dc * Da * (1 - Sa)) * Ea + , Da' != 0
(Dc * Da) * (1 - Ea)) / Da'
= (Sc * Sa * Ea +
Dc * Da * ((Ea - Sa * Ea) + (1 - Ea))) / Da'
= (Sc * Sa * Ea + Dc * Da * (1 - Sa * Ea)) / Da'
Dc' = 0 , Da' == 0
DstOver: Da' = (Sa * (1 - Da) + Da) * Ea + Da * (1 - Ea)
= Sa * Ea * (1 - Da) + Da * (Ea + (1 - Ea))
= Sa * Ea * (1 - Da) + Da
Dc' = ((Sc * Sa * (1 - Da) + Dc * Da) * Ea + , Da' != 0
(Dc * Da) * (1 - Ea)) / Da'
= (Sc * Sa * Ea * (1 - Da) +
Dc * Da * (Ea + (1 - Ea))) / Da'
= (Sc * Sa * Ea * (1 - Da) + Dc * Da) / Da'
Dc' = 0 , Da' == 0
SrcIn: Da' = Sa * Da * Ea + Da * (1 - Ea)
Dc' = (Sc * Sa * Da * Ea + Dc * Da * (1 - Ea)) / Da' , Da' != 0
Dc' = 0 , Da' == 0
DstIn: Da' = Da * Sa * Ea + Da * (1 - Ea)
Dc' = (Dc * Da * Sa * Ea + Dc * Da * (1 - Ea)) / Da' , Da' != 0
= (Dc * Da * (Sa * Ea + 1 - Ea)) / Da'
= (Dc * Da * (1 + Sa * Ea - Ea)) / Da'
Dc' = 0 , Da' == 0
SrcOut: Da' = Sa * (1 - Da) * Ea + Da * (1 - Ea)
Dc' = (Sc * Sa * (1 - Da) * Ea + , Da' != 0
Dc * Da * (1 - Ea)) / Da'
Dc' = 0 , Da' == 0
DstOut: Da' = Da * (1 - Sa) * Ea + Da * (1 - Ea)
Dc' = (Dc * Da * (1 - Sa) * Ea + , Da' != 0
Dc * Da * (1 - Ea)) / Da'
= (Dc * Da * (Ea - Sa * Ea + 1 - Ea)) / Da'
= (Dc * Da * (1 - Sa * Ea)) / Da'
Dc' = 0 , Da' == 0
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".