ETC AP703000-B03

User’s Manual
µSAP703000-B03
JPEG Middleware
Target Devices
V850 Series™
Document No. U10684EJ3V0UM00 (3rd edition)
Date Published August 2002 N CP (K)
©
Printed in Japan
1995, 2001, 2002
[MEMO]
2
User’s Manual U10684EJ3V0UM
V850 Series, V850/SA1, V850/SB1, V850/SB2, V850/SC1, V850/SC2, V850/SC3, V850/SF1, V850/SV1,
V850E/MS1, V850E/MS2, V850E/MA1, V850E/MA2, V850E/IA1, V850E/IA2, and V853 are trademarks of NEC
Corporation.
Green Hills Software is a trademark of Green Hills Software, Inc.
UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open
Company Limited.
Windows is either a registered trademark or a trademark of Microsoft Corporation in the United States and/or
other countries.
TRON stands for The Real-Time Operating system Nucleus.
ITRON is an abbreviation of Industrial TRON.
• The information in this document is current as of May, 2002. The information is subject to change
without notice. For actual design-in, refer to the latest publications of NEC's data sheets or data
books, etc., for the most up-to-date specifications of NEC semiconductor products. Not all products
and/or types are available in every country. Please check with an NEC sales representative for
availability and additional information.
• No part of this document may be copied or reproduced in any form or by any means without prior
written consent of NEC. NEC assumes no responsibility for any errors that may appear in this document.
• NEC does not assume any liability for infringement of patents, copyrights or other intellectual property rights of
third parties by or arising from the use of NEC semiconductor products listed in this document or any other
liability arising from the use of such products. No license, express, implied or otherwise, is granted under any
patents, copyrights or other intellectual property rights of NEC or others.
• Descriptions of circuits, software and other related information in this document are provided for illustrative
purposes in semiconductor product operation and application examples. The incorporation of these
circuits, software and information in the design of customer's equipment shall be done under the full
responsibility of customer. NEC assumes no responsibility for any losses incurred by customers or third
parties arising from the use of these circuits, software and information.
• While NEC endeavours to enhance the quality, reliability and safety of NEC semiconductor products, customers
agree and acknowledge that the possibility of defects thereof cannot be eliminated entirely. To minimize
risks of damage to property or injury (including death) to persons arising from defects in NEC
semiconductor products, customers must incorporate sufficient safety measures in their design, such as
redundancy, fire-containment, and anti-failure features.
• NEC semiconductor products are classified into the following three quality grades:
"Standard", "Special" and "Specific". The "Specific" quality grade applies only to semiconductor products
developed based on a customer-designated "quality assurance program" for a specific application. The
recommended applications of a semiconductor product depend on its quality grade, as indicated below.
Customers must check the quality grade of each semiconductor product before using it in a particular
application.
"Standard": Computers, office equipment, communications equipment, test and measurement equipment, audio
and visual equipment, home electronic appliances, machine tools, personal electronic equipment
and industrial robots
"Special": Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster
systems, anti-crime systems, safety equipment and medical equipment (not specifically designed
for life support)
"Specific": Aircraft, aerospace equipment, submersible repeaters, nuclear reactor control systems, life
support systems and medical equipment for life support, etc.
The quality grade of NEC semiconductor products is "Standard" unless otherwise expressly specified in NEC's
data sheets or data books, etc. If customers wish to use NEC semiconductor products in applications not
intended by NEC, they must contact an NEC sales representative in advance to determine NEC's willingness
to support a given application.
(Note)
(1) "NEC" as used in this statement means NEC Corporation and also includes its majority-owned subsidiaries.
(2) "NEC semiconductor products" means any semiconductor product developed or manufactured by or for
NEC (as defined above).
M8E 00. 4
User’s Manual U10684EJ3V0UM
3
Major Revisions in This Edition (1/2)
Page
Description
p.17
Modification of 1.2.1 Overview of JPEG
p.18
Modification of 1.2.1 (2) YCbCr/RGB
p.19
Modification of 1.2.1 (3) Sampling and MCU
p.34
Modification of 1.2.2 (1) (c) DQT (define quantization table) marker
p.35
Modification of 1.2.2 (1) (d) DHT (define Huffman table) marker
p.37
Modification of 1.2.2 (1) (f) SOFn (start of frame) marker
p.38
Modification of 1.2.2 (1) (g) SOS (start of scan) marker
p.44
Addition of description on additional libraries in 1.3 Outline of System
p.48
Change of Figure 1-18 Libraries and Sample Sources
p.51
Change of Table 1-8 ROM Size of Basic Library (Unit: Bytes)
p.51
Addition of Table 1-9 ROM Size of Additional Library (Unit: Bytes)
p.53
Addition of Table 1-11 RAM Size of Additional Library (Unit: Bytes)
p.56
Modification of 2.2.1 (1) (b) jpeg_Compress
p.60
Addition of Notes in Table 2-1 User-Set Members
p.65
Modification of 2.2.2 (1) (b) jpeg_Compress
p.71
Modification of Table 2-10 Decompression Result Information Members
p.74
Modification of 2.2.3 (1) (b) jpeg_Analysis
p.77
Addition of Caution in Table 2-14 User-Set Members
p.78
Modification of Table 2-16 Analysis Result Information Members
p.79
Modification of Table 2-18 Supported JPEG Formats
p.86
Modification of Figure 2-16 Setting of JPEG File
p.86
Modification of 2.3.4 DNL marker
p.89
Modification of 2.4 Configuration of VRAM
p.92
Modification of Figure 2-20 Example of Setting VRAM-Related Members of Basic Library
p.111
Modification of 2.7.2 (4) Sampling
p.114
Modification of 2.7.2 (13) VRAM_W_Pixel
p.114
Modification of 2.7.2 (14) VRAM_H_Pixel
p.117
Modification of 2.7.2 (29) APP_Info_Bptr
p.118
Modification of 2.7.2 (33) DNL
p.119
Modification of 2.7.2 (34) CI1, CI2, CI3
p.120
Modification of 2.7.3 Structure of APPINFO structure
p.121
Modification of Table 2-33 Symbols
p.124
Modification of 2.7.6 (2) jpeg_Compress
p.126
Modification of 2.7.6 (5) jpeg_Decompress
p.129
Modification of 2.7.6 (8) jpeg_Analysis
The mark
4
shows major revised points.
User’s Manual U10684EJ3V0UM
Major Revisions in This Edition (2/2)
Page
p.133
Description
Addition of CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY
SPECIFICATIONS
TM
p.178
Modification of 4.1 (2) UNIX
p.178
Modification of 4.2 Execution Procedure of Sample Program
p.197
Addition of A.2 Additional Decompression Sample Program (Single-Pass Mode)
p.201
Addition of A.3 Sample Program for Basic Compression and Additional Decompression
The mark
version
shows major revised points.
User’s Manual U10684EJ3V0UM
5
Regional Information
Some information contained in this document may vary from country to country. Before using any NEC
product in your application, pIease contact the NEC office in your country to obtain a list of authorized
representatives and distributors. They will verify:
•
Device availability
•
Ordering information
•
Product release schedule
•
Availability of related technical literature
•
Development environment specifications (for example, specifications for third-party tools and
components, host computers, power plugs, AC supply voltages, and so forth)
•
Network requirements
In addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary
from country to country.
NEC Electronics Inc. (U.S.)
Santa Clara, California
Tel: 408-588-6000
800-366-9782
Fax: 408-588-6130
800-729-9288
NEC do Brasil S.A.
Electron Devices Division
Guarulhos-SP, Brasil
Tel: 11-6462-6810
Fax: 11-6462-6829
• Filiale Italiana
Milano, Italy
Tel: 02-66 75 41
Fax: 02-66 75 42 99
NEC Electronics Hong Kong Ltd.
• Branch The Netherlands
Eindhoven, The Netherlands
Tel: 040-244 58 45
Fax: 040-244 45 80
NEC Electronics Hong Kong Ltd.
• Branch Sweden
Taeby, Sweden
Tel: 08-63 80 820
NEC Electronics (Europe) GmbH Fax: 08-63 80 388
Duesseldorf, Germany
• United Kingdom Branch
Tel: 0211-65 03 01
Milton Keynes, UK
Fax: 0211-65 03 327
Tel: 01908-691-133
Fax: 01908-670-290
• Sucursal en España
Madrid, Spain
Tel: 091-504 27 87
Fax: 091-504 28 60
Hong Kong
Tel: 2886-9318
Fax: 2886-9022/9044
Seoul Branch
Seoul, Korea
Tel: 02-528-0303
Fax: 02-528-4411
NEC Electronics Shanghai, Ltd.
Shanghai, P.R. China
Tel: 021-6841-1138
Fax: 021-6841-1137
NEC Electronics Taiwan Ltd.
Taipei, Taiwan
Tel: 02-2719-2377
Fax: 02-2719-5951
NEC Electronics Singapore Pte. Ltd.
Novena Square, Singapore
Tel: 253-8311
Fax: 250-3583
• Succursale Française
Vélizy-Villacoublay, France
Tel: 01-30-67 58 00
Fax: 01-30-67 58 99
J02.4
6
User’s Manual U10684EJ3V0UM
PREFACE
Target Readers
This manual is intended for users who wish to design and develop application systems
based on the V850 Series.
Purpose
This manual is intended to give users an understanding of the functions of the
µSAP703000-B03 described in the Organization below.
Organization
This manual is organized as follows.
• Overview
y Library specifications
• Installation
• Source lists of sample programs
How to Read This Manual The “µSAP703000-B03” is referred to as the “AP703000-B03” throughout this manual.
Conventions
Note:
Footnote for items marked with Note in the text
Caution:
Information requiring particular attention
Remark:
Supplementary information
Numerical representation:
Binary... xxxx or xxxxB
Decimal... xxxx
Hexadecimal... 0xXXXX
Prefix indicating power of 2 (address space, memory capacity):
K (kilo)
10
2 … 1024
20
M (mega) 2 … 1024
User’s Manual U10684EJ3V0UM
2
7
Related Documents
The related documents indicated in this publication include preliminary versions.
However, preliminary versions are not marked as such.
Documents related to the V850 Series
Document Name
Data Sheet
Product Name
V853TM
TM
V850/SA1
V850/SB1TM
TM
V850/SB2
V850/SC1TM,
V850/SC2TM,
V850/SC3TM
V850/SF1TM
TM
V850/SV1
TM
V850E/MS1
TM
V850E/MA1
Hardware
µPD703003A, 703004A, 703025A
703003A(A), 703025A(A)
U13188E
µPD70F3003A, 70F3025A, 70F3003A(A)
U13189E
µPD703014A, 703014AY, 703014B, 703014BY,
703015A, 703015AY, 703015B, 703015BY,
703017A, 703017AY
U14526E
µPD70F3015B, 70F3015BY, 70F3017A,
70F3017AY
U14527E
µPD703031A, 703031AY, 703033A, 703033AY,
70F3033A, 70F3033AY
U14734E
µPD703032A, 703032AY, 70F3032A, 70F3032AY
U14893E
µPD703034A, 703034AY, 703035A, 703035AY,
70F3035A, 70F3035AY
U14780E
µPD703037A, 703037AY, 70F3037A, 70F3037AY
U14894E
µPD703068A, 703069Y, 703088Y, 703089Y,
70F3089Y
To be prepared
U15109E
µPD703078Y, 703079Y, 70F3079Y
U15183E
U14665E
µPD703038, 703038Y, 703039, 703039Y, 703040,
703040Y, 703041, 703041Y
U13953E
U14462E
µPD70F3038, 70F3038Y, 70F3040, 70F3040Y
U14462E
µPD703100-33, 703100-40, 703101-33, 70310233
U13995E
µPD703100A-33, 703100A-40, 703101A-33,
703102A-33
U14168E
µPD70F3102-33
U13844E
µPD70F3102A-33
U13845E
µPD703103A, 703105A, 703106A, 703106A(A),
703107A, 703107A(A)
U14792E
µPD70F3107A, 70F3107A(A)
U14618E
U10913E
U12688E
U12197E
U14359E
U14559E
To be prepared
U14980E
µPD70F3116, 70F3116(A), 70F3116(A1)
U15299E
U14492E
TM
µPD703114, 70F3114
To be prepared
U15195E
V850E/IA1
V850E/IA2
User’s Manual U10684EJ3V0UM
U10243E
U13850E
µPD703108
V850E/MA2
Architecture
U12768E
TM
TM
8
User’s Manual
Documents related to development tools (user’s manuals)
Document Name
Document No.
IE-703002-MC (In-Circuit Emulator for V853, V850/SA1, V850/SB1, V850/SB2,
V850/SF1, V850/SV1)
U11595E
IE-V850E-MC (In-Circuit Emulator for V850E/IA1, V850E/IA2), IE-V850E-MC-A (In-Circuit
Emulator for V850E/MA1, V850E/MA2)
U14487E
IE-703003-MC-EM1 (In-Circuit Emulator Option Board for V853)
U11596E
IE-703017-MC-EM1 (In-Circuit Emulator Option Board for V850/SA1)
U12898E
IE-703037-MC-EM1 (In-Circuit Emulator Option Board for V850/SB1, V850/SB2)
U14151E
IE-703040-MC-EM1 (In-Circuit Emulator Option Board for V850/SV1)
U14337E
IE-703079-MC-EM1 (In-Circuit Emulator Option Board for V850/SF1)
U15447E
IE-703102-MC (In-Circuit Emulator for V850E/MS1)
U13875E
IE-703102-MC-EM1, IE-703102-MC-EM1-A (In-Circuit Emulator Option Board for
V850E/MS1)
U13876E
IE-703107-MC-EM1 (In-Circuit Emulator Option Board for V850E/MA1)
U14481E
IE-703117-MC-EM1 (In-Circuit Emulator Option Board for V850E/IA1)
U14770E
CA850 (Ver. 2.30 or Later) (C Compiler Package)
Operation
U14568E
C Language
U14566E
Project Manager
U14569E
Assembly Language
U14567E
Operation
U15024E
C Language
U15025E
Project Manager
U15026E
CA850 (Ver. 2.40 or Later) (C Compiler Package)
Assembly Language
TM
U15027E
ID850 (Ver. 2.40 or Later) (Integrated Debugger)
Operation Windows
SM850 (Ver. 2.40 or Later) (System Simulator)
Operation Windows Based
U15182E
SM850 (Ver. 2.00 or Later) (System Simulator)
External Part User Open Interface
Specifications
U14873E
RX850 (Ver. 3.13 or Later) (Real-Time OS )
Basics
U13430E
Installation
U13410E
Technical
U13431E
Basics
U13773E
Installation
U13774E
Technical
U13772E
RX850 Pro (Ver. 3.13 ) (Real-Time OS)
Based
U15181E
RX-NET (TCP/IP Library)
U15083E
RD850 (Ver. 3.01 ) (Task Debugger)
U13737E
RD850 Pro (Ver. 3.01 ) (Task Debugger)
U13916E
AZ850 (Ver. 3.0 ) (System Performance Analyzer)
U14410E
PG-FP3 (Flash Memory Programmer)
U13502E
PG-FP4 (Flash Memory Programmer)
U15260E
• Documents related to tools made by Green Hills SoftwareTM, Inc. (GHS)
The tools made by GHS are handled by the following company in Japan. For each product and related
document, contact:
Advanced Data Controls Corp. (ADaC) TEL: +81-3-3576-5351
User’s Manual U10684EJ3V0UM
9
CONTENTS
CHAPTER 1 OVERVIEW ..........................................................................................................................16
1.1
1.2
Middleware...................................................................................................................................16
JPEG .............................................................................................................................................16
1.2.1
Overview of JPEG..........................................................................................................................17
1.2.2
JPEG file format .............................................................................................................................32
1.3 Outline of System ...........................................................................................................................44
1.3.1
Library configuration ......................................................................................................................44
1.3.2
Features of basic and additional libraries ......................................................................................44
1.3.3
Features of basic libraries..............................................................................................................45
1.3.4
Features of additional library..........................................................................................................46
1.3.5
Differences between basic libraries and additional library .............................................................47
1.3.6
Package contents ..........................................................................................................................48
1.3.7
Operating environment...................................................................................................................51
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS ................................................................................54
2.1
2.2
2.3
Functions .....................................................................................................................................54
Details of Processing..................................................................................................................55
2.2.1
Compression ..................................................................................................................................55
2.2.2
Decompression ..............................................................................................................................64
2.2.3
Analysis..........................................................................................................................................73
JPEG Format................................................................................................................................79
2.3.1
2.4
2.5
2.6
2.3.2
DHT marker....................................................................................................................................80
2.3.3
APPn marker..................................................................................................................................84
2.3.4
DNL marker....................................................................................................................................86
2.3.5
Supporting monochrome format.....................................................................................................87
Configuration of VRAM...............................................................................................................89
Structure of MCU Buffer .............................................................................................................93
Basic Library Customization......................................................................................................97
2.6.1
2.7
10
Supported formats..........................................................................................................................79
Handling of image data by basic library .........................................................................................97
2.6.2
Sampling ratio and block..............................................................................................................101
2.6.3
MCU buffer...................................................................................................................................102
2.6.4
VRAM access functions for compression.....................................................................................103
2.6.5
VRAM access function for decompression ..................................................................................104
2.6.6
One point to assembler coding ....................................................................................................105
Basic Library Reference ...........................................................................................................107
2.7.1
Details of data type ......................................................................................................................107
2.7.2
Structure of JPEGINFO structure.................................................................................................107
2.7.3
Structure of APPINFO structure...................................................................................................120
2.7.4
Constants .....................................................................................................................................121
2.7.5
External variable ..........................................................................................................................123
2.7.6
Function .......................................................................................................................................123
2.7.7
Section .........................................................................................................................................130
2.7.8
Symbol name conventions ...........................................................................................................130
User’s Manual U10684EJ3V0UM
2.7.9
Selecting basic library.................................................................................................................. 131
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS ..................133
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
Function .....................................................................................................................................133
3.1.1
Sampling of progressive format and MCU ................................................................................... 133
3.1.2
Color space.................................................................................................................................. 135
3.1.3
Options for additional decompression ......................................................................................... 136
Symbol Name Convensions.....................................................................................................137
Sections .....................................................................................................................................137
Library Selection .......................................................................................................................137
Function Specifications ...........................................................................................................138
3.5.1
Additional decompression............................................................................................................ 139
3.5.2
Additional decompression processing flow.................................................................................. 140
3.5.3
Customize function ...................................................................................................................... 143
Structures of Additional Library..............................................................................................150
3.6.1
JPEGEXINFO structure ............................................................................................................... 150
3.6.2
JPEGEXWORK Structure ............................................................................................................ 163
3.6.3
JPEGEXVIDEO Structure ............................................................................................................ 164
3.6.4
JPEGEXBUFF structure .............................................................................................................. 168
3.6.5
JPEGEXMCUSTR structure ........................................................................................................ 169
Errors During Additional Decompression ..............................................................................170
Warning Messages Output During Additional Decompression ...........................................172
List of Additional Library Constants.......................................................................................173
Customizing Additional Library...............................................................................................176
3.10.1
Simple customization................................................................................................................... 176
3.10.2
Advanced customization.............................................................................................................. 176
3.10.3
Example of customization............................................................................................................ 176
CHAPTER 4 INSTALLATION.................................................................................................................178
4.1
4.2
Installation Procedure ..............................................................................................................178
Execution Procedure of Sample Program ..............................................................................178
4.2.1
Outline of sample program for basic libraries .............................................................................. 178
4.2.2
Outline of sample program of additional library ........................................................................... 180
4.2.3
Outline of sample program of basic and additional libraries ........................................................ 182
APPENDIX A SAMPLE PROGRAM SOURCE LIST...........................................................................184
A.1
A.2
A.3
Sample Program Basic Library................................................................................................184
Additional Decompression Sample Program (Single-Pass Mode).......................................197
Sample Program for Basic Compression and Additional Decompression.........................201
APPENDIX B INDEX...............................................................................................................................208
User’s Manual U10684EJ3V0UM
11
LIST OF FIGURES (1/2)
Figure No.
Title
Page
1-1
Image Compression/Decompression................................................................................................................16
1-2
JPEG Versions .................................................................................................................................................17
1-3
JPEG Processing..............................................................................................................................................17
1-4
Outline of JPEG Processing .............................................................................................................................18
1-5
Sampling of Image............................................................................................................................................20
1-6
Matrix Components...........................................................................................................................................23
1-7
Distribution of Frequency Components ............................................................................................................23
1-8
Quantized Matrix and Quantization ..................................................................................................................24
1-9
Zigzag Scan and Coding ..................................................................................................................................25
1-10
Huffman Encoding ............................................................................................................................................27
1-11
Example of Incorrect Decompression Due to Bit Error in JPEG File ................................................................28
1-12
Example of Correct Decompression Using Restart Markers ............................................................................28
1-13
Restart Marker ..................................................................................................................................................29
1-14
Increase in File Size Caused by Use of Restart Marker ...................................................................................30
1-15
Structure of APPn Segment..............................................................................................................................31
1-16
JPEG File Format .............................................................................................................................................32
1-17
DCT/Reverse DCT Algorithm............................................................................................................................43
1-18
Libraries and Sample Source ...........................................................................................................................48
2-1
Compression.....................................................................................................................................................54
2-2
Decompression.................................................................................................................................................54
2-3
Analysis ............................................................................................................................................................54
2-4
Flow of Compression ........................................................................................................................................58
2-5
JPEG Buffer Manipulation ................................................................................................................................59
2-6
Image Memory Manipulation.............................................................................................................................59
2-7
Flow of Decompression ....................................................................................................................................68
2-8
JPEG Buffer Manipulation ................................................................................................................................69
2-9
Image Memory Manipulation.............................................................................................................................69
2-10
Flow of Analysis................................................................................................................................................76
2-11
JPEG Buffer Manipulation ................................................................................................................................77
2-12
DHT Segment ...................................................................................................................................................80
2-13
Determination of Values of Compressed Codes...............................................................................................81
2-14
Flow of Compression Using APPn Marker........................................................................................................84
2-15
Flow of Decompression Using APPn Marker....................................................................................................85
2-16
Setting of JPEG File .........................................................................................................................................86
2-17
Monochrome Format.........................................................................................................................................87
2-18
Selecting Basic Library and Execution Result ..................................................................................................88
2-19
Configuration of VRAM .....................................................................................................................................90
2-20
Example of Setting VRAM-Related Members of Basic Library .........................................................................92
2-21
Storing in MCU Buffer .......................................................................................................................................94
2-22
Contents of MCU Buffer....................................................................................................................................95
2-23
Storing Data of Upper Left 2 × 2 Pixels ............................................................................................................96
12
User’s Manual U10684EJ3V0UM
LIST OF FIGURES (2/2)
Figure No.
Title
Page
2-24
Flow of JPEG Processing................................................................................................................................. 97
2-25
Member CurrentX/CurrentY of Structure .......................................................................................................... 98
2-26
Image Data of 1 MCU ....................................................................................................................................... 99
2-27
Sampling......................................................................................................................................................... 101
2-28
Image Data in MCU Buffer.............................................................................................................................. 102
2-29
Quantization Parameter Quality and Constant Q ........................................................................................... 110
3-1
Additional Decompression.............................................................................................................................. 133
3-2
Sampling and MCU (at Sampling Ratio of 1:2:3:4)......................................................................................... 134
3-3
Additional Decompression Processing Flow .................................................................................................. 140
3-4
Updating of JPEG Buffer ................................................................................................................................ 143
3-5
Processing When APP Marker Is Found ........................................................................................................ 144
3-6
Processing When APP Marker Is Found ........................................................................................................ 145
3-7
Processing If Error That Does Not Disrupt Processing Occurs ...................................................................... 146
3-8
Processing before Start of Drawing................................................................................................................ 147
3-9
Forced Termination of Additional Decompression Processing with JPEGEXModeTerminate Specified..................... 151
3-10
Bit Configuration of Policy .............................................................................................................................. 152
3-11
Drawing Timing of Baseline Format ............................................................................................................... 153
3-12
Progressive Format Drawing Timing .............................................................................................................. 154
3-13
Stuffing Bit ...................................................................................................................................................... 155
3-14
Number of Passes for Additional Decompression Processing and Drawing Timing ...................................... 159
3-15
Decompression Processing if JPEG File in JPEG Buffer is Disrupted (Two Passes) .................................... 160
3-16
Position of DNL Marker in JPEG File ............................................................................................................. 161
3-17
Example of Setting VRAM-Related Members of Additional Library................................................................ 165
3-18
Clipping Area .................................................................................................................................................. 166
3-19
Clipping Area with Image Zoomed In/Out....................................................................................................... 167
4-1
Example of Basic Library Memory Mapping (V850E/MS1)............................................................................. 178
4-2
Example of Additional Library Memory Mapping (V850E/MS1)...................................................................... 180
4-3
Example of Basic/Additional Library Memory Mapping (V850E/MS1)............................................................182
User’s Manual U10684EJ3V0UM
13
LIST OF TABLES (1/2)
Table No.
Title
Page
1-1
Sampling Ratio and MCU .................................................................................................................................19
1-2
Sampling Ratio and Block.................................................................................................................................21
1-3
Values of DC/AC Components and Bit Length .................................................................................................26
1-4
JPEG Markers ..................................................................................................................................................33
1-5
Recommended Huffman Table .........................................................................................................................40
1-6
Product Library Configuration ...........................................................................................................................44
1-7
Differences Between Basic Libraries and Additional Library ............................................................................47
1-8
ROM Size of Basic Libraries (Unit: Bytes) ........................................................................................................51
1-9
ROM Size of Additional Library (Unit: Bytes) ....................................................................................................51
1-10
RAM Size of Basic Libraries (Unit: Bytes) ........................................................................................................52
1-11
RAM Size of Additional Library (Unit: Bytes) ....................................................................................................53
2-1
User-Set Members............................................................................................................................................60
2-2
Return Values of jpeg_Compress .....................................................................................................................61
2-3
Compression Result Information Members.......................................................................................................61
2-4
Compression Parameter Members (1)..............................................................................................................62
2-5
Compression Parameter Members (2)..............................................................................................................63
2-6
Compression Parameter Members (3)..............................................................................................................63
2-7
Compression Parameter Members (4)..............................................................................................................63
2-8
User-Set Members............................................................................................................................................70
2-9
Return Values of jpeg_Decompress .................................................................................................................71
2-10
Decompression Result Information Members...................................................................................................71
2-11
Setting of Decompression Parameter (1)..........................................................................................................72
2-12
Setting of Decompression Parameter (2)..........................................................................................................72
2-13
Setting of Decompression Parameter (3)..........................................................................................................72
2-14
User-Set Members............................................................................................................................................77
2-15
Return Value of jpeg_Analysis..........................................................................................................................78
2-16
Analysis Result Information Members ..............................................................................................................78
2-17
Setting of Analysis Parameter ..........................................................................................................................78
2-18
Supported JPEG Formats.................................................................................................................................79
2-19
Value of DC/AC Component and Bit Length.....................................................................................................80
2-20
Configuration of VRAM .....................................................................................................................................89
2-21
Configuration of MCU Buffer.............................................................................................................................93
2-22
Definition of Buffer ............................................................................................................................................94
2-23
Storing Data of 1 MCU (at 4:1:1) ......................................................................................................................96
2-24
MCU..................................................................................................................................................................98
2-25
MCU and Block ...............................................................................................................................................101
2-26
Sampling of Chrominance Component ...........................................................................................................101
2-27
VRAM Access Functions Used for Compression............................................................................................103
2-28
VRAM Access Functions Used for Decompression........................................................................................104
2-29
Data Type .......................................................................................................................................................107
2-30
Members of JPEGINFO Structure ..................................................................................................................108
2-31
Setting of Quality Parameter...........................................................................................................................111
14
User’s Manual U10684EJ3V0UM
LIST OF TABLES (2/2)
Table No.
Title
Page
2-32
Members of APPINFO Structure .................................................................................................................... 120
2-33
Symbols.......................................................................................................................................................... 121
2-34
External Variables .......................................................................................................................................... 123
2-35
Functions ........................................................................................................................................................ 123
2-36
Sections Used by Basic Libraries ................................................................................................................... 130
2-37
Basic Library Symbol Name Conventions ...................................................................................................... 130
2-38
Basic Library File Names................................................................................................................................ 131
2-39
Example of Selecting Basic Library ................................................................................................................ 132
3-1
Symbol Name Conventions of Additional Library ........................................................................................... 137
3-2
Sections Used by Additional Library............................................................................................................... 137
3-3
Additional Library File Names......................................................................................................................... 137
3-4
Additional Decompression Functions ............................................................................................................. 138
3-5
VRAM Settings When Customizing Image Drawing Function ........................................................................ 148
3-6
JPEGEXINFO Structure ................................................................................................................................. 150
3-7
Mode Setting of Additional Decompression Processing................................................................................. 150
3-8
Option Setting by Policy ................................................................................................................................. 152
3-9
ByteStuffDisable/ByteStuffEnable (Stuffing Byte) Option............................................................................... 156
3-10
Differences in Decompression Processing Due to of Number of Passes....................................................... 156
3-11
VideoZoomLinear/VideoZoomNormal (Zoom in/Decompression) Options..................................................... 162
3-12
JPEGEXWORK Structure............................................................................................................................... 163
3-13
JPEGEXVIDEO Structure............................................................................................................................... 164
3-14
JPEGEXBUFF Structure................................................................................................................................. 168
3-15
JPEGEXMCUSTR Structure........................................................................................................................... 169
3-16
Additional Library Errors ................................................................................................................................. 170
3-17
Warning Messages for Additional Library....................................................................................................... 172
3-18
Additional Library Constants........................................................................................................................... 173
4-1
Destination of File (1) ..................................................................................................................................... 179
4-2
Destination of File (2) ..................................................................................................................................... 181
4-3
Destination of File (3) ..................................................................................................................................... 183
A-1
Setting of Compression .................................................................................................................................. 184
A-2
Setting of Decompression .............................................................................................................................. 185
A-3
Setting of Analysis .......................................................................................................................................... 185
A-4
Additional Decompression Settings (1) .......................................................................................................... 197
A-5
Compression Settings (1) ............................................................................................................................... 201
A-6
Compression Settings (2) ............................................................................................................................... 202
User’s Manual U10684EJ3V0UM
15
CHAPTER 1 OVERVIEW
1.1
Middleware
Middleware is the name given to a group of software that has been tuned so that it draws out the maximum
performance of a processor.
Recently, a high performance RISC (Reduced Instruction Set Computer) processor introduced on the market
enables processing that is conventionally performed by hardware to be performed using the “high performance RISC
processor” and “software”. This “software” is called middleware.
NEC supplies system solutions that support a wide range of user needs by providing human-machine interface and
signal processing technologies in the form of middleware.
1.2
JPEG
JPEG stands for Joint Photographic Experts Group, an international still image compression/decompression
standard, established in 1991. This standard is defined in the document ISO/IEC 10918.
Figure 1-1. Image Compression/Decompression
Compression
Decompression
JPEG file
Still image
16
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
1.2.1
Overview of JPEG
There are several versions of the JPEG standard, such as progressive JPEG, in which an outline of the image
appears first, detail being added subsequently, and lossless JPEG, which can completely restore an image to the
state existing before compression. The AP703000-B03 supports not only the most commonly used version, called
baseline DCT, but also extended DCT (including progressive JPEG).
In the AP703000-B03, basic and additional libraries are provided. The additional library can be used alone or with the
basic libraries. The basic library is a small memory type for high-speed processing whereas the additional library is a
function-based type that supports many formats.
Decompression processing of the basic libraries is called basic decompression, and that of the additional library is
called additional decompression.
Figure 1-2. JPEG Versions
JPEG
Baseline process
DCT
Sequential
Huffman
Extended DCT-based process
DCT
Sequential or progressive
Huffman or arithmetic coding
Lossless process
Sequential
Huffman or arithmetic coding
(1) Flow of JPEG processing
JPEG compression involves compressing data in three steps: <1> DCT, <2> quantization, and <3> entropy
compression. JPEG decompression involves reproducing a compressed image by applying the reverse of the
above procedure: <1> entropy decompression, <2> reverse quantization, and <3> reverse DCT.
Figure 1-3. JPEG Processing
Compression
Quantization
Entropy coding
JPEG file
Image data
DCT
Reverse DCT
Reverse
quantization
Entropy decoding
Decompression
DCT (Discrete Cosine Transform) processing involves the disassembly of frequencies. Quantization reduces
the volume of information by eliminating, from the data obtained as a result of DCT (i.e., data whose frequency
has been disassembled), those frequency components that humans cannot sense.
Entropy encoding is
generally known as reversible compression/decompression, while baseline DCT uses a technology based on
Huffman encoding.
The AP703000-B03 performs DCT and quantization as part of the same function. Similarly, entropy decoding
and reverse quantization are performed as part of the same function. This increases the processing speed.
User’s Manual U10684EJ3V0UM
17
CHAPTER 1 OVERVIEW
(2) YCbCr/RGB
JPEG compresses/decompresses images in YCbCr color space. If the image data is not YCbCr but RGB,
processing to transform the RGB data into YCbCr for compression, or that to transform YCbCr data into RGB
before displaying the result of decompression, is added.
The Y of YCbCr is luminance (brightness index), and Cb/Cr is chrominance, a color difference (Cb is the
difference in color tone between green and blue, while Cr is the difference in color tone between green and
red). Transformation between YCbCr and RGB can be illustrated as follows.
When R, G, and B are in the range of 0 to 255 in the following expression, the range of Y is 0 to 255 and the
range of Cb/Cr is –128 to 127.
Y
Cb
=
Cr
0.29900
0.58700
0.11400
R
−0.16874
−0.33126
0.50000
G
0.50000
−0.41869
−0.08131
B
R
G
=
B
1
0
1.40200
Y
1
−0.34414
−0.71414
Cb
1
1.77200
0
Cr
Figure 1-4. Outline of JPEG Processing
RGB display
RGB-to-YCbCr
transformation
YCbCr-to-RGB
transformation
RGB data
YCbCr display
DCT
Reverse DCT
YCbCr data
Quantization
Reverse
quantization
JPEG data
Huffman compression
Huffman decompression
JPEG file
18
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
(3) Sampling and MCU
The minimum unit in which JPEG processing is performed is called an MCU (Minimum Coded Unit). The MCU
is separated into Y/Cb/Cr in units of 8 × 8 pixels, each of which is called a block.
Obtaining four blocks of Y, one block of Cb, and one block of Cr from one MCU can be expressed as “sampling
ratio of 4:1:1”. Similarly, when obtaining two blocks of Y, one block of Cb, and one block of Cr from one MCU,
the sampling ratio is said to be 4:2:2. When obtaining one block each of Y, Cb, and Cr from one MCU, the
sampling ratio is 4:4:4.
Table 1-1. Sampling Ratio and MCU
MCU
Sampling Ratio
Block
Vertical 16 pixels
Horizontal 16 pixels
4:1:1
[H:V = 2:2]
Y: 4 blocks, Cb: 1 block,
Cr: 1 block
Vertical 8 pixels
Horizontal 32 pixels
4:1:1
[H:V = 4:1]
Y: 4 blocks, Cb: 1 block,
Cr: 1 block
Vertical 8 pixels
Horizontal 16 pixels
4:2:2
[H:V = 2:1]
Y: 2 blocks, Cb: 1 block,
Cr: 1 block
Vertical 8 pixels
Horizontal 8 pixels
4:4:4
[H:V = 1:1]
Y: 1 block, Cb: 1 block,
Cr: 1 block
Remark
H: MCU horizontal sampling ratio
V: MCU vertical sampling ratio
Although the JPEG standard covers sampling ratios other than those listed in Table 1-1, the basic libraries of
the AP703000-B03 support only those sampling ratios listed in the table, whereas the additional library
supports any sampling ratio.
JPEG compression starts by dividing the image into grids in this MCU unit. Conversely, JPEG decompression
involves arranging the processing result for each MCU in a manner exactly like paving a floor with tiles.
For example, an image is vertically and horizontally divided into 16-pixel units, each at a sampling ratio of 4:1:1
[H:V = 2:2]. Next, the 16 × 16 pixel image is separated into Y, Cb, and Cr components, and the Y component is
divided into four blocks, each block consisting of 8 × 8 pixels. For the Cb and Cr components, an 8 × 8 pixel
image is created from the 16 × 16 pixel image. At this time, the vertically and horizontally adjacent 4 pixels are
averaged. This is called “thinning out”.
User’s Manual U10684EJ3V0UM
19
CHAPTER 1 OVERVIEW
Figure 1-5. Sampling of Image
Y
Original 16 × 16 pixel image
Cb
Cr
YCbCr separation
Sampling
Sampling ratio of 4:1:1 [H:V = 2:2]
Y
Original 16 × 8 pixel image
Cb
YCbCr separation
Sampling
Cr
Sampling ratio of 4:2:2
Original 8 × 8 pixel image
Y
Cb
Cr
YCbCr separation and sampling
Sampling ratio of 4:4:4
Original 32 × 8 pixel image
Y
Cb
Cr
Sampling ratio of 4:1:1 [H:V = 4:1]
With JPEG compression, a sampling ratio of 4:1:1 is used more often than 4:4:4.
At a sampling ratio of 4:1:1, the chrominance component is subjected to less processing than the luminance
component. This is because the human eye is more sensitive to changes in brightness than changes in color,
so a high compression ratio can be realized by omitting that information which is difficult for the human eye to
detect.
20
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
As an example, let’s consider a case in which an image consisting of 640 × 480 pixels is compressed.
To compress this image at a sampling ratio of 4:1:1 [H:V = 2:2], it is divided by 16 pixels both horizontally and
vertically, giving 40 horizontal segments and 30 vertical segments. Six blocks are extracted from each MCU:
four blocks of the Y component, one block of the Cb component, and one block of Cr component.
Consequently, 7200 blocks (= 40 × 30 × 6) are obtained from the entire image. To these 7200 blocks, DCT,
quantization, and Huffman compression are applied in sequence.
Table 1-2. Sampling Ratio and Block
640 × 480 Pixels
Sampling Ratio
Horizontal
Vertical
Number of Blocks
per MCU
Total Number of
Blocks
4:1:1
[H:V = 2:2]
40 segments
30 segments
6
7200
4:1:1
[H:V = 4:1]
20 segments
60 segments
6
7200
4:2:2
[H:V = 2:1]
40 segments
60 segments
4
9600
4:4:4
[H:V = 1:1]
80 segments
60 segments
3
14400
Remark
H: MCU horizontal sampling ratio
V: MCU vertical sampling ratio
As is evident from the above table, more blocks are needed at a sampling ratio of 4:4:4 than at 4:1:1. The
greater the number of blocks, the more processing time is required. Moreover, the size of the resulting JPEG
file also increases.
In JPEG compression, processing is performed on a block-by-block basis after sampling. DCT, quantization,
and entropy encoding are performed based on the information indicating to which of Y or Cb/Cr a given block
belongs.
In JPEG decompression, the result is obtained in units of blocks once entropy decoding, reverse quantization,
and reverse DCT have been completed.
User’s Manual U10684EJ3V0UM
21
CHAPTER 1 OVERVIEW
(4) DCT
DCT uses the following expression:
DCT
2C(u)C(v)
F(u, v) =
N
N −1
N −1
i =0
j =0
∑ ∑ f (i, j) cos {
(2i + 1)uπ
} cos {
(2j + 1)vπ
2N
}
2N
Reverse DCT
2
f(i, j) =
N
N −1
N −1
u =0
v =0
∑ ∑ C(u)C(v) F(u, v) cos {
(2i + 1)uπ
} cos {
2N
(2j + 1)vπ
}
2N
1
C(w) =
2
(w = 0)
(w ≠ 0)
=
Generally, this DCT is applied to 8 × 8 elements with signal processing techniques such as JPEG and MPEG.
DCT disassembles a frequency of cos (nπ/16) (where n = 0, 1, 2, ... 7) in both the vertical and horizontal
directions.
Generally, relatively few elements of a natural image, such as a photograph, have values; the other elements
tending to have values close to zero when the frequency is disassembled in this way. Even by approximating
those elements having a value close to zero with zero, an image close to the original can be produced by using
the remaining elements. Moreover, the differences between the original image and an image created in this
way are barely visible to the human eye.
22
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
When image data of 8 × 8 pixels is transformed by means of DCT, the first element indicates the average value
for the entire matrix, while the other 63 elements indicate the distortion of color in the matrix. Because of the
difference in nature between the first element in the matrix and the other 63 elements, the first element is
called a DC (direct current) component, while the other 63 elements are called AC (alternating current)
components.
Figure 1-6. Matrix Components
: DC component
: AC components
In an 8 × 8 matrix after the application of DCT, the low-frequency components are concentrated at the left and
top edges, while the high-frequency components are concentrated at the right and bottom edges. If the
original image exhibits few changes in tone, such as those that approach monochrome, a matrix of only lowfrequency components (with almost all the high-frequency values being 0) can be obtained. Conversely, with a
delicate image such as a diced pattern, a matrix with several high frequencies can be obtained.
Figure 1-7. Distribution of Frequency Components
High frequency
High frequency
Low frequency
Low frequency
: DC component
: AC components
User’s Manual U10684EJ3V0UM
23
CHAPTER 1 OVERVIEW
(5) Quantization and zigzag scan
It is said that the human eye can barely recognize changes in high-frequency components but can easily
recognize the most subtle changes in low-frequency components. To increase the compression ratio, JPEG
compression divides low-frequency components by a small value and high-frequency components by a greater
value. This processing is called quantization. To decompress compressed data, the data is multiplied by the
same value by which it was divided (reverse quantization). However, the data cannot be fully restored by
applying quantization and reverse quantization (cannot be reversed). This is because, when data is quantized,
only the quotient resulting from division is used as information, the remainder being ignored. The JPEG
quantization processing therefore attempts to raise the compression ratio so that differences in the image are
not visible to the human eye.
Figure 1-8. Quantized Matrix and Quantization
Example of quantized 8 × 8 matrix
Example of quantized matrix
Q (i, j ) =
8 16 19 22 26 27 29 34
43 −9
0
1
0
0
0
0
16 16 22 24 27 29 34 37
−8 −4
0
1
0
0
0
0
19 22 26 27 29 34 34 38
0
3
2
0 −1
0
0
0
22 22 26 27 29 34 37 40
−1
1
0
0
0
0
0
0
22 26 27 29 32 35 40 48
0
1
0
0
0
0
0
0
26 27 29 32 35 40 48 58
0
0
0
0
0
0
0
0
26 27 29 34 38 46 56 69
0
0
0
0
0
0
0
0
27 29 35 38 46 56 69 83
0
0
0
0
0
0
0
0
Data obtained by applying DCT to a block of the original image is notable in that the data of the Y component
differs from that of the Cb/Cr component. Therefore, JPEG uses two types of quantized matrixes for the Y and
Cb/Cr components, respectively (in some cases, only one quantized matrix is used).
These quantized
matrixes can be defined independently for each image (JPEG file). Information relating to these quantized
matrixes is stored as a DQT segment in the header of the JPEG file.
As shown by the example in Figure 1-8, if most of the values in the obtained matrix are 0, the information that
“there is a sequence of n zeroes followed by a value that is not zero” is interpreted to increase the compression
rate. The JPEG standard refers to this “sequence of zeroes” as “the length of zero run”. The non-zero values
in the matrix obtained as a result of quantization gather in the upper left part of the matrix most of the time. For
this reason, the length of the zero run is counted by JPEG in the sequence illustrated below (zigzag scan).
24
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Figure 1-9. Zigzag Scan and Coding
43
−9
0
1
0
0
0
0
−8
−4
0
1
0
0
0
0
0
3
2
0
−1
0
0
0
−1
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
(RUN, LEVEL)
(0, −9)
(0, −8)
(1, −4)
(1, 1)
(1, 3)
(0, −1)
(1, 1)
(0, 2)
(0, 1)
(5, 1)
(5, −1)
EOB
VLC
0000 0001 1000 1
0000 0001 1101 1
0000 0011 001
0110
0010 0101 0
111
0110
0100 0
110
0001 110
0001 111
10
0x01, 0x88,
0x0E, 0xC0,
0xCB, 0x12,
0xBB, 0x21,
0x87, 0x0F,
0x80,
(6) Entropy encoding
With the baseline DCT version of JPEG, entropy encoding that uses Huffman coding is performed. In entropy
encoding, the absolute values and distribution of the DC and AC components differ.
While the absolute value of an AC component is relatively low, the absolute value of the DC component tends
to be great. This is because the DC component is the average value of a given block. With JPEG, a difference
between the DC component of the current block and the DC component of the preceding block is calculated for
each of the Y, Cb, and Cr components, and this difference is compressed by means of entropy when the DC
component is compressed. For the AC coefficients, the combination of the length of the zero run and the value
of a non-zero coefficient (LEVEL value) is compressed by means of entropy. The compressed code is called a
VLC (Variable Length Code).
In JPEG compression, the DC and AC components are compressed in accordance with different Huffman
encoding conventions. This is referred to as “the DC and AC components using different Huffman tables”.
Moreover, like quantization, because the distribution of values differs between the Y and Cb/Cr components,
separate Huffman tables are usually used for the Y and Cb/Cr components. Consequently, four Huffman tables
are used for JPEG compression. Information relating to these Huffman tables can be defined by each JPEG
file, and is stored as a DHT segment in the JPEG file header.
For entropy encoding of a certain value, an absolute value of n bits can only contain n bits of information. In
other words, a value whose absolute value is n bits can be expressed using n bits. In signal processing, values
are usually defined as follows:
Positive number consisting of n bits:
Lower n bits of value
Negative number consisting of n bits: Lower n bits of value, with the sign inverted
In JPEG compression, entropy encoding follows the above scheme.
User’s Manual U10684EJ3V0UM
25
CHAPTER 1 OVERVIEW
Table 1-3. Values of DC/AC Components and Bit Length
Value of Component
0
−1, 1
−3, −2, 2, 3
−7 to −4, 4 to 7
−15 to −8, 8 to 15
−31 to −16, 16 to 31
−63 to −32, 32 to 63
−127 to −64, 64 to 127
−255 to −128, 128 to 255
−511 to −256, 256 to 511
−1023 to −512, 512 to 1023
−2047 to −1024, 1024 to 2047
Category
0
1
2
3
4
5
6
7
8
9
10
11
In JPEG compression, entropy compression of the values in this category is performed.
For example, suppose the Huffman table for the DC component for luminance (Y) follows the convention shown
below:
Huffman compressed code 00 (2 bits) is allocated to a value 0 bits long.
Huffman compressed code 010 (3 bits) is allocated to a value 1 bit long.
Huffman compressed code 011 (3 bits) is allocated to a value 2 bits long.
Huffman compressed code 100 (3 bits) is allocated to a value 3 bits long.
Huffman compressed code 001 (3 bits) is allocated to a value 4 bits long.
.
.
.
If the difference in the DC component of the block of the Y component (difference from the DC component of
the block of the preceding Y component) is “−3”, “−3” is encoded as follows, because it belongs to category 2.
Huffman compressed code of category 2: 011 (3 bits)
Lower 2 bits of “−3” with sign inverted:
00
3 + 2 = 5 bits
26
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Figure 1-10. Huffman Encoding
Determined from Huffman table
Huffman compressed code
Level value
Positive number: Lower n bits of value of component
Negative number: Lower n bits, with sign inverted
(n: category)
For the AC components, the Huffman table follows the convention shown below:
Compressed code 00 (2 bits) is allocated to a 1-bit value with a zero run of 0.
Compressed code 01 (2 bits) is allocated to a 2-bit value with a zero run of 0.
Compressed code 100 (3 bits) is allocated to a 3-bit value with a zero run of 0.
Compressed code 1010 (4 bits) is allocated to a 4-bit value with a zero run of 0.
Compressed code 1011 (4 bits) is allocated to a 1-bit value with a zero run of 1.
Compressed code 1100 (4 bits) is allocated to a 5-bit value with a zero run of 0.
Compressed code 11010 (5 bits) is allocated to a 2-bit value with a zero run of 1.
.
.
.
User’s Manual U10684EJ3V0UM
27
CHAPTER 1 OVERVIEW
(7) Restart marker
In JPEG compression, a 2-byte marker (restart marker) is inserted in a code for compressing an MCU.
The restart marker can be used to decompress only the lower part of a JPEG image. If a bit error occurs while
a JPEG file is being transferred, and if that file uses restart markers, decompression can be correctly resumed
from the next restart marker. With a JPEG file that does not use restart markers, the data cannot be correctly
decompressed if a bit error occurs.
Figure 1-11. Example of Incorrect Decompression Due to Bit Error in JPEG File
Figure 1-12. Example of Correct Decompression Using Restart Markers
28
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
There are 8 types of restart markers, in the value range of 0xFF, 0xD0 to 0xFF, 0xD7. A restart marker is
inserted in a compressed code every m MCUs, and used in the order of RST0, RST1, and RST2 to RST7.
Following RST7, RST0 is used. The value of m is called the restart interval.
If the restart interval is 3, the image will be as shown in the figure below.
Figure 1-13. Restart Marker
RST0
FF, D0
RST1
FF, D1
RST2
FF, D2
RST3
FF, D3
RST4
FF, D4
RST5
FF, D5
RST7
FF, D7
RST6
FF, D6
RST0
FF, D0
The number of restart markers to be inserted is determined by the size of the image. For example, the number
of restart markers for an image measuring 640 × 480 pixels, for a sampling ratio of 4:2:2 and a restart interval
of 2, is calculated as follows:
MCU (minimum compression unit):
16 × 8 pixels
Restart marker:
every 2 MCUs
Therefore,
(640 × 480) ÷ (16 × 8) ÷ 2 = 1200 restart markers
User’s Manual U10684EJ3V0UM
29
CHAPTER 1 OVERVIEW
A restart marker is located on a byte boundary. On the other hand, compressed code is located in bit units. If
one restart marker is inserted, therefore, the data quantity increases to a value equal to the marker, plus 2
bytes. The number of bytes per restart marker is usually less than 4 bytes, although it tends to vary slightly.
The DC component immediately after a restart marker is compressed not as the difference from the preceding
DC component, but as the value of the DC component itself.
For example, the size of the file for an image measuring 640 × 480 pixels, where the sampling ratio is 4:2:2 and
the restart interval is 2, increases by about 4800 bytes (1200 markers × about 4 bytes) relative to when no
restart marker is used.
Figure 1-14. Increase in File Size Caused by Use of Restart Marker
One MCU
;
Compressed code
DC coefficient of Cr component (difference)
DC coefficient of Cb component (difference)
DC coefficient of Y component (difference)
Restart marker inserted
Byte align
One MCU
Restart marker
30
DC coefficient of Cr component
(absolute value)
DC coefficient of Cb component (absolute value)
DC coefficient of Y component (absolute value)
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
(8) APPn marker
In JPEG compression, an application data segment (APPn segment) can be used so that data not directly
related to JPEG compression/decompression can be embedded in or extracted from the header of a JPEG file.
There are 16 types of APPn segments. The contents of these segments can be defined by the user.
Figure 1-15. Structure of APPn Segment
APPn marker
(2 bytes)
Data length
(2 bytes)
Data
(1 to 65,533 bytes)
There are 16 types of APPn markers, from 0xFF, 0xE0 to 0xFF, 0xEF, each corresponding to an APPn
segment.
The AP703000-B03 determines whether an APPn segment is to be used during compression. When an APPn
segment is to be used, which of the segments is to be used is specified by selecting the corresponding APPn
marker. An analysis routine that detects the position of an APPn segment in the JPEG file is also provided.
User’s Manual U10684EJ3V0UM
31
CHAPTER 1 OVERVIEW
1.2.2
JPEG file format
A JPEG file consists of a header that contains several pieces of information necessary for decompressing the file,
and data obtained by means of DCT, quantization, and entropy compression of an image. All the header data is in
byte units (when information is analyzed, however, 1 byte is processed as “4 bits + 4 bits”). Data is in bit units. All
data is accommodated on a byte boundary.
Figure 1-16. JPEG File Format
SOI
COM
DQT
JPEG header
SOF
DHT
SOS
compressed code
EOI
Data
JPEG footer
(1) Header
In JPEG compression, tables are managed in units called “segments” that start with a “marker”. A marker
always consists of 2 bytes, a combination of 0xFF and 1 byte unique to each marker. If a JPEG file is searched
for all occurrences of 0xFF, all the markers used in the file can be detected. However, 0xFF is also used in the
compressed data, not only in the header. To distinguish between the markers and data, therefore, 0xFF in the
compressed data is immediately followed by 0x00, which is meaningless as compressed data. “0xFF,0x00” is
not a marker, instead being compressed data “0xFF”.
The sequence of each segment (such as COM, DQT, SOF, and DHT) of the JPEG header is arbitrary.
The following table lists the JPEG markers.
32
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Table 1-4. JPEG Markers
Value
Contents
0xFF 0x00
Non-marker (compressed data 0xFF)
0xFF 0x01
TEM (temporary marker for arithmetic compression)
0xFF 0x02 to 0xFF 0xBF
RES (reserved)
0xFF 0xC0
SOF0 marker (baseline DCT (Huffman))
0xFF 0xC1
SOF1 marker (extended sequential DCT (Huffman))
0xFF 0xC2
SOF2 marker (progressive DCT (Huffman))
0xFF 0xC3
SOF3 marker (spatial (sequential) lossless (Huffman))
0xFF 0xC4
DHT marker (Huffman table definition segment)
0xFF 0xC5
SOF5 marker (differential sequential DCT (Huffman))
0xFF 0xC6
SOF6 marker (differential progressive DCT (Huffman))
0xFF 0xC7
SOF7 marker (differential spatial (Huffman))
0xFF 0xC8
JPG marker (reserved for JPEG decompression)
0xFF 0xC9
SOF9 marker (extended sequential DCT (arithmetic))
0xFF 0xCA
SOF10 marker (progressive DCT (arithmetic))
0xFF 0xCB
SOF11 marker (spatial (sequential) lossless (arithmetic))
0xFF 0xCC
DAC marker (environment setting segment for arithmetic coding)
0xFF 0xCD
SOF12 marker (differential sequential DCT (arithmetic))
0xFF 0xCE
SOF13 marker (differential progressive DCT (arithmetic))
0xFF 0xCF
SOF14 marker (differential spatial (arithmetic))
0xFF 0xD0 to 0xFF 0xD7
RSTm marker (restart marker)
0xFF 0xD8
SOI marker (header of JPEG file)
0xFF 0xD9
EOI marker (tail of JPEG file)
0xFF 0xDA
SOS marker (header of compressed data)
0xFF 0xDB
DQT marker (quantization table definition)
0xFF 0xDC
DNL marker (number of lines definition)
0xFF 0xDD
DRI marker (definition of restart interval)
0xFF 0xDE
DHP marker (definition of Huffman table)
0xFF 0xDF
EXP marker (decompress segment)
0xFF 0xE0 to 0xFF 0xEF
APPn marker (reserved for user application)
0xFF 0xF0 to 0xFF 0xFD
JPGn marker (reserved for JPEG decompression)
0xFF 0xFE
COM marker (comment)
User’s Manual U10684EJ3V0UM
33
CHAPTER 1 OVERVIEW
(a) SOI (start of image) marker
SOI
0xFF
0xD8
This marker indicates the beginning of a JPEG file. A JPEG file always starts with this 2-byte marker.
(b) EOI (end of image) marker
EOI
0xFF
0xD9
This marker indicates the end of a JPEG file. A JPEG file always ends with this 2-byte marker.
(c) DQT (define quantization table) marker
This marker defines a quantization table.
Multiple
DQT
0xFF
0xDB
Lq
Pq Tq
Q0
Q1
Q63
Lq byte
Lq: Length of DQT segment
Pq: Quantization factor (Q0 to Q63) accuracy
0: 8-bit accuracy
1: 12-bit accuracy (fixed to 0 with baseline)
Tq: Quantization table number (0, 1, 2, 3)
Q0 to Q63: Quantization factor
· 1 to 255 when Pq = 0
· 1 to 65535 when Pq = 1
Two DQT markers, one for the normal luminance component (luminance quantization table) and the other
for the chrominance component (chrominance quantization table), are supported.
34
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
(d) DHT (define Huffman table) marker
This marker defines a Huffman table.
multiple
DHT
0xFF
0xC4
Tc Th
Lh
L1
L2
L16
V1
V2
Vm
Lh byte
Lh: Length of DHT segment
Tc: 0 = DC, 1 = AC
Th: Huffman table number
· Baseline: 0, 1
· Extended baseline/progressive: 0, 1, 2, 3
L1 to L16: Indicates how many Huffman codes of i bits in length exist
V1 to Vm: Corresponding Huffman code
Example
00, 01, 05, 01, 01, 01, 01, 01, 01, 00, 00, 00, 00, 00, 00, 00
If L1 to L16 are as shown above, the meaning is as follows.
Zero 1-bit codes
One 2-bit code, 00
Five 3-bit codes, 010, 011, 100, 101, and 110
One 4-bit code, 1110
One 5-bit code, 11110
One 6-bit code, 111110
One 7-bit code, 1111110
One 8-bit code, 11111110
One 9-bit code, 111111110
No other codes
V1 to Vm are the corresponding Huffman codes. For example, the Huffman code corresponding to
compressed code ‘010’ is V2 (in this case, ‘010’ is the second compressed code).
User’s Manual U10684EJ3V0UM
35
CHAPTER 1 OVERVIEW
(e) APPn (reserved for application segments) marker
APPn
0xE0
Lp
0xFF
AP1
AP2
APn
0xEF
Lp byte
Lp: Length of APPn segment
AP1 to APn: Data peculiar to application
The application data segment is a segment that can be freely used by each application. Usually, this
segment contains the version of the application that created a JPEG file. In some cases, a small JPEG file
is contained as is. This segment can be skipped by only referring to the value of Lp.
36
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
(f) SOFn (start of frame) marker
In JPEG compression, the part of a JPEG file other than the SOI marker and EOI marker is called a frame.
The SOFn segment specifies a quantization table number necessary for decompression. The SOFn
segment is also called a frame header.
With JPEG, color elements such as Y, Cb, and Cr are called components.
SOFn
0xFF
0xC0
to 0xC2
P
Lf
C1
H1 V1
Y
Tq1
X
C2
H2 V2
component-spec.
parameters
Nf
Tq2
CNf
HNf VNf
TqNf
SOFn: SOF0: 0xFF 0xC0 (baseline)
SOF1: 0xFF 0xC1 (extended baseline)
SOF2: 0 xFF 0xC2 (progressive)
Lf: Length of SOFn segment
P: Number of bits constituting component
(8 bits are allocated to each color element for 24-bit full color compression. In this case, P = 8)
Y: Vertical size of image (number of pixels)
X: Horizontal size of image (number of pixels)
Nf: Number of components (Nf = 3 in the case of YCbCr, because the number of colors is 3)
Cn: Number of nth component
Hn: Horizontal sampling ratio of nth component
Vn: Vertical sampling ratio of nth component
Tqn: Quantization table number used for nth component
Example
0xFF 0xC0, 0x00, 0x11, 0x08, 0x00, 0x90, 0x00, 0xE0, 0x03,
0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01
If the contents of this segment are as shown above, the meaning will be as follows.
The sampling ratio of the first component (Y) is 2 × 2 and the quantization table number is 0.
The sampling ratio of the second component (Cb) is 1 × 1 and the quantization table number is 1.
The sampling ratio of the third component (Cr) is 1 × 1 and the quantization table number is 1.
User’s Manual U10684EJ3V0UM
37
CHAPTER 1 OVERVIEW
(g) SOS (start of scan) marker
The SOS segment is also called a scan header.
immediately after the scan header.
The data constituting a compressed image starts
The scan header specifies the Huffman table number of the
compressed data.
SOS
0xFF
Ls
0xDA
Ns
component-spec.
parameters
Ss
Se
Ah
Al
TdNs
Cs1
Td1 Ta1
Cs2
Td2 Ta2
CsNs
TaNs
Ls: Length of SOS segment
Ns: Number of colors included in scan
3: Y block, Cb block, Cr block
1: Either of Y, Cb, or Cr
Csn: ID of nth component
Tdn: Huffman table number of DC coefficient of nth component
Baseline:
0, 1
Extended baseline or progressive: 0 to 3
Tan: Huffman table number of AC coefficient of nth component
Baseline:
0, 1
Extended baseline or progressive: 0 to 3
Ss: Start number of DCT coefficient
Baseline or extended baseline: Fixed to 0
Progressive:
0 to 63
Se: End number of DCT coefficient
Baseline or extended baseline: Fixed to 63
Progressive:
Ss - 63 (Se = 0 fixed when Ss = 63)
Ah: Higher bits of DCT coefficient
Baseline or extended baseline: Fixed to 0
Progressive:
0 to 13
Al: Lower bits of DCT coefficient
Baseline or extended baseline: Fixed to 0
Progressive:
0 to 13
(h) DRI (Define restart interval) marker and RSTm (Restart interval termination) marker
A restart marker is used to minimize the influence of illegal data such as a communication error. A restart
marker is inserted every number of MCUs, as set by the DRI marker.
For example, to insert a marker every four MCUs, restart markers are inserted sequentially, starting from
RST0 and RST1 to RST7, as follows:
[MCU1][MCU2][MCU3][MCU4]RST0[MCU5][MCU6][MCU7][MCU8]RST1 ...
Because the DC coefficient is differential information with JPEG, the preceding DC coefficient is required
to decompress an 8 × 8 pixel block. The DC coefficient immediately after a restart marker is a differential
from 0. Consequently, even if data is destroyed in MCU4, MCU5 and subsequent MCUs can be correctly
decompressed.
38
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
DRI
0xFF
0xDD
Lr
Ri
Lr: Length of DRI segment (4)
Ri: Restart interval
(2) Data
Although the header is stored in a file in units of bytes, data is stored in a file in units of bits (the overall data is
stored in multiples of bytes).
The first point to be noted concerning data is that data 0xFF is immediately followed by 0x00 to distinguish it
from a marker. For decompression, therefore, all occurrences of 0x00 following 0xFF must be ignored. To do
so, data must be read from memory 1 byte at a time, and a judgment made each time to determine whether
each item of byte data is 0xFF. This means that a technique to increase the speed, such as reading data from
memory in blocks of 2 or 4 bytes, cannot be used.
(3) Huffman decoding
Example
FF C4 00 1F 00
00 01 05 01 01 01 01 01 01 00 00 00 00 00 00 00 00
00 01 02 03 04 05 06 07 08 09 0A 0B
The Huffman table segment shown above is interpreted as follows.
There is no 1-bit Huffman code.
There is one 2-bit Huffman code, ‘00’, for which the corresponding value is ‘0x00’.
There are five 3-bit Huffman codes: ‘010’, ‘011’, ‘100’, ‘101’, and ‘110’. The corresponding values are
‘0x01’, ‘0x02’, ‘0x03’, ‘0x04’, and ‘0x05’.
There is one 4-bit Huffman code, ‘1110’, for which the corresponding value is ‘0x06’.
....
If this interpretation were to be made each time compressed image data is decompressed, processing would
take an excessively long time. It is also wasteful to repeat the same processing over and over again. Actually,
therefore, a simple table is created by analyzing the Huffman table segment before starting the decompression
of compressed image data. This table is referenced when the image data is decompressed.
User’s Manual U10684EJ3V0UM
39
CHAPTER 1 OVERVIEW
(a) Huffman table initialization
The JPEG standard recommends the creation of the following table.
Table 1-5. Recommended Huffman Table
Number of Bits
Minimum Value of Code
Maximum Value of Code
Number of Minimum Code
1 bit
Undefined
−1
Undefined
2 bits
0x0
0x0
0x0
3 bits
0x2
0x6
0x1
4 bits
0xE
0xE
0x6
5 bits
0x1E
0x1E
0x7
6 bits
0x3E
0x3E
0x8
7 bits
0x7E
0x7E
0x9
8 bits
0xFE
0xFE
0xA
9 bits
0x1FE
0x1FE
0xB
10 bits
Undefined
−1
Undefined
11 bits
Undefined
−1
Undefined
12 bits
Undefined
−1
Undefined
13 bits
Undefined
−1
Undefined
14 bits
Undefined
−1
Undefined
15 bits
Undefined
−1
Undefined
16 bits
Undefined
−1
Undefined
In the above Huffman code segment, the minimum value of the 3-bit Huffman code is ‘010’ (= 0x02) while
the maximum value is ‘110’ (= 0x06). The minimum code ‘010’ is the second (0x1) of those that follow ‘00’.
(b) Decoding of DC coefficient
As an example, suppose that the Huffman table segment shown in Table 1-5 is given.
Also suppose that the compressed code has the following value:
0xDA 0x49 (= 1101 1010 0100 1001)
First, the first bit ‘1’ (= 0x1) of the compressed data is compared with the maximum 1-bit value of the
Huffman code table.
0x1 > −1 (maximum 1-bit value of table)
It can be determined, therefore, that the compressed code is not a 1-bit code.
Next, the first 2 bits ‘11’ (= 0x3) are compared with the maximum 2-bit value of the table.
0x3 > 0x0 (maximum 2-bit value of table)
40
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Therefore, the compressed data is not a 2-bit code, either.
Then, the first 3 bits ‘110’ (= 0x6) are compared with the maximum 3-bit value of the table.
0x6 = 0x6 (maximum 3-bit value of table)
This determines that the compressed code is 3 bits long.
By using this 3-bit compressed code, the position of ‘110’ as a Huffman code must be obtained. To do this,
the minimum 3-bit value ‘0x2’ of the Huffman table is subtracted from compressed code ‘0x6’.
0x6 − 0x2 = 0x4
This means that the 3-bit compressed code is at the 0x4th position. Because the minimum 3-bit code ‘0x2’
is at the 0x1th position (if the table is referenced), the following calculation is performed:
0x4 + 0x1 = 0x5
This indicates that the compressed code is at the 0x5th code position.
Next, the Huffman code segment is referenced.
00 01 02 03 04 05 06 07 08 09 0A 0B
The value of the 0x5th position is ‘05’. This means that the ‘5’ bits following the compressed code are a
level value.
Next, the decoded 3 bits, ‘110’, are stripped from the compressed code and discarded.
0xDA 0x49 (= 1101 1010 0100 1001)
↓
0xD2 0x48 (=
1 1010 0100 1001)
The first 5 bits are ‘11010’ (= 0x1A). Because the first sign bit in this case is ‘1’ (indicating a positive number), the
obtained value is ‘0x1A’. This completes the decoding of the DC coefficient.
(c) Decoding of AC coefficient
Basically, the AC coefficient is decoded in the same manner as the DC coefficient, but with the following
differences:
• The Huffman code table is different.
• The higher 4 bits of the value taken from the Huffman code segment indicate the length of the zero run,
while the lower 4 bits indicate the number of bits of the level value.
User’s Manual U10684EJ3V0UM
41
CHAPTER 1 OVERVIEW
(4) Reverse quantization
Reverse quantization involves multiplying the 8 × 8 pixel matrix obtained as a result of Huffman decoding, by a
quantized matrix defined by the quantization segment.
Because this processing only involves calculating the product of the two values read from memory, followed by
writing the result to another memory address, processing that restores the original sequence of a zigzag scan
is also performed at the same time, so that the number of times memory is accessed can be reduced and the
overall processing speed improved.
Almost all the elements of the matrix obtained as a result of Huffman decoding have a value of ‘0’ (zero). The
normal CPU requires several clocks to execute the multiplication or memory access (read or write). The
AP703000-B03 inserts one expression to identify whether the value of an element is ‘0’. If the value is ‘0’, that
element is rejected.
(5) Actuality of DCT/reverse DCT
DCT is equivalent to repeating the following one-dimensional calculation twice (vertically and horizontally).
F(u,v) = 2C(u)C(v)/N* Σ Σ f (i, j)*cos {(2i + 1)uπ/2N} *cos {(2j + 1)vπ/2N}
= 2C(u)C(v)/N* Σ cos {(2i + 1)uπ/2N} *Σf (i, j)*cos {(2j + 1)vπ/2N}
The number of constants required for two dimensions and eight orders (N = 8; i.e., 8 × 8 matrix) is 32. Actually,
however, this can be decreased by applying the formula of a trigonometric function to the subsequent seven.
cos(nπ/16) (n = 0, 1, 2, ... 31)
↓
cos (nπ/16) (n = 1, 2, 3, 4, 5, 6, 7)
If the following value has been calculated in advance, the number of times multiplication is executed can be
reduced.
f (0, j) ± f (7, j), f (1, j) ± f (6, j), ...
Further, the vertical and horizontal routines can be used commonly if the DCT expression is changed as
follows:
g (i, v) = Σf (i, j)*cos {(2j + 1)vπ/16}
f (u, v) = Σg (i, v)*cos {(2i + 1)uπ/16}
42
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Figure 1-17. DCT/Reverse DCT Algorithm
;
;;;
;;;
;; ;
;;;;;;;;;
;;
;;
f (i , j )
g (i , v )
;;;;;;;
F (u , v )
Actually, the pointer of f (i, j) and the pointer of work area g (i, v) are passed as arguments to the DCT routine.
By allocating this work area to high-speed RAM, the processing speed can be increased.
User’s Manual U10684EJ3V0UM
43
CHAPTER 1 OVERVIEW
1.3 Outline of System
1.3.1 Library configuration
The JPEG middleware library consists of the following libraries.
Table 1-6. Product Library Configuration
Product
Library Configuration
AP703000-B03
Basic library (compression)
(supports V850 Series)
Basic library (decompression)
Supported File Format
Baseline
Basic library (analysis)
Additional library (decompression)
Progressive
Baseline
Extended baseline
The AP703000-B03 has basic libraries and an additional library. The additional library can be used either by itself
or together with the basic libraries. The basic libraries are for high-speed processing and are of small memory type,
while the additional library emphasizes functions and supports a range of formats.
In this user’s manual, the decompression processing of the basic libraries is called basic decompression, while the
decompression processing of the additional library is called additional decompression.
1.3.2 Features of basic and additional libraries
The features common to the basic and additional libraries are as follows:
(1) VRAM and coordinates (x, y)
The libraries do not include a VRAM access function. This function is hardware-dependent, so the user must
describe the VRAM access function according to the system (C can be used).
For VRAM that can be accessed by an LD.B or ST.B instruction, however, default routines are provided as
libraries.
Assuming VRAM specification for both YCbCr and RGB, an image can be decompressed and compressed at
any point in VRAM.
(2) Quantization table
Specify the two quantization tables that can be set.
A default quantization table is provided for compression, but a user-defined quantization table can also be
used. A quantization parameter (Quality) is also provided. Setting this parameter to a value of between 0 and
100 causes all values in the quantization tables to be multiplied by a constant, so that the values of the
elements will be within the range of 1 to 255. (To use the quantization tables as is, specify 50 for the
quantization parameter.)
The value written to the DQT header is used for decompression.
(3) Huffman table
Specify the four Huffman tables that can be set (for luminance DC, for luminance AC, for chrominance DC, and
for chrominance AC).
A default Huffman table is provided for compression, but a user-defined Huffman table can also be used.
The value written to the DHT header is used for decompression.
44
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
(4) Restart marker (restart internal)
Whether restart markers are to be used can be specified for compression. If they are used, the restart interval
can be changed.
The value of the DRI segment in the JPEG file is used for decompression.
(5) APPn segment
The insertion of an APPn segment can be specified for compression.
Although APPn segments are ignored during basic decompression, their locations can be detected.
The JPEGEXdecodeAPP function (see 3.5.3 (2) JPEGEXdecodeAPP) is called when the APPn segment is
detected for additional compression.
(6) DNL segment
Whether a DNL segment is to be inserted or not can be selected for compression.
A DNL segment is recognized automatically for basic decompression.
Setting an option is required for additional decompression (see 3.6.1 (3) (e) DNLEnable (D option)).
(7) Component ID
Any component ID can be set for compression.
A component ID is recognized automatically for decompression.
(8) OS support
The compression, analysis, and decompression routines are reenterable. To execute a routine, specified
structures are required.
1.3.3
Features of basic libraries
(1) Buffer to store JPEG files
A buffer to store JPEG files is required to execute the basic libraries for compression, decompression, and
analysis. When the size of the JPEG file used is larger than that of the buffer, processing is aborted at the end
of the buffer. Processing is resumed after the user performs buffer processing (saving buffers when
compressing or updating buffers when decompressing/analyzing) and calls the basic library again. An arbitrary
value of 1 byte or more can be set for the size of the buffer to store JPEG files.
(2) Line processing
Processing of both compression and decompression can be aborted in 1 MCU line units.
Using this function enables compression/decompression for systems in which image memory (VRAM, etc.)
cannot hold one entire image.
(3) Color and monochrome
Compression and decompression is possible for both color images and monochrome images.
(4) Sampling ratio
The following four sampling ratios are supported.
• 4:1:1 [H:V = 2:2] (The screen size is a multiple of 16 both vertically and horizontally.)
• 4:1:1 [H:V = 4:1] (The screen size is a multiple of 32 horizontally, and of 8 vertically.)
• 4:2:2 [H:V = 2:1] (The screen size is a multiple of 16 horizontally, and of 8 vertically.)
• 4:4:4 [H:V = 1:1] (The screen size is a multiple of 8 both vertically and horizontally.)
The code size can be reduced by limiting the sampling ratio to be used.
User’s Manual U10684EJ3V0UM
45
CHAPTER 1 OVERVIEW
1.3.4 Features of additional library
(1) JPEG file storage buffer
To execute the additional library, the buffer for storing JPEG files is necessary. The library updates the JPEG
buffer by calling the JPEG acquisition function created by the user (see 3.5.3 (1) JPEGEXGetJpegStream).
Set the JPEG file storage buffer size to 32 bytes or larger (see 3.6.4 JPEGEXBUFF structure).
(2) Support of three file formats
The following three file formats can be decompressed.
• Progressive file format
• Baseline file format
• Extended baseline file format
(3) Sampling ratio
All sampling ratios are supported.
(4) Support of non-interleave format
The compressed data of a JPEG file is divided into units starting from an SOS segment called a scan.
The ordinary baseline format is an interleave format (single-scan format) in which only one scan exists in a file.
The additional library also supports a non-interleave format (multiscan format) that has multiple scans, as well
as the progressive format.
(5) Color components
In addition to a monochrome format, three-color formats and a four-color format are also supported.
(6) Clipping (in pixel units)
Clipping can be performed in pixel units (see 3.6.3 JPEGEXVIDEO structure).
(7) Zooming out/in during decompression
Zooming out or in can be carried out at a ratio of n/8 (n = 1, 2, 3, ...) during decompression (see 3.6.1
JPEGEXINFO structure).
(8) Library discontinuation
The execution of a library can be abandoned prior to its completion (see 3.6.1 JPEGEXINFO structure).
46
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
1.3.5 Differences between basic libraries and additional library
Table 1-7 shows the differences between the basic libraries and the additional library of the AP703000-B03.
Table 1-7. Differences Between Basic Libraries and Additional Library
Library
Basic Library
Additional Library
Baseline
O
O
Extended baseline
×
ONote
Progressive
×
O
Other
×
×
Interleave
O
O
Non-interleave
×
O
O
O
Item
File format
Encoding mode
Encoding
sequence
DNL marker support
Interface
library
Sampling ratio
4:1:1 (H:V = 2:2)
4:1:1 (H:V = 4:1)
4:2:2 (H:V = 2:1)
4:4:4
All sampling ratios supported
Color components
Monochrome, three colors
Monochrome, three colors, four
colors
Processing speed
Fast
Slow
Support if JPEG file storage buffer runs
short
Terminates library (library must
be called again for resumption)
Calls JPEG buffer replenishing
function
Clipping
×
Pixel units
Zooming out/in during decompression
×
Zooming out/in at ratio of n/8
Note A 16-bit quantization table is not supported. If a JPEG file with a 16-bit quantization table is decompressed,
an abnormal termination occurs (see 3.7 Errors During Additional Decompression).
Remark
O: Supported
×:
Not supported
When decompressing a file in the same baseline format, the additional library is slower than the basic library
because the additional library is intended for general-purpose use.
In addition, how options are to be set differs between the basic libraries and additional library. When setting an
option, refer to the description of how to set the option in question.
User’s Manual U10684EJ3V0UM
47
CHAPTER 1 OVERVIEW
1.3.6
Package contents
The package includes the following libraries and sample source.
Figure 1-18. Libraries and Sample Source (1/3)
NEC Tools32
lib850
r32
libjpegc.a:
[Basic compression] Compression main
libjcsm.a:
[Basic compression] Monochrome compression
libjcs11.a:
[Basic compression] Color compression sampling ratio 4:4:4 [H:V = 1:1]
libjcs21.a:
[Basic compression] Color compression sampling ratio 4:2:2 [H:V = 2:1]
libjcs22.a:
[Basic compression] Color compression sampling ratio 4:1:1 [H:V = 2:2]
libjcs41.a:
[Basic compression] Color compression sampling ratio 4:1:1 [H:V = 4:1]
libjcy.a:
[Basic compression] Image memory color space YCbCr
libjcr.a:
[Basic compression] Image memory color space RGB
libjpegd.a:
[Basic decompression] Decompression main
libjdsm.a:
[Basic decompression] Monochrome decompression
libjds11.a:
[Basic decompression] Color decompression sampling ratio 4:4:4 [H:V = 1:1]
libjds21.a:
[Basic decompression] Color decompression sampling ratio 4:2:2 [H:V = 2:1]
libjds22.a:
[Basic decompression] Color decompression sampling ratio 4:1:1 [H:V = 2:2]
libjds41.a:
[Basic decompression] Color decompression sampling ratio 4:1:1 [H:V = 4:1]
libjdhl.a:
[Basic decompression] Huffman decompression
libjdy.a:
[Basic decompression] Image memory color space YCbCr
libjdr.a:
[Basic decompression] Image memory color space RGB
libjpega.a:
[Basic analysis] Analysis main
libjpeg.a:
[Basic common] Common library
libjprg.a
[Additional decompression] Decompression
libjprog.a
[Additional decompression] Symbol resolution
libjprg_l.a
[Additional decompression] Decompression (long jump supported)
libjprog_l.a [Additional decompression] Symbol resolution (long jump supported)
lib850_ghs
inc850
r32
libjpegc.a:
[Basic compression] Compression main
libjcsm.a:
[Basic compression] Monochrome compression
libjcs11.a:
[Basic compression] Color compression sampling ratio 4:4:4 [H:V = 1:1]
libjcs21.a:
[Basic compression] Color compression sampling ratio 4:2:2 [H:V = 2:1]
libjcs22.a:
[Basic compression] Color compression sampling ratio 4:1:1 [H:V = 2:2]
libjcs41.a:
[Basic compression] Color compression sampling ratio 4:1:1 [H:V = 4:1]
libjcy.a:
[Basic compression] Image memory color space YCbCr
libjcr.a:
[Basic compression] Image memory color space RGB
libjpegd.a:
[Basic decompression] Decompression main
libjdsm.a:
[Basic decompression] Monochrome decompression
libjds11.a:
[Basic decompression] Color decompression sampling ratio 4:4:4 [H:V = 1:1]
libjds21.a:
[Basic decompression] Color decompression sampling ratio 4:2:2 [H:V = 2:1]
libjds22.a:
[Basic decompression] Color decompression sampling ratio 4:1:1 [H:V = 2:2]
libjds41.a:
[Basic decompression] Color decompression sampling ratio 4:1:1 [H:V = 4:1]
libjdhl.a:
[Basic decompression] Huffman decompression
libjdy.a:
[Basic decompression] Image memory color space YCbCr
libjdr.a:
[Basic decompression] Image memory color space RGB
libjpega.a:
[Basic analysis] Analysis main
libjpeg.a:
[Basic common] Common library
libjprg.a
[Additional decompression] Decompression
libjprog.a
[Additional decompression] Symbol resolution
jpeg.h
[Basic common] Header file for JPEG middleware
jpegex.h
[Additional decompression] Header file for JPEG middleware
sample.h
[Basic common] Header file for sample
[A] (see 2/3)
[B] (see 3/3)
48
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Figure 1-18. Libraries and Sample Source (2/3)
[A] (see 1/3)
smp850
jpeg
base
ex
archive:
Archive specification file
makefile:
make file
make.lx:
Link directive
main.c:
Sample main
sample.c:
Sample source
table.c:
Quantize/Huffman table (C language version)
vramacc0.s:
Sample getmcu/putmcu (assembly language version)
vramacc1.c:
Sample getmcu/putmcu (C language version)
start.s:
Startup
fish.tga:
Sample bitmap (Targa format)
archive:
Archive specification file
makefile:
make file
make.lx:
Link directive
1pass.c:
Single-pass processing sample source (RGB decompression)
2pass.c:
Two-pass processing sample source (RGB decompression)
jpexmcu.c:
C language putmcu sample
start.s:
Startup
basesmp.jpg: Sample image file (baseline format)
progsmp.jpg: Sample image file (progressive format)
both
archive:
Archive specification file
makefile:
make file
make.lx:
Link directive
main.c:
Sample main (basic compression, additional decompression)
sample.c:
Sample source
table.c:
Quantize/Huffman table (C language version)
jpexmcu.c:
C language putmcu sample
vramacc0.s:
Sample getmcu/putmcu (assembly language version)
vramacc1.c:
Sample getmcu/putmcu (C language version)
start.s:
Startup
fish.tga:
Sample bitmap (Targa format)
User’s Manual U10684EJ3V0UM
49
CHAPTER 1 OVERVIEW
Figure 1-18. Libraries and Sample Source (3/3)
[B] (see 1/3)
smp850_ghs
jpeg
base
archive:
Archive specification file
makefile:
make file
make.lx:
Link directive
main.c:
Sample main
sample.c:
Sample source
table.c:
Quantize/Huffman table (C language version)
vramacc0.s: Sample getmcu/putmcu (assembly language version)
vramacc1.c: Sample getmcu/putmcu (C language version)
ex
start.s:
Startup
fish.tga:
Sample bitmap (Targa format)
archive:
Archive specification file
makefile:
make file
make.lx:
Link directive
1pass.c:
Single-pass processing sample source (RGB decompression)
2pass.c:
Two-pass processing sample source (RGB decompression)
jpexmcu.c:
C language putmcu sample
start.s:
Startup
basesmp.jpg: Sample image file (baseline format)
progsmp.jpg: Sample image file (progressive format)
both
archive:
Archive specification file
makefile:
make file
make.lx:
Link directive
main.c:
Sample main (basic compression, additional decompression)
sample.c:
Sample source
table.c:
Quantize/Huffman table (C language version)
jpexmuc.c:
C language putmcu sample
vramacc0.s: Sample getmcu/putmcu (assembly language version)
vramacc1.c: Sample getmcu/putmcu (C language version)
50
start.s:
Startup
fish.tga:
Sample bitmap (Targa format)
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
1.3.7
Operating environment
(1) Applicable CPU
V850 Series
(2) Compiler package used
GHS (Green Hills Software, Inc.) compiler
CCV850 Ver. 4.0.2
NEC compiler package
CA850 Ver.2.40
(3) Memory capacity
The amount of ROM/RAM required for each library is as follows. However, the total differs depending on which
sampling ratio is selected.
When using RGB, more memory is required.
Table 1-8. ROM Size of Basic Libraries (Unit: Bytes)
No. of Required
Bytes
Option (Selection of Corresponding Sampling Ratio)
4:4:4 [H:V = 1:1]
4:2:2 [H:V = 2:1]
4:1:1 [H:V = 2:2]
4:1:1 [H:V = 4:1]
mono
Compression
6.0K
+0.6K
+0.8K
+1.2K
+1.2K
+0.5K
Decompression
5.0K
+0.5K
+0.6K
+0.8K
+0.8K
+0.5K
Analysis
2.0K
−
−
−
−
−
Table 1-9. ROM Size of Additional Library (Unit: Bytes)
NEC Compiler
GHS Compiler
Additional library
48 K
55 K
Additional library (long jump supported)
55 K
64 K
User’s Manual U10684EJ3V0UM
51
CHAPTER 1 OVERVIEW
Table 1-10. RAM Size of Basic Libraries (Unit: Bytes) (1/2)
(a) Compression
Name
Size
<1> JPEGINFO structure
148
<2> Work 1
256
<3> Work 2
3072
<4> MCU buffer
<5> Stack
Remark
Memory mapping to internal RAM is recommended.
128 to 768
128: Corresponding sampling ratio
384: Corresponding sampling ratio
512: Corresponding sampling ratio
768: Corresponding sampling ratio
mono
mono, 4:4:4
mono, 4:4:4, 4:2:2
mono, 4:4:4, 4:2:2, 4:1:1
128
<6> JPEG buffer
(Depends on system)
Compressed data storage memory
<7> Image memory
(Depends on system)
Image data storage memory (e.g., VRAM)
<8> APPINFO structure
<9> APPn data
96
Necessary only when using APPn segment
(Depends on system)
Necessary only when using APPn segment
Note
Subtotal
4372
Note This is the sum of <1> to <5> (with the maximum configuration of the MCU buffer)
(b) Decompression
Name
Size
<1> JPEGINFO structure
148
<2> Work 1
256
<3> Work 2
8192
<4> MCU buffer
<5> Stack
Remark
Memory mapping to internal RAM is recommended.
128 to 768
128: Corresponding sampling ratio
384: Corresponding sampling ratio
512: Corresponding sampling ratio
768: Corresponding sampling ratio
mono
mono, 4:4:4
mono, 4:4:4, 4:2:2
mono, 4:4:4, 4:2:2, 4:1:1
128
<6> JPEG buffer
(Depends on system)
Compressed data storage memory
<7> Image memory
(Depends on system)
Image data storage memory (e.g., VRAM)
Subtotal
9492Note
Note This is the sum of <1> to <5> (with the maximum configuration of the MCU buffer)
52
User’s Manual U10684EJ3V0UM
CHAPTER 1 OVERVIEW
Table 1-10. RAM Size of Basic Libraries (Unit: Bytes) (2/2)
(c) Analysis
Name
Size
<1> JPEGINFO structure
148
<2> Work 1
256
<3> Stack
128
<4> JPEG buffer
Memory mapping to internal RAM is recommended.
(Depends on system)
<5> APPINFO structure
<6> APPn data
Remark
Compressed data storage memory
96
Required only when using the APPn segment
(Depends on system)
Required only when using the APPn segment
Note
Short total
532
Note This is the sum of <1> to <3>
Table 1-11. RAM Size of Additional Library (Unit: Bytes)
Processing System
Additional library
Contents
Note
Size
Word area
Approx. 2 M
Stack
Approx. 500
Subtotal
Approx. 2 M
Additional library
Word areaNote
Approx. 5000
Two-pass setting
Stack
Approx. 500
Subtotal
Approx. 5500
Single-pass setting
Remark
This RAM size is applied only when 640 × 480 pixels
and only three colors are used. For actual use, a
capacitance in proportion to the number of pixels
and the number of colors is required.
Note For details of the work area of the additional library, see Table 3-10 Differences in Decompression
Processing Because of Number of Passes.
Remark
To execute the libraries, in addition to the required byte counts shown in the above table, a buffer that
stores JPEG files and a memory (VRAM etc.: the memory for output of decompressed image data) that
retains the image data are required.
User’s Manual U10684EJ3V0UM
53
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.1
Functions
The following three types of processing can be implemented by using the basic libraries available for the
AP703000-B03.
(1) Compression
Image data is compressed and a JPEG file is created.
Figure 2-1. Compression
Converted
into MCU
data
VRAM
JPEG
compression
xxx.jpg
Library
JPEG file
(2) Decompression
A JPEG file is decompressed and displayed on the screen.
Figure 2-2. Decompression
xxx.jpg
JPEG
decompression
JPEG file
Converted
into VRAM
data
Library
VRAM
(3) Analysis
Information such as the screen size is obtained from a JPEG file.
Figure 2-3. Analysis
xxx.jpg
JPEG file
54
JPEG
analysis
Library
Analysis
result
Analysis buffer
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.2
Details of Processing
2.2.1
Compression
Compression is the processing in which image data is compressed and a JPEG file is created.
(1) Functions
Classification
Compression
Function Name
Description
jpeg_CompressInit
Initialization of JPEG compression library
jpeg_Compress
Main JPEG compression
jpeg_getMCU_M
Note
VRAM access function (monochrome compression)
Note
VRAM access function (color compression, sampling ratio = 4:4:4 [H: V = 1:1])
Note
VRAM access function (color compression, sampling ratio = 4:2:2 [H: V = 2:1])
Note
VRAM access function (color compression, sampling ratio = 4:1:1 [H: V = 2:2])
Note
VRAM access function (color compression, sampling ratio = 4:1:1 [H: V = 4:1])
jpeg_getMCU_11
jpeg_getMCU_21
jpeg_getMCU_22
jpeg_getMCU_41
Note Reference these functions only for customization.
(a) jpeg_CompressInit
Classification
Compression
Function name
jpeg_CompressInit
Function outline Initializes a JPEG compression library.
Format
#include “jpeg.h”
void jpeg_CompressInit (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
This function initializes the JPEG compression library and prepares it for compression
execution.
User’s Manual U10684EJ3V0UM
55
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(b) jpeg_Compress
Classification
Compression
Function name
jpeg_Compress
Function outline Main JPEG compression
Format
#include “jpeg.h”
long jpeg_Compress (JPEGINFO *info)
Argument
Argument
Type
info
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
Error code
Error Code
Function
Description
JPEGRET_OK
Normal completion
JPEGRET_CONT1
Continuation 1 (request to save JPEG buffer)
JPEGRET_CONT2
Continuation 2 (request to update image data)
JPEGRET_ERR
Abnormal termination (contents of error are stored in member
“ErrorState” of JPEGINFO structure.)
This function executes JPEG compression specified by info.
If it is terminated abnormally, the value stored in member “ErrorState” of info is as follows.
Value of ErrorState
56
Description
JPEGERR_VRAM
Specified area of compressed image is illegal.
JPEGERR_USF
Compression cannot be executed at specified sampling ratio.
JPEGERR_IMY
Vertical size of compressed image is illegal.
JPEGERR_FID
Component ID values are duplicated.
JPEGERR_DLH
Lh value of DHT header is illegal.
JPEGERR_DCL
Huffman table for DC components is illegal.
JPEGERR_JPB
JPEG buffer size is illegal.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(2) Memory resources
The minimum memory (RAM) capacity necessary for using the compression library is as follows.
Name
Size
<1> JPEGINFO structure
148
<2> Work 1
256
<3> Work 2
3072
<4> MCU buffer
<5> Stack
Remark
Memory mapping to internal RAM is recommended.
128 to 768
128: Sampling ratio mono
384: Sampling ratio mono, 4:4:4
512: Sampling ratio mono, 4:4:4, 4:2:2
768: Sampling ratio mono, 4:4:4, 4:2:2, 4:1:1
Refer to 2.5 Structure of MCU Buffer.
128
<6> JPEG buffer
(Depends on system)
Compressed data storage memory
<7> Image memory
(Depends on system)
Image data storage memory (e.g., VRAM). Refer to 2.4 Configuration
of VRAM. The capacity of at least 1 MCU line is necessary.
<8> APPINFO structure
<9> APPn data
Subtotal
96
Necessary only when using APPn segment
(Depends on system)
Necessary only when using APPn segment
Note
4372
Note This is the sum of <1> to <5> (with the maximum configuration of the MCU buffer).
Caution
A memory that can be accessed at random in byte, halfword, or word units is necessary.
User’s Manual U10684EJ3V0UM
57
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(3) Compression flow
Figures 2-4 to 2-6 illustrate the flow of application processing using the compression library.
Figure 2-4. Flow of Compression
[User application]
[Library]
Start
<1> Set compression
parameter
(JPEGINFO structure
variable).
(D) Other
Image data
(BMP, TGA, GIF...)
Image processing
(decompression,
reduction,
color conversion...)
<2> Call compression
initialization function
(jpeg_CompressInit).
jpeg_CompressInit
initializes compression
library.
<3> Call compression
function
(jpeg_Compress).
Compression by
jpeg_Compress
JPEGRET_CONT2
JPEGRET_CONT1
(C) Image memory
manipulation.
Refer to Figure 2-6.
(B) JPEG buffer
manipulation.
Refer to Figure 2-5.
<4>
Check return
value.
JPEGRET_OK/
JPEGRET_ERR
(A) MCU disassemble
processing
jpeg_getMCU_M
jpeg_getMCU_11
jpeg_getMCU_21
jpeg_getMCU_22
jpeg_getMCU_41
End
At least processing <1> to <4> in Figure 2-4 is necessary for the user application when using the compression
library. Depending on the case, processing (A), (B), (C), or (D) may also be necessary.
58
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-5. JPEG Buffer Manipulation
Start
<5>
JPEG buffer
manipulation
(save/change)
Save
Change
<6> Set compression
parameter
(JPEGINFO structure
variable).
End
Remark
This is processing necessary to divide the JPEG data of one screen into several segments and
compress them because a memory capacity large enough to store the JPEG data is not available.
Figure 2-6. Image Memory Manipulation
Start
<7> Forced
completion/continuation
Forced
completion
<12> Set compression
parameter
(JPEGINFO structure
variable).
Continue
<8> Check
VRAM capacity.
Empty
Not Empty
Update
<9> Update/change
VRAM data.
Change
<11> Set compression
parameter
(JPEGINFO structure
variable).
<10> Set compression
parameter
(JPEGINFO structure
variable).
End
Remark
This processing is necessary when using a line unit compression function. Shown above is an
example of processing to transfer a compressed image via an external storage medium or by means
of communication.
User’s Manual U10684EJ3V0UM
59
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<1> Set compression parameter
Define the variable of the JPEGINFO structure defined in header file “jpeg.h” and set its members (refer to
2.7.2 Structure of JPEGINFO structure). Be sure to set the members first before executing new
compression. They do not have to be set when continuing the processing.
Table 2-1. User-Set Members
Member
Data to Be Set
Quality
Qauntization coefficient
Sampling
Sampling ratio
Restart
Restart interval
Width
Horizontal size of compressed image
Height
Vertical size of compressed image
StartX
Start x coordinate of compressed image
StartY
Start y coordinate of compressed image
VRAM_Bptr
First address of VRAM
VRAM_W_Pixel
Number of pixels in horizontal direction of VRAM
VRAM_H_Pixel
Number of pixels in vertical direction of VRAM
VRAM_Line_Byte
Number of bytes in 1 line of VRAM
VRAM_Pixel_Byte
Number of bytes in 1 pixel of VRAM
VRAM_Gap1_Byte
Number of bytes equivalent to VRAM address difference of Y/Cb or R/G component of one pixel
VRAM_Gap2_Byte
Number of bytes equivalent to VRAM address difference of Y/Cr or R/B component of one pixel
JPEG_Buff_Bptr
First address of JPEG file storage buffer
JPEG_Buff_Eptr
End address of JPEG file storage buffer
MCU_Buff_Bptr
First address of MCU buffer
DQT_Y_Bptr
First address of luminance component quantization table
DQT_C_Bptr
First address of chrominance component quantization table
DHT_DC_Y_Bptr
First address luminance DC component Huffman tableNote 1
DHT_DC_C_Bptr
First address of chrominance DC component Huffman table Note 1
DHT_AC_Y_Bptr
First address luminance AC component Huffman table Note 1
DHT_AC_C_Bptr
First address of chrominance AC component Huffman table Note 1
APP_Info_Bptr
When APPn marker supported: First address of APPINFO structure variable
When APPn marker not supported: 0
Work1_Bptr
First address of buffer for library work area 1
Work2_Bptr
First address of buffer for library work area 2
Mode
Library
operation
mode
JPEGMODE_NORMAL (normal compression mode)
One entire screen is compressed by calling a function once. AVRAM capacity large
enough to store image of one screen is necessary.
JPEGMODE_LINE (line compression mode)
Only one MCU line is compressed by calling a function once. AVRAM capacity large
enough to store the image of one MCU line is necessary. The image of one screen can be
compressed by calling a function several times.
DNL Note 2
When using DNL marker: JPEGDNL_ON
When not using DNL marker: JPEGDNL_OFF
CI1,CI2,CI3
Component ID Note 3
Notes 1. To use a Huffman table specified by the user, see 2.3.2 (1) Constraints of Huffman table.
2. If Height is set to 0, set JPEGDNL_ON. If JPEGDNL_OFF is set, abnormal termination occurs.
3. Set CI1, CI2, and CI3 to different values. If they are set to the same value, abnormal termination occurs.
60
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<2> Call compression initialization function [jpeg_CompressInit]
Call the compression initialization function, specifying the pointer to the structure set in “<1> Setting of
compression parameter” as the argument.
This function initializes the data necessary for compression and prepares the compression library for
execution. Be sure to call this function once before performing new compression. To continue compression,
this function does not have to be called.
<3> Call compression function [jpeg_Comrpess]
Call the compression function, specifying the pointer of the structure used in “<2> Call compression
initialization function” as the argument.
<4> Check return value [JPEGRET_OK/JPEGRET_ERR/JPEGRET_CONT1/JPEGRET_CONT2]
The return values of jpeg_ Compress are shown in the table below.
Table 2-2. Return Values of jpeg_Compress
Return Value
Meaning
Description
JPEGRET_OK
Normal completion
The function has been completed normally. To perform new
compression, start from “<1> Set compression parameter” again.
JPEGRET_ERR
Abnormal termination
Processing has been aborted because an error has been detected.
The details of the error are stored in member “ErrorState” of the
JPEGINFO structure. To perform new compression, start from “<1> Set
compression parameter” again.
JPEGRET_CONT1
Continuation 1
Processing has been stopped because the specified JPEG file storage
buffer has become full. To forcibly terminate the function and perform
new compression, start from “<1> Set compression parameter” again.
To continue the processing, execute “<5> Buffer manipulation”, and
start from “<3> Call compression function” again.
JPEGRET_CONT2
Continuation 2
This occurs only if the line compression mode is selected.
Processing has been stopped because compression of one MCU line
has been completed. To forcibly terminate the function and perform new
compression, start from “<1> Set compression parameter” again.
To continue the processing, execute “<8> Check VRAM capacity”, and
start from “<3> Call compression function” again.
To terminate the line compression mode, execute “<12> Set
compression parameter” and start from “<3> Call compression
function” again.
Table 2-3. Compression Result Information Members
Member
Data to Be Stored
ErrorState
Error status
FileSize
JPEG file size
User’s Manual U10684EJ3V0UM
61
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<5> JPEG buffer manipulation (save/change)
Select whether the contents of the JPEG file storage buffer are saved or changed.
To save the contents of the JPEG buffer and continue using the same buffer, start from “<3> Call
compression function” again.
To change the JPEG buffer, execute “<6> Set compression parameter” and then start from “<3> Call
compression function” again.
<6> Set compression parameter
Table 2-4. Compression Parameter Members (1)
Member
Data to Be Set
JPEG_Buff_Bptr
First address of JPEG file storage buffer
JPEG_Buff_Eptr
End address of JPEG file storage buffer
<7> Forced termination/continuation
To dump compressed data and forcibly terminate the processing by appending EOI, execute “<12> Set
compression parameter” and start from “<3> Call compression function”.
To continue, select “<8> Check VRAM capacity” and “<9> Update/change VRAM data”, execute “<10> Set
compression parameter” and “<11> Set compression parameter”, and then start from “<3> Call
compression function” again.
<8> Check VRAM capacity
If the VRAM is empty (if it has no image data), select “<9> Update/change VRAM data”, execute “<10> Set
compression parameter” and “<11> Set compression parameter”, and then start from “<3> Call
compression function” again.
If the VRAM is not empty, execute “<11> Set compression parameter” and then start from “<3> Call
compression function”.
<9> Update/change VRAM data
Update or change the VRAM data.
To change the data, execute “<10> Set compression parameter” and start from “<3> Call compression
function” again.
To update the data, execute “<11> Set compression parameter” and start from “<3> Call compression
function” again.
62
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<10> Set compression parameter
Table 2-5. Compression Parameter Members (2)
Member
Data to Be Set
StartX
Start x coordinate of compressed image
StartY
Start y coordinate of compressed image
VRAM_Bptr
First address of VRAM
VRAM_W_Pixel
Number of pixels of VRAM in horizontal direction
VRAM_H_Pixel
Number of pixels of VRAM in vertical direction
VRAM_Line_Byte
Number of bytes in one line of VRAM
VRAM_Pixel_Byte
Number of bytes in one pixel of VRAM
VRAM_Gap1_Byte
Number of bytes equivalent to VRAM address difference of Y/Cb or R/G
component of one pixel
VRAM_Gap2_Byte
Number of bytes equivalent to VRAM address difference of Y/Cr or R/B
component of one pixel
<11> Set compression parameter
Table 2-6. Compression Parameter Members (3)
Member
Data to Be Set
StartX
Start x coordinate of compressed image
StartY
Start y coordinate of compressed image
<12> Set compression parameter
Table 2-7. Compression Parameter Members (4)
Member
Mode
Data to Be Set
Forced termination mode (JPEGMODE_STOP)
User’s Manual U10684EJ3V0UM
63
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.2.2
Decompression
Decompression is processing in which a JPEG file is decompressed and displayed on screen.
(1) Functions
Classification
Decompression
Function Name
Functional Outline
jpeg_DecompressInit
Initialization of JPEG decompression library
jpeg_Decompress
Main JPEG decompression
jpeg_putMCU_M
Note
VRAM access function (monochrome decompression)
Note
VRAM access function (color decompression, sampling ratio = 4:4:4 [H:V = 1:1]
Note
VRAM access function (color decompression, sampling ratio = 4:2:2 [H:V = 2:1]
Note
VRAM access function (color decompression, sampling ratio = 4:1:1 [H:V = 2:2]
Note
VRAM access function (color decompression, sampling ratio = 4:1:1 [H:V = 4:1]
jpeg_putMCU_11
jpeg_putMCU_21
jpeg_putMCU_22
jpeg_putMCU_41
Note Reference these functions only for customization.
(a) jpeg_DecompressInit
Classification
Decompression
Function name
jpeg_DecompressInit
Function outline Initialization of JPEG decompression library
Format
#include “jpeg.h”
void jpeg_DecompressInit (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
This function initializes the JPEG decompression library and prepares it for
decompression execution.
64
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(b) jpeg_Decompress
Classification
Decompression
Function name
jpeg_Decompress
Function outline Main JPEG decompression
Format
#include “jpeg.h”
long jpeg_Decompress (JPEGINFO *info)
Argument
Argument
Type
info
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
Error code
Error Code
Description
JPEGRET_OK
Normal termination
JPEGRET_CONT1
Continuation 1 (JPEG buffer updating request)
JPEGRET_CONT2
Continuation 2 (image data saving request)
JPEGRET_ERR
Abnormal termination (error contents are stored in member
“ErrorState” of JPEGINFO structure.)
User’s Manual U10684EJ3V0UM
65
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Function
This function executes the JPEG decompression specified by info.
If it is terminated abnormally, the value stored in member “ErrorState” of info is as follows.
Value of ErrorState
66
Description
JPEGERR_VRAM
Area of image specified for decompression is illegal.
JPEGERR_USF
This sampling ratio cannot be decompressed.
JPEGEER_QPQ
Value of Pq of DQT header is not set to 0.
JPEGERR_QTQ
Quantization table number (Tq) of DQT header is value other than 0
and 1.
JPEGERR_DHT
Values of Tc and Th of DHT header are illegal.
JPEGERR_SNS
Ns value (number of components) of SOS header is illegal (other than
1 and 3).
JPEGERR_SCD
Huffman table number specified by SOS table is wrong.
JPEGERR_SSS
Value of Ss of SOS header is not 0.
JPEGERR_SSE
Value of Se of SOS header is not 63.
JPEGERR_SAA
Value of Ah and Al of SOS header is not 0.
JPEGERR_SFP
Value other than 8 is set to P of SOF header.
JPEGERR_SFN
Value of Nf of SOF header is illegal (other than 1 and 3).
JPEGERR_UKM
Unknown marker has appeared.
JPEGERR_OTH
Illegal marker has appeared in compressed data.
JPEGERR_RST
RSTm marker is illegal.
JPEGERR_SOS
Other SOS header error (component ID is illegal).
JPEGERR_SOF
SOF header is not defined or two or more are defined.
JPEGERR_FTQ
Required quantization table is not defined.
JPEGERR_STH
Required Huffman table is not defined.
JPEGERR_IMY
Vertical size of image is illegal.
JPEGERR_FID
Component IDs of SOF header are duplicated.
JPEGERR_SID
Component IDs of SOS header are duplicated.
JPEGERR_QEL
0 is included in quantization table elements.
JPEGERR_VIJ
Huffman table elements are duplicated.
JPEGERR_JPB
JPEG buffer size is illegal.
JPEGERR_HUF
Compressed data is illegal.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(2) Memory resources
The minimum memory (RAM) capacity necessary for using the decompression library is as follows.
Name
Size
<1> JPEGINFO structure
148
<2> Work 1
256
<3> Work 2
8192
<4> MCU buffer
<5> Stack
Remark
Memory mapping to internal RAM is recommended.
128 to 768
128: Sampling ratio mono
384: Sampling ratio mono, 4:4:4
512: Sampling ratio mono, 4:4:4, 4:2:2
768: Sampling ratio mono, 4:4:4:, 4:2:2, 4:1:1
Refer to 2.5 Structure of MCU Buffer.
128
<6> JPEG buffer
(Depends on system)
Compressed data storage memory
<7> Image memory
(Depends on system)
Image storage memory (e.g., VRAM). Refer to 2.4 Configuration of
VRAM. The capacity of at least 1 MCU line is necessary.
Subtotal
9492Note
Note This is the sum of <1> to <5> (with the maximum capacity of the MCU buffer).
Caution
A memory that can be accessed at random in byte, halfword, or word units is necessary.
User’s Manual U10684EJ3V0UM
67
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(3) Decompression flow
Figures 2-7 to 2-9 show the flow of an application using the decompression library.
Figure 2-7. Flow of Decompression
[User application]
[Library]
Start
<1> Set decompression
parameter
(JPEGINFO structure
variable)
(D) Other
Image encoder
(BMP, TGA, GIF...)
Image processing
(decompression,
reduction,
color conversion...)
<2> Call decompression
initialization function
(jpeg_DecompressInit).
jpeg_DecompressInit
Initializes decompression
library.
<3> Call decompression
function
(jpeg_Decompress).
jpeg_Decompress
Decompression
JPEGRET_CONT2
JPEGRET_CONT1
(C) Image memory
manipulation.
Refer to Figure 2-9.
(B) JPEG buffer
manipulation.
Refer to Figure 2-8.
<4> Check
return value.
JPEGRET_OK/
JPEGRET_ERR
(A) MCU disassemble
processing
jpeg_putMCU_M
jpeg_putMCU_11
jpeg_putMCU_21
jpeg_putMCU_22
jpeg_putMCU_41
End
At least processing <1> to <4> in Figure 2-7 is necessary for the user application when using the
decompression library. Depending on the case, processing (A), (B), (C), and (D) may be necessary.
68
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-8. JPEG Buffer Manipulation
Start
<5> JPEG
buffer manipulation
(update/change).
Update
Change
<6> Set decompression
parameter
(JPEGINFO structure
variable).
End
Remark
This processing is necessary to divide JPEG data of one screen into several segments and
decompress them because a memory capacity large enough to store the JPEG data is not available.
Figure 2-9. Image Memory Manipulation
Start
<7> Check VRAM
capacity.
Not Full
Save
Full
<8> Update/change
VRAM data.
Change
<10> Set decompression
parameter
(JPEGINFO structure
variable).
<9> Set decompression
parameter
(JPEGINFO structure
variable).
End
Remark
This processing is necessary when using a line unit decompression function. Shown above is an
example of processing to transfer a decompressed image via an external storage medium or by
means of communication.
User’s Manual U10684EJ3V0UM
69
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<1> Set decompression parameter
Define the variable of the JPEGINFO structure defined in header file “jpeg.h” and set the members (refer to
2.7.2
Structure of JPEGINFO structure).
Be sure to set the members first before executing new
decompression. They do not have to be set when continuing decompression.
Table 2-8. User-Set Members
Member
Data to Be Set
StartX
Start x coordinate of decompressed image
StartY
Start y coordinate of decompressed image
VRAM_Bptr
First address of VRAM
VRAM_W_Pixel
Number of pixels in horizontal direction of VRAM
VRAM_H_Pixel
Number of pixels in vertical direction of VRAM
VRAM_Line_Byte
Number of bytes in 1 line of VRAM
VRAM_Pixel_Byte
Number of bytes in 1 pixel of VRAM
VRAM_Gap1_Byte
Number of bytes equivalent to VRAM address difference of Y/Cb or R/G
component of one pixel
VRAM_Gap2_Byte
Number of bytes equivalent to VRAM address difference of Y/Cr or R/B
component of one pixel
JPEG_Buff_Bptr
First address of JPEG file storage buffer
JPEG_Buff_Eptr
End address of JPEG file storage buffer
MCU_Buff_Bptr
First address of MCU buffer
APP_Info_Bptr
0
Work1_Bptr
First address of buffer for library work area 1
Work2_Bptr
First address of buffer for library work area 2
Mode
Library
operation
mode
JPEGMODE_NORMAL (normal decompression mode)
One entire screen is decompressed by calling a function once.
AVRAM capacity large enough to store the image of one
screen is necessary.
JPEGMODE_MCULINE (line decompression mode)
Only one MCU line is decompressed by calling a function
once. AVRAM capacity large enough to store the image of 1
MCU line is necessary. The image of one screen can be
decompressed by calling a function as many times as required.
<2> Call decompression initialization function [jpeg_DecompressInit]
Call the decompression initialization function, specifying the pointer to the structure set in “<1> Set
decompression parameter” as the argument.
This function initializes the data necessary for decompression and prepares the decompression library for
execution. Be sure to call this function once to perform new decompression. To continue decompression,
this function does not have to be called.
70
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<3> Call decompression function [jpeg_Decompress]
Call the decompression function, specifying the pointer to the structure used in “<2> Call decompression
initialization function” as the argument.
<4> Check return value [JPEGRET_OK/JPEGRET_ERR/JPEGRET_CONT1/JPEGRET_CONT2]
The return values of jpeg_Decompress are shown in the table below.
Table 2-9. Return Values of jpeg_Decompress
Return Value
Meaning
Description
JPEGRET_OK
Normal completion
The function has been completed normally. To perform new
decompression, start from “<1> Set decompression parameter” again.
JPEGRET_ERR
Abnormal termination
Processing has been aborted because an error has been detected.
The details of the error are stored in member “ErrorState” of the
JPEGINFO structure. To perform new decompression, start from “<1>
Set decompression parameter” again.
JPEGRET_CONT1
Continuation 1
Processing has been stopped because a JPEG file end code could not
be found after the contents of the specified JPEG file storage buffer were
decompressed.
To forcibly terminate the function and perform new decompression, start
from “<1> Set decompression parameter” again. To continue the
processing, execute “<5> Manipulate buffer”, and start from “<3> Call
decompression function” again.
JPEGRET_CONT2
Continuation 2
This occurs only if the line decompression mode is selected.
Processing has been stopped because decompression of one MCU line
has been completed. To forcibly terminate the function and perform new
decompression, start from “<1> Set decompression parameter” again.
To continue the processing, execute “<7> Check VRAM capacity”, and
start from “<3> Call decompression function” again.
Table 2-10. Decompression Result Information Members
Member
Data to Be Stored
ErrorState
Error status
FileSize
JPEG file size
Sampling
Sampling ratio
Restart
Restart interval
Width
Horizontal size of image
Height
Vertical size of image
CI1
Component ID1
CI2
Component ID2
CI3
Component ID3
<5> JPEG buffer manipulate (update/change)
Select whether the contents of the JPEG file storage buffer are updated or changed.
To update the contents of the JPEG buffer and continue using the same buffer, start from “<3> Call
decompression function” again.
To change the JPEG buffer, execute “<6> Set decompression parameter” and then start from “<3> Call
decompression function” again.
User’s Manual U10684EJ3V0UM
71
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
<6> Set decompression parameter
Table 2-11. Setting of Decompression Parameter (1)
Member
Data to Be Set
JPEG_Buff_Bptr
First address of JPEG file storage buffer
JPEG_Buff_Eptr
End address of JPEG file storage buffer
<7> Check VRAM capacity
If the VRAM is full (if it is filled with image data), select “<8> Save/change VRAM data”, execute “<9> Set
decompression parameter”/“<10> Set decompression parameter”, and then start from “<3> Call
decompression function” again.
If the VRAM is not full, execute “<10> Set decompression parameter” and start from “<3> Call
decompression function” again.
<8> Save/change VRAM data
Save or change the VRAM data.
To save the data, execute “<9> Set decompression parameter” and start from “<3> Call decompression
function” again.
To update the data, execute “<10> Set decompression parameter” and start from “<3> Call
decompression function” again.
<9> Set decompression parameter
Table 2-12. Setting of Decompression Parameter (2)
Member
Data to Be Set
StartX
Start x coordinate of decompressed image
StartY
Start y coordinate of decompressed image
VRAM_Bptr
First address of VRAM
VRAM_W_Pixel
Number of pixels of VRAM in horizontal direction
VRAM_H_Pixel
Number of pixels of VRAM in vertical direction
VRAM_Line_Byte
Number of bytes in one line of VRAM
VRAM_Pixel_Byte
Number of bytes in one pixel of VRAM
VRAM_Gap1_Byte
Number of bytes equivalent to VRAM address difference of Y/Cb or R/G
component of one pixel
VRAM_Gap2_Byte
Number of bytes equivalent to VRAM address difference of Y/Cr or R/B
component of one pixel
<10> Set decompression parameter
Table 2-13. Setting of Decompression Parameter (3)
Member
72
Data to Be Set
StartX
Start x coordinate of decompressed image
StartY
Start y coordinate of decompressed image
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.2.3
Analysis
Analysis is processing in which a JPEG file is analyzed and the following data is obtained.
<1> Sampling ratio
<2> Restart interval
<3> Size of screen (horizontal/vertical)
<4> JPEG file size
<5> Application data (APP data)
<6> Component ID
(1) Functions
Function Name
Function
jpeg_AnalysisInit
Initialization of JPEG analysis library
jpeg_Analysis
JPEG analysis
(a) jpeg_AnalysisInit
Classification
Analysis
Function name
jpeg_AnalysisInit
Function outline Initialization of JPEG analysis library
Format
#include “jpeg.h”
void jpeg_AnalysisInit (JPEGINFO *info)
Argument
Argument
info
Note
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
This function initializes the JPEG analysis library and prepares it for analysis execution.
User’s Manual U10684EJ3V0UM
73
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(b) jpeg_Analysis
Classification
Analysis
Function name
jpeg_Analysis
Function outline Main JPEG analysis
Format
#include “jpeg.h”
long jpeg_Analysis (JPEGINFO *info)
Argument
Argument
Type
info
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
Error code
Error Code
Function
Description
JPEGRET_OK
Normal completion
JPEGRET_CONT1
Continuation 1 (JPEG buffer updating request)
JPEGRET_ERR
Abnormal termination (error contents are stored in the member
“ErrorState” of the JPEGINFO structure.)
This function executes the JPEG analysis specified by info.
If the function is abnormally terminated, the value stored in member “ErrorState” of info is
as follows.
Value of ErrorState
74
Description
JPEGERR_SNS
Ns value (number of components) of SOS header is illegal (other than
1 or 3).
JPEGERR_SCD
Huffman table number specified by SOS header is wrong.
JPEGEER_SSS
Value of Ss of SOS header is not 0.
JPEGERR_SSE
Value of Se of SOS header is not 63.
JPEGERR_SAA
Values of Ah and Al of SOS header are not 0.
JPEGERR_SFP
Value other than 8 is set to P of SOF header.
JPEGERR_SFN
Value of Nf of SOF header is illegal (other than 1 or 3).
JPEGERR_UKM
Unknown marker appears.
JPEGERR_JPB
JPEG buffer size is illegal.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(2) Memory resources
The minimum memory (RAM) capacity necessary for using the analysis library is as follows.
Name
Size
<1> JPEGINFO structure
148
<2> Work 1
256
<3> Stack
128
<4> JPEG buffer
<5> APPINFO structure
<6> APPn data
Subtotal
Remark
Memory mapping to internal RAM is recommended.
(Depends on system)
Compressed data storage memory
96
Necessary only when using APPn segment
(Depends on system)
Necessary only when using APPn segment
Note
532
Note This is the sum of <1> to <3>.
Caution
A memory that can be accessed at random in byte, halfword, or word units is necessary.
User’s Manual U10684EJ3V0UM
75
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(3) Processing flow
Figures 2-10 and 2-11 show the flow of application processing using the analysis library.
Figure 2-10. Flow of Analysis
[User application]
[Library]
Start
<1> Set analysis
parameter
(JPEGINFO structure
variable).
<2> Call analysis
initialization function
(jpeg_AnalysisInit).
jpeg_AnalysisInit
Initializes analysis library.
<3> Call analysis function
(jpeg_Analysis).
jpeg_Analysis
Analysis
JPEGRET_CONT1
(A) JPEG buffer
manipulation
Refer to Figure 2-11.
<4> Check
return value.
JPEGRET_OK/
JPEGRET_ERR
End
At least processing <1> to <4> in Figure 2-10 is necessary for the user application when using the analysis
library. Depending on the case, processing <A> may be also necessary.
76
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-11. JPEG Buffer Manipulation
Start
<5> JPEG
buffer manipulation
(update/change)
Update
Change
<6> Set analysis
parameter
(JPEGINFO structure
variable).
End
<1> Set analysis parameter
Define the variable of the JPEGINFO structure defined in header file “jpeg.h” and set the members (refer to
2.7.2 Structure of JPEGINFO structure). Be sure to set the members first before executing new analysis.
They do not have to be set when continuing the processing.
Table 2-14. User-Set Members
Member
Caution
Data to Be Set
JPEG_Buff_Bptr
First address of JPEG file storage buffer
JPEG_Buff_Eptr
End address of JPEG file storage buffer
APP_Info_Bptr
When APPn marker supported: First address of APPINFO structure variable
When APPn marker not supported: 0
Work1_Bptr
First address of library work area buffer
If APP_Info_Bptr is set to a value other than 0, the structure is initialized in the analysis
initialization function (jpeg_AnalysisInit). Because 96 bytes from the set value are cleared to 0,
save the required data before calling the function.
<2> Call analysis initialization function [jpeg_AnalysisInit]
Call the analysis initialization function, specifying the pointer to the structure set in “<1> Set analysis
parameter” as the argument.
This function initializes the data necessary for analysis and prepares the analysis library for execution. Be
sure to call this function once before performing new analysis. To continue analysis, this function does not
have to be called.
<3> Call analysis function [jpeg_Analysis]
Call the analysis function, specifying the pointer to the structure used in “<2> Call analysis initialization
function” as the argument.
<4> Check return value [JPEGRET_OK/JPEGRET_ERR/JPEGRET_CONT1]
The return values of the jpeg_Analysis function are shown in the table below.
User’s Manual U10684EJ3V0UM
77
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Table 2-15. Return Value of jpeg_Analysis
Return Value
Meaning
Description
JPEGRET_OK
Normal completion
The function has been completed normally.
To perform new analysis, start from “<1> Set analysis parameter” again.
JPEGRET_ERR
Abnormal termination
Processing has been terminated because an error has been detected.
The details of the error are stored in the member “ErrorState” of the
JPEGINFO structure.
To perform new analysis, start from “<1> Set analysis parameter” again.
JPEGRET_CONT1
Continuation 1
Processing has been stopped because a JPEG file end code could not
be found after the contents of the specified JPEG file storage buffer were
analyzed.
To forcibly terminate the processing and perform new analysis, start from
“<1> Set analysis parameter” again.
To continue the processing, execute “<5> JPEG buffer manipulation
(update/change)” and then start from “<3> Call analysis function”
again.
Table 2-16. Analysis Result Information Members
Member
Data to Be Stored
ErrorState
Error status
Sampling
Sampling ratio
Restart
Restart interval
Width
Horizontal size of image
Height
Vertical size of image
FileSize
JPEG file size
APP_Info_Bptr
The address of the APPn marker and data
size are stored in the member of the
specified APPINFO structure variable only if
the address of the APPINFO structure
variable is set to this member when the
initial parameter is set.
CI1
Component ID1
CI2
Component ID2
CI3
Component ID3
<5> JPEG buffer manipulation (update/change)
Select whether the contents of the JPEG buffer are updated or changed.
To update the contents of the JPEG buffer and continue using the same buffer, start from “<3> Call analysis
function” again.
To change the JPEG buffer, execute “<6> Set analysis parameter”, and then start from “<3> Call analysis
function” again.
<6> Set analysis parameter
Table 2-17. Setting of Analysis Parameter
Member
78
Data to Be Set
JPEG_Buff_Bptr
First address of JPEG file storage buffer
JPEG_Buff_Eptr
End address of JPEG file storage buffer
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.3
2.3.1
JPEG Format
Supported formats
The AP703000-B03 supports the following formats.
Table 2-18. Supported JPEG Formats
Coding method
Coding sequence
Baseline
Extended baseline
×
Progressive
×
Other
×
Interleave
Non-interleave
×
Lossless method (reversible method)
×
Hierarchical method
×
Sampling ratio
Color
4:4:4 [H:V = 1:1]
4:2:2 [H:V = 2:1]
4:1:1 [H:V = 2:2]
4:1:1 [H:V = 4:1]
Monochrome
H:V = 1:1
H:V = 1:2
H:V = 1:3
H:V = 1:4
H:V = 2:1
H:V = 2:2
H:V = 2:3
H:V = 2:4
H:V = 3:1
H:V = 3:2
H:V = 3:3
H:V = 4:1
H:V = 4:2
Component
Monochrome, 3 colors
Quantization table
2 planes (compression), 4 planes (decompression)
Huffman table
4 planes
(decompression)
COM (comment marker)
APPn (application marker)
DRI/RSTm (restart marker)
DNL (line count redefinition marker)
Remark
: Supported
×: Not supported
User’s Manual U10684EJ3V0UM
79
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.3.2
DHT marker
(1) Constraints of Huffman table
In the AP703000-B03, the Huffman table that is used for compression can be exchanged. However, it does not
mean that the Huffman table can be exchanged with any table. If an incorrect Huffman table is specified, some
images cannot be compressed correctly. Nevertheless, the compression routine of the AP703000-B03 is
completed normally even in such a case (i.e., the routine returns JPEGRET_OK).
To avoid this situation, keep in mind the following two points when creating a Huffman table.
(a) L1 to L16 of the new Huffman table must be logically correct.
(b) V1 to Vm of the new Huffman table must include DC components up to category 11 or AC components up
to category 10.
Figure 2-12. DHT Segment
0xFF 0xC4
Lh
id
L1
L2
...
L16
V1
V2
Table 2-19. Value of DC/AC Component and Bit Length
Value of Component
0
−1, 1
−3, −2, 2, 3
−7 to −4, 4 to 7
−15 to −8, 8 to 15
−31 to −16, 16 to 31
−63 to −32, 32 to 63
−127 to −64, 64 to 127
−255 to −128, 128 to 255
−511 to −256, 256 to 511
−1023 to −512, 512 to 1023
−2047 to −1024, 1024 to 2047
80
User’s Manual U10684EJ3V0UM
Category
0
1
2
3
4
5
6
7
8
9
10
11
...
Vm
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(i) L1 to L16 of the DHT segment indicate how many Huffman codes of a bit length of i exist.
Suppose the values of L1 to L16 are as follows.
00, 01, 05, 01, 01, 01, 01, 01, 01, 00, 00, 00, 00, 00, 00, 00
The meaning of this is that there are:
0 1-bit codes
One 2-bit code, 00
Five 3-bit codes, 010, 011, 100, 101, and 110
One 4-bit code, 1110
One 5-bit code, 11110
One 6-bit code, 111110
One 7-bit code, 1111110
One 8-bit code, 11111110
One 9-bit code, 111111110
No other code
The values of compressed codes are sequentially determined, starting from the code with the shortest bit
length, as illustrated below.
Figure 2-13. Determination of Values of Compressed Codes
First bit
Second bit
Third bit
0
0
: First code
0
: Second code
1
: Third code
0
: Fourth code
1
1
...
0
1
1
0
0
1
0
1
1
...
L1 to L16 of the DHT segment do not have a meaning as data if they do not correspond to the meaning of
each element. For example, a combination having three 1-bit values (L1 = 3) cannot exist. However, the
AP703000-B03 does not check this. Therefore, use a Huffman table that has logically meaningful values
as L1 to L16.
User’s Manual U10684EJ3V0UM
81
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(ii) V1 to Vm of the DHT segment indicate to which combination of a category and zero run each compressed
code corresponds.
Suppose the values of V1 to Vm are as follows.
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B (m = 12)
This means that the category of each code is as follows.
The first compressed code (00) is of category 0 (End of Block).
The second compressed code (010) is of category 1.
The third compressed code (011) is of category 2.
The fourth compressed code (100) is of category 3.
The fifth compressed code (101) is of category 4.
The sixth compressed code (110) is of category 5.
:
The 12th compressed code (111111110) is of category 11 (0xB).
82
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
In elements of V1 to Vm of a Huffman table for DC components are 0 to 0xB. Generally, bit lengths of
categories 2 and 1 are distributed most when an image is compressed. The closer to category 11, the
lower the probability of appearance. Depending on the image, bit lengths of categories 8, 9, 10, and 11 do
not appear at all. In this case, the image is still compressed and decompressed normally even in a
Huffman table that does not have categories 8 and onward for its V1 to Vm. If a Huffman table without
categories 8 and onward is used to compress an image that has a value of category 9, the compression
routine of the AP703000-B03 fills the compressed code corresponding to category 9 with zeroes of bit
length 0. The routine is normally completed, assuming that a compressed code is filled, even if no
compressed code is actually filled. If a JPEG file created in this way is decompressed, an error occurs
from the location where data of category 9 should appear, or the image is mosaic.
The AC coefficient has the same tendency as the DC coefficient. For example, the elements of V1 to Vm
are as follows in the AC component Huffman table (jpeg_DHT_AC_Y) supplied with the AP703000-B03:
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08
0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16
0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28
0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49
0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59
0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69
0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79
0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89
0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98
0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7
0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6
0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5
0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4
0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2
0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA
0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8
0xF9, 0xFA
User’s Manual U10684EJ3V0UM
83
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
The lower 4 bits of each element indicate the category, and the higher 4 bits indicate zero run. 0x00 and
0xF0 are special codes meaning EOB (end of block) and ZRL (zero run length), respectively.
The meanings of the codes in the above example are therefore:
The first compressed code is of zero run 0 and category 1.
The second compressed code is of zero run 0 and category 2.
The third compressed code is of zero run 0 and category 3.
The fourth compressed code is EOB.
The fifth compressed code is of zero run 0 and category 4.
The sixth compressed code is of zero run 1 and category 1.
:
The lower the category of an AC coefficient, the higher the probability the coefficient appears. The higher
the category, the lower the probability of appearance. Zero run of 0 appears most, and the higher the
value, the lower the probability of appearance.
Therefore, creating a Huffman table that does not have a compressed code corresponding to the part with
a high value of zero run and category is an alternative. However, the AP703000-B03 may not decompress
the image correctly if it has been compressed with such a Huffman table specified.
Therefore, use a Huffman table that has well-balanced values of V1 to Vm.
2.3.3
APPn marker
The procedure of each processing supporting the APPn marker is explained below.
(1) Compression
The flow of application processing using the compression library supporting the APPn marker is illustrated
below.
Figure 2-14. Flow of Compression Using APPn Marker
Start
<1> Create APP data.
Create APP data, define the variable of the APPINFO structure
defined in header file “jpeg_h”, and set members.
<1> Create APP data.
For details, refer to 2.7.3 Structure of APPINFO structure.
<2> Compression
<2> Compression
For details, refer to 2.2.1 Compression.
End
84
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(2) Decompression
The flow of application processing using the decompression library supporting the APPn marker is illustrated
below.
Figure 2-15. Flow of Decompression Using APPn Marker
Start
<1> Analysis supporting APP
For details, refer to 2.2.3 Analysis.
<1> Analysis supporting APP
<2> Decompression
For details, refer to 2.2.2 Decompression.
<3> APP processing
<2> Decompression
Based on the data stored in the APPINFO structure variable in
<1> above, perform processing supporting the APPn marker.
<3> APP processing
End
(3) Analysis
For how to use the analysis library supporting the APPn marker, refer to 2.2.3 Analysis.
User’s Manual U10684EJ3V0UM
85
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.3.4
DNL marker
A DNL marker is used to redefine the number of lines (height) of an image and is located at the end of compressed
data.
This is an option for baseline DCT.
Usually, image size (number of lines) is defined by a SOFn segment. If a DNL segment is defined, the number of
lines defined by the DNL segment takes precedence. If the SOFn segment defines image size as 0 lines, the DNL
segment is essential.
The figure below illustrates how the DNL marker is usually used and how to set parameters to realize a DNL
marker with the basic libraries.
Figure 2-16. Setting of JPEG File
Format 1
Format 2
Format 3
SOI
SOI
SOI
Markers
Markers
Markers
SOF0
Image size: 100 lines
SOF0
Image size: 0 lines
SOF0
Image size: 100 lines
Markers
Markers
Markers
Compressed data
of 100 lines
Compressed data
of 100 lines
Compressed data
of 50 lines
DNL
Image size: 100 lines
DNL
Image size: 100 lines
DNL
Image size: 50 lines
EOI
EOI
EOI
Setting of structure
Setting of structure
Setting of structure
Height = 100
Mode = JPEGMODE_MCULINE
DNL = JPEGDNL_ON
Height = 0
Mode = JPEGMODE_MCULINE
DNL = JPEGDNL_ON
Height = 100
Mode = JPEGMODE_MCULINE
DNL = JPEGDNL_ON
After 100-line compression
Mode = JPEGMODE_STOP
After 50-line compression
Mode = JPEGMODE_STOP
If the image size (number of lines) is still unknown when compression is started, a DNL marker can be realized by
setting structure members as shown in Format 2 above. In addition, if the number of lines of an SOF segment is other
than 0 and the number of lines of decompressed data exceeds the number of lines of the SOF segment,
compression/decompression cannot be performed correctly.
Remark
As compared with other option markers (such as DRI and RSTm), not many tools support the DNL
marker. Avoid using the DNL marker when you want to create a versatile JPEG file.
86
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.3.5
Supporting monochrome format
The basic libraries supply the following two methods of compressing/decompressing monochrome images.
Figure 2-17. Monochrome Format
Method 1
If JPEG file is color
Method 2
If JPEG file is monochrome
VRAM
Cb/Cr components
are compressed as
fixed values.
VRAM
Normal VRAM
drawing after
decompression
Only Y component
is extracted and
compressed. Cb/Cr
components are
discarded.
VRAM drawing after
decompression with
Cb/Cr components
as fixed values.
*.JPG
*.JPG
Format 1
Format 2
SOI
SOI
Markers
Markers
SOF0
Number of components = 3
SOF0
Number of components = 1
Markers
Markers
Compressed data
ex. YCbCr
Y = Image data
Cb = Fixed value
Cr = Fixed value
Compressed data
ex. YCbCr
Y = Image data
Cb = No data
Cr = No data
EOI
EOI
User’s Manual U10684EJ3V0UM
87
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
How to use and the result of executing the library by “method 2” are as follows.
Figure 2-18. Selecting Basic Library and Execution Result
Start
Monochrome
LIB selected during
link?Note 1
No
Yes
Monochrome
processing selected
during execution?
Monochrome
processing selected
during execution?Note 2
No
Yes
Normal completion
(monochrome processing)
Notes 1. Compression
Decompression
No
Yes
Normal completion
(color processing)
Abnormal termination
(monochrome processing)
Normal completion
(color processing)
libjcsm.a
libjdsm.a
2. This is determined depending on the value specified as the member “Sampling”.
• Color
JPEGSAMPLE11 (0x11)
JPEGSAMPLE21 (0x21)
JPEGSAMPLE22 (0x22)
JPEGSAMPLE41 (0x41)
• Monochrome
Result of ORing JPEGSAMPLEMONO (0x80) with the following value:
0x11 0x12 0x13 0x14 0x21 0x22 0x23 0x24 0x31 0x32 0x33 0x41 0x42
The meanings of the bits of member “Sampling” are as follows.
bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
V: 1 to 4
Fixed to 0
H: 1 to 4
0: Color
1: Monochrome
88
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.4
Configuration of VRAM
The default VRAM access routine assumes that the VRAM is a memory with Y/Cb/Cr or R/G/B each having a
depth of 256 gray scales (1 byte) and can be accessed by the LD.B and ST.B instructions.
The values of the following members are referenced when the default VRAM access routine is used.
Table 2-20. Configuration of VRAM
Member
Description
VRAM_Bptr
VRAM first address (base address)
VRAM_W_Pixel
Number of horizontal pixels of VRAM
VRAM_H_Pixel
Number of vertical pixels of VRAM
VRAM_Line_Byte
Address difference of VRAM of vertical 1 pixel
VRAM_Pixel_Byte
Address difference of VRAM of horizontal 1 pixel
VRAM_Gap1_Byte
If VRAM is of YCbCr, address difference between Y and Cb of one pixel
If VRAM is of RGB, address difference between R and G of one pixel
VRAM_Gap2_Byte
If VRAM is of YCbCr, address difference between Y and Cr of one pixel
If VRAM is of RGB, address difference between R and B of one pixel
User’s Manual U10684EJ3V0UM
89
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-19. Configuration of VRAM
VRAM_Bptr
VRAM_W_Pixel
VRAM_H_Pixel
Example 1
Example 2
VRAM_Gap2_Byte
VRAM_Gap1_Byte
VRAM_Gap1_Byte
VRAM_Gap2_Byte
Horizontal 1 pixel (VRAM_Pixel_Byte)
Y Cb Cr
Cr
Y Cb Cr
Cb
Vertical 1 pixel
(VRAM_Line_Byte)
VRAM_Pixel_Byte
Y
YCbCr of one pixel
VRAM_Line_Byte
Y Cb Cr
Y
90
User’s Manual U10684EJ3V0UM
Y
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
When the compression library is executed, the values of the following members are checked when a header is
created.
Size relationship between VRAM_W_Pixel and StartX+Width
Size relationship between VRAM_H_Pixel and StartY+Height
Even when customizing the VRAM accessing part (refer to 2.6 Basic Library Customization), set a value to
members VRAM_W_Pixel and VRAM_H_Pixel (specify the correct size so that an error does not occur and the check
routine is not terminated abnormally). For customization, the value of the members of the next JPEGINFO structure
may be undefined but within the allowable setting range.
• VRAM_Bptr
• VRAM_Line_Byte
• VRAM_Pixel_Byte
• VRAM_Gap1_Byte
• VRAM_Gap2_Byte
An example of setting VRAM-related members is shown below.
User’s Manual U10684EJ3V0UM
91
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-20. Example of Setting VRAM-Related Members of Basic Library
Address 0x00100001
Address 0x00100000
Address 0x00100002
1 pixel
Address 0x00100800
Y
Cr
Cb
0
Y
Cr
Cb
0
Y
Cr
Cb
0
Example of setting 1
VRAM_Bptr = 0x00100000;
VRAM_Line_Byte = 0x800;
VRAM_Pixel_Byte = 4;
VRAM_Gap1_Byte = 2;
VRAM_Gap2_Byte = 1;
Address 0x00100001
Address 0x00100000
Address 0x00100002
1 pixel
B
G
R
B
G
R
B
G
R
Example of setting 2
Address 0x00100500
VRAM_Bptr = 0x00100002;
"R" must be the base
in the case of RGB.
VRAM_Line_Byte = 0x500;
VRAM_Pixel_Byte = 3;
VRAM_Gap1_Byte = −1;
VRAM_Gap2_Byte = −2;
Address 0x00100000
Address 0x00100100
Address 0x00100001
R
R
R
R
R
R
1 pixel
R
Example of setting 3
VRAM_Bptr = 0x00100000;
Address 0x00110000
VRAM_Line_Byte = 0x100;
G
G
G
G
VRAM_Pixel_Byte = 1;
VRAM_Gap1_Byte = 0x10000;
Address 0x00120000
VRAM_Gap2_Byte = 0x20000;
B
92
B
B
B
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.5
Structure of MCU Buffer
When using a basic library (compression/decompression), the user must prepare an MCU buffer to store data.
Data that is sampled in MCU units when it is compressed is stored in the MCU buffer. DCT processing is
performed on the stored data. If the VRAM is of RGB method, the method is converted into the YCbCr method and
then the data is stored. When the data is decompressed, the result of reverse DCT processing is output in MCU units.
The configuration of the MCU buffer is shown below.
Table 2-21. Configuration of MCU Buffer
Declaration
Size (Bytes)
Supported Sampling Ratio
short name [1] [64]
128
Monochrome
short name [3] [64]
384
Monochrome, 4:4:4 [H:V = 1:1]
short name [4] [64]
512
Monochrome, 4:4:4 [H:V = 1:1], 4:2:2 [H:V = 2:1]
short name [6] [64]
768
Monochrome, 4:4:4 [H:V = 1:1], 4:2:2 [H:V = 2:1], 4:1:1 [H:V = 2:2],
4:1:1 [H:V = 4:1]
Configure the buffer as follows.
(1) Define the entity in the application and pass the pointer to a member of the JPEGINFO structure variable. For
the JPEGINFO structure, refer to 2.7.1 Details of data type.
(2) Although data is of 8 bits, be sure to declare it as short type (16 bits) because it is also used internally as a
work buffer.
(3) Give any name to name.
(4) Be sure to prepare one buffer per JPEGINFO structure variable.
Store each MCU in the buffer as follows.
User’s Manual U10684EJ3V0UM
93
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-21. Storing in MCU Buffer
(a) 4:1:1
(b) 4:2:2
(c) 4:4:4
Y component,
first block
Y component,
first block
Y component
block
Y component,
second block
Y component,
second block
Cb component
block
Y component,
third block
Cb component
block
Cr component
block
Y component,
fourth block
Cr component
block
Cb component
block
Cr component
block
Define the following buffer.
Table 2-22. Definition of Buffer
Processing
Necessary Size
Compression
Size supporting compression sampling ratio
Example Define name [4] [64] as the buffer to compress
data at a sampling ratio of 4:2:2, regardless of
the library.
Decompression
Supported library with the largest buffer size
Example Define name [4] [64] as the buffer when the
library supports sampling ratios of 4:4:4 and
4:2:2.
−
Analysis
The contents of the buffer are shown below.
94
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-22. Contents of MCU Buffer
(a) 4:4:4
0
1
8
9
...
7
0
1
8
9
Y
...
7
0
1
8
9
Cb
name [0]
[]
...
7
Cr
name [1]
[]
name [2]
[]
(b) 4:2:2
0
1
8
9
...
7
0
1
8
9
Y1
Y0
name [0]
7
0
1
8
9
Cb
name [1]
[]
...
7
Cr
name [2]
[]
...
name [3]
[]
[]
(c) 4:1:1 [H:V = 2:2]
0
1
8
9
...
7
Y1
Y0
name [0]
Y2
1
8
9
...
7
0
1
8
9
Cb
name [1]
[]
0
[]
...
7
Cr
name [4]
[]
name [5]
[]
Y3
name [2]
name [3]
[]
[]
(d) 4:1:1 [H:V = 4:1]
0
1
8
9
...
7
Y1
Y0
name [0]
0
1
8
9
...
7
Cb
name [4]
name [1]
[]
0
1
8
9
Y2
name [2]
[]
...
Y3
[]
name [3]
[]
7
Cr
[]
name [5]
[]
Remark 0, 1, ...: Value of second element of array for MCU buffer
User’s Manual U10684EJ3V0UM
95
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Here is an example of defining the MCU buffer as buff [6] [64] at a sampling ratio of 4:1:1.
Table 2-23. Storing Data of 1 MCU (at 4:1:1)
Array
Stored Data
buff [0] [ ]
Y component (upper left 8 × 8 pixels)
buff [1] [ ]
Y component (upper right 8 × 8 pixels)
buff [2] [ ]
Y component (lower left 8 × 8 pixels)
buff [3] [ ]
Y component (lower right 8 × 8 pixels)
buff [4] [ ]
Cb component (16 × 16 pixels: However, one element is the average of 2 × 2 pixels.)
buff [5] [ ]
Cr component (16 × 16 pixels: However, one element is the average of 2 × 2 pixels.)
Figure 2-23. Storing Data of Upper Left 2 × 2 Pixels
<1> <2>
<3> <4>
Y0
buff
[0]
Y1
[]
buff
Y2
buff
[2]
[1]
Cb
[]
buff
[4]
Cr
[]
buff
Y3
[]
buff
Component
96
<6>
<5>
[3]
[]
Storage Position
Y
<1 >buff [0] [0], <2> buff [0] [1], <3> buff [0] [8], <4> buff [0] [9]
Cb
<5> buff [4] [0]
Cr
<6> buff [5] [0]
User’s Manual U10684EJ3V0UM
[5]
[]
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.6
Basic Library Customization
The image I/O part of JPEG compression/decompression is influenced most by hardware. The basic libraries allow
users to create the image I/O part (although the default VRAM access function supplied with the basic libraries can be
used, emphasis is not placed on this function because its specification is for general purposes).
This section explains the specifications of a VRAM access function created by the user without using the default
function.
The AP703000-B03 includes vramacc0.s/vramacc1.c as a sample source for reference when creating a VRAM
access function.
2.6.1
Handling of image data by basic library
The basic libraries process image data in MCU (Minimum Coded Unit) (for compression, image input, DCT,
quantization, and Huffman coding are performed in that order in the MCU. For decompression, Huffman decoding,
reverse quantization, reverse DCT transformation, and image output are performed in that order).
To access the image memory, the getMCU and putMCU functions are used.
Figure 2-24. Flow of JPEG Processing
Flow of compression routine
Flow of decompression routine
Start
Start
Create header/initialize table
Analyze header/initialize table.
Loop by number
of MCUs
Call getMCU
function.
Decompression
of 1 MCU
Store data of
corresponding
MCU to
MCU buffer.
Call putMCU
function
Transfer data of
MCU buffer to
corresponding
memory
Compression
of 1 MCU
No
All MCU
buffer contents
compressed?
No
Loop by number
of MCUs
Yes
All MCU
buffer contents decompressed?
Yes
End
End
The area of the MCU buffer is reserved as the last member of the CJINFO and DJINFO structures.
User’s Manual U10684EJ3V0UM
97
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-25. Member CurrentX/CurrentY of Structure
VRAM
(CurX, CurY) = (StartX, StartY)
(StartX + n, StartY)
(StartX + 2n, StartY)
(StartX, StartY + m)
(StartX, StartY + 2m)
One grid equals to 1 MCU.
n: Number of horizontal pixels of 1 MCU (for example, n = 16 at 4:2:2 [H:V = 2:1].)
m: Number of vertical pixels of 1 MCU (for example, m = 8 at 4:2:2 [H:V = 2:1].)
When customizing the putMCU/getMCU function, refer to the members (CurrentX and CurrentY) of the JPEGINFO
structure for which part of the image the MCU indicates.
The basic libraries update the values of members CurrentX and CurrentY each time MCU processing has been
performed once. Do not change the values from the side customized by the user.
To customize the getMCU function for compression, the data of the corresponding MCU must be stored in the MCU
buffer in the form of Y/Cb/Cr Cr (each Y/Cb/Cr is 0 to 255) each time the getMCU function is called by the basic
library. To customize the putMCU function for decompression, the data corresponding to the MCU is stored in the
form of Y/Cb/Cr (each Y/Cb/Cr is 0 to 255) when the putMCU function is called, and therefore, that data must be
transferred to the VRAM.
Table 2-24. MCU
Sampling Ratio
MCU
4:4:4 [H:V = 1:1]
Horizontally 8 × vertically 8 pixels
4:2:2 [H:V = 2:1]
Horizontally 16 × vertically 8 pixels
4:1:1 [H:V = 2:2]
Horizontally 16 × vertically 16 pixels
4:1:1 [H:V = 4:1]
Horizontally 32 × vertically 8 pixels
The basic libraries input an image for DCT for compression and output the image resulting from reverse DCT for
decompression in YCbCr format, instead of in RGB format. If the VRAM is in the RGB format, RGB-to-YCbCr
conversion is necessary in pixel units to match the format of the image data (refer to Figure 1-4 Outline of JPEG
Processing).
These basic libraries handle the values of Y, Cb, and Cr as unsigned char type, in conformance with CCIR
Recommendation 601.
98
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-26. Image Data of 1 MCU (1/2)
(a) At 4:4:4 [H:V = 1:1]
0
1
8
9
2
3
4
Cr
5
0
1
8
9
6
2
7
3
4
5
0
1
8
9
Cb
6
2
7
3
4
5
6
7
Y
(b) At 4:2:2 [H:V = 2:1]
0
1
8
9
Cr
2
3
4
0
1
8
9
Cb
5
2
6
3
0
1
8
9
7
4
2
3
5
4
5
6
6
Y0
User’s Manual U10684EJ3V0UM
7
7
0
1
8
9
2
3
4
5
6
7
Y1
99
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Figure 2-26. Image Data of 1 MCU (2/2)
(c) At 4:1:1 [H:V = 2:2]
0
1
8
9
2
3
4
0
1
8
9
Cr
5
6
2
3
7
4
5
6
7
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
8 9
8 9
Cb Y0
Y1
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
8 9
8 9
Y2
Y3
(d) At 4:1:1 [H:V = 4:1]
0
8
Cr
1
9
2
0
8
Cb
3
1
9
4
2
3
6
4
7
5
6
7
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
8 9
8 9
8 9
8 9
Y0
100
5
Y1
User’s Manual U10684EJ3V0UM
Y2
Y3
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.6.2
Sampling ratio and block
For compression, each MCU is disassembled into YCbCr and blocks in accordance with the sampling ratio.
Table 2-25. MCU and Block
Sampling Ratio
MCU
Block
4:4:4 [H:V = 1:1]
8×8
3 blocks (1 block of Y component, 1 block of Cb component, 1 block of Cr component)
4:2:2 [H:V = 2:1]
16 × 8
4 blocks (2 blocks of Y component, 1 block of Cb component, 1 block of Cr component)
4:1:1 [H:V = 2:2]
16 × 16
6 blocks (4 blocks of Y component, 1 block of Cb component, 1 block of Cr component)
4:1:1 [H:V = 4:1]
32 × 8
6 blocks (4 blocks of Y component, 1 block of Cb component, 1 block of Cr component)
For compression, the average of several pixels adjoining each other of chrominance components (Cb/Cr) must be
calculated (except at a sampling ratio of 4:4:4). This average calculation processing is called sampling.
For decompression, the same chrominance component value is written to the pixels whose average was calculated
for compression.
Table 2-26. Sampling of Chrominance Component
Sampling Ratio
Sampling
4:4:4 [H:V = 1:1]
Average is not calculated.
4:2:2 [H:V = 2:1]
Average of chrominance components of 2 horizontal pixels is calculated.
4:1:1 [H:V = 2:2]
Average of chrominance components of 2 vertical pixels × 2 horizontal
pixels is calculated.
4:1:1 [H:V = 4:1]
Average of chrominance components of 4 horizontal pixels is calculated.
Figure 2-27. Sampling
Sampling ratio of 4:1:1 (H:V = 2:2)
Average is calculated
for compression.
Pixels are filled with same
color for decompression.
User’s Manual U10684EJ3V0UM
101
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.6.3
MCU buffer
The image data of 1 MCU is stored in the MCU buffer.
The location to which data is to be stored is determined, as illustrated below.
Figure 2-28. Image Data in MCU Buffer
4:1:1
0x0
0
2
4:2:2
0x0
1
3
0
2
4:4:4
Y0
0x80
:
62
0
2
:
63
1
3
0x80
0x100
:
63
1
3
:
62
0
2
:
63
1
3
0x180
:
63
1
3
0x200
:
62
0
2
:
63
1
3
1
3
Y
0x80
:
62
0
2
:
63
1
3
Y1
0x100
:
62
0
2
:
63
1
3
Y2
:
62
0
2
0
2
Y0
Y1
:
62
0
2
0x0
1
3
Cb
0x100
:
62
0
2
:
63
1
3
Cb
0x180
:
62
0
2
:
63
1
3
:
62
:
63
Y3
Cr
:
62
:
63
0x180
Cr
0x200
Cb
0x280
:
62
0
2
:
63
1
3
:
62
:
63
Cr
Data of one color element of one pixel (8 bits) is treated as an unsigned short type (16 bits) in the MCU buffer, with
the higher 8 bits filled with 0.
102
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.6.4
VRAM access functions for compression
The following functions are necessary for accessing the VRAM for compression.
Table 2-27. VRAM Access Functions Used for Compression
Function Name
Outline
jpeg_getMCU_M
VRAM access function (monochrome compression)
jpeg_getMCU_11
VRAM access function (color compression, sampling ratio = 4:4:4 [H:V = 1:1])
jpeg_getMCU_21
VRAM access function (color compression, sampling ratio = 4:2:2 [H:V = 2:1])
jpeg_getMCU_22
VRAM access function (color compression, sampling ratio = 4:1:1 [H:V = 2:2])
jpeg_getMCU_41
VRAM access function (color compression, sampling ratio = 4:1:1 [H:V = 4:1])
These functions extract data from the VRAM in MCU, convert it into YCbCr format, and store the data in the MCU
buffer in a specific format. A function for an unnecessary sampling ratio does not have to be created. An arbitrary
function name must not be given by the user. Make sure that the function names are same as those shown in Table 227.
The specifications of each function are as follows.
Function name
jpeg_getMCU_M (monochrome compression)
jpeg_getMCU_11 (color compression, sampling ratio = 4:4:4 [H:V = 1:1])
jpeg_getMCU_21 (color compression, sampling ratio = 4:2:2 [H:V = 2:1])
jpeg_getMCU_22 (color compression, sampling ratio = 4:1:1 [H:V = 2:2])
jpeg_getMCU_41 (color compression, sampling ratio = 4:1:1 [H:V = 4:1])
Function outline Samples data from the image memory and stores it in the MCU buffer.
Format
#include “jpeg.h”
void jpeg_getMCU_M (JPEGINFO *info)
void jpeg_getMCU_11 (JPEGINFO *info)
void jpeg_getMCU_21 (JPEGINFO *info)
void jpeg_getMCU_22 (JPEGINFO *info)
void jpeg_getMCU_41 (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
These functions sample data of one MCU from the current position of the image memory
specified by the member CurrentX/CurrentY of info, and store the data to the MCU buffer.
Remark
When describing the jpeg_getMCU_xx function in assembler, observe the C language rules.
The size of one MCU corresponding to each sampling ratio is as shown in Table 2-25. If the VRAM is of RGB, each
pixel converted into YCbCr corresponds to one MCU.
For how data is stored in the MCU buffer, refer to 2.6.3 MCU buffer.
User’s Manual U10684EJ3V0UM
103
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
The following information is necessary for the jpeg_getMCU_xx function:
2.6.5
JPEGINFO -> MCU_Buff_Bptr:
First address of MCU buffer
JPEGINFO -> CurrentX:
x coordinate of corresponding MCU
JPEGINFO -> CurrentY:
y coordinate of corresponding MCU
VRAM access function for decompression
The following functions are necessary for accessing the VRAM for decompression.
Table 2-28. VRAM Access Functions Used for Decompression
Function Name
Outline
jpeg_putMCU_M
VRAM access function (monochrome decompression)
jpeg_putMCU_11
VRAM access function (color decompression, sampling ratio = 4:4:4 [H:V = 1:1]
jpeg_putMCU_21
VRAM access function (color decompression, sampling ratio = 4:2:2 [H:V = 2:1]
jpeg_putMCU_22
VRAM access function (color decompression, sampling ratio = 4:1:1 [H:V = 2:2]
jpeg_putMCU_41
VRAM access function (color decompression, sampling ratio = 4:1:1 [H:V = 4:1]
These functions draw the data in YCbCr format stored in the MCU buffer in a specific format to VRAM. The
function of an unnecessary sampling ratio does not have to be created. An arbitrary function name must not be given
by the user.
Make sure that the function names are the same as those in Table 2-28.
The specifications of each function are as follows.
Function name
jpeg_putMCU_M (monochrome decompression)
jpeg_putMCU_11 (color decompression, sampling ratio = 4:4:4 [H:V = 1:1])
jpeg_putMCU_21 (color decompression, sampling ratio = 4:2:2 [H:V = 2:1])
jpeg_putMCU_22 (color decompression, sampling ratio = 4:1:1 [H:V = 2:2])
jpeg_putMCU_41 (color decompression, sampling ratio = 4:1:1 [H:V = 4:1])
Function outline Decompresses the data of the MCU buffer in the image memory.
Format
#include “jpeg.h”
void jpeg_putMCU_M (JPEGINFO *info)
void jpeg_putMCU_11 (JPEGINFO *info)
void jpeg_putMCU_21 (JPEGINFO *info)
void jpeg_putMCU_22 (JPEGINFO *info)
void jpeg_putMCU_41 (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
These functions decompress data of 1 MCU to the current location of the image memory
specified by the member CurrentX/CurrentY of info.
Remark
104
When describing the jpeg_getMCU_xx function in assembler, observe the C language rules.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
The size of one MCU corresponding to each sampling ratio is as shown in Table 2-25. If the VRAM is of RGB, each
pixel converted into YCbCr corresponds to one MCU.
For how data is stored in the MCU buffer, refer to 2.6.3 MCU buffer.
The following information is necessary for these functions.
JPEGINFO -> MCU_Buff_Bptr:
2.6.6
First address of MCU buffer
JPEGINFO -> CurrentX:
x coordinate of corresponding MCU
JPEGINFO -> CurrentY:
y coordinate of corresponding MCU
One point to assembler coding
When describing this routine in an assembler, the processing speed can be increased by using the 16-bit
displacement of a load/store instruction.
Suppose that following is executed.
* (mcu + 0) = Y0;
* (mcu + 1) = Y1;
* (mcu + 2) = Y2;
* (mcu + 3) = Y3;
And suppose that the following contents are stored in the registers.
r7: mcu
r10: Y0
r11: Y1
r12: Y2
r13: Y3
If the description is made as follows, address calculation is substantially shortened. As a result, the processing
speed increases.
st.h r10, 0x0000 [r7]
st.h r11, 0x0002 [r7]
st.h r12, 0x0004 [r7]
st.h r13, 0x0006 [r7]
In addition, define the value of the symbol in the assembler file as follows (same as #define of C., with GHS
version).
VRAM_GAP1 = 1 … Address difference between Y and Cb of one pixel of VRAM
VRAM_GAP2 = 1 … Address difference between Y and Cr of one pixel of VRAM
User’s Manual U10684EJ3V0UM
105
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Assuming that r8 has the address of the Y component of the pixel of the VRAM to be accessed, execute the
instructions as follows.
ld.b 0x0000 [r8], r10
ld.b VRAM_GAP1 [r8], r11
ld.b VRAM_GAP2 [r8], r12
andi 0x00FF, r10, r10
andi 0x00FF, r11, r11
andi 0x00FF, r12, r12
As a result, the following contents are stored in the registers.
r10: Value of Y component
r11: Value of Cb component
r12: Value of Cr component
106
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.7
2.7.1
Basic Library Reference
Details of data type
The two data types shown in Table 2-29 are available. Declare all variables of structures and variables that pass an
address to a member as external variables.
Table 2-29. Data Type
2.7.2
Classification
Data Type Name
Data Type
Size
Outline
Common
JPEGINFO
Structure
148 bytes
Sets compression, decompression, and analysis
parameters.
APPINFO
Structure
96 bytes
Saves APPn marker information.
Structure of JPEGINFO structure
Table 2-30 shows the member configuration of the JPEGINFO structure.
This structure is commonly used for JPEG compression, decompression, and analysis.
User’s Manual U10684EJ3V0UM
107
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Table 2-30. Members of JPEGINFO Structure (1/2)
Member
Type
Size
(Bytes)
IN/OUT
Description
ComDecom- Analysis
pression pression
ErrorState
long
4
OUT
OUT
OUT
Error status
FileSize
long
4
OUT
OUT
OUT
JPEG file size
Quality
char
1
IN
RSV
RSV
Quantization parameter
Sampling
char
1
IN
OUT
OUT
Sampling ratio
Restart
unsigned short
2
IN
OUT
OUT
Setting of restart interval (DRI/RSTm)
Width
unsigned short
2
IN
OUT
OUT
Horizontal size of image
Height
unsigned short
2
IN
OUT
OUT
Vertical size of image
StartX
unsigned short
2
IN
IN
RSV
Start x coordinate of image
StartY
unsigned short
2
IN
IN
RSV
Start y coordinate of image
CurrentX
unsigned short
2
RSV
RSV
RSV
Current x coordinate
CurrentY
unsigned short
2
RSV
RSV
RSV
Current y coordinate
VRAM_Bptr
unsigned char*
4
IN
IN
RSV
VRAM first address
VRAM_W_Pixel
unsigned short
2
IN
IN
RSV
VRAM specification (width: number of
horizontal pixels)
VRAM_H_Pixel
unsigned short
2
IN
IN
RSV
VRAM specification (height: number of
vertical pixels)
VRAM_Line_Byte
short
2
IN
IN
RSV
VRAM specification (number of bytes of
address difference of 1 vertical pixel)
VRAM_Pixel_Byte
short
2
IN
IN
RSV
VRAM specification (number of bytes of
address difference of 1 horizontal pixel)
VRAM_Gap1_Byte
short
2
IN
IN
RSV
VRAM specification (number of bytes of
address difference between Y-Cb/R-G)
VRAM_Gap2_Byte
short
2
IN
IN
RSV
VRAM specification (number of bytes of
address difference between Y-Cr/R-B)
JPEG_Buff_Bptr
unsigned char*
4
IN
IN
IN
First address of JPEG file storage buffer
JPEG_Buff_Eptr
unsigned char*
4
IN
IN
IN
End address of JPEG file storage buffer
MCU_Buff_Bptr
short*
4
IN
IN
RSV
Setting of MCU buffer
RGB_Buff_Bptr
short*
4
RSV
RSV
RSV
Reserved field
DQT_Y_Bptr
char*
4
IN
RSV
RSV
Address of luminance component
quantization table
DQT_C_Bptr
char*
4
IN
RSV
RSV
Address of color difference component
quantization table
DHT_DC_Y_Bptr
char*
4
IN
RSV
RSV
Address of luminance DC component
Huffman table
DHT_DC_C_Bptr
char*
4
IN
RSV
RSV
Address of color difference DC component
Huffman table
DHT_AC_Y_Bptr
char*
4
IN
RSV
RSV
Address of luminance AC component
Huffman table
DHT_AC_C_Bptr
char*
4
IN
RSV
RSV
Address of color difference AC component
Huffman table
108
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Table 2-30. Members of JPEGINFO Structure (2/2)
Member
Type
IN/OUT
Size
(Bytes)
Description
ComDecom- Analysis
pression pression
APP_Info_Bptr
APPINFO*
4
IN
RSV
IN
Address of APPINFO structure variable
Work1_Bptr
long*
4
IN
IN
IN
Address of library work area 1
Work2_Bptr
long*
4
IN
IN
IN
Address of library work area 2
Mode
long
4
IN
IN
RSV
Operation mode
DNL
long
4
IN
RSV
RSV
Setting of DNL segment
CI1
long
4
IN
OUT
OUT
Component ID1
CI2
long
4
IN
OUT
OUT
Component ID2
CI3
long
4
IN
OUT
OUT
Component ID3
User
long
4
IN
IN
IN
JPEG_Buff_Cptr
unsigned char*
4
OUT
OUT
OUT
Current address of JPEG file storage buffer
Work3
char
28
RSV
RSV
RSV
Library work area 3
Total
Remark
User-defined area
148
IN:
A value must be set by the user.
OUT:
A value is set by the basic library (return value).
RSV:
Reserved field of basic library
The details of each member are as follows.
(1) ErrorState
Classification
IN/OUT
Compression
OUT
Decompression
OUT
Analysis
OUT
Address Value
0x00000000 to
0xFFFFFFFF
Description
Stores error status.
For details of the error status, refer to 2.7.6 Function.
(2) FileSize
Classification
IN/OUT
Compression
OUT
Decompression
OUT
Analysis
OUT
Address Value
0x00000000 to
0xFFFFFFFF
Description
Stores size of JPEG file.
(3) Quality
Classification
IN/OUT
Address Value
0 to 100
Description
Compression
IN
Set the quantization coefficient.
Decompression
RSV
−
−
Analysis
RSV
−
−
User’s Manual U10684EJ3V0UM
109
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
The AP703000-B03 has a quantization parameter (Quality) so that the value of the quantization table can be easily
changed.
Calculate constant “Q” from this Quality parameter inside the AP703000-B03, from the following expression.
Multiply each element of the quantization table by “Q” and round the result in a range of 1 to 255. The rounded value
is used for actual quantization processing as a quantization coefficient.
Where Quality < 50: Q = 50/Quality (automatically set to 1 by program where Quality = 0)
Where Quality ≥ 50: Q = 2 – Quality/50
Figure 2-29. Quantization Parameter Quality and Constant Q
50
Q
1
0
0
50
100
Quality
To use the default quantization table as is without processing, set “50” as the value of the Quality parameter.
110
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Table 2-31. Setting of Quality Parameter
Quality parameter
100
…
50
…
0
Constant Q
0
…
1
…
50
Quantization table
All elements are 1.
…
Default
…
Almost all elements are 255.
Definition
High
…
Low
Size of JPEG file
Large
…
Small
(4) Sampling
Classification
IN/OUT
Value
Description
Compression
IN
JPEGSAMPLE11
JPEGSAMPLE21
JPEGSAMPLE22
JPEGSAMPLE41
JPEGSAMPLEMONO
Set the sampling ratio.
This information is appended to the JPEG header.
When using monochrome, set a value ORed with an arbitrary
sampling ratio (see 2.3.5 Supporting monochrome
format).
Decompression
OUT
JPEGSAMPLE11
JPEGSAMPLE21
JPEGSAMPLE22
JPEGSAMPLE41
JPEGSAMPLEMONO
The sampling ratio is automatically stored from the JPEG file.
Because the decompression library automatically identifies
which sampling ratio is used, the sampling ratio does not
need to be considered.
When using monochrome, set a value ORed with an arbitrary
sampling ratio (see 2.3.5 Supporting monochrome
format).
Analysis
OUT
Higher 4 bits: [0x1 to 0x4]
Lower 4 bits: [0x1 to 0x4]
The sampling ratio is automatically stored from the JPEG file.
JPEGSAMPLEn is defined in header file “jpeg.h” as for compression/decompression.
Sampling
(sampling ratio)
JPEGSAMPLE22 (4:1:1 [H:V = 2:2])
JPEGSAMPLE41 (4:1:1 [H:V = 4:1])
Color
Normal
←→
Clear
File size
Reference value (1 time)
About 3/4 times
About 2 times
Remark
JPEGSAMPLE21
(4:2:2 [H:V = 2:1])
JPEGSAMPLE11
(4:4:4 [H:V = 1:1])
Neither the color nor the file size of the monochrome format depends on the sampling ratio.
(5) Restart
Classification
Compression
Decompression
Analysis
IN/OUT
IN
OUT
OUT
Value
Description
0
RSTm marker/DRI marker is not inserted.
1 to 65535
RSTm marker is inserted. The restart interval (DRI) is a set value.
0
RSTm/DRI marker is not inserted.
1 to 65535
RSTm maker is inserted. The restart interval (DRI) is a stored value.
0
RSTm/DRI marker is not inserted.
1 to 65535
RSTm maker is inserted. The restart interval (DRI) is a stored value.
User’s Manual U10684EJ3V0UM
111
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(6) Width
Classification
IN/OUT
Value
Description
Compression
IN
1 to 65535
Set the horizontal size of the JPEG compressed image.
Decompression
OUT
1 to 65535
The horizontal size of the JPEG compressed image is automatically
stored from the JPEG file.
Analysis
OUT
1 to 65535
The horizontal size of the JPEG compressed image is automatically
stored from the JPEG file.
For compression/decompression, the “Value” is limited by the sampling ratio (Sampling).
Sampling
Width
4:4:4 [H:V = 1:1]
Multiple of 8
4:2:2 [H:V = 2:1]
Multiple of 16
4:1:1 [H:V = 2:2]
Multiple of 16
4:1:1 [H:V = 4:1]
Multiple of 32
(7) Height
Classification
IN/OUT
Value
Description
Compression
IN
0 to 65535
Set the vertical size of the JPEG compressed image.
Decompression
OUT
0 to 65535
The vertical size of the JPEG compressed image is automatically
stored from the JPEG file.
Analysis
OUT
0 to 65535
The vertical size of the JPEG compressed image is automatically
stored from the JPEG file.
For compression/decompression, the “Value” is limited by the sampling ratio.
Sampling
Width
4:4:4 [H:V = 1:1]
Multiple of 8
4:2:2 [H:V = 2:1]
Multiple of 8
4:1:1 [H:V = 2:2]
Multiple of 16
4:1:1 [H:V = 4:1]
Multiple of 8
(8) StartX
Classification
IN/OUT
Value
Description
Compression
IN
0 to 32767
Set the compression start x coordinate of the JPEG compressed
image.
Decompression
IN
0 to 32767
Set the decompression start x coordinate of the JPEG compressed
image.
Analysis
RSV
112
−
−
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(9) StartY
Classification
IN/OUT
Value
Description
Compression
IN
0 to 32767
Set the compression start y coordinate of the JPEG compressed
image.
Decompression
IN
0 to 32767
Set the decompression start y coordinate of the JPEG compressed
image.
Analysis
RSV
−
−
Value
Description
(10) CurrentX
Classification
IN/OUT
Compression
RSV
0 to 32767
The compression current x coordinate of the JPEG compressed image
is stored. Referencing this member is enabled only for the function
jpeg_getMCU_xx and only when the function is customized.
Decompression
RSV
0 to 32767
The decompression current x coordinate of the JPEG compressed
image is stored. Referencing this member is enabled only for the
function jpeg_putMCU_xx and only when the function is customized.
Analysis
RSV
−
−
Value
Description
(11) CurrentY
Classification
IN/OUT
Compression
RSV
0 to 32767
The compression current y coordinate of the JPEG compressed image
is stored. Referencing this member is enabled only for the function
jpeg_getMCU_xx and only when the function is customized.
Decompression
RSV
0 to 32767
The decompression current y coordinate of the JPEG compressed
image is stored. Referencing this member is enabled only for the
function jpeg_putMCU_xx and only when the function is customized.
Analysis
RSV
−
−
Value
Description
(12) VRAM_Bptr
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
RSV
0x00000000 to
0xFFFFFFFF
Set the first address of the image memory (VRAM).
−
−
User’s Manual U10684EJ3V0UM
113
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(13) VRAM_W_Pixel
Classification
IN/OUT
Value
1 to 10912
Compression
IN
Decompression
IN
Analysis
RSV
Description
Set the number of horizontal pixels of the image memory (VRAM).
−
−
Value
Description
(14) VRAM_H_Pixel
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
RSV
1 to 10912
Set the number of vertical pixels of the image memory (VRAM).
−
−
Value
Description
(15) VRAM_Line_Byte
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
RSV
1 to 32767
Set the number of bytes of address difference of one vertical pixel of
the image memory (VRAM).
−
−
Value
Description
(16) VRAM_Pixel_Byte
Classification
IN/OUT
1 to 32767
Compression
IN
Decompression
IN
Analysis
RSV
Set the number of bytes of address difference of one horizontal pixel of
the image memory (VRAM).
−
−
Value
Description
(17) VRAM_Gap1_Byte
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
RSV
114
−32768 to
+32767
Number of bytes of address difference between Y/Cb components of
one pixel if the image memory (VRAM) is of YCbCr.
Number of bytes of address difference between R/G components of
one pixel if the image memory (VRAM) is of RGB.
−
−
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(18) VRAM_Gap2_Byte
Classification
IN/OUT
Value
Description
−32768 to
+32767
Compression
IN
Decompression
IN
Analysis
RSV
Number of bytes of address difference between Y/Cr components of
one pixel if the image memory (VRAM) is of YCbCr.
Number of bytes of address difference between R/B components of
one pixel if the image memory (VRAM) is of RGB.
−
−
Value
Description
(19) JPEG_Buff_Bptr
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
IN
0x00000000 to
0xFFFFFFFF
Set the first address of the JPEG buffer.
(20) JPEG_Buff_Eptr
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
IN
Value
Description
0x00000000 to
0xFFFFFFFF
Set the end address of the JPEG buffer, as follows:
“End address” = “First address” + “Buffer size”
(21) MCU_Buff_Bptr
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
RSV
Value
Description
0x00000000 to
0xFFFFFFFF
Set the first address of the MCU buffer.
−
−
Value
Description
−
−
(22) RGB_Buff_Bptr
Classification
IN/OUT
Compression
RSV
Decompression
RSV
Analysis
RSV
User’s Manual U10684EJ3V0UM
115
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(23) DQT_Y_Bptr
Classification
IN/OUT
Compression
IN
Decompression
RSV
Analysis
RSV
Value
Description
0x00000000 to
0xFFFFFFFF
Set the addresses of the luminance component quantization table. The
table supplied by the basic library is jpeg_DQT_Y.
−
−
(24) DQT_C_Bptr
Classification
IN/OUT
Compression
IN
Decompression
RSV
Analysis
RSV
Value
Description
0x00000000 to
0xFFFFFFFF
Set the addresses of the color difference quantization table.
The table supplied by the basic library is jpeg_DQT_C.
−
−
Value
Description
(25) DHT_DC_Y_Bptr
Classification
IN/OUT
Compression
IN
0x00000000 to
0xFFFFFFFF
Decompression
RSV
Analysis
RSV
Set the addresses of the luminance DC component Huffman table.
The table supplied by the basic library is jpeg_DHT_DC_Y.
To create a Huffman table, see 2.3.2 (1) Constraints of Huffman table.
−
−
Value
Description
(26) DHT_DC_C_Bptr
Classification
IN/OUT
Compression
IN
0x00000000 to
0xFFFFFFFF
Decompression
RSV
Analysis
RSV
Set the addresses of the chrominance DC component Huffman table.
The table supplied by the basic library is jpeg_DHT_DC_C.
To create a Huffman table, see 2.3.2 (1) Constraints of Huffman table.
−
−
Value
Description
(27) DHT_AC_Y_Bptr
Classification
IN/OUT
Compression
IN
Decompression
RSV
Analysis
RSV
116
0x00000000 to
0xFFFFFFFF
Set the addresses of the luminance AC component Huffman table.
The table supplied by the basic library is jpeg_DHT_AC_Y.
To create a Huffman table, see 2.3.2 (1) Constraints of Huffman table.
−
−
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(28) DHT_AC_C_Bptr
Classification
IN/OUT
Compression
IN
Decompression
RSV
Analysis
RSV
Value
Description
0x00000000 to
0xFFFFFFFF
Set the addresses of the color difference AC component Huffman table.
The table supplied by the basic library is jpeg_DHT_AC_C.
To create a Huffman table, see 2.3.2 (1) Constraints of Huffman
table.
−
−
Value
Description
(29) APP_Info_Bptr
Classification
Compression
IN/OUT
IN
Decompression
RSV
Analysis
IN
0x00000000
The APPn marker is not inserted.
0x00000000 to
0xFFFFFFFF
The APPn marker is inserted. Set the address of the APPINFO
structure variable that indicates the contents of the APPn segment.
−
−
0x00000000
The APPn marker is not analyzed.
0x00000000 to
0xFFFFFFFF
The APPn marker is analyzed. Set the address of the APPINFO
structure variable that stores the analysis result.
The APPINFO structure is cleared to 0 in the analysis initialization
function jpeg_AnalysisInit.
(30) Work1_Bptr
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
IN
Value
Description
0x00000000 to
0xFFFFFFFF
Set the address of a high-speed work area for the library.
The user must declare a buffer of “long type and 256 bytes” as the
work area.
If this work area is placed in the internal RAM, the processing speed is
increased.
Value
Description
(31) Work2_Bptr
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
RSV
0x00000000 to
0xFFFFFFFF
Set the address of a low-speed work area for the library.
The user must declare a buffer of “long type and 3072 bytes” as the
work area.
Set the address of a low-speed work area for the library.
The user must declare a buffer of “long type and 8192 bytes” as the
work area.
−
−
User’s Manual U10684EJ3V0UM
117
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(32) Mode
Classification
Compression
IN/OUT
IN
Decompression
Analysis
IN
RSV
Value
Description
JPEGMODE
_NORMAL
Normal compression mode. One entire screen is compressed by
calling the function once. A VRAM capacity large enough to store the
image of one screen is necessary.
JPEGMODE
_MCULINE
Line compression mode. Only one MCU line is compressed by calling
the function once. A VRAM capacity large enough to store the image
of one MCU line is necessary. The image of one screen can be
compressed by calling the function as many times as required.
JPEGMODE
_STOP
Forcibly terminates the compression. This value is used to forcibly
terminate the processing in the line compression mode
(JPEGMODE_MCULINE).
The processing is terminated after the EOI marker has been appended
if the value of structure member DNL is JPEGDNL_OFF. It is
terminated after the DNL/EOI marker has been appended if the value
of structure member DNL is JPEGDNL_ON.
This value can be set to call the next library if both the following
conditions are satisfied.
<1> Compression in line processing mode (JPEGMODE_MCULINE)
<2> If the return value updates the VRAM when the library is called the
last time (JPEGRET_CONT2).
JPEGMODE
_NORMAL
Normal decompression mode. One entire screen is decompressed by
calling the function once. A VRAM capacity large enough to store the
image of one screen is necessary.
JPEGMODE
_MCULINE
Line decompression mode. Only one MCU line is decompressed by
calling the function once. A VRAM capacity large enough to store the
image of one line is necessary. The image of one screen can be
decompressed by calling the function as many times as required.
−
−
Value
Description
(33) DNL
Classification
Compression
IN/OUT
IN
Decompression
RSV
Analysis
RSV
Caution
118
JPEGDNL_ON
The DNL marker is appended after compression has been completed.
JPEGDNL_OFF
The DNL marker is not appended after compression has been
completed.
−
−
When Height is 0, be sure to set JPEGDNL_ON.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(34) CI1, CI2, CI3
Classification
IN/OUT
Value
Description
Compression
IN
0 to 255
Set values so that each component ID differs.
Decompression
OUT
0 to 255
The component ID specified by the SOFn/SOS segment is set.
Analysis
OUT
(35) User
Classification
IN/OUT
Compression
IN
Decompression
IN
Analysis
IN
Value
Description
0x00000000 to
0xFFFFFFFF
The user can use this member freely. The basic libraries do not
reference this member.
(36) JPEG_Buff_Cptr
Classification
IN/OUT
Compression
OUT
Decompression
OUT
Analysis
OUT
Value
−
Description
The last accessed position (address) of the JPEG buffer is stored.
The last written position is stored for compression and the last read
position is stored for decompression/analysis.
This member is read-only and must not be written by the user.
(37) Work3
Classification
IN/OUT
Compression
RSV
Decompression
RSV
Analysis
RSV
Value
Description
−
−
User’s Manual U10684EJ3V0UM
119
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.7.3
Structure of APPINFO structure
The APPINFO structure is used to support the APPn segment during compression/analysis (to insert the APPn
segment into the JPEG file during compression or to get information on the APPn segment in the JPEG file during
analysis).
To support the APPn segment during compression/analysis, declare the APPINFO structure variable and set its
first address to member the “APP_Info_Bptr” of the JPEGINFO structure member. If “APP_Info_Bptr” is not 0, all the
members are cleared to 0 in the analysis initialization function jpeg_AnalysisInit.
If the APPn segment is not to be supported during compression/analysis, and during decompression, the
APPINFO structure variable does not have to be declared.
Table 2-32. Members of APPINFO Structure
Member
Type
Size
(Bytes)
IN/OUT
Description
ComDecom- Analysis
pression pression
APP00_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP01_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP02_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP03_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP04_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP05_Buff_ Bptr
unsigned char*
4
IN
RSV
OUT
APP06_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP07_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP08_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP09_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP10_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP11_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP12_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP13_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP14_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP15_Buff_Bptr
unsigned char*
4
IN
RSV
OUT
APP00_BuffSize
unsigned short
2
IN
RSV
OUT
APP01_BuffSize
unsigned short
2
IN
RSV
OUT
APP02_BuffSize
unsigned short
2
IN
RSV
OUT
APP03_BuffSize
unsigned short
2
IN
RSV
OUT
APP04_BuffSize
unsigned short
2
IN
RSV
OUT
APP05_BuffSize
unsigned short
2
IN
RSV
OUT
APP06_BuffSize
unsigned short
2
IN
RSV
OUT
APP07_BuffSize
unsigned short
2
IN
RSV
OUT
APP08_BuffSize
unsigned short
2
IN
RSV
OUT
APP09_BuffSize
unsigned short
2
IN
RSV
OUT
APP10_BuffSize
unsigned short
2
IN
RSV
OUT
APP11_BuffSize
unsigned short
2
IN
RSV
OUT
APP12_BuffSize
unsigned short
2
IN
RSV
OUT
APP13_BuffSize
unsigned short
2
IN
RSV
OUT
APP14_BuffSize
unsigned short
2
IN
RSV
OUT
APP15_BuffSize
unsigned short
2
IN
RSV
OUT
Total
Remark
120
96
IN:
A value must be set by the user.
OUT:
A value is set by the basic library (return value).
RSV:
Reserved field of basic library
User’s Manual U10684EJ3V0UM
Address of the data of the APPn (n = 0 to 15)
segment
[Compression]
0x00000000
The APPn segment is not inserted.
Other than 0x00000000
The APPn segment is inserted. Declare the
buffer that stores data to be inserted, and
set its address.
[Decompression]
Setting is prohibited.
[Analysis]
0x00000000
The APPn segment has not been inserted.
Other than 0x00000000
The APPn segment has been inserted.
Store the address of the data as an absolute
address in the JPEG file.
Size of the data of the APPn (n = 0 to 15)
segment
[Compression]
0x00000000
The APPn segment is not inserted.
Other than 0x00000000
The APPn segment is inserted. Declare the
buffer that stores data to be inserted, and
set its data size. The maximum data size is
0x0000FFFD.
[Decompression]
Setting is prohibited.
[Analysis]
0x00000000
The APPn segment has not been inserted.
Other than 0x00000000
The APPn segment has been inserted.
Store the data size.
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.7.4
Constants
Table 2-33. Symbols (1/2)
Symbol
Value
ComDecom- Analysis
pression pression
Meaning
JPEGRET_OK
0x00000000
Normal completion
JPEGRET_CONT1
0x00000001
JPEGRET_CONT2
0x00000002
JPEGRET_ERR
0xFFFFFFFF
JPEGERR_VRAM
0x00000001
×
Specified VRAM area is illegal.
JPEGERR_USF
0x00000002
×
Illegal sampling ratio
Continuation 1 (library terminated by JPEG buffer)
×
Continuation 2 (library terminated by VRAM)
Abnormal termination
JPEGERR_QPQ
0x00000003
×
×
Pq value of DQT is illegal (other than 0).
JPEGERR_QTQ
0x00000004
×
×
Tq value (quantization table number) of DQT is illegal
(other than 0 or 1).
JPEGERR_DHT
0x00000005
×
×
JPEGERR_SNS
0x00000006
×
Ns value (number of components) of SOS is illegal
(other than 1 or 3).
JPEGERR_SCD
0x00000007
×
Tan/Tdn value (Huffman table number) of SOS is illegal.
JPEGERR_SSS
0x00000008
×
Ss value of SOS is illegal (other than 0).
JPEGERR_SSE
0x00000009
×
Se value of SOS is illegal (other than 63).
JPEGERR_SAA
0x0000000A
×
Ah/Al value of SOS is illegal (other than 0).
JPEGERR_SFP
0x0000000B
×
P value of SOF is illegal (other than 8).
JPEGERR_SFN
0x0000000C
×
Nf value of SOF is illegal (other than 1 or 3).
JPEGERR_UKM
0x0000000D
×
JPEGERR_RST
0x0000000E
×
×
RSTm marker is illegal.
JPEGERR_OTH
0x0000000F
×
×
Compressed data is illegal (marker detected)
JPEGERR_SOS
0x00000010
×
×
Other SOS segment error (component ID is illegal)
JPEGERR_SOF
0x00000011
×
×
SOF is undefined or defined in duplicate.
JPEGERR_FTQ
0x00000012
×
×
Quantization table required for decompression is
undefined.
JPEGERR_STH
0x00000013
×
×
Huffman table required for decompression is undefined.
JPEGERR_IMY
0x00000014
×
Quantization table required for decompression is
undefined.
JPEGERR_FID
0x00000015
×
Component IDs of SOF are duplicated.
JPEGERR_SID
0x00000016
×
×
Component IDs of SOS are duplicated.
JPEGERR_QEL
0x00000017
×
×
Quantization table element is illegal (0).
JPEGERR_VIJ
0x00000018
×
×
JPEGERR_JPB
0x00000019
JPEGERR_DLH
0x0000001A
JPEGERR_DCL
0x0000001B
JPEGERR_HUF
0x0000001C
JPEGSAMPLE11
0x00000011
Y component, H:V = 1:1
JPEGSAMPLE12
0x00000012
Y component, H:V = 1:2
JPEGSAMPLE13
0x00000013
Y component, H:V = 1:3
JPEGSAMPLE14
0x00000014
Y component, H:V = 1:4
JPEGSAMPLE21
0x00000021
Y component, H:V = 2:1
JPEGSAMPLE22
0x00000022
Y component, H:V = 2:2
JPEGSAMPLE23
0x00000023
Y component, H:V = 2:3
Tc/Th value of DHT is illegal.
Unknown marker is generated.
Huffman table element is illegal (duplication).
JPEG buffer size is illegal (0 or less).
×
×
×
×
Lh value of DHT is illegal (2 or less).
×
L value of DHT for DC component is illegal (17 or larger).
×
Compressed data is illegal (decode error).
User’s Manual U10684EJ3V0UM
121
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Table 2-33. Symbols (2/2)
Symbol
Value
ComDecom- Analysis
pression pression
Meaning
JPEGSAMPLE24
0x00000024
Y component, H:V = 2:4
JPEGSAMPLE31
0x00000031
Y component, H:V = 3:1
JPEGSAMPLE32
0x00000032
Y component, H:V = 3:2
JPEGSAMPLE33
0x00000033
Y component, H:V = 3:3
JPEGSAMPLE41
0x00000041
Y component, H:V = 4:1
JPEGSAMPLE42
0x00000042
Y component, H:V = 4:2
JPEGSAMPLECOLOR
0x00000000
Color JPEG
JPEGSAMPLEMONO
0x00000080
Monochrome JPEG
JPEGMODE_NORMAL
0x00000000
×
Normal operation mode
JPEGMODE_MCULINE 0x00000001
×
MCU line operation mode
JPEGMODE_STOP
0x00000002
×
×
Forced termination
JPEGDNL_OFF
0x00000000
×
×
DNL marker inserted
JPEGDNL_ON
0x00000001
×
×
DNL marker not inserted
Remark
: Used
X: Not used
122
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.7.5
External variable
The basic libraries supply the following default table data.
Table 2-34. External Variables
Classification
External Variable Name
Compression
jpeg_DQT_Y
char
64
Luminance component quantization table (only table of
DQT segment defined)
jpeg_DQT_C
char
64
Chrominance component quantization table (only table of
DQT segment defined)
jpeg_DHT_DC_Y
char
Approx. 50
Luminance DC component Huffman table (DHT
segment)
jpeg_DHT_DC_C
char
Approx. 50
Chrominance DC component Huffman table (DHT
segment)
jpeg_DHT_AC_Y
char
Approx. 300
Luminance AC component Huffman table (DHT segment)
jpeg_DHT_AC_C
char
Approx. 300
Chrominance AC component Huffman table (DHT
segment)
2.7.6
Type
Description
Size
(Bytes)
Function
The basic libraries supply the following functions.
Table 2-35. Functions
Classification
Compression
Function Name
jpeg_CompressInit
Initialization of JPEG compression library
jpeg_Compress
Main JPEG compression
jpeg_getMCU_M
Note
VRAM access function (color compression, sampling ratio = 4:4:4 [H:V = 1:1])
Note
jpeg_getMCU_21
VRAM access function (color compression, sampling ratio = 4:2:2 [H:V = 2:1])
jpeg_getMCU_22Note
VRAM access function (color compression, sampling ratio = 4:1:1 [H:V = 2:2])
Note
jpeg_getMCU_41
VRAM access function (color compression, sampling ratio = 4:1:1 [H:V = 4:1])
jpeg_DecompressInit
Initialization of JPEG decompression library
jpeg_Decompress
Main JPEG decompression
jpeg_putMCU_M
Note
VRAM access function (monochrome decompression)
Note
VRAM access function (color decompression, sampling ratio = 4:4:4 [H:V = 1:1])
Note
VRAM access function (color decompression, sampling ratio = 4:2:2 [H:V = 2:1])
Note
jpeg_putMCU_22
VRAM access function (color decompression, sampling ratio = 4:1:1 [H:V = 2:2])
jpeg_putMCU_41Note
VRAM access function (color decompression, sampling ratio = 4:1:1 [H:V = 4:1])
jpeg_AnalysisInit
Initialization of JPEG analysis library
jpeg_Analysis
Main JPEG analysis
jpeg_putMCU_11
jpeg_putMCU_21
Analysis
VRAM access function (monochrome compression)
Note
jpeg_getMCU_11
Decompression
Outline
Note Reference these functions only for customization.
User’s Manual U10684EJ3V0UM
123
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(1) jpeg_CompressInit
Classification
Compression (1/7)
Function name
jpeg_CompressInit
Function outline Initializes a JPEG compression library.
Format
#include “jpeg.h”
long jpeg_CompressInit (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
This function initializes the JPEG compression library and prepares it for compression
execution.
(2) jpeg_Compress
Classification
Compression (2/7)
Function name
jpeg_Compress
Function outline Main JPEG compression
Format
#include “jpeg.h”
long jpeg_Compress (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
Error code
Error Code
Function
Description
JPEGRET_OK
Normal completion
JPEGRET_CONT1
Continuation 1 (request to save JPEG buffer)
JPEGRET_CONT2
Continuation 2 (request to update image data)
JPEGRET_ERR
Abnormal termination (Error contents are stored in member “ErrorState” of
JPEGINFO structure.)
This function executes the JPEG compression specified by info.
If it is terminated abnormally, the value stored in member “ErrorState” of info is as follows:
Value of ErrorState
124
Description
JPEGERR_VRAM
Specified area of compressed image is illegal.
JPEGERR_USF
Compression cannot be executed at specified sampling ratio.
JPEGERR_IMY
Vertical size of compressed image is illegal.
JPEGERR_FID
Component ID values are duplicated.
JPEGERR_DLH
Lh value of DHT header is illegal.
JPEGERR_DCL
Huffman table for DC component is illegal.
JPEGERR_JPB
JPEG buffer size is illegal.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(3) jpeg_getMCU_M/jpeg_getMCU_11/jpeg_getMCU_21/jpeg_getMCU_22/jpeg_getMCU_41
Classification
Compression (3/7 to 7/7)
Function name
jpeg_getMCU_M (monochrome compression)
jpeg_getMCU_11 (color compression, sampling ratio = 4:4:4 [H:V = 1:1])
jpeg_getMCU_21 (color compression, sampling ratio = 4:2:2 [H:V = 2:1])
jpeg_getMCU_22 (color compression, sampling ratio = 4:1:1 [H:V = 2:2])
jpeg_getMCU_41 (color compression, sampling ratio = 4:1:1 [H:V = 4:1])
Function outline Samples data from the image memory and stores it in the MCU buffer.
Format
#include “jpeg.h”
void jpeg_getMCU_M (JPEGINFO *info)
void jpeg_getMCU_11 (JPEGINFO *info)
void jpeg_getMCU_21 (JPEGINFO *info)
void jpeg_getMCU_22 (JPEGINFO *info)
void jpeg_getMCU_41 (JPEGINFO *info)
Argument
Argument
Type
info
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
These functions sample data of one MCU from the current position of the image memory
specified by the member CurrentX/CurrentY of info and stores it in the MCU buffer.
Remark
Observe the C language rules when describing the jpeg_getMCU_xx function in the
assembler.
(4) jpeg_DecompressInit
Classification
Decompression (1/7)
Function name
jpeg_DecompressInit
Function outline Initialization of JPEG decompression library
Format
#include “jpeg.h”
void jpeg_DecompressInit (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
This function initializes the JPEG decompression library and prepares it for decompression
execution.
User’s Manual U10684EJ3V0UM
125
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(5) jpeg_Decompress
Classification
Decompression (2/7)
Function name
jpeg_Decompress
Function outline Main JPEG decompression
Format
#include “jpeg.h”
long jpeg_Decompress (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
Error code
Error Code
126
Description
JPEGRET_OK
Normal termination
JPEGRET_CONT1
Continuation 1 (JPEG buffer updating request)
JPEGRET_CONT2
Continuation 2 (image data saving request)
JPEGRET_ERR
Abnormal termination (error contents are stored in member “ErrorState” of
JPEGINFO structure.)
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Function
This function executes JPEG decompression specified by info.
If it is terminated abnormally, the value stored in member “ErrorState” of info is as follows.
Value of ErrorState
Description
JPEGERR_VRAM
Area of image specified for decompression is illegal.
JPEGERR_USF
This sampling ratio cannot be decompressed.
JPEGERR_QPQ
Value of Pq of DQT header is not set to 0.
JPEGERR_QTQ
Quantization table number (Tq) of DQT header is value other than 0 and 1.
JPEGERR_DHT
Values of Tc and Th of DHT header are illegal.
JPEGERR_SNS
Ns value (number of components) of SOS header is illegal (other than 1
and 3).
JPEGERR_SCD
Huffman table number specified by SOS table is wrong.
JPEGERR_SSS
Value of Se of SOS header is not 0.
JPEGERR_SSE
Value of Se of SOS header is not 63.
JPEGERR_SAA
Values of Ah and Al of SOS header are not 0.
JPEGERR_SFP
Value other than 8 is set to P of SOF header.
JEPGERR_SFN
Value of Nf of SOF header is illegal (other than 1 and 3).
JPEGERR_UKM
Unknown marker has appeared.
JPEGERR_OTH
Illegal marker has appeared in compressed data.
JPEGERR_RST
RSTn marker is illegal.
JPEGERR_SOS
Other SOS header error (component ID is illegal).
JPEGERR_SOF
SOF header is not defined or two or more are defined.
JPEGERR_FTQ
Required quantization table is not defined.
JPEGERR_STH
Required Huffman table is not defined.
JPEGERR_IMY
Vertical size of image is illegal.
JPEGERR_FID
Component IDs of SOF header are duplicated.
JPEGERR_SID
Component IDs of SOS header are duplicated.
JPEGERR_QEL
0 is included in quantization table elements.
JPEGERR_VIJ
Huffman table elements are duplicated.
JPEGERR_JPB
JPEG buffer size is illegal.
JPEGERR_HUF
Compressed data is illegal.
User’s Manual U10684EJ3V0UM
127
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(6) jpeg_putMCU_M/jpeg_putMCU_11/jpeg_putMCU_21/jpeg_putMCU_22/jpeg_putMCU_41
Classification
Decompression (3/7 to 7/7)
Function name
jpeg_putMCU_M (monochrome decompression)
jpeg_putMCU_11 (color decompression, sampling ratio = 4:4:4 [H:V = 1:1])
jpeg_putMCU_21 (color decompression, sampling ratio = 4:2:2 [H:V = 2:1])
jpeg_putMCU_22 (color decompression, sampling ratio = 4:1:1 [H:V = 2:2])
jpeg_putMCU_41 (color decompression, sampling ratio = 4:1:1 [H:V = 4:1])
Function outline Decompresses the data of the MCU buffer in the image memory.
Format
#include “jpeg.h”
void jpeg_putMCU_M (JPEGINFO *info)
void jpeg_putMCU_11 (JPEGINFO *info)
void jpeg_putMCU_21 (JPEGINFO *info)
void jpeg_putMCU_22 (JPEGINFO *info)
void jpeg_putMCU_41 (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
None
Function
These functions decompress data of one MCU to the current position of the image memory
specified by the member CurrentX/CurrentY of info.
Remark
Observe the C language rules when describing the jpeg_putMCU_xx function in the
assembler.
(7) jpeg_AnalysisInit
Classification
Analysis (1/2)
Function name
jpeg_AnalysisInit
Function outline Initialization of JPEG analysis library
Format
#include “jpeg.h”
void jpeg_AnalysisInit (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
128
Return value
None
Function
This function initializes the JPEG analysis library and prepares it for analysis execution.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
(8) jpeg_Analysis
Classification
Analysis (2/2)
Function name
jpeg_Analysis
Function outline Main JPEG analysis
Format
#include “jpeg.h”
long jpeg_Analysis (JPEGINFO *info)
Argument
Argument
info
Type
JPEGINFO*
Description
Pointer to JPEGINFO structureNote
Note For the JPEGINFO structure, refer to 2.7.2 Structure of JPEGINFO structure.
Return value
Error code
Error Code
Function
Description
JPEGRET_OK
Normal completion
JPEGRET_CONT1
Continuation 1 (JPEG buffer updating request)
JPEGRET_ERR
Abnormal termination (error contents are stored in the member “ErrorState”
of the JPEGINFO structure.)
This function executes the JPEG analysis specified by info.
If the function is abnormally terminated, the value stored in member “ErrorState” of info is
as follows.
Value of ErrorState
Description
JPEGERR_SNS
Ns value (number of components) of SOS header is illegal (other than 1 or
3).
JPEGERR_SCD
Huffman table number specified by SOS header is wrong.
JPEGERR_SSS
Value of Ss of SOS header is not 0.
JPEGERR_SSE
Value of Se of SOS header is not 63.
JPEGERR_SAA
Values of Ah and Al of SOS header are not 0.
JPEGERR_SFP
Value other than 8 is set to P of SOF header.
JEPGERR_SFN
Value of Nf of SOF header is undefined (other than 1 or 3).
JPEGERR_UKM
Unknown marker appears.
JPEGERR_JPB
JPEG buffer size is illegal.
User’s Manual U10684EJ3V0UM
129
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.7.7
Section
The sections defined by (reserved by) the basic libraries are as follows.
Table 2-36. Sections Used by Basic Libraries
Processing
Section Name
Compression
Decompression
Analysis
Common
Mapping
ROM
Description
NEC
Version
GHS
Version
RAM
.JPCTEXT
.text
.text
Text (instruction code)
.JPCTBL
.const
.rodata
Table data (read-only)
.JPCDATA
.data
.data
×
Data with default value
.JPCBSS
.bss
.bss
×
Data without default value
.JPDTEXT
.text
.text
Text (instruction code)
.JPDTBL
.const
.rodata
Table data (read-only)
.JPDDATA
.data
.data
×
Data with default value
.JPDBSS
.bss
.bss
×
Data without default value
.JPATEXT
.text
.text
Text (instruction code)
.JPATBL
.const
.rodata
Table data (read-only)
.JPADATA
.data
.data
×
Data with default value
.JPABSS
.bss
.bss
×
Data without default value
.JPJTEXT
.text
.text
Text (instruction code)
.JPJTBL
.const
.rodata
Table data (read-only)
.JPJDATA
.data
data
×
Data with default value
.JPJBSS
.bss
.bss
×
Data without default value
: Can be located.
Remark
×:
2.7.8
Attribute
Cannot be located
Symbol name conventions
The symbol names used in the basic libraries are applied in accordance with the following conventions. When
defining a symbol in the application, exercise care not to specify a reserved symbol name.
Table 2-37. Basic Library Symbol Name Conventions
Classification
130
Description
Function
“jpeg_” is prefixed.
Variable
“jpeg_” is prefixed.
Constant
“JPEG” is prefixed.
Data type
“JPEGINFO”, “APPINFO”
Section
“.JP” is prefixed.
User’s Manual U10684EJ3V0UM
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
2.7.9
Selecting basic library
The following files are supplied as the basic libraries.
Table 2-38. Basic Library File Names
Classification
Compression
Link Priority
File Name
Description
Remark
1
libjpegc.a
Main compression
Be sure to select this file when using
JPEG compression.
2
libjcsm.a
Monochrome compression
3
libjcs11.a
Color compression, sampling ratio =
4:4:4 [H:V = 1:1]
Select all corresponding compression
methods.
4
libjcs21.a
Color compression, sampling ratio =
4:2:2 [H:V = 2:1]
5
libjcs22.a
Color compression, sampling ratio =
4:1:1 [H:V = 2:2]
6
libjcs41.a
Color compression, sampling ratio =
4:1:1 [H:V = 4:1]
7
libjcy.a
Image memory color space YCbCr
8
libjcr.a
Image memory color space RGB
9
libjpegd.a
Main decompression
Be sure to select this file when using
JPEG decompression.
10
libjdsm.a
Monochrome decompression
11
libjds11.a
Color decompression, sampling ratio =
4:4:4 [H:V = 1:1]
Select all corresponding
decompression methods.
12
libjds21.a
Color decompression, sampling ratio =
4:2:2 [H:V = 2:1]
13
libjds22.a
Color decompression, sampling ratio =
4:1:1 [H:V = 2:2]
14
libjds41.a
Color decompression, sampling ratio =
4:1:1 [H:V = 4:1]
15
libjdhl.a
Huffman decompression
Be sure to select this file when using
JPEG decompression.
16
libjdy.a
Image memory color space YCbCr
17
libjdr.a
Image memory color space RGB
Be sure to select either of these files
when using the default
“jpeg_putMCU_xx()”.
Analysis
18
libjpega.a
Main analysis
Be sure to select this file when using
JPEG analysis.
Common
19
libjpeg.a
Common
Be sure to select this file when using
basic library
Decompression
User’s Manual U10684EJ3V0UM
Be sure to select either of these files
when using the default
“jpeg_getMCU_xx()”.
131
CHAPTER 2 BASIC LIBRARY SPECIFICATIONS
Table 2-39. Example of Selecting Basic Library
Processing Method
Condition
Selected Library and Link Order
Compression
Supported sampling ratio: 4:4:4 [H:V = 1:1], 4:2:2 [H:V = 2:1]
jpeg_getMCU: Default file of library (YCbCr method) is used.
libjpegc.a
libjcs11.a
libjcs21.a
libjcy.a
libjpeg.a
Decompression
Supported sampling ratio: 4:2:2 [H:V = 2:1]
jpeg_putMCU: Default file of library (RGB method) is used.
libjpegd.a
libjcs21.a
libjdhl.a
libjcr.a
libjpeg.a
Analysis
None
libjpega.a
libjpeg.a
132
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.1 Function
By using the additional library, decompression that cannot be supported by the basic libraries is possible.
For the main functions, see 1.3.4 Features of additional library.
A JPEG file is decompressed and displayed on the screen.
Figure 3-1. Additional Decompression
xxx.jpg
JPEG
decompression
JPEG file
Converted
into VRAM
data
Library
VRAM
3.1.1 Sampling of progressive format and MCU
The minimum unit in which JPEG performs processing is called an MCU (Minimum Coded Unit). An MCU,
separated into Y, Cb, and Cr in units of 8 × 8 pixels, is called a block (see Section 1.2.1 (3)).
If the number of color components is three, 16 × 16 pixels constitute one MCU at a sampling ratio of 4:1:1 (H:V =
2:2). The MCU at this sampling ratio consists of four blocks of the Y (luminance) component, one block of the Cb
(chrominance) component, and one block of the Cr (chrominance) component.
The size of the MCU and the number of blocks are determined by the Hi and Vi values included in the SOF marker
segment, as follows.
Max number of horizontal pixels of MCU (H0, H1, ...) × 8
Max number of vertical pixels of MCU (V0, V1, ...) × 8
∑iHi × Vi ≤ 10 (limit by ISO/IEC 10918-1)
∑iHi × Vi ≤ 20 (limit of extended format by ISO/IEC 10918-3)
For example, the values of Hi and Vi are as follows for a sampling ratio of 4:1:1 (H:V = 2:2).
H0 = 2, V0 = 2
H1 = 1, V1 = 1
H2 = 1, V2 = 1
If this is substituted into the above expression as follows, then the size of the MCU is 16 × 16 pixels.
Max (H0, H1, H2) × 8 = 16
Max (V0, V1, V2) × 8 = 16
Next, suppose that the number of components is four and that a complicated sampling ratio, such as 1:2:3:4, is
used. The values of Hi and Vi are as follows.
H0 = 1, V0 = 1
H1 = 1, V1 = 2
H2 = 3, V2 = 1
H3 = 1, V3 = 4
User’s Manual U10684EJ3V0UM
133
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
If this is substituted into the above expression as follows, the size of MCU is 24 × 32 pixels.
Max (H0, H1, H2, H3) × 8 = 24
Max (V0, V1, V2, V3) × 8 = 32
At this time, the first component (H0 = 1, V0 = 1) is decompressed into 24 × 32 pixels.
Because the second component (H1 = 1, V1 = 2) has 2 blocks and 24 × 32 pixels, the first block is decompressed to
24 × 16 pixels. Similarly, the first block of the third component (H2 = 3, V2 = 1) is decompressed to 8 × 32 pixels, and
the first block of the fourth component (H3 = 1, V3 = 4) is decompressed to 24 × 8 pixels.
Figure 3-2. Sampling and MCU (at Sampling Ratio of 1:2:3:4)
24 pixels
First component (H0 = 1, V0 = 1)
32 pixels
Second component (H1 = 1, V1 = 2)
Third component (H2 = 3, V2 = 1)
Fourth component (H3 = 1, V3 = 4)
134
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.1.2 Color space
The AP703000-B03 additional library specifies the color space as follows.
• Monochrome format: Luminance (conforms to JFIF Standard)
• Three-color format: YCbCr (conforms to JFIF Standard)
• Four-color format: CMYK, YCCK
If the input JPEG file is in four-color format, the CMYK or YCCK format is automatically identified based on the
information in the file header, and processing is executed with the following expressions.
(1) In CMYK format
C: First component, M: Second component, Y: Third component, K: Fourth component, R, G, B: (R:G:B) of
output
R = C + K; if (R < 0) R = 0; if (R > 255) R = 255;
G = M + K; if (G < 0) G = 0; if (G > 255) G = 255;
B = Y + K; if (B < 0) B = 0; if (B > 255) B = 255;
Remark If the VRAM format is YCbCr instead of RGB, the values of (R:G:B), calculated by this expression,
are transformed into (Y:Cb:Cr).
(2) In YCCK format
Yin: First component, C1in: Second component, C2in: Third component, Kin: Fourth component , Yout,
Cbout, Crout: (Y:Cb:Cr) of output
Yout = Kin-Yin;
Cbout = 0xFF-C1in;
Crout = 0xFF-C2in;
Remark If the VRAM format is RGB instead of YCbCr, the values (Y:Cb:Cr) calculated by this expression are
transformed into (R:G:B).
User’s Manual U10684EJ3V0UM
135
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.1.3 Options for additional decompression
The following options are supported for additional decompression.
(1) Forced termination of additional decompression processing
Additional decompression processing under execution can be forcibly terminated.
This option is specified by the JPEGEXINFO structure.
(2) Stuffing bit and stuffing byte
The value of the stuffing bit in the JPEG file can be checked. In addition, whether the stuffing byte in the JPEG
file is used can be specified.
These options are specified by the JPEGEXINFO structure.
(3) Number of passes for decompression
The number of passes for additional decompression processing can be specified.
This option is specified by the JPEGEXINFO structure.
(4) DNL marker
Whether the existence of a DNL marker (redefinition of the number of lines) is approved can be specified.
This option is specified by the JPEGEXINFO structure.
(5) Zooming in/out of image
Whether an image is zoomed in or out can be specified.
This option is specified by the JPEGEXINFO structure.
(6) Clipping
Clipping for decompression can be set in pixel units.
This option is specified by the JPEGEXVIDEO structure.
136
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.2
Symbol Name Conventions
Symbol names, etc. used in the additional library are as follows.
Table 3-1. Symbol Name Conventions of Additional Library
Classification
Description
Function
[JPEGEX] is prefixed.
Constant (reference-only ROM data)
[JPEGEX] is prefixed.
Constant
[JPEGEX] is prefixed.
Data type
[JPEGEX] is prefixed.
Section
[.JPD] is prefixed.
3.3
Sections
The sections defined (reserved) by the additional library are as follows.
Table 3-2. Sections Used by Additional Library
Processing
Section Name
NEC
Additional
decompression
3.4
.JPD.text
−
Attribute
GHS
Mapping
Description
ROM
RAM
.JPD.TEXT
.text
O
O
Text (instruction code)
.JPDRODATA
.rodata
O
O
Table data (read-only)
.data
O
O
Data with initialization
.JPD.const
−
.const
O
O
Table data (read-only)
.JPD.data
−
.data
×
O
Data with initialization
Library Selection
Files supplied as the additional library are as follows.
Table 3-3. Additional Library File Names
Classification
Additional
decompression
Link Priority
File Name
Description
1
libjprg.a
Additional
decompression main
2
libjprg_l.a
Additional
decompression main
(long jump supported)
3
libjprog.a
For symbol resolution
4
libjprog_I.a
For symbol resolution
(long jump supported)
User’s Manual U10684EJ3V0UM
Remark
Select either of these when using
additional decompression.
Select libjprog.a when using libjprg.a as
additional decompression main, and
libjprog_l.a when using libjprg_l.a.
137
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.5
Function Specifications
In additional library processing, decompression that cannot be supported by the basic libraries is possible.
Only decompression is included in the additional library processing; compression and analysis are not included.
Table 3-4. Additional Decompression Functions
Classification
Additional
decompression
Function Name
JPEGEXdecodeNote 1
Additional decompression main function
JPEGEXGetJpegStream
JPEGEXdecodeAPP
JPEGEXWarning
JPEGEXputMCU
JPEGEXpset
Note 2
Note 3
Note 3
JPEGEXVSyncWait
Description
JPEG data acquisition
APPn segment processing
Warning processing
Note 3
Display timing adjustment processing
Note 3
VRAM drawing processing
Note 3
Pixel data output
Notes 1. Before calling this function, set the members of the JPEGEXINFO, JPEGEXWORK, JPEGEXVIDEO,
and JPEGEXBUFF structures.
2. Required customization function. Be sure to define user applications.
3. Reference these functions only for customization.
138
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.5.1
Additional decompression
(1) JPEGEXdecode
Classification
Additional decompression
Function name
JPEGEXdecode
Function outline
JPEG decompression main
Format
#include “jpegex.h”
int JPEGEXdecode (struct JPEGEXINFO *JPInfo)
Argument
Argument
Format
JPInfo
Description
Pointer to JPEGEXINFO structureNote
JPEGEXINFO*
Note For the JPEGEXINFO structure, see 3.6.1 JPEGEXINFO structure.
Return value
Error Code
Function
Description
JPEGEXDecodeStatusComplete
Normal termination
JPEGEXDecodeStatusTerminate
Forced termination
JPEGEXDecodeStatusError
Error termination
JPEGEXDecodeStatusNotRunning
Process to be forcibly terminated is not operating.
JPEG decompression specified by JPInfo is performed.
When abnormally terminated, check the error contents using the member “ErrorState” of
the JPInfo (see 3.7 Errors During Additional Decompression).
Restriction
In the additional library, a 16-bit quantization table is not supported. If a JPEG file with a
16-bit quantization table is decompressed, an abnormal termination occurs.
User’s Manual U10684EJ3V0UM
139
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.5.2 Additional decompression processing flow
The basic flow of additional decompression processing is shown below.
Figure 3-3. Additional Decompression Processing Flow
User application
Additional library
Start
Allocation of work area.
Structure member setting.
Library function call
Decompression processing
Decode processing
Checking of JPEG buffer
JPEG buffer
update request
Yes
Updating of JPEG buffer
JPEG buffer must
be updated.
No
Yes
Erroneous
termination
Error?
No
End?
Yes
End
140
User’s Manual U10684EJ3V0UM
No
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(1) Setting decompression parameter
Define the argument of the four structures (JPEGEXINFO type, JPEGEXWORK type, JPEGEXVIDEO type,
and JPEGEXBUFF type) defined by the header file “jpegex.h” and set the members (see 3.6 Structure of
Additional Library).
To perform decompression newly, be sure to set this parameter first.
Structure
JPEGEXINFO
JPEGEXWORK
JPEGEXVIDEO
Member
Data to Be Set
TaskID
ID number of task
Mode
Normal decompression/forced termination of decompression
Policy
Decompression option
ratio
Image zoom in/out ratio
Work
Address of JPEGEXWORK structure
Video
Address of JPEGEXVIDEO structure
User1
Member for user definition
User2
Member for user definition
Work1
Work area 1 start address
Work1Len
Work area 1 size (bytes)
Work2
Work area 2 start address
Work2Len
Work area 2 size (bytes)
VRAMAddress
VRAM start address
VRAMWidth
VRAM horizontal width
VRAMHeight
VRAM vertical width
VRAMPixel
Address difference of VRAM horizontal width of one pixel
VRAMLine
Address difference of VRAM vertical width of one pixel
VRAMGap0
Byte offset of Y pixel (or R pixel)
VRAMGap1
Byte offset of Cb pixel (or G pixel)
VRAMGap2
Byte offset of Cr pixel (or B pixel)
ClipStartX
Clipping start position (X coordinate)
ClipStartY
Clipping start position (Y cordinate)
ClipWidth
Clipping horizontal size (pixel)
ClipHeight
Clipping vertical size (pixel)
(2) Calling decompression function [JPEGEXdecode]
Call the decompression function using the pointer of the structure set in (1) Setting decompression
parameter as the argument.
User’s Manual U10684EJ3V0UM
141
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(3) Checking return value
The return values of JPEGEXdecode are as follows.
Return value
Meaning
Description
JPEGEXDecodeStatusComplete
Normal termination
Terminated normally.
JPEGEXDecodeStatusTerminate
Forced termination
Decompression is forcibly terminated.
JPEGEXDecodeStatusError
Abnormal termination
Decompression is terminated due to error detection.
The details of the error are stored in a member
(ErrorState) of the JPEGEXINFO type structure
JPEGEXDecodeStatusNotRunning
Normal termination
Since the process to be forcibly terminated is not
operating, decompression is terminated.
Caution
To perform decompression newly, start again from the processing shown in (1) Setting
decompression parameter.
After decompression is terminated, the size of the work area used can be checked using the JPEGEXWORK
structure.
Member
142
Data to Be Stored
Work1Used
Size of used work area 1 (bytes)
Work2Used
Size of used work area 2 (bytes)
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.5.3
Customize function
Of the functions offered by the additional library, those that can be overwritten by the user are called customize
functions. Of the customize functions, the JPEGEXGetJpegStream function must always be overwritten and defined.
The other customize functions are optional and do not have to be overwritten.
(1) JPEGEXGetJpegStream
Classification
Additional decompression
Function name
JPEGEXGetJpegStream
Function outline
JPEG data acquisition
Format
#include “jpegex.h”
void JPEGEXGetJpegStream (struct JPEGEXBUFF *JPBUFF)
Argument
Argument
Format
JPBUFF
Description
Pointer to JPEGEXBUFF structureNote
JPEGEXBUFF*
Note For the JPEGEXBUFF structure, see 3.6.4 JPEGEXBUFF structure.
Return value
None
Function
The JPEG data is stored in the JPEG buffer.
Values are set to the JPEGEXBUFF structure’s members JPEGBUF and JPEGBUFFLEN.
Be sure to set the JPEGEXGetJpegStream function using a user application.
To update the contents of the JPEG buffer, the members of the JPEGEXBUFF structure are set and then the
JPEGEXGetJpegStream function is called.
If the additional library requests updating of the JPEG file, the contents of the JPEG buffer are updated on the
user application side.
If additional decompression processing is executed in single pass mode, this function is called each time the
additional library requests updating of the JPEG file. In two-pass mode, this function is called only once (for
details of how to set the number of passes, see 3.6.1 (3) (d) 2passEnable (T option)).
Figure 3-4. Updating of JPEG Buffer
Additional library
User application
Decompression processing
Necessity of updating
JPEG buffer arises.
JPEGEXGetJpegStream function is called.
JPEG buffer is updated.
User’s Manual U10684EJ3V0UM
143
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(2) JPEGEXdecodeAPP
Classification
Additional decompression
Function name
JPEGEXdecodeAPP
Function outline
APPn segment processing
Format
#include “jpegex.h”
void JPEGEXdecodeAPP (int APPnumber, int JpegStreamOffset, int Length)
Argument
Argument
Format
Description
APPnumber
int
0: APP0 (0xFF 0xE1)
1: APP1 (0xFF 0xE2)
:
15: APP15 (0xFF 0xEF)
16: COM (0xFF 0xFE)
JpegStreamOffset
int
Offset byte count of APPn segment (from start of JPEG file)
Length
int
APPn segment length (byte count)
Return value
None
Function
APPn segment processing is performed.
The additional library calls this function when an APPn segment is found. This function is optional. If any
processing is necessary, the user can overwrite this function. If the user does not overwrite this function, the
default JPEGEXdecodeAPP function is called. The default function performs no processing.
Figure 3-5. Processing When APP Marker Is Found
Additional library
User application
Decompression processing
APPn is found.
JPEGEXdecodeAPP function is called.
Necessary processing
144
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Figure 3-6. Processing When APP Marker Is Found
JPEG file
SOI
APPn
Offset
APPn segment
......
Length of APPn
(3) JPEGEXWarning
Classification
Additional decompression
Function name
JPEGEXWarning
Function outline
Warning processing
Format
#include “jpegex.h”
void JPEGEXWarning (int WarningNumber)
Argument
Argument
WarningNumber
Format
int
Return value
None
Function
Warning processing is performed.
Description
Warning message number
If an error that is not so serious as to terminate the entire processing occurs during additional decompression
processing, the additional library calls this function. This function is optional. If there is any necessary
processing, the user can overwrite this function. If the user does not overwrite this function, the default
JPEGEXWarning function is called. The default function performs no processing.
For a description of the warning message number that is set as an argument, see 3.8 Warning Messages
Output During Additional Decompression.
User’s Manual U10684EJ3V0UM
145
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Figure 3-7. Processing If Error That Does Not Disrupt Processing Occurs
Additional library
User application
Decompression processing
Error occurs
Can continue
JPEGEXWarning function is called.
Can continue?
Necessary processing
Cannot continue
Error termination
processing
(4) JPEGEXVSyncWait
Classification
Additional decompression
Function name
JPEGEXVSyncWait
Function outline
Display timing adjustment
Format
#include “jpegex.h”
void JPEGEXVSyncWait (void)
Argument
None
Return value
None
Function
The display timing is adjusted.
This function is called before the additional library starts drawing. This function is optional. The user can
overwrite this function if there is a need to adjust the display timing. If the user does not overwrite this function,
the default JPEGEXVSyncWait function is called. The default function does not perform any processing.
146
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Figure 3-8. Processing before Start of Drawing
Additional library
User application
Decompression processing
JPEGEXVSyncWait function is called.
Necessary processing
Drawing starts.
(5) JPEGEXputMCU
Classification
Additional decompression
Function name
JPEGEXputMCU
Function outline
VRAM drawing
Format
#include “jpegex.h”
void JPEGEXputMCU (short *mcubuff, int Y, int X, struct JPEGEXMCUSTR *MCUstr)
Argument
Argument
Format
Description
mcubuff
short*
Pointer to MCU buffer
Y
int
Vertical coordinate of top-left corner of MCU where
drawing is performed
X
int
Horizontal coordinate of top-left corner of MCU where
drawing is performed
MCUstr
struct
Start address of JPEGEXMCUSTR structure
JPEGEXMCUSTR*
Return value
None
Function
Image is displayed in the VRAM.
User’s Manual U10684EJ3V0UM
147
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
This function draws an image in VRAM. This part of the decompression processing, which is affected by
hardware, can be overwritten and created by the user. This function is optional.
To create a JPEGEXputMCU function, the UseExPutMCU bit of the Policy member of the JPEGEXINFO
structure must be set (see 3.6.1 (3) (h) UseExPutMCU (X option)). If this bit is not set, the additional library
dynamically changes between the JPEGEXputMCU function and its alternate function.
To overwrite the JPEGEXputMCU function, see 3.10 Customizing Additional Library.
In the first argument, MCU buffer, values of 0 to 255 are stored in short format. For details of the MCU buffer
structure, see 2.5 MCU Buffer Structure. When using four components, also see 3.1.2 Color space.
Settings related to the image memory when customizing are as follows.
Table 3-5. VRAM Settings When Customizing Image Drawing Function
Structure Member
Customizing Function
JPEGEXputMCU
JPEGEXpset
Both Functions
JPEGEXINFO structure
Video
Required
Required
Required
JPEGEXVRAM structure
VRAMAddress
Required
Dummy value possible
Dummy value possible
VRAMWidth
Dummy value possible
Required
Dummy value possible
VRAMHeight
Dummy value possible
Required
Dummy value possible
VRAMPixel
Required
Dummy value possible
Dummy value possible
VRAMLine
Required
Dummy value possible
Dummy value possible
VRAMGap0
Required
Dummy value possible
Dummy value possible
VRAMGap1
Required
Dummy value possible
Dummy value possible
VRAMGap2
Required
Dummy value possible
Dummy value possible
ClipStartX
0
0
0
ClipStartY
0
0
0
ClipWidth
0x7FFFFFFF
0x7FFFFFFF
0x7FFFFFFF
ClipHeight
0x7FFFFFFF
0x7FFFFFFF
0x7FFFFFFF
148
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(6) JPEGEXpset
Classification
Additional decompression
Function name
JPEGEXpset
Function outline
Pixel data output
Format
#include “jpegex.h”
The argument differs depending on the image output method for this function.
• YCbCr output method:
void JPEGEXpset (struct JPEGEXMCUSTR *MCUstr, int y, int x, int Cy, int Cu, int
Cv);
• RGB output method:
void JPEGEXpset (struct JPEGEXMCUSTR *MCUstr, int y, int x, int R, int G, int B)
Argument
Argument
Format
Description
MCUstr
struct
JPEGEXMCUSTR*
Start address of JPEGEXMCUSTR structure
y
int
Y coordinate of pixel where drawing is performed
x
int
X coordinate of pixel where drawing is performed
Cy, R
int
Y color element data for YCbCr output
R color element data for RGB output
Cu, G
int
Cb color element data for YCbCr output
G color element data for RGB output
Cv, B
int
Cr color element data for YCbCr output
B color element data for RGB output
Return value
None
Function
Image is displayed in the VRAM.
This function draws an image in VRAM. This part of the decompression processing, which is affected by
hardware, can be overwritten and created by the user. This function is optional. For customizing, see Table 35 VRAM Settings When Customizing Image Drawing Function.
The values of variables Cy, Cu, and Cv, and R, G, and B are 0 to 255.
An example of a C source of the pset function is shown below.
void JPEGEXpset( struct JPEGEXMCUSTR * MCUstr, int y, int x, int Cy, int Cu, int Cv )
{
unsigned char * vram;
vram
= MCUstr->VRAMAddress + y * MCUstr->VRAMLine + x * MCUstr->VRAMPixel;
*(vram + MCUstr->VRAMGap0) = (unsigned char)Cy;
*(vram + MCUstr->VRAMGap1) = (unsigned char)Cu;
*(vram + MCUstr->VRAMGap2) = (unsigned char)Cv;
}
User’s Manual U10684EJ3V0UM
149
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.6 Structures of Additional Library
This section explains the structures used for the decompression processing of the additional library.
3.6.1 JPEGEXINFO structure
The JPEGEXINFO structure is used to set the parameters for additional decompression processing. The first
address of this structure is passed to the additional decompression main function as an argument.
Table 3-6. JPEGEXINFO Structure
Member
Type
Description
IN/OUT
TaskID
int
ID number of task
IN
Mode
int
Selection of ordinary decompression processing/forced
termination of expansion processing
IN
Policy
int
Setting of options for expansion processing
IN
ratio
int
Setting image zoom in/out ratio
IN
ErrorState
int
Error status number
OUT
Work
struct JPEGEXWORK
JPEGEXWORK structure first address
IN
Video
struct JPEGEXVIDEO
JPEGEXVIDEO structure first address
IN
Inf
struct JPEGEXFrmlNFO
JPEGEXFrmINFO structure first address
IN/OUT
User1
int
User definition member
IN/OUT
User2
int
User definition member
IN/OUT
(1) TaskID
The value of TaskID is used to distinguish one task from another when two or more tasks are started in a
multitask environment. Because an individual JPEGEXINFO structure is necessary for each task, set a
different value for each TaskID. TaskID does not have to be set when a single task is used.
Note that this value is substituted into the TaskID member of the JPEGEXBUFF structure.
(2) Mode
This member specifies whether decompression processing is performed normally, or is forcibly terminated.
Do not set the forced termination mode before starting a decompression processing.
Table 3-7. Mode Setting of Additional Decompression Processing
Definition name
Numeric value
Description
JPEGEXModeStart
1
Normal decompression mode
JPEGEXModeTerminate
−1
Decompression processing being executed is forcibly terminated.
Specify JPEGEXModeStart to start JPEG decompression.
struct JPEGEXINFO
JPINFO;
main ()
{
JPINFO.Mode = JPEGEXModeStart;
JPEGEXdecode (&JPINFO);
}
150
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
If JPEGEXModeTerminate is specified, additional decompression processing being executed can be forcibly
terminated. By calling the JPEGEXdecode function from an interrupt handler by using the same structure as
the JPEGEXINFO structure specified by the library executing a decompression operation, or from another task
when the OS is used, a signal that prompts forced termination is sent to the additional library being executed.
Figure 3-9. Forced Termination of Additional Decompression Processing with JPEGEXModeTerminate Specified
Additional library
Interrupt handler or another task
Start
Forced termination signal
End
User’s Manual U10684EJ3V0UM
151
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(3) Policy
Policy has option bits in the 4-byte area shown in Figure 3-10.
Policy sets the options listed in Table 3-8.
Figure 3-10. Bit Configuration of Policy
31
23
15
VL K
BY T D
7
0
ZM R X
Table 3-8. Option Setting by Policy
Option Name
VL
Bit Position
Bit Name
Meaning
21
VideoOutLastOnly
Setting of drawing timing
1: Only end is displayed for progressive without an intermediate result.
0: Intermediate result is also displayed.
20
LuminanceOutOnly
Setting of drawing timing (valid when VideoOutLastOnly = 0)
1: Only scan with the luminance component updated is displayed.
0: Display for all scan
K
19
BitStuffCheck
Checking of stuffing bit
1: Checked
0: Not checked
BY
17
ByteStuffDisable
Stuffing byte
1: Disabled
0: Enabled
16
ByteStuffEnable
Stuffing byte (valid when ByteStuffDisable = 0)
1: Permitted up to 0x10000
0: Permitted up to four bytes between segments
T
15
2passEnable
Setting of the number of passes of decompressed processing
(automatically decompressed with two pass when DNLEnable = 1)
1: Decompressed with two passes
0: Decompressed with one pass
D
14
DNLEnable
DNL marker
1: Disabled
0: Disabled
ZM
9
VideoZoomLinear
8
VideoZoomNormal
Zoom in/out of image (automatically decompressed at a multiple of 1
when UseExPutMCU = 1)
ZM = 01: Zoomed in/out
11: Zoomed in/out
10: Zoomed in/out with linear filter
00: Not zoomed in/out (decompressed at a multiple of 1)
R
7
PutMCURGB
Setting of image output (valid when UseExPutMCU = 0)
1: Output as RGB
2: Output as YCbCr
X
6
UseExPutMCU
Use of JPEGEXputMCU function
1: Used
0: Not used
Caution
152
Be sure to set vacant bits other than the bits shown in the above table to 0.
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(a) VideoOutLastOnly/LuminanceOutOnly (VL options)
These options specify the drawing timing.
When the VideoOutLastOnly option is specified, drawing is not performed during decompression. Instead,
it is performed once decompression has ended.
The LuminanceOutOnly option is valid when VideoOutLastOnly = 0 (LuminanceOutOnly is not referenced
when VideoOutLastOnly = 1).
When LuminanceOutOnly = 0, drawing is performed for each scan in which the luminance component has
been updated.
When LuminanceOutOnly = 1, drawing is performed in each scan.
Figure 3-11. Drawing Timing of Baseline Format
Baseline/interleave format
Baseline/non-interleave format
SOI
SOI
JPEG
header
JPEG
header
SOS
SOS
Scan updating
Y, Cb, and Cr
Scan updating Y
★◆❍
EOI
◆❍
SOS
Scan updating Cb
★: Drawing timing of VL = 10, 11
(only last)
❍
◆: Drawing timing of VL = 01
SOS
(luminance only)
❍: Drawing timing of VL = 00
(every time)
Scan updating Cr
★◆❍
EOI
User’s Manual U10684EJ3V0UM
153
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Figure 3-12. Progressive Format Drawing Timing
Y, Cb, Cr
Y, Cb, Cr
◆❍
Cb
◆❍
Y
◆❍
❍
Cr
Cb
❍
❍
Y
Cr
◆❍
Cb
❍
Cb
❍
❍
Cr
Cr
❍
❍
Y
Y
★◆❍
◆❍
Y
◆❍
★: Drawing timing of VL = 10, 11
Cb
❍
(only last)
◆: Drawing timing of VL = 01
Cr
❍
(luminance only)
❍: Drawing timing of VL = 00
Y, Cb, Cr
◆❍
(every time)
Y
◆❍
Cb
❍
Cr
★◆❍
154
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(b) BitStuffCheck (K option)
This option specifies whether the stuffing bit is checked.
The compressed data of a JPEG file is processed in bit units, and markers such as SOF, DHT segment,
and RSTn are processed in byte units. Consequently, a gap of 1 to 7 bits may be created in a section
where compressed data is changed to a marker (such as EOI, SOS, RSTn, and DNL). This gap is called
the stuffing bit, and ISO/IEC 10918-1 stipulates that the values of this stuffing bit be ‘1’.
If BitStuffCheck = 1, the additional library checks whether the stuffing bit in the JPEG file is ‘1’ or ‘0’. If a
bit that is ‘0’ has been found as a result of this check, warning processing is performed (see 3.5.3 (3)
JPEGEXWarning).
Usually, there is no problem regardless of whether the stuffing bit of the JPEG file is ‘1’ or ‘0’.
Figure 3-13. Stuffing Bit
JPEG bit stream
Compressed data
RSTn
Byte boundary
Stuffing bit
User’s Manual U10684EJ3V0UM
155
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(c) ByteStuffDisable/ByteStuffEnable (BY option)
A byte filling the gap between the segments in a JPEG file is called a stuffing byte. For example, if 1 byte
of 0x00 exists between an SOI segment and the subsequent APP0 segment, this stuffing byte is
meaningless for the JPEG file. However, ISO/IEC 10918-1 does not specifically stipulate the existence of
a stuffing byte in the JPEG file.
This option is used by the user to determine whether the existence of a stuffing byte is permitted.
Table 3-9. ByteStuffDisable/ByteStuffEnable (Stuffing Byte) Option
Set value
Meaning
BY = 10
Rejects the existence of a stuffing byte.
In this case, if a JPEG file including a stuffing byte is decompressed, a “marker error: 0x00001007” occurs and
the file is erroneously terminated.
BY = 11
BY = 01
Permits the existence of a stuffing byte up to 0x10000.
However, if a byte string that may be taken as a marker of the JPEG file exists in the stuffing byte, the operation
of the JPEGEXdecode function is undefined.
BY = 00
Default. Four stuffing bytes are permitted between segments.
(d) 2passEnable (T option)
This option specifies the number of passes for additional decompression processing.
When 2passEnable = 1, decompression processing is executed with two passes; when 2passEnable = 0, it
is executed with one pass. However, if DNLEnable = 1 (see 3.6.1 (3) (e) DNLEnable (Doption), it is
unconditionally assumed that the JPEG file is decompressed with two passes.
The differences between decompressed processing with one pass and that with two passes are shown in
Table 3-10.
Table 3-10. Differences in Decompression Processing Due to of Number of Passes
Item
One Pass
Two Passes
Work area size
Must be large
May be small
Example) 4:1:1 (640 x 480 pixels)
Approx. 1 MB
Approx. 5 KB
Example) 1:1:1 (640 x 480 pixels)
Approx. 2 MB
Execution time
Short
Long
Function limit
None
• JPEG buffer cannot be updated
(processing is stopped after data in the JPEG buffer has
been decompressed).
Remark
The example of the work area size is for reference only.
The work area size is set by the JPEGEXWORK structure. If the number of passes is two, the work area size must
be about 5 KB regardless of the size of the image to be decompressed. If only one pass is used, a very large work
area is necessary because all the decompressed DCT coefficients must be saved.
156
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
The expression for the required work area size (unit: bytes) is as follows.
• Single-pass mode:
Work area size = 1408 + (128 × number of blocks per MCU) + (128 × number of quantization tables) + (208 ×
number of Huffman tables for DC component) + (432 × number of Huffman tables for AC component) + (108 ×
number of SOS markers) + (128 × total number of blocks of image to be decompressed)
• Two-pass mode:
Work area size = 1408 + (128 × number of blocks per MCU) + (128 × number of quantization tables) + (208 ×
number of Huffman tables for DC component) + (432 × number of Huffman tables for AC component) + (404 ×
number of SOS markers)
Caution
When using clipping for decompression, calculate using the total number of blocks of the
original image.
However, when the following condition is satisfied, the following size is additionally required for
single-pass and two-pass modes.
• When SOS marker is 15 or larger: Work area size + (68 × (number of SOS markers – 14))
[Calculation example 1]
When decompression is performed under the following conditions
• Image size = 640 × 480 (baseline format)
• Sampling ratio = 4:1:1 (H:V = 2:2)
• Number of quantization tables = 2
• Number of Huffman tables for DC component = 2
• Number of Huffman tables for AC component = 2
• Number of SOS markers = 1
The number of image blocks is calculated as follows using a sampling ratio of 4:1:1 (H:V = 2:2).
Total number of blocks of image =
(Number of pixels of original image in horizontal direction × number of pixels of
original image in vertical direction)/(number of pixels of MCU of Y component)
× (total number of blocks of 1 MCU)
= (640 × 480)/(16 × 16) × (4 + 1 + 1)
= 7200
Therefore, the work area size is as follows.
<1> In single-pass mode
Work area size
= 1408 + (128 × (4 + 1 + 1)) + (128 × 2) + (208 × 2) + (432 × 2) + (108 × 1) + (128 × 7200)
= 1408 + 768 + 256 + 416 + 864 + 108 + 921600
= 925420 bytes
<2> In two-pass mode
Work area size
=1408 + (128 × (4 +1 +1)) + (128 × 2) + (208 × 2) + (432 × 2) + (404 × 1)
= 1408 + 768 + 256 + 416 + 864 + 404
= 4116 bytes
User’s Manual U10684EJ3V0UM
157
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
[Calculation example 2]
When decompression is performed under the following conditions
• Image size = 640 × 480 (progressive format)
• Sampling ratio = 4:1:1 (H:V = 2:2)
• Number of quantization tables = 2
• Number of Huffman tables for DC component = 2
• Number of Huffman tables for AC component = 3
• Number of SOS markers = 7
The number of image blocks is calculated as follows using a sampling ratio of 4:1:1 (H:V = 2:2).
Total number of blocks of image = (Number of pixels of image)/(number of pixels of MCU of Y component) × (total
number of blocks of 1 MCU)
= (640 × 480)/(16 × 16) × (4 + 1 + 1)
= 7200
Therefore, the work area size is as follows.
<1> In single-pass mode
Work area size
= 1408 + (128 × (4 + 1 + 1)) + (128 × 2) + (208 × 2) + (432 × 3) + (108 × 7) + (128 × 7200)
= 1408 + 768 + 256 + 416 + 1296 + 756 + 921600
= 926500 bytes
<2> In two-pass mode
Work area size
= 1408 + (128 × (4 +1 +1)) + (128 × 2) + (208 × 2) + (432 × 3) + (404 × 7)
= 1408 + 768 + 256 + 416 + 1296 + 2828
= 6972 bytes
Remark
In the two-pass mode, processing speed is extremely low because the compressed data is traced from
the start of the JPEG file for every drawing. Also, the image display speed is low because decoding of
compression data is performed during drawing.
158
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Figure 3-14. Number of Passes for Additional Decompression Processing and Drawing Timing
One pass
Two passes
Y, Cb, Cr
◆
Y
◆
Cb
Cr
Cb
Cr
Y
◆
Y
◆
Cb
Cr
Y, Cb, Cr
◆
Y
◆
Cb
Cr
◆
◆: Drawing timing
User’s Manual U10684EJ3V0UM
159
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
If the specified JPEG file is too large for the JPEG buffer, the contents of the JPEG buffer cannot be
exchanged and decompression processing cannot be continued when two passes are used. In this case, the
processing is stopped as soon as the JPEG file in the JPEG buffer specified first has been decompressed (see
3.6.4 (3) JPEGBUFFLEN).
Figure 3-15. Decompression Processing if JPEG File in JPEG Buffer is Disrupted (Two Passes)
Contents of JPEG file
If JPEG file in JPEG
buffer is disrupted (1)
If JPEG file in JPEG
buffer is disrupted (2)
Y, Cb, Cr
Y, Cb, Cr
Y, Cb, Cr
◆
Y
◆
Y
◆
◆
Y
◆
◆
Cb
Cb
Cb
Cr
Cr
Cr
Cb
Cb
Cb
◆
Cr
Cr
Y
Y
◆
◆
Y
Y
◆
◆
Cb
Cb
◆
Cr
Y, Cb, Cr
◆
Y
◆
If two passes are used and if the file in the
buffer is disrupted, processing is stopped.
Cb
Cr
◆
◆: Drawing timing
160
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(e) DNLEnable (D option)
This option enables or disables the decompression of a JPEG file including a DNL marker (re-definition of
the number of lines). When DNLEnable = 1, the JPEG file including a DNL marker can be decompressed.
When DNLEnable = 0, if the JPEG file including a DNL marker is decompressed, decompression is forcibly
terminated (ErrorState: 0x0000101C).
When DNLEnable = 1, decompression is forcibly performed with two passes (the setting of the
2passEnable option is ignored).
The DNL segment corrects the value of Y (number of vertical pixels of image) specified in the SOF marker.
It is specified that the position of the DNL marker is immediately after the first scan (conforms to ISO/IEC
10918-1). If this is violated, an error occurs with the additional library.
The DNL marker is seldom used in an ordinary JPEG file.
Figure 3-16. Position of DNL Marker in JPEG File
If position DNL marker is correct
If position of DNL marker is not correct
:
:
:
SOF
SOF
SOF
DNL
SOS
Y, Cb, Cr
SOS
Y, Cb, Cr
DNL
Y, Cb, Cr
SOS
SOS
SOS
:
:
:
DNL
SOS
First scan
User’s Manual U10684EJ3V0UM
161
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(f) VideoZoomLinear/VideoZoomNormal (ZM option)
These options specify the zoom in/decompression of an image. When setting the ZM option (to perform
zoom in/decompression), do not set the UseExPutMCU option. When UseExPutMCU = 1, the ZM option
is ignored and decompression is performed with a multiple of 1.
Table 3-11. VideoZoomLinear/VideoZoomNormal (Zoom in/Decompression) Options
Set Value
Meaning
ZM = 01
ZM = 11
(VideoZoomNormal)
Zooms in.
As the multiple, the ratio member of the JPEGEXINFO structure ÷ 8 is used.
ZM = 10
(VideoZoomLinear)
Zooms in in the form of linear primary interpolation.
As the multiple, the ratio member of the JPEGEXINFO structure ÷ 8 is used.
Decompression in the linear primary interpolation form takes longer than the VideoZoomNormal form.
Linear primary interpolation is a type of filter. Because processing is performed in
MCU units, the MCU boundary may be conspicuous, although inside the MCU is smooth.
ZM = 00
Does not zoom but performs decompression with a multiple of 1.
The value of the ratio member of the JPEGEXINFO structure is ignored.
(g) PutMCURGB (R option)
This option sets the output mode for an image. When PutMCURGB = 1, the image is output in RGB
mode, instead of YCbCr mode. When PutMCURGB = 0, the image is output in YCbCr mode.
PutMCURGB is valid when UseExPutMCU = 0.
(h) UseExPutMCU (X option)
This option is set when the user customizes the JPEGEXputMCU function.
To customize the JPEGEXputMCU function, set UseExPutMCU to 1 (for customizing the JPEGEXputMCU
function, see 3.10 Customizing Additional Library).
When UseExPutMCU = 0, the JPEGEXputMCU function and its alternate function are dynamically
selected in the additional library.
When UseExPutMCU = 1, the additional library does not perform
dynamic selection and always calls the JPEGEXputMCU function.
If other than ZM = 00 is used for the VideoZoomLinear/VideoZoomNormal option, be sure to set the
UseExPutMCU option to 0. If UseExPutMCU = 1, JPEGEXputMCU is called.
162
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(4) ratio
If the image zoom in/decompression option (VideoZoomLinear/VideoZoomNormal) is validated by the Policy
member of the JPEGEXINFO structure, the zoom-in/out ratio is specified by this ratio member.
Multiply the actual rate by eight and round the result to an integer. Substitute this integer value into ratio. If a
negative value or zero is specified, it is assumed that a value ‘1’ is specified.
The range of the values that can be set to “ratio” is as follows.
(a) For normal zoom in/decompression (when VideoZoomLinear is set)
Set so that “ratio” satisfies the expression below.
1 ≤ ratio ≤ 65536
(b) For linear primary interpolation (when VideoZoomLinear is set) zoom in/decompression
Set so that “ratio” satisfies the expression below.
1 ≤ ratio ≤ 256
(5) ErrorState
If an error occurs during decompression processing, an error number is written to the ErrorState member. For
the meaning of the error number, see 3.7 Errors During Additional Decompression.
(6) Work
Set the first address of the JPEGEXWORK structure to the Work member. The JPEGEXWORK structure
specifies the work area that can be used by the additional library (see 3.6.2 JPEGEXWORK structure).
(7) Video
Set the first address of the JPEGEXVIDEO structure to the Video member. The JPEGEXVIDEO structure
performs settings related to drawing (see 3.6.3 JPEGEXVIDEO structure).
(8) Inf
The additional library itself sets the first address of the JPEGEXFrmINFO structure to the Inf member. The
JPEGEXFrmINFO structure is used by the additional library to store the variables needed for decompression
processing, and is allocated in the work area.
To call the library in decompression mode, set the initial value to 0.
3.6.2
JPEGEXWORK Structure
With the JPEGEXWORK structure, specify a work area that can be used by the additional library. Set the first
address of this structure to the Work member of the JPEGEXINFO structure.
Table 3-12. JPEGEXWORK Structure
Member
Type
Description
IN/OUT
Work1
unsigned int
Work area 1 first address
IN
Work1Len
unsigned int
Work area 1 size (bytes)
IN
Work1Used
unsigned int
Size of work area 1 used (bytes)
OUT
Work2
unsigned int
Work area 2 first address
IN
Work2Len
unsigned int
Work area 2 size (bytes)
IN
Work2Used
unsigned int
Size of work area 2 used (bytes)
OUT
User’s Manual U10684EJ3V0UM
163
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Specify the start address of the work area in which the additional library can be used in either Work1, Work2, or
both of them, and specify the usable size (byte count) in either Work1Len or Work2Len. After the additional library is
terminated, the byte count actually used is stored in Work1Used/Work2Used.
Since work area 1 is used preferentially in the additional library, mapping work area 1 to a high-speed memory is
recommended.
3.6.3 JPEGEXVIDEO Structure
The JPEGEXVIDEO structure performs settings related to drawing. Specify the first address of this structure in the
Video member of the JPEGEXINFO structure.
Specify a value that specifies the structure of VRAM, as a member (VRAMxxx) related to VRAM.
To perform clipping during additional decompression processing, an appropriate value must be set to a member
(Clipxxx) related to clipping. When clipping is not performed, set the dummy values shown in Table 3-13 to the
clipping-related member (Clipxxx).
Table 3-13. JPEGEXVIDEO Structure
Member
Type
Description
IN/OUT
VRAMAddress
unsigned char*
VRAM first address
IN
VRAMWidth
int
Horizontal width of VRAM
IN
VRAMHeight
int
Vertical width of VRAM
IN
VRAMPixel
int
Address difference of VRAM of one horizontal pixel
IN
VRAMLine
int
Address difference of VRAM of one vertical pixel
IN
VRAMGap0
int
Byte offset of Y pixel (or R pixel)
IN
VRAMGap1
int
Byte offset of Cb pixel (or G pixel)
IN
VRAMGap2
int
Byte offset of Cr pixel (or B pixel)
IN
ClipStartX
int
Clipping start position (X coordinate)
Set dummy value 0 when not performing clipping.
IN
ClipStartY
int
Clipping start position (Y coordinate)
Set dummy value 0 when not performing clipping.
IN
ClipWidth
int
Clipping horizontal size (pixel)
Set dummy value 0x7FFFFFFF when not performing clipping.
IN
ClipHeight
int
Clipping vertical size (pixel)
Set dummy value 0x7FFFFFFF when not performing clipping.
IN
(1) VRAM structure
An example of setting VRAM-related members (VRAMxxx) is shown in Figure 3-17.
164
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Figure 3-17. Example of Setting VRAM-Related Members of Additional Library
Address 0 x 2 0 0 0 0 1
Address 0 x 2 0 0 0 0 0
Address 0 x 2 0 0 0 0 2
1 pixel
Address 0 x 1 0 0 0 0 8 0 0
Y
Cr
Cb
0
Y
Cr
Cb
0
Y
Cr
Cb
0
Setting example 1
VRAMAddress = 0 x 2 0 0 0 0 0;
VRAMLine = 0 x 8 0 0;
VRAMPixel = 4;
VRAMGap0 = 0;
VRAMGap1 = 2;
VRAMGap2 = 1;
Address 0 x 6 0 0 0 0 1
Address 0 x 6 0 0 0 0 0
Address 0 x 6 0 0 0 0 2
1 pixel
B
G
R
B
G
R
B
G
R
Setting example 2
Address 0 x 6 0 0 5 0 0
VRAMAddress = 0 x 6 0 0 0 0 0;
Start from "R" in
VRAMLine = 0 x 5 0 0;
the case of RGB.
VRAMPixel = 3;
VRAMGap0 = 2;
VRAMGap1 = 1;
VRAMGap2 = 0;
Address 0 x 8 0 0 0 0 0
Address 0 x 8 0 0 1 0 0
Address 0 x 8 0 0 0 0 1
R
R
R
R
R
R
1 pixel
R
Setting example 3
VRAMAddress = 0 x 8 0 0 0 0 0;
Address 0 x 8 1 0 0 0 0
VRAMLine = 0 x 1 0 0;
G
G
G
G
VRAMPixel = 1;
VRAMGap0 = 0;
Address 0 x 8 2 0 0 0 0
VRAMGap1 = 0 x 1 0 0 0 0;
B
B
B
B
VRAMGap2 = 0 x 2 0 0 0 0;
User’s Manual U10684EJ3V0UM
165
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(2) Setting clipping
Clipping during additional decompression is performed when a value other than the dummy value is set to the
clipping-related members (Clipxxx). When not performing clipping, substitute the dummy values shown in
Table 3-13 for the clipping-related members.
The area of a JPEG image specified by the clipping-related members (Clipxxx) is shown in Figure 3-18.
Set the coordinates whose origin (0, 0) is in the top-left corner of the JPEG image for ClipStartX and
ClipStartY. Set the number of pixels to be clipped for ClipWidth and ClipHeight.
To change the position at which a clipped image is to be drawn, adjust the values of the VRAMAddress
members.
Figure 3-18. Clipping Area
JPEG image
ClipStartX
Clipping area
ClipStartY
ClipHeight
ClipWidth
166
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
(3) Relationship between setting of clipping and zooming in/out
If zooming in or out is specified by using the option of the Policy member of the JPEGEXINFO structure (see
3.6.1 (3) (f) VideoZoomLinear/VideoZoomMormal (ZM option)), the values of ClipStartX, ClipStartY,
ClipWidth, and ClipHeight are applied to the zoomed in or out image.
Figure 3-19 shows the clipping area when the image is zoomed in or out.
Figure 3-19. Clipping Area with Image Zoomed In/Out
JPEG image
Image zoomed in
ClipStartX
Clipping area
ClipStartY
ClipHeight
ClipWidth
User’s Manual U10684EJ3V0UM
167
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.6.4 JPEGEXBUFF structure
The JPEGEXBUFF structure specifies the JPEG buffer into which a JPEG file is to be stored. The first address of
this structure is passed to the JPEG file acquisition function (JPEGEXGetJpegStream) as an argument.
Table 3-14. JPEGEXBUFF Structure
Member
Type
Description
IN/OUT
TaskID
int
Task ID number
OUT (can be overwritten)
JPEGBUFF
unsigned char*
First address of JPEG buffer
IN
JPEGBUFFLEN
unsigned int
Size of JPEG buffer (bytes)
IN
(1) TaskID
TaskID is initialized with the value of TaskID, a member of the JPEGEXINFO structure, (see 3.6.1 (1) TaskID)
when the JPEGEXBUFF structure is allocated in the work area.
The value of this TaskID is used as the ID of the task when the operation is performed in a multitask
environment. When a single task is used, the value of this TaskID member may be overwritten. The additional
library does not reference the value of this member after initialization.
(2) JPEGBUFF
Set the first address of the JPEG buffer in JPEGBUFF.
(3) JPEGBUFFLEN
To decompress in two-pass mode, set JPEGBUFFLEN to the value larger than the size of the JPEG file to be
decompressed. If the JPEG buffer size is smaller than the JPEG file size, the additional library operation is
undefined (normal or abnormal termination).
To decompress in single-pass mode, set as large a JPEG buffer size as possible (the same size as the JPEG
file to be decompressed is recommended).
If the JPEG buffer size is smaller than the JPEG file size, the JPEGEXdecode function calls the JPEG file
acquisition function (see 3.5.3 (1) JPEGEXGetJpegStream) and updates the JPEG buffer.
When the JPEG buffer size is 32 bytes or less, the additional library is terminated abnormally (ErrorState:
0x00001006).
168
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.6.5 JPEGEXMCUSTR structure
The additional library sets a parameter that specifies the structure of the MCU buffer, and a parameter related to
data output in the JPEGEXMCUSTR structure. Specify the first address of this structure as the fourth argument of the
MCU data output function (JPEGEXputMCU) or the first argument of the JPEGEXpset function.
Table 3-15. JPEGEXMCUSTR Structure
Member
Type
Description
IN/OUT
component
unsigned char
Number of color components
1: Luminance only
3: Three colors of Y, Cb, and Cr
4: Four colors
OUT
adobeflag
char
Output mode of four colors
(valid only when four colors is specified)
0: CMYK
1: YCbCr
2: YCCK
OUT
hf [4]
unsigned char
Number of horizontal blocks of MCU buffer
OUT
vf [4]
unsigned char
Number of vertical blocks of MCU buffer
OUT
VRAMAddress
unsigned char*
OUT
VRAMWidth
int
The set value of the JPEGEXVIDEO structure is stored by the
additional library.
VRAMHeight
int
OUT
VRAMPixel
int
OUT
VRAMLine
int
OUT
VRAMGap0
int
OUT
VRAMGap1
int
OUT
VRAMGap2
int
OUT
ClipStartX
int
ClipStartY
int
OUT
ClipWidth
int
OUT
ClipHeight
int
OUT
hfMax
unsigned char
Horizontal width of MCU
(Horizontal size of MCU: hfMax x 8 pixels)
OUT
vfMax
unsigned char
Vertical width of MCU
(Vertical size of MCU: vfMax x 8 pixels)
OUT
The size to be actually clipped is stored by the additional library.
User’s Manual U10684EJ3V0UM
OUT
OUT
169
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.7 Errors During Additional Decompression
The numbers stored in the ErrorState member of the JPEGEXINFO structure when the additional library is
terminated by an error and their meanings are listed in Table 3-16.
Table 3-16. Additional Library Errors (1/2)
Error Message
Number
Meaning
ErrorMode
0x1000
An invalid value has been set in Mode member of JPEGEXINFO structure.
ErrorAllocate
0x1001
Processing cannot be performed because the work area has run short.
ErrorMultiFrame
0x1002
Multiframe format is not supported. Processing is terminated.
ErrorMultiScan
0x1003
Decompression cannot be performed because of format of multiscan is illegal.
ErrorMultiDQT
0x1004
Quantization tables having the same number are defined in a JPEG file in duplicate for
the first and subsequent scans.
ErrorJPEGBuffLen
0x1006
Size of JPEG buffer is too small.
ErrorJPEGMarker
0x1007
An error has been found during JPEG marker analysis.
An unknown marker has been found.
ErrorSOIMarker
0x1008
Marker other than SOI is at the beginning.
ErrorDQTsegment
0x1009
DQT segment contains an error.
ErrorDQTsegmentTq
0x100A
Quantization table number written to DQT segment does not conform to JPEG standard.
ErrorDQTsegmentPq
0x100B
Value of quantization table precision written to DQT segment is other than 8.
ErrorSOFsegment
0x100C
SOF segment contains an error.
ErrorSOFsegmentNf
0x100D
Too many color components are specified for SOF segment.
ErrorSOFsegmentSF
0x100E
Value of sampling factor written to SOF segment does not conform to JPEG standard.
ErrorSOFsegmentTq
0x100F
Quantization table number written to SOF segment does not conform to JPEG standard.
ErrorDHTsegment
0x1010
DHT segment contains an error.
ErrorDHTsegmentTc
0x1011
Table number (Tc) written to DHT segment does not conform to JPEG standard.
ErrorDHTsegmentTh
0x1012
Table number (Th) written to DHT segment does not conform to JPEG standard.
ErrorSOSsegment
0x1014
SOS segment contains an error.
ErrorSOSsegmentCi
0x1015
Color component ID number written to SOS segment is not found in ID written to SOF
segment.
ErrorSOSsegmentTq
0x1016
No quantization table is defined for decompressing the specified scan.
ErrorSOSsegmentTa
0x1017
No AC component Huffman table is defined for decompressing the specified scan.
ErrorSOSsegmentTd
0x1018
No DC component Huffman table is defined for decompressing the specified scan.
ErrorDCcode
0x1019
An error is found in compressed data during DC coefficient decoding.
ErrorACcode
0x101A
An error is found in compressed data during AC coefficient decoding.
ErrorHuffcode
0x101B
A marker is found at an unexpected position.
An error is found in compressed data during progressive decoding.
ErrorDNLsegment
0x101C
DNL segment contains an error.
DNL marker is not enabled.
ErrorRSTsegment
0x101D
RSTn marker contains an error.
ErrorDRIsegment
0x101E
DRI segment contains an error.
ErrorDNLnot1stScan
0x101F
Position of DNL segment is not immediately after the first scan.
170
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Table 3-16. Additional Library Errors (2/2)
Error Message
Number
Meaning
ErrorSOIMarker2
0x1021
Multiple SOI markers are defined.
ErrorDQTelement
0x1022
Table element written to DQT segment does not conform to JPEG standard.
ErrorDHTelement
0x1023
Table element written to DHT segment does not conform to JPEG standard.
ErrorImageX
0x1024
Number of image pixels in horizontal direction written to SOF segment does not conform
to JPEG standard.
ErrorSOFsegmentID2
0x1025
Duplicated component IDs are written to SOF segment.
ErrorSOSMarker
0x1026
No SOS segment is defined.
ErrorSOSsegmentID2
0x1027
Duplicated component IDs are written to SOS segment.
ErrorSOSsegmentSS
0x1028
Ss written to SOS segment does not conform to JPEG standard.
ErrorSOSsegmentSA
0x1029
Compression data information is duplicated.
ErrorDataNotEnough
0x102A
Reserved
ErrorSOF0segmentP
0x102B
Sample bit accuracy is 12 bits (baseline).
ErrorImageY
0x102C
Number of pixels of image in vertical direction written to SOF or DNL segment does not
conform to JPEG standard.
ErrorDNLMarker2
0x102E
Multiple DNL segments are defined.
ErrorSOSnotAlloc
0x102F
Reserved
User’s Manual U10684EJ3V0UM
171
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.8
Warning Messages Output During Additional Decompression
If a warning message is displayed during additional library execution, the JPEGEXWarning function is called, and
the warning number is passed as its first argument. The warning numbers and their meanings are listed in Table 3-17.
Table 3-17. Warning Messages for Additional Library
Warning Message
Number
Meaning
WarningBitStuff
0x2000
Error is found as a result of stuffing bit check. This error is ignored and processing
continues.
WarningProgACInterleave
0x2001
AC coefficient must be non-interleave in progressive format (outside JPEG standard).
Processing continues because there is no problem.
WarningBlock20
0x2002
Total number of blocks in one MCU exceeds 20 (outside JPEG extended standard).
Processing continues because there is no problem.
WarningBlock10
0x2003
Total number of blocks in one MCU exceeds 10 (outside JPEG standard).
Processing continues because there is no problem.
WarningDHTbaselineTh
0x2005
Huffman table numbers 2 and 3 are defined on base line (outside JPEG standard).
Processing continues because there is no problem.
WarningAPP14
0x2006
Although APP segment (APP14) is found, the value of color space identifier in
APP14 segment is other than 0, 1, or 2.
Processing continues on the following assumption:
Single color:
Monochrome
Three colors:
YCbCr
Four colors:
YCbCr with last color ignored
WarningSOFYDNL
0x2009
A value other than 0 is set as the number of vertical pixels but the value defined by
this DNL is assumed as the number of vertical pixels of image and processing
continues.
172
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.9
List of Additional Library Constants
The constants defined by the additional library (jpegex.h) are listed below.
Table 3-18. Additional Library Constants (1/3)
Symbol
Value
IN/OUT
Meaning
JPEGEXModeStart
0x00000001
IN
Normal decompression mode (JPEGEXINFO structure mode)
JPEGEXModeTerminate
0xFFFFFFFF
IN
Forced termination mode (JPEGEXINFO structure mode)
JPEGEXVideoOutLastOnly
0x00200000
IN
In progressive JPEG decompression, only the last image is
displayed (JPEGEXINFO structure Policy)
JPEGEXLuminanceOutOnly
0x00100000
IN
In progressive JPEG decompression, displayed per luminance
component (JPEGEXINFO structure Policy)
JPEGEXBitStuffCheck
0x00080000
IN
Stuffing bit check (JPEGEXINFO structure Policy)
JPEGEXByteStuffDisable
0x00020000
IN
Stuffing byte enabled (JPEGEXINFO structure Policy)
JPEGEXByteStuffEnable
0x00010000
IN
Up to 0x10000 bytes are allowed for stuffing byte
(JPEGEXINFO structure Policy)
JPEGEX2passEnable
0x00008000
IN
Two-pass mode (JPEGEXINFO structure Policy)
JPEGEXDNLEnable
0x00004000
IN
DNL marker enabled (JPEGEXINFO structure Policy)
JPEGEXUsePset
0x00000800
IN
User-created JPEGEXpse function is used (JPEGEXINFO
structure Policy)
JPEGEXVideoZoomLinear
0x00000200
IN
Zooming in/out by a linear filter (JPEGEXINFO structure
Policy)
JPEGEXVideoZoomNormal
0x00000100
IN
Zooming in/out (JPEGEXINFO structure Policy)
JPEGEXPutMCURGB
0x00000080
IN
RGB output (JPEGEXINFO structure Policy)
JPEGEXUseExPutMCU
0x00000040
IN
User-created JPEGEXputMCU function is used (JPEGEXINFO
structure Policy)
JPEGEXWarningBitStuff
0x00002000
OUT
Stuffing bit is illegal (JPEGExWarning () argument)
JPEGEXWarningProgACInterleave
0x00002001
OUT
AC coefficient of progressive JPEG is interleave
(JPEGWarning () argument)
JPEGEXWarningBlock20
0x00002002
OUT
Number of MCU blocks per MCU is 20 or more
(JPEGExWarning () argument)
JPEGEXWarningBlock10
0x00002003
OUT
Number of MCU blocks per MCU is 10 or more
(JPEGExWarning () argument)
JPEGEXWarningDHTbaselineTh
0x00002005
OUT
2 and 3 are used as Huffman table number for baseline JPEG
(JPEGWarning () argument)
JPEGEXWarningAdobe
0x00002006
OUT
Space identifier value in the APP14 segment is other than 0, 1,
and 2 (JPEGExWarning () argument)
JPEGEXWarningSOFYDNL
0x00002009
OUT
Number of pixels in vertical direction is set to other than 0
(JPEGExWarning () argument)
JPEGEXDecodeStatusComplete
0x00000001
OUT
Normal termination (JPEGEXdecode return value)
JPEGEXDecodeStatusTerminate
0x00000002
OUT
Forced termination (JPEGEXdecode return value)
JPEGEXDecodeStatusError
0xFFFFFFFF
OUT
Abnormal termination (JPEGEXdecode return value)
JPEGEXDecodeStatusNotRunning
0xFFFFFFFE
OUT
Process to be forcibly terminated is not operating
(JPEGEXdecode return value)
User’s Manual U10684EJ3V0UM
173
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Table 3-18. Additional Library Constants (2/3)
Symbol
Value
IN/OUT
Meaning
JPEGEXErrorMode
0x00001000
OUT
Decompression mode error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorAllocate
0x00001001
OUT
Insufficient work area size (JPEGEXINFO structure ErrorState)
JPEGEXErrorMultiFrame
0x00001002
OUT
Multi-frame format not supported (JPEGEXINFO structure
ErrorState)
JPEGEXErrorMultiScan
0x00001003
OUT
Multi-scan format error (JPEGEXINFO structure ErrorState)
JPEGEXErrorMultiDQT
0x00001004
OUT
Quantization table duplicate definition (JPEGEXINFO structure
ErrorState)
JPEGEXErrorJPEGBuffLen
0x00001006
OUT
Insufficient JPEG buffer size (JPEGEXINFO structure
ErrorState)
JPEGEXErrorJPEGMarker
0x00001007
OUT
JPEG marker error (JPEGEXINFO structure ErrorState)
JPEGEXErrorSOIMarker
0x00001008
OUT
No SOI marker (JPEGEXINFO structure ErrorState)
JPEGEXErrorDQTsegment
0x00001009
OUT
DQT segment error (JPEGEXINFO structure ErrorState)
JPEGEXErrorDQTsegmentTq
0x0000100A
OUT
DQT segment quantization table number error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorDQTsegmentPq
0x0000100B
OUT
DQT segment quantization table accuracy error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorSOFsegment
0x0000100C
OUT
SOF segment error (JPEGEXINFO structure ErrorState)
JPEGEXErrorSOFsegmentNf
0x0000100D
OUT
SOF segment component count error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOFsegmentSF
0x0000100E
OUT
SOF segment sampling factor error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOFsegmentTq
0x0000100F
OUT
SOF segment quantization table number error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorDHTsegment
0x00001010
OUT
DHT segment error (JPEGEXINFO structure ErrorState)
JPEGEXErrorDHTsegmentTc
0x00001011
OUT
DHT segment Huffman table class error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorDHTsegmentTh
0x00001012
OUT
DHT segment Huffman table number error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorSOSsegment
0x00001014
OUT
SOS segment error (JPEGEXINFO structure ErrorState)
JPEGEXErrorSOSsegmentCi
0x00001015
OUT
Component ID is not defined (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOSsegmentTq
0x00001016
OUT
Quantization table is not defined (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOSsegmentTa
0x00001017
OUT
Huffman table for AC component is not defined (JPEGEXINFO
structure ErrorState)
JPEGEXErrorSOSsegmentTd
0x00001018
OUT
Huffman table for DC component is not defined (JPEGEXINFO
structure ErrorState)
JPEGEXErrorDCcode
0x00001019
OUT
DC component Huffman decode error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorACcode
0x0000101A
OUT
AC component Huffman decode error (JPEGEXINFO structure
ErrorState)
174
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
Table 3-18. Additional Library Constants (3/3)
Symbol
Value
IN/OUT
Meaning
JPEGEXErrorHuffcode
0x0000101B
OUT
Marker (other than RST) appears in compressed data
(JPEGEXINFO structure ErrorState)
JPEGEXErrorDNLsegment
0x0000101C
OUT
DNL marker not allowed, or DNL segment error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorRSTsegment
0x0000101D
OUT
RST marker error (JPEGEXINFO structure ErrorState)
JPEGEXErrorDRIsegment
0x0000101E
OUT
DRI segment error (JPEGEXINFO structure ErrorState)
JPEGEXErrorDNLnot1stScan
0x0000101F
OUT
DNL segment position error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOIMarker2
0x00001021
OUT
SOI marker duplicate definition (JPEGEXINFO structure
ErrorState)
JPEGEXErrorDQTelement
0x00001022
OUT
DQT segment element error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorDHTelement
0x00001023
OUT
DHT segment element error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorImageX
0x00001024
OUT
Error of Horizontal size of image (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOFsegmentID2
0x00001025
OUT
SOF segment component ID duplicate definition
(JPEGEXINFO structure ErrorState)
JPEGEXErrorSOSMarker
0x00001026
OUT
No SOS segment (JPEGEXINFO structure ErrorState)
JPEGEXErrorSOSsegmentID2
0x00001027
OUT
SOF segment component ID duplicate definition
(JPEGEXINFO structure ErrorState)
JPEGEXErrorSOSsegmentSS
0x00001028
OUT
SOS segment spectral selection error (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOSsegmentSA
0x00001029
OUT
SOS segment successive approximation error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorDataNotEnough
0x0000102A
OUT
Reserved
JPEGEXErrorSOF0segmentP
0x0000102B
OUT
SOF0 segment sample bit accuracy error (JPEGEXINFO
structure ErrorState)
JPEGEXErrorImageY
0x0000102C
OUT
Error of vertical size of image (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOSsegmentSA
0x0000102E
OUT
DNL segment duplicate definition (JPEGEXINFO structure
ErrorState)
JPEGEXErrorSOSsegmentSA
0x0000102F
OUT
Reserved
User’s Manual U10684EJ3V0UM
175
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
3.10 Customizing Additional Library
The image output section of the additional library can be customized by overwriting related functions.
The image output section must always be customized in accordance with the specification of the image memory to
be used or the setting of the image output options. The following cases can be cited as examples.
• If the color space of the image memory is not 24-bit RGB (24-bit YCbCr)
• If the image memory cannot be accessed with st.b/st.h/st.w
To customize the image output section, change the JPEGEXpset or JPEGEXputMCU function. The JPEGEXpset
function draws dots on the screen and is called the internal putMCU function of the additional library.
The
JPEGEXputMCU function outputs data to the screen in MCU units and is dedicated to customization (if this function is
not customized, the internal putMCU function of the additional library is called).
3.10.1 Simple customization
The image output portion can easily be customized by customizing the JPEGEXpset function.
For the
specifications of the JPEGEXpset function, see 3.5.3 (7) JPEGEXpset.
When customizing the JPEGEXpset function, the JPEGEXpset function (default) is not used.
3.10.2 Advanced customization
To improve the overall performance of the system, the image output section must be customized by overwriting the
JPEGEXputMCU function, in addition to the JPEGEXpset function. By overwriting the JPEGEXputMCU function,
redundant sections such as address calculation and storing/loading arguments to/from the stack can be reduced.
For the specifications of the JPEGEXputMCU function, see 3.5.3 (6) JPEGEXputMCU.
The Policy member of the JPEGEXINFOR structure has options related to image output.
To customize the
JPEGEXputMCU function, set the UseExPutMCU option of Policy to 1 (see 3.6.1 (3) Policy).
3.10.3 Example of customization
The next page shows a C source example that defines the JPEGEXputMCU and JPEGEXpset functions. In this
example, the JPEGEXpset function is called repeatedly. To improve the processing speed of the additional library, it is
necessary to expand functions that are often called inline as shown in this example.
176
User’s Manual U10684EJ3V0UM
CHAPTER 3 PROGRESSIVE-SUPPORTING ADDITIONAL LIBRARY SPECIFICATIONS
#include "jpegex.h"
#defineR_Cr
(int)(1.40200*0x4000)
#defineG_Cb
(int)(-0.34414*0x4000)
#defineG_Cr
(int)(-0.71414*0x4000)
#defineB_Cb
(int)(1.77200*0x4000)
#defineshiftbit 14
void JPEGEXpset(struct JPEGEXMCUSTR *MCUstr,int y,int x,int Cy,int Cu,int Cv)
{
unsigned char *vram;
vram=MCUstr->VRAMAddress+y*MCUstr->VRAMLine+x*MCUstr->VRAMPixel;
*(vram+MCUstr->VRAMGap0)=(unsigned char)Cy;
*(vram+MCUstr->VRAMGap1)=(unsigned char)Cu;
*(vram+MCUstr->VRAMGap2)=(unsigned char)Cv;
}
void JPEGEXputMCU(short*mcubuff,int Y,int X,struct JPEGEXMCUSTR*MCUstr)
{
int x,y,w,h,Cy,Cu,Cv,R,G,B;
int hf0,hf1,hf2,vf0,vf1,vf2,hfs0,hfs1,hfs2;
int x0,x1,x2,y0,y1,y2;
short* mcubuff1;
short* mcubuff2;
hf0=MCUstr->hf[0];vf0=MCUstr->vf[0];
hf1=MCUstr->hf[1];vf1=MCUstr->vf[1];
hf2=MCUstr->hf[2];
w=(MCUstr->hfMax)*8;h=(MCUstr->vfMax)*8;
mcubuff1=mcubuff+((vf0*hf0)<<6);
mcubuff2=mcubuff1+((vf1*hf1)<<6);
vf0=MCUstr->vfs[0];
vf1=MCUstr->vfs[1];
vf2=MCUstr->vfs[2];
hfs0=MCUstr->hfs[0];
hfs1=MCUstr->hfs[1];
hfs2=MCUstr->hfs[2];
for(y=0;y<h;y++){
y0=(y>>vf0);
y1=(y>>vf1);
y2=(y>>vf2);
for(x=0;x<w;x++){
x0=(x>>hfs0);
x1=(x>>hfs1);
x2=(x>>hfs2);
Cy=*(mcubuff+(((x0>>3)+(y0>>3)*hf0)<<6)+(y0&7)*8+(x0&7));
Cu=*(mcubuff1+(((x1>>3)+(y1>>3)*hf1)<<6)+(y1&7)*8+(x1&7));
Cv=*(mcubuff2+(((x2>>3)+(y2>>3)*hf2)<<6)+(y2&7)*8+(x2&7));
R=(((Cy<<shiftbit)+(Cv-0x80)*R_Cr+(1<<(shiftbit-1)))>>shiftbit);
G=(((Cy<<shiftbit)+(Cu-0x80)*G_Cb+(Cv-0x80)*G_Cr+(1<<(shiftbit-1)))>>
shiftbit);
B=(((Cy<<shiftbit)+(Cu-0x80)*B_Cb+(1<<(shiftbit-1)))>>shiftbit);
Cy=(R<0)? 0:(R>255)?255:R;
Cu=(G<0)? 0:(G>255)?255:G;
Cv=(B<0)? 0:(B>255)?255:B;
JPEGEXpset(MCUstr,Y+y,X+x,Cy,Cu,Cv);
}
}
}
User’s Manual U10684EJ3V0UM
177
CHAPTER 4 INSTALLATION
4.1
Installation Procedure
(1) Windows version
Copy the contents of the medium to the hard disk by using a copy command or filer (file manipulation
application).
At this time, the directory configuration does not have to be specified.
TM
(2) UNIX
version
Copy “NEC_JPEG.tar” to the hard disk and restore the file using the command “tar xovf NEC_JPEG.tar”. The
device specification differs depending on the environment.
The directory configuration when copying the medium contents to the hard disk does not have to be specified.
4.2
Execution Procedure of Sample Program
The source of the sample program of compression/decompression/analysis is supplied with the package. Use this
source as a system example.
4.2.1 Outline of sample program for basic libraries
(1) Outline of sample program
Download a bitmap file (Targa format) and execute JPEG compression using a library. Decompress and
analyze the created JPEG file. To execute the file, the actual machine or a simulator is necessary.
The memory mapping is as illustrated below.
Figure 4-1. Example of Basic Library Memory Mapping (V850E/MS1)
0x00FFFFFF
0 x 0 0 F F F 0 0 0 Peripheral I/O area
0x00FFEFFF
0 x 0 0 F F E 0 0 0 Internal RAM area
0x00FFDFFF
External memory
0x00100000
0 x 0 0 0 F F F F F Internal ROM area
0x00000160
0x0000015F
Interrupt vector table
0x00000000
178
Not used
Not used
0x00800000 to 0x008FFFFF
Stack
Data (sample)
0x00200000 to 0x002FFFFF
Image memory (VRAM)
Program
(library, sample)
Data for reference
(library, sample)
(Reset vector is used)
User’s Manual U10684EJ3V0UM
CHAPTER 4 INSTALLATION
(2) Compiling and linking
(a) Moving directory
Move the file to the work directory. The destination is as follows.
Table 4-1. Destination of File (1)
Windows Version
UNIX Version
NEC version
\NECtools32\smp850\jpeg\base
/NECtools32/smp850/jpeg/base
GHS version
\NECtools32\smp850_ghs\jpeg\base
/NECtools/smp850_ghs/jpeg/base
(b) Changing sample source
Change the setting of TOOLDIR described in the makefile.
Describe the setting of MM/DWC1/DWC2/BCC… to start.s. Set MM in the external extension mode (e.g.,
0x07 in the case of the V850E/MS1) (this setting is not always necessary if a software simulator is used).
(c) make
Execute the “make” command.
(3) Execution with actual machine or simulator
(a) Setting of debugger and simulator
Make the following setting because an external memory is used.
MM: External extension mode
External memory setting: 0x00100000 to 0x00FFEFFF must be usable.
(b) Download
Program (execution format)
Bitmap file (Download fish.tga to _tgaFile0.)
(c) Setting of breakpoint
Set a breakpoint “where tp02() is terminated” in main().
(d) Execution
(e) Upload
JPEG file (compression result: 0x2327 bytes from _jpegFile1)
Bitmap file (decompression result: 0x17A12 bytes from _tgaFile1)
(f) Check
Check to see if the value of err is 0x00000000.
Check the data uploaded in (e) with an image viewer.
User’s Manual U10684EJ3V0UM
179
CHAPTER 4 INSTALLATION
4.2.2 Outline of sample program of additional library
(1) Outline of sample program
Download a JPEG file to the JPEG buffer and execute JPEG decompression using the additional library. To
execute the file, the actual machine or a simulator is necessary.
The memory mapping is as illustrated below.
Figure 4-2. Example of Additional Library Memory Mapping (V850E/MS1)
0x00FFFFFF
0 x 0 0 F F F 0 0 0 Peripheral I/O area
0x00FFEFFF
0 x 0 0 F F E 0 0 0 Internal RAM area
0x00FFDFFF
External memory
0x00100000
0 x 0 0 0 F F F F F Internal ROM area
0x00000160
0x0000015F
Interrupt vector table
0x00000000
180
Not used
Not used
0x00800000 to 0x008FFFFF
Stack
Data (sample)
0x00200000 to 0x002FFFFF
Image memory (VRAM)
Program
(library, sample)
Data for reference
(library, sample)
(Reset vector is used)
User’s Manual U10684EJ3V0UM
CHAPTER 4 INSTALLATION
(2) Compiling and linking
(a) Moving directory
Move the file to the work directory. The destination is as follows.
Table 4-2. Destination of File (2)
Windows Version
UNIX Version
NEC version
\NECTools32\smp850\jpeg\ex
/NECTools32/smp850/jpeg/ex
GHS version
\NECTools32\smp850_ghs\jpeg\ex
/NECTools32/smp850_ghs/jpeg/ex
(b) Changing sample source
Change the setting of TOOLDIR described in the makefile.
Describe the setting of MM/DWC1/DWC2/BCC… to start.s. Set MM in the external extension mode (e.g.,
0x07 in the case of the V850E/MS1) (this setting is not always necessary if a software simulator is used).
(c) make
Execute the “make” command.
(3) Execution with actual machine or simulator
(a) Setting of debugger and simulator
Make the following setting because an external memory is used.
MM: External extension mode
External memory setting: 0x00100000 to 0x00FFEFFF must be usable.
(b) Download
Program (execution format)
Bitmap file (Download basesmp.jpg or progsmp.jpg to _tgaFile1.)
(c) Setting of breakpoint
Set a breakpoint “where JPEGEXdecode() is terminated” in main().
(d) Execution
(e) Upload
Bitmap file (result of decompressing: _tgaFile1 to 0x38412 bytes)
(f) Check
Check to see if the value of err is 0x00000001.
Check the data uploaded in (e) with an image viewer.
User’s Manual U10684EJ3V0UM
181
CHAPTER 4 INSTALLATION
4.2.3 Outline of sample program of basic and additional libraries
(1) Outline of sample program
Download a bitmap file (Targa format) and execute JPEG decompression using a library. To execute the file,
the actual machine or a simulator is necessary.
The memory mapping is as illustrated below.
Figure 4-3. Example of Basic/Additional Library Memory Mapping (V850E/MS1)
0x00FFFFFF
0 x 0 0 F F F 0 0 0 Peripheral I/O area
0x00FFEFFF
0 x 0 0 F F E 0 0 0 Internal RAM area
0x00FFDFFF
External memory
0x00100000
0x000FFFFF
Internal ROM area
0x00000160
0x0000015F
Interrupt vector table
0x00000000
182
Not used
Not used
0x00800000 to 0x008FFFFF
Stack
Data (sample)
0x00200000 to 0x002FFFFF
Image memory (VRAM)
Program
(library, sample)
Data for reference
(library, sample)
(Reset vector is used)
User’s Manual U10684EJ3V0UM
CHAPTER 4 INSTALLATION
(2) Compiling and linking
(a) Moving directory
Move the file to the work directory. The destination is as follows.
Table 4-3. Destination of File (3)
Windows Version
UNIX Version
NEC version
\NECTools32\smp850\jpeg\both
/NECTools32/smp850/jpeg/both
GHS version
\NECTools32\smp850_ghs\jpeg\both
/NECTools32/smp850_ghs/jpeg/both
(b) Changing sample source
Change the setting of TOOLDIR described in the makefile.
Describe the setting of MM/DWC1/DWC2/BCC… to start.s. Set MM in the external extension mode (e.g.,
0x07 in the case of the V850E/MS1) (this setting is not always necessary if a software simulator is used).
(c) make
Execute the “make” command.
(3) Execution with actual machine or simulator
(a) Setting of debugger and simulator
Make the following setting because an external memory is used.
MM: External extension mode
External memory setting: 0x00100000 to 0x00FFEFFF must be usable.
(b) Download
Program (execution format)
Bitmap file (Download fish.tga to _tgaFile0.)
(c) Setting of breakpoint
Set a breakpoint “where JPEGEXdecode () is terminated” in main().
(d) Execution
(e) Upload
JPEG file (result of compressing: _jpegFile1 to 0x2327 bytes)
Bitmap file (result of decompressing: _tgaFile1 to 0x17A12 bytes)
(f) Check
Check to see if the value of err is 0x00000001.
Check the data uploaded in (e) with an image viewer.
User’s Manual U10684EJ3V0UM
183
APPENDIX A SAMPLE PROGRAM SOURCE LIST
A.1
Sample Program Basic Library
The sample program source lists shown later are examples of when the program is executed under the conditions
shown in Tables A-1 to A-3.
Table A-1. Setting of Compression
Item
Image memory (VRAM)
JPEG compression
information 1
JPEG compression
information 2 (JPEG-specific
setting)
JPEG storage memory
Library work
Structure Member
Set Value
VRAM_Bptr
& (vramArea [2])
Image memory: uchar vramAre []
VRAM_W_Pixel
320
VRAM_H_Pixel
240
Image size: 320 [W] × 240 [H]
Coordinate position: (0,0) to (319, 239)
VRAM_Line_Byte
1280
VRAM_Pixel_Byte
4
VRAM_GAP1_Byte
−1
VRAM_GAP2_Byte
−2
Mode
JPEGMODE_NORMAL
Operation mode: Normal compression
Width
320
Image size: 320 [W] × 240 [H]
Height
240
StartX
0
StartY
0
Cl1
0x01
ID of component 1: 0x01
Cl2
0x02
ID of component 2: 0x02
Cl3
0x03
ID of component 3: 0x03
Quality
75
Quality parameter: 75
Sampling
JPEGSAMPLE21
Sampling ratio: 4: 2: 2 [H:V = 2:1]
DQT_Y_Bptr
& (jpeg_DQT_Y [0])
Quantization table: Library default
DQT_C_Bptr
& (jpeg_DQT_C [0])
DHT_DC_Y_Bptr
& (jpeg_DHT_DC_Y [0])
DHT_DC_C_Bptr
& (jpeg_DHT_DC_C [0])
DHT_AC_Y_Bptr
& (jpeg_DHT_AC_Y [0])
DHT_AC_C_Bptr
& (jpeg_DHT_AC_C [0])
Restart
0
RSTm marker: Not inserted
DNL
JPEGDNL_OFF
DNL marker: Not inserted
APP_Info_Bptr
0
APPn marker: Not inserted
JPEG_Buff_Bptr
& (jpegBuff [0])
JPEG file storage buffer
JPEG_Buff_Eptr
& (jpegBuff [0]) + 0x8000
MCU_Buff_Bptr
& (mcuBuff [0] [0])
MCU buffer
Work1_Bptr
& (work1Buff [0])
Library work 1
Work2_Bptr
& (work2Buff [0])
Library work 2
JPEGINFO structure variable
jpegInfo
Corresponding program position
L121 to L197
184
Description
User’s Manual U10684EJ3V0UM
Image storage sequence: Left to right,
top to bottom
Color space: 24-bit RGB
Pixel-format: B, G, R, and reserved in
that order.
B = G = R = rev = 1 [byte]
Coordinate position: (0, 0) to (319, 239)
Huffman table: Library default
APPENDIX A SAMPLE PROGRAM SOURCE LIST
Table A-2. Setting of Decompression
Item
Image memory (VRAM)
Structure Member
Set Value
Description
VRAM_Bptr
& (vramArea [2])
Image memory: uchar vramAre []
VRAM_W_Pixel
320
VRAM_H_Pixel
240
Image size: 320 [W] × 240 [H]
Coordinate position: (0,0) to (319, 239)
VRAM_Line_Byte
1280
VRAM_Pixel_Byte
4
VRAM_GAP1_Byte
−1
VRAM_GAP2_Byte
−2
Mode
JPEGMODE_NORMAL
Operation mode: Normal decompression
StartX
0
Coordinate position: (0, 0) to (w, h)
StartY
0
JPEG decompression
information 2 (JPEG-specific
setting)
APP_Info_Bptr
0
APPn marker: Fixed to 0 with this
function
JPEG storage memory
JPEG_Buff_Bptr
& (jpegBuff [0])
JPEG file storage buffer
JPEG_Buff_Eptr
& (jpegBuff [0]) + 0x8000
MCU_Buff_Bptr
& (mcuBuff [0] [0])
MCU buffer
Work1_Bptr
& (work1Buff [0])
Library work 1
Work2_Bptr
& (work2Buff [0])
Library work 2
JPEG decompression
information 1
Library work
Image storage sequence: Left to right,
top to bottom
Color space: 24-bit RGB
Pixel format: B, G, R, and reserved in
that order.
B = G = R = rev = 1 [byte]
JPEGINFO structure variable
jpegInfo
Corresponding program position
L198 to L257
Table A-3. Setting of Analysis
Item
Structure Member
Set Value
Description
JPEG analysis information 2
(JPEG-specific setting)
APP_Info_Bptr
0
APPn marker: APPn marker is not
analyzed.
JPEG storage memory
JPEG_Buff_Bptr
& (jpegBuff [0])
JPEG file storage buffer
JPEG_Buff_Eptr
& (jpegBuff [0]) + 0x8000
Work1_Bptr
& (work1Buff [0])
Library work
JPEGINFO structure variable
jpegInfo
Corresponding program position
L258 to L294
User’s Manual U10684EJ3V0UM
Library work 1
185
APPENDIX A SAMPLE PROGRAM SOURCE LIST
001
/*======================================================================
*/
002
/*Copyright (C) NEC Corporation 1995,2002
*/
003
/*NEC CONFIDENTIAL AND PROPRIETARY
*/
004
/*All rights reserved by NEC Corporation.
*/
005
/*Use of copyright notice does not evidence publication */
006
/*----------------------------------------------------------------------
007
/*80[character/line], 4[character/tab]
*/
008
/*======================================================================
*/
010
/*======================================================================
*/
011
/* include file
*/
012
/*======================================================================
*/
013
#include
<string.h>
014
#include
"jpeg.h"
015
/*======================================================================
*/
016
/* common definition
*/
017
/*======================================================================
018
#define
B2H(x)
(x >> 1)
019
#define
B2W(x)
(x >> 2)
020
#define
H2B(x)
(x << 1)
021
#define
H2W(x)
(x >> 1)
022
#define
W2B(x)
(x << 2)
023
#define
W2H(x)
(x << 1)
024
#define
RET_OK
0
025
#define
RET_ERR
(-1)
026
#define
COLOR_YCBCR
0
027
#define
COLOR_RGB
1
028
/*======================================================================
029
/* definition necessary to use JPEG-middleware
*/
030
/*======================================================================
*/
031
JPEGINFO
jpegInfo;
032
#define
DEF_JPEGBUFFSIZE
033
U08
034
S16
035
APPINFO
appInfo;
/* APPINFO structure
*/
036
S32
work1Buff[B2W(0x00000100)];
/* work1
*/
037
S32
work2Buff[B2W(0x00002000)];
/* work2
038
/*======================================================================
039
/* definition necessary to use JPEG-middleware (setting of VRAM)
*/
040
/*======================================================================
*/
041
#define
DEF_VRAM_W
320
042
#define
DEF_VRAM_H
240
043
#define
DEF_VRAM_PIXEL
4
044
#define
DEF_VRAM_LINE
(DEF_VRAM_W * DEF_VRAM_PIXEL)
045
#define
DEF_VRAM_SIZE
(DEF_VRAM_H * DEF_VRAM_LINE)
046
#define
DEF_VRAM_GAP1
-1
047
#define
DEF_VRAM_GAP2
-2
048
#define
DEF_VRAM_COLOR
COLOR_RGB
*/
009
186
*/
*/
/* JPEGINFO structure
*/
/* JPEG Buffer
*/
jpegBuff[DEF_JPEGBUFFSIZE];
/* JPEG buffer
*/
mcuBuff[6][64];
/* MCU buffer
*/
0x00008000
User’s Manual U10684EJ3V0UM
*/
*/
APPENDIX A SAMPLE PROGRAM SOURCE LIST
049
U08
050
/*======================================================================
051
/* definition necessary to use this sample
*/
052
/*======================================================================
*/
053
054
vramArea[DEF_VRAM_SIZE];
typedefstruct
*/
{
PU08 Bp;
/* start address
*/
055
U16
imgWidth;
/* display area width (pixel)
*/
056
U16
imgHeight;
/* display area height (pixel)
*/
057
S16
ByteLine;
/* 1 line (byte)
*/
058
S16
BytePixel;
/* 1 pixel (byte)
*/
059
S16
ByteGap1;
/* Gap1(byte)
*/
060
S16
ByteGap2;
/* Gap2(byte)
*/
061
S32
ColorType;
/* color space
*/
062
} VRAMINFO;
063
typedef
064
typedefstruct
065
S16
X;
/* start x coordinate
*/
066
S16
Y;
/* start y coordinate
*/
067
S16
W;
/* width
*/
068
S16
H;
/* height
*/
069
} RECT;
070
typedef
071
VRAMINFO vramInfo;
/* VRAM configuration
*/
072
RECT
imgRect;
/* image size and position
*/
073
U08
tgaFile0[DEF_VRAM_SIZE+18];
/* TGAFILE1 area
*/
074
U08
tgaFile1[DEF_VRAM_SIZE+18];
/* TGAFILE2 area
*/
075
U08
jpegFile1[0x00010000];
/* JPEGFILE1 area
076
/*======================================================================
077
/* function prototype declaration
078
/*======================================================================
079
S32
tpCompress( void );
080
S32
tpDecompress( void );
081
S32
tpAnalyze( void );
082
S32
VRAM2TGA( PVRAMINFO, PRECT, PU08 );
083
void
TGA2VRAM( PVRAMINFO, PRECT, PU08 );
084
void
FIX_YCC2RGB_CCIR601( U08, U08, U08, PU08, PU08, PU08 );
085
void
FIX_RGB2YCC_CCIR601( U08, U08, U08, PU08, PU08, PU08 );
086
/*======================================================================
087
/* main program
*/
088
/*======================================================================
*/
089
void main( void )
090
{
091
S32
VRAMINFO * PVRAMINFO;
{
RECT * PRECT;
*/
*/
*/
*/
*/
err;
092
093
/* --------------------------------------------------------
*/
094
/* sets VRAM configuration to VRAMINFO structure
*/
095
/* --------------------------------------------------------
*/
096
vramInfo.Bp
= &(vramArea[0]);
User’s Manual U10684EJ3V0UM
187
APPENDIX A SAMPLE PROGRAM SOURCE LIST
097
vramInfo.imgWidth
098
vramInfo.imgHeight = DEF_VRAM_H;
= DEF_VRAM_W;
099
vramInfo.ByteLine
100
vramInfo.BytePixel = DEF_VRAM_PIXEL;
101
vramInfo.ByteGap1
= DEF_VRAM_GAP1;
102
vramInfo.ByteGap2
= DEF_VRAM_GAP2;
103
vramInfo.ColorType = DEF_VRAM_COLOR;
104
err
105
/* --------------------------------------------------------
*/
106
/* Stop!
*/
107
/* [1] downloads TGAFILE (FISH.TGA->tgaFile0)
108
/* --------------------------------------------------------
109
err |= tpCompress();
/* compression test
*/
110
err |= tpDecompress();
/* decompression test
*/
111
err |= tpAnalyze();
/* analysis test
112
/* --------------------------------------------------------
113
/* Stop!
*/
114
/* [1] checks error value (err==RET_OK)?(OK):(NG)
*/
115
/* [2] uploads JPEGFILE (jpegFile1->FISH??R1.JPG)
*/
116
/* [3] uploads TGAFILE (tgaFile1->FISH??R2.TGA)
117
/*
118
/* --------------------------------------------------------
119
return;
120
}
121
/*======================================================================
122
/* compression test program
123
/*======================================================================
124
S32
125
{
126
PU08 file;
127
S32
= DEF_VRAM_LINE;
= RET_OK;
*/
*/
*/
*/
"??"=SAMPLE value (11,21,22,...)
*/
*/
*/
*/
tpCompress( void )
size;
128
129
imgRect.X
= 0;
130
imgRect.Y
= 0;
131
TGA2VRAM( &vramInfo, &imgRect, &(tgaFile0[0]) );
132
memset( (PU08)(&jpegInfo), 0x00, sizeof(JPEGINFO) );
133
jpegInfo.Quality
= 75;
134
jpegInfo.Sampling
= JPEGSAMPLE21;
135
jpegInfo.Restart
= 0;
136
jpegInfo.Width
= imgRect.W;
137
jpegInfo.Height
= imgRect.H;
138
jpegInfo.StartX
= imgRect.X;
139
jpegInfo.StartY
= imgRect.Y;
140
jpegInfo.VRAM_Bptr
= vramInfo.Bp;
141
jpegInfo.VRAM_W_Pixel
= vramInfo.imgWidth;
142
jpegInfo.VRAM_H_Pixel
= vramInfo.imgHeight;
143
jpegInfo.VRAM_Line_Byte
= vramInfo.ByteLine;
144
jpegInfo.VRAM_Pixel_Byte
= vramInfo.BytePixel;
188
*/
User’s Manual U10684EJ3V0UM
*/
APPENDIX A SAMPLE PROGRAM SOURCE LIST
145
jpegInfo.VRAM_Gap1_Byte
= vramInfo.ByteGap1;
146
jpegInfo.VRAM_Gap2_Byte
= vramInfo.ByteGap2;
147
jpegInfo.JPEG_Buff_Bptr
= &(jpegBuff[0]);
148
jpegInfo.JPEG_Buff_Eptr
= jpegInfo.JPEG_Buff_Bptr + DEF_JPEGBUFFSIZE;
149
jpegInfo.MCU_Buff_Bptr
= &(mcuBuff[0][0]);
150
jpegInfo.DQT_Y_Bptr
= jpeg_DQT_Y;
151
jpegInfo.DQT_C_Bptr
= jpeg_DQT_C;
152
jpegInfo.DHT_DC_Y_Bptr
= jpeg_DHT_DC_Y;
153
jpegInfo.DHT_DC_C_Bptr
= jpeg_DHT_DC_C;
154
jpegInfo.DHT_AC_Y_Bptr
= jpeg_DHT_AC_Y;
155
jpegInfo.DHT_AC_C_Bptr
= jpeg_DHT_AC_C;
156
jpegInfo.APP_Info_Bptr
= 0;
157
jpegInfo.Work1_Bptr
= &(work1Buff[0]);
158
jpegInfo.Work2_Bptr
= &(work2Buff[0]);
159
jpegInfo.Mode
= JPEGMODE_NORMAL;
160
jpegInfo.DNL
= JPEGDNL_OFF;
161
jpegInfo.CI1
= 0x01;
162
jpegInfo.CI2
= 0x02;
163
jpegInfo.CI3
= 0x03;
164
file = &(jpegFile1[0]);
165
size = 0;
166
jpeg_CompressInit( &jpegInfo );
167
for( ; ; ) {
168
switch( jpeg_Compress( &jpegInfo ) ) {
169
case JPEGRET_OK:
170
size = jpegInfo.FileSize - size;
171
memcpy( file, jpegInfo.JPEG_Buff_Bptr, size );
172
return( RET_OK );
173
case JPEGRET_CONT1:
174
size = jpegInfo.FileSize - size;
175
memcpy( file, jpegInfo.JPEG_Buff_Bptr, size );
176
file += size;
177
size = jpegInfo.FileSize;
178
break;
179
case JPEGRET_CONT2:
180
if( jpegInfo.Mode != JPEGMODE_MCULINE ) {
181
return( RET_ERR );
182
}
183
jpegInfo.StartX =
184
if( (jpegInfo.Sampling & JPEGSAMPLEMONO) == 0 ) {
185
186
jpegInfo.StartY += JPEGGET_MCUV( jpegInfo.Sampling );
} else {
187
188
189
190
191
192
imgRect.X;
jpegInfo.StartY += 8;
}
break;
case JPEGRET_ERR:
return( RET_ERR );
default:
User’s Manual U10684EJ3V0UM
189
APPENDIX A SAMPLE PROGRAM SOURCE LIST
193
return( RET_ERR );
194
}
195
}
196
return( RET_ERR );
197
}
198
/*======================================================================
199
/* decompression test program
*/
200
/*======================================================================
*/
201
S32
202
{
203
PU08 file;
204
S32
tpDecompress( void )
size;
205
206
imgRect.X
= 0;
207
imgRect.Y
= 0;
208
memset( (PU08)(&jpegInfo), 0x00, sizeof(JPEGINFO) );
209
jpegInfo.StartX
= imgRect.X;
210
jpegInfo.StartY
= imgRect.Y;
211
jpegInfo.VRAM_Bptr
= vramInfo.Bp;
212
jpegInfo.VRAM_W_Pixel
= vramInfo.imgWidth;
213
jpegInfo.VRAM_H_Pixel
= vramInfo.imgHeight;
214
jpegInfo.VRAM_Line_Byte
= vramInfo.ByteLine;
215
jpegInfo.VRAM_Pixel_Byte
= vramInfo.BytePixel;
216
jpegInfo.VRAM_Gap1_Byte
= vramInfo.ByteGap1;
217
jpegInfo.VRAM_Gap2_Byte
= vramInfo.ByteGap2;
218
jpegInfo.JPEG_Buff_Bptr
= &(jpegBuff[0]);
219
jpegInfo.JPEG_Buff_Eptr
= jpegInfo.JPEG_Buff_Bptr + DEF_JPEGBUFFSIZE;
220
jpegInfo.MCU_Buff_Bptr
= &(mcuBuff[0][0]);
221
jpegInfo.APP_Info_Bptr
= 0;
222
jpegInfo.Work1_Bptr
= &(work1Buff[0]);
223
jpegInfo.Work2_Bptr
= &(work2Buff[0]);
224
jpegInfo.Mode
= JPEGMODE_NORMAL;
225
file = &(jpegFile1[0]);
226
size = jpegInfo.JPEG_Buff_Eptr - jpegInfo.JPEG_Buff_Bptr;
227
memcpy( jpegInfo.JPEG_Buff_Bptr, file, size );
228
jpeg_DecompressInit( &jpegInfo );
229
for( ; ; ) {
230
switch( jpeg_Decompress( &jpegInfo ) ) {
231
case JPEGRET_OK:
232
imgRect.W = jpegInfo.Width;
233
imgRect.H = jpegInfo.Height;
234
VRAM2TGA( &vramInfo, &imgRect, &(tgaFile1[0]) );
235
return( RET_OK );
236
case JPEGRET_CONT1:
237
memcpy( jpegInfo.JPEG_Buff_Bptr, file, size );
238
break;
239
240
190
case JPEGRET_CONT2:
if( jpegInfo.Mode != JPEGMODE_MCULINE ) {
User’s Manual U10684EJ3V0UM
*/
APPENDIX A SAMPLE PROGRAM SOURCE LIST
241
return( RET_ERR );
242
}
243
jpegInfo.StartX =
244
if( (jpegInfo.Sampling & JPEGSAMPLEMONO) == 0 ) {
245
imgRect.X;
jpegInfo.StartY += JPEGGET_MCUV( jpegInfo.Sampling );
246
} else {
247
jpegInfo.StartY += 8;
248
}
249
break;
250
case JPEGRET_ERR:
251
return( RET_ERR );
252
default:
253
return( RET_ERR );
254
}
255
}
256
return( RET_ERR );
257
}
258
/*======================================================================
259
/* analysis test program
*/
260
/*======================================================================
*/
261
S32
262
{
263
PU08 file;
264
S32
*/
tpAnalyze( void )
size;
265
266
imgRect.X
= 0;
267
imgRect.Y
= 0;
268
memset( (PU08)(&jpegInfo), 0x00, sizeof(JPEGINFO) );
269
jpegInfo.JPEG_Buff_Bptr
= &(jpegBuff[0]);
270
jpegInfo.JPEG_Buff_Eptr
= jpegInfo.JPEG_Buff_Bptr + DEF_JPEGBUFFSIZE;
271
jpegInfo.APP_Info_Bptr
= 0;
272
jpegInfo.Work1_Bptr
= &(work1Buff[0]);
273
file = &(jpegFile1[0]);
274
size = jpegInfo.JPEG_Buff_Eptr - jpegInfo.JPEG_Buff_Bptr;
275
memcpy( jpegInfo.JPEG_Buff_Bptr, file, size );
276
jpeg_AnalysisInit( &jpegInfo );
277
for( ; ; ) {
278
switch( jpeg_Analysis( &jpegInfo ) ) {
279
case JPEGRET_OK:
280
imgRect.W = jpegInfo.Width;
281
imgRect.H = jpegInfo.Height;
282
return( RET_OK );
283
case JPEGRET_CONT1:
284
285
memcpy( jpegInfo.JPEG_Buff_Bptr, file, size );
break;
286
case JPEGRET_CONT2:
287
case JPEGRET_ERR:
288
return( RET_ERR );
User’s Manual U10684EJ3V0UM
191
APPENDIX A SAMPLE PROGRAM SOURCE LIST
289
default:
290
return( RET_ERR );
291
}
292
}
293
return( RET_ERR );
294
}
295
/*======================================================================
*/
296
/* VRAM/Targa conversion program
*/
297
/*======================================================================
*/
298
S32
VRAM2TGA( PVRAMINFO info, PRECT rect, PU08 tga )
299
{
300
S16
sx, sy, x, y;
301
S16
width, height;
302
S16
pixel, line;
303
PU08
304
U08
p0, p1, p2;
305
S32
size;
307
sx
= (S16)(rect->X);
308
sy
= (S16)(rect->Y);
309
width
= (S16)(rect->W);
310
height = (S16)(rect->H);
311
pixel
= (S16)(info->BytePixel);
312
line
= (S16)(info->ByteLine);
313
*(tga +
0) = 0;
314
*(tga +
1) = 0;
315
*(tga +
2) = 2;
316
*(tga +
3) = 0;
317
*(tga +
4) = 0;
318
*(tga +
5) = 0;
319
*(tga +
6) = 0;
320
*(tga +
7) = 0;
321
*(tga +
8) = 0;
322
*(tga +
9) = 0;
323
*(tga + 10) = 0;
324
*(tga + 11) = 0;
325
*(tga + 12) = (U08)(width & 0xFF);
326
*(tga + 13) = (U08)((width >> 8) & 0xFF);
327
*(tga + 14) = (U08)(height & 0xFF);
328
*(tga + 15) = (U08)((height >> 8) & 0xFF);
329
*(tga + 16) = 24;
330
*(tga + 17) = 0x20;
331
tga
332
size =
333
for( y = 0; y < height; y ++ ){
vp;
306
334
+= 18;
18;
for( x = 0; x < width; x ++ ){
335
vp =
336
vp += (S32)((S16)(sx + x) * pixel);
192
info->Bp;
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
337
vp += (S32)((S16)(sy + y) * line);
338
p0 = *vp;
339
p1 = *(vp + (info->ByteGap1));
340
p2 = *(vp + (info->ByteGap2));
341
if( info->ColorType == COLOR_YCBCR ) {
342
FIX_YCC2RGB_CCIR601( p0, p1, p2, &p0, &p1, &p2 );
343
}
344
*(tga + 0) = p2;
345
*(tga + 1) = p1;
346
*(tga + 2) = p0;
347
tga
348
size += 3;
349
+= 3;
}
350
}
351
return( size );
352
}
353
354
void TGA2VRAM( PVRAMINFO info, PRECT rect, PU08 tga )
355
{
356
S16
sx, sy, x, y;
357
S16
width, height;
358
S16
pixel, line;
359
PU08 vp;
360
U08
p0, p1, p2;
361
362
sx
=
(S16)(rect->X);
363
sy
=
(S16)(rect->Y);
364
width
=
((S16)(*(tga+12)) & 0xFF);
365
width |= (((S16)(*(tga+13)) & 0xFF) << 8);
366
height =
367
height|= (((S16)(*(tga+15)) & 0xFF) << 8);
368
pixel
=
(S16)(info->BytePixel);
369
line
=
(S16)(info->ByteLine);
370
rect->W=
width;
371
rect->H=
height;
372
tga
373
for( y = 0; y < height; y ++ ){
374
((S16)(*(tga+14)) & 0xFF);
+= 18;
for( x = 0; x < width; x ++ ){
375
vp = info->Bp;
376
vp += (S32)((S16)(sx + x) * pixel);
377
vp += (S32)((S16)(sy + y) * line);
378
p2 = *(tga + 0);
379
p1 = *(tga + 1);
380
p0 = *(tga + 2);
381
if( info->ColorType == COLOR_YCBCR ) {
382
FIX_RGB2YCC_CCIR601( p0, p1, p2, &p0, &p1, &p2 );
383
}
384
*vp
= p0;
User’s Manual U10684EJ3V0UM
193
APPENDIX A SAMPLE PROGRAM SOURCE LIST
385
*(vp + (info->ByteGap1))
= p1;
386
*(vp + (info->ByteGap2))
= p2;
387
tga += 3;
388
}
389
}
390
return;
391
}
392
/*======================================================================
393
/* CCIR601-1 color conversion (RGB/YCbCr) program
*/
394
/*======================================================================
*/
395
#defineS08MIN
((S08)0xFFFFFF80)
396
#defineS08MAX
((S08)0x0000007F)
397
#defineU08MIN
((U08)0x00000000)
398
#defineU08MAX
((U08)0x000000FF)
399
#defineZERO
( 0)
400
#definePOSITIVE
( 1)
401
#defineNEGATIVE
(-1)
402
#defineMIN(x,min)
(((x)>(min))?(min):(x))
403
#defineMAX(x,max)
(((x)<(max))?(max):(x))
404
#defineSAT(x,min,max)
(((x)<(min))?(min):(((x)>(max))?(max):(x)))
405
#defineSIGN(x)
(((x)==ZERO)?(ZERO):(((x)>ZERO)?(POSITIVE):(NEGATIVE)))
406
#defineABS(x)
(((x)>=ZERO)?((x)):(-(x)))
407
#defineFLT2FIX(x,p)
((S16)((ABS((x))*(1<<(p))
408
#defineRNDFLT2FIX(x,p)
((S16)((ABS((x))*(1<<(p))+0.5)*(SIGN((x)))))
409
#defineFIX2INT(x,p)
( (x)
410
#defineRNDFIX2INT(x,p)
(((x)+(1<<((p)-1)))>>(p))
411
#defineFLT2INT(x)
((S16)((ABS((x))
412
#defineRNDFLT2INT(x)
((S16)((ABS((x))+0.5)*(SIGN((x)))))
413
#defineFLT_RGB2YCC_R2Y
( 0.29900)
414
#defineFLT_RGB2YCC_G2Y
( 0.58700)
415
#defineFLT_RGB2YCC_B2Y
( 0.11400)
416
#defineFLT_RGB2YCC_R2CB (-0.16874)
417
#defineFLT_RGB2YCC_G2CB (-0.33126)
418
#defineFLT_RGB2YCC_B2CB ( 0.50000)
419
#defineFLT_RGB2YCC_R2CR ( 0.50000)
420
#defineFLT_RGB2YCC_G2CR (-0.41869)
421
#defineFLT_RGB2YCC_B2CR (-0.08131)
422
#defineFIX_RGB2YCC_FP
(14)
423
#defineFIX_RGB2YCC_R2Y
(RNDFLT2FIX(FLT_RGB2YCC_R2Y, FIX_RGB2YCC_FP))
424
#defineFIX_RGB2YCC_G2Y
(RNDFLT2FIX(FLT_RGB2YCC_G2Y, FIX_RGB2YCC_FP))
425
#defineFIX_RGB2YCC_B2Y
(RNDFLT2FIX(FLT_RGB2YCC_B2Y, FIX_RGB2YCC_FP))
426
#defineFIX_RGB2YCC_R2CB (RNDFLT2FIX(FLT_RGB2YCC_R2CB,FIX_RGB2YCC_FP))
427
#defineFIX_RGB2YCC_G2CB (RNDFLT2FIX(FLT_RGB2YCC_G2CB,FIX_RGB2YCC_FP))
428
#defineFIX_RGB2YCC_B2CB (RNDFLT2FIX(FLT_RGB2YCC_B2CB,FIX_RGB2YCC_FP))
429
#defineFIX_RGB2YCC_R2CR (RNDFLT2FIX(FLT_RGB2YCC_R2CR,FIX_RGB2YCC_FP))
430
#defineFIX_RGB2YCC_G2CR (RNDFLT2FIX(FLT_RGB2YCC_G2CR,FIX_RGB2YCC_FP))
431
#defineFIX_RGB2YCC_B2CR (RNDFLT2FIX(FLT_RGB2YCC_B2CR,FIX_RGB2YCC_FP))
432
#defineFLT_YCC2RGB_Y2R
194
)*(SIGN((x)))))
>>(p))
)*(SIGN((x)))))
( 1.00000)
User’s Manual U10684EJ3V0UM
*/
APPENDIX A SAMPLE PROGRAM SOURCE LIST
433
#defineFLT_YCC2RGB_CB2R ( 0.00000)
434
#defineFLT_YCC2RGB_CR2R ( 1.40200)
435
#defineFLT_YCC2RGB_Y2G
436
#defineFLT_YCC2RGB_CB2G (-0.34414)
437
#defineFLT_YCC2RGB_CR2G (-0.71414)
438
#defineFLT_YCC2RGB_Y2B
439
#defineFLT_YCC2RGB_CB2B ( 1.77200)
440
#defineFLT_YCC2RGB_CR2B ( 0.00000)
441
#defineFIX_YCC2RGB_FP
(14)
442
#defineFIX_YCC2RGB_Y2R
(RNDFLT2FIX(FLT_YCC2RGB_Y2R, FIX_YCC2RGB_FP))
443
#defineFIX_YCC2RGB_CB2R (RNDFLT2FIX(FLT_YCC2RGB_CB2R,FIX_YCC2RGB_FP))
444
#defineFIX_YCC2RGB_CR2R (RNDFLT2FIX(FLT_YCC2RGB_CR2R,FIX_YCC2RGB_FP))
445
#defineFIX_YCC2RGB_Y2G
446
#defineFIX_YCC2RGB_CB2G (RNDFLT2FIX(FLT_YCC2RGB_CB2G,FIX_YCC2RGB_FP))
447
#defineFIX_YCC2RGB_CR2G (RNDFLT2FIX(FLT_YCC2RGB_CR2G,FIX_YCC2RGB_FP))
448
#defineFIX_YCC2RGB_Y2B
449
#defineFIX_YCC2RGB_CB2B (RNDFLT2FIX(FLT_YCC2RGB_CB2B,FIX_YCC2RGB_FP))
450
#defineFIX_YCC2RGB_CR2B (RNDFLT2FIX(FLT_YCC2RGB_CR2B,FIX_YCC2RGB_FP))
( 1.00000)
( 1.00000)
(RNDFLT2FIX(FLT_YCC2RGB_Y2G, FIX_YCC2RGB_FP))
(RNDFLT2FIX(FLT_YCC2RGB_Y2B, FIX_YCC2RGB_FP))
451
452
void FIX_RGB2YCC_CCIR601( U08 R, U08 G, U08 B, PU08 Y, PU08 Cb, PU08 Cr )
453
{
454
S16
r, g, b;
455
S32
y, cb, cr;
456
457
r
=
(S16)R;
458
g
=
(S16)G;
459
b
=
(S16)B;
460
y
=
(FIX_RGB2YCC_R2Y *r)+(FIX_RGB2YCC_G2Y *g)+(FIX_RGB2YCC_B2Y *b);
461
cb
=
(FIX_RGB2YCC_R2CB*r)+(FIX_RGB2YCC_G2CB*g)+(FIX_RGB2YCC_B2CB*b);
462
cr
=
(FIX_RGB2YCC_R2CR*r)+(FIX_RGB2YCC_G2CR*g)+(FIX_RGB2YCC_B2CR*b);
463
y
=
FIX2INT(y, FIX_RGB2YCC_FP);
464
cb
=
FIX2INT(cb,FIX_RGB2YCC_FP);
465
cr
=
FIX2INT(cr,FIX_RGB2YCC_FP);
466
y
=
SAT(y, U08MIN,U08MAX);
467
cb
=
SAT(cb,S08MIN,S08MAX);
468
cr
=
SAT(cr,S08MIN,S08MAX);
469
y
+= 0x00000000;
470
cb
+= 0x00000080;
471
cr
+= 0x00000080;
472
*Y
=
473
*Cb =
(U08)cb;
474
*Cr =
(U08)cr;
475
return;
476
}
(U08)y;
477
478
void FIX_YCC2RGB_CCIR601( U08 Y, U08 Cb, U08 Cr, PU08 R, PU08 G, PU08 B )
479
{
480
S16
y, cb, cr;
User’s Manual U10684EJ3V0UM
195
APPENDIX A SAMPLE PROGRAM SOURCE LIST
481
S32
r, g, b;
482
483
y
484
cb =
(S16)Cb;
485
cr =
(S16)Cr;
486
y
487
cb -= 0x00000080;
488
cr -= 0x00000080;
489
r
=
(FIX_YCC2RGB_Y2R*y)+(FIX_YCC2RGB_CB2R*cb)+(FIX_YCC2RGB_CR2R*cr);
490
g
=
(FIX_YCC2RGB_Y2G*y)+(FIX_YCC2RGB_CB2G*cb)+(FIX_YCC2RGB_CR2G*cr);
491
b
=
(FIX_YCC2RGB_Y2B*y)+(FIX_YCC2RGB_CB2B*cb)+(FIX_YCC2RGB_CR2B*cr);
492
r
=
FIX2INT(r,FIX_YCC2RGB_FP);
493
g
=
FIX2INT(g,FIX_YCC2RGB_FP);
494
b
=
FIX2INT(b,FIX_YCC2RGB_FP);
495
r
=
SAT(r,U08MIN,U08MAX);
496
g
=
SAT(g,U08MIN,U08MAX);
497
b
=
SAT(b,U08MIN,U08MAX);
498
*R =
(U08)r;
499
*G =
(U08)g;
500
*B =
(U08)b;
501
return;
502
}
196
=
(S16)Y;
-= 0x00000000;
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
A.2
Additional Decompression Sample Program (Single-Pass Mode)
The sample program source list shown later only indicates an example when the program is executed with the
settings in Table A-4.
Table A-4. Additional Decompression Settings (1)
Item
JPEG decompression
information
(JPEGEXINFO structure)
Library work
(JPEGEXWORK structure)
Image memory (VRAM)
(JPEGEXVIDEO structure)
JPEG storage memory
(JPEGEXBUFF structure)
Structure Member
Set Value
Description
Mode
JPEGEXModeStart
Operation mode: Normal decompression
Policy
JPEGEXLuminanceOutOnly
Option for decompression:
 JPEGEXPutMCURGB
Drawing for each luminance component
RGB output
Work
&JPWORK
struct JPEGEXWORK JPWORK
Video
&JPVIDEO
struct JPEGEXVIDEO JPVIDEO
Work1
Work1Area
Work1Len
0x800
Work area 1:
int Work1Area [0x200]
Work2
Work2Area
Work2Len
0x50000
VRAMAddress
&tgaFile1 [20]
VRAM: unsigned char tgaFile1 []
VRAMWidth
320
VRAMHeight
240
VRAM size: 320 [W] × 240 [H]
Coordinate position: (0, 0) to (319, 239)
VRAMPixel
3
Image storage sequence:
VRAMLine
960
VRAMGap0
0
VRAMGap1
−1
Left to right and top to bottom
Color space: 24-bit RGB
Pixel format: B, G, R in that order
B = G = R = 1 [byte]
VRAMGap2
−2
ClipStartX
0
ClipStartY
0
ClipWidth
0x7FFFFFFF
ClipHeight
0x7FFFFFFF
JPEGBUFF
&jpegFile1 [0]
JPEG file storage buffer:
JPEGBUFFLEN
100000
unsigned char jpegFile1 [100000]
Position of supported program
Work area 2:
int Work2Area [0x14000
No clipping (dummy value is set)
L067 to L124
001
/****************************************************************/
002
/*
Copyright (C) NEC Corporation 1995,2002
*/
003
/*
NEC CONFIDENTIAL AND PROPRIETARY
*/
004
/*
All rights reserved by NEC Corporation.
*/
005
/*
Use of copyright notice does not evidence publication
*/
006
/****************************************************************/
007
/*************************************************
008
* include
009
*************************************************/
011
#include "jpegex.h"
012
User’s Manual U10684EJ3V0UM
197
APPENDIX A SAMPLE PROGRAM SOURCE LIST
013
/*************************************************
014
**
015
*************************************************/
016
#define
JPEG_BUFSIZE
100000
017
#define
TMP_BUFSIZE
0x1000
019
#define
VRAM_WIDTH
320
020
#define
VRAM_HEIGHT
240
021
#define
VRAM_PIXEL
3
022
#define
VRAM_GAP1
-1
023
#define
VRAM_GAP2
-2
024
#define
VRAM_LINE
( VRAM_WIDTH * VRAM_PIXEL )
025
#define
WORK1LENGTH
0x800
026
#define
WORK2LENGTH
0x50000
Definition of the global variable
018
027
028
/* structure definition */
029
struct JPEGEXINFO JPINFO;
030
struct JPEGEXWORK JPWORK;
031
struct JPEGEXVIDEO JPVIDEO;
032
033
/*************************************************
034
** Reference of the global variable
035
*************************************************/
036
unsigned char
jpegFile1[JPEG_BUFSIZE];
037
unsigned char
tgaFile1[VRAM_WIDTH * VRAM_HEIGHT * VRAM_PIXEL + 18];
038
unsigned char
VRAM[VRAM_WIDTH * VRAM_HEIGHT * VRAM_PIXEL];
040
unsigned int
Work1Area[WORK1LENGTH/4];
041
unsigned int
Work2Area[WORK2LENGTH/4];
043
unsigned char
jpegtmp[TMP_BUFSIZE];
044
unsigned char
*jpegptr = (unsigned char*)(&(jpegFile1[0]));
039
042
045
046
/*************************************************
047
** Function definition
048
*************************************************/
049
void jd_proc(void);
050
void main(void);
051
void JPEGEXGetJpegStream(struct JPEGEXBUFF*);
052
void fillMem( unsigned char * dst, signed long size );
053
void tga_head( unsigned char * tga );
054
055
/*************************************************
056
*
057
*************************************************/
058
void main(void)
059
{
main
060
061
/*
the decompression processing */
062
tga_head( &tgaFile1[0] );
063
064
198
jd_proc();
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
065
}
066
067
void jd_proc(void)
068
{
069
int ret;
070
071
fillMem( &tgaFile1[18], (signed long)(VRAM_HEIGHT * VRAM_LINE) );
072
073
/* jpeg decompress parameter */
074
JPINFO.Mode
= JPEGEXModeStart;
075
JPINFO.Policy
= JPEGEXLuminanceOutOnly | JPEGEXPutMCURGB;
076
JPINFO.Work
= &JPWORK;
077
JPWORK.Work1
= (unsigned int*)Work1Area;
078
JPWORK.Work1Len
= (int)WORK1LENGTH;
079
JPWORK.Work2
= (unsigned int*)Work2Area;
080
JPWORK.Work2Len
= (int)WORK2LENGTH;
081
JPINFO.Video
= &JPVIDEO;
082
JPVIDEO.VRAMAddress
= (unsigned char*)&tgaFile1[20];
083
JPVIDEO.VRAMWidth
= VRAM_WIDTH;
084
JPVIDEO.VRAMHeight
= VRAM_HEIGHT;
085
JPVIDEO.VRAMPixel
= VRAM_PIXEL;
086
JPVIDEO.VRAMLine
= VRAM_LINE;
087
JPVIDEO.VRAMGap0
= 0;
088
JPVIDEO.VRAMGap1
= VRAM_GAP1;
089
JPVIDEO.VRAMGap2
= VRAM_GAP2;
090
JPVIDEO.ClipStartX
= 0;
091
JPVIDEO.ClipStartY
= 0;
092
JPVIDEO.ClipWidth
= 0x7FFFFFFF;
093
JPVIDEO.ClipHeight
= 0x7FFFFFFF;
094
095
ret = JPEGEXdecode(&JPINFO);
096
if(ret == JPEGEXDecodeStatusComplete){
097
/* normal ending */
098
return;
099
}
100
if(ret == JPEGEXDecodeStatusError){
101
/* unusual ending */
102
return;
103
}
104
if(ret == JPEGEXDecodeStatusTerminate){
105
/* The compulsion ending */
106
return;
107
}
108
if(ret == JPEGEXDecodeStatusNotRunning){
109
/* The object is not running */
110
return;
111
112
}
}
113
114
115
void JPEGEXGetJpegStream(struct JPEGEXBUFF* JPBUFF)
116
{
User’s Manual U10684EJ3V0UM
199
APPENDIX A SAMPLE PROGRAM SOURCE LIST
117
int i;
118
119
for(i = 0; i<TMP_BUFSIZE; i++){
120
jpegtmp[i] = *jpegptr++;
121
}
122
JPBUFF->JPEGBUFF = jpegtmp;
123
124
JPBUFF->JPEGBUFFLEN = TMP_BUFSIZE;
}
125
126
/****************
127
*
128
*****************/
129
void fillMem( unsigned char * dst, signed long size )
130
{
131
for( ; size > 0; size-- ) {
FillMem
*
132
*dst = 0x00;
133
dst++;
134
}
135
136
137
return;
}
138
139
/****************
140
*
141
****************/
142
void tga_head( unsigned char * tga )
143
{
144
VRAM2TGA
*
signed short
width, height;
145
146
width
147
height = (signed short)VRAM_HEIGHT;
148
*(tga +
0) = 0;
149
*(tga +
1) = 0;
150
*(tga +
2) = 2;
151
*(tga +
3) = 0;
152
*(tga +
4) = 0;
153
*(tga +
5) = 0;
154
*(tga +
6) = 0;
155
*(tga +
7) = 0;
156
*(tga +
8) = 0;
157
*(tga +
9) = 0;
158
*(tga + 10) = 0;
159
*(tga + 11) = 0;
160
*(tga + 12) = (unsigned char)(width & 0xFF);
161
*(tga + 13) = (unsigned char)((width >> 8) & 0xFF);
162
*(tga + 14) = (unsigned char)(height & 0xFF);
163
*(tga + 15) = (unsigned char)((height >> 8) & 0xFF);
164
*(tga + 16) = 24;
165
*(tga + 17) = 0x20;
166
200
= (signed short)VRAM_WIDTH;
}
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
A.3
Sample Program for Basic Compression and Additional Decompression
The sample program source list shown later only indicates an example when the program is executed with the
settings in Tables A-5 and A-6.
Table A-5. Compression Settings (1)
Item
Image memory
(VRAM)
JPEG compression
information 1
JPEG compression
information 2
(JPEG unique setting)
JPEG storage
memory
Library work
Structure Member
Set Value
Description
VRAM_Bptr
& (vramArea [2] )
Image memory: uchar vramAre []
VRAM_W_Pixel
320
Image size: 320 [W] × 240 [H]
VRAM_H_Pixel
240
Coordinate position: (0, 0) to (319, 239)
VRAM_Line_Byte
1280
VRAM_Pixel_Byte
4
VRAM_Gap1_Byte
−1
VRAM_Gap2_Byte
−2
Image storage sequence:Left to right and top
to bottom
Color space: 24-bit RGB
Pixel format: B, G, R, reserve, in that order
B = G = R = rev = 1 [byte]
Mode
JPEGMODE_NORMAL
Operation mode: Normal compression
Width
320
Image size: 320 [W] × 240 [H]
Height
240
StartX
0
StartY
0
CI1
0x01
ID of component 1: 0x01
CI2
0x02
ID of component 2: 0x02
CI3
0x03
ID of component 3: 0x03
Quality
75
Quality parameter: 75
Sampling
JPEGSAMPLE21
Sample ratio: 4:2:2 (H:V = 2:1)
DQT_Y_Bptr
& (jpeg_DQT_Y [0] )
Quantization table: Library default
DQT_C_Bptr
& (jpeg_DQT_C [0] )
DHT_DC_Y_Bptr
& (jpeg_DHT_DC_Y [0] )
DHT_DC_C_Bptr
& (jpeg_DHT_DC_C [0] )
DHT_AC_Y_Bptr
& (jpeg_DHT_AC_Y [0] )
DHT_AC_C_Bptr
& (jpeg_DHT_AC_C [0] )
Restart
0
RSTm marker: Not inserted
DNL
JPEGDNL_OFF
DNL marker: Not inserted
APP_Info_Bptr
0
APPn marker: Not inserted
JPEG_Buff_Bptr
& (jpegBuff [0] )
JPEG file storage buffer
JPEG_Buff_Eptr
& (jpegBuff [0] ) +0x8000
MCU_Buff_Bptr
& (mcuBuff [0] [0] )
MCU buffer
Work1_Bptr
& (work1Buff [0] )
Library work 1
Work2_Bptr
& (work2Buff [0] )
Library work 2
JPEGINFO structure variables
jpegInfo
Position of program supported
L101 to L211
User’s Manual U10684EJ3V0UM
Coordinate position: (0, 0) to (319, 239)
Huffman table: Library default
201
APPENDIX A SAMPLE PROGRAM SOURCE LIST
Table A-6. Compression Settings (2)
Item
Structure Member
JPEG decompression
information
(JPEGEXINFO
structure, variable:
JPINFO)
Mode
Policy
Set Value
JPEGEXModeStart
JPEGEXLuminanceOutOnly
Description
Operation mode: Normal decompression
Option for decompression:
 JPEGEXPutMCURGB
Drawing for each luminance component
 JPEGEX2passEnable
RGB output
Two-pass mode decompression
Library work
(JPEGEXWORK
structure, variable:
JPWORk)
Image memory (VRAM)
(JPEGEXVIDEO
structure, variable:
JPVIDEO)
JPEG storage memory
(JPEGEXBUFF
structure, variable:
JPBUFF)
Work
&JPWORK
struct JPEGEXWORK JPWORK
Video
&JPVIDEO
struct JPEGEXVIDEO JPVIDEO
Work1
Work1Area
Work area 1: int Work1Area [0x40]
Work1Len
0x100
Work2
Work2Area
Work2Len
0x2000
Work area 2: int Work2Area [0x800]
VRAMAddress
&tgaFile1 [2]
VRAM: unsigned char tgaFile1 []
VRAMWidth
320
VRAM size: 320 [W] × 240 [H]
VRAMHeight
240
Coordinate position: (0, 0) to (319,239)
VRAMPixel
4
Image storage sequence: Left to right and top to
VRAMLine
1280
VRAMGap0
0
VRAMGap1
−1
VRAMGap2
−2
ClipStartX
0
ClipStartY
0
ClipWidth
0x7FFFFFFF
ClipHeight
0x7FFFFFFF
JPEGBUFF
&jpegFile1 [0]
JPEGBUFFLEN
0x00008000
Position of program supported
bottom
Color space: 24-bit RGB
Pixel format: B, G, R, reserve, in that order
B = G = R = rev = 1 [byte]
No clipping (dummy value is set)
JPEG file storage buffer: unsigned char
jpegFile1 [0x8000]
L213 to L272
001
/****************************************************************/
002
/*
Copyright (C) NEC Corporation 1995,2002
*/
003
/*
NEC CONFIDENTIAL AND PROPRIETARY
*/
004
/*
All rights reserved by NEC Corporation.
*/
005
/*
Use of copyright notice does not evidence publication
*/
006
/****************************************************************/
007
008
/****************************************************************/
009
/*
010
/****************************************************************/
011
/*
012
#include
"jpeg.h"
013
#include
"sample.h"
014
/*
202
Include Header File
base
ex
*/
*/
*/
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
015
#include
"jpegex.h"
016
017
/****************************************************************/
018
/*
019
/****************************************************************/
020
#define
DEF_QUALITY
75
021
#define
DEF_SAMPLE
(JPEGSAMPLE11)
022
#define
DEF_RST
0
024
#define
TGA_FILE_SIZE
(DEF_VRAM_SIZE + 18)
025
#define
JPEG_FILE_SIZE
0x00010000
026
#define
JPEG_WORK1_SIZE
0x00000100
027
#define
JPEG_WORK2_SIZE
0x00002000
028
#define
JPEG_BUFF_SIZE
0x00008000
Definition Constant
*/
023
029
030
/****************************************************************/
031
/*
032
/****************************************************************/
033
/* None */
Definition Type & Struct
*/
034
035
/****************************************************************/
036
/*
037
/****************************************************************/
038
/* None */
Definition Macro
*/
039
040
/****************************************************************/
041
/*
042
/****************************************************************/
043
/*
044
JPEGINFO
jpegInfo;
045
APPINFO
appInfo;
046
/*
047
struct
JPEGEXINFO JPINFO;
048
struct
JPEGEXWORK JPWORK;
049
struct
JPEGEXVIDEO JPVIDEO;
051
S32
work1Buff[B2W(JPEG_WORK1_SIZE)];
052
S32
work2Buff[B2W(JPEG_WORK2_SIZE)];
053
S16
mcuBuff[6][64];
054
U08
jpegBuff[JPEG_BUFF_SIZE];
055
U08
vramArea[DEF_VRAM_SIZE];
/* VRAM Area
*/
056
U08
tgaFile0[TGA_FILE_SIZE];
/* DownLoad 1
*/
057
U08
tgaFile1[TGA_FILE_SIZE];
/* UpLoad 2,4
*/
058
U08
jpegFile1[JPEG_FILE_SIZE];
/* UpLoad 1,3
*/
059
VRAMINFO
vramInfo;
060
RECT
imgRect;
Definition Global(External) Variable
base
ex
*/
*/
*/
050
061
062
/****************************************************************/
063
/*
064
/****************************************************************/
065
/*
base
066
S32
tp01( void );
Definition Global(External) Function
*/
*/
User’s Manual U10684EJ3V0UM
203
APPENDIX A SAMPLE PROGRAM SOURCE LIST
067
S32
tpCompress( PJPEGINFO, PU08, PRECT );
068
void
InitApplication( void );
069
/*
ex
070
void
jd_proc(void);
071
void
JPEGEXGetJpegStream(struct JPEGEXBUFF*);
*/
072
073
/****************************************************************/
074
/*
075
/****************************************************************/
076
/****************************************************************/
077
/*
078
/****************************************************************/
079
void
080
{
081
Function
*/
main
*/
main( void )
S32
err;
082
083
InitApplication();
084
err = RET_OK;
085
/* ----------------------------------------------------*/
086
/* Stop!
*/
087
/* DownLoad "FISH.TGA" -> "tgaFile0"
*/
088
/* ----------------------------------------------------*/
089
err |= tp01();
/* JPEG Compress
090
jd_proc();
/* JPEG Decompress ex
091
/* ----------------------------------------------------*/
092
/* Stop!
*/
093
/* Check "err" = RET_OK -> OK
*/
094
/* UpLoad "jpegFile1"->"FISH??R1.JPG"(result tp01)
*/
095
/* UpLoad "tgaFile1 "->"FISH??R2.TGA"(result jd_proc)
*/
096
/* ----------------------------------------------------*/
base
*/
*/
097
098
099
return;
}
100
101
/****************************************************************/
102
/*
103
/****************************************************************/
104
S32
105
{
tp01
*/
tp01( void )
106
imgRect.X
= 0;
107
imgRect.Y
= 0;
108
imgRect.W
= vramInfo.imgWidth;
109
imgRect.H
= vramInfo.imgHeight;
110
fillVRAM( &vramInfo, &imgRect );
111
TGA2VRAM( &vramInfo, &imgRect, &(tgaFile0[0]) );
112
113
fillMem( (PU08)(&jpegInfo), sizeof(JPEGINFO) );
114
jpegInfo.Quality
= DEF_QUALITY;
115
jpegInfo.Sampling
= DEF_SAMPLE;
116
jpegInfo.Restart
= DEF_RST;
117
jpegInfo.Width
= imgRect.W;
118
jpegInfo.Height
= imgRect.H;
204
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
119
jpegInfo.StartX
= imgRect.X;
120
jpegInfo.StartY
= imgRect.Y;
121
jpegInfo.VRAM_Bptr
= vramInfo.Bp;
122
jpegInfo.VRAM_W_Pixel
= vramInfo.imgWidth;
123
jpegInfo.VRAM_H_Pixel
= vramInfo.imgHeight;
124
jpegInfo.VRAM_Line_Byte
= vramInfo.ByteLine;
125
jpegInfo.VRAM_Pixel_Byte
= vramInfo.BytePixel;
126
jpegInfo.VRAM_Gap1_Byte
= vramInfo.ByteGap1;
127
jpegInfo.VRAM_Gap2_Byte
= vramInfo.ByteGap2;
128
jpegInfo.JPEG_Buff_Bptr
= &(jpegBuff[0]);
129
jpegInfo.JPEG_Buff_Eptr
= jpegInfo.JPEG_Buff_Bptr + JPEG_BUFF_SIZE;
130
jpegInfo.MCU_Buff_Bptr
= &(mcuBuff[0][0]);
131
jpegInfo.DQT_Y_Bptr
= jpeg_DQT_Y;
132
jpegInfo.DQT_C_Bptr
= jpeg_DQT_C;
133
jpegInfo.DHT_DC_Y_Bptr
= jpeg_DHT_DC_Y;
134
jpegInfo.DHT_DC_C_Bptr
= jpeg_DHT_DC_C;
135
jpegInfo.DHT_AC_Y_Bptr
= jpeg_DHT_AC_Y;
136
jpegInfo.DHT_AC_C_Bptr
= jpeg_DHT_AC_C;
137
jpegInfo.APP_Info_Bptr
= 0;
138
jpegInfo.Work1_Bptr
= &(work1Buff[0]);
139
jpegInfo.Work2_Bptr
= &(work2Buff[0]);
140
jpegInfo.Mode
= JPEGMODE_NORMAL;
141
jpegInfo.DNL
= JPEGDNL_OFF;
142
jpegInfo.CI1
= 0x01;
143
jpegInfo.CI2
= 0x02;
144
jpegInfo.CI3
= 0x03;
145
146
147
return( tpCompress( &jpegInfo, &(jpegFile1[0]), &imgRect ) );
}
148
149
/****************************************************************/
150
/*
151
/****************************************************************/
152
S32
153
{
154
tpCompress
*/
tpCompress( PJPEGINFO info, PU08 file, PRECT rect )
S32
size;
155
156
size = 0;
157
jpeg_CompressInit( info );
158
for( ; ; ) {
159
switch( jpeg_Compress( info ) ) {
160
case JPEGRET_OK:
161
size = info->FileSize - size;
162
copyMem( info->JPEG_Buff_Bptr, file, size );
163
return( RET_OK );
164
case JPEGRET_CONT1:
165
size = info->FileSize - size;
166
copyMem( info->JPEG_Buff_Bptr, file, size );
167
file += size;
168
size = info->FileSize;
169
break;
170
case JPEGRET_CONT2:
User’s Manual U10684EJ3V0UM
205
APPENDIX A SAMPLE PROGRAM SOURCE LIST
171
if( info->Mode != JPEGMODE_MCULINE ) {
172
return( RET_ERR );
173
}
174
info->StartX =
175
if( (info->Sampling & JPEGSAMPLEMONO) == 0 ) {
176
info->StartY += JPEGGET_MCUV( info->Sampling );
177
} else {
178
info->StartY += 8;
179
}
180
break;
181
case JPEGRET_ERR:
182
return( RET_ERR );
183
default:
184
return( RET_ERR );
185
}
186
}
187
return( RET_ERR );
188
rect->X;
}
189
190
/****************************************************************/
191
/*
192
/****************************************************************/
193
void
194
{
195
#if
Init Application
*/
InitApplication( void )
1
196
vramInfo.Bp
= DEF_VRAM_BP;
197
vramInfo.Ep
= (PU08)(vramInfo.Bp + DEF_VRAM_SIZE);
vramInfo.Bp
= &(vramArea[0]);
vramInfo.Ep
= &(vramArea[0]) + DEF_VRAM_SIZE;
202
vramInfo.imgWidth
= DEF_VRAM_W;
203
vramInfo.imgHeight
= DEF_VRAM_H;
204
vramInfo.ByteLine
= DEF_VRAM_LINE;
205
vramInfo.BytePixel
= DEF_VRAM_PIXEL;
206
vramInfo.ByteGap1
= DEF_VRAM_GAP1;
207
vramInfo.ByteGap2
= DEF_VRAM_GAP2;
208
vramInfo.ColorType
= DEF_VRAM_COLOR;
198
#else
199
200
201
#endif
209
210
211
return;
}
212
213
/****************************************************************/
214
/*
215
/****************************************************************/
216
void jd_proc(void)
217
{
218
jd_proc
*/
int ret;
219
220
fillMem( &tgaFile1[0], (signed long)(TGA_FILE_SIZE) );
221
222
206
/* jpeg decompress parameter */
User’s Manual U10684EJ3V0UM
APPENDIX A SAMPLE PROGRAM SOURCE LIST
223
JPINFO.Mode
= JPEGEXModeStart;
224
JPINFO.Policy
= JPEGEXLuminanceOutOnly | JPEGEXPutMCURGB;
225
JPINFO.Policy
|= JPEGEX2passEnable;
226
JPINFO.Work
= &JPWORK;
227
JPWORK.Work1
= (unsigned int*)work1Buff;
228
JPWORK.Work1Len
= (int)JPEG_WORK1_SIZE;
229
JPWORK.Work2
= (unsigned int*)work2Buff;
230
JPWORK.Work2Len
= (int)work2Buff;
231
JPINFO.Video
= &JPVIDEO;
232
JPVIDEO.VRAMAddress
= (unsigned char*)&tgaFile1[2];
233
JPVIDEO.VRAMWidth
= DEF_VRAM_W;
234
JPVIDEO.VRAMHeight
= DEF_VRAM_H;
235
JPVIDEO.VRAMPixel
= DEF_VRAM_PIXEL;
236
JPVIDEO.VRAMLine
= DEF_VRAM_LINE;
237
JPVIDEO.VRAMGap0
= 0;
238
JPVIDEO.VRAMGap1
= DEF_VRAM_GAP1;
239
JPVIDEO.VRAMGap2
= DEF_VRAM_GAP2;
240
JPVIDEO.ClipStartX
= 0;
241
JPVIDEO.ClipStartY
= 0;
242
JPVIDEO.ClipWidth
= 0x7FFFFFFF;
243
JPVIDEO.ClipHeight
= 0x7FFFFFFF;
244
245
ret = JPEGEXdecode(&JPINFO);
246
if(ret == JPEGEXDecodeStatusComplete){
247
/* normal ending */
248
VRAM2TGA( &vramInfo, &imgRect, &(tgaFile1[0]) );
249
return;
250
}
251
if(ret == JPEGEXDecodeStatusError){
252
/* unusual ending */
253
return;
254
}
255
if(ret == JPEGEXDecodeStatusTerminate){
256
/* The compulsion ending */
257
return;
258
}
259
if(ret == JPEGEXDecodeStatusNotRunning){
260
/* The object is not running */
261
return;
262
263
}
}
264
265
/****************************************************************/
266
/*
267
/****************************************************************/
268
void JPEGEXGetJpegStream(struct JPEGEXBUFF* JPBUFF)
269
{
JPEGEXGetJpegStream
*/
270
JPBUFF->JPEGBUFF = jpegFile1;
271
JPBUFF->JPEGBUFFLEN = JPEG_FILE_SIZE;
272
}
User’s Manual U10684EJ3V0UM
207
APPENDIX B INDEX
2passEnable .......................................................... 156
DHT_AC_C_Bptr ................................................... 117
DHT_AC_Y_Bptr ................................................... 116
[A]
DHT_DC_C_Bptr ................................................... 116
Actuality of DCT/reverse DCT .................................. 42
DHT_DC_Y_Bptr ................................................... 116
Additional decompression ...................................... 139
Differences between basic library
Additional decompression flow............................... 140
and additional library................................................ 47
Additional decompression sample program ........... 197
DNL ....................................................................... 118
Additional library structure...................................... 150
DNL marker ............................................................. 86
Advanced customization ........................................ 176
DQT marker ............................................................. 34
Analysis........................................................ 54, 73, 85
DQT_C_Bptr .......................................................... 116
APP_Info_Bptr ....................................................... 117
DQT_Y_Bptr .......................................................... 116
APPn marker................................................ 31, 36, 84
DRI marker .............................................................. 38
[B]
[E]
Basic library reference............................................ 107
Entropy encoding..................................................... 25
Basic library sample program................................. 184
EOI marker .............................................................. 34
Basic library selection ............................................ 131
Errors during additional decompression ................ 170
Basic library specifications ....................................... 54
ErrorState ...................................................... 109, 163
BitStuffCheck ......................................................... 155
Execution procedure of sample program ............... 178
ByteStuffDisable..................................................... 156
ByteStuffEnable ..................................................... 156
[F]
Features of basic library .......................................... 44
[C]
Features of basic/additional library .......................... 44
CI1, CI2, CI3 .......................................................... 119
FileSize.................................................................. 109
Clipping .................................................................... 46
Function................................................................. 123
Color and monochrome............................................ 45
Color element........................................................... 46
[H]
Color space ............................................................ 135
Header..................................................................... 32
Component ID .......................................................... 45
Height .................................................................... 112
Compression ................................................ 52, 55, 84
Huffman decoding.................................................... 39
Configuration of VRAM............................................. 89
Huffman table .......................................................... 44
Constants ............................................................... 121
Huffman table initialization ....................................... 40
CurrentX................................................................. 113
CurrentY................................................................. 113
[I]
Customize function................................................. 143
Inf........................................................................... 163
Customizing additional library ................................ 176
Installation ............................................................. 178
Customizing basic library ......................................... 97
Installation procedure ............................................ 178
[D]
[J]
Data ......................................................................... 39
JPEG ....................................................................... 16
DCT.......................................................................... 22
JPEG file format....................................................... 32
Decoding of AC coefficient ....................................... 41
JPEG file storage buffer..................................... 45, 46
Decompression ............................................ 54, 64, 85
JPEG format ............................................................ 79
Details of data type ................................................ 107
jpeg_Analysis .................................................. 74, 129
Details of processing................................................ 55
jpeg_AnalysisInit.............................................. 73, 128
DHT marker........................................................ 35, 80
JPEGBUFF ............................................................ 168
208
User’s Manual U10684EJ3V0UM
APPENDIX B INDEX
JPEG_Buff_Bptr..................................................... 115
Outline of sample program of additional library ..... 180
JPEG_Buff_Cptr..................................................... 119
Outline of system ..................................................... 44
JPEG_Buff_Eptr..................................................... 115
Overview of JPEG ................................................... 17
JPEGBUFFLEN ..................................................... 168
jpeg_Compress ................................................ 56, 124
[P]
jpeg_CompressInit ........................................... 55, 124
Package contents .................................................... 48
jpeg_Decompress ............................................ 65, 126
Policy ..................................................................... 152
jpeg_DecompressInit ....................................... 64, 125
Progressive supporting additional library
JPEGEXBUFF structure......................................... 168
specifications ......................................................... 133
JPEGEXGetJpegStream ........................................ 143
PutMCURBG ......................................................... 162
JPEGEXINFO structure ......................................... 150
[Q]
JPEGEXMCUSTR structure................................... 169
JPEGEXVIDEO structure....................................... 164
Quality ................................................................... 109
JPEGEXVSyncWait................................................ 146
Quantization ............................................................ 24
JPEGEXWORK structure ....................................... 163
Quantization table.................................................... 44
JPEGEXWarning.................................................... 145
[R]
JPEGEXdecode ..................................................... 139
JPEGEXdecodeAPP .............................................. 144
JPEGEXpset .......................................................... 149
JPEGEXputMCU.................................................... 147
jpeg_getMCU_11 ................................................... 125
jpeg_getMCU_21 ................................................... 125
jpeg_getMCU_22 ................................................... 125
jpeg_getMCU_41 ................................................... 125
jpeg_getMCU_M .................................................... 125
jpeg_putMCU_11 ................................................... 127
jpeg_putMCU_21 ................................................... 127
jpeg_putMCU_22 ................................................... 127
jpeg_putMCU_41 ................................................... 127
jpeg_putMCU_M .................................................... 127
[L]
ratio........................................................................ 163
Restart................................................................... 111
Restart marker................................................... 28, 45
Reverse quantization ............................................... 42
RGB_Buff_Bptr ...................................................... 115
RSTm marker .......................................................... 38
[S]
Sample program for basic compression
and additional decompression ............................... 201
Sample program outline for additional library......... 180
Sample program outline for basic
library/additional library.......................................... 182
Sampling.......................................................... 19, 111
Sampling ratio.................................................... 45, 46
Library discontinuation ............................................. 46
Line processing ........................................................ 45
List of additional library constants .......................... 173
Sampling ratio and block........................................ 101
Section........................................................... 130, 137
Selecting basic library............................................ 131
Simple customization............................................. 176
[M]
SOFn marker ........................................................... 37
MCU ......................................................................... 19
SOI marker .............................................................. 34
MCU buffer ............................................................. 102
SOS marker ............................................................. 38
MCU_Buff_Bptr ...................................................... 115
StartX .................................................................... 112
Middleware............................................................... 16
StartY .................................................................... 113
Mode .............................................................. 118, 150
Structure of APPINFO structure ............................ 120
Structure of JPEGINFO structure .......................... 107
[O]
Structure of MCU buffer ........................................... 93
One point to assembler coding............................... 105
Supporting monochrome format .............................. 87
Operating environment............................................. 51
Supporting non-interleave format ............................ 46
Option for additional decompression ...................... 136
Symbol name conventions............................. 130, 137
OS support............................................................... 45
User’s Manual U10684EJ3V0UM
209
APPENDIX B INDEX
[T]
VRAM_Line_Byte ...................................................114
VRAM_Pixel_Byte ..................................................114
TaskID............................................................ 150, 168
VRAM_W_Pixel ......................................................114
[U]
[W]
UseExPutMCU....................................................... 162
Warning messages output during
User ....................................................................... 119
additional decompression.......................................172
Width ......................................................................112
[V]
Work .......................................................................163
Video...................................................................... 163
Work1_Bptr ............................................................117
VideoOutLastOnly.................................................. 153
Work2_Bptr ............................................................117
VideoZoomLinear................................................... 162
Work3 .....................................................................119
VideoZoomNormal................................................. 162
[Y]
VRAM access function for decompression............. 104
VRAM access functions for compression............... 103
YCbCr/RGB ..............................................................18
VRAM and coordinates ............................................ 99
YCCK format ..........................................................135
VRAM_Bptr ............................................................ 113
[Z]
VRAM_Gap1_Byte................................................. 114
VRAM_Gap2_Byte................................................. 115
VRAM_H_Pixel ...................................................... 114
210
Zigzag scan ..............................................................24
Zooming out/in during decompression .....................46
User’s Manual U10684EJ3V0UM
Facsimile Message
From:
Name
Company
Tel.
Although NEC has taken all possible steps
to ensure that the documentation supplied
to our customers is complete, bug free
and up-to-date, we readily accept that
errors may occur. Despite all the care and
precautions we've taken, you may
encounter problems in the documentation.
Please complete this form whenever
you'd like to report errors or suggest
improvements to us.
FAX
Address
Thank you for your kind support.
North America
Hong Kong, Philippines, Oceania
NEC Electronics Inc.
NEC Electronics Hong Kong Ltd.
Corporate Communications Dept. Fax: +852-2886-9022/9044
Fax: +1-800-729-9288
+1-408-588-6130
Korea
Europe
NEC Electronics Hong Kong Ltd.
NEC Electronics (Europe) GmbH
Seoul Branch
Market Communication Dept.
Fax: +82-2-528-4411
Fax: +49-211-6503-274
Taiwan
NEC Electronics Taiwan Ltd.
Fax: +886-2-2719-5951
South America
NEC do Brasil S.A.
Fax: +55-11-6462-6829
Japan
NEC Semiconductor Technical Hotline
Fax: +81- 44-435-9608
P.R. China
NEC Electronics Shanghai, Ltd.
Fax: +86-21-6841-1137
Asian Nations except Philippines
NEC Electronics Singapore Pte. Ltd.
Fax: +65-250-3583
I would like to report the following error/make the following suggestion:
Document title:
Document number:
Page number:
If possible, please fax the referenced page or drawing.
Document Rating
Excellent
Good
Acceptable
Poor
Clarity
Technical Accuracy
Organization
CS 02.3