OCD is a set of Open Color format Definitions.

Color formats are used in everything from BLTers to video codecs, and from cameras to displays.  But although there are plenty of common formats, the definition of the code specifying them is never the same.

OCD attempts to solve this problem.  It provides logical color format codes, and is extensible.


CC BY-ND

License

The definitions are designed and maintained by Texas Instruments, Inc., but anyone is free to use them with no cost or obligation.

This project is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License.


Source

Get the source code on GitHub at graphics/ocd, or download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/graphics/ocd

Wiki
https://github.com/graphics/ocd/wiki

Header File

ocd.h contains the Open Color format Definitions.

How does it work?

OCD was designed to allow a single 32-bit word (int) to specify the color format.  The color format is specified as an enumeration.  The enumeration values are constructed using bitfields.

OCD breaks off a chunk of those 32 bits to specify a vendor ID.  With this, OCD can allow vendors with very unique formats to obtain their own vendor ID and specify any of 16 million formats of their own.  Minimum sharing here, but maximum flexibility.

OCDFMTDEF_VENDOR_ALL

The power of OCD lies in the shared vendor ID.  The OCDFMTDEF_VENDOR_ALL vendor ID indicates that the common set of definitions is being used.  And this set of definitions is designed to specify pretty much any reasonably common color format in use today.

When OCDFMTDEF_VENDOR_ALL is chosen, the remaining 24 bits of the format are sub-divided into bitfields used to describe the format.

Predefined Names

A set of enumeration values are already provided with predefined names.  It is easiest for clients to use these predefined values.  They already cover most of the formats likely to be encountered.

NOTE:  The naming conventions of the predefined formats are based on their byte ordering, so they are not endian-dependent.  The exceptions are the 16-bit packed formats, which are little-endian.

Some examples:

OCDFMT_RGB24 is a format where each pixel consists of 3 bytes (24 bits).  The first byte in memory (at address A, read as a byte) is the red component.  The second byte in memory (at address A+1, read as a byte) is the green component.  The third byte in memory (at address A+2, read as a byte) is the blue component.

OCDFMT_xRGB24 is a format where each pixel consists of 4 bytes (32 bits), but only 3 of these (24 bits) contain color information.  The remaining 8 bits are ignored on a read, or filled with 0s on a write.

If the format of interest is not already specified, it is still likely that the format is supported by the VENDOR_ALL design.  Using the bitfields below, new combinations can be constructed.  These combinations are already legal, but they just have not been given names.  Users of OCD can define their own names in a separate header file and include it using the OCD_EXTERNAL_INCLUDE mechanism:

file: myocdfmts.h

MYOCDFMT_ALPHAMONO8 = OCDFMT_MONO8 |
                      OCDFMTDEF_ALPHA,

file:  mysource.c

#define OCD_EXTERNAL_INCLUDE "myocdfmts.h"
#include <ocd.h>

VENDOR_ALL Bitfields

The following bitfields only apply to the OCDFMTDEF_VENDOR_ALL color formats.

Color Space

The first field specifies the color space.  Currently there are five color spaces defined, but there is room for three more if the need arises:

Once the color space has been selected, the remaining bits depend on that choice:

OCDFMTDEF_CS_MONO

31:24 23:21 20:19 18 17 16 15:14 13:11 10 9 8:6 5:0
00000000 000 reserved
(00)
alpha non-premult/
fill empty 0
reserved
(0)
reserved
(0)
reserved
(0)
reversed reserved
(0)
container
size
color
bits-1

OCDFMTDEF_CS_LUT

31:24 23:21 20:19 18 17 16 15:14 13:11 10 9 8:6 5:0
00000000 001 reserved
(00)
reserved
(0)
reserved
(0)
reserved
(0)
reserved
(0)
reserved
(0)
reversed reserved
(0)
container
size
color
bits-1

OCDFMTDEF_CS_RGB

31:24 23:21 20:19 18 17 16 15:14 13:11 10 9 8:6 5:0
00000000 010 reserved
(00)
alpha non-premult/
fill empty 0
reserved
(0)
reserved
(00)
layout reversed left
justified
container
size
color
bits-1

OCDFMTDEF_CS_YCbCr

31:24 23:21 20:19 18 17 16 15:14 13:11 10 9 8:6 5:0
00000000 011 standard alpha non-premult/
fill empty 0
subsample
position
subsampling layout reversed left
justified
container
size
color
bits-1

OCDFMTDEF_CS_ALPHA

