A-UG-CSCONVERTER-1.0
MegaCore Function
Color Space Converter
101 Innovation Drive
San Jose, CA 95134
(408) 544-7000
http://www.altera.com
User Guide
April 2001
Core Version 2.0.0
ii Altera Corporation
Color Space Converter MegaCore Function User Guide
Altera, ACEX, APEX, APEX 20K, APEX 20KE, FLEX, FLEX 10KE, MAX+PLUS II, MegaCore, MegaWizard, OpenCore, and
Quartus II are trademarks and/or service marks of Altera Corporation in the United States and other countries. Altera
Corporation acknowledges the trademarks of other organizations for their respective products or services mentioned in this
document, including the following: Verilog is a registered trademark of Cadence Design Systems, Incorporated. Java is a
trademark of Sun Microsystems Inc. ModelSim is a trademark of Model Technologies. MATLAB is a registered trademark of the
MathWorks. Microsoft is a registered trademark and Windows is a trademark of Microsoft Corporation. Altera products are
protected under numerous U.S. and foreign patents and pending applications, maskwork rights, and copyrights. Altera warrants
performance of its semiconductor products to current specifications in accordance with Altera’s standard
warranty, but reserves the right to make changes to any products and services at any time without notice. Altera
assumes no responsibility or liability arising out of the application or use of any information, product, or service
described herein except as expressly agreed to in writing by Altera Corporation. Altera customers are advised to
obtain the latest version of device specifications before relying on any published information and before placing
orders for products or services.
Copyright 2001 Altera Corporation. All rights reserved.
Altera Corporation iii
User Guide
About this User Guide
This user guide provides comprehensive information about the Altera®
color space converter MegaCore®function.
Table 1 shows the user guide revision history.
How to Find
Information
The Adobe Acrobat Find feature allows you to search the contents of
a PDF file. Click the binoculars icon in the top toolbar to open the Find
dialog box.
Bookmarks serve as an additional table of contents.
Thumbnail icons, which provide miniature previews of each page,
provide a link to the pages.
Numerous links, shown in green text, allow you to jump to related
information.
Table 1. Revision History
Revision Date Description
1.0 April 23, 2001 Version 1.0 of the user guide.
iv Altera Corporation
About this User Guide Color Space Converter MegaCore Function User Guide
How to Contact
Altera
For the most up-to-date information about Altera products, go to the
Altera world-wide web site at http://www.altera.com.
For additional information about Altera products, consult the sources
shown in Table 2.
Note:
(1) You can also contact your local Altera sales office or sales representative.
Table 2. How to Contact Altera
Information Type Access USA & Canada All Other Locations
Altera Literature
Services
Electronic mail lit_req@altera.com
(1)
lit_req@altera.com
(1)
Non-technical
customer service
Telephone hotline (800) SOS-EPLD (408) 544-7000
(7:30a.m.to5:30p.m.
Pacific Time)
Fax (408) 544-7606 (408) 544-7606
Technical support Telephone hotline (800) 800-EPLD
(6:00 a.m. to 6:00 p.m.
Pacific Time)
(408) 544-7000
(1)
(7:30a.m.to5:30p.m.
Pacific Time)
Fax (408) 544-6401 (408) 544-6401
(1)
Electronic mail dsp@altera.com dsp@altera.com
FTP site ftp.altera.com ftp.altera.com
General product
information
Telephone (408) 544-7104 (408) 544-7104
(1)
World-wide web site http://www.altera.com http://www.altera.com
Altera Corporation v
Color Space Converter MegaCore Function User Guide About this User Guide
Typographic
Conventions
The Color Space Converter MegaCore Function User Guide uses the
typographic conventions shown in Table 3.
Table 3. Conventions
Visual Cue Meaning
Bold Type with Initial
Capital Letters
Command names, dialog box titles, checkbox options, and dialog box options are
shown in bold, initial capital letters. Example: Save As dialog box.
Bold type External timing parameters, directory names, project names, disk drive names,
filenames, filename extensions, and software utility names are shown in bold type.
Examples: fMAX, \maxplus2 directory, d: drive, chiptrip.gdf file.
Bold italic type
Book titles are shown in bold italic type with initial capital letters. Example:
1999 Device Data Book
.
Italic Type with Initial
Capital Letters
Document titles are shown in italic type with initial capital letters. Example: AN 75
(High-Speed Board Design).
Italic type Internal timing parameters and variables are shown in italic type. Examples: tPIA,n+1.
Variable names are enclosed in angle brackets (< >) and shown in italic type. Example:
<file name>, <project name>.pof file.
Initial Capital Letters Keyboard keys and menu names are shown with initial capital letters. Examples:
Delete key, the Options menu.
“Subheading Title” References to sections within a document and titles of Quartus and MAX+PLUS II Help
topics are shown in quotation marks. Example: Configuring a FLEX 10K or FLEX 8000
Device with the BitBlasterDownload Cable.”
Courier type Signal and port names are shown in lowercase Courier type. Examples: data1,tdi,
input. Active-low signals are denoted by suffix _n, e.g., reset_n.
Anything that must be typed exactly as it appears is shown in Courier type. For
example: c:\max2work\tutorial\chiptrip.gdf. Also, sections of an actual
file, such as a Report File, references to parts of files (e.g., the AHDL keyword
SUBDESIGN), as well as logic function names (e.g., TRI)areshowninCourier.
1., 2., 3., and a., b., c.,... Numbered steps are used in a list of items when the sequence of the items is
important, such as the steps listed in a procedure.
Bullets are used in a list of items when the sequence of the items is not important.
vThe checkmark indicates a procedure that consists of one step only.
1The hand points to information that requires special attention.
rThe angled arrow indicates you should press the Enter key.
fThe feet direct you to more information on a particular topic.
Notes:
Altera Corporation vii
Contents
User Guide
About this User Guide ............................................................................iii
How to Find Information ......................................................................................................... iii
How to Contact Altera ...............................................................................................................iv
Typographic Conventions ..........................................................................................................v
Specifications ......................................................................................9
Features .......................................................................................................................................... 9
General Description ..................................................................................................................... 9
Functional Description .............................................................................................................. 10
Signals .......................................................................................................................................... 10
MegaWizard Plug-In ................................................................................................................. 10
Performance ................................................................................................................................ 11
Getting Started ................................................................................... 13
Download & Install the Function ............................................................................................. 14
Download the Function ..................................................................................................... 14
Installing the MegaCore Files ........................................................................................... 14
Generating a Custom Color Space Converter MegaCore .................................................... 15
MATLAB Simulation ......................................................................................................... 19
Compiling & Simulating in the Quartus Software ........................................................ 19
Compiling & Simulating in the MAX+PLUS II Software ............................................. 19
Performing Synthesis, Compilation & Post-Routing Simulation ................................ 20
For the Quartus II Software ...................................................................................... 20
For the MAX+PLUS II Software ............................................................................... 21
Configuring a Device ................................................................................................................. 22
References .................................................................................................................................... 22
Notes:
Altera Corporation 9
User Guide
Specifications
1
Specifications
Features
Optimized for Altera®devices, including the APEX,FLEX
®,
Mercury,andACEXdevice families
Computes one output per clock cycle
Typicallyrunsatclockspeedsover100MHz
Supports a variety of conversion functions:
Studio video RGBto YCbCr
YCbCr to studio video RGB
Computer RGBto YCbCr
YCbCr to computer RGB
YIQ to YUV
Computer RGBto YUV
YUV to computer RGB
User-specified conversion constants
Supports signed and unsigned input data widths from 2 to 32 bits
Provides user-selectable output precision via parameterizable
rounding, saturation, and truncation
Generates bit- and cycle-accurate MATLAB models to aid in system-
level design and analysis
Generates MAX+PLUS®II and QuartusII vector stimulus files
General
Description
Color space conversion is often necessary when transferring data between
devices that use different color space models. For example, to transfer a
television image to a computer monitor, you may need to convert the
image from the YCrCb color space to the RGBcolor space. Conversely,
transferring an image from a computer display to a television set may
require a transformation from the RGBcolor space to the YCrCb color
space. The Altera color space converter MegaCore function can be used to
perform these types of color transformations for a variety of applications
including image filtering, machine vision, and digital video.
A 3-dimensional color space is defined as a mathematical representation
of a set of colors, where each color is mapped to three coordinates. The
Altera color space converter MegaCore function can transform a color
from one 3-dimensional color space to another by multiplying the
tristimulus value by a 3 x 4-matrix transform.
10 Altera Corporation
Specifications Color Space Converter MegaCore Function User Guide
Functional
Description
The color space converter uses the following equation to convert data
from one color space to another:
Because the inputs are multiplied by constant values, the look-up table
(LUT) architecture of FLEX 10K, FLEX 10KE, APEX 20K, APEX 20KE,
Mercury, and ACEX devices is ideal for performing the conversion
equations. Pre-computing partial products and storing them in look-up
tablescanprovideasmaller,fasterimplementationthanonethatcanbe
realized with soft-core multipliers.
Signals Figure 1 shows the symbol and signals for the color space converter
function.
Figure 1. Color Space Converter Symbol
MegaWizard
Plug-In
Thecolorspaceconverterusesaninteractivewizard-driveninterfaceto
create a customizable, high-speed, area-efficient function. You can use the
wizard to:
Specify values for the transform matrix by either selecting from a set
of standard conversion functions or by manually entering the
coefficients.
Specify the coefficient width, input width, input representation, and
output width. The parameterized coefficient width and input width
allow the user to optimize for speed and area based on the system
requirements.
Optimize the design for performance by specifying input data as
unsigned when applicable.
Z_OUT
c11
c21
c31
c12
c22
c32
c13
c23
c33
c14
c24
c34
X_OUT
Y_OUT
C
A
B
1
=
CLK
SCLR
A[ ]
B[ ]
C[ ]
X_OUT[ ]
Y_OUT[ ]
Z_OUT[ ]
Altera Corporation 11
Color Space Converter MegaCore Function User Guide Specifications
Specifications
1
Limit the output precision by truncating or saturating the MSB
and/or rounding or truncating the LSB using the built-in precision
limiter.
After you have gone through the color space converter wizard, it
generates the following files:
HDL design file:
AHDL Text Design File (<variation name>.tdf)
VHDL Design File (<variation name>.vhd)
Verilog Design File (<variation name>.v)
Block Design Files <variation name>.bsf for the Quartus II software,
<variation name>.sym and Symbol Files for the MAX+PLUS II
software, which are used to instantiate the function into a schematic
design
<variation name>.inc file (Verilog HDL and AHDL only)
Anexamplecoreinstantiation<variation name>_inst
A component declaration file <variation name>.cmp (for VHDL cores)
A MATLAB testbench <variation name>.m to aid in system level
design and analysis
Performance Table 1 provides the resource utilization and maximum clock frequency
for the computer RGBto YCrCb conversion function. This
implementation uses 8-bit unsigned input ports and 10-bit coefficients.
Table 1. Color Space Converter Performance
Device Software Software Settings LEs Used fMAX
(MHz)
EPF10K30ETC144-1 MAX+PLUS II Fast global project logic synthesis style
fMAX = 200 MHz
358 172.41
EP1K10TC100-1 MAX+PLUS II Fast global project logic synthesis style
fMAX = 200 MHz
358 185.18
EPF6016ATC100-1 MAX+PLUS II Fast global project logic synthesis style
fMAX = 200 MHz
358 84.47
EPF20K30ETC144-1 Quartus II fMAX = 200 MHz 380 145.73
EP1M120F484C5ES Quartus II fMAX = 200 MHz 380 268.53
Notes:
Altera Corporation 13
User Guide
2
Getting Started
Getting Started
The Altera color space converter function provides solutions for
integrating DSP functions into your digital system. This section describes
how to obtain the color space conversion function, explains how to install
it on your PC, and how to implement a function using the wizard. You can
test-drive MegaCore functions using the Altera OpenCorefeature to
simulate the functions within your custom logic. When you are ready to
generate programming or configuration files, you should license the
function through the Altera web site or through your local Altera sales
representative. The color space converter is optimized for Altera APEX
20K, APEX 20KE, FLEX, and ACEX devices, greatly enhancing your
productivity by allowing you to focus efforts on the custom logic in the
system.
The design walkthrough involves the following steps:
1. Obtain and install the color space converter function.
2. Generate the function for your system using the wizard.
3. Simulate the filter using the wizard-generated MATLAB M-file.
4. Implement the rest of your system using the Altera Hardware
Description Language (AHDL), VHDL, Verilog HDL, or schematic
entry.
5. Compile your design and perform place-and-route.
6. Perform system verification.
7. License the color space converter function to configure or program
the devices.
The instructions assume that:
You are using a PC.
You are familiar with the Quartus II or MAX+PLUS II software.
MAX+PLUS II version 10.0 or higher is installed in the default
location or Quartus II version 1.0 or higher is installed in the default
location.
14 Altera Corporation
Getting Started Color Space Converter MegaCore Function User Guide
You are using the MATLAB software version 6.0 R12 or higher.
You are using the OpenCore feature to test-drive the color space
converter or you have licensed the function.
Download &
Install the
Function
Before you can start using the color space converter, you must obtain the
MegaCore files and install them on your PC. The following instructions
describe this process.
Download the Function
If you have Internet access, you can download MegaCore functions from
the Altera web site at http://www.altera.com. Follow the instructions
below to obtain the MegaCore functions via the Internet. If you do not
have Internet access, you can obtain the MegaCore functions from your
local Altera representative.
1. Point your web browser to http://www.altera.com/IPmegastore.
2. Type color space converter in the Keyword Search box of the
IP MegaSearch area and click Go.
3. Click the link for the color space converter.
4. Click the line to test-drive the function for free and follow the on-line
instructions to save the function to your hard disk.
Installing the MegaCore Files
To install the files on Windows, follow the instructions below:
1. Click Run (Start menu).
2. Type <path name>\<filename>.exe, where <path name> is the location
of the downloaded MegaCore function and <filename> is the
filename of the function.
3. Click OK. TheMegaCoreInstallerdialog box appears. Follow the
on-line instructions to finish installation.
4. After you have finished installing the MegaCore files, you must
specify the <installation directory>\Color Space Converter-v2.0\lib
directory as a user library in the Quartus II or MAX+PLUS II
software. Search for User Librariesin Quartus II or MAX+PLUS II
Help for instructions on how to add these libraries.
Altera Corporation 15
Color Space Converter MegaCore Function User Guide Getting Started
2
Getting Started
Generating a
Custom Color
Space
Converter
MegaCore
This section describes the design flow using the color space converter and
the Quartus II or MAX+PLUS II development system. Altera provides a
MegaWizard Plug-In with the color space converter, which you can use
within the Quartus II or MAX+PLUS II software. The MegaWizard
Plug-In Manager lets you create or modify design files to meet the needs
of your application. You can then instantiate the megafunction variation
in your project. The Altera OpenCore feature allows you to compile and
simulate MegaCore functions in the Quartus II or MAX+PLUS II software,
to evaluate the functions before purchasing a license.
To create a variation of the color space converter follow these steps:
1. Start the MegaWizard Plug-In Manager by choosing the
MegaWizard Plug-In Manager command (Tools menu in the
Quartus II software, File menu in any MAX+PLUS II application).
The MegaWizard Plug-In Manager dialog box is displayed.
1Refer to Quartus II or MAX+PLUS II Help for more
information on how to use the MegaWizard Plug-In
Manager.
2. Specify that you want to create a new custom megafunction and
click Next.
3. Select Color Space Converter in the DSP MegaCore folder. Choose
thelanguagefortheoutputfile(s)either AHDL, VHDL, or
Verilog H DLand specify a folder, <folder name> and name for the
output file, <variation name>. Click Next to start the wizard (see
Figure 1).
1<variation name> and <folder name> must be the same name
and the same folder that your Quartus II or MAX+PLUS II
project use.
16 Altera Corporation
Getting Started Color Space Converter MegaCore Function User Guide
Figure 1. Select the Color Space Converter Function
4. Specify the bit width of the input data bus. You can also specify
whether the bus is signed or unsigned; the signed representation
uses the twos complement numbering scheme (see Figure 2). Click
Next.
Figure 2. Specify the Bit Width & Number System
Altera Corporation 17
Color Space Converter MegaCore Function User Guide Getting Started
2
Getting Started
5. Specify the coefficients for your matrix transform. You can select a
predefined conversion function by turning on the Convert between
fundamental color models check box and selecting a predefined
function from the drop-down list box; or you can manually enter
your own custom transform matrix by turning off Convert between
fundamental color models.SeeFigure 3.
Figure 3. Select the Coefficient Values
6. After you have specified the coefficients, either by selecting a
predefined conversion function or by manually entering them, you
can scale the coefficients. Click Next to continue.
7. You can specify whether to use full or limited precision for the
converter output (X_OUT,Y_OUT,andZ_OUT). The color space
converter determines the output bit width based on the actual
coefficient values and the input bit width. These two parameters
define the maximum positive and negative output values.
The wizard extrapolates the number of bits required to represent that
range of values. For full precision, you must use this number of bits
in your system. If you choose limited precision, the wizard gives you
the option of truncating or saturating the most significant bit (MSB)
and/or rounding or truncating the least significant bit (LSB).
Saturation and rounding are non-linear operations. See Figure 4.
Make your selections and click Next.
18 Altera Corporation
Getting Started Color Space Converter MegaCore Function User Guide
Figure 4. Specify the Precision
8. The wizard displays the files that the wizard will generate. Click
Finish to accept your selections and generate the new megafunction
variation (see Figure 5).
Figure 5. View the
Once you have created a megafunction variation, you can integrate it into
your custom design. After you have finished your design, you are ready
to instantiate it in your system design and compile it.
Altera Corporation 19
Color Space Converter MegaCore Function User Guide Getting Started
2
Getting Started
MATLAB Simulation
The color space converter wizard generates a MATLAB script named
<variation name>.m, which provides a set of stimuli to run the bit- and
cycle-accurate MATLAB model. Type the name of the script at the
MATLAB command prompt to run the script. MATLAB displays the
output data on screen.
Compiling & Simulating in the Quartus Software
The following steps explain how to compile and simulate your design in
the Quartus II software, and use the test vector configuration file.
1. Click Start Compilation (Processing Menu) to compile your design.
2. Click Simulation Mode (Processing menu). Choose Simulator
Settings (Processing menu) and select the Time/Vectors tab. Turn off
the Automatically add Pin to Simulation Output Waveforms
option. In the Source of Vector Stimuli box, select <output
name>.vec,where <output name> is the name you specified in the
color space converter wizard. Click OK.
3. Click Run Simulation (Processing menu) to begin simulation.
Compiling & Simulating in the MAX+PLUS II Software
The following steps explain how to compile and simulate your design in
the MAX+PLUS II software.
1. In the MAX+PLUS II Compiler, turn on Functional SNF Extractor
(Processing menu).
2. Click Start to compile your design.
3. Run the MAX+PLUS II Simulator. The Vector File created by the
wizard for your color space converter variation is loaded
automatically. Click Start to begin simulation.
4. Once simulation has completed, click the Open SCF button to view
the waveform for the design. After you have verified that your
design is functionally correct, you are ready to perform system
verification.
20 Altera Corporation
Getting Started Color Space Converter MegaCore Function User Guide
Performing Synthesis, Compilation & Post-Routing Simulation
The Quartus II and MAX+PLUS II software work seamlessly with tools
from all EDA vendors, including Cadence, Exemplar Logic, Mentor
Graphics, Synopsys, Synplicity, and Viewlogic. After you have licensed
the MegaCore function, you can generate EDIF, VHDL, Verilog HDL, and
Standard Delay Output Files from the Quartus II or MAX+PLUS II
software and use them with your existing EDA tools to perform functional
modeling and post-route simulation of your design.
The following sections describe the design flow to compile and simulate
your MegaCore variation with a third-party EDA tool. To synthesize your
design in a third-party EDA tool and perform post-route simulation,
perform the following steps.
1. Create your custom design instantiating a color space converter
function.
2. Synthesize the design using your third party EDA tool. Your EDA
tool should treat the MegaCore instantiation as a black box by either
setting attributes or ignoring the instantiation.
1For more information on setting compiler options in your
third-party EDA tool, refer to the MAX+PLUS II ACCESS
Interfaces Guidelines.
3. After compilation, generate a hierarchical netlist file in your third-
party EDA tool.
4. Open your netlist file in the Quartus II or MAX+PLUS II software.
For the Quartus II Software
1. Select Compile mode (Processing Menu).
2. Specify the Compiler settings in the Compiler Settings dialog box
(Processing menu) or use the Compiler Settings wizard.
3. Specify the user libraries for the project and the order in which the
compiler searches the libraries.
4. Specify the input settings for the project. Choose EDA Tool Settings
(Project menu). Select Custom EDIF in the Design entry/synthesis
tool list. Click Settings.Inthe EDA Tool Input Settings dialog box,
make sure that the relevant tool name or option is selected in the
Design Entry/Synthesis Tool list.
Altera Corporation 21
Color Space Converter MegaCore Function User Guide Getting Started
2
Getting Started
5. Depending on the type of output file you want, specify Verilog HDL
output settings or VHDL output settings in the General Settings
dialog box (Project Menu). Use the 1993 VHDL language option.
6. Compile your design. The Quartus II Compiler synthesizes and
performs place-and-route on your design, and generates output and
programming files.
7. Import your Quartus II-generated output files (.edo,.vho,.vo,or
.sdo) into your third-party EDA tool for post-route, device-level, and
system-level simulation.
For the MAX+PLUS II Software
1. SetyourEDIFfileasthecurrentproject.
2. Choose EDIF Netlist Reader Settings (Interfaces menu).
3. In the EDIF Netlist Reader Settings dialog box, select the vendor for
your EDIF netlist file in the Ven dor drop-down list box and click
OK.
4. Make logic option and/or place-and-route assignments for your
custom logic using the commands in the Assign menu.
5. In the MAX+PLUS II Compiler, make sure Functional SNF Extractor
(Processing menu) is turned off.
6. Turn on the Verilog Netlist Writer or VHDL Netlist Writer
command (Interfaces menu), depending on the type of output file
you want to use in your third-party simulator. Use the 1993 VHDL
language option.
7. Compile your design. The MAX+PLUS II Compiler synthesizes and
performs place-and-route on your design, and generates output and
programming files.
8. Import your MAX+PLUS II-generated output files (.edo,.vho,.vo,or
.sdo) into your third-party EDA tool for post-route, device-level, and
system-level simulation.
1For more information on setting compiler options in your third-
party EDA tool, refer to the MAX+PLUS II ACCESS Key
Guidelines.
22 Altera Corporation
Getting Started Color Space Converter MegaCore Function User Guide
Configuring a
Device
After you have compiled and analyzed your design, you are ready to
configure your targeted Altera device. If you are evaluating the MegaCore
function with the OpenCore feature, you must license the function before
you can generate configuration files.
References Jack, Keith. Video Demystified, A Handbook for the Digital Engineer.
Second Edition. Solana Beach: Hightext Publications, 1996.
This book discusses fundamental computer-video applications, including
color space conversion considerations such as equations, data word
saturation, and data word rounding.
ISBN: 1-878707-23-X (paperback edition), Library of Congress catalog
card number: 96-076446.