Khronos Data Format Specification v1.2 rev 1

Khronos Data Format Specification License Information

This specification is protected by copyright laws and contains material proprietary to the Khronos Group, Inc. It or any components may not be reproduced, republished, distributed, transmitted, displayed, broadcast, or otherwise exploited in any manner without the express prior written permission of Khronos Group. You may use this specification for implementing the functionality therein, without altering or removing any trademark, copyright or other notice from the specification, but the receipt or possession of this specification does not convey any rights to reproduce, disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe, in whole or in part.

This version of the Data Format Specification is published and copyrighted by Khronos, but is not a Khronos ratified specification. Accordingly, it does not fall within the scope of the Khronos IP policy, except to the extent that sections of it are normatively referenced in ratified Khronos specifications. Such references incorporate the referenced sections into the ratified specifications, and bring those sections into the scope of the policy for those specifications.

Khronos Group grants express permission to any current Promoter, Contributor or Adopter member of Khronos to copy and redistribute UNMODIFIED versions of this specification in any fashion, provided that NO CHARGE is made for the specification and the latest available update of the specification for any version of the API is used whenever possible. Such distributed specification may be reformatted AS LONG AS the contents of the specification are not changed in any way. The specification may be incorporated into a product that is sold as long as such product includes significant independent work developed by the seller. A link to the current version of this specification on the Khronos Group website should be included whenever possible with specification distributions.

Khronos Group makes no, and expressly disclaims any, representations or warranties, express or implied, regarding this specification, including, without limitation, any implied warranties of merchantability or fitness for a particular purpose or non-infringement of any intellectual property. Khronos Group makes no, and expressly disclaims any, warranties, express or implied, regarding the correctness, accuracy, completeness, timeliness, and reliability of the specification. Under no circumstances will the Khronos Group, or any of its Promoters, Contributors or Members or their respective partners, officers, directors, employees, agents, or representatives be liable for any damages, whether direct, indirect, special or consequential damages for lost revenues, lost profits, or otherwise, arising from or in connection with these materials.

Khronos, SYCL, SPIR, WebGL, EGL, COLLADA, StreamInput, OpenVX, OpenKCam, glTF, OpenKODE, OpenVG, OpenWF, OpenSL ES, OpenMAX, OpenMAX AL, OpenMAX IL and OpenMAX DL are trademarks and WebCL is a certification mark of the Khronos Group Inc. OpenCL is a trademark of Apple Inc. and OpenGL and OpenML are registered trademarks and the OpenGL ES and OpenGL SC logos are trademarks of Silicon Graphics International used under license by Khronos. All other product names, trademarks, and/or company names are used solely for identification and belong to their respective owners.

Revision History
Revision 0.1 Jan 2015 AG
Initial sharing
Revision 0.2 Feb 2015 AG
Revision 0.3 Feb 2015 AG
Further cleanup
Revision 0.4 Apr 2015 AG
Channel ordering standardized
Revision 0.5 Apr 2015 AG
Typos and clarification
Revision 1.0 May 2015 AG
Submission for 1.0 release
Revision 1.0 rev 2 Jun 2015 AG
Clarifications for 1.0 release
Revision 1.0 rev 3 Jul 2015 AG
Revision 1.0 rev 4 Jul 2015 AG
Clarified KHR_DF_SAMPLE_DATATYPE_LINEAR
Revision 1.0 rev 5 Mar 2019 AG
Clarification and typography
Revision 1.1 Nov 2015 AG
Added definitions of compressed texture formats
Revision 1.1 rev 2 Jan 2016 AG
Added definitions of floating point formats
Revision 1.1 rev 3 Feb 2016 AG
Fixed typo in sRGB conversion (thank you, Tom Grim!)
Revision 1.1 rev 4 Mar 2016 AG
Fixed typo/clarified sRGB in ASTC, typographical improvements
Revision 1.1 rev 5 Mar 2016 AG
Switch to official Khronos logo, removed scripts, restored title
Revision 1.1 rev 6 Jun 2016 AG
ASTC "block footprint" note, fixed credits/changelog/contents
Revision 1.1 rev 7 Sep 2016 AG
ASTC multi-point "part" and quint decode typo fixes
Revision 1.1 rev 8 Jun 2017 AG
ETC2 legibility and table typo fix
Revision 1.1 rev 9 Mar 2019 AG
Typo fixes and much reformatting
Revision 1.2 rev 0 Sep 2017 AG
Added color conversion formulae and extra options
Revision 1.2 rev 1 Mar 2019 AG
Typo fixes and much reformatting

Abstract

This document describes a data format specification for non-opaque (user-visible) representations of user data to be used by, and shared between, Khronos standards. The intent of this specification is to avoid replication of incompatible format descriptions between standards and to provide a definitive mechanism for describing data that avoids excluding useful information that may be ignored by other standards. Other APIs are expected to map internal formats to this standard scheme, allowing formats to be shared and compared. This document also acts as a reference for the memory layout of a number of common compressed texture formats, and describes conversion between a number of common color spaces.

1. Introduction

Many APIs operate on bulk data — buffers, images, volumes, etc. — each composed of many elements with a fixed and often simple representation. Frequently, multiple alternative representations of data are supported: vertices can be represented with different numbers of dimensions, textures may have different bit depths and channel orders, and so on. Sometimes the representation of the data is highly specific to the application, but there are many types of data that are common to multiple APIs — and these can reasonably be described in a portable manner. In this standard, the term data format describes the representation of data.

It is typical for each API to define its own enumeration of the data formats on which it can operate. This causes a problem when multiple APIs are in use: the representations are likely to be incompatible, even where the capabilities intersect. When additional format-specific capabilities are added to an API which was designed without them, the description of the data representation often becomes inconsistent and disjoint. Concepts that are unimportant to the core design of an API may be represented simplistically or inaccurately, which can be a problem as the API is enhanced or when data is shared.

Some APIs do not have a strict definition of how to interpret their data. For example, a rendering API may treat all color channels of a texture identically, leaving the interpretation of each channel to the user’s choice of convention. This may be true even if color channels are given names that are associated with actual colors — in some APIs, nothing stops the user from storing the blue quantity in the red channel and the red quantity in the blue channel. Without enforcing a single data interpretation on such APIs, it is nonetheless often useful to offer a clear definition of the color interpretation convention that is in force, both for code maintenance and for communication with external APIs which do have a defined interpretation. Should the user wish to use an unconventional interpretation of the data, an appropriate descriptor can be defined that is specific to this choice, in order to simplify automated interpretation of the chosen representation and to provide concise documentation.

Where multiple APIs are in use, relying on an API-specific representation as an intermediary can cause loss of important information. For example, a camera API may associate color space information with a captured image, and a printer API may be able to operate with that color space, but if the data is passed through an intermediate compute API for processing and that API has no concept of a color space, the useful information may be discarded.

The intent of this standard is to provide a common, consistent, machine-readable way to describe those data formats which are amenable to non-proprietary representation. This standard provides a portable means of storing the most common descriptive information associated with data formats, and an extension mechanism that can be used when this common functionality must be supplemented.

While this standard is intended to support the description of many kinds of data, the most common class of bulk data used in Khronos standards represents color information. For this reason, the range of standard color representations used in Khronos standards is diverse, and a significant portion of this specification is devoted to color formats.

Later sections provide a description of the memory layout of a number of common texture compression formats, and describe some of the common color space conversions.

2. Overview

This document describes a standard layout for a data structure that can be used to define the representation of simple, portable, bulk data. Using such a data structure has the following benefits:

• Ensuring a precise description of the portable data
• Simplifying the writing of generic functionality that acts on many types of data
• Offering portability of data between APIs

The “bulk data” may be, for example:

• Pixel/texel data
• Vertex data
• A buffer of simple type

The layout of proprietary data structures is beyond the remit of this specification, but the large number of ways to describe colors, vertices and other repeated data makes standardization useful.

The data structure in this specification describes the elements in the bulk data in memory, not the layout of the whole. For example, it may describe the size, location and interpretation of color channels within a pixel, but is not responsible for determining the mapping between spatial coordinates and the location of pixels in memory. That is, two textures which share the same pixel layout can share the same descriptor as defined in this specification, but may have different sizes, line strides, tiling or dimensionality. An example pixel format is described in Figure 1: a single 5:6:5-bit pixel with blue in the low 5 bits, green in the next 6 bits, and red in the top 5 bits of a 16-bit word as laid out in memory on a little-endian machine (see Table 28).

In some cases, the elements of bulk texture data may not correspond to a conventional texel. For example, in a compressed texture it is common for the atomic element of the buffer to represent a rectangular block of texels. Alternatively the representation of the output of a camera may have a repeating pattern according to a Bayer or other layout, as shown in Figure 2. It is this repeating and self-contained atomic unit, termed a texel block, that is described by this standard.

The sampling or reconstruction of texel data is not a function of the data format. That is, a texture has the same format whether it is point sampled or a bicubic filter is used, and the manner of reconstructing full color data from a camera sensor is not defined. Where information making up the data format has a spatial aspect, this is part of the descriptor: it is part of the descriptor to define the spatial configuration of color samples in a Bayer sensor or whether the chroma difference channels in a Y′CBCR format are considered to be centered or co-sited, but not how this information must be used to generate coordinate-aligned full color values.

The data structure defined in this specification is termed a data format descriptor. This is an extensible block of contiguous memory, with a defined layout. The size of the data format descriptor depends on its content, but is also stored in a field at the start of the descriptor, making it possible to copy the data structure without needing to interpret all possible contents.

The data format descriptor is divided into one or more descriptor blocks, each also consisting of contiguous data, as shown in Table 1. These descriptor blocks may, themselves, be of different sizes, depending on the data contained within. The size of a descriptor block is stored as part of its data structure, allowing applications to process a data format descriptor while skipping contained descriptor blocks that it does not need to understand. The data format descriptor mechanism is extensible by the addition of new descriptor blocks.

Table 1. Data format descriptor and descriptor blocks

Data format descriptor

 Descriptor block 1 Descriptor block 2 :

The diversity of possible data makes a concise description that can support every possible format impractical. This document describes one type of descriptor block, a basic descriptor block, that is expected to be the first descriptor block inside the data format descriptor where present, and which is sufficient for a large number of common formats, particularly for pixels. Formats which cannot be described within this scheme can use additional descriptor blocks of other types as necessary.

Later sections of this specification provide a description of the in-memory representation of a number of common compressed texture formats, and describe several common color spaces.

Glossary

Data format: The interpretation of individual elements in bulk data. Examples include the channel ordering and bit positions in pixel data or the configuration of samples in a Bayer image. The format describes the elements, not the bulk data itself: an image’s size, stride, tiling, dimensionality, border control modes, and image reconstruction filter are not part of the format and are the responsibility of the application.

Data format descriptor: A contiguous block of memory containing information about how data is represented, in accordance with this specification. A data format descriptor is a container, within which can be found one or more descriptor blocks. This specification does not define where or how the the data format descriptor should be stored, only its content. For example, the descriptor may be directly prepended to the bulk data, perhaps as part of a file format header, or the descriptor may be stored in a CPU memory while the bulk data that it describes resides within GPU memory; this choice is application-specific.

(Data format) descriptor block: A contiguous block of memory with a defined layout, held within a data format descriptor. Each descriptor block has a common header that allows applications to identify and skip descriptor blocks that it does not understand, while continuing to process any other descriptor blocks that may be held in the data format descriptor.

Basic (data format) descriptor block: The initial form of descriptor block as described in this standard. Where present, it must be the first descriptor block held in the data format descriptor. This descriptor block can describe a large number of common formats and may be the only type of descriptor block that many portable applications will need to support.

Texel block: The units described by the Basic Data Format Descriptor: a repeating element within bulk data. In simple texture formats, a texel block may describe a single pixel. In formats with subsampled channels, the texel block may describe several pixels. In a block-based compressed texture, the texel block typically describes the compression block unit. The basic descriptor block supports texel blocks of up to four dimensions.

Sample: In this standard, texel blocks are considered to be composed of contiguous bit patterns with a single channel or component type and a single spatial location. A typical ARGB pixel has four samples, one for each channel, held at the same coordinate. A texel block from a Bayer sensor might have a different location for different channels, and may have multiple samples representing the same channel at multiple locations. A Y′CBCR buffer with downsampled chroma may have more luma samples than chroma, each at different locations.

Plane: In some formats, a texel block is not contiguous in memory. In a two-dimensional texture, the texel block may be spread across multiple scan lines, or channels may be stored independently. The basic format descriptor block defines a texel block as being made of a number of concatenated bits which may come from different regions of memory, where each region is considered a separate plane. For common formats, it is sufficient to require that the contribution from each plane is an integer number of bytes. This specification places no requirements on the ordering of planes in memory — the plane locations are described outside the format. This allows support for multiplanar formats which have proprietary padding requirements that are hard to accommodate in a more terse representation.

In many existing APIs, planes may be “downsampled” differently. For example, in these APIs, a Y′CBCR (colloquially YUV) 4:2:0 buffer as in Table 2 (with byte offsets shown for each channel/location) would typically be represented with three planes (Table 3), one for each channel, with the luma (Y′) plane containing four times as many pixels as the chroma (CB and CR) planes, and with two horizontal lines of the luma held within the same plane for each horizontal line of the chroma planes.

Table 2. Possible memory representation of a 4×4 Y′CBCR 4:2:0 buffer

Y′ channel

 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

CB channel

 16 17 18 19

CR channel

 20 21 22 23

Table 3. Plane descriptors for the above Y′CBCR-format buffer in a conventional API

 Y′ plane offset 0 byte stride 4 downsample 1×1 CB plane offset 16 byte stride 2 downsample 2×2 CR plane offset 20 byte stride 2 downsample 2×2

This approach does not extend logically to more complex formats such as a Bayer grid. Therefore in this specification, we would instead define the luma channel as in Table 4, using two planes, vertically interleaved (in a linear mapping between addresses and samples) by the selection of a suitable offset and line stride, with each line of luma samples contiguous in memory. Only one plane is used for each of the chroma channels (or one plane collectively if the chroma samples are stored adjacently).

Table 4. Plane descriptors for the above Y′CBCR-format buffer using this standard

 Y′ plane 1 offset 0 byte stride 8 plane bytes 2 Y′ plane 2 offset 4 byte stride 8 plane bytes 2 CB plane offset 16 byte stride 2 plane bytes 1 CR plane offset 20 byte stride 2 plane bytes 1

The same approach can be used to represent a static interlaced image, with a texel block consisting of two planes, one per field. This mechanism is all that is required to represent a static image without downsampled channels; however correct reconstruction of interlaced, downsampled color difference formats (such as Y′CBCR), which typically involves interpolation of the nearest chroma samples in a given field rather than the whole frame, is beyond the remit of this specification. There are many proprietary and often heuristic approaches to sample reconstruction, particularly for Bayer-like formats and for multi-frame images, and it is not practical to document them here.

There is no expectation that the internal format used by an API that wishes to make use of the Khronos Data Format Specification must use this specification’s representation internally: reconstructing downsampling information from this standard’s representation in order to revert to the more conventional representation should be trivial if required.

There is no requirement that the number of bytes occupied by the texel block be the same in each plane. The descriptor defines the number of bytes that the texel block occupies in each plane, which for most formats is sufficient to allow access to consecutive elements. For a two-dimensional data structure, it is up to the controlling interface to resolve byte stride between consecutive lines. For a three-dimensional structure, the controlling API may need to add a level stride. Since these strides are determined by the data size and architecture alignment requirements, they are not considered to be part of the format.

3. Required concepts not in the “format”

This specification encodes how atomic data should be interpreted in a manner which is independent of the layout and dimensionality of the collective data. Collections of data may have a “compatible format” in that their format descriptor may be identical, yet be different sizes. Some additional information is therefore expected to be recorded alongside the “format description”.

The API which controls the bulk data is responsible for controlling which memory location corresponds to the indexing mechanism chosen. A texel block has the concept of a coordinate offset within the block, which implies that if the data is accessed in terms of spatial coordinates, a texel block has spatial locality as well as referring to contiguous memory (per plane). For texel blocks which represent only a single spatial location, this is irrelevant; for block-based compression, for formats with downsampled channels, or for Bayer-like formats, the texel block represents a finite extent in up to four dimensions. However, the mapping from coordinate system to the memory location containing a texel block is beyond the control of this API.

The minimum requirements for accessing a linearly-addressed buffer is to store the start address and a stride (typically in bytes) between texels in each dimension of the buffer, for each plane contributing to the texel block. For the first dimension, the memory stride between texels may simply be the byte size of texel block in that plane — this implies that there are no gaps between texel blocks. For other dimensions, the stride is a function of the size of the data structure being represented — for example, in a compact representation of a two-dimensional buffer, the texel block at coordinate (x,y+1) might be found at the address of coordinate (x,y) plus the buffer width multiplied by the texel size in bytes. Similarly in a three-dimensional buffer, the address of the pixel at (x,y,z+1) may be at the address of (x,y,z) plus the byte size of a two-dimensional slice of the texture. In practice, even linear layouts may have padding, and often more complex relationships between coordinates and memory location are used to encourage locality of reference. The details of all of these data structures are beyond the remit of this specification.

Most simple formats contain a single plane of data. Those formats which require additional planes compared with a conventional representation are typically downsampled Y′CBCR formats, which already have the concept of separate storage for different color channels. While this specification uses multiple planes to describe texel blocks that span multiple scan lines if the data is disjoint, there is no expectation that the API using the data formats needs to maintain this representation — interleaved planes should be easy to identify and coalesce if the API requires a more conventional representation of downsampled formats.

Some image representations are composed of tiles of texels which are held contiguously in memory, with the texels within the tile stored in some order that improves locality of reference for multi-dimensional access. This is a common approach to improve memory efficiency when texturing. While it is possible to represent such a tile as a large texel block (up to the maximum representable texel block size in this specification), this is unlikely to be an efficient approach, since a large number of samples will be needed and the layout of a tile usually has a very limited number of possibilities. In most cases, the layout of texels within the tile should be described by whatever interface is aware of image-specific information such as size and stride, and only the format of the texels should be described by a format descriptor.

The complication to this is where texel blocks larger than a single pixel are themselves encoded using proprietary tiling. The spatial layout of samples within a texel block is required to be fixed in the basic format descriptor — for example, if the texel block size is 2×2 pixels, the top left pixel might always be expected to be in the first byte in that texel block. In some proprietary memory tiling formats, such as ones that store small rectangular blocks in raster order in consecutive bytes or in Morton order, this relationship may be preserved, and the only proprietary operation is finding the start of the texel block. In other proprietary layouts such as Hilbert curve order, or when the texel block size does not divide the tiling size, a direct representation of memory may be impossible. In these cases, it is likely that this data format standard would be used to describe the data as it would be seen in a linear format, and the mapping from coordinates to memory would have to be hidden in proprietary translation. As a logical format description, this is unlikely to be critical, since any software which accesses such a layout will necessarily need proprietary knowledge anyway.

4. Translation to API-specific representations

The data format container described here is too unwieldy to be expected to be used directly in most APIs. The expectation is that APIs and users will define data descriptors in memory, but have API-specific names for the formats that the API supports. If these names are enumeration values, a mapping can be provided by having an array of pointers to the data descriptors, indexed by the enumeration. It may commonly be necessary to provide API-specific supplementary information in the same array structure, particularly where the API natively associates concepts with the data which is not uniquely associated with the content.

In this approach, it is likely that an API would predefine a number of common data formats which are natively supported. If there is a desire to support dynamic creation of data formats, this array could be made extensible with a manager returning handles.

Even where an API supports only a fixed set of formats, it is flexible to provide a comparison with user-provided format descriptors in order to establish whether a format is compatible.

5. Data format descriptor

The layout of the data structures described here are assumed to be little-endian for the purposes of data transfer, but may be implemented in the natural endianness of the platform for internal use.

The data format descriptor consists of a contiguous area of memory, as shown in Table 5, divided into one or more descriptor blocks, which are tagged by the type of descriptor that they contain. The size of the data format descriptor varies according to its content.

Table 5. Data Format Descriptor layout

 uint32_t totalSize Descriptor block First descriptor Descriptor block Second descriptor (optional) etc.

The totalSize field, measured in bytes, allows the full format descriptor to be copied without need for details of the descriptor to be interpreted. totalSize includes its own uint32_t, not just the following descriptor blocks. For example, we will see below that a four-sample Khronos Basic Data Format Descriptor Block occupies 88 bytes; if there are no other descriptor blocks in the data format descriptor, the totalSize field would then indicate 88 + 4 bytes (for the totalSize field itself) for a final value of 92.

6. Descriptor block

Each Descriptor Block has the same prefix, shown in Table 6.

Table 6. Descriptor Block layout

 uint32_t vendorId | (descriptorType << 16) uint32_t versionNumber | (descriptorBlockSize << 16) Format-specific data

The vendorId is a 16-bit value uniquely assigned to organisations, allocated by Khronos; ID 0 is used to identify Khronos itself. The ID 0xFFFF is reserved for internal use which is guaranteed not to clash with third-party implementations; this ID should not be shipped in libraries to avoid conflicts with development code.

The descriptorType is a unique identifier defined by the vendor to distinguish between potential data representations.

The versionNumber is vendor-defined, and is intended to allow for backwards-compatible updates to existing descriptor blocks.

The descriptorBlockSize indicates the size in bytes of this Descriptor Block, remembering that there may be multiple Descriptor Blocks within one container, as shown in Table 7. The descriptorBlockSize therefore gives the offset between the start of the current Descriptor Block and the start of the next — so the size includes the vendorId, descriptorType, versionNumber and descriptorBlockSize fields, which collectively contribute 8 bytes.

Having an explicit descriptorBlockSize allows implementations to skip a descriptor block whose format is unknown, allowing known data to be interpreted and unknown information to be ignored. Some descriptor block types may not be of a uniform size, and may vary according to the content within.

This specification initially describes only one type of descriptor block. Future revisions may define additional descriptor block types for additional applications — for example, to describe data with a large number of channels or pixels described in an arbitrary color space. Vendors can also implement proprietary descriptor blocks to hold vendor-specific information within the standard Descriptor.

totalSize

 vendorId | (descriptorType << 16) versionNumber | (descriptorBlockSize << 16) :
 vendorId | (descriptorType << 16) versionNumber | (descriptorBlockSize << 16) :

7. Khronos Basic Data Format Descriptor Block

One basic descriptor block, shown in Table 8 is intended to cover a large amount of metadata that is typically associated with common bulk data — most notably image or texture data. While this descriptor contains more information about the data interpretation than is needed by many applications, having a relatively comprehensive descriptor reduces the risk that metadata needed by different APIs will be lost in translation.

The format is described in terms of a repeating axis-aligned texel block composed of samples. Each sample contains a single channel of information with a single spatial offset within the texel block, and consists of an amount of contiguous data. This descriptor block consists of information about the interpretation of the texel block as a whole, supplemented by a description of a number of samples taken from one or more planes of contiguous memory. For example, a 24-bit red/green/blue format may be described as a 1×1 pixel region, containing three samples, one of each color, in one plane. A Y′CBCR 4:2:0 format may consist of a repeating 2×2 region consisting of four Y′ samples and one sample each of CB and CR.

Table 8. Basic Data Format Descriptor layout

Byte 0 (LSB)   Byte 1   Byte 2   Byte 3 (MSB)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

24 + 16 × #samples (descriptorBlockSize)

colorModel

colorPrimaries

transferFunction

flags

texelBlockDimension0

texelBlockDimension1

texelBlockDimension2

texelBlockDimension3

bytesPlane0

bytesPlane1

bytesPlane2

bytesPlane3

bytesPlane4

bytesPlane5

bytesPlane6

bytesPlane7

Sample information for the first sample

Sample information for the second sample (optional), etc.

The fields of the Basic Data Format Descriptor Block are described in the following sections.

7.1. vendorId

The vendorId for the Basic Data Format Descriptor Block is 0, defined as KHR_DF_VENDORID_KHRONOS in the enum khr_df_vendorid_e.

7.2. descriptorType

The descriptorType for the Basic Data Format Descriptor Block is 0, a value reserved in the enum of Khronos-specific descriptor types, khr_df_khr_descriptortype_e, as KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT.

7.3. versionNumber

The versionNumber relating to the Basic Data Format Descriptor Block as described in this specification is 1.

7.4. descriptorBlockSize

The size of the Basic Data Format Descriptor Block depends on the number of samples contained within it. The memory requirements for this format are 24 bytes of shared data plus 16 bytes per sample. The descriptorBlockSize is measured in bytes.

7.5. colorModel

The colorModel determines the set of color (or other data) channels which may be encoded within the data, though there is no requirement that all of the possible channels from the colorModel be present. Most data fits into a small number of common color models, but compressed texture formats each have their own color model enumeration. Note that the data need not actually represent a color — this is just the most common type of content using this descriptor. Some standards use color container for this concept.

The available color models are described in the khr_df_model_e enumeration, and are represented as an unsigned 8-bit value.

Note that the numbering of the component channels is chosen such that those channel types which are common across multiple color models have the same enumeration value. That is, alpha is always encoded as channel ID 15, depth is always encoded as channel ID 14, and stencil is always encoded as channel ID 13. Luma/Luminance is always in channel ID 0. This numbering convention is intended to simplify code which can process a range of color models. Note that there is no guarantee that models which do not support these channels will not use this channel ID. Particularly, RGB formats do not have luma in channel 0, and a 16-channel undefined format is not obligated to represent alpha in any way in channel number 15.

The value of each enumerant is shown in parentheses following the enumerant name.

7.5.1. KHR_DF_MODEL_UNSPECIFIED (= 0)

When the data format is unknown or does not fall into a predefined category, utilities which perform automatic conversion based on an interpretation of the data cannot operate on it. This format should be used when there is no expectation of portable interpretation of the data using only the basic descriptor block.

For portability reasons, it is recommended that pixel-like formats with up to sixteen channels, but which cannot have those channels described in the basic block, be represented with a basic descriptor block with the appropriate number of samples from UNSPECIFIED channels, and then for the channel description to be stored in an extension block. This allows software which understands only the basic descriptor to be able to perform operations that depend only on channel location, not channel interpretation (such as image cropping). For example, a camera may store a raw format taken with a modified Bayer sensor, with RGBW (red, green, blue and white) sensor sites, or RGBE (red, green, blue and “emerald”). Rather than trying to encode the exact color coordinates of each sample in the basic descriptor, these formats could be represented by a four-channel UNSPECIFIED model, with an extension block describing the interpretation of each channel.

7.5.2. KHR_DF_MODEL_RGBSDA (= 1)

This color model represents additive colors of three channels, nominally red, green and blue, supplemented by channels for alpha, depth and stencil, as shown in Table 9. Note that in many formats, depth and stencil are stored in a completely independent buffer, but there are formats for which integrating depth and stencil with color data makes sense.

Table 9. Basic Data Format RGBSDA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_RGBSDA_RED

Red

1

KHR_DF_CHANNEL_RGBSDA_GREEN

Green

2

KHR_DF_CHANNEL_RGBSDA_BLUE

Blue

13

KHR_DF_CHANNEL_RGBSDA_STENCIL

Stencil

14

KHR_DF_CHANNEL_RGBSDA_DEPTH

Depth

15

KHR_DF_CHANNEL_RGBSDA_ALPHA

Alpha (opacity)

Portable representation of additive colors with more than three primaries requires an extension to describe the full color space of the channels present. There is no practical way to do this portably without taking significantly more space.

7.5.3. KHR_DF_MODEL_YUVSDA (= 2)

This color model represents color differences with three channels, nominally luma (Y′) and two color-difference chroma channels, U (CB) and V (CR), supplemented by channels for alpha, depth and stencil, as shown in Table 10. These formats are distinguished by CB and CR being a delta between the Y′ channel and the blue and red channels respectively, rather than requiring a full color matrix. The conversion between Y′CBCR and RGB color spaces is defined in this case by the choice of value in the colorPrimaries field as described in Section 15.1.

 Most single-channel luma/luminance monochrome data formats should select KHR_DF_MODEL_YUVSDA and use only the Y channel, unless there is a reason to do otherwise.

Table 10. Basic Data Format YUVSDA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_YUVSDA_Y

Y/Y′ (luma/luminance)

1

KHR_DF_CHANNEL_YUVSDA_CB

CB (alias for U)

1

KHR_DF_CHANNEL_YUVSDA_U

U (alias for CB)

2

KHR_DF_CHANNEL_YUVSDA_CR

CR (alias for V)

2

KHR_DF_CHANNEL_YUVSDA_V

V (alias for CR)

13

KHR_DF_CHANNEL_YUVSDA_STENCIL

Stencil

14

KHR_DF_CHANNEL_YUVSDA_DEPTH

Depth

15

KHR_DF_CHANNEL_YUVSDA_ALPHA

Alpha (opacity)

 Terminology for this color model is often abused. This model is based on the idea of creating a representation of monochrome light intensity as a weighted average of color channels, then calculating color differences by subtracting two of the color channels from this monochrome value. Proper names vary for each variant of the ensuing numbers, but YUV is colloquially used for all of them. In the television standards from which this terminology is derived, Y′CBCR is more formally used to describe the representation of these color differences. See Section 15.1 for more detail.

7.5.4. KHR_DF_MODEL_YIQSDA (= 3)

This color model represents color differences with three channels, nominally luma (Y) and two color-difference chroma channels, I and Q, supplemented by channels for alpha, depth and stencil, as shown in Table 11. This format is distinguished by I and Q each requiring all three additive channels to evaluate. I and Q are derived from CB and CR by a 33-degree rotation.

Table 11. Basic Data Format YIQSDA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_YIQSDA_Y

Y (luma)

1

KHR_DF_CHANNEL_YIQSDA_I

I (in-phase)

2

KHR_DF_CHANNEL_YIQSDA_Q

13

KHR_DF_CHANNEL_YIQSDA_STENCIL

Stencil

14

KHR_DF_CHANNEL_YIQSDA_DEPTH

Depth

15

KHR_DF_CHANNEL_YIQSDA_ALPHA

Alpha (opacity)

7.5.5. KHR_DF_MODEL_LABSDA (= 4)

This color model represents the ICC perceptually-uniform L*a*b* color space, combined with the option of an alpha channel, as shown in Table 12.

Table 12. Basic Data Format LABSDA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_LABSDA_L

L* (luma)

1

KHR_DF_CHANNEL_LABSDA_A

a*

2

KHR_DF_CHANNEL_LABSDA_B

b*

13

KHR_DF_CHANNEL_LABSDA_STENCIL

Stencil

14

KHR_DF_CHANNEL_LABSDA_DEPTH

Depth

15

KHR_DF_CHANNEL_LABSDA_ALPHA

Alpha (opacity)

7.5.6. KHR_DF_MODEL_CMYKA (= 5)

This color model represents secondary (subtractive) colors and the combined key (black) channel, along with alpha, as shown in Table 13.

Table 13. Basic Data Format CMYKA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_CMYKA_CYAN

Cyan

1

KHR_DF_CHANNEL_CMYKA_MAGENTA

Magenta

2

KHR_DF_CHANNEL_CMYKA_YELLOW

Yellow

3

KHR_DF_CHANNEL_CMYKA_KEY

Key/Black

15

KHR_DF_CHANNEL_CMYKA_ALPHA

Alpha (opacity)

7.5.7. KHR_DF_MODEL_XYZW (= 6)

This “color model” represents channel data used for coordinate values, as shown in Table 14 — for example, as a representation of the surface normal in a bump map. Additional channels for higher-dimensional coordinates can be used by extending the channel number within the 4-bit limit of the channelType field.

Table 14. Basic Data Format XYZW channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_XYZW_X

X

1

KHR_DF_CHANNEL_XYZW_Y

Y

2

KHR_DF_CHANNEL_XYZW_Z

Z

3

KHR_DF_CHANNEL_XYZW_W

W

7.5.8. KHR_DF_MODEL_HSVA_ANG (= 7)

This color model represents color differences with three channels, value (luminance or luma), saturation (distance from monochrome) and hue (dominant wavelength), supplemented by an alpha channel, as shown in Table 15. In this model, the hue relates to the angular offset on a color wheel.

Table 15. Basic Data Format angular HSVA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_HSVA_ANG_VALUE

V (value)

1

KHR_DF_CHANNEL_HSVA_ANG_SATURATION

S (saturation)

2

KHR_DF_CHANNEL_HSVA_ANG_HUE

H (hue)

15

KHR_DF_CHANNEL_HSVA_ANG_ALPHA

Alpha (opacity)

7.5.9. KHR_DF_MODEL_HSLA_ANG (= 8)

This color model represents color differences with three channels, lightness (maximum intensity), saturation (distance from monochrome) and hue (dominant wavelength), supplemented by an alpha channel, as shown in Table 16. In this model, the hue relates to the angular offset on a color wheel.

Table 16. Basic Data Format angular HSLA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS

L (lightness)

1

KHR_DF_CHANNEL_HSLA_ANG_SATURATION

S (saturation)

2

KHR_DF_CHANNEL_HSLA_ANG_HUE

H (hue)

15

KHR_DF_CHANNEL_HSLA_ANG_ALPHA

Alpha (opacity)

7.5.10. KHR_DF_MODEL_HSVA_HEX (= 9)

This color model represents color differences with three channels, value (luminance or luma), saturation (distance from monochrome) and hue (dominant wavelength), supplemented by an alpha channel, as shown in Table 17. In this model, the hue is generated by interpolation between extremes on a color hexagon.

Table 17. Basic Data Format hexagonal HSVA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_HSVA_HEX_VALUE

V (value)

1

KHR_DF_CHANNEL_HSVA_HEX_SATURATION

S (saturation)

2

KHR_DF_CHANNEL_HSVA_HEX_HUE

H (hue)

15

KHR_DF_CHANNEL_HSVA_HEX_ALPHA

Alpha (opacity)

7.5.11. KHR_DF_MODEL_HSLA_HEX (= 10)

This color model represents color differences with three channels, lightness (maximum intensity), saturation (distance from monochrome) and hue (dominant wavelength), supplemented by an alpha channel, as shown in Table 18. In this model, the hue is generated by interpolation between extremes on a color hexagon.

Table 18. Basic Data Format hexagonal HSLA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS

L (lightness)

1

KHR_DF_CHANNEL_HSLA_HEX_SATURATION

S (saturation)

2

KHR_DF_CHANNEL_HSLA_HEX_HUE

H (hue)

15

KHR_DF_CHANNEL_HSLA_HEX_ALPHA

Alpha (opacity)

