\documentclass[a4paper]{article}

\usepackage{amsmath}

\newcommand{\code}{\texttt}
\newcommand{\dfn}{\textbf}

\author{Ms2ger}
\title{Notes on Philip Taylor's \code{canvas} tests}

\newtheorem{definition}{Definition}[section]

\bibliographystyle{IEEEtran}

\begin{document}
\maketitle

\abstract{\
  This document presents some notes about Philip Taylor's conformance tests
  \cite{tests} for the HTML specification, \cite{html} related to the
  Porter--Duff operators. \cite{pd}}

\section{Introductory definitions}
\begin{definition}[Color]
  A color $A$ is defined as
  $$A:=\left(r,g,b,a\right) \qquad r,g,b,a\in[0,255]$$
\end{definition}

\begin{definition}[Post-multiplied color]
  The post-multiplied representation of a color $A$ is
  $$C_A:=\left(r,g,b,\alpha\right) \qquad \alpha:=\frac a {255}$$
\end{definition}

\begin{definition}[Pre-multiplied color]
  The pre-multiplied representation of a post-multiplied color $C_A$ is
  $$c_A:=\left(\alpha\cdot r,\alpha\cdot g,\alpha\cdot b\right)$$
\end{definition}

Given a value for $F_A$ and $F_B$, we define the result of compositing colors
$A$ and $B$ as follows:

\begin{definition}[Composited colors]
  $$c_O := (r_O, g_O, b_O) := c_AF_A+c_BF_B$$
  $$\alpha_O := \alpha_AF_A+\alpha_BF_B$$
  $$C_O := \left(\frac{r_O}{\alpha_O}, \frac{g_O}{\alpha_O}, \frac{b_O}{\alpha_O}, \alpha_O\right)$$
  $$O := C_O \cdot \begin{pmatrix}
    1&0&0&0\\
    0&1&0&0\\
    0&0&1&0\\
    0&0&0&255
  \end{pmatrix}$$
\end{definition}

\section{Tests}
We use the terminology in the HTML specification: \cite{html} $A$ is the image
being rendered and $B$ is the state of the bitmap.

These are the results for the \code{2d.composite.transparent.*} tests.

\subsection{\code{source-over}}
The associated Porter--Duff operator is $$A \text{ over } B.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1,F_B=1-\alpha_A=\frac14.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= 1\cdot c_A + \frac14 \cdot c_B = \left(0,\frac18\cdot255,\frac34\cdot255\right)\\
  \alpha_O &= 1\cdot\frac34+\frac12\cdot\frac14=\frac78\\
  C_O      &= \left(0, \frac87\frac18255, \frac87\frac34255, \frac78\right)\\
  O        &= \left(0, \frac87\frac18255, \frac87\frac34255, \frac78255\right)\\
     &\approx \left(0, 36.43, 218.57, 223.13\right)\\
     &\approx \left(0, 36, 219, 223\right)
\end{align*}

The test has $(0,36,218,223)\pm5$: approved with \code{s/218/219/}.

\subsection{\code{destination-over}}
The associated Porter--Duff operator is $$B \text{ over } A.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1-\alpha_B=\frac12,F_B=1.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= \frac12\cdot c_A + 1 \cdot c_B = \left(0,\frac12\cdot255,\frac38\cdot255\right)\\
  \alpha_O &= \frac12\cdot\frac34+1\cdot\frac12=\frac78\\
  C_O      &= \left(0, \frac87\frac12255, \frac87\frac38255, \frac78\right)\\
  O        &= \left(0, \frac87\frac12255, \frac87\frac38255, \frac78255\right)\\
     &\approx \left(0, 145.71, 109.29, 223.13\right)\\
     &\approx \left(0, 146, 109, 223\right)
\end{align*}

The test has $(0,145,109,223)\pm5$: approved with \code{s/145/146/}.

\subsection{\code{source-in}}
The associated Porter--Duff operator is $$A \text{ in } B.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=\alpha_B=\frac12,F_B=0.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= \frac12\cdot c_A + 0 \cdot c_B = \left(0,0,\frac38\cdot255\right)\\
  \alpha_O &= \frac12\cdot\frac34+0\cdot\frac12=\frac38\\
  C_O      &= \left(0, 0, \frac83\frac38255, \frac38\right)\\
  O        &= \left(0, 0, 255, \frac38255\right)\\
     &\approx \left(0, 0, 255.00, 95.63\right)\\
     &\approx \left(0, 0, 255, 96\right)
\end{align*}

The test has $(0,0,255,95)\pm5$: approved with \code{s/95/96/}.

\subsection{\code{destination-in}}
The associated Porter--Duff operator is $$B \text{ in } A.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=0,F_B=\alpha_A=\frac34.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= 0\cdot c_A + \frac34\cdot c_B = \left(0,\frac38\cdot255,0\right)\\
  \alpha_O &= 0\cdot\frac34+\frac34\cdot\frac12=\frac38\\
  C_O      &= \left(0, \frac83\frac38255, 0, \frac38\right)\\
  O        &= \left(0, 255, 0, \frac38255\right)\\
     &\approx \left(0, 255.00, 0, 95.63\right)\\
     &\approx \left(0, 255, 0, 96\right)
\end{align*}

The test has $(0,255,0,95)\pm5$: approved with \code{s/95/96/}.

\subsection{\code{source-out}}
The associated Porter--Duff operator is $$A \text{ out } B.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1-\alpha_B=\frac12,F_B=0.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= \frac12\cdot c_A + 0 \cdot c_B = \left(0,0,\frac38\cdot255\right)\\
  \alpha_O &= \frac12\cdot\frac34+0\cdot\frac12=\frac38\\
  C_O      &= \left(0, 0, \frac83\frac38255, \frac38\right)\\
  O        &= \left(0, 0, 255, \frac38255\right)\\
     &\approx \left(0, 0, 255.00, 95.63\right)\\
     &\approx \left(0, 0, 255, 96\right)
\end{align*}

The test has $(0,255,0,95)\pm5$: approved with \code{s/95/96/}.

\subsection{\code{destination-out}}
The associated Porter--Duff operator is $$B \text{ out } A.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=0,F_B=1-\alpha_A=\frac14.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= 0\cdot c_A + \frac14\cdot c_B = \left(0,\frac18\cdot255,0\right)\\
  \alpha_O &= 0\cdot\frac34+\frac14\cdot\frac12=\frac18\\
  C_O      &= \left(0, 8\frac18255, 0, \frac18\right)\\
  O        &= \left(0, 255, 0, \frac18255\right)\\
     &\approx \left(0, 255.00, 0, 31.88\right)\\
     &\approx \left(0, 255, 0, 32\right)
\end{align*}

The test has $(0,255,0,31)\pm5$: approved with \code{s/31/32/}.

\subsection{\code{source-atop}}
The associated Porter--Duff operator is $$A \text{ atop } B.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=\alpha_B=\frac12,F_B=1-\alpha_A=\frac14.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= \frac12\cdot c_A + \frac14\cdot c_B = \left(0,\frac18\cdot255,\frac38\cdot255\right)\\
  \alpha_O &= \frac12\cdot\frac34+\frac14\cdot\frac12=\frac12\\
  C_O      &= \left(0, 2\frac18255, 2\frac38255, \frac12\right)\\
  O        &= \left(0, \frac14255, \frac34255, \frac12255\right)\\
           &= \left(0, 63.75, 191.25, 127.50\right)\\
     &\approx \left(0, 64, 191, 128\right)
\end{align*}

The test has $(0,63,191,127)\pm5$: approved with \code{s/63/64/} and \code{s/127/128/}.

\subsection{\code{destination-atop}}
The associated Porter--Duff operator is $$B \text{ atop } A.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1-\alpha_B=\frac12,F_B=\alpha_A=\frac34.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= \frac12\cdot c_A + \frac34\cdot c_B = \left(0,\frac38\cdot255,\frac38\cdot255\right)\\
  \alpha_O &= \frac12\cdot\frac34+\frac34\cdot\frac12=\frac34\\
  C_O      &= \left(0, \frac43\frac38255, \frac43\frac38255, \frac34\right)\\
  O        &= \left(0, \frac12255, \frac12255, \frac34255\right)\\
           &= \left(0, 127.50, 127.50, 191.25\right)\\
     &\approx \left(0, 128, 128, 191\right)
\end{align*}

The test has $(0,127,127,191)\pm5$: approved with \code{s/127/128/g}.

\subsection{\code{xor}}
The associated Porter--Duff operator is $$A \text{ xor } B.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1-\alpha_B=\frac12,F_B=1-\alpha_A=\frac14.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= \frac12\cdot c_A + \frac14\cdot c_B = \left(0,\frac18\cdot255,\frac38\cdot255\right)\\
  \alpha_O &= \frac12\cdot\frac34+\frac14\cdot\frac12=\frac12\\
  C_O      &= \left(0, 2\frac18255, 2\frac38255, \frac12\right)\\
  O        &= \left(0, \frac14255, \frac34255, \frac12255\right)\\
           &= \left(0, 63.75, 191.25, 127.50\right)\\
     &\approx \left(0, 64, 191, 128\right)
\end{align*}

The test has $(0,63,191,127)\pm5$: approved with \code{s/63/64/} and \code{s/127/128/}.

\subsection{\code{copy}}
The associated Porter--Duff operator is $$A.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1,F_B=0.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= 1\cdot c_A + 0\cdot c_B = \left(0,0,\frac34\cdot255\right)\\
  \alpha_O &= 1\cdot\frac34+0\cdot\frac12=\frac34\\
  C_O      &= \left(0, 0, \frac43\frac34255, \frac34\right)\\
  O        &= \left(0, 0, 255, \frac34255\right)\\
           &= \left(0, 0, 225.00, 191.25\right)\\
     &\approx \left(0, 0, 225, 191\right)
\end{align*}

The test has $(0,0,255,191)\pm5$: approved.

\subsection{\code{lighter}}
The associated Porter--Duff operator is $$A \text{ plus } B.$$

The test uses $$C_A = \left(0,0,255,\frac34\right), C_B = \left(0,255,0,\frac12\right),$$
and we get $$F_A=1,F_B=1.$$

We find
\begin{align*}
  c_A      &= \left(0,0,\frac34\cdot255\right)\\
  c_B      &= \left(0,\frac12\cdot255,0\right)\\
  c_O      &= 1\cdot c_A + 1\cdot c_B = \left(0,\frac12\cdot255,\frac34\cdot255\right)\\
  \alpha_O &= \max\left(1,1\cdot\frac34+1\cdot\frac12\right)=1\\
  C_O      &= \left(0, \frac12255, \frac34255, 1\right)\\
  O        &= \left(0, \frac12255, \frac34255, 255\right)\\
           &= \left(0, 127.50, 191.25, 255\right)\\
     &\approx \left(0, 128, 191, 255\right)
\end{align*}

The test has $(0,63,191,127)\pm5$: approved with \code{s/127/128/}.

\tableofcontents
\bibliography{refs}

\end{document}
