[tig] A Bit about Bits

Martin Euredjian ecinema
Thu Jan 29 03:19:22 GMT 2004


Robert Houllahan wrote,

> I know that video is represented in 4 bits for Luma and 2 bits each for
color difference I kind of assumed that those samples were the 8 bits we
were all talking about, I think I am mistaken,  Is it that each R,G and B
are represented as 8 bits per channel (or 10) and the 4:2:2 is a separate
representation with RGB being translated into YUV?


I think part of the problem is the loose nomenclature.  Let me see if I can
clarify some of these concepts for you.

Computer images (whether video or still) as you know are stored as RGB
values.  Generally speaking, it is easiest to use 8 bits for each, R, G and
B.  This means that it is very common for computer imagery to require 24
bits per pixel.

At the same time, in uncompressed computer images (JPEG is a different
ballgame) we will generally store a full 24 bit RGB value for each and every
single pixel.  Video geeks might call this a "full bandwidth" signal/image.

Video is a different game.  For starters, video does not use RGB.  And, in
particular, modern digital video interconnects and devices use something
called "YCbCr".  I'm talking digital video here, not old-school analog where
RGB could be found.

Another clarification.  "YUV" is not a technically accurate term when
referring to digital video.  This term is very narrowly constrained to a
type of analog video only.  It has no meaning in digital unless you are
willing to do a lot of math.  "YCbCr" is the proper term.  "YPbPr" is
"YCbCr" made into analog signals and scaled so that they have the same
amplitude.

Now, what is "YCbCr".  Well, if you are not into the math involved it might
be a bit difficult to understand, but, let me try to use an
analogy --admittedly imperfect-- to at least convey the general idea.

For starters, break "YCbCr" into three components: Y, Cb, and Cr.  Like R, G
and B, these are three values, three numbers that get stored for each pixel,
that describe the color and intensity for that particular pixel.

Now (and here's the bad analogy), what is Y, Cb, Cr with respect to RGB?
Think in terms of the metric system vs. the imperial system of measures.
RGB can be one and YCbCr the other.  In other words, we are representing the
same thing; weight, distance, velocity, etc. with different units.

It's not as simple as that, of course, but maybe this idea can help you
understand what the quantities we are talking about mean.

To extend this further, if we only used integers (1, 2, 3, etc., the numbers
you count with) there are certain quantities that you cannot represent
exactly when going from one system to the other.  For example, a one liter
is not one gallon.

The same sort of issue exists in between RGB and YCbCr.  Now, if you can
picture a one-gallon bottle and a one-liter bottle you can understand the
shortcomings of YCbCr vs. RGB.  YCbCr is a liter-bottle and RGB is a
gallon-bottle.  YCbCr fits inside the RGB space and is substantially
smaller.  The funny thing is that the YCbCr vs. RGB volume ratio is close to
the liter/gallon ratio!  :-)

In practical terms this means that not all the colors that exist in the RGB
volume can be represented (contained, carried, transmitted, stored, etc.)
with a YCbCr container.  That's why your computer can display colors that
you've never seen on TV.  The computer has a bag of colors that's the size
of an RGB "gallon-bottle" while all TV systems can only take a
"liter-bottle" worth of colors for display, etc.

OK, so, hopefully we got the RGB vs. YCbCr part sorted out.  Now, what are
bits?

Well, if I continue with the gallon/liter analogy, the number of bits would
determine the smallest amount of liquid you are able to measure.  Let's say
you are asked to divide a gallon (or liter) into a certain number of exact
parts and the only container you have is an 8 ounce cup (or 100ml glass).
You can only get so many cups of liquid.  Say you get sixteen.  Following
along this crazy analogy, it would mean that you can only get sixteen colors
out of the gallon (RGB) container.  If, instead of using a cup you could use
a tea spoon you could probably divide a gallon into 1000 small chunks
(colors).

Now for some math.  The number of chunks (colors) you can get from either
the RGB or YCbCr volumes is determined by how finely you slice each R, G, B
or Y, Cb, Cr.  Since all of this is binary, it means powers of two:

1 bit = 2 to the first power = 2
2 bits = 2 to the second power = 4
...
8 bits = 2 to the eight power = 256
...
10 bits = 2 to the tenth power = 1024

So, then, imagine RGB as a cube.  A toy box perhaps.  Take the three edges
that meet at any given corner and name each of them R, G and B,
respectively.  Choose your bit depth (or number of divisions), say, 8 bits
or 256 division.  Mark 256 division on each of those three edges.  What
you've just done is divide the RGB cube, the volume, the "gallon-bottle"
into 256 x 256 x 256 little sub-cubes.  Why?  Because, if you can imagine
extending each of the divisions you marked off into the volume of the cube
they will intersect and form little cubes.  Each one of these is the
smallest possible chunk-o-cube you can pull out.  Remember the cup vs. the
spoon.  It's that measurement.

Here's another visual.  Remember Rubiks cube?  That's a 3 x 3 x 3
(divisions, not bits) cube.  It contains 27 little cubes, the smallest
possible component.  If you built a Rubik's cube with 256 little cubes to
the side (8 bits) you'd need 256 x 256 x 256 little cubes, or over sixteen
million of them!  That would be how many colors you could get out of an RGB
space that was 8 bits per component (a component means each R, G or B).

If the cube had 10 bits to the side you could get 1024 x 1024 x 1024
distinct colors out of the same space for a choice of one color from among
over one billion (1000 million in the rest of the World).  That's a lot of
colors.

On first inspection, it would seem that YCbCr can produce the same 16M or
1000M colors.  You could say: If I use 8 bits per component, that's 256 x
256 x 256.  Well, the math for the real deal (not our gallon vs. liter
example) is such that a lot of the combinations are not legal AND the YCbCr
volume is a small volume inside the RGB volume, so, while you can have lots
of little division, they can only represent about 25% of the contents of the
RGB cube, no matter how you slice and dice it.

To button it up.  Eight bits has generally been favored by the computer
world because most microprocessors are descendants of eight bit processors.
Managing data in chunks that are multiples of eight bits tends to be very
efficient.  With 32 and 64 bit processors and very powerful graphic adapter
cards one could argue that this difference hasn't been that significant for
a long time.  What can I say, old habits die hard?

I hope this was useful and that I didn't loose my train of thought half way
and turned it into one big metric vs. imperial mess.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Euredjian
eCinema Systems, Inc.
voice: 661-305-9320
fax: 661-775-4876
martin at ecinemasys.com
ecinema at ieee.org
www.ecinemasys.com















More information about the Tig mailing list