7.5.12. KHR_DF_MODEL_YCGCOA (= 11)

This color model represents low-cost approximate color differences with three channels, nominally luma (Y) and two color-difference chroma channels, Cg (green/purple color difference) and Co (orange/cyan color difference), supplemented by a channel for alpha, as shown in Table 19.

Table 19. Basic Data Format YCoCgA channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_YCGCOA_Y

Y

1

KHR_DF_CHANNEL_YCGCOA_CG

Cg

2

KHR_DF_CHANNEL_YCGCOA_CO

Co

15

KHR_DF_CHANNEL_YCGCOA_ALPHA

Alpha (opacity)

7.5.13. KHR_DF_MODEL_YCCBCCRC (= 12)

This color model represents the “Constant luminance” $Y'_CC'_\mathit{BC}C'_\mathit{RC}$ color model defined as an optional representation in ITU-T BT.2020 and described in Section 15.2.

Table 20. Basic Data Format Y′CC′BCC′RC channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_YCCBCCRC_YC

$Y'_C$ (luminance)

1

KHR_DF_CHANNEL_YCCBCCRC_CBC

$C'_\mathit{BC}$

2

KHR_DF_CHANNEL_YCCBCCRC_CRC

$C'_\mathit{RC}$

13

KHR_DF_CHANNEL_YCCBCCRC_STENCIL

Stencil

14

KHR_DF_CHANNEL_YCCBCCRC_DEPTH

Depth

15

KHR_DF_CHANNEL_YCCBCCRC_ALPHA

Alpha (opacity)

7.5.14. KHR_DF_MODEL_ICTCP (= 13)

This color model represents the “Constant intensity ICTCP color model” defined as an optional representation in ITU-T BT.2100 and described in Section 15.3.

Table 21. Basic Data Format ICTCP channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_ICTCP_I

I (intensity)

1

KHR_DF_CHANNEL_ICTCP_CT

CT

2

KHR_DF_CHANNEL_ICTCP_CP

CP

13

KHR_DF_CHANNEL_ICTCP_STENCIL

Stencil

14

KHR_DF_CHANNEL_ICTCP_DEPTH

Depth

15

KHR_DF_CHANNEL_ICTCP_ALPHA

Alpha (opacity)

7.5.15. KHR_DF_MODEL_CIEXYZ (= 14)

This color model represents channel data used to describe color coordinates in the CIE 1931 XYZ coordinate space, as shown in Table 22.

Table 22. Basic Data Format CIE XYZ channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_CIEXYZ_X

X

1

KHR_DF_CHANNEL_CIEXYZ_Y

Y

2

KHR_DF_CHANNEL_CIEXYZ_Z

Z

7.5.16. KHR_DF_MODEL_CIEXYY (= 15)

This color model represents channel data used to describe chromaticity coordinates in the CIE 1931 xyY coordinate space, as shown in Table 23.

Table 23. Basic Data Format CIE xyY channels

Channel number   Name   Description

0

KHR_DF_CHANNEL_CIEXYZ_X

x

1

KHR_DF_CHANNEL_CIEXYZ_YCHROMA

y

2

KHR_DF_CHANNEL_CIEXYZ_YLUMA

Y

7.6. colorModel for compressed formats

A number of compressed formats are supported as part of khr_df_model_e. In general, these formats will have the texel block dimensions of the compression block size. Most contain a single sample of channel type 0 at offset 0,0 — where further samples are required, they should also be sited at 0,0. By convention, models which have multiple channels that are disjoint in memory have these channel locations described accurately.

The ASTC family of formats have a number of possible channels, and are distinguished by samples which reference some set of these channels. The texelBlockDimension fields determine the compression ratio for ASTC.

Floating-point compressed formats have lower and upper limits specified in floating point format. Integer compressed formats with a lower and upper of 0 and UINT32_MAX (for unsigned formats) or INT32_MIN and INT32_MAX (for signed formats) are assumed to map the full representable range to 0..1 or -1..1 respectively.

7.6.1. KHR_DF_MODEL_DXT1A/KHR_DF_MODEL_BC1A (= 128)

This model represents the DXT1 or BC1 format. Channel 0 indicates color. If a second sample is present it should use channel 1 to indicate that the “special value” of the format should represent transparency — otherwise the “special value” represents opaque black.

7.6.2. KHR_DF_MODEL_DXT2/3/KHR_DF_MODEL_BC2 (= 129)

This model represents the DXT2/3 format, also described as BC2. The alpha premultiplication state (the distinction between DXT2 and DXT3) is recorded separately in the descriptor. This model has two channels: ID 0 contains the color information and ID 15 contains the alpha information. The alpha channel is 64 bits and at offset 0; the color channel is 64 bits and at offset 64. No attempt is made to describe the 16 alpha samples for this position independently, since understanding the other channels for any pixel requires the whole texel block.

7.6.3. KHR_DF_MODEL_DXT4/5/KHR_DF_MODEL_BC3 (= 130)

This model represents the DXT4/5 format, also described as BC3. The alpha premultiplication state (the distinction between DXT4 and DXT5) is recorded separately in the descriptor. This model has two channels: ID 0 contains the color information and ID 15 contains the alpha information. The alpha channel is 64 bits and at offset 0; the color channel is 64 bits and at offset 64.

7.6.4. KHR_DF_MODEL_BC4 (= 131)

This model represents the Direct3D BC4 format for single-channel interpolated 8-bit data. The model has a single channel of id 0 with offset 0 and length 64 bits.

7.6.5. KHR_DF_MODEL_BC5 (= 132)

This model represents the Direct3D BC5 format for dual-channel interpolated 8-bit data. The model has two channels, 0 (red) and 1 (green), which should have their bit depths and offsets independently described: the red channel has offset 0 and length 64 bits and the green channel has offset 64 and length 64 bits.

7.6.6. KHR_DF_MODEL_BC6H (= 133)

This model represents the Direct3D BC6H format for RGB floating-point data. The model has a single channel 0, representing all three channels, and occupying 128 bits.

7.6.7. KHR_DF_MODEL_BC7 (= 134)

This model represents the Direct3D BC7 format for RGBA data. This model has a single channel 0 of 128 bits.

7.6.8. KHR_DF_MODEL_ETC1 (= 160)

This model represents the original Ericsson Texture Compression format, with a guarantee that the format does not rely on ETC2 extensions. It contains a single channel of RGB data.

7.6.9. KHR_DF_MODEL_ETC2 (= 161)

This model represents the updated Ericsson Texture Compression format, ETC2, and also the related R11 EAC and RG11 EAC formats. Channel ID 0 represents red, and is used for the R11 EAC format. Channel ID 1 represents green, and both red and green should be present for the RG11 EAC format. Channel ID 2 represents RGB combined content, for ETC2. Channel 15 indicates the presence of alpha. If the texel block size is 8 bytes and the RGB and alpha channels are co-sited, “punch through” alpha is supported. If the texel block size is 16 bytes and the alpha channel appears in the first 8 bytes, followed by 8 bytes for the RGB channel, 8-bit separate alpha is supported.

7.6.10. KHR_DF_MODEL_ASTC (= 162)

This model represents Adaptive Scalable Texture Compression as a single channel in a texel block of 16 bytes. ASTC HDR (high dynamic range) and LDR (low dynamic range) modes are distinguished by the channelId containing the flag KHR_DF_SAMPLE_DATATYPE_FLOAT: an ASTC texture that is guaranteed by the user to contain only LDR-encoded blocks should have the channelId KHR_DF_SAMPLE_DATATYPE_FLOAT bit clear, and an ASTC texture that may include HDR-encoded blocks should have the channelId KHR_DF_SAMPLE_DATATYPE_FLOAT bit set to 1. ASTC supports a number of compression ratios defined by different texel block sizes; these are selected by changing the texel block size fields in the data format. The single sample has a size of 128 bits.

ASTC encoding is described in Section 23.

7.7. colorPrimaries

It is not sufficient to define a buffer as containing, for example, additive primaries. Additional information is required to define what “red” is provided by the “red” channel. A full definition of primaries requires an extension which provides the full color space of the data, but a subset of common primary spaces can be identified by the khr_df_primaries_e enumeration, represented as an unsigned 8-bit integer value.

7.7.1. KHR_DF_PRIMARIES_UNSPECIFIED (= 0)

This “set of primaries” identifies a data representation whose color representation is unknown or which does not fit into this list of common primaries. Having an “unspecified” value here precludes users of this data format from being able to perform automatic color conversion unless the primaries are defined in another way. Formats which require a proprietary color space — for example, raw data from a Bayer sensor that records the direct response of each filtered sample — can still indicate that samples represent “red”, “green” and “blue”, but should mark the primaries here as “unspecified” and provide a detailed description in an extension block.

7.7.2. KHR_DF_PRIMARIES_BT709 (= 1)

This value represents the Color Primaries defined by the ITU-R BT.709 specification and described in Section 14.1, which are also shared by sRGB.

RGB data is distinguished between BT.709 and sRGB by the Transfer Function. Conversion to and from BT.709 Y′CBCR (YUV) representation uses the color conversion matrix defined in the BT.709 specification, and described in Section 15.1.1, except in the case of sYCC (which can be distinguished by the use of the sRGB transfer function), in which case conversion to and from BT.709 Y′CBCR representation uses the color conversion matrix defined in the BT.601 specification, and described in Section 15.1.2. This is the preferred set of color primaries used by HDTV and sRGB, and likely a sensible default set of color primaries for common rendering operations.

KHR_DF_PRIMARIES_SRGB is provided as a synonym for KHR_DF_PRIMARIES_BT709.

7.7.3. KHR_DF_PRIMARIES_BT601_EBU (= 2)

This value represents the Color Primaries defined in the ITU-R BT.601 specification for standard-definition television, particularly for 625-line signals, and described in Section 14.2. Conversion to and from BT.601 Y′CBCR (YUV) typically uses the color conversion matrix defined in the BT.601 specification and described in Section 15.1.2.

7.7.4. KHR_DF_PRIMARIES_BT601_SMPTE (= 3)

This value represents the Color Primaries defined in the ITU-R BT.601 specification for standard-definition television, particularly for 525-line signals, and described in Section 14.3. Conversion to and from BT.601 Y′CBCR (YUV) typically uses the color conversion matrix defined in the BT.601 specification and described in Section 15.1.2.

7.7.5. KHR_DF_PRIMARIES_BT2020 (= 4)

