# p237RGB by Vid the Kid

## Goals

The goals of this new color space, in decreasing order of importance, are as follows:

1. Map from XYZ to new color space preserves collinearity.
2. Transfer function relating new color space gray values to actual brightness resembles that relating sRGB gray values to actual brightness.
3. Gamut is reasonable.
4. New color space has some semblance of perceptual uniformity. (As this property is expected to emerge from the others, little additional effort was made towards this goal.)

## Name

In order to meet both of the first two goals, the transformation between spaces would have to involve a perspective transformation between intermediate spaces.  In the development of the color space, there were some degrees of freedom in the choice of mapping between an intermediate color space and the final RGB color space.  There was a choice that would enclose sRGB's entire nominal range in the new color space's nominal range, matching its secondary colors, but also consisted of a high proportion of imaginary colors.  There was a choice which would put the new color space's nominal range entirely inside of sRGB's nominal range, matching its primary colors, but leaving many common bright colors outside of the new space's nominal range.  A family of compromises were considered, with three degrees of freedom.  The chosen compromise was parametrized as (28,38,78).  Given the use of a perspective transform, and to distinguish it from potential alternate choices, the color space is named p237RGB.

## Transformation

Transformation between XYZ and p237RGB is performed in three steps each way.

### XYZ to RGB

1.  u v w
= M1
 X Y Z
+ B1
2.  u' v' w'
=
 u⁄w v⁄w 1⁄w
3.  R G B
= M2 (
 X Y Z
B2 )

### RGB to XYZ

1.  u' v' w'
= M3
 R G B
+ B2
2.  u v w
=
 u'⁄w' v'⁄w' 1⁄w'
3.  X Y Z
= M4 (
 u v w
B1 )

### Referenced Matrices

• M1 =  1.25 −1.25XW 0 0 −.4ZW .4 0 1 0
=  1.25 −1.188125 0 0 −0.4356 .4 0 1 0
where XW and ZW are the X and Z coordinates of the reference white point (illuminant D65 with Y = 1).  XYZ coordinates are unity-scaled.
• M2 =  1.84764 −.8884146 −.67676542659827 −.6493278 0.0869466 −.67676542659827 .05962001 3.53482 −.67676542659827
• M3 = M2−1 =  .3707108 −.4755804 .1048696 −.07622514 −.1922456 .2684707 −.3654743 −1.046016 −.06612648
• M4 = M1−1 =  0.8 0 .9505 0 0 1 0 2.5 1.089
• B1 =  0 0 .46268656716414
• B2 =  0 0 2.1612903225808

## Gamut Considering only chromaticity, the gamut of p237RGB is considerably larger than that of sRGB, illustrated in the above graphic.  The extents are somewhere between those of Adobe RGB and Wide Gamut RGB, also by Adobe.  Some imaginary chromaticities fall within p237RGB's gamut, near the red and blue primary axes. With nearly all RGB color spaces, the gamut over chromaticities is caused by the requirement that color components are represented with nonnegative numbers.  If negative values are allowed for one or more channels, and the meaning of negative values well-defined, then any chromaticity becomes possible.

Considering an upper limit on RGB values — specifically, that an RGB value in any channel for a “normal” color is not greater than the value in the same channel for the reference white — the gamut of p237RGB actually falls a bit short of covering the entire sRGB gamut.  The “brightest” colors representable in sRGB are not representable in p237RGB if RGB values are limited to the nominal range [0…1]. The graphic below illustrates the cuboid region which is common to the nominal gamut of both sRGB and p237RGB.  The coordinates given are in p237RGB and can hint at what deeper colors are representable in p237RGB but cannot be displayed on a typical computer screen. It is the author's opinion that the “bright” colors possible in sRGB which would require greater-than-one values in p237RGB aren't typically reproducible by typical consumer printers. Therefore, if content is to eventually be printed, it may be advisable to stay within p237RGB's slightly reduced range at the content creation stage.

If RGB values greater than one are allowed, p237RGB can easily represent the brighter colors of sRGB's nominal gamut.  Furthermore, because of the perspective transform, the gamut of p237RGB actually extends to colors of infinite luminosity with finite RGB values.

The primary requirement in the development of this color space is that collinearity is preserved in conversion to and from CIE XYZ. A physical mix of two light sources of different colors will lie on a line in the XYZ color space; the same property was desired for the new color space, so therefore preservation of collinearity was made a priority.  As a result, linear numerical interpolations between two colors in p237RGB represent linear physical combinations of physical light sources in those two colors.  This feature is not true of RGB color systems that utilize nonlinear transfer functions independently for each channel, as most do.

Preservation of collinearity ensures that colors in a p237RGB linear gradient are accurate interpolations between the endpoint colors.  As a (wanted) side-effect of the desired grayscale transfer curve, linear gradients in p237RGB usually do not, however, have a pace that is linear in CIE XYZ space.  Instead, the colors in a gradient change at a fairly uniform pace in human perception.  Noticeable exceptions occur when one endpoint of the gradient is black, as the color seems to change a bit more rapidly towards the black end; still, this is less noticeable than it would be if the gradient were interpolated in CIE XYZ.  Additionally, in most nonlinear RGB color spaces, if a gradient changes primarily in one channel whose value is zero at one end but the color is not black, that end will have almost no perceptible color change near that end; this phenomenon does not occur in p237RGB.

## Grayscale Conversion

Colors in p237RGB can easily be converted to grayscale without converting to other color spaces.  In the intermediate stages of transformation between XYZ and RGB, the w parameter depends only on the Y (luminance) value in XYZ.  In the next stage, w' depends only on ww' can be calculated from p237RGB as a weighted sum of the RGB components and a bias term, though its scale isn't convenient as a general luminance measurement.  Instead, we can use a new parameter, linearly related to w': w* = .2473R + .7079G + .0448B.  If a color is modified so its R, G, and B values are replaced by their w* weighted average, the resulting color is a pure gray with the same luminance (CIE Y value) as the original color.

## Perceptual Uniformity

p237RGB comes relatively close to being perceptually uniform, compared to other RGB color spaces.  Euclidean distance between colors in p237RGB may be a better predictor of perceived color difference than in other RGB spaces.  However, such a metric would tend to underestimate perceived difference between colors of different chroma, and overestimate that between colors of different luminance. Perhaps an even better metric is Euclidean distance in the intermediate u'v'w' space described above.  An alternative final transformation (which would result in pmpRGB) was considered which put perceptual uniformity above gamut in importance, but this was abandoned when it became apparent that a unity-clamped RGB space in such an arrangement would exclude colors with high or even moderate saturation.  For the purposes of measuring color difference, however, p237RGB can be transformed via a simple matrix into pmpRGB, in which Euclidean distance should be a fairly good predictor of perceived color difference.

 Rmp Gmp Bmp
=
 1.4268 −.164 −.2628 −.7679 2.4438 −.6759 .083 −.1561 1.073
 R G B