background image
JPEG File Interchange Format, Version 1.02
3
Conversion to and from RGB
Y, Cb, and Cr are converted from R, G, and B as defined in CCIR Recommendation 601
but are normalized so as to occupy the full 256 levels of a 8-bit binary encoding. More
precisely:
Y = 256 * E'y
Cb = 256 * [ E'Cb ] + 128
Cr = 256 * [ E'Cr ] + 128
where the E'y, E'Cb and E'Cb are defined as in CCIR 601. Since values of E'y have a
range of 0 to 1.0 and those for E 'Cb and E 'Cr have a range of -0.5 to +0.5, Y, Cb, and
Cr must be clamped to 255 when they are maximum value.
RGB to YCbCr Conversion
YCbCr (256 levels) can be computed directly from 8-bit RGB as follows:
Y = 0.299 R + 0.587 G + 0.114 B
Cb = - 0.1687 R - 0.3313 G + 0.5 B + 128
Cr = 0.5 R - 0.4187 G - 0.0813 B + 128
NOTE - Not all image file formats store image samples in the order R
0
, G
0
,
B
0
, ... Rn, Gn, Bn. Be sure to verify the sample order before converting
an RGB file to JFIF.
YCbCr to RGB Conversion
RGB can be computed directly from YCbCr (256 levels) as follows:
R = Y + 1.402 (Cr-128)
G = Y - 0.34414 (Cb-128) - 0.71414 (Cr-128)
B = Y + 1.772 (Cb-128)
Image Orientation
In JFIF files, the image orientation is always top-down. This means that the first image
samples encoded in a JFIF file are located in the upper left hand corner of the image and
encoding proceeds from left to right and top to bottom. Top-down orientation is used for
both the full resolution image and the thumbnail image.
The process of converting an image file having bottom-up orientation to JFIF must include
inverting the order of all image lines before JPEG encoding.
[1] [2] [3] [4] [5] [6] [7] [8] [9]