This value represents the Color Primaries defined in the ITU-R BT.2020 specification for ultra-high-definition television and described in Section 14.4. Conversion to and from BT.2020 Y′CBCR (YUV uses the color conversion matrix defined in the BT.2020 specification and described in Section 15.1.3.

7.7.6. KHR_DF_PRIMARIES_CIEXYZ (= 5)

This value represents the theoretical Color Primaries defined by the International Color Consortium for the ICC XYZ linear color space.

7.7.7. KHR_DF_PRIMARIES_ACES (= 6)

This value represents the Color Primaries defined for the Academy Color Encoding System and described in Section 14.7.

7.7.8. KHR_DF_PRIMARIES_ACESCC (= 7)

This value represents the Color Primaries defined for the Academy Color Encoding System compositor and described in Section 14.8.

7.7.9. KHR_DF_PRIMARIES_NTSC1953 (= 8)

This value represents the Color Primaries defined for the NTSC 1953 color television transmission standard and described in Section 14.5.

7.7.10. KHR_DF_PRIMARIES_PAL525 (= 9)

This value represents the Color Primaries defined for 525-line PAL signals, described in Section 14.6.

7.7.11. KHR_DF_PRIMARIES_DISPLAYP3 (= 10)

This value represents the Color Primaries defined for the Display P3 color space, described in Section 14.9.

7.7.12. KHR_DF_PRIMARIES_ADOBERGB (= 11)

This value represents the Color Primaries defined in Adobe RGB (1998), described in Section 14.10.

7.8. transferFunction

Many color representations contain a non-linear transfer function which maps between a linear (intensity-based) representation and a more perceptually-uniform encoding. Common transfer functions are represented as an unsigned 8-bit integer and encoded in the enumeration khr_df_transfer_e. A fully-flexible transfer function requires an extension with a full color space definition. Where the transfer function can be described as a simple power curve, applying the function is commonly known as “gamma correction”. The transfer function is applied to a sample only when the sample’s KHR_DF_SAMPLE_DATATYPE_LINEAR bit is 0; if this bit is 1, the sample is represented linearly irrespective of the transferFunction.

When a color model contains more than one channel in a sample and the transfer function should be applied only to a subset of those channels, the convention of that model should be used when applying the transfer function. For example, ASTC stores both alpha and RGB data but is represented by a single sample; in ASTC, any sRGB transfer function is not applied to the alpha channel of the ASTC texture. In this case, the KHR_DF_SAMPLE_DATATYPE_LINEAR bit being zero means that the transfer function is “applied” to the ASTC sample in a way that only affects the RGB channels. This is not a concern for most color models, which explicitly store different channels in each sample.

If all the samples are linear, KHR_DF_TRANSFER_LINEAR should be used. In this case, no sample should have the KHR_DF_SAMPLE_DATATYPE_LINEAR bit set.

The enumerant value for each of the following transfer functions is shown in parentheses alongside the title.

7.8.1. KHR_DF_TRANSFER_UNSPECIFIED (= 0)

This value should be used when the transfer function is unknown, or specified only in an extension block, precluding conversion of color spaces and correct filtering of the data values using only the information in the basic descriptor block.

7.8.2. KHR_DF_TRANSFER_LINEAR (= 1)

This value represents a linear transfer function: for color data, there is a linear relationship between numerical pixel values and the intensity of additive colors. This transfer function allows for blending and filtering operations to be applied directly to the data values.

7.8.3. KHR_DF_TRANSFER_SRGB (= 2)

This value represents the non-linear transfer function defined in the sRGB specification for mapping between numerical pixel values and intensity. This is described in Section 13.3.

7.8.4. KHR_DF_TRANSFER_ITU (= 3)

This value represents the non-linear transfer function defined by the ITU and used in the BT.601, BT.709 and BT.2020 specifications. This is described in Section 13.2.

7.8.5. KHR_DF_TRANSFER_NTSC (= 4)

This value represents the non-linear transfer function defined by the original NTSC television broadcast specification. This is described in Section 13.8.

 More recent formulations of this transfer functions, such as that defined in SMPTE 170M-2004, use it ITU formulation described above.

7.8.6. KHR_DF_TRANSFER_SLOG (= 5)

This value represents a nonlinear Transfer Function used by some Sony video cameras to represent an increased dynamic range, and is described in Section 13.13.

7.8.7. KHR_DF_TRANSFER_SLOG2 (= 6)

This value represents a nonlinear Transfer Function used by some Sony video cameras to represent a further increased dynamic range, and is described in Section 13.14.

7.8.8. KHR_DF_TRANSFER_BT1886 (= 7)

This value represents the nonlinear OETF defined in BT.1886 and described in Section 13.4.

7.8.9. KHR_DF_TRANSFER_HLG_OETF (= 8)

This value represents the Hybrid Log Gamma OETF defined by the ITU in BT.2100 for high dynamic range television, and described in Section 13.5.

7.8.10. KHR_DF_TRANSFER_HLG_EOTF (= 9)

This value represents the Hybrid Log Gamma OETF defined by the ITU in BT.2100 for high dynamic range television, and described in Section 13.5.

7.8.11. KHR_DF_TRANSFER_PQ_EOTF (= 10)

This value represents the Perceptual Quantization EOTF defined by the ITU in BT.2100 for high dynamic range television, and described in Section 13.6.

7.8.12. KHR_DF_TRANSFER_PQ_OETF (= 11)

This value represents the Perceptual Quantization EOTF defined by the ITU in BT.2100 for high dynamic range television, and described in Section 13.6.

7.8.13. KHR_DF_TRANSFER_DCIP3 (= 12)

This value represents the transfer function defined in DCI P3 and described in Section 13.7.

7.8.14. KHR_DF_TRANSFER_PAL_OETF (= 13)

This value represents the OETF for legacy PAL systems described in Section 13.9.

7.8.15. KHR_DF_TRANSFER_PAL625_EOTF (= 14)

This value represents the EOTF for legacy 625-line PAL systems described in Section 13.10.

7.8.16. KHR_DF_TRANSFER_ST240 (= 15)

This value represents the transfer function associated with the legacy ST-240 (SMPTE240M) standard, described in Section 13.11.

7.8.17. KHR_DF_TRANSFER_ACESCC (= 16)

This value represents the nonlinear Transfer Function used in the ACEScc Academy Color Encoding System logarithmic encoding system for use within Color Grading Systems, S-2014-003, defined in [aces]. This is described in Section 13.15.

7.8.18. KHR_DF_TRANSFER_ACESCCT (= 17)

This value represents the nonlinear Transfer Function used in the ACEScc Academy Color Encoding System quasi-logarithmic encoding system for use within Color Grading Systems, S-2016-001, defined in [aces]. This is described in Section 13.16.

7.8.19. KHR_DF_TRANSFER_ADOBERGB (= 18)

This value represents the transfer function defined in the Adobe RGB (1998) specification and described in Section 13.12.

7.9. flags

The format supports some configuration options in the form of boolean flags; these are described in the enumeration khr_df_flags_e and represented in an unsigned 8-bit integer value.

7.9.1. KHR_DF_FLAG_ALPHA_PREMULTIPLIED (= 1)

If the KHR_DF_FLAG_ALPHA_PREMULTIPLIED bit is set, any color information in the data should be interpreted as having been previously scaled by the alpha channel when performing blending operations.

The value KHR_DF_FLAG_ALPHA_STRAIGHT (= 0) is provided to represent this flag not being set, which indicates that the color values in the data should be interpreted as needing to be scaled by the alpha channel when performing blending operations. This flag has no effect if there is no alpha channel in the format.

7.10. texelBlockDimension[0..3]

The texelBlockDimension fields define an integer bound on the range of coordinates covered by the repeating block described by the samples. Four separate values, represented as unsigned 8-bit integers, are supported, corresponding to successive dimensions. The Basic Data Format Descriptor Block supports up to four dimensions of encoding within a texel block, supporting, for example, a texture with three spatial dimensions and one temporal dimension. Nothing stops the data structure as a whole from having higher dimensionality: for example, a two-dimensional texel block can be used as an element in a six-dimensional look-up table.

The value held in each of these fields is one fewer than the size of the block in that dimension — that is, a value of 0 represents a size of 1, a value of 1 represents a size of 2, etc. A texel block which covers fewer than four dimensions should have a size of 1 in each dimension that it lacks, and therefore the corresponding fields in the representation should be 0.

For example, a Y′CBCR 4:2:0 representation may use a Texel Block of 2×2 pixels in the nominal coordinate space, corresponding to the four Y′ samples, as shown in Table 24. The texel block dimensions in this case would be 2×2×1×1 (in the X, Y, Z and T dimensions, if the fourth dimension is interpreted as T). The texelBlockDimension[0..3] values would therefore be:

Table 24. Example Basic Data Format texelBlockDimension values for Y′CBCR 4:2:0

 texelBlockDimension0 1 texelBlockDimension1 1 texelBlockDimension2 0 texelBlockDimension3 0

7.11. bytesPlane[0..7]

The Basic Data Format Descriptor divides the image into a number of planes, each consisting of an integer number of consecutive bytes. The requirement that planes consist of consecutive data means that formats with distinct subsampled channels — such as Y′CBCR 4:2:0 — may require multiple planes to describe a channel. A typical Y′CBCR 4:2:0 image has two planes for the Y′ channel in this representation, offset by one line vertically.

The use of byte granularity to define planes is a choice to allow large texels (of up to 255 bytes). A consequence of this is that formats which are not byte-aligned on each addressable unit, such as 1-bit-per-pixel formats, need to represent a texel block of multiple samples, covering multiple texels.

A maximum of eight independent planes is supported in the Basic Data Format Descriptor. Formats which require more than eight planes — which are rare — require an extension.

The bytesPlane[0..7] fields each contain an unsigned 8-bit integer which represents the number of bytes which that plane contributes to the format. The first field which contains the value 0 indicates that only a subset of the 8 possible planes are present; that is, planes which are not present should be given the bytesPlane value of 0, and any bytesPlane values after the first 0 are ignored. If no bytesPlane value is zero, 8 planes are considered to exist.

As an exception, if bytesPlane0 has the value 0, the first plane is considered to hold indices into a color palette, which is described by one or more additional planes and samples in the normal way. The first sample in this case should describe a 1×1×1×1 texel holding an unsigned integer value. The number of bits used by the index should be encoded in this sample, with a maximum value of the largest palette entry held in sampleUpper. Subsequent samples describe the entries in the palette, starting at an offset of bit 0. Note that the texel block in the index plane is not required to be byte-aligned in this case, and will not be for paletted formats which have small palettes. The channel type for the index is irrelevant.

For example, consider a 5-color paletted texture which describes each of these colors using 8 bits of red, green, blue and alpha. The color model would be RGBSDA, and the format would be described with two planes. bytesPlane0 would be 0, indicating the special case of a palette, and bytesPlane1 would be 4, representing the size of the palette entry. The first sample would then have a number of bits corresponding to the number of bits for the palette — in this case, three bits, corresponding to the requirements of a 5-color palette. The sampleUpper value for this sample is 4, indicating only 5 palette entries. Four subsequent samples represent the red, green, blue and alpha channels, starting from bit 0 as though the index value were not present, and describe the contents of the palette. The full data format descriptor for this example is provided in Table 33 as one of the example format descriptors.

7.12. Sample information

The layout and position of the information within each plane is determined by a number of samples, each consisting of a single channel of data and with a single corresponding position within the texel block, as shown in Table 25.

The bytes from the plane data contributing to the format are treated as though they have been concatenated into a bit stream, with the first byte of the lowest-numbered plane providing the lowest bits of the result. Each sample consists of a number of consecutive bits from this bit stream.

If the content for a channel cannot be represented in a single sample, for example because the data for a channel is non-consecutive within this bit stream, additional samples with the same coordinate position and channel number should follow from the first, in order increasing from the least significant bits from the channel data.

Note that some native big-endian formats may need to be supported with multiple samples in a channel, since the constituent bits may not be consecutive in a little-endian interpretation. There is an example, Table 35, in the list of format descriptors provided. In this case, the sampleLower and sampleUpper fields for the combined sample are taken from the first sample to belong uniquely to this channel/position pair.

By convention, to avoid aliases for formats, samples should be listed in order starting with channels at the lowest bits of this bit stream. Ties should be broken by increasing channel type id, as shown in Table 40.

The number of samples present in the format is determined by the descriptorBlockSize field. There is no limit on the number of samples which may be present, other than the maximum size of the Data Format Descriptor Block. There is no requirement that samples should access unique parts of the bit-stream: formats such as combined intensity and alpha, or shared exponent formats, require that bits be reused. Nor is there a requirement that all the bits in a plane be used (a format may contain padding).

Table 25. Basic Data Format Descriptor Sample Information

Byte 0 (LSB)   Byte 1   Byte 2   Byte 3 (MSB)

bitOffset

bitLength

channelType

samplePosition0

samplePosition1

samplePosition2

samplePosition3

sampleLower

sampleUpper

7.12.1. bitOffset

The bitOffset field describes the offset of the least significant bit of this sample from the least significant bit of the least significant byte of the concatenated bit stream for the format. Typically the bitOffset of the first sample is therefore 0; a sample which begins at an offset of one byte relative to the data format would have a bitOffset of 8. The bitOffset is an unsigned 16-bit integer quantity.

7.12.2. bitLength

The bitLength field describes the number of consecutive bits from the concatenated bit stream that contribute to the sample. This field is an unsigned 8-bit integer quantity, and stores the number of bits contributed minus 1; thus a single-byte channel should have a bitLength field value of 7. If a bitLength of more than 256 is required, further samples should be added; the value for the sample is composed in increasing order from least to most significant bit as subsequent samples are processed.

7.12.3. channelType

The channelType field is an unsigned 8-bit quantity.

The bottom four bits of the channelType indicates which channel is being described by this sample. The list of available channels is determined by the colorModel field of the Basic Data Format Descriptor Block, and the channelType field contains the number of the required channel within this list — see the colorModel field for the list of channels for each model.

The top four bits of the channelType are described by the khr_df_sample_datatype_qualifiers_e enumeration:

If the KHR_DF_SAMPLE_DATATYPE_LINEAR bit is not set, the sample value is modified by the transfer function defined in the format’s transferFunction field; if this bit is set, the sample is considered to contain a linearly-encoded value irrespective of the format’s transferFunction.

If the KHR_DF_SAMPLE_DATATYPE_EXPONENT bit is set, this sample holds an exponent (in integer form) for this channel. For example, this would be used to describe the shared exponent location in shared exponent formats (with the exponent bits listed separately under each channel). An exponent is applied to any integer sample of the same type. If this bit is not set, the sample is considered to contain mantissa information. If the KHR_DF_SAMPLE_DATATYPE_SIGNED bit is also set, the exponent is considered to be two’s complement — otherwise it is treated as unsigned. The bias of the exponent can be determined by the exponent’s sampleLower value. The presence or absence of an implicit leading digit in the mantissa of a format with an exponent can be determined by the sampleUpper value of the mantissa.

If the KHR_DF_SAMPLE_DATATYPE_SIGNED bit is set, the sample holds a signed value in two’s complement form. If this bit is not set, the sample holds an unsigned value. It is possible to represent a sign/magnitude integer value by having a sample of unsigned integer type with the same channel and sample location as a 1-bit signed sample.

If the KHR_DF_SAMPLE_DATATYPE_FLOAT bit is set, the sample holds floating point data in a conventional format of 10, 11 or 16 bits, as described in Section 10, or of 32, or 64 bits as described in [IEEE 754]. Unless a genuine unsigned format is intended, KHR_DF_SAMPLE_DATATYPE_SIGNED should be set. Less common floating point representations can be generated with multiple samples and a combination of signed integer, unsigned integer and exponent fields, as described above and in Section 10.4.

7.12.4. samplePosition[0..3]

The sample has an associated location within the 4-dimensional space of the texel block. Each sample has an offset relative to the 0,0 position of the texel block, determined in units of half a coordinate. This allows the common situation of downsampled channels to have samples conceptually sited at the midpoint between full resolution samples. Support for offsets other than multiples of a half coordinates require an extension. The direction of the sample offsets is determined by the coordinate addressing scheme used by the API. There is no limit on the dimensionality of the data, but if more than four dimensions need to be contained within a single texel block, an extension will be required.

Each samplePosition is an 8-bit unsigned integer quantity. samplePosition0 is the X offset of the sample, samplePosition1 is the Y offset of the sample, etc. Formats which use an offset larger than 127.5 in any dimension require an extension.

It is legal, but unusual, to use the same bits to represent multiple samples at different coordinate locations.

7.12.5. sampleLower

sampleLower, combined with sampleUpper, is used to represent the mapping between the numerical value stored in the format and the conceptual numerical interpretation. For unsigned formats, sampleLower typically represents the value which should be interpreted as zero (the black point). For signed formats, sampleLower typically represents “-1”. For color difference models such as Y′CBCR, sampleLower represents the lower extent of the color difference range (which corresponds to an encoding of -0.5 in numerical terms).

If the channel encoding is an integer format, the sampleLower value is represented as a 32-bit integer — signed or unsigned according to whether the channel encoding is signed. Signed negative values should be sign-extended if the channel has fewer than 32 bits, such that the value encoded in sampleLower is itself negative. If the channel encoding is a floating point value, the sampleLower value is also floating point. If the number of bits in the sample is greater than 32, the lowest representable value for sampleLower is interpreted as the smallest value representable in the channel format.

If the channel consists of multiple co-sited integer samples, for example because the channel bits are non-contiguous, there are two possible behaviors. If the total number of bits in the channel is less than or equal to 32, the sampleLower values in the samples corresponding to the least-significant bits of the sample are ignored, and only the sampleLower from the most-significant sample is considered. If the number of bits in the channel exceeds 32, the sampleLower values from the sample corresponding to the most-significant bits within any 32-bit subset of the total number are concatenated to generate the final sampleLower value. For example, a 48-bit signed integer may be encoded in three 16-bit samples. The first sample, corresponding to the least-significant 16 bits, will have its sampleLower value ignored. The next sample of 16 bits takes the total to 32, and so the sampleLower value of this sample should represent the lowest 32 bits of the desired 48-bit virtual sampleLower value. Finally, the third sample indicates the top 16 bits of the 48-bit channel, and its sampleLower contains the top 16 bits of the 48-bit virtual sampleLower value.

The sampleLower value for an exponent should represent the exponent bias — the value that should be subtracted from the encoded exponent to indicate that the mantissa’s sampleUpper value will represent 1.0. See Section 10.4 for more detail on this.

For example, the BT.709 television broadcast standard dictates that the Y′ value stored in an 8-bit encoding should fall between the range 16 and 235. In this case, sampleLower should contain the value 16.

In OpenGL terminology, a “normalized” channel contains an integer value which is mapped to the range 0..1.0. A channel which is not normalized contains an integer value which is mapped to a floating point equivalent of the integer value. Similarly an “snorm” channel is a signed normalized value mapping from -1.0 to 1.0. Setting sampleLower to the minimum signed integer value representable in the channel is equivalent to defining an “snorm” texture.

7.12.6. sampleUpper

sampleUpper, combined with sampleLower, is used to represent the mapping between the numerical value stored in the format and the conceptual numerical interpretation. sampleUpper typically represents the value which should be interpreted as “1.0” (the “white point”). For color difference models such as Y′CBCR, sampleUpper represents the upper extent of the color difference range (which corresponds to an encoding of 0.5 in numerical terms).

If the channel encoding is an integer format, the sampleUpper value is represented as a 32-bit integer — signed or unsigned according to whether the channel encoding is signed. If the channel encoding is a floating point value, the sampleUpper value is also floating point. If the number of bits in the sample is greater than 32, the highest representable value for sampleUpper is interpreted as the largest value representable in the channel format. If the channel encoding is the mantissa of a custom floating point format (that is, the encoding is integer but the same sample location and channel is shared by a sample that encodes an exponent), the presence of an implicit “1” digit can be represented by setting the sampleUpper value to a value one larger than can be encoded in the available bits for the mantissa, as described in Section 10.4.

The sampleUpper value for an exponent should represent the largest conventional legal exponent value. If the encoded exponent exceeds this value, the encoded floating point value encodes either an infinity or a NaN value, depending on the mantissa. See Section 10.4 for more detail on this.

If the channel consists of multiple co-sited integer samples, for example because the channel bits are non-contiguous, there are two possible behaviors. If the total number of bits in the channel is less than or equal to 32, the sampleUpper values in the samples corresponding to the least-significant bits of the sample are ignored, and only the sampleUpper from the most-significant sample is considered. If the number of bits in the channel exceeds 32, the sampleUpper values from the sample corresponding to the most-significant bits within any 32-bit subset of the total number are concatenated to generate the final sampleUpper value. For example, a 48-bit signed integer may be encoded in three 16-bit samples. The first sample, corresponding to the least-significant 16 bits, will have its sampleUpper value ignored. The next sample of 16 bits takes the total to 32, and so the sampleUpper value of this sample should represent the lowest 32 bits of the desired 48-bit virtual sampleUpper value. Finally, the third sample indicates the top 16 bits of the 48-bit channel, and its sampleUpper contains the top 16 bits of the 48-bit virtual sampleUpper value.

For example, the BT.709 television broadcast standard dictates that the Y′ value stored in an 8-bit encoding should fall between the range 16 and 235. In this case, sampleUpper should contain the value 235.

In OpenGL terminology, a “normalized” channel contains an integer value which is mapped to the range 0..1.0. A channel which is not normalized contains an integer value which is mapped to a floating point equivalent of the integer value. Similarly an “snorm” channel is a signed normalized value mapping from -1.0 to 1.0. Setting sampleUpper to the maximum signed integer value representable in the channel for a signed channel type is equivalent to defining an “snorm” texture. Setting sampleUpper to the maximum unsigned value representable in the channel for an unsigned channel type is equivalent to defining a “normalized” texture. Setting sampleUpper to “1” is equivalent to defining an “unnormalized” texture.

Sensor data from a camera typically does not cover the full range of the bit depth used to represent it. sampleUpper can be used to specify an upper limit on sensor brightness — or to specify the value which should map to white on the display, which may be less than the full dynamic range of the captured image.

There is no guarantee or expectation that image data be guaranteed to fall between sampleLower and sampleUpper unless the users of a format agree that convention.

8. Extension for more complex formats

Some formats will require more channels than can be described in the Basic Format Descriptor, or may have more specific color requirements. For example, it is expected than an extension will be available which places an ICC color profile block into the descriptor block, allowing more color channels to be specified in more precise ways. This will significantly enlarge the space required for the descriptor, and is not expected to be needed for most common uses. A vendor may also use an extension block to associate metadata with the descriptor — for example, information required as part of hardware rendering. So long as software which uses the data format descriptor always uses the totalSize field to determine the size of the descriptor, this should be transparent to user code.

The extension mechanism is the preferred way to support even simple extensions such as additional color spaces transfer functions that can be supported by an additional enumeration. This approach improves compatibility with code which is unaware of the additional values. Simple extensions of this form that have cross-vendor support have a good chance of being incorporated more directly into future revisions of the specification, allowing application code to distinguish them by the versionId field.

As an example, consider a single-channel 32-bit depth buffer, as shown in Table 26. A tiled renderer may wish to indicate that this buffer is “virtual”: it will be allocated real memory only if needed, and will otherwise exist only a subset at a time in an on-chip representation. Someone developing such a renderer may choose to add a vendor-specific extension (with ID 0xFFFF to indicate development work and avoid the need for a vendor ID) which uses a boolean to establish whether this depth buffer exists only in virtual form. Note that the mere presence or absence of this extension within the data format descriptor itself forms a boolean, but for this example we will assume that an extension block is always present, and that a boolean is stored within. We will give the enumeration 32 bits, in order to simplify the possible addition of further extensions.

In this example (which should not be taken as an implementation suggestion), the data descriptor would first contain a descriptor block describing the depth buffer format as conventionally described, followed by a second descriptor block that contains only the enumeration. The descriptor itself has a totalSize that includes both of these descriptor blocks.

Table 26. Example of a depth buffer with an extension to indicate a virtual allocation

56 (totalSize: total size of the two blocks plus one 32-bit value)

 Basic descriptor block 0 (vendorId) 0 (descriptorType) 1 (versionNumber) 40 (descriptorBlockSize) RGBSDA (colorModel) UNSPECIFIED   (colorPrimaries) UNSPECIFIED   (transferFunction) 0 (flags) 0   (texelBlockDimension0) 0   (texelBlockDimension1) 0   (texelBlockDimension2) 0   (texelBlockDimension3) 4 (bytesPlane0) 0 (bytesPlane1) 0 (bytesPlane2) 0 (bytesPlane3) 0 (bytesPlane4) 0 (bytesPlane5) 0 (bytesPlane6) 0 (bytesPlane7) Sample information for the depth value 0 (bitOffset) 31 (= “32”) (bitLength) SIGNED | FLOAT |   DEPTH 0 (samplePosition0) 0 (samplePosition1) 0 (samplePosition2) 0 (samplePosition3) 0xbf800000 (sampleLower: -1.0f) 0x3f800000U (sampleUpper: 1.0f) Extension descriptor block 0xFFFF (vendorId) 0 (descriptorType) 0 (versionNumber) 12 (descriptorBlockSize) Data specific to the extension follows 1 (buffer is “virtual”)

It is possible for a vendor to use the extension block to store peripheral information required to access the image — plane base addresses, stride, etc. Since different implementations have different kinds of non-linear ordering and proprietary alignment requirements, this is not described as part of the standard. By many conventional definitions, this information is not part of the “format”, and particularly it ensures that an identical copy of the image will have a different descriptor block (because the addresses will have changed) and so a simple bitwise comparison of two descriptor blocks will disagree even though the “format” matches. Additionally, many APIs will use the format descriptor only for external communication, and have an internal representation that is more concise and less flexible. In this case, it is likely that address information will need to be represented separately from the format anyway. For these reasons, it is an implementation choice whether to store this information in an extension block, and how to do so, rather than being specified in this standard..

9.1. Why have a binary format rather than a human-readable one?

While it is not expected that every new container will have a unique data descriptor or that analysis of the data format descriptor will be on a critical path in an application, it is still expected that comparison between formats may be time-sensitive. The data format descriptor is designed to allow relatively efficient queries for subsets of properties, to allow a large number of format descriptors to be stored, and to be amenable to hardware interpretation or processing in shaders. These goals preclude a text-based representation such as an XML schema.

9.2. Why not use an existing representation such as those on FourCC.org?

Formats in FourCC.org do not describe in detail sufficient information for many APIs, and are sometimes inconsistent.

9.3. Why have a descriptive format?

Enumerations are fast and easy to process, but are limited in that any software can only be aware of the enumeration values in place when it was defined. Software often behaves differently according to properties of a format, and must perform a look-up on the enumeration — if it knows what it is — in order to change behaviors. A descriptive format allows for more flexible software which can support a wide range of formats without needing each to be listed, and simplifies the programming of conditional behavior based on format properties.

9.4. Why describe this standard within Khronos?

Khronos supports multiple standards that have a range of internal data representations. There is no requirement that this standard be used specifically with other Khronos standards, but it is hoped that multiple Khronos standards may use this specification as part of a consistent approach to inter-standard operation.

9.5. Why should I use this format if I don’t need most of the fields?

While a library may not use all the data provided in the data format descriptor that is described within this standard, it is common for users of data — particularly pixel-like data — to have additional requirements. Capturing these requirements portably reduces the need for additional metadata to be associated with a proprietary descriptor. It is also common for additional functionality to be added retrospectively to existing libraries — for example, Y′CBCR support is often an afterthought in rendering APIs. Having a consistent and flexible representation in place from the start can reduce the pain of retrofitting this functionality.

Note that there is no expectation that the format descriptor from this standard be used directly, although it can be. The impact of providing a mapping between internal formats and format descriptors is expected to be low, but offers the opportunity both for simplified access from software outside the proprietary library and for reducing the effort needed to provide a complete, unambiguous and accurate description of a format in human-readable terms.

9.6. Why not expand each field out to be integer for ease of decoding?

There is a trade-off between size and decoding effort. It is assumed that data which occupies the same 32-bit word may need to be tested concurrently, reducing the cost of comparisons. When transferring data formats, the packing reduces the overhead. Within these constraints, it is intended that most data can be extracted with low-cost operations, typically being byte-aligned (other than sample flags) and with the natural alignment applied to multi-byte quantities.

9.7. Can this descriptor be used for text content?

For simple ASCII content, there is no reason that plain text could not be described in some way, and this may be useful for image formats that contain comment sections. However, since many multilingual text representations do not have a fixed character size, this use is not seen as an obvious match for this standard.

10. Floating-point formats

Some common floating-point numeric representations are defined in [IEEE 754]. Additional floating point formats are defined in this section.

10.1. 16-bit floating-point numbers

A 16-bit floating-point number has a 1-bit sign (S), a 5-bit exponent (E), and a 10-bit mantissa (M). The value V of a 16-bit floating-point number is determined by the following:

$V = \begin{cases} (-1)^S \times 0.0, & E = 0, M = 0 \\ (-1)^S \times 2^{-14} \times { M \over 2^{10} }, & E = 0, M \neq 0 \\ (-1)^S \times 2^{E-15} \times { \left( 1 + { M \over 2^{10} } \right) }, & 0 < E < 31 \\ (-1)^S \times \mathit{Inf}, & E = 31, M = 0 \\ \mathit{NaN}, & E = 31, M \neq 0 \end{cases}$

If the floating-point number is interpreted as an unsigned 16-bit integer N, then

$$S = \left\lfloor { { N \bmod 65536 } \over 32768 } \right\rfloor$$ $$E = \left\lfloor { { N \bmod 32768 } \over 1024 } \right\rfloor$$ $$M = N \bmod 1024.$$

10.2. Unsigned 11-bit floating-point numbers

An unsigned 11-bit floating-point number has no sign bit, a 5-bit exponent (E), and a 6-bit mantissa (M). The value V of an unsigned 11-bit floating-point number is determined by the following:

$V = \begin{cases} 0.0, & E = 0, M = 0 \\ 2^{-14} \times { M \over 64 }, & E = 0, M \neq 0 \\ 2^{E-15} \times { \left( 1 + { M \over 64 } \right) }, & 0 < E < 31 \\ \mathit{Inf}, & E = 31, M = 0 \\ \mathit{NaN}, & E = 31, M \neq 0 \end{cases}$

If the floating-point number is interpreted as an unsigned 11-bit integer N, then

$$E = \left\lfloor { N \over 64 } \right\rfloor$$ $$M = N \bmod 64.$$

10.3. Unsigned 10-bit floating-point numbers

An unsigned 10-bit floating-point number has no sign bit, a 5-bit exponent (E), and a 5-bit mantissa (M). The value V of an unsigned 10-bit floating-point number is determined by the following:

$V = \begin{cases} 0.0, & E = 0, M = 0 \\ 2^{-14} \times { M \over 32 }, & E = 0, M \neq 0 \\ 2^{E-15} \times { \left( 1 + { M \over 32 } \right) }, & 0 < E < 31 \\ \mathit{Inf}, & E = 31, M = 0 \\ \mathit{NaN}, & E = 31, M \neq 0 \end{cases}$

If the floating-point number is interpreted as an unsigned 10-bit integer N, then

$$E = \left\lfloor { N \over 32 } \right\rfloor$$ $$M = N \bmod 32.$$

10.4. Non-standard floating point formats

Rather than attempting to enumerate every possible floating-point format variation in this specification, the data format descriptor can be used to describe the components of arbitrary floating-point data, as follows. Note that non-standard floating point formats do not use the KHR_DF_SAMPLE_DATATYPE_FLOAT bit.

An example of use of the 16-bit floating point format described in Section 10.1 but described in terms of a custom floating point format is provided in Table 42. Note that this is provided for example only, and this particular format would be better described using the standard 16-bit floating point format as documented in Table 43.

10.4.1. The mantissa

The mantissa of a custom floating point format should be represented as an integer channelType. If the mantissa represents a signed quantity encoded in two’s complement, the KHR_DF_SAMPLE_DATATYPE_SIGNED bit should be set. To encode a signed mantissa represented in sign-magnitude format, the main part of the mantissa should be represented as an unsigned integer quantity (with KHR_DF_SAMPLE_DATATYPE_SIGNED not set), and an additional one-bit sample with KHR_DF_SAMPLE_DATATYPE_SIGNED set should be used to identify the sign bit. By convention, a sign bit should be encoded in a later sample than the corresponding mantissa.

The sampleUpper and sampleLower values for the mantissa should be set to indicate the representation of 1.0 and 0.0 (for unsigned formats) or -1.0 (for signed formats) respectively when the exponent is in a 0 position after any bias has been corrected. If there is an implicit “1” bit, these values for the mantissa will exceed what can be represented in the number of available mantissa bits.

For example, the shared exponent formats shown in Table 36 does not have an implicit “1” bit, and therefore the sampleUpper values for the 9-bit mantissas are 256 — this being the mantissa value for 1.0 when the exponent is set to 0.

For the 16-bit signed floating point format described in Section 10.1, sampleUpper should be set to 1024, indicating the implicit “1” bit which is above the 10 bits representable in the mantissa. sampleLower should be 0 in this case, since the mantissa uses a sign-magnitude representation.

By convention, the sampleUpper and sampleLower values for a sign bit are 0 and -1 respectively.

10.5. The exponent

The KHR_DF_SAMPLE_DATATYPE_EXPONENT bit should be set in a sample which contains the exponent of a custom floating point format.

The sampleLower for the exponent should indicate the exponent bias. That is, the mantissa should be scaled by two raised to the power of the stored exponent minus this sampleLower value.

The sampleUpper for the exponent indicates the maximum legal exponent value. Values above this are used to encode infinities and not-a-number (NaN) values. sampleUpper can therefore be used to indicate whether or not the format supports these encodings.

10.6. Special values

Floating point values encoded with an exponent of 0 (before bias) and a mantissa of 0 are used to represent the value 0. An explicit sign bit can distinguish between +0 and -0.

Floating point values encoded with an exponent of 0 (before bias) and a non-zero mantissa are assumed to indicate a denormalized number, if the format has an implicit “1” bit. That is, when the exponent is 0, the “1” bit becomes explicit and the exponent is considered to be the negative sample bias minus one.

Floating point values encoded with an exponent larger than the exponent’s sampleUpper value and with a mantissa of 0 are interpreted as representing +/- infinity, depending on the value of an explicit sign bit. Note that in some formats, no exponent above sampleUpper is possible — for example, Table 36.

Floating point values encoded with an exponent larger than the exponent’s sampleUpper value and with a mantissa of non-0 are interpreted as representing not-a-number (NaN).

Note that these interpretations are compatible with the corresponding numerical representations in [IEEE 754].

10.7. Conversion formulae

Given an optional sign bit S, a mantissa value of M and an exponent value of E, a format with an implicit “1” bit can be converted from its representation to a real value as follows:

$V = \begin{cases} (-1)^S \times 0.0, & E = 0, M = 0 \\ (-1)^S \times 2^{-(E_\mathit{sampleLower}-1)} \times { M \over M_\mathit{sampleUpper} }, & E = 0, M \neq 0 \\ (-1)^S \times 2^{E-E_\mathit{sampleLower}} \times { \left( 1 + { M \over M_\mathit{sampleUpper} } \right) }, & 0 < E \leq E_\mathit{sampleUpper} \\ (-1)^S \times \mathit{Inf}, & E > E_\mathit{sampleUpper}, M = 0 \\ \mathit{NaN}, & E > E_\mathit{sampleUpper}, M \neq 0. \end{cases}$

If there is no implicit “1” bit (that is, the sampleUpper value of the mantissa is representable in the number of bits assigned to the mantissa), the value can be converted to a real value as follows:

$V = \begin{cases} (-1)^S \times 2^{E-E_{\mathit{sampleUower}}} \times { \left( { M \over M_\mathit{sampleUpper} } \right) }, & 0 < E \leq E_\mathit{sampleUpper} \\ (-1)^S \times \mathit{Inf}, & E > E_\mathit{sampleUpper}, M = 0 \\ \mathit{NaN}, & E > E_\mathit{sampleUpper}, M \neq 0. \end{cases}$

A descriptor block for a format without an implicit “1” (and with the added complication of having the same exponent bits shared across multiple channels, which is why an implicit “1” bit does not make sense) is shown in Table 36. In the case of this particular example, the above equations simplify to:

$$red = \mathit{red}_\mathrm{shared}\times 2^{(\mathit{exp}_\mathrm{shared}-B-N)}$$ $$green = \mathit{green}_\mathrm{shared}\times 2^{(\mathit{exp}_\mathrm{shared}-B-N)}$$ $$blue = \mathit{blue}_\mathrm{shared}\times 2^{(\mathit{exp}_\mathrm{shared}-B-N)}$$

Where:

$$N = 9 \textrm{ (= number of mantissa bits per component)}$$ $$B = 15 \textrm{ (= exponent bias)}$$

Note that in general conversion from a real number to any representation may require rounding, truncation and special value management rules which are beyond the scope of a data format specification and may be documented in APIs which generate these formats.

11. Example format descriptors

Table 27. Four co-sited 8-bit sRGB channels, assuming premultiplied alpha

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

92 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

88 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

SRGB (transferFunction)

PREMULTIPLIED (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

4 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample

0 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the second sample

8 (bitOffset)

7 (= “8”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the third sample

16 (bitOffset)

7 (= “8”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the fourth sample

24 (bitOffset)

7 (= “8”) (bitLength)

31 (channelType)

(ALPHA | LINEAR)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Table 28. 565 RGB packed 16-bit format as written to memory by a little-endian architecture

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

76 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

72 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

2 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample: 5 bits of blue

0 (bitOffset)

4 (= “5”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

31 (sampleUpper)

Sample information for the second sample: 6 bits of green

5 (bitOffset)

5 (= “6”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

63 (sampleUpper)

Sample information for the third sample: 5 bits of red

11 (bitOffset)

4 (= “5”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

31 (sampleUpper)

Table 29. A single 8-bit monochrome channel

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

44 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

40 (descriptorBlockSize)

YUVSDA (colorModel)

BT709 (colorPrimaries)

ITU (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

4 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample

0 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (Y)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Table 30. A single 1-bit monochrome channel, as an 8×1 texel block to allow byte-alignment, part 1 of 2

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

156 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

152 (descriptorBlockSize)

YUVSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

7 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

1 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample

0 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Sample information for the second sample

1 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

2 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Sample information for the third sample

2 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

4 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Table 31. A single 1-bit monochrome channel, as an 8×1 texel block to allow byte-alignment, part 2 of 2

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

Sample information for the fourth sample

3 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

6 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Sample information for the fifth sample

4 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

8 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Sample information for the sixth sample

5 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

10 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Sample information for the seventh sample

6 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

12 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Sample information for the eighth sample

7 (bitOffset)

0 (= “1”) (bitLength)

0 (channelType) (Y)

14 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1 (sampleUpper)

Table 32. 2×2 Bayer pattern: four 8-bit distributed sRGB channels, spread across two lines (as two planes)

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

92 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

88 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

SRGB (transferFunction)

ALPHA_STRAIGHT (flags)

1 (texelBlockDimension0)

1 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

2 (bytesPlane0)

2 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample

0 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the second sample

8 (bitOffset)

7 (= “8”) (bitLength)

1 (channelType) (GREEN)

2 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the third sample

16 (bitOffset)

7 (= “8”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

2 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the fourth sample

24 (bitOffset)

7 (= “8”) (bitLength)

2 (channelType) (BLUE)

2 (samplePosition0)

2 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Table 33. Four co-sited 8-bit channels in the sRGB color space described by an 5-entry, 3-bit palette

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

108 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

104 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

SRGB (transferFunction)

PREMULTIPLIED (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

0 (bytesPlane0)

4 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the palette index

0 (bitOffset)

2 (= “3”) (bitLength)

0 (channelType) (irrelevant)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

4 (sampleUpper) — this specifies that there are 5 palette entries

Sample information for the first sample

0 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the second sample

8 (bitOffset)

7 (= “8”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the third sample

16 (bitOffset)

7 (= “8”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the fourth sample

24 (bitOffset)

7 (= “8”) (bitLength)

31 (channelType)

(ALPHA | LINEAR)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Table 34. Y′CBCR 4:2:0: BT.709 reduced-range data, with CB and CR aligned to the midpoint of the Y samples

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

124 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

120 (descriptorBlockSize)

YUVSDA (colorModel)

BT709 (colorPrimaries)

ITU (transferFunction)

ALPHA_STRAIGHT (flags)

1 (texelBlockDimension0)

1 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

2 (bytesPlane0)

2 (bytesPlane1)

1 (bytesPlane2)

1 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first Y sample

0 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (Y)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

16 (sampleLower)

235 (sampleUpper)

Sample information for the second Y sample

8 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (Y)

2 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

16 (sampleLower)

235 (sampleUpper)

Sample information for the third Y sample

16 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (Y)

0 (samplePosition0)

2 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

16 (sampleLower)

235 (sampleUpper)

Sample information for the fourth Y sample

24 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (Y)

2 (samplePosition0)

2 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

16 (sampleLower)

235 (sampleUpper)

Sample information for the U sample

32 (bitOffset)

7 (= “8”) (bitLength)

1 (channelType) (U)

1 (samplePosition0)

1 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

16 (sampleLower)

240 (sampleUpper)

Sample information for the V sample

36 (bitOffset)

7 (= “8”) (bitLength)

2 (channelType) (V)

1 (samplePosition0)

1 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

16 (sampleLower)

240 (sampleUpper)

Table 35. 565 RGB packed 16-bit format as written to memory by a big-endian architecture

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

92 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

88 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

SRGB (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

2 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample: bit 0 belongs to green, bits 0..2 of channel in 13..15

13 (bitOffset)

2 (= “3”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

63 (sampleUpper)

Sample information for the second sample: bits 3..5 of green in 0..2

0 (bitOffset)

2 (= “3”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower) — ignored, taken from first sample

0 (sampleUpper) — ignored, taken from first sample

Sample information for the third sample

3 (bitOffset)

4 (= “5”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

31 (sampleUpper)

Sample information for the fourth sample

8 (bitOffset)

4 (= “5”) (bitLength)

1 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

31 (sampleUpper)

Table 36. R9G9B9E5 shared-exponent format

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

124 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

120 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

4 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the R mantissa

0 (bitOffset)

8 (= “9”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

256 (sampleUpper) — mantissa at 1.0

Sample information for the R exponent

27 (bitOffset)

4 (= “5”) (bitLength)

32 (channelType)

(RED | EXPONENT)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

15 (sampleUpper) — exponent bias

Sample information for the G mantissa

9 (bitOffset)

8 (= “9”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

256 (sampleUpper) — mantissa at 1.0

Sample information for the G exponent

27 (bitOffset)

4 (= “5”) (bitLength)

33 (channelType)

(GREEN | EXPONENT)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

15 (sampleUpper) — exponent bias

Sample information for the B mantissa

18 (bitOffset)

8 (= “9”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

256 (sampleUpper) — mantissa at 1.0

Sample information for the B exponent

27 (bitOffset)

4 (= “5”) (bitLength)

34 (channelType)

(BLUE | EXPONENT)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

15 (sampleUpper) — exponent bias

Table 37. Acorn 256-color format (2 bits each independent RGB, 2 bits shared “tint”)

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

108 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

120 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

1 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the R value and tint (shared low bits)

0 (bitOffset)

3 (= “4”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

15 (sampleUpper) — unique R upper value

Sample information for the G tint (shared low bits)

0 (bitOffset)

1 (= “2”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

0 (sampleUpper) — ignored, not unique

Sample information for the G unique (high) bits

4 (bitOffset)

1 (= “2”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

15 (sampleUpper) — unique G upper value

Sample information for the B tint (shared low bits)

0 (bitOffset)

1 (= “2”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

0 (sampleUpper) — ignored, not unique

Sample information for the B unique (high) bits

6 (bitOffset)

1 (= “2”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

15 (sampleUpper) — unique B upper value

Table 38. V210 format (full-range Y′CBCR) part 1 of 2

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

220 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

216 (descriptorBlockSize) — 12 samples

YUVSDA (colorModel)

BT709 (colorPrimaries)

ITU (transferFunction)

ALPHA_STRAIGHT (flags)

5 (dimension0)

0 (dimension1)

0 (dimension2)

0 (dimension3)

16 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the shared U0/U1 value

0 (bitOffset)

9 (= “10”) (bitLength)

1 (channelType) (U)

1 (assume mid-sited)

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the Y′0 value

10 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (Y)

0

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the shared V0/V1 value

20 (bitOffset)

9 (= “10”) (bitLength)

2 (channelType) (V)

1 (assume mid-sited)

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the Y′1 value

32 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (Y)

2

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the shared U2/U3 value

42 (bitOffset)

9 (= “10”) (bitLength)

1 (channelType) (U)

5 (assume mid-sited)

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the Y′2 value

52 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (Y)

4

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Table 39. V210 format (full-range Y′CBCR) part 2 of 2

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

Sample information for the shared V2/V3 value

64 (bitOffset)

9 (= “10”) (bitLength)

2 (channelType) (V)

5 (assume mid-sited)

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the Y′3 value

74 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (Y)

6

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the shared U4/U5 value

84 (bitOffset)

9 (= “10”) (bitLength)

1 (channelType) (U)

9 (assume mid-sited)

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the Y′4 value

96 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (Y)

8

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the shared V4/V5 value

106 (bitOffset)

9 (= “10”) (bitLength)

2 (channelType) (V)

9 (assume mid-sited)

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Sample information for the Y′4 value

116 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (Y)

10

0

0

0

0 (sampleLower)

1023 (sampleUpper)

Table 40. Intensity-alpha format showing aliased samples

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

92 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

88 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

PREMULTIPLIED (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

1 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample

0 (bitOffset)

7 (= “8”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the second sample

0 (bitOffset)

7 (= “8”) (bitLength)

1 (channelType) (GREEN)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the third sample

0 (bitOffset)

7 (= “8”) (bitLength)

2 (channelType) (BLUE)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Sample information for the fourth sample

0 (bitOffset)

7 (= “8”) (bitLength)

31 (channelType)

(ALPHA | LINEAR)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

255 (sampleUpper)

Table 41. A 48-bit signed middle-endian red channel: three co-sited 16-bit little-endian words, high word first

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

76 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

72 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

6 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample

32 (bitOffset)

15 (= “16”) (bitLength)

64 (channelType)

(RED | SIGNED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower) — ignored, overridden by second sample

0 (sampleUpper) — ignored, overridden by second sample

Sample information for the second sample

16 (bitOffset)

15 (= “16”) (bitLength)

64 (channelType)

(RED | SIGNED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0x00000000 (sampleLower) — bottom 32 bits of sampleLower

0xFFFFFFFF (sampleUpper) — bottom 32 bits of sampleUpper

Sample information for the third sample

0 (bitOffset)

15 (= “16”) (bitLength)

64 (channelType)

(RED | SIGNED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0xFFFF8000 (sampleLower) — top 16 bits of sampleLower, sign-extended

0x7FFF (sampleUpper) — top 16 bits of sampleUpper

Table 42. A single 16-bit floating-point red value, described explicitly (example only!)

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

76 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

72 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

2 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information for the first sample (mantissa)

0 (bitOffset)

9 (= “10”) (bitLength)

0 (channelType) (RED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0 (sampleLower)

1024 (sampleUpper) — implicit 1

Sample information for the second sample (sign bit)

15 (bitOffset)

0 (= “1”) (bitLength)

64 (channelType)

(RED | SIGNED)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0xFFFFFFFF (sampleLower)

0x0 (sampleUpper)

Sample information for the third sample (exponent)

10 (bitOffset)

4 (= “5”) (bitLength)

32 (channelType)

(RED | EXPONENT)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

15 (sampleLower) — bias

30 (sampleUpper) — support for infinities (because 31 can be encoded)

Table 43. A single 16-bit floating-point red value, described normally

Byte 0 (LSB) Byte 1 Byte 2 Byte 3 (MSB)

44 (totalSize)

0 (vendorId)

0 (descriptorType)

1 (versionNumber)

40 (descriptorBlockSize)

RGBSDA (colorModel)

BT709 (colorPrimaries)

LINEAR (transferFunction)

ALPHA_STRAIGHT (flags)

0 (texelBlockDimension0)

0 (texelBlockDimension1)

0 (texelBlockDimension2)

0 (texelBlockDimension3)

2 (bytesPlane0)

0 (bytesPlane1)

0 (bytesPlane2)

0 (bytesPlane3)

0 (bytesPlane4)

0 (bytesPlane5)

0 (bytesPlane6)

0 (bytesPlane7)

Sample information

0 (bitOffset)

15 (= “16”) (bitLength)

192 (channelType)

(RED | SIGNED | FLOAT)

0 (samplePosition0)

0 (samplePosition1)

0 (samplePosition2)

0 (samplePosition3)

0xbf80000 (sampleLower) = -1.0

0x3f80000 (sampleUpper) = 1.0

12. Introduction to color conversions

12.1. Color space composition

A “color space” determines the meaning of decoded numerical color values: that is, it is distinct from the bit patterns, compression schemes and locations in memory used to store the data.

A color space consists of three basic components:

• Transfer functions define the relationships between linear intensity and linear numbers in the encoding scheme. Since the human eye’s sensitivity to changes in intensity is non-linear, a non-linear encoding scheme typically allows improved visual quality at reduced storage cost.

• An opto-electrical transfer function (OETF) describes the conversion from “scene-referred” normalized linear light intensity to a (typically) non-linear electronic representation. The inverse function is written “OETF -1”.
• An electro-optical transfer function (EOTF) describes the conversion from the electronic representation to “display-referred” normalized linear light intensity in the display system. The inverse function is written “EOTF -1”.
• An opto-optical transfer function (OOTF) describes the relationship between the linear scene light intensity and linear display light intensity: OOTF(x) = EOTF(OETF(x)). OETF = EOTF -1 and EOTF = OETF -1 only if the OOTF is linear.
• Historically, a non-linear transfer function has been implicit due to the non-linear relationship between voltage and intensity provided by a CRT display. In contrast, many computer graphics applications are best performed in a representation with a linear relationship to intensity.
• Use of an incorrect transfer function can result in images which have too much or too little contrast or saturation, particularly in mid-tones.
• Color primaries define the spectral response of a “pure color” in an additive color model - typically, what is meant by “red”, “green” and “blue” for a given system, and (allowing for the relative intensity of the primaries) consequently define the system’s white balance.

• These primary colors might refer to the wavelengths emitted by phosphors on a CRT, transmitted by filters on an LCD for a given back-light, or emitted by the LED sub-pixels of an OLED. The primaries are typically defined in terms of a reference display, and represent the most saturated colors the display can produce, since other colors are by definition created by combining the primaries. The definition usually describes a relationship to the responses of the human visual system rather than a full spectrum.
• Use of incorrect primaries introduces a shift of hue, most visible in saturated colors.

• Color models describe the distinction between a color representation and additive colors. Since the human visual system treats differences in absolute intensity differently from differences in the spectrum composing a color, many formats benefit from transforming the color representation into one which can separate these aspects of color. Color models are frequently “named” by listing their component color channels.

• For example, a color model might directly represent additive primaries (RGB), simple color difference values (Y′CBCR — colloquially YUV), or separate hue, saturation and intensity (HSV/HSL).
• Interpreting an image with an incorrect color model typically results in wildly incorrect colors: a (0,0,0) triple in an RGB additive color model typically represents black, but may represent white in CMYK, or saturated green in color difference models.

12.2. Operations in a color conversion

Conversion between color representations may require a number of separate conversion operations:

• Conversion between representations with different color primaries can be performed directly. If the input and output of the conversion do not share the same color primaries, this transformation forms the “core” of the conversion.
• The color primary conversion operates on linear RGB additive color values; if the input or output are not defined in linear terms but with a non-linear transfer function, any color primary conversion must be “wrapped” with any transfer functions; conventionally, non-linear RGB values are written R′G′B′.
• If the input or output color model is not defined in terms of additive primaries (for example, Y′CBCR — colloquially known as YUV), the model conversion is applied to the non-linear R′G′B′ values; the Y′CC′CBC′CR and ICTCP color models are created from both linear and non-linear RGB.
• Converting numerical values stored in memory to the representation of the color model may itself require additional operations - in order to remove dependence on bit depth, all the formulae described here work with continuous natural numbers, but some common in-memory quantization schemes must often be applied.

Details of these conversion operations are described in the following chapters.

 As described in the License Information at the start of this document, the Khronos Data Format Specification does not convey a right to implement the operations it describes. This is particularly true of the conversion formulae in the following sections, whose inclusion is purely informative. Please refer to the originating documents and the bodies responsible for the standards containing these formulae for the legal framework required for implementation.

Common cases such as converting a Y′CBCR image encoded for 625-line BT.601 to a Y′CBCR image encoded for BT.709 can involve multiple costly operations. An example is shown in the following diagram, which represents sampling from a Y′CBCR texture in one color space, and the operations needed to generate a different set of Y′CBCR values representing the color of the sample position in a different color space:

In this diagram, non-linear luma Y′ channels are shown in black and white, color difference CB/CR channels are shown with the colors at the extremes of their range, and color primary channels are shown as the primary color and black. Linear representations are shown diagonally divided by a straight line; non-linear representations are shown with a gamma curve. The luma and color difference representation is discussed in Section 15.1. The interpretation of color primaries is discussed in Section 14. Non-linear transfer functions are described in Section 13. As described below, the diagram shows a 2×3 grid of input chroma texel values, corresponding to a 4×6 grid of luma texel values, since the chroma channels are stored at half the horizontal and half the vertical resolution of the luma channel (i.e. in “4:2:0” representation). Grayed-out texel values do not contribute to the final output, and are shown only to indicate relative alignment of the coordinates.

The stages numbered in the above diagram show the following operations:

1. Arranging the channels from the representation correctly for the conversion operations (a “swizzle”). In this example, the implementation requires that the CB and CR values be swapped.
2. Range expansion to the correct range for the values in the color model (handled differently, for example, for “full” and “narrow” ranges); in this example, the result is to increase the effective dynamic range of the encoding: contrast and saturation are increased.

In this example, operations 1 and 2 can be combined into a single sparse matrix multiplication of the input channels, although actual implementations may wish to take advantage of the sparseness.

3. Reconstruction to full resolution of channels which are not at the full sampling resolution (“chroma reconstruction”), for example by replication or interpolation at the sites of the luma samples, allowing for the chroma sample positions; this example assumes that the chroma samples are being reconstructed through linear interpolation. In the diagram, sample positions for each channel are shown as green dots, and each channel corresponds to the same region of the image; in this example, the chroma samples are located at the horizontal and vertical midpoint of quads of luma samples, but different standards align the chroma samples differently. Note that interpolation for channel reconstruction necessarily happens in a non-linear representation for color difference representations such as Y′CBCR: creating a linear representation would require converting to RGB, which in turn requires a full set of Y′CBCR samples for a given location.
4. Conversion between color models — in this example, from non-linear Y′CBCR to non-linear R′G′B′. For example, the conversion might be that between BT.601 Y′CBCR and BT.601 non-linear R′G′B′ described in Section 15.1.2. For Y′CBCR to R′G′B′, this conversion is a sparse matrix multiplication.
5. Application of a transfer function to convert from non-linear R′G′B′ to linear RGB, using the color primaries of the input representation. In this case, the conversion might be the EOTF -1 described in Section 13.2.

The separation of stages 4 and 5 is specific to the Y′CBCR to R′G′B′ color model conversion. Other representations such as Y′CC′BCC′RC and ICTCP have more complex interactions between the color model conversion and the transfer function.

6. Interpolation of linear color values at the sampling position shown with a magenta cross according to the chosen sampling rules.
7. Convert from the color primaries of the input representation to the desired color primaries of the output representation, which is a matrix multiplication operation. Conversion from linear BT.601 EBU primaries to BT.709 primaries, as described in Section 14.2 and Section 14.1.
8. Convert from the linear RGB representation using the target primaries to a non-linear R′G′B′ representation, for example the OETF described in Section 13.2.
9. Conversion from non-linear R′G′B′ to the Y′CBCR color model, for example as defined in as defined in Section 15.1.1 (a matrix multiplication).

If the output is to be written to a frame buffer with reduced-resolution chroma channels, chroma values for multiple samples need to be combined. Note that it is easy to introduce inadvertent chroma blurring in this operation if the source space chroma values are generated by interpolation.

In this example, generating the four linear RGB values required for linear interpolation at the magenta cross position requires six chroma samples. In the example shown, all four Y′ values fall between the same two chroma sample centers on the horizontal axis, and therefore recreation of these samples by linear blending on the horizontal axis only requires two horizontally-adjacent samples. However, the upper pair of Y′ values are sited above the sample position of the middle row of chroma sample centers, and therefore reconstruction of the corresponding chroma values requires interpolation between the upper four source chroma values. The lower pair of Y′ values are sited below the sample position of the middle row of chroma sample centers, and therefore reconstruction of the corresponding chroma values requires interpolation between the lower four source chroma values. In general, reconstructing four chroma values by interpolation may require four, six or nine source chroma values, depending on which samples are required. The worst case is reduced if chroma samples are aligned (“co-sited”) with the luma values, or if chroma channel reconstruction uses replication (nearest-neighbor filtering) rather than interpolation.

An approximation to the above conversion is depicted in the following diagram:

A performance-optimized approximation to our example conversion may use the following steps:

1. Channel rearrangement (as in the previous example)
2. Range expansion (as in the previous example)
3. Chroma reconstruction combined with sampling. In this case, the desired chroma reconstruction operation is approximated by adjusting the sample locations to compensate for the reduced resolution and sample positions of the chroma channels, resulting in a single set of non-linear Y′CBCR values.
4. Model conversion from Y′CBCR to R′G′B′ as described in Section 15.1.2, here performed after the sampling/filtering operation.
5. Conversion from non-linear R′G′B′ to linear RGB, using the EOTF -1 described in Section 13.2.
6. Conversion of color primaries, corresponding to step 7 of the previous example.
7. Conversion to a non-linear representation, corresponding to step 8 of the previous example.
8. Conversion to the output color model, corresponding to step 9 of the previous example.
 Since stages 1 and 2 represent an affine matrix transform, linear interpolation of input values may equivalently be performed before these operations. This observation allows stages 1..4 to be combined into a single matrix transformation.

Large areas of constant color will be correctly converted by this approximation. However, there are two sources of errors near color boundaries:

1. Interpolation takes place on values with a non-linear representation; the repercussions of this are discussed in Section 13, but can introduce both intensity and color shifts. Note that applying a non-linear transfer function as part of filtering does not improve accuracy for color models other than R′G′B′ since the non-linear additive values have been transformed as part of the color model representation.
2. When chroma reconstruction is bilinear and the final sample operation is bilinear, the interpolation operation now only access a maximum of four chroma samples, rather than up to nine for the precise series of operations. This has the potential to introduce a degree of aliasing in the output.

This approximation produces identical results to the more explicit sequence of operations in two cases:

1. If chroma reconstruction uses nearest-neighbor replication and the sampling operation is also a nearest-neighbor operation rather than a linear interpolation.
2. If the sampling operation is a nearest-neighbor operation and chroma reconstruction uses linear interpolation, if the sample coordinate position is adjusted to the nearest luma sample location.

As another example, the conversion from BT.709-encoded Y′CBCR to sRGB R′G′B′ may be considered to be a simple model conversion (to BT.709 R′G′B′ non-linear primaries using the “ITU” OETF), since sRGB shares the BT.709 color primaries and is defined as a complementary EOTF intended to be combined with BT.709’s OETF. This interpretation imposes a $\gamma \approx$ 1.1 OOTF. Matching the OOTF of a BT.709-BT.1886 system, for which $\gamma \approx$ 1.2, implies using the BT.1886 EOTF to convert to linear light, then the sRGB EOTF -1 to convert back to sRGB non-linear space. Encoding linear scene light with linear OOTF means applying the BT.709 OETF -1; if the sRGB R′G′B′ target is itself intended to represent a linear OOTF, then the {R′sRGB, G′sRGB, B′sRGB} should be calculated as:

$$\{\mathit{R}'_\mathit{sRGB},\mathit{G}'_\mathit{sRGB},\mathit{B}'_\mathit{sRGB}\} = \textrm{EOTF}^{-1}_{sRGB}(\textrm{OETF}^{-1}_{\mathit{BT}.709} (\{\mathit{R}'_{\mathit{BT}.709},\mathit{G}'_{\mathit{BT}.709},\mathit{B}'_{\mathit{BT}.709}\}))$$

13. Transfer functions

The transfer function describes the mapping between a linear numerical representation and a non-linear encoding. The eye is more sensitive to relative light levels than absolute light levels. That is, if one image region is twice as bright as another, this will be more visible than if one region is 10% brighter than another, even if the absolute difference in brightness is the same in both cases. To make use of the eye’s non-linear response to light to provide better image quality with a limited number of quantization steps, it is common for color encodings to work with a non-linear representation which dedicates a disproportionate number of bits to darker colors compared with lighter colors. The typical effect of this encoding is that mid-tones are stored with a larger (nearer-to-white) numerical value than their actual brightness would suggest, and that mid-values in the non-linear encoding typically represent darker intensities than their fraction of the representation of white would suggest.

The behavior has historically been approximated by a power function with an exponent conventionally called $\gamma$ : {R,G,B}non-linear = {R,G,B}linear $\gamma$ . Hence this conversion is colloquially known as gamma correction.

 Many practical transfer functions incorporate a small linear segment near 0, instead of being a pure power function. This linearity reduces the required resolution for representing the conversion, especially where results must be reversible, and also reduces the noise sensitivity of the function in an analog context. When combined with a linear segment, the power function has a different exponent from the pure power function that best approximates the resulting curve.

A consequence of this non-linear encoding is that many image processing operations should not be applied directly to the raw non-linearly-encoded numbers, but require conversion back to a linear representation. For example, linear color gradients will appear distorted unless the encoding is adjusted to compensate for the encoding; CGI lighting calculations need linear intensity values for operation, and filtering operations require texel intensities converted to linear form.

In the following example, the checker patterns are filtered in the right-most square of each row by averaging the checker colors, emulating a view of the pattern from a distance at which the individual squares are no longer distinct. The intended effect can be seen by viewing the diagram from a distance, or deliberately out of focus. The output is interpreted using the sRGB EOTF, approximating the behavior of a CRT with uncorrected signals. The background represents 50% gray.

• In row 1 black (0.0) and white (1.0) texels are averaged to calculate a 0.5 value in the frame buffer. Due to the sRGB non-linearity, the appearance of the value 0.5 is darker than the average value of the black and white texels, so the gray box appears darker than the average intensity of the checker pattern.
• In row 2 the 0.5 average of the frame buffer is corrected using the sRGB (electro-optical) EOTF -1 to ∼0.74. The gray box accordingly appears a good match for the average intensity of the black and white squares on most media.
• In row 3 the checker pattern instead represents values of 25% and 75% of the light intensity (the average of which should be the same as the correct average of the black and white squares in the first two rows). These checker values have been converted to their non-linear representations, as might be the case for a texture in this format: the darker squares are represented by ∼0.54, and the lighter squares are represented by ∼0.88. Averaging these two values to get a value of 0.71 results in the right-most square: this appears slightly too dark compared with the correct representation of mid-gray (∼0.74) because, due to the non-linear encoding, the calculated value should not lie exactly half way between the two end points. Since the end points of the interpolation are less distant than the black and white case, the error is smaller than in the first example, and can more clearly be seen by comparing with the background gray.
• In row 4 the checker values have been converted using the EOTF to a linear representation which can be correctly interpolated, but the resulting output represents linear light, which is therefore interpreted as too dark by the non-linear display.
• In row 5 the results of row 4 have been converted back to the non-linear representation using the EOTF -1. The checker colors are restored to their correct values, and the interpolated value is now the correct average intensity of the two colors.

Incorrectly-applied transfer functions can also introduce color shifts, as demonstrated by the saturation change in the following examples:

A standard for image representation typically defines one or both of two types of transfer functions:

• An opto-electronic transfer function (OETF) defines the conversion between a normalized linear light intensity as recorded in the scene, and a non-linear electronic representation. Note that there is no requirement that this directly correspond to actual captured light: the content creator or scene capture hardware may adjust the apparent intensity compared to reality for aesthetic reasons, as though the colors (or lighting) of objects in the scene were similarly different from reality. For example, a camera may implement a roll-off function for highlights, and a content creator may introduce tone mapping to preserve shadow detail in the created content, with these being logically recorded as if the scene was actually modified accordingly. The inverse of the OETF (the conversion from the non-linear electronic representation to linear scene light) is written OETF -1(n).
• An electro-optical transfer function (EOTF) converts between a non-linear electronic representation and a linear light normalized intensity as produced by the output display. The inverse of the EOTF (the conversion from linear display light to the non-linear electronic representation) is written EOTF -1(n). Typical CRT technology has implicitly applied a non-linear EOTF which coincidentally offered an approximately perceptually linear gradient when supplied with a linear voltage; other display technologies must implement the EOTF explicitly. As with the OETF, the EOTF describes a logical relationship that in reality will be modified by the viewer’s aesthetic configuration choices and environment, and by the implementation choices of the display medium. Modern displays often incorporate proprietary variations from the reference intensity, particularly when mapping high dynamic range content to the capabilities of the hardware.
 Some color models derive chroma (color difference) channels wholly or partly from non-linear intensities. It is common for image representations which use these color models to use a reduced-resolution representation of the chroma channels, since the human eye is less sensitive to high resolution chroma errors than to errors in brightness. Despite the color shift introduced by interpolating non-linear values, these chroma channels are typically resampled directly in their native, non-linear representation.

The opto-optical transfer function (OOTF) of a system is the relationship between linear input light intensity and displayed output light intensity: OOTF(input) = EOTF(OETF(input)). It is common for the OOTF to be non-linear. For example, a brightly-lit scene rendered on a display that is viewed in a dimly-lit room will typically appear washed-out and lacking contrast, despite mapping the full range of scene brightness to the full range supported by the display. A non-linear OOTF can compensate for this by reducing the intensity of mid-tones, which is why television standards typically assume a non-linear OOTF: logical scene light intensity is not proportional to logical display intensity.

In the following diagram, the upper pair of images are identical, as are the lower pair of images (which have mid-tones darkened but the same maximum brightness). Adaptation to the surround means that the top left and lower right images look similar.

In the context of a non-linear OOTF, an application should be aware of whether operations on the image are intended to reflect the representation of colors in the scene or whether the intent is to represent the output color accurately, at least when it comes to the transfer function applied. For example, an application could choose to convert lighting calculations from a linear to non-linear representation using the OETF (to match the appearance of lighting in the scene), but to perform image scaling operations using the EOTF in order to avoid introducing intensity shifts due to filtering. Working solely with the EOTF or OETF results in ignoring the intended OOTF of the system.

In practice, the OOTF is usually near enough to linear that this distinction is subtle and rarely worth making for computer graphics, especially since computer-generated images may be designed to be viewed in brighter conditions which would merit a linear OOTF, and since a lot of graphical content is inherently not photo-realistic (or of limited realism, so that the transfer functions are not the most important factor in suspending disbelief). For video and photographic content viewed in darker conditions, the non-linearity of the OOTF is significant. The effect of a non-linear OOTF is usually secondary to the benefits of using non-linear encoding to reduce quantization.

By convention, non-linearly-encoded values are distinguished from linearly-encoded values by the addition of a prime (′) symbol. For example, (R,G,B) may represent a linear set of red, green and blue components; (R′,G′,B′) would represent the non-linear encoding of each value. Typically the non-linear encoding is applied to additive primary colors; derived color differences may or may not retain the prime symbol.

Charles Poynton provides a further discussion on “Gamma” in http://www.poynton.com/PDFs/TIDV/Gamma.pdf.

13.2. ITU transfer functions

 “ITU” is used in this context as a shorthand for the OETF shared by the current BT.601, BT.709 and BT.2020 family of standard dynamic range digital television production standards. The same OETF is shared by SMPTE 170M. The ITU does define other transfer functions, for example the PQ and HLG transfer functions described below (originating in BT.2100) and the list of EOTFs listed in BT.470-6.

13.2.1. ITU OETF

The ITU-T BT.601, BT.709 and BT.2020 specifications (for standard definition television, HDTV and UHDTV respectively), and SMPTE 170M, which defines NTSC broadcasts, define an opto-electrical transfer function. The (OETF) conversion from linear (R,G,B) encoding to non-linear (R′,G′,B′) encoding is:

\begin{align*} \textit{R}' &= \begin{cases} \textit{R} \times 4.500, & \textit{R} < \beta \\ \alpha \times \textit{R}^{0.45} - (\alpha - 1), & \textit{R} \geq \beta \end{cases} \\ \textit{G}' &= \begin{cases} \textit{G} \times 4.500, & \textit{G} < \beta \\ \alpha \times \textit{G}^{0.45} - (\alpha - 1), & \textit{G} \geq \beta \end{cases} \\ \textit{B}' &= \begin{cases} \textit{B} \times 4.500, & \textit{B} < \beta \\ \alpha \times \textit{B}^{0.45} - (\alpha - 1), & \textit{B} \geq \beta \end{cases} \end{align*}

Where α = 1.0993 and β = 0.0181 for 12-bit encoding in the BT.2020 specification, and $\alpha = 1.099$ and $\beta = 0.018$ otherwise.

13.2.2. ITU OETF -1

From this the inverse (OETF -1) transformation can be deduced:

\begin{align*} \textit{R} &= \begin{cases} {{\textit{R}'}\over{4.500}}, & \textit{R}' < \delta \\ {\left({\textit{R}' + (\alpha - 1)}\over{\alpha}\right)}^{1\over{0.45}}, & \textit{R}' \geq \delta \end{cases} \\ \textit{G} &= \begin{cases} {{\textit{G}'}\over{4.500}}, & \textit{G}' < \delta \\ {\left({\textit{G}' + (\alpha - 1)}\over{\alpha}\right)}^{1\over{0.45}}, & \textit{G}' \geq \delta \end{cases} \\ B &= \begin{cases} {{\textit{B}'}\over{4.500}}, & \textit{B}' < \delta \\ {\left({\textit{B}' + (\alpha - 1)}\over{\alpha}\right)}^{1\over{0.45}}, & \textit{B}' \geq \delta \end{cases} \end{align*}

δ can be deduced from α × β0.45 - (α - 1) ≈ 0.0812. Note that this is subtly different from 4.5 × β due to rounding. See the following section for the derivation of these values.

SMPTE 170M-2004, which defines the behavior of NTSC televisions, defines the EOTF of the “reference reproducer” as the OETF -1 function above, with δ explicitly written as 0.0812. Therefore the SMPTE 170M-2004 EOTF -1 equals the OETF given above. The “reference camera” of SMTPE 170M-2004 has an OETF function matching that of the ITU specifications. That is, the OOTF of the system described in SMPTE 170M-2004 provides a linear mapping of captured scene intensity to display intensity: the SMPTE 170M-2004 OETF is described as being chosen to result in a linear OOTF on a typical display. This is distinct from the current ITU specifications, which assume a non-linear OOTF. SMPTE 170M-2004 also represents a change from the “assumed gamma” of 2.2 associated with most NTSC display devices as described in ITU-T BT.470-6 and BT.2043, although these standards also define a linear OOTF.

This “ITU” OETF is closely approximated by a simple power function with an exponent of 0.5 (and therefore the OETF -1 is quite closely approximated by a simple power function with an exponent of 2.0); the linear segment and offset mean that the best match is not the exponent of 0.45 that forms part of the exact equation. ITU standards deliberately chose a different transfer curve from that of a typical CRT in order to introduce a non-linear OOTF, as a means to compensate for the typically dim conditions in which a television is viewed. ITU BT.2087 refers to the approximation of the OETF with a square root $\left(\gamma = {1\over{2}}\right)$ function.

The following graph shows the close relationship between the ITU OETF (shown in red) and a pure power function with $\gamma={1\over{2}}$ (in blue). The difference between the curves is shown in black. The largest difference between the curve values at the same point when quantized to 8 bits is 15, mostly due to the sharp vertical gradient near 0.

 SMPTE 170M-2004 contains a note that the OETF is a more “technically correct” definition of the transfer function, and compares it to a “transfer gradient (gamma exponent) of 2.2” in previous specifications, and that the OETF in older documents is described as “1/2.2 (0.455…)”. While both versions define a linear OOTF, there is no explicit mention that curve has substantially changed; this might be due to conflation of the 0.455 exponent in older specifications with the 0.45 exponent in the new formulae. The ITU OETF is actually a closer match to a gamma exponent of $1\over{2.0}$ , as shown above; it is a relatively poor match to a gamma exponent of $1\over{2.2}$ ; the following graph shows the difference between the ITU OETF (shown in red) and a pure power function with $\gamma={1\over{2.2}}$ (in blue). The difference between the curves is shown in black.

13.2.3. Derivation of the ITU alpha and beta constants (informative)

Using the 12-bit encoding values for α and β from Rec.2020, there is an overlap around a non-linear value of 0.08145. In other cases, the conversion from linear to non-linear representation with encoding introduces a discontinuity between (0.018 × 4.500) = 0.081 and (1.099 × 0.0180.45 - 0.099) ≈ 0.0812, corresponding to roughly a single level in a 12-bit range. SMPTE 170M-2004 provides formulae for both transformations and uses 0.0812 as a case selector for the non-linear-to-linear transformation.

The values of α and β in the ITU function were apparently chosen such that the linear segment and power segment meet at the same value and with the same derivative (that is, the linear segment meets the power segment at a tangent). The α and β values can be derived as follows:

At {R,G,B} = β, the linear and non-linear segments of the curve must calculate the same value:

$$4.5 \times \beta = \alpha \times \beta^{0.45} - (\alpha - 1)$$

Additionally, the derivatives of the linear and non-linear segments of the curve must match:

$$4.5 = 0.45 \times \alpha \times \beta^{-0.55}$$

The derivative can be rearranged to give the equation:

$$\alpha = 10 \times \beta^{0.55}$$

Substituting this into the original equation results in the following:

$$4.5 \times \beta = 10 \times \beta^{0.55} \times \beta^{0.45} - (10 \times \beta^{0.55} - 1)$$

This simplifies to:

$$5.5 \times \beta - 10 \times \beta^{0.55} + 1 = 0$$

This can be solved numerically (for example by Newton-Raphson iteration), and results in values of:

\begin{align*} \beta &\approx 0.018053968510808\\ \alpha &\approx 1.099296826809443\\ \delta &= \alpha\times\beta^{0.45} - (\alpha-1) = 4.5\times\beta\\ &\approx 0.081242858298635\\ \end{align*}

13.3. sRGB transfer functions

13.3.1. sRGB EOTF

The sRGB specification defines an electro-optical transfer function. The EOTF conversion from non-linear $(R', G', B')$ encoding to linear $(R, G, B)$ encoding is:

\begin{align*} R &= \begin{cases} {R' \over 12.92}, & R' \leq 0.04045 \\ \left({R' + 0.055} \over 1.055\right)^{2.4}, & R' > 0.04045 \end{cases} \\ G &= \begin{cases} {G' \over 12.92}, & G' \leq 0.04045 \\ \left({G' + 0.055} \over 1.055\right)^{2.4}, & G' > 0.04045 \end{cases} \\ B &= \begin{cases} {B' \over 12.92}, & B' \leq 0.04045 \\ \left({B' + 0.055} \over 1.055\right)^{2.4}, & B' > 0.04045 \end{cases} \end{align*}

13.3.2. sRGB EOTF-1

The corresponding sRGB EOTF -1 conversion from linear $(R, G, B)$ encoding to non-linear $(R', G', B')$ encoding is:

\begin{align*} R' &= \begin{cases} R \times 12.92, & R \leq 0.0031308 \\ 1.055 \times R^{1\over 2.4} - 0.055, & R > 0.0031308 \end{cases} \\ G' &= \begin{cases} G \times 12.92, & G \leq 0.0031308 \\ 1.055 \times G^{1\over 2.4} - 0.055, & G > 0.0031308 \end{cases} \\ B' &= \begin{cases} B \times 12.92, & B \leq 0.0031308 \\ 1.055 \times B^{1\over 2.4} - 0.055, & B > 0.0031308 \end{cases} \end{align*}

13.3.3. sRGB EOTF vs gamma 2.2

The sRGB EOTF approximates a simple power function with an exponent of 2.2, which is intended to be consistent with legacy CRT content, particularly for NTSC devices, and to approximate the expected EOTF for BT.709 content, given the implicit OOTF used in production video content. sRGB is distinct from ITU-T BT.1886, which offers a (different) reference EOTF for flat panels used for HDTV and is also intended to complement BT.709; in addition to the change in EOTF, sRGB specifies a reference display maximum luminance of 80cd/m2, compared with 100cd/m2 for BT.1886. sRGB is also distinct from SMPTE 170M, which defines its EOTF as the inverse of its (and BT.709’s) OETF.

The following graph compares the sRGB EOTF (in red) and a pure power function with $\gamma=2.2$ (in blue); the area between the two curves is shown in black. The largest non-linear difference at the same linear value when quantized to 8 bits is 3.

 The sRGB standard assumes a quantization scheme in which 0.0 is represented by the value 0 and 1.0 is represented by 255. Despite the goal of complementing ITU-T Rec. BT.709, this is different from the ITU “full-range” encoding scheme defined in ITU-T Rec. BT.2100, which represents 1.0 as a power of two (not $2^n-1$ ) and therefore cannot exactly represent 1.0.

The following graph shows the relationship between the sRGB EOTF (shown in red) and the ITU OETF (shown in blue). The result of applying the two functions in turn, resulting in the OOTF of a combined ITU-sRGB system, is shown in black. Since the sRGB EOTF approximates a power function with $\gamma=2.2$ and the ITU OETF approximates a power function with $\gamma=2.0$ , also shown in green is the resulting OOTF corresponding to a power function with $\gamma={2.2\over{2.0}}=1.1$ .

13.3.4. scRGB EOTF and EOTF-1

The original sRGB specification was defined only in terms of positive values between 0 and 1. Subsequent standards, such as scRGB annex B, use the same transfer function but expand the range to incorporate values less than 0 and greater than 1.0. In these cases, when the input channel to the conversion is negative, the output should be the negative version of the conversion applied to the absolute value of the input. That is:

\begin{align*} R' &= \begin{cases} -1.055 \times (-R)^{1\over 2.4} + 0.055, & R \leq -0.0031308 \\ R \times 12.92, & -0.0031308 < R < 0.0031308 \\ 1.055 \times R^{1\over 2.4} - 0.055, & R \geq 0.0031308 \end{cases} \\ G' &= \begin{cases} -1.055 \times (-G)^{1\over 2.4} + 0.055, & G \leq -0.0031308 \\ G \times 12.92, & -0.0031308 < G < 0.0031308 \\ 1.055 \times G^{1\over 2.4} - 0.055, & G \geq 0.0031308 \end{cases} \\ B' &= \begin{cases} -1.055 \times (-B)^{1\over 2.4} + 0.055, & B \leq -0.0031308 \\ B \times 12.92, & -0.0031308 < B < 0.0031308 \\ 1.055 \times B^{1\over 2.4} - 0.055, & B \geq 0.0031308 \end{cases} \end{align*}
 scRGB annex B changes the behavior of the $\{R,G,B\} = 0.0031308$ case compared with the sRGB specification. Since both calculations agree to seven decimal places, this is unlikely to be significant in most applications. scRGB annex B does not define the EOTF -1, so the formulae below are derived by extending the sRGB formulae.
\begin{align*} R &= \begin{cases} -\left({0.055 - R'} \over 1.055\right)^{2.4}, & R' < -0.04045 \\ {R' \over 12.92}, & -0.04045 \leq R' \leq 0.04045 \\ \left({R' + 0.055} \over 1.055\right)^{2.4}, & R' > 0.04045 \end{cases} \\ G &= \begin{cases} -\left({0.055 - G'} \over 1.055\right)^{2.4}, & G' < -0.04045 \\ {G' \over 12.92}, & -0.04045 \leq G' \leq 0.04045 \\ \left({G' + 0.055} \over 1.055\right)^{2.4}, & G' > 0.04045 \end{cases} \\ B &= \begin{cases} -\left({0.055 - B'} \over 1.055\right)^{2.4}, & B' < -0.04045 \\ {B' \over 12.92}, & -0.04045 \leq B' \leq 0.04045 \\ \left({B' + 0.055} \over 1.055\right)^{2.4}, & B' > 0.04045 \end{cases} \end{align*}
 sYCC includes a hint that a 1cd/m2 level of flare should be assumed for the reference 80cd/m2 output, and that the black level should therefore be assumed to be ${1\over 80} = 0.0125$ . It notes that the non-linear sRGB { $R',G',B'$ } values can be corrected as follows:\begin{align*} E_{sYCC} &= \begin{cases} 0.0125 - \left({1-0.0125\over 1.055^{2.4}}\right) \times (0.055 - E'_{sRGB})^{2.4}, & E'_{sRGB} \leq -0.04045\ [\textrm{sic}]\\ 0.0125 + {1-0.0125\over 12.92} \times E'_{sRGB}, & -0.04045 \leq E'_{sRGB} \leq 0.04045 \\ 0.0125 + \left({1-0.0125\over 1.055^{2.4}}\right) \times (0.055 + E'_{sRGB})^{2.4}, & E'_{sRGB} > 0.04045 \end{cases}\\ E_{sYCC} &= (\textrm{linear}) \{R_{sYCC},G_{sYCC},B_{sYCC}\} \\ E'_{sRGB} &= (\textrm{non-linear}) \{R'_{sRGB},G'_{sRGB},B'_{sRGB}\} \end{align*}This is equivalent to applying $E_{sYCC} = 0.0125 + {1\over 1-0.0125} \times E_{sRGB}$ to linear $\{R,G,B\}$ values. The resulting linear $E_{sYCC}$ values then need to be non-linearly encoded with the EOTF.

13.3.5. Derivation of the sRGB constants (informative)

Similar to the ITU transfer function, the EOTF -1 of the sRGB function can be written as:

\begin{align*} \{R,G,B\} &= \begin{cases} \{R',G',B'\} \times 12.92, & \{R',G',B'\} \leq \beta \\ \alpha \times \{R',G',B'\}^{1\over{2.4}} - (\alpha - 1), & \{R',G',B'\} < \beta \end{cases} \end{align*}

Like the ITU transfer function above, the values of $\alpha$ and $\beta$ in the sRGB function appear to have been chosen such that the linear segment and power segment meet at the same value and with the same derivative (that is, the linear segment meets the power segment at a tangent). The $\alpha$ and $\beta$ values can be derived as follows:

At $\{R',G',B'\} = \beta$ , the linear and non-linear segments of the function must calculate the same value:

$$12.92 \times \beta = \alpha \times \beta^{1\over{2.4}} - (\alpha - 1)$$

Additionally, the derivatives of the linear and non-linear segments of the function must match:

$$12.92 = {{\alpha \times \beta^{{1\over{2.4}}-1}}\over{2.4}}$$

This formula can be rearranged to give $\alpha$ in terms of $\beta$ :

$$\alpha = 12.92\times 2.4\times \beta^{1-{1\over{2.4}}}$$

Substituting this into the formula for $\{R,G,B\}$ :

$$12.92 \times \beta = 12.92\times 2.4\times \beta^{1-{1\over{2.4}}} \times \beta^{1\over{2.4}} - (12.92\times 2.4\times \beta^{1-{1\over{2.4}}} - 1)$$

This equation simplifies to:

$$1.4 \times 12.92 \times \beta - 2.4 \times 12.92 \times \beta^{1 - {1\over{2.4}}} + 1 = 0$$

This can be further simplified to:

$$1.4 \times \beta - 2.4 \times \beta^{1 - {1\over{2.4}}} + {1\over{12.92}} = 0$$

The value of $\beta$ can be found numerically (for example by Newton-Raphson iteration, with a derivative of $1.4-1.4\beta^{-{1\over{2.4}}}$ ), and results in values of:

\begin{align*} \beta &\approx 0.003041282560128\\ \alpha &\approx 1.055010718947587\\ \delta &= 12.92\times\beta = \alpha\times\beta^{1\over{2.4}}-(\alpha-1.0)\\ &\approx 0.039293370676848 \end{align*}

Where $\delta$ is the value of the EOTF -1 at $\{R',G',B'\} = \beta$ .

 These deduced values are appreciably different from those in the sRGB specification, which does not state the origin of its constants. The intersection point of the sRGB EOTF has less numerical stability (and more nearby local minima in curves being optimized) that the corresponding ITU function - it is sensitive to the start value used for numerical approximations. This may explain how different values were reached for the sRGB specification. However, the errors both in value and derivative at the point of selection between the linear and exponent segments are small in practice.

The EOTF can be written with these derived values as:

$$\{R,G,B\} = \begin{cases} {{\{R',G',B'\}}\over{12.92}}, & \{R',G',B'\} \leq \delta \\ \left({{\{R',G',B'\}}\over{\alpha}} + {{\alpha-1}\over\alpha}\right)^{2.4}, & \{R',G',B'\} > \delta \end{cases}$$
 Apple describes the Display P3 color space as using the sRGB transfer function. The profile viewer in Apple’s ColorSync utility reports that the EOTF is of the following form: $$f(x) = \begin{cases} cx, & x < d \\ (ax+b)^\gamma, & x \geq d \end{cases}$$The reported figures for $\gamma=2.4,\ a=0.948,\ b=0.52$ and $c=0.077$ correspond to the equivalent values in the sRGB specification:\begin{align*} {1\over{\alpha}} &\approx 0.948 = a\\ {{\alpha-1}\over\alpha} &\approx 0.52 = b\\ {1\over{12.92}} &\approx 0.077 = c \end{align*}These values are correct to the reported precision both for the value $\alpha = 1.055$ in the sRGB specification and for the more precise $\alpha \approx 1.055010718947587$ derived above. However, where the sRGB specification states that $\delta = 0.04045$ , the profile viewer reports a corresponding d = 0.039. The disparity can be explained if the profile values have been derived as described in this section:$$\delta \approx 0.039293370676848\approx 0.039 = d$$Note that this value assumes a correspondingly corrected version of $\alpha$ rather than $a = 1.055$ . The extra precision may be needed over the constants in the sRGB specification due to the use of additional bits of accuracy in the Display P3 representation, which may expose a discontinuity due to rounding with the original numbers, particularly in the gradient of the curve. However, this distinction is subtle: when calculated over a [0..1] range, the derived EOTF and EOTF -1 agree with the official sRGB formulae to greater than 16-bit precision.

Without allowing for adjusting the $\alpha = 1.055$ constant in the sRGB formula, the power function cannot be made to intersect perfectly at a tangent to the linear segment with gradient of 12.92. However, the intersection point $\beta$ can be found by solving:

$$1.055\times\beta^{1\over{2.4}}-12.92\times\beta-0.055 = 0$$

This equation can give us a slightly more precise pair of values for the original sRGB equation:

\begin{align*} \beta &\approx 0.003130668 \\ \delta &\approx 0.040448236 \end{align*}

In practice this makes no measurable difference, but does suggest that the values of $\beta = 0.0031308$ in the sRGB specification may have been incorrectly rounded.

13.4. BT.1886 transfer functions

The BT.1886 standard for the “Reference electro-optical transfer function for flat panel displays used in HDTV studio production” is intended to represent a typical OETF for CRTs and to document this to ensure consistency between other display technologies:

$$L = a(\textrm{max}(V+b,0))^\gamma$$
 L = screen luminance in cd/m2 V = input signal normalized to [0..1] a = user gain (legacy “contrast”) b = black level lift (legacy “brightness”) $\gamma$ = 2.4

If LW is the screen luminance of maximum white and LB is the screen luminance of minimum black:

\begin{align*} L_B &= a \times b^\gamma \\ L_W &= a \times (1 + b)^\gamma \\ a &= (L_W^{1\over\gamma} - L_B^{1\over\gamma})^\gamma \\ b &= {{L_B^{1\over\gamma}}\over{L_W^{1\over\gamma} - L_B^{1\over\gamma}}} \end{align*}

ITU BT.2087 proposes the use of a simple power function with a $\gamma = 2.4$ as an approximation to this EOTF for the purposes of color conversion, effectively assuming b = 0 and LB is pure black. The reference display described in BT.1886 has a maximum luminance level of 100cd/m2 (brighter than the equivalent sRGB reference display).

The following graph shows the relationship between the BT.1886 EOTF (shown in red) and the ITU OETF such as used for BT.709 (shown in blue). The result of applying the two functions in turn, resulting in the OOTF of a combined BT.709-BT.1886 system, is shown in black. Since the ITU OETF approximates a power function with $\gamma=2.0$ , also shown in green is the resulting OOTF corresponding to a power function with $\gamma={2.4\over{2.0}}=1.2$ .

BT.1886 also offers an alternative EOTF which may provide a better match to CRT measured luminance than the standard formula listed above:

\begin{align*} L &= \begin{cases} k(V_C+b)^{(\alpha_1-\alpha_2)}(V+b)^{\alpha_2}, & V < V_C \\ k(V+b)^{\alpha_1}, & V_C \leq V \end{cases} \end{align*}
 VC = 0.35 $\alpha_1$ = 2.6 $\alpha_2$ = 3.0 k = coefficient of normalization (so that V = 1 gives white), $k=L_W(1+b)^{-\alpha_1}$ b = black level lift (legacy “brightness”)

13.5. BT.2100 HLG transfer functions

HLG (and PQ, below) are intended to allow a better encoding of high-dynamic-range content compared with the standard ITU OETF.

13.5.1. HLG OETF (normalized)

The BT.2100-1 Hybrid Log Gamma description defines the following OETF for linear scene light:

$$E'_\mathit{norm} = \textrm{OETF}(E) = \begin{cases} \sqrt{3E}, & 0 \leq E \leq {1\over{12}} \\ a \times \textrm{ln}((12\times E) - b) + c, & {1\over{12}} < E \leq 1 \end{cases}$$
 $E$ = the $R_S$ , $G_S$ or $B_S$ color component of linear scene light, normalized to [0..1] $E'$ = the resulting non-linear $R_S'$ , $G_S'$ or $B_S'$ non-linear scene light value in in the range [0..1] a = 0.17883277 b = $1 - 4\times a = 0.28466892$ c = $0.5 - a\times ln(4\times a) \approx 0.55991073$

BT.2100-0, in note 5b, defines these formulae equivalently, but slightly differently:

$$E'_\mathit{norm} = \textrm{OETF}(E) = \begin{cases} \sqrt{3E}, & 0 \leq E \leq {1\over{12}} \\ a \times \textrm{ln}(E - b_0) + c_0, & {1\over{12}} < E \leq 1 \end{cases}$$

This formulation in BT.2100-0 uses different constants for b and c (a is unmodified), as follows:

BT.2100-1 BT.2100-0

b

b1 = 0.28466892

b0 = 0.02372241

c

c1 = 0.55991073

c0 = 1.00429347

These variations can be derived from the BT.2100-1 numbers as:

\begin{align*} a \times \textrm{ln}((12 \times E) - b_1)+ c_1 & = a \times \textrm{ln}\left(12\times\left(E - {b_1\over{12}}\right)\right) + c_1\\ & = a \times \textrm{ln}\left(E - {{b_1}\over{12}}\right) + a\times\textrm{ln}(12) + c_1 \\ {{b_1}\over{12}} = {{0.28466892}\over{12}} &= 0.023772241 = b_0 \\ a\times\textrm{ln}(12) + c_1 = 0.17883277\times\textrm{ln}(12) + 0.55991073 &= 1.00429347 = c_0 \end{align*}

13.5.2. HLG OETF -1 (normalized)

The OETF -1 of normalized HLG is:

$$E = \textrm{OETF}^{-1}(E') = \begin{cases} {{E'^2}\over 3}, & 0 \leq E' \leq {1\over 2} \\ {1\over 12} \times \left({b + e^{(E'-c)/a}}\right), & {1\over 2} < E' \leq 1 \end{cases}$$

a, b and c are defined as for the normalized HLG OETF. BT.2100-0 again defines an equivalent formula without the $1\over{12}$ scale factor in the ${1\over 2}$  <  $E' \leq 1$ term, using the modified b0 and c0 constants described in the note in the HLG OETF above.

 BT.2100-1 (the current version at the time of writing) includes an apparent typographical error in its definition of the OETF -1, providing both the equation with E normalized to the range [0..1] and the (legacy) equation with E normalized to the range [0..12], without explanation.

13.5.3. Unnormalized HLG OETF

BT.2100-0 describes the HLG OETF formulae with E “normalized” to the range [0..12], with the variant with the range normalized to [0..1] as an alternative. Only the variant normalized to the range [0..1] is described in the updated version of the specification, BT.2100-1.

$$E' = \textrm{OETF}(E) = \begin{cases} {{\sqrt{E}}\over{2}}, & 0 \leq E \leq 1 \\ a \times \textrm{ln}(E-b) + c, & 1 < E \end{cases}$$
 $E'$ = the $R_S$ , $G_S$ or $B_S$ color component of linear scene light, normalized to [0..12] $E_S'$ = the resulting non-linear $R_S'$ , $G_S'$ or $B_S'$ value in in the range [0..1] a = 0.17883277 b = 0.28466892 c = 0.55991073

Note that these constants are the same as those used in the BT.2100-1 version of the normalized formulae.

13.5.4. Unnormalized HLG OETF -1

The OETF -1 of “unnormalized” HLG (producing E in the range [0..12]) is:

$$E = \textrm{OETF}^{-1}(E') = \begin{cases} 4\times E'^2, & 0 \leq E' \leq {1\over 2} \\ b + e^{(E'-c)/a}, & {1\over 2} < E' \end{cases}$$

a, b and c are defined as for the unnormalized HLG OETF.

BT.2100-0 describes this “unnormalized” version of the formulae, with the variant with the E normalized to [0..1] as an alternative. Only the variant with E normalized to [0..1] is described in the updated version, BT.2100-1.

13.5.5. Derivation of the HLG constants (informative)

HLG constants appear to have chosen a, b and c to meet the following constraints, which are easiest to express in terms of the unnormalized OETF -1:

• The derivative of the $0 \leq E' \leq {1\over 2}$ term of the unnormalized EOTF -1 has the same value as the derivative of the ${1\over 2}$  <  $E' \leq 1$ term of the unnormalized EOTF -1 at $E' = {1\over 2}$ :

\begin{align*} {{d(4\times E'^2)}\over{dE'}} = 8\times E' &= 8 \times {1\over 2} = 4 \textrm{ (derivative of the } 0 \leq E' \leq {1\over 2} \textrm{ case)}\\ {{d(e^{(E'-c)/a} + b)}\over{dE'}} &= {{d{(e^{E'/a}\times e^{-c/a} + b)}}\over{dE'}} \textrm{ (derivative of the } {1\over 2} < E' \textrm{ case)} \\ &= {{d((e^{E'}\times e^{-c})^{1/a} + b)}\over{dE'}} \\ &= {1\over a}\times\left(e^{E'}\times e^{-c}\right)^{(1/a) - 1}\times\left(e^{E'}\times e^{-c}\right)\\ & = {1\over a}\times\left(e^{E'}\times e^{-c}\right)^{1/a}\\ 4 &= {1\over a}\times\left(e^{0.5}\times e^{-c}\right)^{1/a} \textrm{at } E' = {1\over 2}\\ \implies (4\times a)^a &= e^{0.5}\times e^{-c}\\ \implies c &= -\textrm{ln}\left({{(4\times a)^a}\over{e^{0.5}}}\right)\\ &= 0.5 - a\times\textrm{ln}(4\times a) \end{align*}
• The $0 \leq E' \leq {1\over 2}$ term of the unnormalized EOTF -1 has the same value as the ${1\over 2}$  <  $E'\leq 1$ term of the unnormalized EOTF -1 at $E' = {1\over 2}$ :

\begin{align*} 4\times{E'}^2 &= e^{{E' - c}\over a} + b \textrm{ (from the }0 \leq E' \leq {1\over 2}\textrm{ and }{1\over 2} < E' \textrm{ cases})\\ 4\times{1\over 2}^2 = 1 &= e^{{0.5 - c}\over a} + b \textrm{ (at }E' = {1\over 2})\\ &= e^{{0.5 - 0.5 + a\times\textrm{ln}(4\times a)}\over a} + b \\ &= e^{\textrm{ln}(4\times a)} + b\\ b &= 1 - 4\times a \end{align*}
• At E' = 1, the ${1\over 2}$  <  $E'$ term of the unnormalized EOTF -1 = 12:

\begin{align*} 12 &= e^{{E'-c}\over a} + b\\ &= {e^{{1 - 0.5 + a\times\textrm{ln}(4\times a)}\over a} + 1 - 4\times a} \\ 11 + 4\times a &= e^{{0.5\over a} + \textrm{ln}(4\times a)} \\ 11 + 4\times a &= (4\times a)\times e^{0.5\over a} \\ {11\over{4\times a}} + 1 &= \sqrt{e^{1\over a}} \\ {121\over{16\times a^2}} + {11\over{2\times a}} + 1 &= e^{1\over a}\\ {121\over{16}} + {a\times 11\over 2} + a^2 \times (1 - e^{1\over a}) = 0 \end{align*}

This last equation can be solved numerically to find:

\begin{align*} a \approx 0.1788327726569497656312771 \end{align*}

With this precision, more accurate values of the other constants are:

\begin{align*} b &= 0.28466890937 \\ c &= 0.55991072776 \end{align*}

The b = 0.28466892 official figure assumes the rounded a = 0.17883277 value as an input to the b = $1 - 4\times a$ relation.

 No explanation for the choice of [0..12] range in the official version of the formula is explicitly offered in BT.2100-0 (it does not, for example, appear to relate to the BT.1886 OOTF $\gamma = 1.2$ combined with the $10\times$ ratio between the 1000cd/m2 of a standard HLG HDR TV and the 100cd/m2 of a standard dynamic range set). However, allowing for the difference in the maximum display brightness of HDR and SDR systems there is deliberate (scaled) compatibility between the HLG OETF and the BT.2020 OETF (which itself approximates a square root function) over much of the encodable dynamic range of a BT.2020 system. Since HDR content is intended to support accurate highlights more than to maintain a higher persistent screen brightness (many HDR displays can only support maximum brightness in a small area or over a small period without overheating), agreement over a significant chunk of the tone curve allows a simple adaptation between HDR and SDR devices: fed HLG-encoded content, an SDR display may represent darker tones accurately and simply under-represent highlights. The origins of both HLG and PQ are discussed in ITU-R BT.2390. As graphed in ITU-R BT.2390, the “unnormalized” HLG OETF (red) is a good approximation to the standard dynamic range ITU transfer function (blue, output scaled by 0.5) up to $E \approx 1$ and $\textrm{OETF}(E) = E' \approx 0.5$ , with a smooth curve up to the maximum HLG representable scene light value of “12”:

13.5.6. HLG OOTF

The OOTF of HLG is described as:

\begin{align*} R_D &= \alpha\times Y_S^{\gamma-1}\times R_S + \beta \\ G_D &= \alpha\times Y_S^{\gamma-1}\times G_S + \beta \\ B_D &= \alpha\times Y_S^{\gamma-1}\times B_S + \beta \\ \end{align*}

where RD, GD and BD describe the luminance of the displayed linear component in cd/m2 and RS, GS and BS describe each color component in scene linear light, scaled by camera exposure and normalized to the representable range.

 BT.2100 notes that some legacy displays apply the $\gamma$ function to each channel separately, rather than to the luminance component. That is, $\{R_D,G_D,B_D\}=\alpha\times\{R_S,G_S,B_S\}^\gamma+\beta$ . This is an approximation to the official OOTF.

YS is the normalized scene luminance, defined as:

$$Y_S = 0.2627\times R_S + 0.6780\times G_S + 0.0593\times B_S$$

$\beta$ represents the black level (display “brightness”):

$$\beta = L_B$$

$\alpha$ represents the black level (display “contrast”):

Scene light normalized to [0..1] Scene light normalized to [0..12]

$\alpha$

${L_W - L_B}$

${{L_W - L_B}\over{\left(12\right)^\gamma}}$

LW is the nominal peak luminance of the display in cd/m2, and LB is the display luminance of black in cd/m2.

 BT.2100-1 (the current version at the time of writing) includes an apparent typographical error in its definition of the OOTF, providing both the equation with scene light normalized to the range [0..1] and the (legacy) equation with scene light normalized to the range [0..12], without explanation.

$\gamma = 1.2$ for a nominal peak display luminance of 1000cd/m2. For displays with higher peak luminance or if peak luminance is reduced through a contrast control, $\gamma = 1.2 + 0.42\times \textrm{log}_{10}\left({L_W\over 1000}\right)$ .

For the purposes of general conversion, LW can be assumed to be 1000cd/m2, and LB can be approximated as 0, removing the constant offset from the above equations and meaning $\gamma=1.2$ .

13.5.7. HLG EOTF

The EOTF of BT.2100 HLG is defined in terms of the OETF and OOTF defined above:

\begin{align*} R_D &= \alpha\times Y_S^{\gamma-1}\times R_S + \beta \\ G_D &= \alpha\times Y_S^{\gamma-1}\times G_S + \beta \\ B_D &= \alpha\times Y_S^{\gamma-1}\times B_S + \beta \end{align*}
$$\{R_D,G_D,B_D\}=\textrm{OOTF}(\textrm{OETF}^{-1}(\{R_S',G_S',B_S'\}))$$

13.5.8. HLG OOTF -1

Using the formula from the OOTF leads to the following relationship between YD and YS:

\begin{align*} Y_D =& 0.2627\times R_D + 0.6780\times G_D + 0.0593\times B_D \\ =& 0.2627\times(\alpha\times Y_S^{\gamma-1}\times R_S + \beta) + 0.6780\times(\alpha\times Y_S^{\gamma-1}\times G_S + \beta) + 0.0593\times(\alpha\times Y_S^{\gamma-1}\times B_S + \beta) \\ =& \alpha\times Y_S^{\gamma-1}\times(0.2627\times R_S + 0.6780\times G_S + 0.0593\times B_S)+\beta \\ =& \alpha\times Y_S^{\gamma}+\beta \\ \therefore Y_S =& \left({{Y_D-\beta}\over\alpha}\right)^{1\over\gamma}\\ Y_S^{1-\gamma} =& \left({{Y_D-\beta}\over\alpha}\right)^{(1-\gamma)/\gamma} \end{align*}

From this, the following relations can be derived:

\begin{align*} R_S &= {(R_D - \beta)\over{\alpha\times Y_S^{\gamma-1}}} = Y_S^{1-\gamma}\times{{(R_D-\beta)}\over\alpha} = \left({{Y_D - \beta}\over\alpha}\right)^{(1-\gamma)/\gamma} \times \left({{R_D - \beta}\over{\alpha}}\right) \\ G_S &= {(G_D - \beta)\over{\alpha\times Y_S^{\gamma-1}}} = Y_S^{1-\gamma}\times{{(G_D-\beta)}\over\alpha} = \left({{Y_D - \beta}\over\alpha}\right)^{(1-\gamma)/\gamma} \times \left({{G_D - \beta}\over{\alpha}}\right) \\ B_S &= {(B_D - \beta)\over{\alpha\times Y_S^{\gamma-1}}} = Y_S^{1-\gamma}\times{{(B_D-\beta)}\over\alpha} = \left({{Y_D - \beta}\over\alpha}\right)^{(1-\gamma)/\gamma} \times \left({{B_D - \beta}\over{\alpha}}\right) \end{align*}

For processing without knowledge of the display, $\alpha$ can be treated as 1.0cd/m2 and $\beta$ can be considered to be 0.0cd/m2. This simplifies the equations as follows:

\begin{align*} Y_S &= Y_D^{1/\gamma} \\ Y_S^{1-\gamma} &= Y_D^{(1/\gamma)-1} \\ R_S&=Y_D^{(1/\gamma)-1}\times R_D \\ G_S&=Y_D^{(1/\gamma)-1}\times G_D \\ B_S&=Y_D^{(1/\gamma)-1}\times B_D \end{align*}

13.5.9. HLG EOTF -1

The EOTF -1 can be defined as:

$$\{R_S',G_S',B_S'\} = \textrm{OETF}(\textrm{OOTF}^{-1}(\{R_D,G_D,B_D\}))$$

13.6. BT.2100 PQ transfer functions

 Unlike BT.2100 HLG and other ITU broadcast standards, PQ is defined in terms of an EOTF (mapping from the encoded values to the display output), not an OETF (mapping from captured scene content to the encoded values).

13.6.1. PQ EOTF

The BT.2100 Perceptual Quantization description defines the following EOTF:

\begin{align*} F_D &= \textrm{EOTF}(E') = 10000\times Y \\ Y &= \left(\textrm{max}(({E'}^{1\over{m_2}} - c_1),0)\over{c_2 - c_3\times {E'}^{1\over{m_2}}}\right)^{1\over{m_1}} \end{align*}

$E'$ is a non-linear color channel $\{R',G',B'\}$ or $\{L',M',S'\}$ encoded as PQ in the range [0..1]. $F_D$ is the luminance of the displayed component in cd/m2 (where the luminance of an $\{R_D,G_D,B_D\}$ or $Y_D$ or $I_D$ component is considered to be the luminance of the color with all channels set to the same value as the component). When $R'=G'=B'$ the displayed pixel is monochromatic. $Y$ is a linear color value normalized to [0..1].

\begin{align*} m_1 &= {2610\over 16384} = 0.1593017578125 \\ m_2 &= {2523\over 4096} \times 128 = 78.84375 \\ c_1 &= {3424\over 4096} = 0.8359375 = c_3 - c_2 + 1 \\ c_2 &= {2413\over 4096} \times 32 = 18.8515625 \\ c_3 &= {2392\over 4096} \times 32 = 18.6875 \end{align*}

13.6.2. PQ EOTF -1

The corresponding EOTF -1 is:

\begin{align*} Y &= {F_D\over 10000} \\ \textrm{EOTF}^{-1}(F_D) &= \left({c_1 + c_2\times Y^{m_1}\over 1 + c_3\times Y^{m_1}}\right)^{m_2} \end{align*}

13.6.3. PQ OOTF

The OOTF of PQ matches that of BT.1886's EOTF combined with BT.709's OETF:

$$F_D = \textrm{OOTF}(E) = \textrm{G}_{1886}(\textrm{G}_{709}(E))$$

where E is one of $\{R_S,G_S,B_S,Y_S,I_S\}$ , the linear representation of scene light scaled by camera exposure and in the range [0..1], G1886 is the EOTF described in BT.1886, and G709 is the OETF described in BT.709 with a scale factor of 59.5208 applied to E:

\begin{align*} F_D &= \textrm{G}_{1886}(\textrm{G}_{709}(E)) &=\ &\textrm{G}_{1886}(E') = 100\times E'^{2.4} \\ E' &= \textrm{G}_{709}(E) &= &\begin{cases} 1.099\times(59.5208\times E)^{0.45} - 0.099, & 1 > E > 0.0003024 \\ 267.84\times E, & 0.0003024 \geq E \geq 0 \end{cases} \end{align*}
 ITU-R BT.2390 explains the derivation of the scale factor: PQ can encode 100 times the display brightness of a standard dynamic range (“SDR”) encoding (10000cd/m2 compared with the 100cd/m2 SDR reference display described in BT.1886). High dynamic range (HDR) displays are intended to represent the majority of scene content within a “standard” dynamic range, and exposure of a normalized SDR signal is chosen to provide suitable exposure. HDR displays offer extra capability for representation of small or transient highlights (few HDR displays can actually reach the maximum 10000cd/m2 encodable brightness, and few HDR displays can maintain their maximum intensity over a large area for an extended period without overheating). Therefore the behavior of HDR displays is intended to approximate a conventional standard dynamic range display for most of the image, while retaining the ability to encode extreme values. As described in BT.2390, the OOTF of SDR is roughly $\gamma = 1.2$ (deviating from this curve more near a 0 value), so the maximum scene light intensity that can be represented is roughly $100^{1\over 1.2} \approx 46.42$ times that of a SDR encoding. Using exact equations from BT.709 and BT.1886 to create the OOTF, rather than the $\gamma = 1.2$ approximation, the maximum representable scene brightness, if 1.0 is the maximum normalized SDR brightness is:\begin{align*} \left({100^{1\over 2.4} + 0.099\over 1.099}\right)^{1\over 0.45} &\approx 59.5208 \end{align*}The other constants in the G709 formula are derived as follows:\begin{align*} {0.018\over 59.5208} &\approx 0.0003024 \\ 4.5\times 59.5208 &\approx 267.84 \end{align*}Note that these constants differ slightly if the more accurate $\alpha = 1.0993$ figure from BT.2020 is used instead of 1.099.

13.6.4. PQ OETF

The OETF of PQ is described in terms of the above OOTF:

$$E' = \textrm{OETF}(E) = \textrm{EOTF}^{-1}(\textrm{OOTF}(E)) = \textrm{EOTF}^{-1}(F_D)$$

13.6.5. PQ OOTF -1

The PQ OOTF -1 is:

$$E=\textrm{OOTF}^{-1}(F_D)=\textrm{G}_{709}^{-1}(\textrm{G}_{1886}^{-1}(F_D))$$

where FD, display intensity, is one of $\{R_D,G_D,B_D,Y_D,I_D\}$ , and E is the corresponding normalized scene intensity.

\begin{align*} E' &= \textrm{G}_{1886}^{-1}(F_D) &= &\left({F_D\over 100}\right)^{1\over 2.4} \\ E &= \textrm{G}_{709}^{-1}(E') &= &\begin{cases} {\left({(E'+0.099)\over {1.099\times 59.5208^{0.45}}}\right)^{1\over 0.45}}, & E'>0.081\implies F_D>8.1^{2.4} \\ {E'\over{267.84}}, & 0.081\geq E'\geq 0 \implies {8.1}^{2.4}\geq F_D\geq 0 \end{cases} \end{align*}

13.6.6. PQ OETF -1

The PQ OETF -1 is described in terms of the OOTF -1:

$$E = \textrm{OETF}^{-1}(E') = \textrm{OOTF}^{-1}(\textrm{EOTF}(E')) = \textrm{OOTF}^{-1}(F_D)$$

13.7. DCI P3 transfer functions

DCI P3 defines a simple power function with an exponent of 2.6 (applied to scaled CIE XYZ values).

That is:

\begin{align*} X' &= \left({X\over{52.37}}\right)^{1\over{2.6}}\\ Y' &= \left({Y\over{52.37}}\right)^{1\over{2.6}}\\ Z' &= \left({Z\over{52.37}}\right)^{1\over{2.6}}\\ X &= X'^{2.6}\times 52.37\\ Y &= Y'^{2.6}\times 52.37\\ Z &= Z'^{2.6}\times 52.37\\ \end{align*}

This power function is applied directly to scaled CIE XYZ color coordinates: the “primaries” in DCI define the bounds of the gamut, but the actual color encoding uses XYZ coordinates. DCI scales the resulting non-linear values to the range [0..4095] prior to quantization, rounding to nearest.

 “Display P3” uses the sRGB transfer function, modified in some implementations to have more accurate constants (see the section on the derivation of the sRGB constants).

13.8. Legacy NTSC transfer functions

ITU-R BT.470-6, which has now been deprecated, lists a number of regional TV standard variants; an updated list of variant codes used by country is defined in ITU-R BT.2043. This standard, along with e-CFR title 47 section 73.682, documents a simple EOTF power function with $\gamma = 2.2$ for NTSC display devices.

\begin{align*} R' &= R^{1\over{2.2}} \\ G' &= G^{1\over{2.2}} \\ B' &= B^{1\over{2.2}} \\ R &= R'^{2.2} \\ G &= G'^{2.2} \\ B &= B'^{2.2} \end{align*}

This value of $\gamma$ is also used for N/PAL signals in the Eastern Republic of Uruguay, and was also adopted by ST-240.

Combined with the reference in SMPTE 170M to a $\gamma = 2.2$ being used in “older documents”, this suggests a linear design OOTF for NTSC systems.

ITU-R BT.1700, which partly replaced BT.470, also describes an “assumed gamma of display device” of 2.2 for PAL and SECAM systems; this is distinct from the $\gamma = 2.8$ value listed in ITU-R BT.470-6. Combined with the ITU OETF which approximates $\gamma = {1\over{2.0}}$ , the PAL OOTF retains a $\gamma \approx 1.1$ when this value of $\gamma = 2.2$ is used for the EOTF, similar to the figure described under the legacy PAL EOTF.

In contrast, ITU-R BT.1700 also includes SMPTE 170m, which defines the assumed EOTF of the display device as being the inverse of the current ITU OETF. Hence the new NTSC formulation also assumes a linear OOTF.

13.9. Legacy PAL OETF

ITU-R BT.472, “Video-frequency characteristics of a television system to be used for the international exchange of programmes between countries that have adopted 625-line colour or monochrome systems”, defines that the “gamma of the picture signal” should be “approximately 0.4”. The reciprocal of this value is 2.5.

That is, this standard defines an approximate OETF and OETF -1 for PAL content:

\begin{align*} R' &\approx R^{0.4} \\ G' &\approx G^{0.4} \\ B' &\approx B^{0.4} \\ R &\approx R'^{2.5} \\ G &\approx G'^{2.5} \\ B &\approx B'^{2.5} \end{align*}

13.10. Legacy PAL 625-line EOTF

ITU-R BT.470-6, which has now been deprecated in favor of BT.1700, lists a number of regional TV standard variants; an updated list of variant codes used by country is defined in ITU-R BT.2043.

This specification describes a simple EOTF power function with $\gamma_{\textrm{EOTF}} = 2.8$ for most PAL and SECAM display devices:

\begin{align*} R' &\approx R^{1\over{2.8}} \\ G' &\approx G^{1\over{2.8}} \\ B' &\approx B^{1\over{2.8}} \\ R &\approx R'^{2.8} \\ G &\approx G'^{2.8} \\ B &\approx B'^{2.8} \end{align*}
 Poynton describes a $\gamma$ of 2.8 as being “unrealistically high” for actual CRT devices.

Combined with the corresponding legacy EOTF with $\gamma_{\textrm{EOTF}} = 0.4$ , the described system OOTF is:

\begin{align*} R_{display} &\approx R_{scene}^{2.8\over{2.5}}\\ G_{display} &\approx G_{scene}^{2.8\over{2.5}}\\ B_{display} &\approx B_{scene}^{2.8\over{2.5}} \end{align*}

Or $\gamma_{\textrm{OOTF}} \approx 1.12$ .

The value of $\gamma_{\textrm{EOTF}} = 2.8$ is described in BT.470-6 as being chosen for “an overall system gamma” (OOTF power function exponent) of “approximately 1.2”; this suggests that the “approximately 0.4” exponent in BT.472-6 should be interpreted as nearer to ${1.2\over{2.8}} \approx 0.43$ , or at least that there was enough variation in early devices for precise formulae to be considered irrelevant.

 The EOTF power function of $\gamma_{\textrm{EOTF}} = 2.2$ described in BT.1700 combines with the ITU OETF described in BT.601 (which approximates $\gamma_{\textrm{OETF}} \approx 0.5$ ) to give a similar system $\gamma_{\textrm{OOTF}} \approx 1.1$ . As described above, the ITU OETF combined with the BT.1886 EOTF results in a more strongly non-linear $\gamma_{\textrm{OOTF}} \approx {2.4\over{2.0}} = 1.2$ .

13.11. ST240/SMPTE240M transfer functions

The ST-240, formerly SMPTE240M, interim standard for HDTV defines the following OETF:

$$R' = \begin{cases} R \times 4, & 0 \leq R < 0.0228 \\ 1.1115 \times R^{0.45} - 0.1115, & 1 \geq R \geq 0.0228 \end{cases}$$ $$G' = \begin{cases} G \times 4, & 0 \leq G < 0.0228 \\ 1.1115 \times G^{0.45} - 0.1115, & 1 \geq G \geq 0.0228 \end{cases}$$ $$B' = \begin{cases} B \times 4, & 0 \leq B < 0.0228 \\ 1.1115 \times B^{0.45} - 0.1115, & 1 \geq B \geq 0.0228 \end{cases}$$

Like SMPTE170m, ST-240 defines a linear OOTF. Therefore the above relationship also holds for the EOTF -1.

The EOTF, and also OETF -1, is:

$$R = \begin{cases} {R' \over 4}, & 0 \leq R < 0.0913 \\ \left({R' + 0.1115\over 1.1115}\right)^{1\over 0.45} - 0.1115, & 1 \geq R' \geq 0.0228 \end{cases}$$ $$G = \begin{cases} {G' \over 4}, & 0 \leq R < 0.0913 \\ \left({G' + 0.1115\over 1.1115}\right)^{1\over 0.45} - 0.1115, & 1 \geq G' \geq 0.0228 \end{cases}$$ $$B = \begin{cases} {B' \over 4}, & 0 \leq R < 0.0913 \\ \left({B' + 0.1115\over 1.1115}\right)^{1\over 0.45} - 0.1115, & 1 \geq B' \geq 0.0228 \end{cases}$$

13.12. Adobe RGB (1998) transfer functions

The Adobe RGB (1998) specification defines the following transfer function (notable for not including a linear component):

\begin{align*} R &= R'^{2.19921875} \\ G &= G'^{2.19921875} \\ B &= B'^{2.19921875} \end{align*}

2.19921875 is obtained from $2{51\over{256}}$ or hexadecimal 2.33. Therefore the inverse transfer function is:

\begin{align*} R' &= R^{256\over{563}} \\ G' &= G^{256\over{563}} \\ B' &= B^{256\over{563}} \end{align*}

13.13. Sony S-Log transfer functions

The Sony S-Log OETF is defined for each color channel as:

$$y = (0.432699 \times \textrm{log}_{10}(t + 0.037584) + 0.616596) + 0.03$$

Linear camera input scaled by exposure t ranges from 0 to 10.0; y is the non-linear encoded value.

The OETF -1 is:

$$Y = 10.0^{t - 0.616596 - 0.03\over 0.432699} - 0.037584$$

The encoded non-linear value t ranges from 0 to 1.09; Y is the linear scene light.

13.14. Sony S-Log2 transfer functions

S-Log2 defines the following OETF:

\begin{align*} y &= \begin{cases} (0.432699\times\textrm{log}_{10}\left({155.0\times x\over 219.0} + 0.037584\right) + 0.616596 + 0.03, &x \geq 0 \\ x \times 3.53881278538813 + 0.030001222851889303, &x < 0 \end{cases} \end{align*}

x is the IRE in scene-linear space. y is the IRE in S-Log2 space.

The OETF -1 is:

\begin{align*} y &= \begin{cases} {219.0 \times 10.0^{x - 0.616596 - 0.03\over 0.432699}\over 155.0}, &x \geq 0.030001222851889303 \\ {x - 0.030001222851889303\over 3.53881278538813}, &x < 0.030001222851889303 \end{cases} \end{align*}

x is the IRE in S-Log2 space. y is the IRE in scene-linear space.

A reflection is calculated by multiplying an IRE by 0.9.

13.15. ACEScc transfer function

ACES is scene-referred; therefore ACEScc defines an OETF.

For each linear color channel linAP1 transformed to the ACEScc primaries, the ACEScc non-linear encoding is:

$$ACEScc = \begin{cases} {{\textrm{log}_\textrm{2}(2^{-16})+9.72}\over{17.52}}, & lin_{AP1} \leq 0 \\ {{\textrm{log}_\textrm{2}(2^{-16} + lin_{AP1}\times 0.5) + 9.72}\over{17.52}}, & lin_{AP1} < 2^{-15} \\ {{\textrm{log}_\textrm{2}(lin_{AP1})+9.72}\over{17.52}}, & lin_{AP1} \geq 2^{-15} \end{cases}$$

13.16. ACEScct transfer function

ACES is scene-referred; therefore ACEScct defines an OETF.

For each linear color channel linAP1 transformed to the ACEScc primaries, the ACEScct non-linear encoding is:

$$ACEScct = \begin{cases} {10.5402377416545 \times lin_{AP1} + 0.0729055341958355}, & lin_{AP1} \leq 0.0078125 \\ {{\textrm{log}_2(lin_{AP1})+9.72}\over{17.52}}, & lin_{AP1} > 0.0078125 \end{cases}$$

14. Color primaries

Color primaries define the interpretation of each color channel of the color model, particularly with respect to the RGB color model. In the context of a typical display, color primaries describe the color of the red, green and blue phosphors or filters.

Primaries are typically defined using the CIE 1931 XYZ color space, which is a color space which preserves the linearity of light intensity. Consequently, the transform from linear-intensity (R, G, B) to (X, Y, Z) is a simple matrix multiplication. Conversion between two sets of (R, G, B) color primaries can be performed by converting to the (X, Y, Z) space and back.

The (X, Y, Z) space describes absolute intensity. Since most standards do not make a requirement about the absolute intensity of the display, color primaries are typically defined using the x and y components of the xyY color space, in which the Y channel represents linear luminance. xyY is related to XYZ via the following formulae:

\begin{align*} x & = {X\over{X + Y + Z}} &&&y & = {Y\over{X + Y + Z}} &&&z & = {Z\over{X + Y + Z}} = 1 - x - y\\ &&X & = {Y\over{y}}x &&&Z & = {Y\over{y}}(1-x-y) \end{align*}

This is relevant because, although the brightness of the display in a color space definition is typically undefined, the white point is known: the x and y coordinates in xyY color space which corresponds to equal amounts of R, G and B. This makes it possible to determine the relative intensities of these color primaries.

 Many color standards use the CIE D65 standard illuminant as a white point. D65 is intended to represent average daylight, and has a color temperature of approximately 6500K. In CIE 1931 terms, this white point is defined in ITU standards as $x=0.3127,\ y=0.3290$ , but elsewhere given as $x=0.312713,\ y=0.329016$ . Different coordinates will affect the conversion matrices given below. The definition of the D65 white point is complicated by the constants in Planck’s Law (which is a component in calculating the white point from the color temperature) having been revised since D65 was standardized, such that the standard formula for calculating CIE coordinates from the color temperature do not agree with the D65 standard. The actual color temperature of D65 is nearer to $6500\times {1.4388\over 1.438} \approx 6503.6\textrm{K}$ .

Assuming an arbitrary white luminance (Y value) of 1.0, it is possible to express the following identity for the X, Y and Z coordinates of each color channel R, G and B, and of the white point W:

\begin{align*} W_X &= R_X + G_X + B_X &W_Y &= R_Y + G_Y + B_Y = 1.0 &W_Z &= R_Z + G_Z + B_Z \end{align*}

The identities $X = Y{x\over{y}}$ and $Z = Y{{(1-x-y)}\over{y}}$ can be used to re-express the above terms in the xyY space:

\begin{align*} R_Y\left({R_x\over{R_y}}\right) + G_Y\left({G_x\over{G_y}}\right) + B_Y\left({B_x\over{B_y}}\right) & = W_Y\left({W_x\over{W_y}}\right) = {W_x\over{W_y}} \\ R_Y + G_Y + B_Y & = W_Y = 1.0 \\ R_Y\left({1-R_x-R_y\over{R_y}}\right) + G_Y\left({1-G_x-G_y\over{G_y}}\right) + B_Y\left({1-B_x-B_y\over{B_y}}\right) & = W_Y\left({1-W_x-W_y\over{W_y}}\right) = {1-W_x-W_y\over{W_y}} \end{align*}

This equation for WZ can be simplified to:

\begin{align*} R_Y\left({1-R_x\over{R_y}}-1\right) + G_Y\left({1-G_x\over{G_y}}-1\right) + B_Y\left({1-B_x\over{B_y}}-1\right) & = W_Y\left({1-W_x\over{W_y}}-1\right) = {1-W_x\over{W_y}}-1 \end{align*}

Since $R_Y + G_Y + B_Y = W_Y = 1$ , this further simplifies to:

\begin{align*} R_Y\left({1-R_x\over{R_y}}\right) + G_Y\left({1-G_x\over{G_y}}\right) + B_Y\left({1-B_x\over{B_y}}\right) & = {1-W_x\over{W_y}} \end{align*}

The $R_Y+G_Y+B_Y$ term for WY can be multiplied by $R_x\over{R_y}$ and subtracted from the equation for WX:

$$G_Y\left({G_x\over{G_y}}-{R_x\over{R_y}}\right) + B_Y\left({B_x\over{B_y}}-{R_x\over{R_y}}\right) = {W_x\over{W_y}}-{R_x\over{R_y}}$$

Similarly, the $R_Y+G_Y+B_Y$ term can be multiplied by $1-R_x\over{R_y}$ and subtracted from the simplified WZ line:

$$G_Y\left({1-G_x\over{G_y}}-{1-R_x\over{R_y}}\right) + B_Y\left({1-B_x\over{B_y}}-{1-R_x\over{R_y}}\right) = {1-W_x\over{W_y}}-{1-R_x\over{R_y}}$$

Finally, the GY term can be eliminated by multiplying the former of these two equations by ${1-G_x\over{G_y}}-{1-R_x\over{R_y}}$ and subtracting it from the latter multiplied by ${G_x\over{G_y}}-{R_x\over{R_y}}$ , giving:

$$B_Y\left(\left({1-B_x\over{B_y}}-{1-R_x\over{R_y}}\right) \left({G_x\over{G_y}}-{R_x\over{R_y}}\right) - \left({B_x\over{B_y}}-{R_x\over{R_y}}\right) \left({1-G_x\over{G_y}}-{1-R_x\over{R_y}}\right)\right)$$ $$= \left({1-W_x\over{W_y}}-{1-R_x\over{R_y}}\right) \left({G_x\over{G_y}}-{R_x\over{R_y}}\right) - \left({W_x\over{W_y}}-{R_x\over{R_y}}\right) \left({1-G_x\over{G_y}}-{1-R_x\over{R_y}}\right)$$

Thus:

$$B_Y = {{\left({1-W_x\over{W_y}}-{1-R_x\over{R_y}}\right) \left({G_x\over{G_y}}-{R_x\over{R_y}}\right) - \left({W_x\over{W_y}}-{R_x\over{R_y}}\right) \left({1-G_x\over{G_y}}-{1-R_x\over{R_y}}\right)} \over{\left({1-B_x\over{B_y}}-{1-R_x\over{R_y}}\right) \left({G_x\over{G_y}}-{R_x\over{R_y}}\right) - \left({B_x\over{B_y}}-{R_x\over{R_y}}\right) \left({1-G_x\over{G_y}}-{1-R_x\over{R_y}}\right)}}$$

This allows GY to be calculated by rearranging an earlier equation:

$$G_Y = {{W_x\over{W_y}}-{R_x\over{R_y}} -B_Y\left({B_x\over{B_y}}-{R_x\over{R_y}}\right) \over{{G_x\over{G_y}}-{R_x\over{R_y}}}}$$

And finally:

$$R_Y = 1 - G_Y - B_Y$$

These relative magnitudes allow the definition of vectors representing the color primaries in the XYZ space, which in turn provides a transformation between colors specified in terms of the color primaries and the XYZ space. Without an absolute magnitude the transformation to XYZ is incomplete, but sufficient to allow transformation to another set of color primaries.

The transform from the defined color primaries to XYZ space is:

$$\left(\begin{array}{c}X\\ Y\\ Z\end{array}\right) = \left(\begin{array}{ccc}R_X, & G_X, & B_X \\ R_Y, & G_Y, & B_Y \\ R_Z, & G_Z, & B_Z\end{array}\right) \left(\begin{array}{c}R \\ G \\ B\end{array}\right) = \left(\begin{array}{ccc}{R_Y\over{R_y}}R_x, & {G_Y\over{G_y}}G_x, & {B_Y\over{B_y}}B_x \\ R_Y, & G_Y, & B_Y \\ {R_Y\over{R_y}}(1-R_x-R_y), & {G_Y\over{G_y}}(1-G_x-G_y), & {B_Y\over{B_y}}(1-B_x-B_y) \end{array}\right)\left(\begin{array}{c}R\\ G\\ B\end{array}\right)$$

The transform from XYZ space to the defined color primaries is therefore:

$$\left(\begin{array}{c}R\\ G\\ B\end{array}\right) = \left(\begin{array}{ccc}R_X, & G_X, & B_X \\ R_Y, & G_Y, & B_Y \\ R_Z, & G_Z, & B_Z\end{array}\right)^{-1} \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) = \left(\begin{array}{ccc}{R_Y\over{R_y}}R_x, & {G_Y\over{G_y}}G_x, & {B_Y\over{B_y}}B_x \\ R_Y, & G_Y, & B_Y \\ {R_Y\over{R_y}}(1-R_x-R_y), & {G_Y\over{G_y}}(1-G_x-G_y), & {B_Y\over{B_y}}(1-B_x-B_y) \end{array}\right)^{-1}\left(\begin{array}{c}X\\ Y\\ Z\end{array}\right)$$
 These transforms assume that the black point for the color space is at $(X, Y, Z) = (0, 0, 0)$ . If the black point is non-zero, these transforms require a translational component. In some color spaces the black point has the same color as the white point, in which case it is also possible to adjust the $(R, G, B)$ values outside the matrix.

14.1. BT.709 color primaries

ITU-T BT.709 (HDTV) defines the following chromaticity coordinates:

\begin{align*} R_x &= 0.640 & R_y &= 0.330 \\ G_x &= 0.300 & G_y &= 0.600 \\ B_x &= 0.150 & B_y &= 0.060 \\ W_x &= 0.3127 & W_y &= 0.3290\ (\textrm{D}65) \end{align*}

These chromaticity coordinates are also shared by sRGB and scRGB.

Therefore to convert from linear color values defined in terms of BT.709 color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.412391, & 0.357584, & 0.180481 \\ 0.212639, & 0.715169, & 0.072192 \\ 0.019331, & 0.119195, & 0.950532\end{array}\right) \left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of BT.709 color primaries, is:

$$\left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right) \approx \left(\begin{array}{ccc} 3.240970, & -1.537383, & -0.498611 \\ -0.969244, & 1.875968, & 0.041555 \\ 0.055630, & -0.203977, & 1.056972\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$
 sYCC lists a slightly different version of this matrix, possibly due to rounding errors.

14.2. BT.601 625-line color primaries

ITU-T Rec.601 defines different color primaries for 625-line systems (as used in most PAL systems) and for 525-line systems (as used in the SMPTE 170M-2004 standard for NTSC).

The following chromaticity coordinates are defined for 625-line “EBU” systems:

\begin{align*} R_x &= 0.640 & R_y &= 0.330 \\ G_x &= 0.290 & G_y &= 0.600 \\ B_x &= 0.150 & B_y &= 0.060 \\ W_x &= 0.3127 & W_y &= 0.3290 \end{align*}
 BT.470-6, which also describes these constants in a legacy context, approximates D65 as $x = 0.313,\ y = 0.329$ .

Therefore to convert from linear color values defined in terms of BT.601 color primaries for 625-line systems to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.430554, & 0.341550, & 0.178352 \\ 0.222004, & 0.706655, & 0.071341 \\ 0.020182, & 0.129553, & 0.939322\end{array}\right) \left(\begin{array}{c} R_{601\textrm{EBU}} \\ G_{601\textrm{EBU}} \\ B_{601\textrm{EBU}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of BT.601 “EBU” 625-line color primaries, is:

$$\left(\begin{array}{c} R_{601\textrm{EBU}} \\ G_{601\textrm{EBU}} \\ B_{601\textrm{EBU}}\end{array}\right) \approx \left(\begin{array}{ccc} 3.063361, & -1.393390, & -0.475824 \\ -0.969244, & 1.875968, & 0.041555 \\ 0.067861, & -0.228799, & 1.069090\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

14.3. BT.601 525-line color primaries

ITU-T Rec.601 defines different color primaries for 625-line systems (as used in most PAL systems) and for 525-line systems (as used in the SMPTE 170M-2004 standard for NTSC).

The following chromaticity coordinates are defined in BT.601 for 525-line digital systems and in SMPTE-170M:

\begin{align*} R_x &= 0.630 & R_y &= 0.340 \\ G_x &= 0.310 & G_y &= 0.595 \\ B_x &= 0.155 & B_y &= 0.070 \\ W_x &= 0.3127 & W_y &= 0.3290 \end{align*}

Therefore to convert from linear color values defined in terms of BT.601 color primaries for 525-line systems to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.393521, & 0.365258, & 0.191677 \\ 0.212376, & 0.701060, & 0.086564 \\ 0.018739, & 0.111934, & 0.958385\end{array}\right) \left(\begin{array}{c} R_{601\textrm{SMPTE}} \\ G_{601\textrm{SMPTE}} \\ B_{601\textrm{SMPTE}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of BT.601 525-line color primaries, is:

$$\left(\begin{array}{c} R_{601\textrm{SMPTE}} \\ G_{601\textrm{SMPTE}} \\ B_{601\textrm{SMPTE}}\end{array}\right) \approx \left(\begin{array}{ccc} 3.506003, & -1.739791, & -0.544058 \\ -1.069048, & 1.977779, & 0.035171 \\ 0.056307, & -0.196976, & 1.049952\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$
 Analog 525-line PAL systems used a different white point, and therefore have a different conversion matrix.

14.4. BT.2020 color primaries

The following chromaticity coordinates are defined in BT.2020 for ultra-high-definition television:

\begin{align*} R_x &= 0.708 & R_y &= 0.292 \\ G_x &= 0.170 & G_y &= 0.797 \\ B_x &= 0.131 & B_y &= 0.046 \\ W_x &= 0.3127 & W_y &= 0.3290 \end{align*}

The same primaries are used for BT.2100 for HDR TV.

Therefore to convert from linear color values defined in terms of BT.2020 color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.636958, & 0.144617, & 0.168881 \\ 0.262700, & 0.677998, & 0.059302 \\ 0.000000, & 0.028073, & 1.060985\end{array}\right) \left(\begin{array}{c} R_{2020} \\ G_{2020} \\ B_{2020}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of BT.2020 color primaries, is:

$$\left(\begin{array}{c} R_{2020} \\ G_{2020} \\ B_{2020}\end{array}\right) \approx \left(\begin{array}{ccc} 1.716651, & -0.355671, & -0.253366 \\ -0.666684, & 1.616481, & 0.015769 \\ 0.017640, & -0.042771, & 0.942103\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

14.5. NTSC 1953 color primaries

The following chromaticity coordinates are defined in ITU-R BT.470-6 and SMPTE 170m as a reference to the legacy NTSC standard:

\begin{align*} R_x &= 0.67 & R_y &= 0.33 \\ G_x &= 0.21 & G_y &= 0.71 \\ B_x &= 0.14 & B_y &= 0.08 \\ W_x &= 0.310 & W_y &= 0.316\ (\textrm{Illuminant C}) \end{align*}
 These primaries apply to the 1953 revision of the NTSC standard. Modern NTSC systems, which reflect displays that are optimized for brightness over saturation, use the color primaries as described in Section 14.3. The white point used in the original NTSC 1953 specification is CIE Standard Illuminant C, 6774K, as distinct from the CIE Illuminant D65 white point used by most modern standards. BT.470-6 notes that SECAM systems may use these NTSC primaries and white point. Japanese legacy NTSC systems used the same primaries but with the white point set to D-white at 9300K.

Therefore to convert from linear color values defined in terms of NTSC 1953 color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.606993, & 0.173449, & 0.200571 \\ 0.298967, & 0.586421, & 0.114612 \\ 0.000000, & 0.066076, & 1.117469\end{array}\right) \left(\begin{array}{c} R_{\textrm{NTSC}} \\ G_{\textrm{NTSC}} \\ B_{\textrm{NTSC}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of NTSC 1953 color primaries, is:

$$\left(\begin{array}{c} R_{\textrm{NTSC}} \\ G_{\textrm{NTSC}} \\ B_{\textrm{NTSC}}\end{array}\right) \approx \left(\begin{array}{ccc} 1.909675, & -0.532365, & -0.288161 \\ -0.984965, & 1.999777, & -0.028317 \\ 0.058241, & -0.118246, & 0.896554\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

14.6. PAL 525-line analog color primaries

ITU-R BT.1700 defines the following chromaticity coordinates for legacy 525-line PAL systems:

\begin{align*} R_x &= 0.630 & R_y &= 0.340 \\ G_x &= 0.310 & G_y &= 0.595 \\ B_x &= 0.155 & B_y &= 0.070 \\ W_x &= 0.3101 & W_y &= 0.3162\ (\textrm{Illuminant C}) \end{align*}
 This matches the color primaries from SMPTE-170m analog NTSC and BT.601 525-line encoding, but the white point used is CIE Standard Illuminant C, 6774K, as distinct from the CIE Illuminant D65 white point used by most modern standards.

Therefore to convert from linear color values defined in terms of PAL 525-line color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.415394, & 0.354637, & 0.210677 \\ 0.224181, & 0.680675, & 0.095145 \\ 0.019781, & 0.108679, & 1.053387\end{array}\right) \left(\begin{array}{c} R_{\textrm{PAL525}} \\ G_{\textrm{PAL525}} \\ B_{\textrm{PAL525}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of PAL 525-line 1953 color primaries, is:

$$\left(\begin{array}{c} R_{\textrm{PAL525}} \\ G_{\textrm{PAL525}} \\ B_{\textrm{PAL525}}\end{array}\right) \approx \left(\begin{array}{ccc} 3.321392, & -1.648181, & -0.515410 \\ -1.101064, & 2.037011, & 0.036225 \\ 0.051228, & -0.179211, & 0.955260\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

14.7. ACES color primaries

The following chromaticity coordinates are defined in SMPTE ST 2065-1

\begin{align*} R_x &= 0.73470 & R_y &= 0.26530 \\ G_x &= 0.0 & G_y &= 1.0 \\ B_x &= 0.00010 & B_y &= -0.0770 \\ W_x &= 0.32168 & W_y &= 0.33767 \end{align*}

Therefore to convert from linear color values defined in terms of ACES color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.9525523959, & 0.0, & 0.0000936786 \\ 0.3439664498, & 0.7281660966, & -0.0721325464 \\ 0.0, & 0.0, & 1.0088251844\end{array}\right) \left(\begin{array}{c} R_{\textrm{ACES}} \\ G_{\textrm{ACES}} \\ B_{\textrm{ACES}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of ACES color primaries, is:

$$\left(\begin{array}{c} R_{\textrm{ACES}} \\ G_{\textrm{ACES}} \\ B_{\textrm{ACES}}\end{array}\right) \approx \left(\begin{array}{ccc} 1.0498110175, & 0.0, & -0.0000974845 \\ -0.4959030231, & 1.3733130458, & 0.0982400361 \\ 0.0, & 0.0, & 0.9912520182\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

14.8. ACEScc color primaries

The following chromaticity coordinates are defined in Academy S-2016-001 (ACEScct) and S-2014-003 (ACEScc), which share the same primaries:

\begin{align*} R_x &= 0.713 & R_y &= 0.293 \\ G_x &= 0.165 & G_y &= 0.830 \\ B_x &= 0.128 & B_y &= 0.044 \\ W_x &= 0.32168 & W_y &= 0.33767 \end{align*}

Therefore to convert from linear color values defined in terms of ACEScc/ACEScct color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.6624541811, & 0.1340042065, & 0.1561876870 \\ 0.2722287168, & 0.6740817658, & 0.0536895174 \\ -0.0055746495, & 0.0040607335, & 1.0103391003\end{array}\right) \left(\begin{array}{c} R_{\textrm{ACEScct}} \\ G_{\textrm{ACEScct}} \\ B_{\textrm{ACEScct}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of ACEScc/ACEScct color primaries, is:

$$\left(\begin{array}{c} R_{\textrm{ACEScc}} \\ G_{\textrm{ACEScc}} \\ B_{\textrm{ACEScc}}\end{array}\right) \approx \left(\begin{array}{ccc} 1.6410233797, & -0.3248032942, & -0.2364246952 \\ -0.6636628587, & 1.6153315917, & 0.0167563477 \\ 0.0117218943, & -0.0082844420, & 0.9883948585\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

14.9. Display P3 color primaries

The following chromaticity coordinates are defined in Display P3:

\begin{align*} R_x &= 0.6800 & R_y &= 0.3200 \\ G_x &= 0.2650 & G_y &= 0.6900 \\ B_x &= 0.1500 & B_y &= 0.0600 \\ W_x &= 0.3127 & W_y &= 0.3290 \end{align*}
 The DCI P3 color space defines the bounds of its gamut using these primaries, but actual color data in DCI P3 is encoded using CIE XYZ coordinates. Display P3, on the other hand, uses these values as primaries in an RGB color space, with a D65 white point.

Therefore to convert from linear color values defined in terms of Display P3 color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.4865709486, & 0.2656676932, & 0.1982172852 \\ 0.2289745641, & 0.6917385218, & 0.0792869141 \\ 0.0000000000, & 0.0451133819, & 1.0439443689\end{array}\right) = \left(\begin{array}{c} R_{\textrm{DisplayP3}} \\ G_{\textrm{DisplayP3}} \\ B_{\textrm{DisplayP3}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of DisplayP3 color primaries, is:

$$\left(\begin{array}{c} R_{\textrm{DisplayP3}} \\ G_{\textrm{DisplayP3}} \\ B_{\textrm{DisplayP3}}\end{array}\right) \approx \left(\begin{array}{ccc} 2.4934969119, & -0.9313836179, & -0.4027107845 \\ -0.8294889696, & 1.7626640603, & 0.0236246858 \\ 0.0358458302, & -0.0761723893, & 0.9568845240\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$
 These matrices differ from those given in SMPTE EG 432-1 due to the choice of a D65 white point in Display P3. The matrices in 432-1 can be reproduced by applying a white point of $W_x = 0.314,\ W_y = 0.351$ to the above primaries.

14.10. Adobe RGB (1998) color primaries

The following chromaticity coordinates are defined in Adobe RGB (1998):

\begin{align*} R_x &= 0.6400 & R_y &= 0.3300 \\ G_x &= 0.2100 & G_y &= 0.7100 \\ B_x &= 0.1500 & B_y &= 0.0600 \\ W_x &= 0.3127 & W_y &= 0.3290 \end{align*}

Therefore to convert from linear color values defined in terms of Adobe RGB (1998) color primaries to XYZ space the formulae in Section 14 result in the following matrix:

$$\left(\begin{array}{c}X \\ Y \\ Z\end{array}\right) \approx \left(\begin{array}{ccc} 0.5766690429, & 0.1855582379, & 0.1882286462 \\ 0.2973449753, & 0.6273635663, & 0.0752914585 \\ 0.0270313614, & 0.0706888525, & 0.9913375368\end{array}\right) = \left(\begin{array}{c} R_{\textrm{AdobeRGB}} \\ G_{\textrm{AdobeRGB}} \\ B_{\textrm{AdobeRGB}}\end{array}\right)$$

The inverse transformation, from the XYZ space to a color defined in terms of Adobe RGB (1998) color primaries, is:

$$\left(\begin{array}{c} R_{\textrm{AdobeRGB}} \\ G_{\textrm{AdobeRGB}} \\ B_{\textrm{AdobeRGB}}\end{array}\right) \approx \left(\begin{array}{ccc} 2.0415879038, & -0.5650069743, & -0.3447313508 \\ -0.9692436363, & 1.8759675015, & 0.0415550574 \\ 0.0134442806, & -0.1183623922, & 1.0151749944\end{array}\right) \left(\begin{array}{c}X \\ Y \\ Z\end{array}\right)$$

Adobe RGB (1998) defines a reference display white brightness of 160cd/m2 and a black point 0.34731% of this brightness, or 0.5557cd/m2, for a contrast ratio of 287.9. The black point has the same color temperature as the white point, and this does not affect the above matrices.

14.11. BT.709/BT.601 625-line primary conversion example

Conversion from BT.709 to BT.601 625-line primaries can be performed using the matrices in Section 14.1 and Section 14.2 as follows:

$$\left(\begin{array}{c} R_{601\textrm{EBU}} \\ G_{601\textrm{EBU}} \\ B_{601\textrm{EBU}}\end{array}\right) \approx \left(\begin{array}{ccc} 3.063361, & -1.393390, & -0.475824 \\ -0.969244, & 1.875968, & 0.041555 \\ 0.067861, & -0.228799, & 1.069090\end{array}\right) \left(\begin{array}{ccc} 0.412391, & 0.357584, & 0.180481 \\ 0.212639, & 0.715169, & 0.072192 \\ 0.019331, & 0.119195, & 0.950532\end{array}\right) \left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right)$$
$$\left(\begin{array}{c} R_{601\textrm{EBU}} \\ G_{601\textrm{EBU}} \\ B_{601\textrm{EBU}}\end{array}\right) \approx \left(\begin{array}{ccc} 0.957815, & 0.042184, & 0.0 \\ 0.0, & 1.0, & 0.0 \\ 0.0, & -0.011934, & 1.011934\end{array}\right) \left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right)$$

Conversion from BT.601 625-line to BT.709 primaries can be performed using these matrices:

$$\left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right) \approx \left(\begin{array}{ccc} 3.240970, & -1.537383, & -0.498611 \\ -0.969244, & 1.875968, & 0.041555 \\ 0.055630, & -0.203977, & 1.056972\end{array}\right) \left(\begin{array}{ccc} 0.430554, & 0.341550, & 0.178352 \\ 0.222004, & 0.706655, & 0.071341 \\ 0.020182, & 0.129553, & 0.939322\end{array}\right) \left(\begin{array}{c} R_{601\textrm{EBU}} \\ G_{601\textrm{EBU}} \\ B_{601\textrm{EBU}}\end{array}\right)$$
$$\left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right) \approx \left(\begin{array}{ccc} 1.044044, & -0.044043, & 0.0 \\ 0.0, & 1.0, & 0.0 \\ 0.0, & 0.011793, & 0.988207\end{array}\right) \left(\begin{array}{c} R_{601\textrm{EBU}} \\ G_{601\textrm{EBU}} \\ B_{601\textrm{EBU}}\end{array}\right)$$

14.12. BT.709/BT.2020 primary conversion example

Conversion from BT.709 to BT.2020 primaries can be performed using the matrices in Section 14.4 and Section 14.1 as follows:

$$\left(\begin{array}{c} R_{2020} \\ G_{2020} \\ B_{2020}\end{array}\right) \approx \left(\begin{array}{ccc} 1.716651, & -0.355671, & -0.253366 \\ -0.666684, & 1.616481, & 0.015769 \\ 0.017640, & -0.042771, & 0.942103\end{array}\right) \left(\begin{array}{ccc} 0.412391, & 0.357584, & 0.180481 \\ 0.212639, & 0.715169, & 0.072192 \\ 0.019331, & 0.119195, & 0.950532\end{array}\right) \left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right)$$
$$\left(\begin{array}{c} R_{2020} \\ G_{2020} \\ B_{2020}\end{array}\right) \approx \left(\begin{array}{ccc} 0.627404, & 0.329282, & 0.043314 \\ 0.069097, & 0.919541, & 0.011362 \\ 0.016392, & 0.088013, & 0.895595\end{array}\right) \left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right)$$

Conversion from BT.2020 primaries to BT.709 primaries can be performed with the following matrices:

$$\left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right) \approx \left(\begin{array}{ccc} 3.240970, & -1.537383, & -0.498611 \\ -0.969244, & 1.875968, & 0.041555 \\ 0.055630, & -0.203977, & 1.056972\end{array}\right) \left(\begin{array}{ccc} 0.636958, & 0.144617, & 0.168881 \\ 0.262700, & 0.677998, & 0.059302 \\ 0.000000, & 0.028073, & 1.060985\end{array}\right) \left(\begin{array}{c} R_{2020} \\ G_{2020} \\ B_{2020}\end{array}\right)$$
$$\left(\begin{array}{c} R_{709} \\ G_{709} \\ B_{709}\end{array}\right) \approx \left(\begin{array}{ccc} 1.660491, & -0.587641, & -0.072850 \\ -0.124551, & 1.132900, & -0.008349 \\ -0.018151, & -0.100579, & 1.118730 \end{array}\right) \left(\begin{array}{c} R_{2020} \\ G_{2020} \\ B_{2020}\end{array}\right)$$

15. Color models

The human eye is more sensitive to high-frequency changes in intensity (absolute quantity of light) than to high-frequency changes in the dominant wavelength and saturation of a color. Additionally the eye does not exhibit equal sensitivity to all wavelengths. Many image representations take advantage of these facts to distribute the number of bits used to represent a texel in a more perceptually-uniform manner than is achieved by representing the color primaries independently - for example by encoding the chroma information at a reduced spatial resolution.

15.1. Y′CBCR color model

Color models based on color differences are often referred to with incorrect or ambiguous terminology, the most common of which is YUV.

In the broadcast standards which define these models:

• A prime mark (′) is used to refer to the “gamma pre-corrected” version of a value. That is, an approximation to a perceptually linear mapping between value and intensity. The absence of a prime mark indicates that the value is linear in intensity.
• R′G′B′ is used to refer to the red, green and blue reference values in “gamma pre-corrected” form. That is, R′, G′ and B′ have a non-linear transfer function, whereas R, G and B are linear with respect to light intensity. The transfer function used resembles an exponentiation “gamma correction” operation, with a linear segment near zero for mathematical stability. See Section 13.2 for details of the transfer function typically used in these cases.
• IEEE standards BT.601 and BT.709 use a prefix of E to refer to a continuous signal value in the range [0..1], mirroring the terminology in analog standards such as BT.1700 and SMPTE-170M. For example, in these standards, the continuous encoding of $R'$ is written $E_R'$ . BT.2020 and BT.2100 no longer use the E convention, and refer to continuous values as, for example, R′ directly. For brevity, this specification does not use the E-prefix convention for model conversions, and all values can be assumed to be continuous. BT.601 refers to the quantized digital version of $E'_R$ , $E'_G$ and $E'_B$ as $E'_{R_D}$ , $E'_{G_D}$ and $E'_{B_D}$ . In BT.709 the quantized digital representation is instead $D'_R$ , $D'_G$ and $D'_B$ , in BT.2020 and BT.2100 written as DR′, DG′ and DB′.
• Y′ is a weighted sum of R′, G′ and B′ values, and represents non-physically-linear (but perceptually-linear) light intensity, as distinct from physically-linear light intensity. Note that the ITU broadcast standards use “luminance” for Y′ despite some authorities reserving that term for a linear intensity representation. Since this is a weighted sum of non-linear values, $Y'$ is not mathematically equivalent to applying the non-linear transfer function to a weighted sum of linear R, G and B values: $R^{\gamma}+G^{\gamma}+B^{\gamma} \neq (R + G + B)^{\gamma}$ . The prime symbol is often omitted so that Y′ is confusingly written Y. BT.601 and BT.709 refers to the continuous non-linear “luminance” signal as $E'_Y$ ; in BT.2020 and BT.2100 this value is just Y′. The quantized digital representation is written as simply Y′ in BT.601, as $D'_Y$ in BT.709, and as DY′ in BT.2020 and BT.2100. In this standard, Y′ refers to a continuous value.

• For the purposes of this section, we will refer to the weighting factor applied to R′ as KR and the weighting factor applied to B′ as KB. The weighting factor of G′ is therefore $1-K_R-K_B$ . Thus $Y' = K_R \times R' + (1-K_R-K_B) \times G' + Kb \times B'$ .

Color differences are calculated from the non-linear Y′ and color components as:

\begin{align*} B'-Y' &= (1-K_B) \times B' - (1-K_R-K_B) \times G' - K_R \times R' \\ R'-Y' &= (1-K_R) \times R' - (1-K_R-K_B) \times G' - K_B \times B' \end{align*}

Note that, for R′, G′, B′ in the range [0..1]:

\begin{align*} (1-K_B) \geq B'-Y' \geq -(1-K_B) \\ (1-K_R) \geq R'-Y' \geq -(1-K_R) \end{align*}
• $(B'-Y')$ scaled appropriately for incorporation into a PAL sub-carrier signal is referred to in BT.1700 as U; note that the scale factor (0.493) is not the same as that used for digital encoding of this color difference. U is colloquially used for other representations of this value.
• $(R'-Y')$ scaled appropriately for incorporation into a PAL sub-carrier signal is referred to in BT.1700 as V; note that the scale factor (0.877) is not the same as that used for digital encoding of this color difference. V is colloquially used for other representations of this value.
• $(B'-Y')$ scaled to the range [ $-0.5..0.5$ ] is referred to in BT.601 and BT.709 as $E'_{C_B}$ , and in BT.2020 and BT.2100 as simply $C'_B$ . In ST-240 this value is referred to as $E'_\mathit{PB}$ , and the analog signal is colloquially known as PB. This standard uses the $C'_B$ terminology for brevity and consistency with $Y'_CC'_\mathit{BC}C'_\mathit{RC}$ . It is common, especially in the name of a color model, to omit the prime symbol and write simply CB.
• $(R'-Y')$ scaled to the range [ $-0.5..0.5$ ] is referred to in BT.601 and BT.709 as $E'_{C_R}$ , and in BT.2020 and BT.2100 as simply $C'_R$ . In ST-240 this value is referred to as $E'_\mathit{PR}$ , and the analog signal is colloquially known as PR. This standard uses the $C'_R$ terminology for brevity and consistency with $Y'_CC'_\mathit{BC}C'_\mathit{RC}$ . It is common, especially in the name of a color model, to omit the prime symbol and write simply CR.
• $(B'-Y')$ scaled and quantized for digital representation is known as simply $C'_B$ in BT.601, $D'_\mathit{CB}$ in BT.709 and $DC_B'$ in BT.2020 and BT.2100.
• $(R'-Y')$ scaled and quantized for digital representation is known as simply $C'_R$ in BT.601, $D'_\mathit{CR}$ in BT.709 and $DC_R'$ in BT.2020 and BT.2100.
• This section considers the color channels in continuous terms; the terminology $DC_B'$ and $DC_R'$ is used in Section 16.

Using this terminology, the following conversion formulae can be derived:

\begin{align*} Y' & = K_r \times R' + (1-K_R-K_B) \times G' + K_B \times B' \\ C'_B & = {(B' - Y')\over{2(1-K_B)}} \\ & = {B'\over{2}} - {{K_R \times R' + (1 - K_R - K_B) \times G'}\over{2(1-K_B)}} \\ C'_R & = {(R' - Y')\over{2(1-K_R)}} \\ & = {R'\over{2}} - {{K_B \times B' + (1 - K_R - K_B) \times G'}\over{2(1-K_R)}} \end{align*}

For the inverse conversion:

\begin{align*} R' & = Y' + 2(1-K_R)\times C'_R \\ B' & = Y' + 2(1-K_B)\times C'_B \end{align*}

The formula for G′ can be derived by substituting the formulae for R′ and B′ into the derivation of Y′:

\begin{align*} Y' = &\ K_R \times R' + (1-K_R-K_B) \times G' + K_B \times B' \\ = &\ K_R \times (Y'+2(1-K_R)\times C'_R) + \\ &\ (1-K_R-K_B) \times G' + \\ &\ K_B \times (Y'+2(1-K_B)\times C'_B) \\ Y'\times(1-K_R-K_B) = &\ (1-K_R-K_B)\times G' + \\ &\ K_R\times 2(1-K_R)\times C'_R + \\ &\ K_B\times 2(1-K_B)\times C'_B \\ G' = &\ Y' - {2(K_R(1-K_R)\times C'_R + K_B(1-K_B)\times C'_B)\over{1-K_R-K_B}} \end{align*}

The values chosen for KR and KB vary between standards.

The required color model conversion between $Y'C_BC_R$ and $R'G'B'$ can typically be deduced from other color space parameters:

15.1.1. BT.709 Y′CBCR conversion

ITU Rec.709 defines KR = 0.2126 and KB = 0.0722.

That is, for conversion between (R′, G′, B′) defined in BT.709 color primaries and using the ITU transfer function:

\begin{align*} Y' & = 0.2126 \times R' + 0.7152 \times G' + 0.0722 \times B' \\ C'_B & = {(B' - Y')\over{1.8556}} \\ C'_R & = {(R' - Y')\over{1.5748}} \\ \end{align*}

Alternatively:

$$\left(\begin{array}{c}Y' \\ C'_B \\ C'_R\end{array}\right) = \left(\begin{array}{ccc}0.2126, & 0.7152, & 0.0722 \\ -{0.2126\over{1.8556}}, & -{0.7152\over{1.8556}}, & 0.5 \\ 0.5, & -{0.7152\over{1.5748}}, & -{0.0722\over{1.5748}}\end{array}\right) \left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right)$$

For the inverse conversion:

$$\left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right) = \left(\begin{array}{ccc}1, & 0, & 1.5748\\ 1, & -{0.13397432\over{0.7152}}, & -{0.33480248\over{0.7152}}\\ 1, & 1.8556, & 0\end{array}\right) \left(\begin{array}{c}Y'\\ C'_B\\ C'_R\end{array}\right)$$

15.1.2. BT.601 Y′CBCR conversion

ITU Rec.601 defines KR = 0.299 and KB = 0.114.

That is, for conversion between (R′, G′, B′) defined in BT.601 EBU color primaries or BT.601 SMPTE color primaries, and using the ITU transfer function:

\begin{align*} Y' & = 0.299 \times R' + 0.587 \times G' + 0.114 \times B' \\ C'_B & = {(B' - Y')\over{1.772}} \\ C'_R & = {(R' - Y')\over{1.402}} \\ \end{align*}

Alternatively:

$$\left(\begin{array}{c}Y' \\ C'_B \\ C'_R\end{array}\right) = \left(\begin{array}{ccc}0.299, & 0.587, & 0.114 \\ -{0.299\over{1.772}}, & -{0.587\over{1.772}}, & 0.5 \\ 0.5, & -{0.587\over{1.402}}, & -{0.114\over{1.402}}\end{array}\right) \left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right)$$

For the inverse conversion:

$$\left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right) = \left(\begin{array}{ccc}1, & 0, & 1.402\\ 1, & -{0.202008\over{0.587}}, & -{0.419198\over{0.587}}\\ 1, & 1.772, & 0\end{array}\right) \left(\begin{array}{c}Y'\\ C'_B\\ C'_R\end{array}\right)$$

15.1.3. BT.2020 Y′CBCR conversion

ITU Rec.2020 and ITU Rec.2100 define KR = 0.2627 and KB = 0.0593.

That is, for conversion between (R′, G′, B′) defined in BT.2020 color primaries and using the ITU transfer function:

\begin{align*} Y' & = 0.2627 \times R' + 0.6780 \times G' + 0.0593 \times B' \\ C'_B & = {(B' - Y')\over{1.8814}} \\ C'_R & = {(R' - Y')\over{1.4746}} \\ \end{align*}

Alternatively:

$$\left(\begin{array}{c}Y' \\ C'_B \\ C'_R\end{array}\right) = \left(\begin{array}{ccc}0.2627, & 0.6780, & 0.0593 \\ -{0.2627\over{1.8814}}, & -{0.6780\over{1.8814}}, & 0.5 \\ 0.5, & -{0.6780\over{1.4746}}, & -{0.0593\over{1.4746}}\end{array}\right) \left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right)$$

For the inverse conversion:

$$\left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right) = \left(\begin{array}{ccc}1, & 0, & 1.4746\\ 1, & -{0.11156702\over{0.6780}}, & -{0.38737742\over{0.6780}}\\ 1, & 1.8814, & 0\end{array}\right) \left(\begin{array}{c}Y'\\ C'_B\\ C'_R\end{array}\right)$$

15.1.4. ST-240/SMPTE 240M Y′CBCR conversion

ST240, formerly SMPTE 240M, defines KR = 0.212 and KB = 0.087.

That is, for conversion using the ST240 transfer function:

\begin{align*} Y' & = 0.212 \times R' + 0.701 \times G' + 0.087 \times B' \\ C'_B & = {(B' - Y')\over{1.826}} \\ C'_R & = {(R' - Y')\over{1.576}} \\ \end{align*}

Alternatively:

$$\left(\begin{array}{c}Y' \\ C'_B \\ C'_R\end{array}\right) = \left(\begin{array}{ccc}0.212, & 0.701, & 0.087 \\ -{0.212\over{1.826}}, & -{0.701\over{1.826}}, & 0.5 \\ 0.5, & -{0.701\over{1.576}}, & -{0.087\over{1.576}}\end{array}\right) \left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right)$$

For the inverse conversion:

$$\left(\begin{array}{c}R'\\ G'\\ B'\end{array}\right) = \left(\begin{array}{ccc}1, & 0, & 1.576\\ 1, & -{0.58862\over{0.701}}, & -{0.334112\over{0.701}}\\ 1, & 1.826, & 0\end{array}\right) \left(\begin{array}{c}Y'\\ C'_B\\ C'_R\end{array}\right)$$

15.2. Y′CC′BCC′CR constant luminance color model

ITU-T Rec. BT.2020 introduced a “constant luminance” color representation as an alternative representation to Y′CBCR:

\begin{align*} Y'_C & = (0.2627R + 0.6780G + 0.0593B)' \\ C'_\mathit{BC} & = \begin{cases} {{B'-Y'_C}\over{1.9404}}, & -0.9702 \leq B'-Y'_C \leq 0 \\ {{B'-Y'_C}\over{1.5816}}, & 0 < B'-Y'_C \leq 0.7908\end{cases} \\ C'_\mathit{RC} & = \begin{cases} {{R'-Y'_C}\over{1.7184}}, & -0.8592 \leq R'-Y'_C \leq 0 \\ {{R'-Y'_C}\over{0.9936}}, & 0 < R'-Y'_C \leq 0.4968\end{cases} \end{align*}

This terminology follow’s BT.2020’s convention of describing the continuous values as $Y'_C$ , $C'_\mathit{BC}$ and $C'_\mathit{RC}$ ; BT.2020 uses $\mathit{DY}'_C$ , $\mathit{DC}'_\mathit{BC}$ and $\mathit{DC}'_\mathit{RC}$ to represent the quantized integer representations of the same values.

 $Y'_C$ is derived from applying a non-linear transfer function to a combination of linear $\mathit{RGB}$ components and applying a non-linear transfer function to the result, but the $C'_\mathit{BC}$ and $C'_\mathit{RC}$ color differences still encode differences between non-linear values.

The inverse transformation can be derived from the above:

\begin{align*} B' & = \begin{cases} Y'_C + 1.9404C'_\mathit{BC}, & C'_\mathit{BC} \leq 0 \\ Y'_C + 1.5816C'_\mathit{BC}, & C'_\mathit{BC} > 0\end{cases}\\ R' & = \begin{cases} Y'_C + 1.7184C'_\mathit{RC}, & C'_\mathit{RC} \leq 0 \\ Y'_C + 0.9936C'_\mathit{RC}, & C'_\mathit{RC} > 0\end{cases}\\ G & = Y_C - 0.2627R - 0.0593B \end{align*}
 Performing these calculations requires conversion between a linear representation and a non-linear transfer function during the transformation. This is distinct from the non-constant-luminance case, which is a simple matrix transform.

15.3. ICTCP constant intensity color model

ITU-T Rec. BT.2100 introduced a “constant intensity” color representation as an alternative representation to Y′CBCR:

\begin{align*} L & = {(1688R + 2146G + 262B)\over{4096}}\\ M & = {(683R + 2951G + 462B)\over{4096}}\\ S & = {(99R + 309G + 3688B)\over{4096}}\\ L' & = \begin{cases} \textrm{EOTF}^{-1}(L_D), & \textrm{PQ transfer function}\\ \textrm{OETF}(L_S), & \textrm{HLG transfer function}\end{cases}\\ M' & = \begin{cases} \textrm{EOTF}^{-1}(M_D), & \textrm{PQ transfer function}\\ \textrm{OETF}(M_S), & \textrm{HLG transfer function}\end{cases}\\ S' & = \begin{cases} \textrm{EOTF}^{-1}(S_D), & \textrm{PQ transfer function}\\ \textrm{OETF}(S_S), & \textrm{HLG transfer function}\end{cases}\\ I & = 0.5L' + 0.5M'\\ C_T & = {(6610L' - 13613M' + 7003S')\over{4096}}\\ C_P & = {(17933L' - 17390M' - 543S')\over{4096}} \end{align*}

Note that the suffix D indicates that PQ encoding is display-referred and the suffix S indicates that HLG encoding is scene-referred — that is, they refer to display and scene light respectively.

To invert this, it can be observed that:

$$\left(\begin{array}{c}L' \\ M' \\ S' \end{array}\right) = 4096\times \left(\begin{array}{rrr}2048, & 2048, & 0 \\ 6610, & -13613, & 7003 \\ 17933, & -17390, & -543\end{array}\right)^{-1} \left(\begin{array}{c}I\\ C_T\\ C_P\end{array}\right)$$ $$\left(\begin{array}{c}L' \\ M' \\ S' \end{array}\right) = \left(\begin{array}{rrr}1, & 1112064/129174029, & 14342144/129174029 \\ 1, & -1112064/129174029, & -14342144/129174029 \\ 1, & 72341504/129174029, & -41416704/129174029\end{array}\right) \left(\begin{array}{c}I\\ C_T\\ C_P\end{array}\right)$$ $$\left(\begin{array}{c}L' \\ M' \\ S' \end{array}\right) \approx \left(\begin{array}{rrr}1, & 0.0086090370, & 0.1110296250 \\ 1, & -0.0086090370, & -0.1110296250 \\ 1, & 0.5600313357, & -0.3206271750\end{array}\right) \left(\begin{array}{c}I\\ C_T\\ C_P\end{array}\right)$$ $$\{L_D,M_D,S_D\} = \textrm{EOTF}_{\textrm{PQ}}(\{L',M',S'\})$$ $$\{L_S,M_S,S_S\} = \textrm{OETF}_{\textrm{HLG}}^{-1}(\{L',M',S'\})$$ $$\left(\begin{array}{c}R \\ G \\ B\end{array}\right) = 4096\times \left(\begin{array}{rrr}1688, & 2146, & 262 \\ 683, & 2951, & 462 \\ 99, & 309, & 3688\end{array}\right)^{-1} \left(\begin{array}{c}L\\ M\\ S\end{array}\right)$$ $$\left(\begin{array}{c}R \\ G \\ B \end{array}\right) = {4096\over 12801351680}\times \left(\begin{array}{rrr}10740530, & -7833490, & 218290 \\ -2473166, & 6199406, & -600910 \\ -81102, & -309138, & 3515570\end{array}\right) \left(\begin{array}{c}L\\ M\\ S\end{array}\right)$$ $$\left(\begin{array}{c}R \\ G \\ B \end{array}\right) \approx \left(\begin{array}{rrr}3.4366066943, & -2.5064521187, & 0.0698454243 \\ -0.7913295556, & 1.9836004518, & -0.1922708962 \\ -0.0259498997, & -0.0989137147, & 1.1248636144\end{array}\right) \left(\begin{array}{c}L\\ M\\ S\end{array}\right)$$

16. Quantization schemes

The formulae in the previous sections are described in terms of operations on continuous values. These values are typically represented by quantized integers. There are standard encodings for representing some color models within a given bit depth range.

16.1. “Narrow range” encoding

ITU broadcast standards typically reserve values at the ends of the representable integer range for rounding errors and for signal control data. The nominal range of representable values between these limits is represented by the following encodings, for bit depth n = {8, 10, 12}:

\begin{align*} \mathit{DG}' & = \lfloor 0.5 + (219\times G' + 16)\times 2^{n-8}\rfloor &\mathit{DB}' & = \lfloor 0.5 + (219\times B' + 16)\times 2^{n-8}\rfloor \\ &&\mathit{DR}' & = \lfloor 0.5 + (219\times R' + 16)\times 2^{n-8}\rfloor \\ \mathit{DY}' & = \lfloor 0.5 + (219\times Y' + 16)\times 2^{n-8}\rfloor &\mathit{DC}'_B & = \lfloor 0.5 + (224\times C'_B + 128)\times 2^{n-8}\rfloor \\ &&\mathit{DC}'_R & = \lfloor 0.5 + (224\times C'_R + 128)\times 2^{n-8}\rfloor \\ \mathit{DY}'_C & = \lfloor 0.5 + (219\times Y'_C + 16)\times 2^{n-8}\rfloor &\mathit{DC}'_\mathit{CB} & = \lfloor 0.5 + (224\times C'_\mathit{CB} + 128)\times 2^{n-8}\rfloor \\ &&\mathit{DC}'_\mathit{CR} & = \lfloor 0.5 + (224\times C'_\mathit{CR} + 128)\times 2^{n-8}\rfloor \\ \mathit{DI} & = \lfloor 0.5 + (219\times I + 16)\times 2^{n-8}\rfloor &\mathit{DC}'_T & = \lfloor 0.5 + (224\times C'_T + 128)\times 2^{n-8}\rfloor \\ &&\mathit{DC}'_P & = \lfloor 0.5 + (224\times C'_P + 128)\times 2^{n-8}\rfloor \end{align*}

The dequantization formulae are therefore:

\begin{align*} G' & = {{{\mathit{DG}'\over{2^{n-8}}} - 16}\over{219}} & Y' & = {{{\mathit{DY}'\over{2^{n-8}}} - 16}\over{219}} & Y'_C & = {{{\mathit{DY}_C'\over{2^{n-8}}} - 16}\over{219}} & I & = {{{\mathit{DI}'\over{2^{n-8}}} - 16}\over{219}} \\ B' & = {{{\mathit{DB}'\over{2^{n-8}}} - 16}\over{219}} & C'_B & = {{{\mathit{DC}'_B\over{2^{n-8}}} - 128}\over{224}} & C'_\mathit{CB} & = {{{\mathit{DC}'_\mathit{CB}\over{2^{n-8}}} - 128}\over{224}} & C'_T & = {{{\mathit{DC}'_T\over{2^{n-8}}} - 128}\over{224}} \\ R' & = {{{\mathit{DR}'\over{2^{n-8}}} - 16}\over{219}} & C'_R & = {{{\mathit{DC}'_R\over{2^{n-8}}} - 128}\over{224}} & C'_\mathit{CR} & = {{{\mathit{DC}'_\mathit{CR}\over{2^{n-8}}} - 128}\over{224}} & C'_P & = {{{\mathit{DC}'_P\over{2^{n-8}}} - 128}\over{224}} \end{align*}

For consistency with $Y'_CC'_\mathit{BC}C'_\mathit{RC}$ , these formulae use the BT.2020 and BT.2100 terminology of prefixing a D to represent the digital quantized encoding of a numerical value.

That is, in “narrow range” encoding:

Value Continuous encoding value Quantized encoding

Black

{R′, G′, B′, Y′, $Y'_C$ , I} = 0.0

{DR′, DG′, DB′, DY′, $\mathit{DY}'_C$ , DI} = $16 \times 2^{n-8}$

Peak brightness

{R′, G′, B′, Y′, $Y'_C$ , I} = 1.0

{DR′, DG′, DB′, DY′, $\mathit{DY}'_C$ , DI} = $235 \times 2^{n-8}$

Minimum color difference value

{ $C'_B$ , $C'_R$ , $C'_\mathit{BC}$ , $C'_\mathit{RC}$ , CT, CP} = -0.5

{ $\mathit{DC}'_B$ , $\mathit{DC}'_R$ , $\mathit{DC}'_\mathit{BC}$ , $\mathit{DC}'_\mathit{CR}$ , DCT, DCP} = $16 \times 2^{n-8}$

Maximum color difference value

{ $C'_B$ , $C'_R$ , $C'_\mathit{BC}$ , $C'_\mathit{RC}$ , CT, CP} = 0.5

{ $\mathit{DC}'_B$ , $\mathit{DC}'_R$ , $\mathit{DC}'_\mathit{BC}$ , $\mathit{DC}'_\mathit{CR}$ , DCT, DCP} = $240 \times 2^{n-8}$

Achromatic colors

R′ = G′ = B′

{ $C'_B$ , $C'_R$ , $C'_\mathit{BC}$ , $C'_\mathit{RC}$ , CT, CP} = 0.0

{ $\mathit{DC}'_B$ , $\mathit{DC}'_R$ , $\mathit{DC}'_\mathit{BC}$ , $\mathit{DC}'_\mathit{CR}$ , DCT, DCP} = $128 \times 2^{n-8}$

If, instead of the quantized values, the input is interpreted as fixed-point values in the range 0.0..1.0, as might be the case if the values were treated as unsigned normalized quantities in a computer graphics API, the following conversions can be applied instead:

\begin{align*} G' & = {{{G'_{\mathit{norm}}\times{2^{n-1}}} - 16\times{2^{n-8}}}\over{219\times 2^{n-8}}} & B' & = {{{B'_{\mathit{norm}}\times{2^{n-1}}} - 16\times{2^{n-8}}}\over{219\times 2^{n-8}}} \\ &&R' & = {{{R'_{\mathit{norm}}\times{2^{n-1}}} - 16\times{2^{n-8}}}\over{219\times 2^{n-8}}} \\ Y' & = {{{Y'_{\mathit{norm}}\times{2^{n-1}}} - 16\times{2^{n-8}}}\over{219\times 2^{n-8}}} & C'_B & = {{{\mathit{DC}'_{\mathit{Bnorm}}\times{2^{n-1}}} - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ &&C'_R & = {{{\mathit{DC}'_{\mathit{Rnorm}}\times{2^{n-1}}} - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ Y'_C & = {{{Y'_{\mathit{Cnorm}}\times{2^{n-1}}} - 16\times{2^{n-8}}}\over{219\times 2^{n-8}}} & C'_\mathit{CB} & = {{{\mathit{DC}'_{CBnorm}\times{2^{n-1}}} - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ &&C'_\mathit{CR} & = {{{\mathit{DC}'_{\mathit{CRnorm}}\times{2^{n-1}}} - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ I & = {{{I'_{\mathit{norm}}\times{2^{n-1}}} - 16\times{2^{n-8}}}\over{219\times 2^{n-8}}} & C'_T & = {{{\mathit{DC}'_{\mathit{Tnorm}}\times{2^{n-1}}} - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ &&C'_P & = {{{\mathit{DC}'_{\mathit{Pnorm}}\times{2^{n-1}}} - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ G'_\mathit{norm} & = {{{G'\times{219\times 2^{n-8}}} + 16\times{2^{n-8}}}\over{2^{n-1}}} & B'_\mathit{norm} & = {{{B'\times{219\times 2^{n-8}}} + 16\times{2^{n-8}}}\over{2^{n-1}}} \\ &&R'_\mathit{norm} & = {{{R'\times{219\times 2^{n-8}}} + 16\times{2^{n-8}}}\over{2^{n-1}}} \\ Y'_\mathit{norm} & = {{{Y'\times{219\times 2^{n-8}}} + 16\times{2^{n-8}}}\over{2^{n-1}}} & C'_\mathit{Bnorm} & = {{{\mathit{DC}'_B\times{224\times ^{n-8}}} + 128\times 2^{n-8}}\over{2^{n-1}}} \\ &&C'_\mathit{Rnorm} & = {{{\mathit{DC}'_R\times{224\times ^{n-8}}} + 128\times 2^{n-8}}\over{2^{n-1}}} \\ Y'_\mathit{Cnorm} & = {{{Y'_C\times{219\times 2^{n-8}}} + 16\times{2^{n-8}}}\over{2^{n-1}}} & C'_\mathit{CBnorm} & = {{{\mathit{DC}'_\mathit{CB}\times{224\times ^{n-8}}} + 128\times 2^{n-8}}\over{2^{n-1}}} \\ &&C'_\mathit{CRnorm} & = {{{\mathit{DC}'_\mathit{CR}\times{224\times ^{n-8}}} + 128\times 2^{n-8}}\over{2^{n-1}}} \\ I_\mathit{norm} & = {{{I\times{219\times 2^{n-8}}} + 16\times{2^{n-8}}}\over{2^{n-1}}} & C'_\mathit{Tnorm} & = {{{\mathit{DC}'_{T}\times{224\times ^{n-8}}} + 128\times 2^{n-8}}\over{2^{n-1}}} \\ &&C'_\mathit{Pnorm} & = {{{\mathit{DC}'_{P}\times{224\times ^{n-8}}} + 128\times 2^{n-8}}\over{2^{n-1}}} \end{align*}

16.2. “Full range” encoding

ITU-T Rec. BT.2100-1 and the current Rec. T.871 JFIF specification define the following quantization scheme that does not incorporate any reserved head-room or foot-room, which is optional and described as “full range” in BT.2100, and integral to Rec. T.871.

 Both these specifications modify a definition used in previous versions of their specifications, which is described below.

For bit depth n = {8 (JFIF),10,12 (Rec.2100)}:

\begin{align*} \mathit{DG}' & = \textrm{Round}\left(G'\times (2^n-1)\right) & \mathit{DB}' & = \textrm{Round}\left(B'\times (2^n-1)\right) \\ &&\mathit{DR}' & = \textrm{Round}\left(R'\times (2^n-1)\right) \\ \mathit{DY}' & = \textrm{Round}\left(Y'\times (2^n-1)\right) & \mathit{DC}'_B & = \textrm{Round}\left(C'_B\times (2^n-1) + 2^{n-1}\right) \\ &&\mathit{DC}'_R & = \textrm{Round}\left(C'_R\times (2^n-1) + 2^{n-1}\right) \\ \mathit{DY}'_C & = \textrm{Round}\left(Y'_C\times (2^n-1)\right) & \mathit{DC}'_\mathit{CB} & = \textrm{Round}\left(C'_\mathit{CB}\times (2^n-1) + 2^{n-1}\right) \\ &&\mathit{DC}'_\mathit{CR} & = \textrm{Round}\left(C'_\mathit{CR}\times (2^n-1) + 2^{n-1}\right) \\ \mathit{DI} & = \textrm{Round}\left(I\times (2^n-1)\right) & \mathit{DC}'_T & = \textrm{Round}\left(C'_T\times (2^n-1) + 2^{n-1}\right) \\ &&\mathit{DC}'_P & = \textrm{Round}\left(C'_P\times (2^n-1) + 2^{n-1}\right) \end{align*}

BT.2100-1 defines Round() as:

\begin{align*} \textrm{Round}(x) &= \textrm{Sign}(x)\times\lfloor|x| + 0.5\rfloor \\ \textrm{Sign}(x) &= \begin{cases} 1, & x > 0 \\ 0, & x = 0 \\ -1, & x < 0 \end{cases} \end{align*}

Note that a chroma channel value of exactly 0.5 corresponds to a quantized encoding of $2^n$ , and must therefore be clamped to the nominal peak value of $2^n-1$ . Narrow-range encoding does not have this problem. A chroma channel value of -0.5 corresponds to a quantized encoding of 1, which is the nominal minimum peak value.

In Rec. T.871 (which defines only n = 8), the corresponding formula is:

\begin{align*} \textrm{Round}(x) &= \textrm{Clamp}(\lfloor|x| + 0.5\rfloor) \\ \textrm{clamp}(x) &= \begin{cases} 255, & x > 255 \\ 0, & x < 0 \\ x, & \textrm{otherwise} \end{cases} \end{align*}

Allowing for the clamping at a chroma value of 0.5, these formulae are equivalent across the expected -0.5..0.5 range for chroma and 0.0..1.0 range for luma values.

The dequantization formulae are therefore:

\begin{align*} G' & = {\mathit{DG}'\over{2^n - 1}} & Y' & = {\mathit{DY}'\over{2^n - 1}} & Y'_C & = {\mathit{DY}_C'\over{2^n - 1}} & I & = {\mathit{DI}'\over{2^n - 1}} \\ B' & = {\mathit{DB}'\over{2^n - 1}} & C'_B & = {\mathit{DC}'_B - 2^{n-1}\over{2^n - 1}} & C'_\mathit{CB} & = {\mathit{DC}'_\mathit{CB} - 2^{n-1}\over{2^n - 1}} & C'_T & = {\mathit{DC}'_T - 2^{n-1}\over{2^n - 1}} \\ R' & = {\mathit{DR}'\over{2^n - 1}} & C'_R & = {\mathit{DC}'_R - 2^{n-1}\over{2^n - 1}} & C'_\mathit{CR} & = {\mathit{DC}'_\mathit{CR} - 2^{n-1}\over{2^n - 1}} & C'_P & = {\mathit{DC}'_P - 2^{n-1}\over{2^n - 1}} \end{align*}

That is, in “full range” encoding:

Value Continuous encoding value Quantized encoding

Black

{R′, G′, B′, Y′, $Y'_C$ , I} = 0.0

{DR′, DG′, DB′, DY′, $\mathit{DY}'_C$ , DI} = 0

Peak brightness

{R′, G′, B′, Y′, $Y'_C$ , I} = 1.0

{DR′, DG′, DB′, DY′, $\mathit{DY}'_C$ , DI} = 2n - 1

Minimum color difference value

{ $C'_B$ , $C'_R$ , $C'_\mathit{BC}$ , $C'_\mathit{RC}$ , CT, CP} = -0.5

{ $\mathit{DC}'_B$ , $\mathit{DC}'_R$ , $\mathit{DC}'_\mathit{BC}$ , $\mathit{DC}'_\mathit{CR}$ , DCT, DCP} = 1

Maximum color difference value

{ $C'_B$ , $C'_R$ , $C'_\mathit{BC}$ , $C'_\mathit{RC}$ , CT, CP} = 0.5

{ $\mathit{DC}'_B$ , $\mathit{DC}'_R$ , $\mathit{DC}'_\mathit{BC}$ , $\mathit{DC}'_\mathit{CR}$ , DCT, DCP} = $2^n - 1$

(clamped)

Achromatic colors

R′ = G′ = B′

{ $C'_B$ , $C'_R$ , $C'_\mathit{BC}$ , $C'_\mathit{RC}$ , CT, CP} = 0.0

{ $\mathit{DC}'_B$ , $\mathit{DC}'_R$ , $\mathit{DC}'_\mathit{BC}$ , $\mathit{DC}'_\mathit{CR}$ , DCT, DCP} = 2n-1

If, instead of the quantized values, the input is interpreted as fixed-point values in the range 0.0..1.0, as might be the case if the values were treated as unsigned normalized quantities in a computer graphics API, the following conversions can be applied instead:

\begin{align*} G' & = G'_{\mathit{norm}} & B' & = B'_{\mathit{norm}} \\ &&R' & = R'_{\mathit{norm}} \\ Y' & = Y'_{\mathit{norm}} & C'_B & = \mathit{DC}'_{\mathit{Bnorm}} - {2^{n-1}\over{2^n - 1}} \\ &&C'_R & = \mathit{DC}'_{\mathit{Rnorm}} - {2^{n-1}\over{2^n - 1}} \\ Y'_C & = Y'_{\mathit{Cnorm}} & C'_\mathit{CB} & = \mathit{DC}'_{\mathit{CBnorm}} - {2^{n-1}\over{2^n - 1}} \\ &&C'_\mathit{CR} & = \mathit{DC}'_{\mathit{CRnorm}} - {2^{n-1}\over{2^n - 1}} \\ I & = I'_{\mathit{norm}} & C'_T & = \mathit{DC}'_{\mathit{Tnorm}} - {2^{n-1}\over{2^n - 1}} \\ &&C'_P & = \mathit{DC}'_{\mathit{Pnorm}} - {2^{n-1}\over{2^n - 1}} \\ G'_{\mathit{norm}} & = G' & B'_{\mathit{norm}} & = B' \\ &&R'_{\mathit{norm}} & = R' \\ Y'_{\mathit{norm}} & = Y' & C'_{\mathit{Bnorm}} & = \mathit{DC}'_B + {2^{n-1}\over{2^n - 1}} \\ &&C'_{\mathit{Rnorm}} & = \mathit{DC}'_R + {2^{n-1}\over{2^n - 1}} \\ Y'_{\mathit{Cnorm}} & = Y'_C & C'_{\mathit{CBnorm}} & = \mathit{DC}'_\mathit{CB} + {2^{n-1}\over{2^n - 1}} \\ &&C'_{\mathit{CRnorm}} & = \mathit{DC}'_\mathit{CR} + {2^{n-1}\over{2^n - 1}} \\ I_{\mathit{norm}} & = I & C'_{\mathit{Tnorm}} & = \mathit{DC}'_{T} + {2^{n-1}\over{2^n - 1}} \\ &&C'_{\mathit{Pnorm}} & = \mathit{DC}'_{P} + {2^{n-1}\over{2^n - 1}} \end{align*}

16.3. Legacy “full range” encoding.

ITU-T Rec. BT.2100-0 formalized an optional encoding scheme that does not incorporate any reserved head-room or foot-room. The legacy JFIF specification similarly used the full range of 8-bit channels to represent $Y'C_BC_R$ color. For bit depth n = {8 (JFIF),10,12 (Rec.2100)}:

\begin{align*} \mathit{DG}' & = \lfloor 0.5 + G'\times 2^n\rfloor & \mathit{DB}' & = \lfloor 0.5 + B'\times 2^n\rfloor \\ &&\mathit{DR}' & = \lfloor 0.5 + R'\times 2^n\rfloor \\ \mathit{DY}' & = \lfloor 0.5 + Y'\times 2^n\rfloor & \mathit{DC}'_B & = \lfloor 0.5 + (C'_B + 0.5)\times 2^n\rfloor \\ &&\mathit{DC}'_R & = \lfloor 0.5 + (C'_R + 0.5)\times 2^n\rfloor \\ \mathit{DY}'_C & = \lfloor 0.5 + Y'_C\times 2^n\rfloor & \mathit{DC}'_\mathit{CB} & = \lfloor 0.5 + (C'_\mathit{CB} + 0.5)\times 2^n\rfloor \\ &&\mathit{DC}'_\mathit{CR} & = \lfloor 0.5 + (C'_\mathit{CR} + 0.5)\times 2^n\rfloor \\ \mathit{DI} & = \lfloor 0.5 + I\times 2^n\rfloor & \mathit{DC}'_T & = \lfloor 0.5 + (C'_T + 0.5)\times 2^n\rfloor \\ &&\mathit{DC}'_P & = \lfloor 0.5 + (C'_P + 0.5)\times 2^n\rfloor \end{align*}

The dequantization formulae are therefore:

\begin{align*} G' & = \mathit{DG}'\times 2^{-n} & Y' & = \mathit{DY}'\times 2^{-n} & Y'_C & = \mathit{DY}_C'\times 2^{-n} & I & = \mathit{DI}'\times 2^{-n} \\ B' & = \mathit{DB}'\times 2^{-n} & C'_B & = \mathit{DC}'_B\times 2^{-n}-0.5 & C'_\mathit{CB} & = \mathit{DC}'_\mathit{CB}\times 2^{-n}-0.5 & C'_T & = \mathit{DC}'_T\times 2^{-n}-0.5 \\ R' & = \mathit{DR}'\times 2^{-n} & C'_R & = \mathit{DC}'_R\times 2^{-n}-0.5 & C'_\mathit{CR} & = \mathit{DC}'_\mathit{CR}\times 2^{-n}-0.5 & C'_P & = \mathit{DC}'_P\times 2^{-n}-0.5 \end{align*}
 These formulae map luma values of 1.0 and chroma values of 0.5 to $2^n$ , for bit depth $n$ . This has the effect that the maximum value (e.g. pure white) cannot be represented directly. Out-of-bounds values must be clamped to the largest representable value.
 ITU-R BT.2100-0 dictates that in 12-bit coding, the largest values encoded should be 4092 (“for consistency” with 10-bit encoding, with a maximum value of 1023). This slightly reduces the maximum intensity which can be expressed, and slightly reduces the saturation range. The achromatic color point is still 2048 in the 12-bit case, so no offset is applied in the transformation to compensate for this range reduction.

If, instead of the quantized values, the input is interpreted as fixed-point values in the range 0.0..1.0, as might be the case if the values were treated as unsigned normalized quantities in a computer graphics API, the following conversions can be applied instead:

\begin{align*} G' & = {{G'_{\mathit{norm}}\times (2^n-1)}\over{2^n}} & B' & = {{B'_{\mathit{norm}}\times (2^n-1)}\over{2^n}} & R' & = {{R'_{\mathit{norm}}\times (2^n-1)}\over{2^n}} \\ Y' & = {{Y'_{\mathit{norm}}\times (2^n-1)}\over{2^n}} & C'_B & = {{C'_{\mathit{Bnorm}}\times (2^n-1)}\over{2^n}} - 0.5 & C'_R & = {{C'_{\mathit{Rnorm}}\times (2^n-1)}\over{2^n}} - 0.5 \\ Y'_C & = {{Y_{\mathit{Cnorm}}'\times (2^n-1)}\over{2^n}} & C'_\mathit{CB} & = {{C'_{\mathit{CBnorm}}\times (2^n-1)}\over{2^n}} - 0.5 & C'_\mathit{CR} & = {{C'_{\mathit{CRnorm}}\times (2^n-1)}\over{2^n}} - 0.5 \\ I & = {{I'_{\mathit{norm}}\times (2^n-1)}\over{2^n}} & C'_T & = {{C'_{\mathit{Tnorm}}\times (2^n-1)}\over{2^n}} - 0.5 & C'_P & = {{C'_{\mathit{Pnorm}}\times (2^n-1)}\over{2^n}} - 0.5 \end{align*}
\begin{align*} G_{norm}' & = {{G'\times 2^n}\over{2^n-1}} & B_{norm}' & = {{B'\times 2^n}\over{2^n-1}} & R_{norm}' & = {{R'\times 2^n}\over{2^n-1}} \\ Y_{norm}' & = {{Y'\times 2^n}\over{2^n-1}} & C'_{\mathit{Bnorm}} & = {{(C'_{B} + 0.5)\times 2^n}\over{2^n-1}} & C'_{\mathit{Rnorm}} & = {{(C'_{R} + 0.5)\times 2^n}\over{2^n-1}} \\ Y'_{\mathit{Cnorm}} & = {{Y_{C}'\times 2^n}\over{2^n-1}} & C'_{\mathit{CBnorm}} & = {{(C'_\mathit{CB} + 0.5)\times 2^n}\over{2^n-1}} & C'_{\mathit{CRnorm}} & = {{(C'_\mathit{CR} + 0.5)\times 2^n}\over{2^n-1}} \\ I_{\mathit{norm}} & = {{I'\times 2^n}\over{2^n-1}} & C'_{\mathit{Tnorm}} & = {{(C'_{T} + 0.5)\times 2^n}\over{2^n-1}} & C'_{\mathit{Pnorm}} & = {{(C'_{P} + 0.5)\times 2^n}\over{2^n-1}} \end{align*}

That is, to match the behavior described in these specifications, the inputs to color model conversion should be expanded such that the maximum representable value is that defined by the quantization of these encodings $\left({255\over 256},\ {1023\over 1024}\ \textrm{or}\ {4095\over 4096}\right)$ , and the inverse operation should be applied to the result of the model conversion.

For example, a legacy shader-based JPEG decoder may read values in a normalized 0..1 range, where the in-memory value 0 represents 0.0 and the in-memory value 1 represents 1.0. The decoder should scale the Y′ value by a factor of $255\over 256$ to match the encoding in the JFIF3 document, and $C'_B$ and CR should be scaled by $255\over 256$ and offset by 0.5. After the model conversion matrix has been applied, the R′, G′ and B′ values should be scaled by $256\over 255$ , restoring the ability to represent pure white.

17. Compressed Texture Image Formats

For computer graphics, a number of texture compression schemes exist, which both reduce the overall texture memory footprint and reduce the bandwidth requirements of using the textures. In this context, “texture compression” is distinct from “image compression” in that texture compression schemes are designed to allow efficient random access as part of texture sampling. “Image compression” can further reduce image redundancy by considering the image as a whole, but doing so is impractical for efficient texture access operations.

The common compression schemes are “block-based”, and rely on similarities between nearby texel regions to describe “blocks” of nearby texels in a unit:

• The “S3TC” schemes describe a block of 4×4 RGB texels in terms of a low-precision pair of color “endpoints”, and allow each texel to specify an interpolation point between these endpoints. Alpha channels, if present, may be described similarly or with an explict per-texel alpha value.
• The “RGTC” schemes provide one- and two-channel schemes for interpolating between two “endpoints” per 4×4 texel block, and are intended to provide efficient schemes for normal encoding, complementing the three-channel approach of S3TC.
• “BPTC” schemes offer a number of ways of encoding and interpolating endpoints, and allow the 4×4 texel block to be divided into multiple “subsets” which can be encoded independently, which can be useful for managing different regions with sharp transitions.
• “ETC1” provides ways of encoding 4×4 texel blocks as two regions of 2×4 or 4×2 texels, each of which are specified as a base color; texels are then encoded as offsets relative to these bases, varying by a grayscale offset.
• “ETC2” is a superset of ETC1 and includes additional schemes for color patterns that would fit poorly into ETC1 options.
• “ASTC” allows a wide range of ways of encoding each color block, and supports choosing different block sizes to encode the texture, providing a range of compression ratios; it also supports 3D and HDR textures.

17.1. Terminology

As can be seen above, the compression schemes have a number of features in common — particularly in having a number of endpoints described encoded in some of the bits of the texel block. For consistency and to make the terms more concise, the following descriptions use some slightly unusual terminology:

The value Xnm refers to bit m (starting at 0) of the nth X value. For example, R13 would refer to bit 3 of red value 1 — R, G, B and A (capitalized and italicized) are generally used to refer to color channels. Similarly, R12..3 refers to bits 2..3 of red value 1.

Although unusual, this terminology should be unambiguous (e.g. none of the formats require exponentiation of arguments).

18. S3TC Compressed Texture Image Formats

This description is derived from the EXT_texture_compression_s3tc extension.

Compressed texture images stored using the S3TC compressed image formats are represented as a collection of 4×4 texel blocks, where each block contains 64 or 128 bits of texel data. The image is encoded as a normal 2D raster image in which each 4×4 block is treated as a single pixel. If an S3TC image has a width or height that is not a multiple of four, the data corresponding to texels outside the image are irrelevant and undefined.

When an S3TC image with a width of w, height of h, and block size of blocksize (8 or 16 bytes) is decoded, the corresponding image size (in bytes) is:

\begin{align*} \left\lceil { w \over 4 } \right\rceil \times \left\lceil { h \over 4 } \right\rceil \times blocksize \end{align*}

When decoding an S3TC image, the block containing the texel at offset (x, y) begins at an offset (in bytes) relative to the base of the image of:

\begin{align*} blocksize \times \left( { \left\lceil { w \over 4 } \right\rceil \times \left\lfloor { y \over 4 } \right\rfloor + \left\lfloor { x \over 4 } \right\rfloor } \right) \end{align*}

The data corresponding to a specific texel (x, y) are extracted from a 4×4 texel block using a relative (x, y) value of

\begin{align*} (x \bmod 4,y \bmod 4) \end{align*}

There are four distinct S3TC image formats:

18.1. BC1 with no alpha

Each 4×4 block of texels consists of 64 bits of RGB image data.

Each RGB image data block is encoded as a sequence of 8 bytes, called (in order of increasing address):

\begin{align*} c0_{\mathit{lo}}, c0_{\mathit{hi}}, c1_{\mathit{lo}}, c1_{\mathit{hi}}, \mathit{bits}_0, \mathit{bits}_1, \mathit{bits}_2, \mathit{bits}_3 \end{align*}

The 8 bytes of the block are decoded into three quantities:

\begin{align*} \mathit{color}_0 & = c0_{\mathit{lo}} + c0_{\mathit{hi}} \times 256 \\ \mathit{color}_1 & = c1_{\mathit{lo}} + c1_{\mathit{hi}} \times 256 \\ \mathit{bits} & = \mathit{bits}_0 + 256 \times (\mathit{bits}_1 + 256 \times (\mathit{bits}_2 + 256 \times \mathit{bits}_3)) \end{align*}

color0 and color1 are 16-bit unsigned integers that are unpacked to RGB colors RGB0 and RGB1 as though they were 16-bit unsigned packed pixels with the R channel in the high 5 bits, G in the next 6 bits and B in the low 5 bits:

\begin{align*} \mathit{R}_n & = {{\mathit{color}_n^{15..11}}\over 31} \\ \mathit{G}_n & = {{\mathit{color}_n^{10..5}}\over 63} \\ \mathit{B}_n & = {{\mathit{color}_n^{4..0}}\over 31} \end{align*}

bits is a 32-bit unsigned integer, from which a two-bit control code is extracted for a texel at location (x, y) in the block using:

\begin{align*} \mathit{code}(x,y) & = \mathit{bits}[2\times (4\times y+x)+1\ \dots\ 2\times(4\times y+x)+0] \end{align*}

where bits[31] is the most significant and bits[0] is the least significant bit.

The RGB color for a texel at location (x, y) in the block is given in Table 44.

Table 44. Block decoding for BC1

Texel value Condition

RGB0

color0 > color1 and code(x, y) = 0

RGB1

color0 > color1 and code(x, y) = 1

$(2\times \mathit{RGB}_0 + \mathit{RGB}_1)\over 3$

color0 > color1 and code(x, y) = 2

$(\mathit{RGB}_0 + 2\times RGB_1)\over 3$

color0 > color1 and code(x, y) = 3

RGB0

color0color1 and code(x, y) = 0

RGB1

color0color1 and code(x, y) = 1

$(\mathit{RGB}_0+\mathit{RGB}_1)\over 2$

color0color1 and code(x, y) = 2

BLACK

color0color1 and code(x, y) = 3

Arithmetic operations are done per component, and BLACK refers to an RGB color where red, green, and blue are all zero.

Since this image has an RGB format, there is no alpha component and the image is considered fully opaque.

18.2. BC1 with alpha

Each 4×4 block of texels consists of 64 bits of RGB image data and minimal alpha information. The RGB components of a texel are extracted in the same way as BC1 with no alpha.

The alpha component for a texel at location (x, y) in the block is given by Table 45.

Table 45. BC1 with alpha

Alpha value Condition

0.0

color0color1 and code(x, y) = 3

1.0

otherwise

The red, green, and blue components of any texels with a final alpha of 0 should be encoded as zero (black).

 Figure 17 shows an example BC1 texel block: color0, encoded as $\left({{29}\over{31}}, {{60}\over{63}}, {{1}\over{31}}\right)$ , and color1, encoded as $\left({{20}\over{31}}, {{2}\over{63}}, {{30}\over{31}}\right)$ , are shown as circles. The interpolated values are shown as small diamonds. Since 29 > 20, there are two interpolated values, accessed when code(x, y) = 2 and code(x, y) = 3.Figure 18 shows the example BC1 texel block with the colors swapped: color0, encoded as $\left({{20}\over{31}}, {{2}\over{63}}, {{30}\over{31}}\right)$ , and color1, encoded as $\left({{29}\over{31}}, {{60}\over{63}}, {{1}\over{31}}\right)$ , are shown as circles. The interpolated value is shown as a small diamonds. Since 20 ≤ 29, there is one interpolated value for code(x, y) = 2, and code(x, y) = 3 represents (R, G, B) = (0, 0, 0).If the format is BC1 with alpha, code(x, y) = 3 is transparent (alpha = 0). If the format is BC1 with no alpha, code(x, y) = 3 represents opaque black.

18.3. BC2

Each 4×4 block of texels consists of 64 bits of uncompressed alpha image data followed by 64 bits of RGB image data.

Each RGB image data block is encoded according to the BC1 formats, with the exception that the two code bits always use the non-transparent encodings. In other words, they are treated as though color0 > color1, regardless of the actual values of color0 and color1.

Each alpha image data block is encoded as a sequence of 8 bytes, called (in order of increasing address):

\begin{align*} a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7 \end{align*}

The 8 bytes of the block are decoded into one 64-bit integer:

\begin{align*} \mathit{alpha} & = a_0 + 256 \times (a_1 + 256 \times (a_2 + 256 \times (a_3 + 256 \times (a_4 + 256 \times (a_5 + 256 \times (a_6 + 256 \times a_7)))))) \end{align*}

alpha is a 64-bit unsigned integer, from which a four-bit alpha value is extracted for a texel at location (x, y) in the block using:

\begin{align*} \mathit{alpha}(x,y) & = \mathit{bits}[4\times(4\times y+x)+3 \dots 4\times(4\times y+x)+0] \end{align*}

where bits[63] is the most significant and bits[0] is the least significant bit.

The alpha component for a texel at location (x, y) in the block is given by $\mathit{alpha}(x,y)\over 15$ .

18.4. BC3

Each 4×4 block of texels consists of 64 bits of compressed alpha image data followed by 64 bits of RGB image data.

Each RGB image data block is encoded according to the BC1 formats, with the exception that the two code bits always use the non-transparent encodings. In other words, they are treated as though color0 > color1, regardless of the actual values of color0 and color1.

Each alpha image data block is encoded as a sequence of 8 bytes, called (in order of increasing address):

\begin{align*} \mathit{alpha}_0, \mathit{alpha}_1, \mathit{bits}_0, \mathit{bits}_1, \mathit{bits}_2, \mathit{bits}_3, \mathit{bits}_4, \mathit{bits}_5 \end{align*}

The alpha0 and alpha1 are 8-bit unsigned bytes converted to alpha components by multiplying by $1\over 255$ .

The 6 bits bytes of the block are decoded into one 48-bit integer:

\begin{align*} \mathit{bits} & = \mathit{bits}_0 + 256 \times (\mathit{bits}_1 + 256 \times (\mathit{bits}_2 + 256 \times (\mathit{bits}_3 + 256 \times (\mathit{bits}_4 + 256 \times \mathit{bits}_5)))) \end{align*}

bits is a 48-bit unsigned integer, from which a three-bit control code is extracted for a texel at location (x, y) in the block using:

\begin{align*} \mathit{code}(x,y) & = \mathit{bits}[3\times(4\times y+x)+2 \dots 3\times(4\times y+x)+0] \end{align*}

where bits[47] is the most-significant and bits[0] is the least-significant bit.

The alpha component for a texel at location (x, y) in the block is given by Table 46.

Table 46. Alpha encoding for BC3 blocks

Alpha value Condition

alpha0

code(x, y) = 0

alpha1

code(x, y) = 1

$(6\times\mathit{alpha}_0 + 1\times\mathit{alpha}_1)\over 7$

alpha0 > alpha1 and code(x, y) = 2

$(5\times\mathit{alpha}_0 + 2\times\mathit{alpha}_1)\over 7$

alpha0 > alpha1 and code(x, y) = 3

$(4\times\mathit{alpha}_0 + 3\times\mathit{alpha}_1)\over 7$

alpha0 > alpha1 and code(x, y) = 4

$(3\times\mathit{alpha}_0 + 4\times\mathit{alpha}_1)\over 7$

alpha0 > alpha1 and code(x, y) = 5

$(2\times\mathit{alpha}_0 + 5\times\mathit{alpha}_1)\over 7$

alpha0 > alpha1 and code(x, y) = 6

$(1\times\mathit{alpha}_0 + 6\times\mathit{alpha}_1)\over 7$

alpha0 > alpha1 and code(x, y) = 7

$(4\times\mathit{alpha}_0 + 1\times\mathit{alpha}_1)\over 5$

alpha0alpha1 and code(x, y) = 2

$(3\times\mathit{alpha}_0 + 2\times\mathit{alpha}_1)\over 5$

alpha0alpha1 and code(x, y) = 3

$(2\times\mathit{alpha}_0 + 3\times\mathit{alpha}_1)\over 5$

alpha0alpha1 and code(x, y) = 4

$(1\times\mathit{alpha}_0 + 4\times\mathit{alpha}_1)\over 5$

alpha0alpha1 and code(x, y) = 5

0.0

alpha0alpha1 and code(x, y) = 6

1.0

alpha0alpha1 and code(x, y) = 7

19. RGTC Compressed Texture Image Formats

This description is derived from the “RGTC Compressed Texture Image Formats” section of the OpenGL 4.5 specification.

Compressed texture images stored using the RGTC compressed image encodings are represented as a collection of 4×4 texel blocks, where each block contains 64 or 128 bits of texel data. The image is encoded as a normal 2D raster image in which each 4×4 block is treated as a single pixel. If an RGTC image has a width or height that is not a multiple of four, the data corresponding to texels outside the image are irrelevant and undefined.

When an RGTC image with a width of w, height of h, and block size of blocksize (8 or 16 bytes) is decoded, the corresponding image size (in bytes) is:

\begin{align*} \left\lceil { w \over 4 } \right\rceil \times \left\lceil { h \over 4 } \right\rceil \times \mathit{blocksize} \end{align*}

When decoding an RGTC image, the block containing the texel at offset $(x,y)$ begins at an offset (in bytes) relative to the base of the image of:

\begin{align*} \mathit{blocksize} \times \left( { \left\lceil { w \over 4 } \right\rceil \times \left\lfloor { y \over 4 } \right\rfloor + \left\lfloor { x \over 4 } \right\rfloor } \right) \end{align*}

The data corresponding to a specific texel (x, y) are extracted from a 4×4 texel block using a relative (x, y) value of

\begin{align*} (x \bmod 4,y \bmod 4) \end{align*}

There are four distinct RGTC image formats described in the following sections.

19.1. BC4 unsigned

Each 4×4 block of texels consists of 64 bits of unsigned red image data.

Each red image data block is encoded as a sequence of 8 bytes, called (in order of increasing address):

\begin{align*} \mathit{red}_0, \mathit{red}_1, \mathit{bits}_0, \mathit{bits}_1, \mathit{bits}_2, \mathit{bits}_3, \mathit{bits}_4, \mathit{bits}_5 \end{align*}

The 6 bits{0..5} bytes of the block are decoded into a 48-bit bit vector:

\begin{align*} \mathit{bits} & = \mathit{bits}_0 + 256 \times \left( { \mathit{bits}_1 + 256 \times \left( { \mathit{bits}_2 + 256 \times \left( { \mathit{bits}_3 + 256 \times \left( { \mathit{bits}_4 + 256 \times \mathit{bits}_5 } \right) } \right) } \right) } \right) \end{align*}

red0 and red1 are 8-bit unsigned integers that are unpacked to red values RED0 and RED1 by multiplying by $1\over 255$ .

bits is a 48-bit unsigned integer, from which a three-bit control code is extracted for a texel at location (x, y) in the block using:

\begin{align*} \mathit{code}(x,y) & = \mathit{bits} \left[ 3 \times (4 \times y + x) + 2 \dots 3 \times (4 \times y + x) + 0 \right] \end{align*}

where bits[47] is the most-significant and bits[0] is the least-significant bit.

The red value R for a texel at location (x, y) in the block is given by Table 47.

Table 47. Block decoding for BC4

R value Condition

RED0

red0 > red1, code(x, y) = 0

RED1

red0 > red1, code(x, y) = 1

${ 6 \times \mathit{RED}_0 + \mathit{RED}_1 } \over 7$

red0 > red1, code(x, y) = 2

${ 5 \times \mathit{RED}_0 + 2 \times \mathit{RED}_1 } \over 7$

red0 > red1, code(x, y) = 3

${ 4 \times \mathit{RED}_0 + 3 \times \mathit{RED}_1 } \over 7$

red0 > red1, code(x, y) = 4

${ 3 \times \mathit{RED}_0 + 4 \times \mathit{RED}_1 } \over 7$

red0 > red1, code(x, y) = 5

${ 2 \times \mathit{RED}_0 + 5 \times \mathit{RED}_1 } \over 7$

red0 > red1, code(x, y) = 6

${ \mathit{RED}_0 + 6 \times \mathit{RED}_1 } \over 7$

red0 > red1, code(x, y) = 7

RED0

red0red1, code(x, y) = 0

RED1

red0red1, code(x, y) = 1

${ 4 \times \mathit{RED}_0 + \mathit{RED}_1 } \over 5$

red0red1, code(x, y) = 2

${ 3 \times \mathit{RED}_0 + 2 \times \mathit{RED}_1 } \over 5$

red0red1, code(x, y) = 3

${ 2 \times \mathit{RED}_0 + 3 \times \mathit{RED}_1 } \over 5$

red0red1, code(x, y) = 4

${ \mathit{RED}_0 + 4 \times \mathit{RED}_1 } \over 5$

red0red1, code(x, y) = 5

REDmin

red0red1, code(x, y) = 6

REDmax

red0red1, code(x, y) = 7

REDmin and REDmax are 0.0 and 1.0 respectively.

Since the decoded texel has a red format, the resulting RGBA value for the texel is (R, 0, 0, 1).

19.2. BC4 signed

Each 4×4 block of texels consists of 64 bits of signed red image data. The red values of a texel are extracted in the same way as BC4 unsigned except red0, red1, RED0, RED1, REDmin, and REDmax are signed values defined as follows:

\begin{align*} \mathit{RED}_0 & = \begin{cases} {\mathit{red}_0 \over 127.0}, & \mathit{red}_0 > -128 \\ -1.0, & \mathit{red}_0 = -128 \end{cases} \\ \mathit{RED}_1 & = \begin{cases} {\mathit{red}_1 \over 127.0}, & \mathit{red}_1 > -128 \\ -1.0, & \mathit{red}_1 = -128 \end{cases} \\ \mathit{RED}_{\mathit{min}} & = -1.0 \\ \mathit{RED}_{\mathit{max}} & = 1.0 \end{align*}

red0 and red1 are 8-bit signed (two’s complement) integers.

CAVEAT: For signed red0 and red1 values: the expressions red0 > red1 and red0red1 above are considered undefined (read: may vary by implementation) when red0 = -127 and red1 = -128. This is because if red0 were remapped to -127 prior to the comparison to reduce the latency of a hardware decompressor, the expressions would reverse their logic. Encoders for the signed red-green formats should avoid encoding blocks where red0 = -127 and red1 = -128.

19.3. BC5 unsigned

Each 4×4 block of texels consists of 64 bits of compressed unsigned red image data followed by 64 bits of compressed unsigned green image data.

The first 64 bits of compressed red are decoded exactly like BC4 unsigned above. The second 64 bits of compressed green are decoded exactly like BC4 unsigned above except the decoded value R for this second block is considered the resulting green value G.

Since the decoded texel has a red-green format, the resulting RGBA value for the texel is (R, G, 0, 1).

19.4. BC5 signed

Each 4×4 block of texels consists of 64 bits of compressed signed red image data followed by 64 bits of compressed signed green image data.

The first 64 bits of compressed red are decoded exactly like BC4 signed above. The second 64 bits of compressed green are decoded exactly like BC4 signed above except the decoded value R for this second block is considered the resulting green value G.

Since this image has a red-green format, the resulting RGBA value is (R, G, 0, 1).

20. BPTC Compressed Texture Image Formats

This description is derived from the “BPTC Compressed Texture Image Formats” section of the OpenGL 4.5 specification. More information on BC7, BC7 modes and BC6h can be found in Microsoft’s online documentation.

Compressed texture images stored using the BPTC compressed image formats are represented as a collection of 4×4 texel blocks, each of which contains 128 bits of texel data stored in little-endian order. The image is encoded as a normal 2D raster image in which each 4×4 block is treated as a single pixel. If a BPTC image has a width or height that is not a multiple of four, the data corresponding to texels outside the image are irrelevant and undefined. When a BPTC image with width w, height h, and block size blocksize (16 bytes) is decoded, the corresponding image size (in bytes) is:

\begin{align*} \left\lceil { w \over 4 } \right\rceil \times \left\lceil { h \over 4 } \right\rceil \times blocksize \end{align*}

When decoding a BPTC image, the block containing the texel at offset (x, y) begins at an offset (in bytes) relative to the base of the image of:

\begin{align*} blocksize \times \left( { \left\lceil { w \over 4 } \right\rceil \times \left\lfloor { y \over 4 } \right\rfloor + \left\lfloor { x \over 4 } \right\rfloor } \right) \end{align*}

The data corresponding to a specific texel (x, y) are extracted from a 4×4 texel block using a relative (x, y) value of:

\begin{align*} (x \bmod 4,y \bmod 4) \end{align*}

There are two distinct BPTC image formats each of which has two variants. BC7 with or without an sRGB transform function used in the encoding of the RGB channels compresses 8-bit unsigned, normalized fixed-point data. BC6H in signed or unsigned form compresses high dynamic range floating-point values. The formats are similar, so the description of the BC6H format will reference significant sections of the BC7 description.

20.1. BC7

Each 4×4 block of texels consists of 128 bits of RGBA image data, of which the RGB channels may be encoded linearly or with the sRGB transfer function.

Each block contains enough information to select and decode a number of colors called endpoints, pairs of which forms subsets, then to interpolate between those endpoints in a variety of ways, and finally to remap the result into the final output by indexing into these interpolated values according to a partition layout which maps each relative coordinate to a subset.

Each block can contain data in one of eight modes. The mode is identified by the lowest bits of the lowest byte. It is encoded as zero or more zeros followed by a one. For example, using ‘x’ to indicate a bit not included in the mode number, mode 0 is encoded as xxxxxxx1 in the low byte in binary, mode 5 is xx100000, and mode 7 is 10000000. Encoding the low byte as zero is reserved and should not be used when encoding a BPTC texture; hardware decoders processing a texel block with a low byte of 0 should return 0 for all channels of all texels.

All further decoding is driven by the values derived from the mode listed in Table 48 and Table 49. The fields in the block are always in the same order for all modes. In increasing bit order after the mode, these fields are: partition pattern selection, rotation, index selection, color, alpha, per-endpoint P-bit, shared P-bit, primary indices, and secondary indices. The number of bits to be read in each field is determined directly from these tables, as shown in Table 50.

 Per texel block, CB = 3(each of R, G, B)×2(endpoints)×NS(#subsets)×CB(bits/channel/endpoint).AB = 2(endpoints)×NS(#subsets)×AB(bits/endpoint). {IB,IB2} = 16(texels)×{IB,IB2}(#index bits/texel) - NS(1bit/subset).

Table 48. Mode-dependent BPTC parameters

 Mode NS PB RB ISB CB AB EPB SPB IB IB2 M CB AB EPB SPB IB IB2 Bits per… …texel block …channel/endpoint …endpoint …subset …texel Bits per texel block (total) 0 3 4 0 0 4 0 1 0 3 0 1 72 0 6 0 45 0 1 2 6 0 0 6 0 0 1 3 0 2 72 0 0 2 46 0 2 3 6 0 0 5 0 0 0 2 0 3 90 0 0 0 29 0 3 2 6 0 0 7 0 1 0 2 0 4 84 0 4 0 30 0 4 1 0 2 1 5 6 0 0 2 3 5 30 12 0 0 31 47 5 1 0 2 0 7 8 0 0 2 2 6 42 16 0 0 31 31 6 1 0 0 0 7 7 1 0 4 0 7 42 14 2 0 63 0 7 2 6 0 0 5 5 1 0 2 0 8 60 20 4 0 30 0

Table 49. Full descriptions of the BPTC mode columns

 M Mode identifier bits NS Number of subsets PB Partition selection bits RB Rotation bits ISB Index selection bit CB Color bits AB Alpha bits EPB Endpoint P-bits (all channels) SPB Shared P-bits IB Index bits IB2 Secondary index bits

Each block can be divided into between 1 and 3 groups of pixels called subsets, which have different endpoints. There are two endpoint colors per subset, grouped first by endpoint, then by subset, then by channel. For example, mode 1, with two subsets and six color bits, would have six bits of red for endpoint 0 of the first subset, then six bits of red for endpoint 1, then the two ends of the second subset, then green and blue stored similarly. If a block has any alpha bits, the alpha data follows the color data with the same organization. If not, alpha is overridden to 255. These bits are treated as the high bits of a fixed-point value in a byte for each color channel of the endpoints: {ER7..0, EG7..0, EB7..0, EA7..0} per endpoint. If the mode has shared P-bits, there are two endpoint bits, the lower of which applies to both endpoints of subset 0 and the upper of which applies to both endpoints of subset 1. If the mode has per-endpoint P-bits, then there are 2 × subsets P-bits stored in the same order as color and alpha. Both kinds of P-bits are added as a bit below the color data stored in the byte. So, for mode 1 with six red bits, the P-bit ends up in bit 1. For final scaling, the top bits of the value are replicated into any remaining bits in the byte. For the example of mode 1, bit 7 (which originated as bit 5 of the 6-bit encoded channel) would be replicated to bit 0. Table 51 and Table 52 show the origin of each endpoint color bit for each mode.

Table 50. Bit layout for BC7 modes (LSB..MSB)

 Mode  0 0: M0 = 1 1..4: PB0..3 5..8: R00..3 9..12: R10..3 13..16: R20..3 17..20: R30..3 21..24: R40..3 25..28: R50..3 29..32: G00..3 33..36: G10..3 37..40: G20..3 41..44: G30..3 45..48: G40..3 49..52: G50..3 53..56: B00..3 57..60: B10..3 61..64: B20..3 65..68: B30..3 69..72: B40..3 73..76: B50..3 77: EPB00 78: EPB10 79: EPB20 80: EPB30 81: EPB40 82: EPB50 83..127: IB0..44 Mode  1 0..1: M0..1 = 01 2..7: PB0..5 8..13: R00..5 14..19: R10..5 20..25: R20..5 26..31: R30..5 32..37: G00..5 38..43: G10..5 44..49: G20..5 50..55: G30..5 56..61: B00..5 62..67: B10..5 68..73: B20..5 74..79: B30..5 80: SPB00 81: SPB10 82..127: IB0..45 Mode  2 0..2: M0..2 = 001 3..8: PB0..5 9..13: R00..4 14..18: R10..4 19..23: R20..4 24..28: R40..4 29..33: R40..4 34..38: R50..4 39..43: G00..4 44..48: G10..4 49..53: G20..4 54..58: G40..4 59..63: G40..4 64..68: G50..4 69..73: B00..4 74..78: B10..4 79..83: B20..4 84..88: B40..4 89..93: B40..4 94..98: B50..4 99..127: IB0..28 Mode  3 0..3: M0..3 = 0001 4..9: PB0..5 10..16: R00..6 17..23: R10..6 24..30: R20..6 31..37: R30..6 38..44: G00..6 45..51: G10..6 52..58: G20..6 59..65: G30..6 66..72: B00..6 73..79: B10..6 80..86: B20..6 87..93: B30..6 94: EPB00 95: EPB10 96: EPB20 97: EPB30 98..127: IB0..29 Mode  4 0..4: M0..4 = 00001 5..6: RB0..1 7: ISB0 8..12: R00..4 13..17: R10..4 18..22: G00..4 23..27: G10..4 28..32: B00..4 33..37: B10..4 38..43: A00..5 44..49: A10..5 50..80: IB0..30 81..127: IB20..46 Mode  5 0..5: M0..5 = 000001 6..7: RB0..1 8..14: R00..6 15..21: R10..6 22..28: G00..6 29..34: G10..6 35..41: B00..6 42..49: B10..6 50..57: A00..7 58..65: A10..7 66..96: IB0..30 97..127: IB20..30 Mode  6 0..6: M0..6 = 0000001 7..13: R00..6 14..20: R10..6 21..27: G00..6 28..34: G10..6 35..41: B00..6 42..48: B10..6 49..55: A00..6 56..62: A10..6 63: EPB00 64: EPB10 65..127: IB0..62 Mode  7 0..7: M0..7 = 00000001 8..13: PB0..5 14..18: R00..4 19..23: R10..4 24..28: R20..4 29..33: R30..4 34..38: G00..4 39..43: G10..4 44..48: G20..4 49..53: G30..4 54..58: B00..4 59..63: B10..4 64..68: B20..4 69..73: B30..4 74..78: A00..4 79..83: A10..4 84..88: A20..4 89..93: A30..4 94: EPB00 95: EPB10 96: EPB20 97: EPB30 98..127: IB0..29

Table 51. Bit sources for BC7 endpoints (modes 0..2, MSB..LSB per channel)

 Mode 0 ER07..0 EG07..0 EB07..0 EA07..0 8 7 6 5 77 8 7 6 32 31 30 29 77 32 31 30 56 55 54 53 77 56 55 54 255 ER17..0 EG17..0 EB17..0 EA17..0 12 11 10 9 78 12 11 10 36 35 34 33 78 36 35 34 60 59 58 57 78 60 59 58 255 ER27..0 EG27..0 EB27..0 EA27..0 16 15 14 13 79 16 15 14 40 39 38 37 79 40 39 38 64 63 62 61 79 64 63 62 255 ER37..0 EG37..0 EB37..0 EA37..0 20 19 18 17 80 20 19 18 44 43 42 41 80 44 43 42 68 67 66 65 80 68 67 66 255 ER47..0 EG47..0 EB47..0 EA47..0 24 23 22 21 81 24 23 22 48 47 46 45 81 48 47 46 72 71 70 69 81 72 71 70 255 ER57..0 EG57..0 EB57..0 EA57..0 28 27 26 25 82 28 27 26 52 51 50 49 82 52 51 50 76 75 74 73 82 76 75 74 255 Mode 1 ER07..0 EG07..0 EB07..0 EA07..0 13 12 11 10 9 8 80 13 37 36 35 34 33 32 80 37 61 60 59 58 57 56 80 61 255 ER17..0 EG17..0 EB17..0 EA17..0 19 18 17 16 15 14 80 19 43 42 41 40 39 38 80 43 67 66 65 64 63 62 80 67 255 ER27..0 EG27..0 EB27..0 EA27..0 25 24 23 22 21 20 81 25 49 48 47 46 45 44 81 49 73 72 71 70 69 68 81 73 255 ER37..0 EG37..0 EB37..0 EA37..0 31 30 29 28 27 26 81 31 55 54 53 52 51 50 81 55 79 78 77 76 75 74 81 79 255 Mode 2 ER07..0 EG07..0 EB07..0 EA07..0 13 12 11 10 9 13 12 11 43 42 41 40 39 43 42 41 73 72 71 70 69 73 72 71 255 ER17..0 EG17..0 EB17..0 EA17..0 18 17 16 15 14 18 17 16 48 47 46 45 44 48 47 46 78 77 76 75 74 78 77 76 255 ER27..0 EG27..0 EB27..0 EA27..0 23 22 21 20 19 23 22 21 53 52 51 50 49 53 52 51 83 82 81 80 79 83 82 81 255 ER37..0 EG37..0 EB37..0 EA37..0 28 27 26 25 24 28 27 26 58 57 56 55 54 58 57 56 88 87 86 85 84 88 87 86 255 ER47..0 EG47..0 EB47..0 EA47..0 33 32 31 30 29 33 32 31 63 62 61 60 59 63 62 61 93 92 91 90 89 93 92 91 255 ER57..0 EG57..0 EB57..0 EA57..0 38 37 36 35 34 38 37 36 68 67 66 65 64 68 67 66 98 97 96 95 94 98 97 96 255

Table 52. Bit sources for BC7 endpoints (modes 3..7, MSB..LSB per channel)

 Mode 3 ER07..0 EG07..0 EB07..0 EA07..0 16 15 14 13 12 11 10 94 44 43 42 41 40 39 38 94 72 71 70 69 68 67 66 94 255 ER17..0 EG17..0 EB17..0 EA17..0 23 22 21 20 19 18 17 95 51 50 49 48 47 46 45 95 79 78 77 76 75 74 73 95 255 ER27..0 EG27..0 EB27..0 EA27..0 30 29 28 27 26 25 24 96 58 57 56 55 54 53 52 96 86 85 84 83 82 81 80 96 255 ER37..0 EG37..0 EB37..0 EA37..0 37 36 35 34 33 32 31 97 65 64 63 62 61 60 59 97 93 92 91 90 89 88 87 97 255 Mode 4 ER07..0 EG07..0 EB07..0 EA07..0 12 11 10 9 8 12 11 10 22 21 20 19 18 22 21 20 32 31 30 29 28 32 31 30 43 42 41 40 39 38 43 42 ER17..0 EG17..0 EB17..0 EA17..0 17 16 15 14 13 17 16 15 27 26 25 24 23 27 26 25 37 36 35 34 33 37 36 35 49 48 47 46 45 44 49 48 Mode 5 ER07..0 EG07..0 EB07..0 EA07..0 14 13 12 11 10 9 8 14 28 27 26 25 24 23 22 28 42 41 40 39 38 37 36 42 57 56 55 54 53 52 51 50 ER17..0 EG17..0 EB17..0 EA17..0 21 20 19 18 17 16 15 21 35 34 33 32 31 30 29 35 49 48 47 46 45 44 43 49 65 64 63 62 61 60 59 58 Mode 6 ER07..0 EG07..0 EB07..0 EA07..0 13 12 11 10 9 8 7 63 27 26 25 24 23 22 21 63 41 40 39 38 37 36 35 63 55 54 53 52 51 50 49 63 ER17..0 EG17..0 EB17..0 EA17..0 20 19 18 17 16 15 14 64 34 33 32 31 30 29 28 64 48 47 46 45 44 43 42 64 62 61 60 59 58 57 56 64 Mode 7 ER07..0 EG07..0 EB07..0 EA07..0 18 17 16 15 14 94 18 17 38 37 36 35 34 94 38 37 58 57 56 55 54 94 58 57 78 77 76 75 74 94 78 77 ER17..0 EG17..0 EB17..0 EA17..0 23 22 21 20 19 95 23 22 43 42 41 40 39 95 43 42 63 62 61 60 59 95 63 62 83 82 81 80 79 95 83 82 ER27..0 EG27..0 EB27..0 EA27..0 28 27 26 25 24 96 28 27 48 47 46 45 44 96 48 47 68 67 66 65 64 96 68 67 88 87 86 85 84 96 88 87 ER37..0 EG37..0 EB37..0 EA37..0 33 32 31 30 29 97 33 32 53 52 51 50 49 97 53 52 73 72 71 70 69 97 73 72 93 92 91 90 89 97 93 92

A texel in a block with one subset is always considered to be in subset zero. Otherwise, a number encoded in the partition bits is used to look up a partition pattern in Table 53 or Table 54 for 2 subsets and 3 subsets respectively. This partition pattern is accessed by the relative x and y offsets within the block to determine the subset which defines the pixel at these coordinates.

The endpoint colors are interpolated using index values stored in the block. The index bits are stored in y-major order. That is, the bits for the index value corresponding to a relative (x, y) position of (0, 0) are stored in increasing order in the lowest index bits of the block (but see the next paragraph about anchor indices), the next bits of the block in increasing order store the index bits of (1, 0), followed by (2, 0) and (3, 0), then (0, 1) etc.

Each index has the number of bits indicated by the mode except for one special index per subset called the anchor index. Since the interpolation scheme between endpoints is symmetrical, we can save one bit on one index per subset by ordering the endpoints such that the highest bit for that index is guaranteed to be zero — and not storing that bit.

Each anchor index corresponds to an index in the corresponding partition number in Table 53 or Table 54, and are indicated in bold italics in those tables. In partition zero, the anchor index is always index zero — that is, at a relative position of (0,0) (as can be seen in Table 53 and Table 54, index 0 always corresponds to partition zero). In other partitions, the anchor index is specified by Table 55, Table 56, and Table 57.

 In summary, the bit offset for index data with relative x,y coordinates within the texel block is:\begin{align*} \textrm{index offset}_{x,y} &= \begin{cases} 0, & x = y = 0 \\ \textrm{IB} \times (x + 4\times y) - 1, & \textrm{NS} = 1,\ 0 < x + 4\times y \\ \textrm{IB} \times (x + 4\times y) - 1, & \textrm{NS} = 2,\ 0 < x + 4\times y \leq \textrm{anchor}_2[\mathit{part}] \\ \textrm{IB} \times (x + 4\times y) - 2, & \textrm{NS} = 2,\ \textrm{anchor}_2[\mathit{part}] < x + 4\times y \\ \textrm{IB} \times (x + 4\times y) - 1, & \textrm{NS} = 3,\ 0 < x + 4\times y \leq \textrm{anchor}_{3,2}[\mathit{part}],\ x + 4\times y \leq \textrm{anchor}_{3,2}[\mathit{part}]\\ \textrm{IB} \times (x + 4\times y) - 3, & \textrm{NS} = 3,\ x + 4\times y > \textrm{anchor}_{3,2}[\mathit{part}],\ x + 4\times y > \textrm{anchor}_{3,3}[\mathit{part}] \\ \textrm{IB} \times (x + 4\times y) - 2, & \textrm{NS} = 3,\ \textrm{otherwise} \\ \end{cases} \\ \end{align*}where anchor2 is Table 55, anchor3,2 is Table 56, anchor3,3 is Table 57, and part is encoded in the partition selection bits PB.

If secondary index bits are present, they follow the primary index bits and are read in the same manner. The anchor index information is only used to determine the number of bits each index has when read from the block data.

The endpoint color and alpha values used for final interpolation are the decoded values corresponding to the applicable subset as selected above. The index value for interpolating color comes from the secondary index bits for the texel if the mode has an index selection bit and its value is one, and from the primary index bits otherwise. The alpha index comes from the secondary index bits if the block has a secondary index and the block either doesn’t have an index selection bit or that bit is zero, and from the primary index bits otherwise.

 As an example of the texel decode process, consider a block encoded with mode 2 — that is, M0 = 0, M1 = 0, M2 = 1. This mode has three subsets, so Table 54 is used to determine which subset applies to each texel. Let us assume that this block has partition pattern 6 encoded in the partition selection bits, and that we wish to decode the texel at relative (x, y) offset (1, 2) — that is, index 9 in y-major order. We can see from Table 54 that this texel is partitioned into subset 1 (the second of three), and therefore by endpoints 2 and 3. Mode 2 stores two index bits per texel, except for index 0 (which is the anchor index for subset 0), index 15 (for subset 1, as indicated in Table 56) and index 3 (for subset 2, as indicated in Table 57). Index 9 is therefore stored in two bits starting at index bits offset 14 (for indices 1..2 and 4..8) plus 2 (for indices 0 and 3) — a total of 16 bit offset into the index bits or, as seen in Table 50, bits 115 and 116 of the block. These two bits are used to interpolate between endpoints 2 and 3 using Equation 1 with weights from the two-bit index row of Table 58, as described below.

Table 53. Partition table for 2-subset BPTC, with the 4×4 block of values for each partition number

 0 1 2 3 4 5 6 7 0 0 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 8 9 10 11 12 13 14 15 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0