UG0639: Color Space Conversion User Guide

Color Space Conversion
UG0639 User Guide
Table of Contents
Introduction ....................................................................................................................3
Hardware Implementation .............................................................................................5
Design Description......................................................................................................................................... 5
Inputs and Outputs ........................................................................................................................................ 6
Configuration Parameters.............................................................................................................................. 8
Timing Diagrams............................................................................................................................................ 8
Testbench ...................................................................................................................................................... 9
Resource Utilizations ................................................................................................................................... 10
List of Changes ............................................................................................................ 12
Product Support........................................................................................................... 13
Customer Service ........................................................................................................................................ 13
Customer Technical Support Center ........................................................................................................... 13
Technical Support ........................................................................................................................................ 13
Website ........................................................................................................................................................ 13
Contacting the Customer Technical Support Center ................................................................................... 13
ITAR Technical Support .............................................................................................................................. 14
UG0639: Color Space Conversion IP User Guide
2
Introduction
A color space is a mathematical representation of a set of colors. The most popular color models are:
•
RGB - Used in computer graphics
•
YIQ, YUV, and YCbCr - Used in video compression
The red, green, and blue (RGB) color space is widely used in computer graphics. These are three primary additive
colors and represented by a three-dimensional, Cartesian coordinate system. These three colors are used to create
any desired color. Therefore, the choice of the RGB color space simplifies the architecture and design of the system.
Also, the system that is designed using the RGB color space takes advantage of the large number of existing
software routines.
However, RGB is not very efficient in terms of bandwidth as all the three components have to be present in equal
bandwidth to produce any color. So an RGB based frame buffer must have same pixel depth and display resolution
for each RGB component. Processing an image in RGB color space is usually not the most efficient method. For
example: to modify the intensity or color of a given pixel, the three RGB values must be read from the frame buffer,
the intensity or color calculated, desired modifications performed, new RGB values calculated and written back into
the frame buffer.
The same can be achieved, if the image color properties are stored directly in intensity and color format.
Due to this reason, many video standards use luma and two color difference signals. One of the common color
spaces in this format is the YCbCr color space format.
The YCbCr color space was developed as part of ITU-R VT.601 during development of a worldwide digital
component video standard. The luma component Y is defined to have a nominal 8-bit range of 16-235 range of
values. The color information is represented as Cb and Cr with nominal 8-bit range of 16-240 range of values. There
are several YCbCr sampling formats such as 4:4:4, 4:2:2, 4:1:1, and 4:2:0.
Table 1 · YCbCr Sample Formats
YCbCr Sample Format
Description
4:4:4
Each sample has a Y, a Cb, and a Cr value represented typically using 8-bits or 10-bits
per component.
Therefore, each sample in 4:4:4 sampling format requires either 24-bits or 30 bits.
4:2:2
In 4:2:2 sampling format, for every two horizontal Y samples, there is one Cb and Cr
value. Each component sample is typically represented as 8-bits or 10-bits.
Therefore, each sample in 4:2:2 sampling format requires either 16-bits or 20-bits.
4:1:1
In 4:1:1 sampling format, for every four horizontal Y samples, there is one Cb and Cr
value. Each component sample is typically represented as 8-bits. Therefore, each sample
in 4:1:1 sampling format requires 12-bits.
4:2:0
In 4:2:0 sampling format, the 2:1 reduction is done on both horizontal and vertical values.
It is commonly used in video compression.
The advantages and disadvantages of various color space formats lead to requirements for the color space
conversions. The objective is to convert the video inputs into the desired color space before performing any video
processing on it. The RGB to YCbCr and vice-versa conversion is one such example.
UG0639: Color Space Conversion IP User Guide
3
Introduction
Following are the RGB to YCbCr conversion standard equations:
Y = (0.257 × R) + (0.504 × G) + (0.098 × B) + 16
Cb = −(0.148 × R) − (0.291 × G) + (0.439 × B) + 128
Cr = (0.439 × R) − (0.368 × G) − (0.071 × B) + 128
EQ1
EQ2
EQ3
Following are the YCbCr to RGB conversion standard equations:
R = 1.164 × (Y − 16) + 1.596 × (Cr − 128)
G = 1.164 × (Y − 16) − 0.813 × (Cr − 128) − 0.391 × (Cb − 128)
B = 1.164 × (Y − 16) + 2.018 × (Cb − 128)
4
EQ4
EQ5
EQ6
UG0639: Color Space Conversion IP User Guide
Hardware Implementation
This section describes the implementation of the Color Space Conversion block.
Design Description
The Color space conversion IP block contains two modules — RGB to YCbCr and YCbCr to RGB. The RGB to
YCbCr Color Space Converter IP module implements the equations to convert 24-bit input RGB color samples to
24-bit YCbCr output samples. The YCbCr to RGB Color Space Converter IP module converts vice-versa of the RGB
to YCbCr. Both the convertors use 4:4:4 sampling format.
Both the modules take data enable, horizontal, and vertical sync signals as inputs and pipeline them accordingly to
match the conversion video data outputs.
To convert the floating point constants into integer multiplication, the floating point constants are scaled by multiplying
15
these constants with 2 = 32768. Then after the computation of the above equations, the output is divided by the
15
scaling factor 2 = 32768.
After scaling, the RGB to YCbCr equations are:
Y =
(8421 × R) + (16515 × G) + (3211 × B) + 16 × 32768
Cb = − (4850 × R) − (9535 × G) + (14385 × B) + 128 × 32768
Cr =
(14385 × R) − (12059 × G) − (2327 × B) + 128 × 32768
EQ7
EQ8
EQ9
After scaling, the YCbCr to RGB equations are:
G
R =
38142 × Y + 52298 × Cr – 7304380
= 38142 × Y – 26640 × Cr – 12812 × Cb + 4439671
B
=
38142 × Y + 66126 × Cb – 9074377
EQ10
EQ11
EQ12
Figure 1 and Figure 2 show the system-level block diagrams of the RGB to YCbCr and YCbCr to RGB blocks.
UG0639: Color Space Conversion IP User Guide
5
Inputs and Outputs
CLOCK_I
Y_out_o
RESET_N_I
Cb_out_o
Red_i
Cr_out_o
Green_i
data_enable_o
Blue_i
RGB-to-YCbCr
horz_sync_o
data_enable_i
vert_sync_o
horz_sync_i
hactive_o
vert_sync_i
vactive_o
hactive_i
vactive_i
Figure 1 · System-Level Block Diagram of RGB to YCbCr
CLOCK_I
Red_out_o
RESET_N_I
Green_out_o
Y_i
Blue_out_o
Cb_i
data_enable_o
Cr_i
YCbCr-to-RGB
horz_sync_o
vert_sync_o
data_enable_i
horz_sync_i
hactive_o
vert_sync_i
vactive_o
hactive_i
vactive_i
Figure 2 · System-Level Block Diagram of YCbCr to RGB
Inputs and Outputs
Table 2 and Table 3 show the input and output ports of the RGB to YCbCr and YCbCr to RGB blocks.
Table 2 · Input and Output Ports of the RGB to YCbCr Block
Signal Name
Direction
Width
RESET_N_I
Input
-
Active low asynchronous reset signal to design
CLOCK_I
Input
-
System clock
Red_i
Input
[(g_RGB_DATA_BIT_WIDTH-1):0]
Red pixel data input
Green_i
Input
[(g_RGB_DATA_BIT_WIDTH-1):0]
Green pixel data input
Blue_i
Input
[(g_RGB_DATA_BIT_WIDTH-1):0]
Blue pixel data input
data_enable_i
Input
-
Video data enable input
horz_sync_i
Input
-
Horizontal sync signal
vert_sync_i
Input
-
Vertical sync signal
6
Description
UG0639: Color Space Conversion IP User Guide
Inputs and Outputs
hactive_i
Input
-
Horizontal active video region. Can be used for
embedded sync generation
vactive_i
Input
-
Vertical active video region. Can be used for
embedded sync generation
Y_out_o
Output
[(g_YCbCr_DATA_BIT_WIDTH-1):0]
Y pixel data output
Cb_out_o
Output
[(g_YCbCr_DATA_BIT_WIDTH-1):0]
Cb pixel data output
Cr_out_o
Output
[(g_YCbCr_DATA_BIT_WIDTH-1):0]
Cr pixel data output
data_enable_o
Output
-
Video data enable output
horz_sync_o
Output
-
Horizontal sync signal
vert_sync_o
Output
-
Vertical sync signal
hactive_o
Output
-
Horizontal active video region. Can be used for
embedded sync generation
vactive_o
Output
-
Vertical active video region. Can be used for
embedded sync generation
Table 3 · Input and Output Ports of the YCbCr-to-RGB Block
Signal Name
Direction
Width
RESET_N_I
Input
-
Active low asynchronous reset signal to design
CLOCK_I
Input
-
System clock
Y_i
Input
[(g_YCbCr_DATA_BIT_WIDTH-1):0]
Y pixel data input
Cb_i
Input
[(g_YCbCr_DATA_BIT_WIDTH-1):0]
Cb pixel data input
Cr_i
Input
[(g_YCbCr_DATA_BIT_WIDTH-1):0]
Cr pixel data input
data_enable_i
Input
-
Video data enable input
horz_sync_i
Input
-
Horizontal sync signal
hactive_i
Input
-
Horizontal active video region. Can be used for
embedded sync generation
vactive_i
Input
-
Vertical active video region. Can be used for
embedded sync generation
Red_out_o
Output
[(g_RGB_DATA_BIT_WIDTH-1):0]
Red pixel data output
Green_out_o
Output
[(g_RGB_DATA_BIT_WIDTH-1):0]
Green pixel data output
Blue_out_o
Output
[(g_RGB_DATA_BIT_WIDTH-1):0]
Blue pixel data output
data_enable_o
Output
-
Video data enable output
horz_sync_o
Output
-
Horizontal sync signal
vert_sync_o
Output
-
Vertical sync signal
hactive_o
Output
-
Horizontal active video region. Can be used for
embedded sync generation
vactive_o
Output
-
Vertical active video region. Can be used for
embedded sync generation
UG0639: Color Space Conversion IP User Guide
Description
7
Configuration Parameters
Configuration Parameters
Table 4 shows the configuration parameters used in the hardware implementation of RGB to YCbCr and YCbCr to
RGB blocks. These are generic parameters and can be varied as per the application requirements.
Table 4 · Configuration Parameters
Name
Description
g_RGB_DATA_BIT_WIDTH
RGB data bit width
g_YCbCr_DATA_BIT_WIDTH
YCbCr data bit width
Timing Diagrams
Figure 3 and Figure 4 show the timing diagrams of RGB to YCbCr and YCbCr to RGB blocks.
CLOCK_I
data_enable_i
Red_i
R0
R1
R2
R3
R4
R5
R6
Green_i
G0
G1
G2
G3
G4
G5
G6
Blue_i
B0
B1
B2
B3
B4
B5
B6
Y5
Y6
Y_out_o
Y0
Y1
Y2
Y3
Y4
Cb_out_o
Cb0
Cb1
Cb2
Cb3
Cb4
Cb5
Cb6
Cr_out_o
Cr0
Cr1
Cr2
Cr3
Cr4
Cr5
Cr6
data_enable_o
Figure 3 · Timing Diagram of RGB to YCbCr
8
UG0639: Color Space Conversion IP User Guide
Timing Diagrams
CLOCK_I
data_enable_i
Y_i
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Cb_i
Cb0
Cb1
Cb2
Cb3
Cb4
Cb5
Cb6
Cr_i
Cr0
Cr1
Cr2
Cr3
Cr4
Cr5
Cr6
Red_out_o
R0
R1
R2
R3
R4
R5
R6
Green_out_o
G0
G1
G2
G3
G4
G5
G6
Blue_out_o
B0
B1
B2
B3
B4
B5
B6
data_enable_o
Figure 4 · Timing Diagram of YCbCr to RGB
Note: All other input signals get delayed by the clock cycles as shown in Figure 4.
Testbench
A testbench is provided to check the functionality of Color Space Convertor core. The following parameters can be
configured according to application:
Table 5 · Configuration Parameters
Name
Description
CLKPERIOD
Clock period
HEIGHT
Height of the image
WIDTH
Width of the image
DATA_BIT_WIDTH
IMAGE_FILE_NAME
UG0639: Color Space Conversion IP User Guide
Data bit width
Input (image) file name
9
Resource Utilizations
Resource Utilizations
Table 6 · and Table 7 · show the resource utilizations of RGB to YCbCr and YCbCr to RGB blocks implemented on
®
the SmartFusion 2 system-on-chip (SoC) field programmable gate array (FPGA) device.
Table 6 · Resource Utilization of RGB to YCbCr
Resource
Usage
DFFs
620
4-input LUTs
520
MACC
9
RAM1kx18
0
RAM64x18
0
Table 7 · Resource Utilization of YCbCr to RGB
Resource
Usage
DFFs
300
4-input LUTs
370
MACC
5
RAM1kx18
0
RAM64x18
0
10
UG0639: Color Space Conversion IP User Guide
List of Changes
The following table shows important changes made in this document for each revision.
Revision
Revision 2
(February 2016)
Changes
Added the Testbench section in the document (SAR 76100).
Updated Resource Utalization Values in Table 6 · and Table 7 · (SAR 76100).
Revision 1
(August 2015)
Initial release.
UG0639: Color Space Conversion IP User Guide
Page
9
10 and 10
NA
11
Product Support
Microsemi SoC Products Group backs its products with various support services, including Customer Service,
Customer Technical Support Center, a website, electronic mail, and worldwide sales offices. This appendix contains
information about contacting Microsemi SoC Products Group and using these support services.
Customer Service
Contact Customer Service for non-technical product support, such as product pricing, product upgrades, update
information, order status, and authorization.
From North America, call 800.262.1060
From the rest of the world, call 650.318.4460
Fax, from anywhere in the world 650. 318.8044
Customer Technical Support Center
Microsemi SoC Products Group staffs its Customer Technical Support Center with highly skilled engineers who can
help answer your hardware, software, and design questions about Microsemi SoC Products. The Customer Technical
Support Center spends a great deal of time creating application notes, answers to common design cycle questions,
documentation of known issues and various FAQs. So, before you contact us, please visit our online resources. It is
very likely we have already answered your questions.
Technical Support
For Microsemi SoC Products Support, visit http://www.microsemi.com/products/fpga-soc/design-support/fpga-socsupport.
Website
You can browse a variety of technical and non-technical information on the Microsemi SoC Products Group home
page, at http://www.microsemi.com/products/fpga-soc/fpga-and-soc.
Contacting the Customer Technical Support Center
Highly skilled engineers staff the Technical Support Center. The Technical Support Center can be contacted by email
or through the Microsemi SoC Products Group website.
Email
You can communicate your technical questions to our email address and receive answers back by email, fax, or
phone. Also, if you have design problems, you can email your design files to receive assistance. We constantly
monitor the email account throughout the day. When sending your request to us, please be sure to include your full
name, company name, and your contact information for efficient processing of your request.
The technical support email address is [email protected].
My Cases
Microsemi SoC Products Group customers may submit and track technical cases online by going to My Cases.
UG0639: Color Space Conversion IP User Guide
12
Resource Utilizations
Outside the U.S.
Customers needing assistance outside the US time zones can either contact technical support via email
([email protected]) or contact a local sales office. Visit About Us for sales office listings and corporate
contacts.
ITAR Technical Support
For technical support on RH and RT FPGAs that are regulated by International Traffic in Arms Regulations (ITAR),
contact us via [email protected]. Alternatively, within My Cases, select Yes in the ITAR
drop-down list. For a complete list of ITAR-regulated Microsemi FPGAs, visit the ITAR web page.
13
UG0639: Color Space Conversion IP User Guide
Microsemi Corporation (Nasdaq: MSCC) offers a comprehensive portfolio of semiconductor
and system solutions for communications, defense & security, aerospace and industrial
markets. Products include high-performance and radiation-hardened analog mixed-signal
integrated circuits, FPGAs, SoCs and ASICs; power management products; timing and
synchronization devices and precise time solutions, setting the world’s standard for time; voice
processing devices; RF solutions; discrete components; Enterprise Storage and
Communication solutions, security technologies and scalable anti-tamper products; Ethernet
solutions; Power-over-Ethernet ICs and midspans; as well as custom design capabilities and
services. Microsemi is headquartered in Aliso Viejo, Calif., and has approximately 4,800
employees globally. Learn more at www.microsemi.com.
Microsemi Corporate Headquarters
One Enterprise, Aliso Viejo,
CA 92656 USA
Within the USA: +1 (800) 713-4113
Outside the USA: +1 (949) 380-6100
Sales: +1 (949) 380-6136
Fax: +1 (949) 215-4996
E-mail: [email protected]
© 2016 Microsemi Corporation. All
rights reserved. Microsemi and the
Microsemi logo are trademarks of
Microsemi Corporation. All other
trademarks and service marks are the
property of their respective owners.
Microsemi makes no warranty, representation, or guarantee regarding the information contained herein or
the suitability of its products and services for any particular purpose, nor does Microsemi assume any
liability whatsoever arising out of the application or use of any product or circuit. The products sold
hereunder and any other products sold by Microsemi have been subject to limited testing and should not
be used in conjunction with mission-critical equipment or applications. Any performance specifications are
believed to be reliable but are not verified, and Buyer must conduct and complete all performance and
other testing of the products, alone and together with, or installed in, any end-products. Buyer shall not
rely on any data and performance specifications or parameters provided by Microsemi. It is the Buyer’s
responsibility to independently determine suitability of any products and to test and verify the same. The
information provided by Microsemi hereunder is provided “as is, where is” and with all faults, and the
entire risk associated with such information is entirely with the Buyer. Microsemi does not grant, explicitly
or implicitly, to any party any patent rights, licenses, or any other IP rights, whether with regard to such
information itself or anything described by such information. Information provided in this document is
proprietary to Microsemi, and Microsemi reserves the right to make any changes to the information in this
document or to any products and services at any time without notice.
50200639-2/02.16