31:24 23:21 20:19 18 17 16 15:14 13:11 10 9 8:6 5:0
00000000 100 reserved
(00)
reserved
(0)
reserved
(0)
reserved
(0)
reserved
(00)
reserved
(00)
reversed reserved
(0)
container
size
alpha
bits-1

 

Standard (YCbCr)

This field specifies the standard being used for this color space.

Currently, this field is only defined for the YCbCr color space:

We believe that this field will be used to add linear format support in the very near future.

Fill Empty 0 (Mono, RGB, YCbCr)

When there is no alpha included with a format, but the color components don't fill up the container, the remainder of the bits must be filled with something when written.  When the OCDFMTDEF_FILL_EMPTY_0 flag is not set, they are filled with 1.  This is done in case they are later used as an alpha value, which will already represent an opaque pixel (whether the pixel is premultiplied or not).  When the flag is set, they are filled with 0, to accommodate those environments where they are required to be cleared when unused.

Alpha (Mono, RGB, YCbCr)

The OCDFMTDEF_ALPHA bit indicates that the format includes an alpha channel along with the main color components.

Non-Premult (Mono, RGB, YCbCr)

Formats with alpha can have their color components pre-multiplied by the alpha component or not.  When the OCDFMTDEF_NON_PREMULT bit is set, the color components are not premultiplied by the accompanying alpha.  When the bit is not set, the color components are already multiplied by the alpha.

Subsampling (YCbCr)

Some formats can be subsampled.  At this point, only subsampled YCbCr is supported.

Subsample Position (YCbCr)

Subsampling can have different equivalent positions relative to the pixels.  Vertical subsampling positions are consistent, so the following are supported to control the horizontal subsampling position:

NOTE:  It is encouraged that users of OCD be generous when handling subsampling positions.  Allowing misaligned subsampling is preferable to complete failure.

Alpha Components (Alpha)

To support applying alpha values to the individual components of other color spaces, the alpha color space can have more than one alpha value per pixel.  This field specifies how many:

Layout (RGB, YCbCr)

The layout values, in conjunction with the reversed and left-justified modifiers, specify how the pixel components are placed into memory.  All non-RGB/YCbCr formats are packed.

Reversed (RGB, YCbCr)

OCDFMTDEF_REVERSED indicates that the order of the color components is the opposite of the defaults.  For RGB formats, this means BGR.  For YCbCr formats, this means CrCb.

Left-Justified (RGB, YCbCr)

OCDFMTDEF_LEFT_JUSTIFIED indicates that the color components are shifted to the left, as opposed to the default of shifting to the right.

Some examples for OCDFMTDEF_REVERSED and OCDFMTDEF_LEFT_JUSTIFIED:

Container (All)

The container field indicates the total size of all the bits of the color components of a color format.  This does not include the alpha component, if it is present.

Component Size (All)

The component size field specifies the total number of bits in the color components, not including the alpha component.  (It is specified in the code with one subtracted.)

NOTE:  The alpha only color space uses this to specify the total number of alpha bits.


Examples

OCDFMT_RGB16

little-endian, 16-bit register

15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
r r r r r g g g g g g b b b b b

in memory, byte order

addr:
07 06 05 04 03 02 01 00
g g g b b b b b
_addr+1:
07 06 05 04 03 02 01 00
r r r r r g g g

OCDFMT_RGB24

in memory, byte order

addr:
07 06 05 04 03 02 01 00
r r r r r r r r
_addr+1:
07 06 05 04 03 02 01 00
g g g g g g g g
_addr+2
07 06 05 04 03 02 01 00
b b b b b b b b

OCDFMT_RGBA24

in memory, byte order

addr:
07 06 05 04 03 02 01 00
r r r r r r r r
_addr+1:
07 06 05 04 03 02 01 00
g g g g g g g g
_addr+2
07 06 05 04 03 02 01 00
b b b b b b b b
_addr+3:
07 06 05 04 03 02 01 00
a a a a a a a a

little-endian, 32-bit register

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
a a a a a a a a b b b b b b b b g g g g g g g g r r r r r r r r

OCDFMT_UYVY

in memory, byte order

addr:
07 06 05 04 03 02 01 00
u u u u u u u u
_addr+1:
07 06 05 04 03 02 01 00
y0 y0 y0 y0 y0 y0 y0 y0
_addr+2
07 06 05 04 03 02 01 00
v v v v v v v v
_addr+3:
07 06 05 04 03 02 01 00
y1 y1 y1 y1 y1 y1 y1 y1

little-endian, 32-bit register

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
y1 y1 y1 y1 y1 y1 y1 y1 v v v v v v v v y0 y0 y0 y0 y0 y0 y0 y0 u u u u u u u u