OpenCores
URL https://opencores.org/ocsvn/jpeg/jpeg/trunk

Subversion Repositories jpeg

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 4 to Rev 5
    Reverse comparison

Rev 4 → Rev 5

/trunk/cores/q_rom.xco File deleted
/trunk/cores/q_rom.xcp File deleted
/trunk/cores/huff_rom.coe File deleted \ No newline at end of file
/trunk/cores/q_rom.edn File deleted
/trunk/cores/dct2d.xco File deleted
/trunk/cores/dct2d.xcp File deleted
/trunk/cores/q_rom.vhd File deleted
/trunk/cores/dct2d.edn File deleted
/trunk/cores/tabla_q.coe File deleted \ No newline at end of file
/trunk/cores/q_rom.vho File deleted
/trunk/cores/buffer_img.coe File deleted \ No newline at end of file
/trunk/cores/dct2d.vhd File deleted
/trunk/cores/q_rom.coe File deleted \ No newline at end of file
/trunk/cores/q_rom.mif File deleted
/trunk/cores/dct2d.vho File deleted
/trunk/gpl.txt
0,0 → 1,674
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
 
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
 
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
 
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
 
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
 
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
 
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
 
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
 
The precise terms and conditions for copying, distribution and
modification follow.
 
TERMS AND CONDITIONS
 
0. Definitions.
 
"This License" refers to version 3 of the GNU General Public License.
 
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
 
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
 
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
 
A "covered work" means either the unmodified Program or a work based
on the Program.
 
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
 
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
 
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
 
1. Source Code.
 
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
 
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
 
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
 
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
 
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
 
The Corresponding Source for a work in source code form is that
same work.
 
2. Basic Permissions.
 
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
 
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
 
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
 
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
 
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
 
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
 
4. Conveying Verbatim Copies.
 
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
 
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
 
5. Conveying Modified Source Versions.
 
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
 
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
 
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
 
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
 
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
 
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
 
6. Conveying Non-Source Forms.
 
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
 
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
 
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
 
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
 
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
 
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
 
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
 
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
 
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
 
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
 
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
 
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
 
7. Additional Terms.
 
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
 
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
 
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
 
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
 
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
 
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
 
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
 
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
 
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
 
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
 
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
 
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
 
8. Termination.
 
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
 
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
 
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
 
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
 
9. Acceptance Not Required for Having Copies.
 
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
 
10. Automatic Licensing of Downstream Recipients.
 
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
 
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
 
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
 
11. Patents.
 
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
 
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
 
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
 
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
 
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
 
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
 
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
 
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
 
12. No Surrender of Others' Freedom.
 
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
 
13. Use with the GNU Affero General Public License.
 
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
 
14. Revised Versions of this License.
 
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
 
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
 
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
 
15. Disclaimer of Warranty.
 
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
 
16. Limitation of Liability.
 
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
 
17. Interpretation of Sections 15 and 16.
 
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
 
END OF TERMS AND CONDITIONS
 
How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
 
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
 
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
 
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
/trunk/compressor_tb.vhd
0,0 → 1,250
---------------------------------------------------------------------------------------------------
--
-- Title : JPEG Hardware Compressor Testbench
-- Design : jpeg
-- Author : Victor Lopez Lorenzo
-- E-mail : victor.lopez ((at)) ono ((dot)) com
--
-- License : GPLv3 (only for NON-COMMERCIAL purposes)
--
---------------------------------------------------------------------------------------------------
--
--
-- Copyright (C) 2004 Victor Lopez Lorenzo
--
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
--
---------------------------------------------------------------------------------------------------
--
-- It is the compressor.vhd itself the one who writes the image.jpg output file
-- when simulated with this testbench.
--
---------------------------------------------------------------------------------------------------
 
library ieee,xilinxcorelib,unisim;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
 
 
entity compressor_tb is
end compressor_tb;
 
architecture TB_ARCHITECTURE of compressor_tb is
component compressor
port(
clk : in std_logic;
reset : in std_logic;
CompressImage : in std_logic; --must be active high for just one cycle
Compression : in std_logic_vector(1 downto 0); --Quality: 00 = low, 01 = medium, 10 = high
Mono : in std_logic; --active high for grey-scale input image (Red=Green=Blue)
ImgColumns : in std_logic_vector(9 downto 0); --columns in each line of the image to compress
ImgLines : in std_logic_vector(8 downto 0); --lines of the image to compress
Compressing : out std_logic;
ProcessRGB : in std_logic;
ProcessingRGB : out std_logic;
Red : in std_logic_vector(7 downto 0);
Green : in std_logic_vector(7 downto 0);
Blue : in std_logic_vector(7 downto 0);
addr: out std_logic_VECTOR(15 downto 0);
din: out std_logic_VECTOR(7 downto 0);
we: out std_logic);
end component;
 
signal clk : std_logic;
signal reset : std_logic;
signal CompressImage : std_logic;
signal Compression : std_logic_vector(1 downto 0);
signal Mono : std_logic;
signal ImgColumns : std_logic_vector(9 downto 0);
signal ImgLines : std_logic_vector(8 downto 0);
signal ProcessRGB : std_logic;
signal Red : std_logic_vector(7 downto 0);
signal Green : std_logic_vector(7 downto 0);
signal Blue : std_logic_vector(7 downto 0);
 
signal Compressing : std_logic;
signal ProcessingRGB : std_logic;
signal addr : std_logic_vector(15 downto 0);
signal din : std_logic_vector(7 downto 0);
signal we : std_logic;
 
 
type ByteT is (c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,c30,c31,c32,c33,c34,c35,c36,c37,c38,c39,c40,c41,c42,c43,c44,c45,c46,c47,c48,c49,c50,c51,c52,c53,c54,c55,c56,c57,c58,c59,c60,c61,c62,c63,c64,c65,c66,c67,c68,c69,c70,c71,c72,c73,c74,c75,c76,c77,c78,c79,c80,c81,c82,c83,c84,c85,c86,c87,c88,c89,c90,c91,c92,c93,c94,c95,c96,c97,c98,c99,c100,c101,c102,c103,c104,c105,c106,c107,c108,c109,c110,c111,c112,c113,c114,c115,c116,c117,c118,c119,c120,c121,c122,c123,c124,c125,c126,c127,c128,c129,c130,c131,c132,c133,c134,c135,c136,c137,c138,c139,c140,c141,c142,c143,c144,c145,c146,c147,c148,c149,c150,c151,c152,c153,c154,c155,c156,c157,c158,c159,c160,c161,c162,c163,c164,c165,c166,c167,c168,c169,c170,c171,c172,c173,c174,c175,c176,c177,c178,c179,c180,c181,c182,c183,c184,c185,c186,c187,c188,c189,c190,c191,c192,c193,c194,c195,c196,c197,c198,c199,c200,c201,c202,c203,c204,c205,c206,c207,c208,c209,c210,c211,c212,c213,c214,c215,c216,c217,c218,c219,c220,c221,c222,c223,c224,c225,c226,c227,c228,c229,c230,c231,c232,c233,c234,c235,c236,c237,c238,c239,c240,c241,c242,c243,c244,c245,c246,c247,c248,c249,c250,c251,c252,c253,c254,c255);
subtype Byte is ByteT;
type ByteFileType is file of Byte;
file infile : ByteFileType open read_mode is "image.bmp";
 
-- integer to bit_vector conversion
function int2bit_vec(A: integer; SIZE: integer) return BIT_VECTOR is
variable RESULT: BIT_VECTOR(SIZE-1 downto 0);
variable TMP: integer;
begin
TMP:=A;
for i in 0 to SIZE-1 loop
if TMP mod 2 = 1 then RESULT(i):='1';
else RESULT(i):='0';
end if;
TMP:=TMP / 2;
end loop;
return RESULT;
end;
 
begin
 
UUT : compressor
port map (
clk => clk,
reset => reset,
CompressImage => CompressImage,
Compressing => Compressing,
Compression => Compression,
Mono => Mono,
ImgColumns => ImgColumns,
ImgLines => ImgLines,
ProcessRGB => ProcessRGB,
ProcessingRGB => ProcessingRGB,
Red => Red,
Green => Green,
Blue => Blue,
addr => addr,
din => din,
we => we
);
 
Clocket : process --40 MHz -> T = 25 ns
begin
clk <= '1';
wait for 12.5 ns;
clk <= '0';
wait for 12.5 ns;
end process;
 
reset <= '1', '0' after 20 ns;
CompressImage <= '1' , '0' after 45 ns;
 
Compression <= "10"; --"01"; --Medium Quality (Q ITU standard)
Mono <= '0';
Data : process(clk)
variable Clock_Up : std_logic := '1';
variable Prev_Proc : std_logic;
variable Bloque : std_logic_vector(511 downto 0) := X"30353A3E40404040353C3E41444141413B4045484341414144464745454444444445464747404040464646464542424247474648474242424747464648434343";
--in decimal it is 48535862646464645360626568656565596469726765656568707169696868686869707171646464707070706966666671717072716666667171707072676767
 
variable Line : std_logic_vector(8 downto 0);
variable Column : std_logic_vector(9 downto 0);
variable PixelIni : integer range 0 to 511;
variable Pixel : Byte;
variable Temp : std_logic_vector(7 downto 0);
variable JumpHeader : std_logic := '0';
variable FinImg : std_logic;
begin
if reset = '1' then
Red <= (others => '1');
Green <= (others => '1');
Blue <= (others => '1');
Prev_Proc := '1';
Pixelini := 0;
ProcessRGB <= '0';
FinImg := '0';
if JumpHeader = '0' then
for i in 0 to 53 loop
read(infile, Pixel);
case i is
when 18 => --1st byte of Width
Column(7 downto 0) := To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
when 19 => --2nd byte of Width
Temp := To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
Column(9 downto 8) := Temp(1 downto 0);
when 22 => --1st byte of Height
Line(7 downto 0) := To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
when 23 => --2nd byte of Height
Temp := To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
Line(8) := Temp(0);
when 24 => --we write to the Compressor the image dimensions
ImgColumns <= Column - 1; --remember for a 352x288 it is (0..351)x(0..287)
ImgLines <= Line - 1;
when others =>
null;
end case;
end loop;
JumpHeader := '1';
end if;
Line := (others => '0');
Column := (others => '0');
elsif (clk = '1' and clk'event) then
if Prev_Proc = '1' and ProcessingRGB = '0' then
--PixelIni := 511 - conv_integer(Line(2 downto 0))*64 - conv_integer(Column(2 downto 0))*8;
--511-504 503-496 495-488 487-480 479-472 471-464 463-456 455-448
read(infile,Pixel);
Blue <= To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
read(infile,Pixel);
Green <= To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
read(infile,Pixel);
Red <= To_Stdlogicvector(int2bit_vec(ByteT'pos(Pixel),8));
--Red <= Bloque(PixelIni downto PixelIni - 7);
--Green <= Bloque(PixelIni downto PixelIni - 7);
--Blue <= Bloque(PixelIni downto PixelIni - 7);
ProcessRGB <= '1';
if Column = ImgColumns then
Column := (others => '0');
if Line = ImgLines then
Line := (others => '0');
else
Line := Line + 1;
end if;
else
Column := Column + 1;
end if;
elsif ProcessingRGB = '1' then
ProcessRGB <= '0';
end if;
 
if FinImg = '0' then
Prev_Proc := ProcessingRGB;
else
Prev_Proc := '0'; --so that it doesn't send again the image
ProcessRGB <= '0'; --must be done here because in the last cycle, with Line=0 and Column=0 the last pixel is being sent!
File_Close(infile);
end if;
 
assert not (FinImg='1' and Compressing = '0')
report "Compression Completed"
severity FAILURE; --everything went fine, it's just to stop the simulation
if Line = 0 and Column = 0 then
FinImg := '1';
end if;
end if;
end process Data;
end TB_ARCHITECTURE;
 
configuration TESTBENCH_FOR_compressor of compressor_tb is
for TB_ARCHITECTURE
for UUT : compressor
use entity work.compressor(jpg);
end for;
end for;
end TESTBENCH_FOR_compressor;
 
/trunk/docs/itu-t81.pdf Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
trunk/docs/itu-t81.pdf Property changes : Deleted: svn:mime-type ## -1 +0,0 ## -application/octet-stream \ No newline at end of property Index: trunk/docs/bmp.txt =================================================================== --- trunk/docs/bmp.txt (revision 4) +++ trunk/docs/bmp.txt (nonexistent) @@ -1,1043 +0,0 @@ -Microsoft Windows Bitmap Format - - - -Note: the constants BI_RGB, BI_RLE8, and BI_RLE4 have the values 0, 1, and 2, - respectively. - -============================================================================= -Graphics File Formats - -This topic describes the graphics-file formats used by the Microsoft Windows -operating system. Graphics files include bitmap files, icon-resource files, -and cursor-resource files. - -Bitmap-File Formats - -Windows bitmap files are stored in a device-independent bitmap (DIB) format -that allows Windows to display the bitmap on any type of display device. The -term "device independent" means that the bitmap specifies pixel color in a -form independent of the method used by a display to represent color. The -default filename extension of a Windows DIB file is .BMP. - -Bitmap-File Structures - -Each bitmap file contains a bitmap-file header, a bitmap-information header, -a color table, and an array of bytes that defines the bitmap bits. The file -has the following form: - -BITMAPFILEHEADER bmfh; -BITMAPINFOHEADER bmih; -RGBQUAD aColors[]; -BYTE aBitmapBits[]; - -The bitmap-file header contains information about the type, size, and layout -of a device-independent bitmap file. The header is defined as a -BITMAPFILEHEADER structure. - -The bitmap-information header, defined as a BITMAPINFOHEADER structure, -specifies the dimensions, compression type, and color format for the bitmap. - -The color table, defined as an array of RGBQUAD structures, contains as many -elements as there are colors in the bitmap. The color table is not present -for bitmaps with 24 color bits because each pixel is represented by 24-bit -red-green-blue (RGB) values in the actual bitmap data area. The colors in the -table should appear in order of importance. This helps a display driver -render a bitmap on a device that cannot display as many colors as there are -in the bitmap. If the DIB is in Windows version 3.0 or later format, the -driver can use the biClrImportant member of the BITMAPINFOHEADER structure to -determine which colors are important. - -The BITMAPINFO structure can be used to represent a combined -bitmap-information header and color table. The bitmap bits, immediately -following the color table, consist of an array of BYTE values representing -consecutive rows, or "scan lines," of the bitmap. Each scan line consists of -consecutive bytes representing the pixels in the scan line, in left-to-right -order. The number of bytes representing a scan line depends on the color -format and the width, in pixels, of the bitmap. If necessary, a scan line -must be zero-padded to end on a 32-bit boundary. However, segment boundaries -can appear anywhere in the bitmap. The scan lines in the bitmap are stored -from bottom up. This means that the first byte in the array represents the -pixels in the lower-left corner of the bitmap and the last byte represents -the pixels in the upper-right corner. - -The biBitCount member of the BITMAPINFOHEADER structure determines the number -of bits that define each pixel and the maximum number of colors in the -bitmap. These members can have any of the following values: - -Value Meaning - -1 Bitmap is monochrome and the color table contains two entries. Each -bit in the bitmap array represents a pixel. If the bit is clear, the pixel is -displayed with the color of the first entry in the color table. If the bit is -set, the pixel has the color of the second entry in the table. - -4 Bitmap has a maximum of 16 colors. Each pixel in the bitmap is -represented by a 4-bit index into the color table. For example, if the first -byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel -contains the color in the second table entry, and the second pixel contains -the color in the sixteenth table entry. - -8 Bitmap has a maximum of 256 colors. Each pixel in the bitmap is -represented by a 1-byte index into the color table. For example, if the first -byte in the bitmap is 0x1F, the first pixel has the color of the -thirty-second table entry. - -24 Bitmap has a maximum of 2^24 colors. The bmiColors (or bmciColors) -member is NULL, and each 3-byte sequence in the bitmap array represents the -relative intensities of red, green, and blue, respectively, for a pixel. - -The biClrUsed member of the BITMAPINFOHEADER structure specifies the number -of color indexes in the color table actually used by the bitmap. If the -biClrUsed member is set to zero, the bitmap uses the maximum number of colors -corresponding to the value of the biBitCount member. An alternative form of -bitmap file uses the BITMAPCOREINFO, BITMAPCOREHEADER, and RGBTRIPLE -structures. - -Bitmap Compression - -Windows versions 3.0 and later support run-length encoded (RLE) formats for -compressing bitmaps that use 4 bits per pixel and 8 bits per pixel. -Compression reduces the disk and memory storage required for a bitmap. - -Compression of 8-Bits-per-Pixel Bitmaps - -When the biCompression member of the BITMAPINFOHEADER structure is set to -BI_RLE8, the DIB is compressed using a run-length encoded format for a -256-color bitmap. This format uses two modes: encoded mode and absolute mode. -Both modes can occur anywhere throughout a single bitmap. - -Encoded Mode - -A unit of information in encoded mode consists of two bytes. The first byte -specifies the number of consecutive pixels to be drawn using the color index -contained in the second byte. The first byte of the pair can be set to zero -to indicate an escape that denotes the end of a line, the end of the bitmap, -or a delta. The interpretation of the escape depends on the value of the -second byte of the pair, which must be in the range 0x00 through 0x02. -Following are the meanings of the escape values that can be used in the -second byte: - -Second byte Meaning - -0 End of line. -1 End of bitmap. -2 Delta. The two bytes following the escape contain unsigned values -indicating the horizontal and vertical offsets of the next pixel from the -current position. - -Absolute Mode - -Absolute mode is signaled by the first byte in the pair being set to zero and -the second byte to a value between 0x03 and 0xFF. The second byte represents -the number of bytes that follow, each of which contains the color index of a -single pixel. Each run must be aligned on a word boundary. Following is an -example of an 8-bit RLE bitmap (the two-digit hexadecimal values in the -second column represent a color index for a single pixel): - -Compressed data Expanded data - -03 04 04 04 04 -05 06 06 06 06 06 06 -00 03 45 56 67 00 45 56 67 -02 78 78 78 -00 02 05 01 Move 5 right and 1 down -02 78 78 78 -00 00 End of line -09 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E -00 01 End of RLE bitmap - -Compression of 4-Bits-per-Pixel Bitmaps - -When the biCompression member of the BITMAPINFOHEADER structure is set to -BI_RLE4, the DIB is compressed using a run-length encoded format for a -16-color bitmap. This format uses two modes: encoded mode and absolute mode. - -Encoded Mode - -A unit of information in encoded mode consists of two bytes. The first byte -of the pair contains the number of pixels to be drawn using the color indexes -in the second byte. - -The second byte contains two color indexes, one in its high-order nibble -(that is, its low-order 4 bits) and one in its low-order nibble. - -The first pixel is drawn using the color specified by the high-order nibble, -the second is drawn using the color in the low-order nibble, the third is -drawn with the color in the high-order nibble, and so on, until all the -pixels specified by the first byte have been drawn. - -The first byte of the pair can be set to zero to indicate an escape that -denotes the end of a line, the end of the bitmap, or a delta. The -interpretation of the escape depends on the value of the second byte of the -pair. In encoded mode, the second byte has a value in the range 0x00 through -0x02. The meaning of these values is the same as for a DIB with 8 bits per -pixel. - -Absolute Mode - -In absolute mode, the first byte contains zero, the second byte contains the -number of color indexes that follow, and subsequent bytes contain color -indexes in their high- and low-order nibbles, one color index for each pixel. -Each run must be aligned on a word boundary. - -Following is an example of a 4-bit RLE bitmap (the one-digit hexadecimal -values in the second column represent a color index for a single pixel): - -Compressed data Expanded data - -03 04 0 4 0 -05 06 0 6 0 6 0 -00 06 45 56 67 00 4 5 5 6 6 7 -04 78 7 8 7 8 -00 02 05 01 Move 5 right and 1 down -04 78 7 8 7 8 -00 00 End of line -09 1E 1 E 1 E 1 E 1 E 1 -00 01 End of RLE bitmap - -Bitmap Example - -The following example is a text dump of a 16-color bitmap (4 bits per pixel): - -Win3DIBFile - BitmapFileHeader - Type 19778 - Size 3118 - Reserved1 0 - Reserved2 0 - OffsetBits 118 - BitmapInfoHeader - Size 40 - Width 80 - Height 75 - Planes 1 - BitCount 4 - Compression 0 - SizeImage 3000 - - XPelsPerMeter 0 - YPelsPerMeter 0 - ColorsUsed 16 - ColorsImportant 16 - Win3ColorTable - Blue Green Red Unused -[00000000] 84 252 84 0 -[00000001] 252 252 84 0 -[00000002] 84 84 252 0 -[00000003] 252 84 252 0 -[00000004] 84 252 252 0 -[00000005] 252 252 252 0 -[00000006] 0 0 0 0 -[00000007] 168 0 0 0 -[00000008] 0 168 0 0 -[00000009] 168 168 0 0 -[0000000A] 0 0 168 0 -[0000000B] 168 0 168 0 -[0000000C] 0 168 168 0 -[0000000D] 168 168 168 0 -[0000000E] 84 84 84 0 -[0000000F] 252 84 84 0 - Image - . - . Bitmap data - . - -Icon-Resource File Format - -An icon-resource file contains image data for icons used by Windows -applications. The file consists of an icon directory identifying the number -and types of icon images in the file, plus one or more icon images. The -default filename extension for an icon-resource file is .ICO. - -Icon Directory - -Each icon-resource file starts with an icon directory. The icon directory, -defined as an ICONDIR structure, specifies the number of icons in the -resource and the dimensions and color format of each icon image. The ICONDIR -structure has the following form: - - - -typedef struct ICONDIR { - WORD idReserved; - WORD idType; - WORD idCount; - ICONDIRENTRY idEntries[1]; -} ICONHEADER; - -Following are the members in the ICONDIR structure: - -idReserved Reserved; must be zero. -idType Specifies the resource type. This member is set to 1. -idCount Specifies the number of entries in the directory. -idEntries Specifies an array of ICONDIRENTRY structures containing -information about individual icons. The idCount member specifies the number -of structures in the array. - -The ICONDIRENTRY structure specifies the dimensions and color format for an -icon. The structure has the following form: - - - -struct IconDirectoryEntry { - BYTE bWidth; - BYTE bHeight; - BYTE bColorCount; - BYTE bReserved; - WORD wPlanes; - WORD wBitCount; - DWORD dwBytesInRes; - DWORD dwImageOffset; -}; - -Following are the members in the ICONDIRENTRY structure: - -bWidth Specifies the width of the icon, in pixels. Acceptable values -are 16, 32, and 64. - -bHeight Specifies the height of the icon, in pixels. Acceptable -values are 16, 32, and 64. - -bColorCount Specifies the number of colors in the icon. Acceptable values -are 2, 8, and 16. - -bReserved Reserved; must be zero. -wPlanes Specifies the number of color planes in the icon bitmap. -wBitCount Specifies the number of bits in the icon bitmap. -dwBytesInRes Specifies the size of the resource, in bytes. -dwImageOffset Specifies the offset, in bytes, from the beginning of the -file to the icon image. - -Icon Image - -Each icon-resource file contains one icon image for each image identified in -the icon directory. An icon image consists of an icon-image header, a color -table, an XOR mask, and an AND mask. The icon image has the following form: - - - -BITMAPINFOHEADER icHeader; -RGBQUAD icColors[]; -BYTE icXOR[]; -BYTE icAND[]; - -The icon-image header, defined as a BITMAPINFOHEADER structure, specifies the -dimensions and color format of the icon bitmap. Only the biSize through -biBitCount members and the biSizeImage member are used. All other members -(such as biCompression and biClrImportant) must be set to zero. - -The color table, defined as an array of RGBQUAD structures, specifies the -colors used in the XOR mask. As with the color table in a bitmap file, the -biBitCount member in the icon-image header determines the number of elements -in the array. For more information about the color table, see Section 1.1, -"Bitmap-File Formats." - -The XOR mask, immediately following the color table, is an array of BYTE -values representing consecutive rows of a bitmap. The bitmap defines the -basic shape and color of the icon image. As with the bitmap bits in a bitmap -file, the bitmap data in an icon-resource file is organized in scan lines, -with each byte representing one or more pixels, as defined by the color -format. For more information about these bitmap bits, see Section 1.1, -"Bitmap-File Formats." - -The AND mask, immediately following the XOR mask, is an array of BYTE values, -representing a monochrome bitmap with the same width and height as the XOR -mask. The array is organized in scan lines, with each byte representing 8 -pixels. - -When Windows draws an icon, it uses the AND and XOR masks to combine the icon -image with the pixels already on the display surface. Windows first applies -the AND mask by using a bitwise AND operation; this preserves or removes -existing pixel color. Windows then applies the XOR mask by using a bitwise -XOR operation. This sets the final color for each pixel. - -The following illustration shows the XOR and AND masks that create a -monochrome icon (measuring 8 pixels by 8 pixels) in the form of an uppercase -K: - -Windows Icon Selection - -Windows detects the resolution of the current display and matches it against -the width and height specified for each version of the icon image. If Windows -determines that there is an exact match between an icon image and the current -device, it uses the matching image. Otherwise, it selects the closest match -and stretches the image to the proper size. - -If an icon-resource file contains more than one image for a particular -resolution, Windows uses the icon image that most closely matches the color -capabilities of the current display. If no image matches the device -capabilities exactly, Windows selects the image that has the greatest number -of colors without exceeding the number of display colors. If all images -exceed the color capabilities of the current display, Windows uses the icon -image with the least number of colors. - - - -Cursor-Resource File Format - -A cursor-resource file contains image data for cursors used by Windows -applications. The file consists of a cursor directory identifying the number -and types of cursor images in the file, plus one or more cursor images. The -default filename extension for a cursor-resource file is .CUR. - -Cursor Directory - -Each cursor-resource file starts with a cursor directory. The cursor -directory, defined as a CURSORDIR structure, specifies the number of cursors -in the file and the dimensions and color format of each cursor image. The -CURSORDIR structure has the following form: - - -typedef struct _CURSORDIR { - WORD cdReserved; - WORD cdType; - WORD cdCount; - CURSORDIRENTRY cdEntries[]; -} CURSORDIR; - -Following are the members in the CURSORDIR structure: - -cdReserved Reserved; must be zero. -cdType Specifies the resource type. This member must be set to 2. -cdCount Specifies the number of cursors in the file. -cdEntries Specifies an array of CURSORDIRENTRY structures containing -information about individual cursors. The cdCount member specifies the number -of structures in the array. - -A CURSORDIRENTRY structure specifies the dimensions and color format of a -cursor image. The structure has the following form: - - - -typedef struct _CURSORDIRENTRY { - BYTE bWidth; - BYTE bHeight; - BYTE bColorCount; - BYTE bReserved; - WORD wXHotspot; - WORD wYHotspot; - DWORD lBytesInRes; - DWORD dwImageOffset; -} CURSORDIRENTRY; - -Following are the members in the CURSORDIRENTRY structure: - -bWidth Specifies the width of the cursor, in pixels. -bHeight Specifies the height of the cursor, in pixels. -bColorCount Reserved; must be zero. -bReserved Reserved; must be zero. -wXHotspot Specifies the x-coordinate, in pixels, of the hot spot. -wYHotspot Specifies the y-coordinate, in pixels, of the hot spot. -lBytesInRes Specifies the size of the resource, in bytes. -dwImageOffset Specifies the offset, in bytes, from the start of the file to -the cursor image. - -Cursor Image - -Each cursor-resource file contains one cursor image for each image identified -in the cursor directory. A cursor image consists of a cursor-image header, a -color table, an XOR mask, and an AND mask. The cursor image has the following -form: - - - -BITMAPINFOHEADER crHeader; -RGBQUAD crColors[]; -BYTE crXOR[]; -BYTE crAND[]; - -The cursor hot spot is a single pixel in the cursor bitmap that Windows uses -to track the cursor. The crXHotspot and crYHotspot members specify the x- and -y-coordinates of the cursor hot spot. These coordinates are 16-bit integers. - -The cursor-image header, defined as a BITMAPINFOHEADER structure, specifies -the dimensions and color format of the cursor bitmap. Only the biSize through -biBitCount members and the biSizeImage member are used. The biHeight member -specifies the combined height of the XOR and AND masks for the cursor. This -value is twice the height of the XOR mask. The biPlanes and biBitCount -members must be 1. All other members (such as biCompression and -biClrImportant) must be set to zero. - -The color table, defined as an array of RGBQUAD structures, specifies the -colors used in the XOR mask. For a cursor image, the table contains exactly -two structures, since the biBitCount member in the cursor-image header is -always 1. - -The XOR mask, immediately following the color table, is an array of BYTE -values representing consecutive rows of a bitmap. The bitmap defines the -basic shape and color of the cursor image. As with the bitmap bits in a -bitmap file, the bitmap data in a cursor-resource file is organized in scan -lines, with each byte representing one or more pixels, as defined by the -color format. For more information about these bitmap bits, see Section 1.1, -"Bitmap-File Formats." - -The AND mask, immediately following the XOR mask, is an array of BYTE values -representing a monochrome bitmap with the same width and height as the XOR -mask. The array is organized in scan lines, with each byte representing 8 -pixels. - -When Windows draws a cursor, it uses the AND and XOR masks to combine the -cursor image with the pixels already on the display surface. Windows first -applies the AND mask by using a bitwise AND operation; this preserves or -removes existing pixel color. Window then applies the XOR mask by using a -bitwise XOR operation. This sets the final color for each pixel. - -The following illustration shows the XOR and the AND masks that create a -cursor (measuring 8 pixels by 8 pixels) in the form of an arrow: - -Following are the bit-mask values necessary to produce black, white, -inverted, and transparent results: - -Pixel result AND mask XOR mask - -Black 0 0 -White 0 1 -Transparent 1 0 -Inverted 1 1 - -Windows Cursor Selection - -If a cursor-resource file contains more than one cursor image, Windows -determines the best match for a particular display by examining the width and -height of the cursor images. - - -============================================================================== - - -BITMAPFILEHEADER (3.0) - - - -typedef struct tagBITMAPFILEHEADER { /* bmfh */ - UINT bfType; - DWORD bfSize; - UINT bfReserved1; - UINT bfReserved2; - DWORD bfOffBits; -} BITMAPFILEHEADER; - -The BITMAPFILEHEADER structure contains information about the type, size, and -layout of a device-independent bitmap (DIB) file. - -Member Description - -bfType Specifies the type of file. This member must be BM. -bfSize Specifies the size of the file, in bytes. -bfReserved1 Reserved; must be set to zero. -bfReserved2 Reserved; must be set to zero. -bfOffBits Specifies the byte offset from the BITMAPFILEHEADER structure -to the actual bitmap data in the file. - -Comments - -A BITMAPINFO or BITMAPCOREINFO structure immediately follows the -BITMAPFILEHEADER structure in the DIB file. - -See Also - -BITMAPCOREINFO, BITMAPINFO - - -============================================================================== -BITMAPINFO (3.0) - - - -typedef struct tagBITMAPINFO { /* bmi */ - BITMAPINFOHEADER bmiHeader; - RGBQUAD bmiColors[1]; -} BITMAPINFO; - -The BITMAPINFO structure fully defines the dimensions and color information -for a Windows 3.0 or later device-independent bitmap (DIB). - -Member Description - -bmiHeader Specifies a BITMAPINFOHEADER structure that contains -information about the dimensions and color format of a DIB. - -bmiColors Specifies an array of RGBQUAD structures that define the -colors in the bitmap. - -Comments - -A Windows 3.0 or later DIB consists of two distinct parts: a BITMAPINFO -structure, which describes the dimensions and colors of the bitmap, and an -array of bytes defining the pixels of the bitmap. The bits in the array are -packed together, but each scan line must be zero-padded to end on a LONG -boundary. Segment boundaries, however, can appear anywhere in the bitmap. The -origin of the bitmap is the lower-left corner. - -The biBitCount member of the BITMAPINFOHEADER structure determines the number -of bits which define each pixel and the maximum number of colors in the -bitmap. This member may be set to any of the following values: - -Value Meaning - -1 The bitmap is monochrome, and the bmciColors member must contain two -entries. Each bit in the bitmap array represents a pixel. If the bit is -clear, the pixel is displayed with the color of the first entry in the -bmciColors table. If the bit is set, the pixel has the color of the second -entry in the table. - -4 The bitmap has a maximum of 16 colors, and the bmciColors member -contains 16 entries. Each pixel in the bitmap is represented by a four-bit -index into the color table. - -For example, if the first byte in the bitmap is 0x1F, the byte represents two -pixels. The first pixel contains the color in the second table entry, and the -second pixel contains the color in the sixteenth table entry. - -8 The bitmap has a maximum of 256 colors, and the bmciColors member -contains 256 entries. In this case, each byte in the array represents a -single pixel. - -24 The bitmap has a maximum of 2^24 colors. The bmciColors member is -NULL, and each 3-byte sequence in the bitmap array represents the relative -intensities of red, green, and blue, respectively, of a pixel. - -The biClrUsed member of the BITMAPINFOHEADER structure specifies the number -of color indexes in the color table actually used by the bitmap. If the -biClrUsed member is set to zero, the bitmap uses the maximum number of colors -corresponding to the value of the biBitCount member. - -The colors in the bmiColors table should appear in order of importance. -Alternatively, for functions that use DIBs, the bmiColors member can be an -array of 16-bit unsigned integers that specify an index into the currently -realized logical palette instead of explicit RGB values. In this case, an -application using the bitmap must call DIB functions with the wUsage -parameter set to DIB_PAL_COLORS. - -Note: The bmiColors member should not contain palette indexes if the bitmap -is to be stored in a file or transferred to another application. Unless the -application uses the bitmap exclusively and under its complete control, the -bitmap color table should contain explicit RGB values. - -See Also - -BITMAPINFOHEADER, RGBQUAD - -============================================================================== -BITMAPINFOHEADER (3.0) - - - -typedef struct tagBITMAPINFOHEADER { /* bmih */ - DWORD biSize; - LONG biWidth; - LONG biHeight; - WORD biPlanes; - WORD biBitCount; - DWORD biCompression; - DWORD biSizeImage; - LONG biXPelsPerMeter; - LONG biYPelsPerMeter; - DWORD biClrUsed; - DWORD biClrImportant; -} BITMAPINFOHEADER; - -The BITMAPINFOHEADER structure contains information about the dimensions and -color format of a Windows 3.0 or later device-independent bitmap (DIB). - -Member Description - -biSize Specifies the number of bytes required by the -BITMAPINFOHEADER structure. - -biWidth Specifies the width of the bitmap, in pixels. -biHeight Specifies the height of the bitmap, in pixels. - -biPlanes Specifies the number of planes for the target device. This -member must be set to 1. - -biBitCount Specifies the number of bits per pixel. This value must be 1, -4, 8, or 24. - -biCompression Specifies the type of compression for a compressed bitmap. It -can be one of the following values: - -Value Meaning - -BI_RGB Specifies that the bitmap is not compressed. - -BI_RLE8 Specifies a run-length encoded format for bitmaps with 8 bits -per pixel. The compression format is a 2-byte format consisting of a count -byte followed by a byte containing a color index. For more information, see -the following Comments section. - -BI_RLE4 Specifies a run-length encoded format for bitmaps with 4 bits -per pixel. The compression format is a 2-byte format consisting of a count -byte followed by two word-length color indexes. For more information, see -the following Comments section. - -biSizeImage Specifies the size, in bytes, of the image. It is valid to -set this member to zero if the bitmap is in the BI_RGB format. - -biXPelsPerMeter Specifies the horizontal resolution, in pixels per meter, of -the target device for the bitmap. An application can use this value to select -a bitmap from a resource group that best matches the characteristics of the -current device. - -biYPelsPerMeter Specifies the vertical resolution, in pixels per meter, of -the target device for the bitmap. - -biClrUsed Specifies the number of color indexes in the color table -actually used by the bitmap. If this value is zero, the bitmap uses the -maximum number of colors corresponding to the value of the biBitCount member. -For more information on the maximum sizes of the color table, see the -description of the BITMAPINFO structure earlier in this topic. - -If the biClrUsed member is nonzero, it specifies the actual number of colors -that the graphics engine or device driver will access if the biBitCount -member is less than 24. If biBitCount is set to 24, biClrUsed specifies the -size of the reference color table used to optimize performance of Windows -color palettes. If the bitmap is a packed bitmap (that is, a bitmap in which -the bitmap array immediately follows the BITMAPINFO header and which is -referenced by a single pointer), the biClrUsed member must be set to zero or -to the actual size of the color table. - -biClrImportant Specifies the number of color indexes that are considered -important for displaying the bitmap. If this value is zero, all colors are -important. - -Comments - -The BITMAPINFO structure combines the BITMAPINFOHEADER structure and a color -table to provide a complete definition of the dimensions and colors of a -Windows 3.0 or later DIB. For more information about specifying a Windows 3.0 -DIB, see the description of the BITMAPINFO structure. - -An application should use the information stored in the biSize member to -locate the color table in a BITMAPINFO structure as follows: - -pColor = ((LPSTR) pBitmapInfo + (WORD) (pBitmapInfo->bmiHeader.biSize)) - -Windows supports formats for compressing bitmaps that define their colors -with 8 bits per pixel and with 4 bits per pixel. Compression reduces the disk -and memory storage required for the bitmap. The following paragraphs describe -these formats. - -BI_RLE8 - -When the biCompression member is set to BI_RLE8, the bitmap is compressed -using a run-length encoding format for an 8-bit bitmap. This format may be -compressed in either of two modes: encoded and absolute. Both modes can occur -anywhere throughout a single bitmap. - -Encoded mode consists of two bytes: the first byte specifies the number of -consecutive pixels to be drawn using the color index contained in the second -byte. In addition, the first byte of the pair can be set to zero to indicate -an escape that denotes an end of line, end of bitmap, or a delta. The -interpretation of the escape depends on the value of the second byte of the -pair. The following list shows the meaning of the second byte: - -Value Meaning - -0 End of line. -1 End of bitmap. -2 Delta. The two bytes following the escape contain unsigned values -indicating the horizontal and vertical offset of the next pixel from the -current position. - -Absolute mode is signaled by the first byte set to zero and the second byte -set to a value between 0x03 and 0xFF. In absolute mode, the second byte -represents the number of bytes that follow, each of which contains the color -index of a single pixel. When the second byte is set to 2 or less, the escape -has the same meaning as in encoded mode. In absolute mode, each run must be -aligned on a word boundary. The following example shows the hexadecimal -values of an 8-bit compressed bitmap: - - - -03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01 -02 78 00 00 09 1E 00 01 - -This bitmap would expand as follows (two-digit values represent a color index -for a single pixel): - - - -04 04 04 -06 06 06 06 06 -45 56 67 -78 78 -move current position 5 right and 1 down -78 78 -end of line -1E 1E 1E 1E 1E 1E 1E 1E 1E -end of RLE bitmap - -BI_RLE4 - -When the biCompression member is set to BI_RLE4, the bitmap is compressed -using a run-length encoding (RLE) format for a 4-bit bitmap, which also uses -encoded and absolute modes. In encoded mode, the first byte of the pair -contains the number of pixels to be drawn using the color indexes in the -second byte. The second byte contains two color indexes, one in its -high-order nibble (that is, its low-order four bits) and one in its low-order -nibble. The first of the pixels is drawn using the color specified by the -high-order nibble, the second is drawn using the color in the low-order -nibble, the third is drawn with the color in the high-order nibble, and so -on, until all the pixels specified by the first byte have been drawn. In -absolute mode, the first byte contains zero, the second byte contains the -number of color indexes that follow, and subsequent bytes contain color -indexes in their high- and low-order nibbles, one color index for each pixel. -In absolute mode, each run must be aligned on a word boundary. The -end-of-line, end-of-bitmap, and delta escapes also apply to BI_RLE4. - -The following example shows the hexadecimal values of a 4-bit compressed -bitmap: - - - -03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01 -04 78 00 00 09 1E 00 01 - -This bitmap would expand as follows (single-digit values represent a color -index for a single pixel): - - - -0 4 0 -0 6 0 6 0 -4 5 5 6 6 7 -7 8 7 8 -move current position 5 right and 1 down -7 8 7 8 -end of line -1 E 1 E 1 E 1 E 1 -end of RLE bitmap - -See Also - -BITMAPINFO - -============================================================================== -RGBQUAD (3.0) - - - -typedef struct tagRGBQUAD { /* rgbq */ - BYTE rgbBlue; - BYTE rgbGreen; - BYTE rgbRed; - BYTE rgbReserved; -} RGBQUAD; - -The RGBQUAD structure describes a color consisting of relative intensities of -red, green, and blue. The bmiColors member of the BITMAPINFO structure -consists of an array of RGBQUAD structures. - -Member Description - -rgbBlue Specifies the intensity of blue in the color. -rgbGreen Specifies the intensity of green in the color. -rgbRed Specifies the intensity of red in the color. -rgbReserved Not used; must be set to zero. - -See Also - -BITMAPINFO - -============================================================================== -RGB (2.x) - -COLORREF RGB(cRed, cGreen, cBlue) - -BYTE cRed; /* red component of color */ -BYTE cGreen; /* green component of color */ -BYTE cBlue; /* blue component of color */ - - -The RGB macro selects an RGB color based on the parameters supplied and the -color capabilities of the output device. - -Parameter Description - -cRed Specifies the intensity of the red color field. -cGreen Specifies the intensity of the green color field. -cBlue Specifies the intensity of the blue color field. - -Returns - -The return value specifies the resultant RGB color. - -Comments - -The intensity for each argument can range from 0 through 255. If all three -intensities are specified as zero, the result is black. If all three -intensities are specified as 255, the result is white. - -Comments - -The RGB macro is defined in WINDOWS.H as follows: - - - -#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)(g)<<8))| \ - (((DWORD)(BYTE)(b))<<16))) - -See Also - -GetBValue, GetGValue, GetRValue, PALETTEINDEX, PALETTERGB - -============================================================================== -BITMAPCOREINFO (3.0) - - - -typedef struct tagBITMAPCOREINFO { /* bmci */ - BITMAPCOREHEADER bmciHeader; - RGBTRIPLE bmciColors[1]; -} BITMAPCOREINFO; - -The BITMAPCOREINFO structure fully defines the dimensions and color -information for a device-independent bitmap (DIB). Windows applications -should use the BITMAPINFO structure instead of BITMAPCOREINFO whenever -possible. - -Member Description - -bmciHeader Specifies a BITMAPCOREHEADER structure that contains -information about the dimensions and color format of a DIB. - -bmciColors Specifies an array of RGBTRIPLE structures that define the -colors in the bitmap. - -Comments - -The BITMAPCOREINFO structure describes the dimensions and colors of a bitmap. -It is followed immediately in memory by an array of bytes which define the -pixels of the bitmap. The bits in the array are packed together, but each -scan line must be zero-padded to end on a LONG boundary. Segment boundaries, -however, can appear anywhere in the bitmap. The origin of the bitmap is the -lower-left corner. - -The bcBitCount member of the BITMAPCOREHEADER structure determines the number -of bits that define each pixel and the maximum number of colors in the -bitmap. This member may be set to any of the following values: - -Value Meaning - -1 The bitmap is monochrome, and the bmciColors member must contain two -entries. Each bit in the bitmap array represents a pixel. If the bit is -clear, the pixel is displayed with the color of the first entry in the -bmciColors table. If the bit is set, the pixel has the color of the second -entry in the table. - -4 The bitmap has a maximum of 16 colors, and the bmciColors member -contains 16 entries. Each pixel in the bitmap is represented by a four-bit -index into the color table. - -For example, if the first byte in the bitmap is 0x1F, the byte represents two -pixels. The first pixel contains the color in the second table entry, and the -second pixel contains the color in the sixteenth table entry. - -8 The bitmap has a maximum of 256 colors, and the bmciColors member -contains 256 entries. In this case, each byte in the array represents a -single pixel. - -24 The bitmap has a maximum of 2^24 colors. The bmciColors member is -NULL, and each 3-byte sequence in the bitmap array represents the relative -intensities of red, green, and blue, respectively, of a pixel. - -The colors in the bmciColors table should appear in order of importance. -Alternatively, for functions that use DIBs, the bmciColors member can be an -array of 16-bit unsigned integers that specify an index into the currently -realized logical palette instead of explicit RGB values. In this case, an -application using the bitmap must call DIB functions with the wUsage -parameter set to DIB_PAL_COLORS. - -Note: The bmciColors member should not contain palette indexes if the -bitmap is to be stored in a file or transferred to another application. -Unless the application uses the bitmap exclusively and under its complete -control, the bitmap color table should contain explicit RGB values. - -See Also - -BITMAPINFO, BITMAPCOREHEADER, RGBTRIPLE - - -============================================================================== -BITMAPCOREHEADER (3.0) - - - -typedef struct tagBITMAPCOREHEADER { /* bmch */ - DWORD bcSize; - short bcWidth; - short bcHeight; - WORD bcPlanes; - WORD bcBitCount; -} BITMAPCOREHEADER; - -The BITMAPCOREHEADER structure contains information about the dimensions and -color format of a device-independent bitmap (DIB). Windows applications -should use the BITMAPINFOHEADER structure instead of BITMAPCOREHEADER -whenever possible. - -Member Description - -bcSize Specifies the number of bytes required by the -BITMAPCOREHEADER structure. - -bcWidth Specifies the width of the bitmap, in pixels. -bcHeight Specifies the height of the bitmap, in pixels. - -bcPlanes Specifies the number of planes for the target device. This -member must be set to 1. - -bcBitCount Specifies the number of bits per pixel. This value must be 1, -4, 8, or 24. - -Comments - -The BITMAPCOREINFO structure combines the BITMAPCOREHEADER structure and a -color table to provide a complete definition of the dimensions and colors of -a DIB. See the description of the BITMAPCOREINFO structure for more -information about specifying a DIB. - -An application should use the information stored in the bcSize member to -locate the color table in a BITMAPCOREINFO structure with a method such as -the following: - - - -lpColor = ((LPSTR) pBitmapCoreInfo + (UINT) (pBitmapCoreInfo->bcSize)) - -See Also - -BITMAPCOREINFO, BITMAPINFOHEADER, BITMAPINFOHEADER - -============================================================================= -RGBTRIPLE (3.0) - - - -typedef struct tagRGBTRIPLE { /* rgbt */ - BYTE rgbtBlue; - BYTE rgbtGreen; - BYTE rgbtRed; -} RGBTRIPLE; - -The RGBTRIPLE structure describes a color consisting of relative intensities -of red, green, and blue. The bmciColors member of the BITMAPCOREINFO -structure consists of an array of RGBTRIPLE structures. Windows applications -should use the BITMAPINFO structure instead of BITMAPCOREINFO whenever -possible. The BITMAPINFO structure uses an RGBQUAD structure instead of the -RGBTRIPLE structure. - -Member Description - -rgbtBlue Specifies the intensity of blue in the color. -rgbtGreen Specifies the intensity of green in the color. -rgbtRed Specifies the intensity of red in the color. - -See Also - -BITMAPCOREINFO, BITMAPINFO, RGBQUAD - -============================================================================== - Index: trunk/docs/lgpl.txt =================================================================== --- trunk/docs/lgpl.txt (revision 4) +++ trunk/docs/lgpl.txt (nonexistent) @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - Index: trunk/docs/jfif3.pdf =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: trunk/docs/jfif3.pdf =================================================================== --- trunk/docs/jfif3.pdf (revision 4) +++ trunk/docs/jfif3.pdf (nonexistent)
trunk/docs/jfif3.pdf Property changes : Deleted: svn:mime-type ## -1 +0,0 ## -application/octet-stream \ No newline at end of property Index: trunk/readme.txt =================================================================== --- trunk/readme.txt (revision 4) +++ trunk/readme.txt (revision 5) @@ -10,60 +10,19 @@ - Description -This project features a complete JPEG Hardware Compressor (standard Baseline DCT, JFIF header) with 2:1:1 subsampling, able to compress at a rate of up to 24 images per second (on XC2V1000-4 @ 40 MHz with resolution 352x288). +This project features a complete JPEG Hardware Compressor (standard Baseline DCT, JFIF header) with 2:1:1 subsampling, able to compress at a rate of up to 24 images per second (on XC2V1000-4 @ 40 MHz with CIF resolution: 352x288). -Image resolution is not limited. It takes an RGB input (row-wise) and outputs to a memory the compressed JPEG image. Its quality is comparable to software solutions. +IMAGE RESOLUTION IS LIMITED TO 352x288. It takes an RGB input (row-wise) and outputs to a memory the compressed JPEG image. -A testbench has been made that takes a bitmap image from your computer and writes a compressed JPEG file by simulating the code. Download the code and try it, it's easy. +A testbench has been made that takes a bitmap image from your computer and writes a compressed JPEG file by simulating the code. -The source code is VHDL and it is LGPL, so it can be used in commercial applications as long as the terms of the license are respected. - Anyone interested in the image standards used in this project, they can be downloaded from the following places: -JPEG (ITU-T81 standard): http://www.w3.org/Graphics/JPEG/itu-t81.pdf -JFIF (JPEG file headers): http://www.w3.org/Graphics/JPEG/jfif3.pdf +JPEG (ITU-T81 standard): http://www.w3.org/Graphics/JPEG/itu-t81.pdf +JFIF (JPEG file headers): http://www.w3.org/Graphics/JPEG/jfif3.pdf BMP (bitmaps for the testbench): http://netghost.narod.ru/gff/vendspec/micbmp/bmp.txt -Please note that there is another Tab in this web page named "Detailed Description" with further info on this core. +If you run into any problems downloading the files from the cvs please check that you are downloading them in binary form. For any questions my email is: +victor.lopez [(at)] ono [(dot)] com -If you run into any problems downloading the files from the cvs please check that you are downloading them in binary form. For any questions my email is: -galland@opencores.org - - -- Notes - -Some quick notes until the time I upload the full documentation: - - * This implementation is compliant with ISO standard (and ITU standard T-81), it features a compliant JPEG compressor Baseline DCT with Huffman encoding and 2x2 1x1 1x1 subsampling. The header is the widely employed JFIF. Baseline DCT JPEG with JFIF header is one of the most used image formats. - * Included with the source code is a Testbench which allows you to compress a bitmap (uncompressed 24 bit BMP) file located in the project folder (if using Active-HDL then in the design folder) just by simulating it. Its name MUST be "image.bmp". By the way, remember that a bitmap image stores the information bottom up, and JPEG is top-bottom, so you should flip (invert) the bitmap image (see the test image if you don't understand what I mean). This is only important for simulation. - * The testbench is made in such a way that it will automatically exit the simulation when it finishes. A 352x288 image takes almost 40 ms of simulation time (that will take some minutes depending on your machine). The output image will be in the same folder as "image.bmp" and its name will be "image.jpg" (it will overwrite previous outputs without warning). - * It has been simulated on Windows machines, so I can't guarantee anything on simulation over Linux though I don't think there could be any problem at all. Please update me on this. - * It has been synthesized and tested in a Xilinx Virtex-2 XC2V1000-4 running at 40 MHz (that is why it takes 40 ms, the testbench simulates a 40 MHz clock). This is one of the worst speed grades (-4), so with most other FPGAs you will get faster implementations. - * It uses at minimum 11 BlockRAMs (one of them for the DCT block), but you will need some more to store the final compressed image (whose size varies as compression depends on the image as well as in the compression level), the source code in the Downloads page includes a memory for this purpose of 51.200 bytes (buffer_img), that is 25 BlockRAMs. - * There is an easily overridable limitation on input image resolution, for a description on how to change the maximum input image size see the Notes at the beginning of the main source file "compressor.vhd". - * The only real limitation is that the input image must have width and height multiple of 16 (that is, an image 32x32 will produce a strictly compliant JPEG image file, but not a 32x24 or a 24x32 input image, although the resulting image will more likely still be viewable), this is due to the subsampling method employed. This limitation could be overriden with some extra logic (for padding as indicated in the JPEG standard). - - * Finally I would like to apologize if you find this code somewhat messy. When I programmed it, I imposed myself very strict deadlines and making it opensource was not in my mind, mainly because, if I were to do it again, I would do it in other way to get much more performance. The main problem faced with this implementation was a very scarce availability of BlockRAM in the target FPGA, so some areas that could perfectly run in parallel, speeding a lot the whole process, had to be made sequential in order to save up BlockRAMs. Anyways, this code works (it functioned as a webcam, attached to a CMOS sensor) and, though not as fast as it could be, it has a good performance. This source code is LGPL. Any questions, suggestions, comments (positive criticism) is always welcome. - - -- Functional Description - -The source code is composed of 9 VHDL files: - - * compressor_tb.vhd : Testbench file for the project. It reads an uncompressed BMP located in the project folder (not necessarily the source code folder) and outputs a JPG compressed image (the actual writing of the output file is carried out by the next file). - - * compressor.vhd : This is the main code file. Inside, there are a few concurrent instructions, declarations of the needed componentes (BlockRAMs and DCT block) and two processes which are responsible of the whole compression process. To better follow the next explanation consult the figure located after this explanation. The first process is RGB2YCbCr is in charge of converting the input signals (Red, Green and Blue, strobed by ProcessRGB signal) to the YCbCr color space and to apply a level shift as specified by the JPEG standard. The second is the process JPEG, it feeds the DCT block (DCT-2D Core in the figure) with data from the previous process (the interface between the two processes are three memories (Y, Cb and Cr Compression Buffers in the figure), one for luminance (Y) data, one for blue chrominance (Cb) and another for red chrominance (Cr)); after the DCT has processed the data (calculated the Forward 2D-DCT) it is quantized with the values stored in memory q_rom (Q ROM in the figure). As this quantization implies dividing by an integer number (remember that only divisions by power of 2 numbers and multiplications times an integer can be made really efficient in digital logic thru the use of shifts, right for division, left for multiplication), the solution was to convert the number to divide into a fraction with denominator 16384 for all the quantization values (128 for every compression level and there are three of these) so that we can multiply times an integer (left shift and some additions) and divide by a power of 2 number (right shift). For instance: to divide by 11 is the same as multiplying times 1/11, which is almost the same as multiplying times 1489/16384, which is actually equal to dividing by 11.003357. Using this apparently complicated way of handling real number operations we get the fastest implementation and no floating point, only a minimal error (you would never notice the visual difference). After quantization of all the values, Huffman encoding starts by looking up the tables stored in huff_rom (Huffman ROM in the figure) and storing in the final image buffer the compressed image (should be buffer_img but in the figure is left as a blue upwards pointing arrow). By the way, at the beginning, when a compression level is selected and the port CompressImage signals the start of a new image, the header in buffer_img (yes, there are some hundred bytes pre-stored with the fixed fields in the header) is updated with image dimensions and with the quantization tables for the selected compression (they are read from the ROM tabla_q in the figure and copied to the appropiate location in buffer_img). - - * buffer_img.vhd : CoreGen generated file with wrapper for the 25 SP BlockRAMs, Read/Write, WidthxDepth = 8 bits x 51200, where final image is stored. - - * buffer_comp.vhd : CoreGen generated file with wrapper for 5 SP BlockRAMs, Read/Write, WidthxDepth = 12 bits x 5632. Y pixels (8 bits) stored here and also, after transformation by DCT, their quantized counterparts (12 bits) are stored over them. - - * buffer_comp_chrom.vhd : CoreGen generated file with wrapper for 1 SP BlockRAM, Read/Write, WidthxDepth = 12 bits x 1408. This component is instantiated twice, one for Cb pixels, and other for Cr pixels. Cx pixels (8 bits) stored here and also, after transformation by DCT, their quantized counterparts (12 bits) are stored over them. - - * huff_rom.vhd : CoreGen generated file with wrapper for 1 SP BlockRAM, Read Only, WidthxDepth = 20 bits x 352. Huffman Code Tables stored here. - - * q_rom.vhd : CoreGen generated file with wrapper for 1 SP BlockRAM, Read Only, WidthxDepth = 13 bits x 384. Quantization Numerators stored here for multiplication and later division by 16384 as explained above. Three compression levels, two tables for each one (AC and DC), 64 elements in each one : 3x2x64=384. - - * tabla_q.vhd : CoreGen generated file with wrapper for 1 SP BlockRAM, Read Only, WidthxDepth = 8 bits x 384. Quantization Tables stored here for updating of the final JPEG file header. Three compression levels, two tables for each one (AC and DC), 64 elements in each one : 3x2x64=384. - - * dct2d.vhd : CoreGen generated file with wrapper for 2-D Discrete Cosine Transform (Forward DCT), Data Width = 8 bits Signed, Coefficients Width = 24 (Enable Symmetry), Precision Control: Round, Internal Width: 19, Result Width: 19, Performance: Clock Cycles per input=9, Transpose Memory = Block, Reset: No. (Results: Latency = 95 cycles, Row Latency = 15 cycles, Column Latency = 15 cycles). Takes as input sixty-four 8 bits signed values and outputs sixty-four 19 bits signed numbers in the frequency domain (the LSBs are decimals). \ No newline at end of file +PLEASE NOTICE THAT THIS CORE IS LICENSED AS GPL. That means you may use it only for NON-COMMERCIAL purposes.
/trunk/compressor.vhd
0,0 → 1,1913
---------------------------------------------------------------------------------------------------
--
-- Title : JPEG Hardware Compressor
-- Design : jpeg
-- Author : Victor Lopez Lorenzo
-- E-mail : victor.lopez ((at)) ono ((dot)) com
--
-- License : GPLv3 (only for NON-COMMERCIAL purposes)
--
---------------------------------------------------------------------------------------------------
--
--
-- Copyright (C) 2004 Victor Lopez Lorenzo
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
--
---------------------------------------------------------------------------------------------------
--
-- Contributors :
-- Peter Eisemann - Fixed GetCategory, writes and file declarations in order to
-- simulate code under ModelSim
--
--
---------------------------------------------------------------------------------------------------
--
--
-- IMPORTANT NOTES :
--
-- This source code features a compliant JPEG compressor Baseline DCT with
-- Huffman enconding and 2x2 1x1 1x1 subsampling. The header is the widely
-- employed JFIF.
--
-- Baseline DCT JPEG with JFIF header is one of the most used image formats.
--
-- The maximum image size is limited to 352x288
--
-- Another limitation is that the input image must have width and height
-- multiple of 16 (that is, an image 32x32 will produce a strictly compliant
-- JPEG image file, but not a 32x24 or a 24x32 input image, although the resulting
-- image will more likely still be viewable), this is due to the subsampling
-- method employed.
--
-- I apologize if you find this code somewhat messy. When I programmed it I imposed
-- myself very strict deadlines and making it opensource was not in my mind, mainly
-- because, if I were to do it again, I would do it in other way to get much
-- more performance. The main problem faced with this implementation was a very
-- scarce availability of BlockRAM in the target FPGA, so some areas that could
-- perfectly run in parallel, speeding a lot the whole process, had to be made
-- sequential in order to save up BlockRAMs. Anyways, this code works
-- (it functioned as a webcam, attached to a CMOS sensor) and, though not
-- as fast as it could be, it has a good performance.
--
-- As a part of this project there is a quite useful Testbench that takes as input
-- any BMP (24 bit color) image and compresses it with this code, outputting a JPG
-- file that you can view in your computer.
--
---------------------------------------------------------------------------------------------------
 
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_unsigned.all; --for arithmetic ops
--pragma translate_off
library STD;
use STD.textio.all;
use IEEE.std_logic_textio.all;
library XilinxCoreLib;
--pragma translate_on
library UNISIM;
use UNISIM.all;
 
entity Compressor is port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
--Control/Status Interface
CompressImage : in std_logic; --must be active high for just one cycle
Compression : in std_logic_vector(1 downto 0); --Quality: 00 = low, 01 = medium, 10 = high
Mono : in std_logic; --active high for grey-scale input image (Red=Green=Blue)
ImgColumns : in std_logic_vector(9 downto 0); --columns in each line of the image to compress
ImgLines : in std_logic_vector(8 downto 0); --lines of the image to compress
Compressing : out std_logic;
--Data Interface
ProcessRGB : in std_logic;
ProcessingRGB : out std_logic;
Red : in std_logic_vector(7 downto 0);
Green : in std_logic_vector(7 downto 0);
Blue : in std_logic_vector(7 downto 0);
--JPEG Image BlockRAM (Output) Interface
addr: out std_logic_VECTOR(15 downto 0);
din: out std_logic_VECTOR(7 downto 0);
we: out std_logic);
end Compressor;
 
architecture JPG of Compressor is
 
--pragma translate_off
 
file Debug: TEXT open WRITE_MODE is "Debug.txt";
file DebugY: TEXT open WRITE_MODE is "DebugY.txt";
file DebugCb: TEXT open WRITE_MODE is "DebugCb.txt";
file DebugCr: TEXT open WRITE_MODE is "DebugCr.txt";
 
-- file Debug:TEXT is out "Debug.txt";
-- file DebugY:TEXT is out "DebugY.txt";
-- file DebugCb:TEXT is out "DebugCb.txt";
-- file DebugCr:TEXT is out "DebugCr.txt";
constant espacio:string:=" ";
constant espacios:string:=" ";
constant puntoycoma:string:=";";
constant strElemento:string:=" Element: ";
constant strColumna:string:=" Column: ";
constant strLinea:string:=" Line: ";
--pragma translate_on
 
 
component dct2d port (
ND: IN std_logic;
RDY: OUT std_logic;
RFD: OUT std_logic;
CLK: IN std_logic;
DIN: IN std_logic_VECTOR(7 downto 0);
DOUT: OUT std_logic_VECTOR(18 downto 0));
end component;
 
component buffer_comp port (
addr: IN std_logic_VECTOR(12 downto 0);
clk: IN std_logic;
din: IN std_logic_VECTOR(11 downto 0);
dout: OUT std_logic_VECTOR(11 downto 0);
we: IN std_logic);
end component;
component buffer_comp_chrom port (
addr: IN std_logic_VECTOR(10 downto 0);
clk: IN std_logic;
din: IN std_logic_VECTOR(11 downto 0);
dout: OUT std_logic_VECTOR(11 downto 0);
we: IN std_logic);
end component;
component q_rom port (
addr: IN std_logic_VECTOR(8 downto 0);
clk: IN std_logic;
dout: OUT std_logic_VECTOR(12 downto 0));
end component;
component huff_rom port (
addr: IN std_logic_VECTOR(8 downto 0);
clk: IN std_logic;
dout: OUT std_logic_VECTOR(19 downto 0));
end component;
 
component tabla_q
port (
addr: IN std_logic_VECTOR(8 downto 0);
clk: IN std_logic;
dout: OUT std_logic_VECTOR(7 downto 0));
end component;
 
--signals for tabla_q
signal addrTablaQ: std_logic_VECTOR(8 downto 0);
signal doutTablaQ: std_logic_VECTOR(7 downto 0);
 
--signal for huff_rom
signal addrH : std_logic_vector(8 downto 0);
signal doutH : std_logic_vector(19 downto 0);
--signals for DCT block
signal ND: std_logic;
signal RDY: std_logic;
signal RFD: std_logic;
signal DIND: std_logic_VECTOR(7 downto 0);
signal DOUTD: std_logic_VECTOR(18 downto 0);
--signals for compression buffer
signal addrY: std_logic_VECTOR(12 downto 0);
signal dinY: std_logic_VECTOR(11 downto 0);
signal doutY: std_logic_VECTOR(11 downto 0);
signal weY: std_logic;
signal addrCb: std_logic_VECTOR(10 downto 0);
signal dinCb: std_logic_VECTOR(11 downto 0);
signal doutCb: std_logic_VECTOR(11 downto 0);
signal weCb: std_logic;
signal addrCr: std_logic_VECTOR(10 downto 0);
signal dinCr: std_logic_VECTOR(11 downto 0);
signal doutCr: std_logic_VECTOR(11 downto 0);
signal weCr: std_logic;
signal addrY1: std_logic_VECTOR(12 downto 0);
signal addrCb1: std_logic_VECTOR(10 downto 0);
signal addrCr1: std_logic_VECTOR(10 downto 0);
signal addrY2: std_logic_VECTOR(12 downto 0);
signal addrCb2: std_logic_VECTOR(10 downto 0);
signal addrCr2: std_logic_VECTOR(10 downto 0);
 
signal dinY1: std_logic_VECTOR(11 downto 0);
signal dinY2: std_logic_VECTOR(11 downto 0);
signal dinCb1: std_logic_VECTOR(11 downto 0);
signal dinCb2: std_logic_VECTOR(11 downto 0);
signal dinCr1: std_logic_VECTOR(11 downto 0);
signal dinCr2: std_logic_VECTOR(11 downto 0);
 
signal weY1: std_logic;
signal weY2: std_logic;
signal weCb1: std_logic;
signal weCb2: std_logic;
signal weCr1: std_logic;
signal weCr2: std_logic;
--signals for the quantization coefficients ROM
signal addrQ : std_logic_vector(8 downto 0);
signal doutQ : std_logic_vector(12 downto 0);
 
signal addri : std_logic_vector(15 downto 0); --to write directly to the port (headers and JPEG size) and read from it
signal addribk : std_logic_vector(15 downto 0); --exclusive when signal Save='1', it holds the current pixel
constant MaxImageSize : std_logic_vector(15 downto 0) :="1100011111111100"; --51196 bytes
signal ColumnToCompress : std_logic_vector(9 downto 0);
signal LineToCompress : std_logic_vector(3 downto 0); --goes from 0 to 15, the 16 that may occupy the luminance buffer
signal LineAbsToCompress: std_logic_vector(8 downto 0);
 
signal MakeDCT : std_logic;
signal CompressingInt : std_logic;
signal Done : std_logic; --the Huffman encoding part rises it for one cycle when finishes
 
signal StepV : integer range 0 to 5;
signal Save : std_logic;
signal NDe : std_logic;
signal WriteAdditionalBits : std_logic;
 
signal WriteTables : std_logic;
signal TableData : std_logic_vector(5 downto 0);
signal Table : std_logic;
signal ZRLing : std_logic;
signal RFDInt : std_logic;
signal RFDIntData : std_logic_vector(7 downto 0);
function Multiplier (Num, Prod : in std_logic_vector) return std_logic_vector;
function Multiplier (Num, Prod : in std_logic_vector) return std_logic_vector is
variable result : std_logic_vector(19 downto 0) := (others => '0');
begin --8 bits * 10 bits both unsigned = 18 bits
result := ('0' & Num(7 downto 0)) * ('0' & Prod);
return result(17 downto 0);
end Multiplier;
 
function MultiplierQ (Num, Prod : in std_logic_vector) return std_logic_vector;
function MultiplierQ (Num, Prod : in std_logic_vector) return std_logic_vector is
variable result : std_logic_vector(26 downto 0);
variable UNum : std_logic_vector(11 downto 0);
begin --it is like Multiplier but admits bigger operands: Num (10..0) (signed) and Prod (10..0) (unsigned)
--max result = 1000_0000_0000 * 111_1111_1111 = 1(sign)11_1111_1111_1000_0000_0000 (-2.048 * 2.047 = -4.192.256)
--UPDATE: now Prod may be of up to 13 bits (12..0), so the result will be 24..0
if Num(Num'High) = '1' then --negative number?
UNum := not (Num) + 1; --two's complement to make it positive
else
UNum := Num;
end if;
result := ('0' & UNum) * ('0' & Prod);
if Num(Num'High) = '1' then --negative result
result := (not result) + 1; --2's Complement
end if;
return result(24 downto 0);
end MultiplierQ;
function Mult_Columns (Line : in std_logic_vector) return std_logic_vector;
function Mult_Columns (Line : in std_logic_vector) return std_logic_vector is
variable result : std_logic_vector(12 downto 0);
begin
result := "0000000000000" + (Line & "00000000") + (Line & "000000") + (Line & "00000");
return result; --with Line max=1111, the max. result will be=1010010100000 (12..0)
end Mult_Columns;
 
function Mult_Half_Columns (Line : in std_logic_vector) return std_logic_vector;
function Mult_Half_Columns (Line : in std_logic_vector) return std_logic_vector is
variable result : std_logic_vector(10 downto 0);
begin
result := "00000000000" + (Line & "0000000") + (Line & "00000") + (Line & "0000");
return result; --with Line max=111, the max. result will be=10011010000 (10..0)
end Mult_Half_Columns;
 
 
function GetCategory (Coef : in std_logic_vector) return integer;
--function fixed to work under ModelSim by Peter Eisemann
function GetCategory (Coef : in std_logic_vector) return integer is
--tells us the category of the coefficient (AC and DC) based on a "sign-less" version of itself!
variable Coeff : std_logic_vector(Coef'High downto 0);
variable result: integer := 0;
begin
if Coef(Coef'High) = '1' then
Coeff := (not Coef) + 1;
else
Coeff := Coef;
end if;
categoryloop:for index in Coeff'range loop
if Coeff(index) = '1' then
-- return (index + 1); Eim
result := (index +1);
exit categoryloop when Coeff(index) = '1';
end if;
end loop categoryloop;
return result;
end GetCategory;
 
-- function GetCategory (Coef : in std_logic_vector) return integer;
--
-- function GetCategory (Coef : in std_logic_vector) return integer is
-- --tells us the category of the coefficient (AC and DC) based on a "sign-less" version of itself!
-- variable Coeff : std_logic_vector(Coef'High downto 0);
-- begin
-- if Coef(Coef'High) = '1' then
-- Coeff := (not Coef) + 1;
-- else
-- Coeff := Coef;
-- end if;
-- for index in Coeff'range loop
-- if Coeff(index) = '1' then
-- return (index + 1);
-- end if;
-- end loop;
-- return 0;
-- end GetCategory;
function AppendHuffmanWord (HuffmanWord, Code : in std_logic_vector; Pos : in integer) return std_logic_vector;
function AppendHuffmanWord (HuffmanWord, Code : in std_logic_vector; Pos : in integer) return std_logic_vector is
variable result : std_logic_vector(22 downto 0);
begin
result := HuffmanWord;
for i in (Code'length-1) downto 0 loop
result(Pos-i) := Code(i); --Code(Code'length-1-i); --MSB first!!
--IMPORTANT: the std_logic_vector is "to", not "downto", that's why the MSB is opposite as usual
end loop;
return result;
end AppendHuffmanWord;
 
--this function is an overload with Code as std_logic (used when it must only append the sign)
function AppendHuffmanWord (HuffmanWord : in std_logic_vector; Code : in std_logic; Pos : in integer) return std_logic_vector;
function AppendHuffmanWord (HuffmanWord : in std_logic_vector; Code : in std_logic; Pos : in integer) return std_logic_vector is
variable result : std_logic_vector(22 downto 0);
begin
result := HuffmanWord;
result(Pos) := Code;
return result;
end AppendHuffmanWord;
--this one is to define the MSB of Code in case it is not length-1, so that CodeLength is the new length-1
function AppendHuffmanWordL (HuffmanWord, Code : in std_logic_vector; CodeLength : in integer; Pos : in integer) return std_logic_vector;
function AppendHuffmanWordL (HuffmanWord, Code : in std_logic_vector; CodeLength : in integer; Pos : in integer) return std_logic_vector is
variable result : std_logic_vector(22 downto 0);
begin
result := HuffmanWord;
for i in Code'length downto 0 loop
if i < CodeLength then --this may look redundant but it avoids an "unbound loop" error
result(Pos-i) := Code(CodeLength-1-i); --careful! here bit 0 is the LSB, X-File
end if;
end loop;
return result;
end AppendHuffmanWordL;
function To_std_logicvpor11(ZeroRun : in integer) return std_logic_vector;
function To_std_logicvpor11(ZeroRun : in integer) return std_logic_vector is
--returns the integer times 11 in a std_logic_vector(8 downto 0)
begin
case ZeroRun is
when 0 =>
return "000000000";
when 1 =>
return "000001011";
when 2 =>
return "000010110";
when 3 =>
return "000100001";
when 4 =>
return "000101100";
when 5 =>
return "000110111";
when 6 =>
return "001000010";
when 7 =>
return "001001101";
when 8 =>
return "001011000";
when 9 =>
return "001100011";
when 10 =>
return "001101110";
when 11 =>
return "001111001";
when 12 =>
return "010000100";
when 13 =>
return "010001111";
when 14 =>
return "010011010";
when others => --15 =>
return "010100101"; --165
end case;
end To_std_logicvpor11;
function To_std_logicv(Cat : in integer) return std_logic_vector;
function To_std_logicv(Cat : in integer) return std_logic_vector is
begin
case Cat is
when 0 =>
return "0000";
when 1 =>
return "0001";
when 2 =>
return "0010";
when 3 =>
return "0011";
when 4 =>
return "0100";
when 5 =>
return "0101";
when 6 =>
return "0110";
when 7 =>
return "0111";
when 8 =>
return "1000";
when 9 =>
return "1001";
when others => -- 10 => there won't be 11 because we only use it for AC
return "1010";
end case;
end To_std_logicv;
function GetMagnitude (Coef : in std_logic_vector; Cat : in integer) return std_logic_vector;
function GetMagnitude (Coef : in std_logic_vector; Cat : in integer) return std_logic_vector is
begin
case Cat is
when 0 =>
return "000000000000"; --we avoid this case with an if because it wouldn't be correct
when 1 =>
return "000000000000"; --we avoid this case with an if because it wouldn't be correct
when 2 =>
return (Coef - "10");
when 3 =>
return (Coef - "100");
when 4 =>
return (Coef - "1000");
when 5 =>
return (Coef - "10000");
when 6 =>
return (Coef - "100000");
when 7 =>
return (Coef - "1000000");
when 8 =>
return (Coef - "10000000");
when 9 =>
return (Coef - "100000000");
when 10 =>
return (Coef - "1000000000");
when others => --11 =>
return (Coef - "10000000000");
end case;
end GetMagnitude;
function CompressDC(Cat : in integer; LumaBlock : in std_logic) return std_logic_vector;
function CompressDC(Cat : in integer; LumaBlock : in std_logic) return std_logic_vector is
variable result : std_logic_vector(14 downto 0) := (others => '0');
begin --the four MSBs of result keep the number of the MSB bit of the data in the LSBs
if LumaBlock = '1' then --compress with DC Luminance Table
case Cat is
when 0 =>
result := "000100000000000";
when 1 =>
result := "001000000000010";
when 2 =>
result := "001000000000011";
when 3 =>
result := "001000000000100";
when 4 =>
result := "001000000000101";
when 5 =>
result := "001000000000110";
when 6 =>
result := "001100000001110";
when 7 =>
result := "010000000011110";
when 8 =>
result := "010100000111110";
when 9 =>
result := "011000001111110";
when 10 =>
result := "011100011111110";
when others => --11
result := "100000111111110";
end case;
else --DC chrominance table
case Cat is
when 0 =>
result := "000100000000000";
when 1 =>
result := "000100000000001";
when 2 =>
result := "000100000000010";
when 3 =>
result := "001000000000110";
when 4 =>
result := "001100000001110";
when 5 =>
result := "010000000011110";
when 6 =>
result := "010100000111110";
when 7 =>
result := "011000001111110";
when 8 =>
result := "011100011111110";
when 9 =>
result := "100000111111110";
when 10 =>
result := "100101111111110";
when others => --11
result := "101011111111110";
end case;
end if;
return result;
end CompressDC;
begin
with Save select addr <= addribk when '1', addri when others;
with CompressingInt select addrY <= addrY2 when '1', addrY1 when others;
with CompressingInt select addrCb <= addrCb2 when '1', addrCb1 when others;
with CompressingInt select addrCr <= addrCr2 when '1', addrCr1 when others;
with CompressingInt select weY <= weY2 when '1', weY1 when others;
with CompressingInt select weCb <= weCb2 when '1', weCb1 when others;
with CompressingInt select weCr <= weCr2 when '1', weCr1 when others;
with CompressingInt select dinY <= dinY2 when '1', dinY1 when others;
with CompressingInt select dinCb <= dinCb2 when '1', dinCb1 when others;
with CompressingInt select dinCr <= dinCr2 when '1', dinCr1 when others;
DCT1 : dct2d port map (ND,RDY,RFD,clk,DIND,DOUTD);
 
buffer_compY : buffer_comp port map (addrY,clk,dinY,doutY,weY);
buffer_compCb : buffer_comp_chrom port map (addrCb,clk,dinCb,doutCb,weCb);
buffer_compCr : buffer_comp_chrom port map (addrCr,clk,dinCr,doutCr,weCr);
 
Q_ROM1 : q_rom port map (addrQ,clk,doutQ);
Huffman_ROM : huff_rom port map (addrH,clk,doutH);
Tabla_Q1 : tabla_q port map(addrTablaQ,clk,doutTablaQ);
 
RGB2YCbCr : process(reset, clk)
--It applies the transformation from RGB to YCBCr and pass it to the JPEG process
-- but what we are going to save in the buffers will be the pixels of the components with
-- the JPEG level shift already applied, so that the transformation's last addition: [0;128;128] will become -[128;0;0]
variable Baton : integer range 0 to 3 := 0; --indicates the current state of the FSM
variable Red1 : std_logic_vector(17 downto 0);
variable Red2 : std_logic_vector(17 downto 0);
variable Red3 : std_logic_vector(17 downto 0);
variable Green1 : std_logic_vector(17 downto 0);
variable Green2 : std_logic_vector(17 downto 0);
variable Green3 : std_logic_vector(17 downto 0);
variable Blue1 : std_logic_vector(17 downto 0);
variable Blue2 : std_logic_vector(17 downto 0);
variable Blue3 : std_logic_vector(17 downto 0);
variable Cb, Cr : std_logic_vector(10 downto 0);
begin
if (reset = '1') then
Compressing <= '0';
addrY1 <= (others => '0');
addrCb1 <= (others => '0');
addrCr1 <= (others => '0');
weY1 <= '0';
weCb1 <= '0';
weCr1 <= '0';
dinCb1 <= (others => '0');
dinCr1 <= (others => '0');
dinY1 <= (others => '0');
LineToCompress <= "0000";
LineAbsToCompress <= (others => '0');
ColumnToCompress <= (others => '0');
Baton := 0;
Cb := (others => '0');
Cr := (others => '0');
ProcessingRGB <= '0';
MakeDCT <= '0';
Red1 := (others => '0');
Red2 := (others => '0');
Red3 := (others => '0');
Green1 := (others => '0');
Green2 := (others => '0');
Green3 := (others => '0');
Blue1 := (others => '0');
Blue2 := (others => '0');
Blue3 := (others => '0');
elsif (clk = '1' and clk'event) then
if CompressImage = '1' then
Compressing <= '1';
addrY1 <= (others => '0');
addrCb1 <= (others => '0');
addrCr1 <= (others => '0');
weY1 <= '0';
weCb1 <= '0';
weCr1 <= '0';
LineToCompress <= "0000";
LineAbsToCompress <= (others => '0');
ColumnToCompress <= (others => '0');
Baton := 0;
ProcessingRGB <= '0';
end if;
 
if (ProcessRGB = '1') then
ProcessingRGB <= '1'; --while this one is high, there won't be another ProcessRGB='1'
Baton := 1;
end if;
 
addrY1 <= Mult_Columns(LineToCompress) + ColumnToCompress;
addrCb1 <= Mult_Half_Columns(LineToCompress(3 downto 1)) + (ColumnToCompress(9 downto 1)); --for the subsampling
addrCr1 <= Mult_Half_Columns(LineToCompress(3 downto 1)) + (ColumnToCompress(9 downto 1));
--we pre-read the saved data, so as to average the chroma components Cb and Cr
--to be able to do a proper subsampling 2x2 1x1 1x1
case Baton is
when 0 =>
weY1 <= '0';
weCb1 <= '0';
weCr1 <= '0';
MakeDCT <= '0';
 
when 1 =>
--we apply only the transformation RGB to YCbCr
Red1 := Multiplier(Red, "0010011001"); --153
Red2 := Multiplier(Red, "0010101101"); --173
Red3 := "0000000000" & Red; --1
Green1 := Multiplier(Green, "1001011001"); --601
Green2 := Multiplier(Green, "0101010011"); --339
Green3 := Multiplier(Green, "0110101101"); --429
Blue1 := Multiplier(Blue, "0001110101"); --117
Blue2 := "0000000000" & Blue; --1
Blue3 := Multiplier(Blue, "0001010011"); --83
--the largest obtainable result would be 255*601=153255 (100101011010100111)
Baton := 2;
MakeDCT <= '0';
when 2 =>
--dinY1 <= "111110000000"; --for debugging, to make Y zero, so that in the resulting image the Blue channel will be Cb and the Red one will be Cr
dinY1 <= "0000" & (Red1(16 downto 9) + Green1(17 downto 10) + Blue1(17 downto 10) - "10000000");-- + Red1(8) + Green1(9) + Blue1(9)); --Red1/512+Green1/1024+Blue1/1024 and with -128 for the level shift
if Mono = '1' then
Cb := (others => '0');
Cr := (others => '0');
else
Cb := "000" & (Blue2(8 downto 1) - Red2(17 downto 10) - Green2(17 downto 10)); -- + Blue2(0) - Red2(9) - Green2(9)); --Red & Green between 1024 and Blue between 2
Cr := "000" & (Red3(8 downto 1) - Green3(17 downto 10) - Blue3(17 downto 10)); -- + Red3(0) - Green3(9) - Blue3(9)); --between 1024 all but Red
--debug: the bits added/substracted at the end are the nearest integer rounding
end if;
--Subsampling: average groups of 4 pixels in blocks of 2x2
if LineAbsToCompress(0) = '0' and ColumnToCompress(0) = '0' then --element (0,0)
--dinCb1 <= "0000" & Cb(7 downto 0);
--dinCr1 <= "0000" & Cr(7 downto 0);
dinCb1 <= "0000" & Cb(7 downto 0);
dinCr1 <= "0000" & Cr(7 downto 0);
elsif LineAbsToCompress(0) = '0' and ColumnToCompress(0) = '1' then --element (0,1)
Cb := (Cb(7) & Cb(7) & Cb(7) & Cb(7 downto 0)) + (doutCb(7) & doutCb(7 downto 0));
Cr := (Cr(7) & Cr(7) & Cr(7) & Cr(7 downto 0)) + (doutCr(7) & doutCr(7 downto 0));
dinCb1 <= "000" & Cb(8 downto 0);
dinCr1 <= "000" & Cr(8 downto 0);
elsif LineAbsToCompress(0) = '1' and ColumnToCompress(0) = '0' then --element (1,0)
Cb := (Cb(7) & Cb(7) & Cb(7) & Cb(7 downto 0)) + (doutCb(8) & doutCb(8 downto 0));
Cr := (Cr(7) & Cr(7) & Cr(7) & Cr(7 downto 0)) + (doutCr(8) & doutCr(8 downto 0));
dinCb1 <= "00" & Cb(9 downto 0);
dinCr1 <= "00" & Cr(9 downto 0);
else --element (1,1) before, we have added directly, now we add and write the average of the 4 pixels, so as to not lose precission
Cb := (Cb(7) & Cb(7) & Cb(7) & Cb(7 downto 0)) + (doutCb(9) & doutCb(9 downto 0));
Cr := (Cr(7) & Cr(7) & Cr(7) & Cr(7 downto 0)) + (doutCr(9) & doutCr(9 downto 0));
dinCb1 <= "0000" & Cb(9 downto 2);
dinCr1 <= "0000" & Cr(9 downto 2);
 
--next lines are for debugging purposes (instead of the last if,elsifs and else to write just
--one chrominance value for Cb and Cr instead of averaging)
--Cb := (Cb(7) & Cb(7) & Cb(7) & Cb(7 downto 2)) + (doutCb(7) & doutCb(7 downto 0));
--Cr := (Cr(7) & Cr(7) & Cr(7) & Cr(7 downto 2)) + (doutCr(7) & doutCr(7 downto 0));
--dinCb1 <= "0000" & Cb(7 downto 0);
--dinCr1 <= "0000" & Cr(7 downto 0);
--weCb1 <= '1';
--weCr1 <= '1';
--else
--weCb1 <= '0';
--weCr1 <= '0';
end if;
weY1 <= '1';
weCb1 <= '1';
weCr1 <= '1';
 
if (LineToCompress(2 downto 0) = "111") then
if (ColumnToCompress(2 downto 0) = "111") then --we've just written pixel 64 of the block [of 64 pixels]
MakeDCT <= '1';
else
MakeDCT <= '0';
end if;
else
MakeDCT <= '0';
end if;
if (ColumnToCompress = ImgColumns) then
LineToCompress <= LineToCompress + 1;
LineAbsToCompress <= LineAbsToCompress + 1;
ColumnToCompress <= (others => '0');
else
ColumnToCompress <= ColumnToCompress + 1;
end if;
Baton := 3;
when 3 => --with this dummy cycle we give time to CompressingInt to rise, if it must, and make the following "if" work fine
weY1 <= '0';
weCb1 <= '0';
weCr1 <= '0';
MakeDCT <= '0';
Baton := 0;
end case;
--MakeDCT is rised in cycle 0, in cycle 1 it is read by the process JPEG which then rises CompressingInt
--and in cycle 2 this process reads CompressingInt='1' so that in that intermediate cycle 1 is when
--the case "when 3 =>" gets executed and the following "if", in which MakeDCT is 1 and CompressingInt is 0
--but it is going to be inverted.
if (Baton = 0 and MakeDCT = '0' and CompressingInt = '0') then --it is fine!
if (LineAbsToCompress > ImgLines) then
Compressing <= '0'; --Compression has ended, image ready
LineAbsToCompress <= (others => '0'); --absolutely incredible, without this line it will only work for the
--first image (it took me much time to debug this one, folks)
end if;
ProcessingRGB <= '0';
end if;
end if;
end process RGB2YCbCr;
 
JPEG : process (reset, clk)
--in this process data are sent to the DCT1 component, its output is quantized and written back
--in the same addresses where they were read (buffers) to be sent to DCT1.
variable Columna : std_logic_vector(9 downto 0);
variable Linea : std_logic_vector(3 downto 0); --0 to 15
variable Bloque : std_logic_vector(1 downto 0);
variable DCTQ : std_logic_vector(24 downto 0); --for multiplication of the result of the DCT with numerator of Q
variable Base : std_logic_vector(8 downto 0); --to access Q coefficients from the tables in ROM
variable BaseH : std_logic_vector(8 downto 0); --for the Huffman tables ROM
variable BaseQ : std_logic_vector(8 downto 0); --for the Q tables ROM
variable HuffmanWord : std_logic_vector(22 downto 0);
variable HuffmanWordPos : integer range -1 to 22;
variable LumaBlock : std_logic;
variable Elemento : std_logic_vector(1 downto 0);
variable Coeficiente : integer range 0 to 63; --indicates which is the next coefficient to be processed by Huffman
variable PrevDC : std_logic_vector(11 downto 0); --previous value of luminance DC
variable Coef : std_logic_vector(11 downto 0); --current coefficient's value
variable LastBlockDCY : std_logic_vector(11 downto 0);
variable LastBlockDCCb : std_logic_vector(11 downto 0);
variable LastBlockDCCr : std_logic_vector(11 downto 0);
variable IniDC : std_logic;
variable FirstDC : std_logic;
variable GetPrevDC : std_logic;
variable ColBk : std_logic_vector(9 downto 0);
variable LinBk : std_logic_vector(3 downto 0); --0 to 15
variable Hlength : integer range 0 to 15;
variable ZeroRun : integer range 0 to 16;
variable ZRL : integer range 0 to 3;
variable WriteZRL : std_logic;
variable Cat : integer range 0 to 11;
variable Sign : std_logic;
variable Primera : std_logic;
variable HeaderFinal : std_logic; --to know if we've already written EOI (End Of Image)
variable VarTamImg : std_logic_vector(10 downto 0);
variable DatoHeader : integer range 0 to 7 := 0; --to know where we are in the writing of the header's image size
variable TempCompDC : std_logic_vector(14 downto 0);
variable AddVal : std_logic_vector(11 downto 0);
variable QDC : std_logic_vector(12 downto 0);
--pragma translate_off
--I couldn't find any testbench where I could read or write binary files and the ones I found were overcomplex
--so I experimented and found this to be a useful way to do it without any complications.
type ByteT is (c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,c30,c31,c32,c33,c34,c35,c36,c37,c38,c39,c40,c41,c42,c43,c44,c45,c46,c47,c48,c49,c50,c51,c52,c53,c54,c55,c56,c57,c58,c59,c60,c61,c62,c63,c64,c65,c66,c67,c68,c69,c70,c71,c72,c73,c74,c75,c76,c77,c78,c79,c80,c81,c82,c83,c84,c85,c86,c87,c88,c89,c90,c91,c92,c93,c94,c95,c96,c97,c98,c99,c100,c101,c102,c103,c104,c105,c106,c107,c108,c109,c110,c111,c112,c113,c114,c115,c116,c117,c118,c119,c120,c121,c122,c123,c124,c125,c126,c127,c128,c129,c130,c131,c132,c133,c134,c135,c136,c137,c138,c139,c140,c141,c142,c143,c144,c145,c146,c147,c148,c149,c150,c151,c152,c153,c154,c155,c156,c157,c158,c159,c160,c161,c162,c163,c164,c165,c166,c167,c168,c169,c170,c171,c172,c173,c174,c175,c176,c177,c178,c179,c180,c181,c182,c183,c184,c185,c186,c187,c188,c189,c190,c191,c192,c193,c194,c195,c196,c197,c198,c199,c200,c201,c202,c203,c204,c205,c206,c207,c208,c209,c210,c211,c212,c213,c214,c215,c216,c217,c218,c219,c220,c221,c222,c223,c224,c225,c226,c227,c228,c229,c230,c231,c232,c233,c234,c235,c236,c237,c238,c239,c240,c241,c242,c243,c244,c245,c246,c247,c248,c249,c250,c251,c252,c253,c254,c255);
subtype Byte is ByteT; --well, maybe I oversubtyped it, hehe
type ByteFileType is file of Byte;
 
file outfile : ByteFileType open write_mode is "image.jpg";
variable Pixel : Byte;
variable bufer: LINE;
variable Header : std_logic_vector(4855 downto 0) := X"FFD8FFE000104A46494600010200000100010000FFC00011080020004003012200021101031101FFDB008400100B0C0E0C0A100E0D0E1211101318281A181616183123251D283A333D3C3933383740485C4E404457453738506D51575F626768673E4D71797064785C656763011112121815182F1A1A2F634238426363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363FFC401A20000010501010101010100000000000000000102030405060708090A0B100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FA0100030101010101010101010000000000000102030405060708090A0B1100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00";
--pragma translate_on
 
begin
if (reset = '1') then
CompressingInt <= '0';
Linea := (others => '0');
Columna := (others => '0');
Bloque := "00";
StepV <= 0;
weY2 <= '0';
weCb2 <= '0';
weCr2 <= '0';
Base := (others => '0');
BaseH := (others => '0');
BaseQ := (others => '0');
DCTQ := (others => '0');
DIND <= (others => '0');
ND <= '0';
--Huffmanear <= '0';
PrevDC := (others => '0');
Coeficiente := 0;
HuffmanWord := (others => '0');
HuffmanWordPos := 22; --first free LSB (HuffmanWord's MSB)
Elemento := "00";
IniDC := '1';
GetPrevDC := '1';
FirstDC := '1';
Save <= '0';
addri <= "0000000000101100"; --first Table
addribk <= "0000001001011110"; --pointer to last Header byte
addrH <= (others => '0');
addrQ <= (others => '0');
addrCb2 <= (others => '0');
addrCr2 <= (others => '0');
addrY2 <= (others => '0');
din <= (others => '0');
we <= '0';
dinY2 <= (others => '0');
dinCr2 <= (others => '0');
dinCb2 <= (others => '0');
Done <= '0';
Cat := 0;
ZRL := 0;
Coef := (others => '0');
ColBk := (others => '0');
LinBk := (others => '0');
Sign := '0';
ZeroRun := 0;
Primera := '0';
LumaBlock := '0';
NDe <= '0';
HeaderFinal := '0';
DatoHeader := 0;
VarTamImg := (others => '0');
WriteAdditionalBits <= '0';
TempCompDC := (others => '0');
WriteZRL := '0';
LastBlockDCY := (others => '0');
LastBlockDCCb := (others => '0');
LastBlockDCCr := (others => '0');
AddVal := (others => '0');
QDC := (others => '0');
WriteTables <= '0';
TableData <= (others => '0');
Table <= '0';
addrTablaQ <= (others => '0');
ZRLing <= '0';
RFDInt <= '0';
RFDIntData <= (others => '0');
elsif (clk = '1' and clk'event) then
if CompressImage = '1' then
FirstDC := '1';
IniDC := '1';
HeaderFinal := '0';
GetPrevDC := '1';
PrevDC := (others => '0'); --initialized to zero at the beginning of the image
HuffmanWord := (others => '0');
HuffmanWordPos := 22;
Save <= '0';
DatoHeader := 0;
WriteAdditionalBits <= '0';
HeaderFinal := '0';
WriteTables <= '1';
TableData <= (others => '0');
Table <= '0';
addribk <= "0000001001011110"; --pointer to the Header's last byte
addri <= "0000000000101100"; --first Table
case Compression is
when "00" => --low quality
BaseQ := "100000000";
when "01" => --medium quality
BaseQ := "010000000";
when others => --10 high quality
BaseQ := "000000000";
end case;
addrTablaQ <= BaseQ; --ready first data
 
CompressingInt <= '0';
Bloque := "00";
StepV <= 0;
weY2 <= '0';
weCb2 <= '0';
weCr2 <= '0';
Base := (others => '0');
BaseH := (others => '0');
ND <= '0';
Coeficiente := 0;
we <= '0';
Done <= '0';
ZRLing <= '0';
RFDInt <= '0';
RFDIntData <= (others => '0');
--pragma translate_off
Columna := ('0' & ImgLines) + 1;
for i in 606 downto 563 loop
case i is
when (606-25) => --MSByte of size Y
Pixel := ByteT'val(conv_integer("0000000" & Columna(8)));
when (606-26) => --LSByte of size Y
Pixel := ByteT'val(conv_integer(Columna(7 downto 0)));
Columna := ImgColumns + 1;
when (606-27) => --MSByte of size X
Pixel := ByteT'val(conv_integer("000000" & Columna(9 downto 8)));
when (606-28) => --LSByte of size X
Pixel := ByteT'val(conv_integer(Columna(7 downto 0)));
when others =>
Pixel := ByteT'val(conv_integer(Header(8*i+7 downto 8*i)));
end case;
write(outfile, Pixel);
end loop;
--pragma translate_on
end if;
we <= '0'; --after the ones that rise it
if WriteTables = '1' then --write in memory the quantization tables for the selected compression level
if Table = '0' then --the start of Table Q of value "00h" is in position 2Bh (43=101011)
addri <= "0000000000101100" + ('0' & TableData);
else--the start of Table Q of value "01h" is in position 6Ch (108=1101100)
addri <= "0000000001101101" + ('0' & TableData);
end if;
din <= doutTablaQ;
addrTablaQ <= addrTablaQ + 1;
if addrTablaQ /= BaseQ then --first coefficient, not written because we'll have it also in next cycle
--until second coefficient is loaded
we <= '1';
TableData <= TableData + 1;
--pragma translate_off
Pixel := ByteT'val(conv_integer(doutTablaQ));
write(outfile, Pixel);
--pragma translate_on
end if;
if TableData = "111111" then
if Table = '1' then --we are over
--pragma translate_off
for i in 433 downto 0 loop
Pixel := ByteT'val(conv_integer(Header(8*i+7 downto 8*i)));
write(outfile, Pixel);
end loop;
--pragma translate_on
 
WriteTables <= '0';
addrTablaQ <= (others => '0'); --so that it doesn't stay in a non-existent address
else
Table <= '1';
--pragma translate_off
Pixel := ByteT'val(1); --points to the start of Table 01
write(outfile, Pixel);
--pragma translate_on
end if;
end if;
end if;
if (MakeDCT = '1' or CompressingInt = '1') then --MakeDCT lasts only one cycle, but CompressingInt is high the following ones
if MakeDCT = '1' then
HeaderFinal := '0';
--write the image size, now that we know it, in the header as at the least we must do
--4 DCTs in an image, there won't be any problem if image size writing is done in four steps
--or if it is repeated throughout the image's processing
case DatoHeader is
when 0 => --MSByte of ImgLines+1
addri <= "0000000000011001"; --position 0 of the two bytes of size Y (lines)
we <= '1';
VarTamImg := ("00" & ImgLines) + 1;
din <= "000000" & VarTamImg(9 downto 8);
DatoHeader := 1;
when 1 => --LSByte of ImgLines+1
addri <= "0000000000011010";
we <= '1';
din <= VarTamImg(7 downto 0);
DatoHeader := 2;
when 2 => --MSByte of ImgColumns+1
addri <= "0000000000011011"; --position 0 of the two bytes of size X (columns)
we <= '1';
VarTamImg := ('0' & ImgColumns) + 1;
din <= "00000" & VarTamImg(10 downto 8);
DatoHeader := 3;
when 3 => --LSByte of ImgColumns+1
addri <= "0000000000011100";
we <= '1';
din <= VarTamImg(7 downto 0);
DatoHeader := 4;
when 4 to 7 => --it's been already written, don't do anything(we put 8 DatoHeader because in the last
--block when we pass to the next image, ImgLines is zero and it is wrongly written)
we <= '0';
if DatoHeader = 7 then
DatoHeader := 0;
else
DatoHeader := DatoHeader + 1;
end if;
end case;
CompressingInt <= '1';
if ColumnToCompress = "0000000000" then --we've changed line, careful
--because we have to process the last block of the previous line
Linea := (not LineToCompress(3)) & "000";
Columna := ImgColumns(9 downto 3) & "000";
else
Linea := LineToCompress(3) & "000";
Columna := (ColumnToCompress(9 downto 3) - 1) & "000";
end if;
Bloque := ColumnToCompress(1 downto 0);
StepV <= 0;
weY2 <= '0';
weCb2 <= '0';
weCr2 <= '0';
Coeficiente := 0;
Save <= '0';
IniDC := '1';
GetPrevDC := '1';
WriteAdditionalBits <= '0';
else
we <= '0';
LumaBlock := Bloque(1) nor Bloque(0); --it is 1 if we are dealing with luminance component
--It is necessary that Base be here so that it changes when Bloque changes in the "if" of Done in the last image's block
if Bloque = "00" then --Q Coefficients of Table 0 (luminance)
BaseH := (others => '0'); --address 0 of Huffman Luminance Table
case Compression is
when "00" => --Low Quality
Base := "100000000";
when "01" => --Medium Quality
Base := "010000000";
when others => --10 High Quality
Base := "000000000";
end case;
else --Q Coefficients of Table 1 (chroma)
BaseH := "010110000"; --address 0 of Huffman Chrominance Table
case Compression is
when "00" => --Low Quality
Base := "101000000";
when "01" => --Medium Quality
Base := "011000000";
when others => --10 High Quality
Base := "001000000";
end case;
end if;
case StepV is
when 0 => --with the first data to let addrXX2 load and have the data in memory
weY2 <= '0';
weCb2 <= '0';
weCr2 <= '0';
if CompressingInt = '1' and Done = '0' then --Done=0 cause in case it is a Y block (but not the fourth (the last)) coming from StepV=3
StepV <= 1;
else
StepV <= 0;
end if;
NDe <= '0';
RFDInt <= '0';
when 1 => --Feeding of DCT1 with 64 pixels
if RFD = '1' then --DCT1 ready for data (RFD)
NDe <= '1';
ND <= NDe; --this way we delay ND one cycle to synchronize data
if RFDInt = '0' then
case Bloque is
when "00" => --block Y
DIND <= doutY(7 downto 0);
when "01" => --block Cb
DIND <= doutCb(7 downto 0);
when others => --can only be block Cr
DIND <= doutCr(7 downto 0);
end case;
else
DIND <= RFDIntData; --to recover the "lost" cycle because RFD was 0 (if the DCT was such that RFD were 0 for more than a cycle it would be necessary to change this part)
RFDInt <= '0';
end if;
if Columna(2 downto 0) = "111" then
Columna := Columna(9 downto 3) & "000";
Linea := Linea + 1;
if Linea(2 downto 0) = "000" then --we've finished this StepV, now we'll wait for the results
StepV <= 2; --we shall go to StepV 2 with the first column of the block
Linea(3) := not Linea(3); --makes it rest in current block
Primera := '1'; --to not let StepV 2 change Linea or Column in its 1st cycle because they already have adequate values
end if;
else
Columna := Columna + 1;
end if;
else
--to not lose the just read pixel (rememer that reads are ahead of their time!!)
RFDInt <= '1';
case Bloque is
when "00" => --block Y
RFDIntData <= doutY(7 downto 0);
when "01" => --block Cb
RFDIntData <= doutCb(7 downto 0);
when others => --can only be block Cr
RFDIntData <= doutCr(7 downto 0);
end case;
--ND <= '0';
end if;
weY2 <= '0';
weCb2 <= '0';
weCr2 <= '0';
addrQ <= Base; --DC Coefficient's Q (Base + Linea*8 + Columna)
QDC := (others => '0');
when 2 => --we receive the data, quantize it, truncate it and save them back to the buffer
--watch out because DCT1 outputs data column-wise (feeding was row-wise)
NDe <= '0'; --it stayed high while sending data byte
ND <= NDe;
case Bloque is --needed to send the last data of the block (it is alright!!!)
when "00" => --block Y
DIND <= doutY(7 downto 0);
when "01" => --block Cb
DIND <= doutCb(7 downto 0);
when others => --can only be block Cr
DIND <= doutCr(7 downto 0);
end case;
if RDY = '1' then --output data ready!!
if QDC /= 0 then
DCTQ := MultiplierQ(DOUTD(14 downto 3), QDC);
QDC := (others => '0');
else
DCTQ := MultiplierQ(DOUTD(14 downto 3), DOUTQ); --multiply the DCT coefficient times Qyx fraction's numerator
end if;
--if DCTQ(24) = '0' then --it is positive, let's round
DCTQ(24 downto 14) := DCTQ(24 downto 14) + DCTQ(13); --round to nearest integer
--end if;
--if DCTQ(24 downto 13) = "111111111111" then --it is less or equal than -0.5, roung to 0
-- DCTQ(24 downto 13) := "000000000000"; --or else it will be read as -1
--end if;
case Bloque is --the "+ DCTQ(13)" is the nearest integer round!
when "00" => --block Y
dinY2 <= DCTQ(24) & DCTQ(24 downto 14);-- + DCTQ(13); --we divide (shifting right) by the general Q coefficient denominator (16384) and save the quantized coefficient
--sign-extension
weY2 <= '1';
when "01" => --block Cb
dinCb2 <= DCTQ(24) & DCTQ(24 downto 14);-- + DCTQ(13); --we divide (shifting right) by the general Q coefficient denominator (16384) and save the quantized coefficient
weCb2 <= '1';
when others => --can only be block Cr
dinCr2 <= DCTQ(24) & DCTQ(24 downto 14);-- + DCTQ(13); --we divide (shifting right) by the general Q coefficient denominator (16384) and save the quantized coefficient
weCr2 <= '1';
end case;
--write column-wise
if Linea(2 downto 0) = "111" and Primera = '0' then --have we reached this line's end?
--Primera is used for the first cycle of StepV2 in which Columna and Linea arrive with the right value
--so they need not be changed in order to get the correct address
Linea := Linea(3) & "000";
Columna := Columna + 1;
else
if Primera = '1' then
Primera := '0';
else
Linea := Linea + 1;
if Linea(2 downto 0) = "111" and Columna(2 downto 0) = "111" then --we have finished this StepV, now we must Huffman encode
StepV <= 3;
end if;
end if;
end if;
--the following code is because we must load one cycle early the addrQ so that in the
--current cycle we can have the right Q coefficient for current Linea and Columna values
if Linea(2 downto 0) = "110" then --have we reached the end?
--next coeff. is Linea 0 of the Coeff. Table and Columna is current plus one
addrQ <= Base + Columna(2 downto 0) + 2; --Base + Linea*8 + Columna --> remember coefficient table is 8x8
else
--next coeff is next Linea of the Coeff. Table and current Columna
addrQ <= Base + ((Linea(2 downto 0) + 2) & "000") + Columna(2 downto 0); --Base + Linea*8 + Columna
end if;
else
--during Latency cycles we will be here waiting until RDY is 1
--and also every X cycles when RDY becomes 0 for one cycle
if QDC = 0 and addrQ = Base then --only happens when we enter this StepV from the previous one
QDC := DOUTQ; --save the DC value because Q reading must be ahead by two cycles now
addrQ <= Base + "1000"; --Base + Linea*8 + Columna (Linea=1, Columna=0)
end if;
weY2 <= '0';
weCr2 <= '0';
weCb2 <= '0';
end if;
when 3 =>
weY2 <= '0';
weCr2 <= '0';
weCb2 <= '0';
--Make the "pointers" Linea and Columna point to the beginning of the next block
--must do it here because in the last cycle of StepV2, when StepV becomes 3, Linea and Columna
--must maintain their value
Linea := Linea(3) & "000";
Columna := Columna + 1;
if LumaBlock = '1' then --if we are processing the luminance block we can only save it when we have processed the 4 ones
--that compose the 2x2 block of subsampling, there is no problem with the order of the chroma ones because these ones too
--are saved when we have averaged four and that is controlled by the process RGB2YCbCr
if Linea(3) = '1' and Columna(3) = '0' then --checked, it is alright (remember it points to the next block)
StepV <= 4;
Elemento := "00"; --process the first square (8x8 block) of the 2x2 luminance block (16x16 pixels, 2x2 squares)
--Ready Linea and Columna to read element 00 that Huffman will receive
Linea := (others => '0');
Columna := (Columna(9 downto 4) - 1) & "0000";
else --the three first squares of the 2x2 luminance block are not sent to Huffman yet (subsampling requirements)
StepV <= 0;
Done <= '1';
end if;
else
Columna := Columna - 1;
Columna := Columna(9 downto 3) & "000"; --it is alright, because Columna arrives already adjusted to Cb and Cr.
StepV <= 4;
end if;
WriteAdditionalBits <= '0';
when 4 => --with this dummy cycle we give time to the memory to give us address 0
--for the DC coefficient
weY2 <= '0';
weCr2 <= '0';
weCb2 <= '0';
Save <= '0'; --just in case we left it high in last step
we <= '0';
StepV <= 5;
when 5 => --Linea and Columna point to the beginning of the block
 
--If we change Linea and/or Columna in cycle 0 of this section, then the new address will
--be sent to memory in cycle 1 and in cycle 2 doutX will have the asked data, so careful!!
case Bloque is
when "00" => --block Y
Coef := doutY;
when "01" => --block Cb
Coef := doutCb;
when others => --can only be block Cr
Coef := doutCr;
end case;
 
we <= '0';
if Done = '0' then --this way it does not go to look for the DC when we change Block (upsetting FirstDC)
if Save = '0' then
if WriteAdditionalBits = '0' then
if Coeficiente = 0 then
--The previous component is read from the buffer varying Linea and Columna
if IniDC = '1' then --we've not yet obtained the previous DC to calculate the difference
if Linea = "0000" and Columna = "000000000" and FirstDC = '1' and GetPrevDC = '1' then --must do it this way
--or else the luminance, which has 4 blocks in its first Huffmanear takes DC=0 for all
--GetPrevDC = 1 is so that execution doesnt get here if in the previous cycle GetPrevDC became zero in the bottom "if"
--and put Linea and Columna to zero
--we are in the first block of the image, PrevDC is zero
if Bloque = "10" then --if we are in the last, we zero it
FirstDC := '0'; --because it has already been used by the three components (Y,Cb,Cr)
end if;
PrevDC := (others => '0');
IniDC := '0';
else
if GetPrevDC = '1' then
ColBk := Columna; --save the values of Linea and Columna
LinBk := Linea;
--Must obtain the quantized DC coefficient of the last processed block
--as stated by specification, but actually the last block is indicated by MCU
if Columna(9 downto 3) = "0000000" then --first block of the row?
if LumaBlock = '1' then
if Elemento = "00" then
--Remember that DCTs are done when only the last line of all is left to be written in the block
--so the DC of the previous block has already been overwritten, that's why we use LastBlockDCY
PrevDC := LastBlockDCY;
IniDC := '0'; --this way we skip the next StepV
else --Elemento 10 need the DC of Elemento 01
Linea(3) := '0';
Columna(3) := '1';
end if;
else --in chrominance ImgColumns has half the image's columns!
if Bloque = "01" then --block Cb
PrevDC := LastBlockDCCb;
else --10 = block Cr
PrevDC := LastBlockDCCr;
end if;
IniDC := '0';
end if;
else
if LumaBlock = '1' then
case Elemento is
when "00" => --DC of previous element 11
Columna := (Columna(9 downto 3)-1) & "000";
Linea(3) := '1';
when "01" => --DC of element 00
Columna(3) := '0';
Linea(3) := '0';
when "10" => --DC of element 01
Columna(3) := '1';
Linea(3) := '0';
when others => --11 DC of element 10
Columna(3) := '0';
Linea(3) := '1';
end case;
else
Columna := (Columna(9 downto 3) - 1) & "000"; --first column of previous block
end if;
end if;
StepV <= 4; --wait one cycle for PrevDC
GetPrevDC := '0';
else
GetPrevDC := '1'; --we rise it for the next block
IniDC := '0';
PrevDC := Coef;
Linea := LinBk;
Columna := ColBk;
StepV <= 4; --wait one cycle to get back the current DC component to operate with it
end if;
end if;
else --IniDC = '0' that is, we now have the PrevDC
GetPrevDC := '1'; --we rise it for the second block after the first one of the image
--in this "if" we see if this is the last block in the buffer and in that case
--save its DC component
if LumaBlock = '1' then
if Columna(9 downto 3) = ImgColumns(9 downto 3) and Elemento="11" then
LastBlockDCY := Coef;
end if;
else
if Columna(9 downto 3) = ImgColumns(9 downto 4) then
if Bloque = "01" then --block Cb
LastBlockDCCb := Coef;
else --block Cr
LastBlockDCCr := Coef;
end if;
end if;
end if;
Coef := Coef - PrevDC; --this IS DIFF
--And I cite the standard: "When DIFF is negative, the SSSS low order bits
-- of (DIFF-1) are appended. Note that the MSB of the appended bit sequence is 0
-- for negative differences and 1 for positive differences."
-- So it was this s***** paragraph's misreading the one that got me a good headache
 
Sign := not Coef(11); --the first additional bit after the category is this one
Cat := GetCategory(Coef); --we send Coeficiente and it returns its category SSSS
if Coef(11) = '1' then --it is negative, must write DIFF-1 (JPEG standard requirement)
AddVal := Coef - 1; --must use AddVal because Coef is overwritten every cycle
else --it is positive, must write DIFF
AddVal := Coef; --must use AddVal because Coef is overwritten every cycle
end if;
TempCompDC := CompressDC(Cat, LumaBlock);
HuffmanWord := AppendHuffmanWordL (HuffmanWord, TempCompDC,conv_integer(TempCompDC(14 downto 11))+1, HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - conv_integer(TempCompDC(14 downto 11)) - 1;
--pragma translate_off
--the following lines are for debugging, comment them out at will
case Bloque is
when "00" => WRITELINE(DebugY,bufer);
when "01" => WRITELINE(DebugCb,bufer);
when others => WRITELINE(DebugCr,bufer);
end case;
WRITE(bufer,now);WRITE(bufer,espacios);
WRITE(bufer,strLinea);WRITE(bufer,Linea);WRITE(bufer,espacios);
WRITE(bufer,strColumna);WRITE(bufer,Columna);
case Bloque is
when "00" => WRITE(bufer,espacios);WRITE(bufer,strElemento);WRITE(bufer,Elemento);WRITELINE(DebugY,bufer);
when "01" => WRITELINE(DebugCb,bufer);
when others => WRITELINE(DebugCr,bufer);
end case;
WRITE(bufer,TempCompDC(conv_integer(TempCompDC(14 downto 11)) downto 0));WRITE(bufer,espacio);
--pragma translate_on
Save <= '1';
WriteAdditionalBits <= '1';
end if;
else --Coeficiente /= 0
if Coef = "000000000000" then
ZeroRun := ZeroRun + 1; --if we get to 16 then we have to write a F/0 (ZRL)
if ZeroRun = 16 then --but we can not write it unless we find later a non-zero AC coefficient
--because if all the following coefficients are zero we have to write instead and EOB (End Of Block)
ZRL := ZRL + 1;
ZeroRun := 0;
end if;
if Coeficiente = 63 then
Save <= '1';
else
Coeficiente := Coeficiente + 1;
StepV <= 4; --to give time to load the next coefficient
end if;
else --the coefficient is not zero
if ZRL > 0 then
--must write in HuffmanWord all the previous ZRLs
Save <= '1'; --before writing the data of the current non-zero coefficient
ZRLing <= '1'; --so that it doesn't skip the current coefficient when it finishes writing the preceding ZRLs
else
if addrH = "000000000" then --this way we know if we still have to ask the ROM for the Huffman code
Sign := not Coef(11); --the first addditional bit after category is this one
Cat := GetCategory(Coef); --we send the coefficient and it returns the category SSSS
if Coef(11) = '1' then --it is negative, we must write DIFF-1 (JPEG standard requirement)
AddVal := Coef - 1; --we have to use AddVal because Coef is overwritten every cycle
else --it is positive, we must write DIFF
AddVal := Coef; --we have to use AddVal because Coef is overwritten every cycle
end if;
--Reading of Huffman_ROM to obtain the code of the coefficient and add it to HuffmanWord
--ZeroRun and Cat tell us which code we are looking for
addrH <= BaseH + To_std_logicvpor11(ZeroRun) + ("00000" & To_std_logicv(Cat));
ZeroRun := 0; --of couse, once used it must be zeroed!
StepV <= 4; --this way we give time to load the Huffman value from memory
else --now we have the Huffman code that the Huffman_ROM gives us and can now write it
--remember that the 4 MSBs of this code mean the length of the code in the 16 LSBs minus one!!
Hlength := conv_integer(doutH(19 downto 16));
HuffmanWord := AppendHuffmanWordL (HuffmanWord, doutH, Hlength+1, HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - Hlength - 1;
--pragma translate_off
WRITE(bufer,doutH(conv_integer(doutH(19 downto 16)) downto 0));WRITE(bufer,espacio);
--pragma translate_on
Save <= '1';
WriteAdditionalBits <= '1';
end if;
end if;
end if;
end if; --if Coeficiente = 0
else --WriteAdditionalBits = '1'
--we can now write the Additional Bits, starting by the sign
case Cat is
when 0 =>
null;
when 1 =>
HuffmanWord := AppendHuffmanWord (HuffmanWord, Sign, HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 1;
--pragma translate_off
WRITE(bufer,Sign);
--pragma translate_on
when others =>
HuffmanWord := AppendHuffmanWord (HuffmanWord, Sign, HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 1;
--Coef := GetMagnitude(Coef, Cat);
HuffmanWord := AppendHuffmanWordL (HuffmanWord, AddVal, Cat-1, HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - Cat + 1;
 
--pragma translate_off
WRITE(bufer,Sign);WRITE(bufer,espacio);
WRITE(bufer,AddVal(Cat-2 downto 0));
--pragma translate_on
end case;
--pragma translate_off
WRITE(bufer,puntoycoma);
--pragma translate_on
addrH <= (others => '0'); --this way we know if we have obtained the Huffman code and may save it
Save <= '1';
WriteAdditionalBits <= '0';
end if; --if WriteAdditionalBits
else --Save = '1'
if (ZRL > 0 or (ZeroRun /=0 and Coeficiente=63 and Coef="000000000000")) and WriteZRL = '0' then --there can be at most 3 ZRLs in a block
--first we have to write the ZRL F/0 that lie between the current coefficient and the last non-zero
--so that these get written in HuffmanWord before the AC coefficient that follows them
--in the previous "if", in which we write the coefficients, when we find one non-zero and ZRL>0
--the first thing it will do is to rise Save to come here to fill HuffmanWord without augmenting Coeficiente
if Coeficiente = 63 and Coef="000000000000" then --there is no need to write the ZRLs, only EOB (which means all to follow are zeros)
if LumaBlock = '1' then --EOB of luminance
HuffmanWord := AppendHuffmanWord (HuffmanWord, "1010", HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 4;
--pragma translate_off
WRITE(bufer, string'("1010 (EOB)"));
--pragma translate_on
else --EOB of chrominance
HuffmanWord := AppendHuffmanWord (HuffmanWord, "00", HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 2;
--pragma translate_off
WRITE(bufer, string'("00 (EOB)"));
--pragma translate_on
end if;
--pragma translate_off
case Bloque is
when "00" => WRITELINE(DebugY,bufer);
when "01" => WRITELINE(DebugCb,bufer);
when others => WRITELINE(DebugCr,bufer);
end case;
--pragma translate_on
ZRL := 0;
ZeroRun := 0;
else --if else, we write ZRLs until ZRL=0
if LumaBlock = '1' then
HuffmanWord := AppendHuffmanWord (HuffmanWord, "11111111001", HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 11;
--pragma translate_off
WRITE(bufer, string'("11111111001 (ZRL)"));WRITE(bufer,puntoycoma);
--pragma translate_on
else
HuffmanWord := AppendHuffmanWord (HuffmanWord, "1111111010", HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 10;
--pragma translate_off
WRITE(bufer, string'("1111111010 (ZRL)"));WRITE(bufer,puntoycoma);
--pragma translate_on
end if;
ZRL := ZRL - 1;
WriteZRL := '1';
end if;
else --ZRL=0
--Code to save in buffer_img whatever we have in HuffmanWord in several cycles, one byte at a time,
--if necessary, until HuffmanWordPos becomes >14 (REMEMBER that this variable points to the
--first empty LSB! so that HuffmanWord will be occupied with data in (22 downto HuffmanWordPos+1))
if HuffmanWordPos < 15 then --there are still byte/s to save
if addribk < MaxImageSize then --the buffer size, so that it doesn't become 0 and overwrite the Header
we <= '1';
if HeaderFinal = '1' and HuffmanWordPos = 14 then --last byte to write in the file
--is +2 because +1 is the last byte of info for address (starts at address 0!) and plus 2 is
--the file size starting from 1
addri <= addribk + 2; --at the end, addr will be addri and its value will be the JPEG compressed image size in bytes
end if;
addribk <= addribk + 1; --always add 1, the writing of the Header will leave it pointing
--at the last byte of the Header so that there won't be any problem
--and at the end of all the compression, addr will be the numerical size of the image because
--it will point at the last position of information plus one (remember data starts at 0)
din <= HuffmanWord(22 downto 15);
--pragma translate_off
Pixel := ByteT'val(conv_integer(HuffmanWord(22 downto 15)));
write(outfile, Pixel);
if HeaderFinal = '1' and HuffmanWordPos = 14 then
File_Close(outfile);
end if;
--pragma translate_on
end if;
 
 
if HuffmanWord(22 downto 15) = "11111111" and HeaderFinal = '0' then --if we ever write FFh it must be followed by 00h
--but in the case of the EOI marker or we will spoil it!
HuffmanWord := "00000000" & HuffmanWord(14 downto 0);
else
HuffmanWord := HuffmanWord(14 downto 0) & "00000000";
HuffmanWordPos := HuffmanWordPos + 8; --free up the 8 written LSBs
end if;
else --HuffmanWordPos > 14 --can't save more
if WriteZRL = '0' then
if Coeficiente = 63 and HeaderFinal = '0' and Bloque = "10" and (LineAbsToCompress > ImgLines) then --last block of all
--must write whatever remains in HuffmanWord and, if not byte aligned, then make one-padding
--and write EOI marker FFD9h
if HuffmanWordPos /= 22 then
HuffmanWord := AppendHuffmanWord (HuffmanWord, "11111111", HuffmanWordPos);
--we write eight ones just to make sure, the extra ones will get overwritten in next cycle by the EOI header
--because we make HuffmanWordPos point the first byte:
HuffmanWordPos := 14; --first free LSB
else --we make first the 1 bit padding and then later the EOI header to not saturate the HuffmanWord variable
HuffmanWord := AppendHuffmanWord (HuffmanWord, "1111111111011001", HuffmanWordPos);
HuffmanWordPos := HuffmanWordPos - 16; --first free LSB
HeaderFinal := '1';
--pragma translate_off
case Bloque is
when "00" => WRITELINE(DebugY,bufer);
when "01" => WRITELINE(DebugCb,bufer);
when others => WRITELINE(DebugCr,bufer);
end case;
--pragma translate_on
end if;
else
Save <= '0';
if ZRLing = '1' then --if not here, it will skip one coefficient after writing the previous ZRLs
ZRLing <= '0'; --because WriteZRL will be 0, ZRL also and WriteAdditionalBits will be 0 and Coeficiente /=63
else
if WriteAdditionalBits = '0' then
if Coeficiente = 63 then --we can only get to Coefficient 63 from here if we have processed the whole block
Coeficiente := 0; --for the next block
IniDC := '1';
if LumaBlock = '1' then
--must process the different elements
Elemento := Elemento + 1;
case Elemento is
when "00" => --we've finished the 2x2 block!!
Done <= '1';
when "01" =>
Columna(3) := '1';
Linea(3) := '0';
when "10" =>
Columna(3) := '0';
Linea(3) := '1';
when others => --11
Columna(3) := '1';
Linea(3) := '1';
end case;
else
Done <= '1';
end if;
else
Coeficiente := Coeficiente + 1;
StepV <= 4; --to give time to the next coefficient to load from mem
end if;
end if;
end if;
end if;
end if;
if WriteZRL = '1' then
WriteZRL := '0';
end if;
end if; --if HuffmanWordPos < 15
end if; --if ZRL > 0
end if;
end if;
--the place for the following cases is here because Coeficiente may be changed from two places, after Save and
--after finding a 00h Coefficient
--These are to prepare the reading (in zigzag order) of the next coefficient from memory
case Coeficiente is
when 0|1|5|6|14|15|27|28 =>
Linea(2 downto 0) := "000";
when 2|4|7|13|16|26|29|42 =>
Linea(2 downto 0) := "001";
when 3|8|12|17|25|30|41|43 =>
Linea(2 downto 0) := "010";
when 9|11|18|24|31|40|44|53 =>
Linea(2 downto 0) := "011";
when 10|19|23|32|39|45|52|54 =>
Linea(2 downto 0) := "100";
when 20|22|33|38|46|51|55|60 =>
Linea(2 downto 0) := "101";
when 21|34|37|47|50|56|59|61 =>
Linea(2 downto 0) := "110";
when 35|36|48|49|57|58|62|63 =>
Linea(2 downto 0) := "111";
end case;
case Coeficiente is
when 0|2|3|9|10|20|21|35 =>
Columna := Columna(9 downto 3) & "000";
when 1|4|8|11|19|22|34|36 =>
Columna := Columna(9 downto 3) & "001";
when 5|7|12|18|23|33|37|48 =>
Columna := Columna(9 downto 3) & "010";
when 6|13|17|24|32|38|47|49 =>
Columna := Columna(9 downto 3) & "011";
when 14|16|25|31|39|46|50|57 =>
Columna := Columna(9 downto 3) & "100";
when 15|26|30|40|45|51|56|58 =>
Columna := Columna(9 downto 3) & "101";
when 27|29|41|44|52|55|59|62 =>
Columna := Columna(9 downto 3) & "110";
when 28|42|43|53|54|60|61|63 =>
Columna := Columna(9 downto 3) & "111";
end case;
end case;
end if;
if Done = '1' then
HeaderFinal := '0';
Done <= '0';
--if LineAbsToCompress > ImgLines then --must process the last three luminance blocks one after the other
if (Elemento = "00" and Linea(3) = '1' and Columna(3)='1' and StepV /= 0) or Bloque /= "00" then --only if the 4 squares of luminance 2x2 block have been processed
--when Elemento is 00 but Linea and Columna still are the ones of element 11
Linea := "0000";
if LumaBlock = '1' then --must change columns (it'll always be Elemento=11 because it is the only one that rises Done)
Columna := '0' & Columna(9 downto 4) & "000"; --half of the columns because of subsampling
else
Columna := Columna(9 downto 3) & "000";
end if;
LumaBlock := '0';
StepV <= 0;
weY2 <= '0';
weCb2 <= '0';
weCr2 <= '0';
Coeficiente := 0;
Save <= '0';
IniDC := '1';
GetPrevDC := '1';
case Bloque is
when "00" => --block Y
Bloque := "01"; --pass on to process las Cb block
when "01" => --block Cb
Bloque := "10"; --pass on to process las Cr block
when others => --can only be block Cr
CompressingInt <= '0'; --we've finished the block
end case;
else
CompressingInt <= '0'; --we've finished compressing this block
end if;
end if;
 
case Bloque is
when "00" => --block Y
addrY2 <= Mult_Columns(Linea) + Columna;
when "01" => --block Cb
addrCb2 <= Mult_Half_Columns(Linea(2 downto 0)) + Columna;
when others => --can only be block Cr
addrCr2 <= Mult_Half_Columns(Linea(2 downto 0)) + Columna;
end case;
 
end if; --if MakeDCT or CompressingInt
end if; --if clk
end process JPEG;
end JPG;
 
configuration configuracionJPG of Compressor is
for JPG
--pragma translate_off
for all : dct2d use entity XilinxCoreLib.C_DA_2D_DCT_V2_0(behavioral)
generic map(
c_clks_per_sample => 9,
c_result_width => 19,
c_internal_width => 19,
c_data_type => 0,
c_precision_control => 2,
c_data_width => 8,
c_operation => 0,
c_enable_rlocs => 0,
c_latency => 95,
c_enable_symmetry => 1,
c_coeff_width => 24,
c_shape => 0,
c_mem_type => 1,
c_col_latency => 15,
c_row_latency => 15,
c_has_reset => 0);
end for;
for all : buffer_comp use entity XilinxCoreLib.blkmemsp_v5_0(behavioral)
generic map(
c_sinit_value => "0",
c_reg_inputs => 0,
c_yclk_is_rising => 1,
c_has_en => 0,
c_ysinit_is_high => 1,
c_ywe_is_high => 1,
c_ytop_addr => "1024",
c_yprimitive_type => "16kx1",
c_yhierarchy => "hierarchy1",
c_has_rdy => 0,
c_has_limit_data_pitch => 0,
c_write_mode => 1,
c_width => 12,
c_yuse_single_primitive => 0,
c_has_nd => 0,
c_enable_rlocs => 0,
c_has_we => 1,
c_has_rfd => 0,
c_has_din => 1,
c_ybottom_addr => "0",
c_pipe_stages => 0,
c_yen_is_high => 1,
c_depth => 5632,
c_has_default_data => 1,
c_limit_data_pitch => 18,
c_has_sinit => 0,
c_mem_init_file => "mif_file_16_1",
c_default_data => "0",
c_ymake_bmm => 0,
c_addr_width => 13);
end for;
 
for all : buffer_comp_chrom use entity XilinxCoreLib.blkmemsp_v5_0(behavioral)
generic map(
c_sinit_value => "0",
c_reg_inputs => 0,
c_yclk_is_rising => 1,
c_has_en => 0,
c_ysinit_is_high => 1,
c_ywe_is_high => 1,
c_ytop_addr => "1024",
c_yprimitive_type => "16kx1",
c_yhierarchy => "hierarchy1",
c_has_rdy => 0,
c_has_limit_data_pitch => 0,
c_write_mode => 1,
c_width => 12,
c_yuse_single_primitive => 0,
c_has_nd => 0,
c_enable_rlocs => 0,
c_has_we => 1,
c_has_rfd => 0,
c_has_din => 1,
c_ybottom_addr => "0",
c_pipe_stages => 0,
c_yen_is_high => 1,
c_depth => 1408,
c_has_default_data => 1,
c_limit_data_pitch => 18,
c_has_sinit => 0,
c_mem_init_file => "mif_file_16_1",
c_default_data => "0",
c_ymake_bmm => 0,
c_addr_width => 11);
end for;
for all : q_rom use entity XilinxCoreLib.blkmemsp_v5_0(behavioral)
generic map(
c_sinit_value => "0",
c_reg_inputs => 0,
c_yclk_is_rising => 1,
c_has_en => 0,
c_ysinit_is_high => 1,
c_ywe_is_high => 1,
c_ytop_addr => "1024",
c_yprimitive_type => "16kx1",
c_yhierarchy => "hierarchy1",
c_has_rdy => 0,
c_has_limit_data_pitch => 0,
c_write_mode => 0,
c_width => 13,
c_yuse_single_primitive => 0,
c_has_nd => 0,
c_enable_rlocs => 0,
c_has_we => 0,
c_has_rfd => 0,
c_has_din => 0,
c_ybottom_addr => "0",
c_pipe_stages => 0,
c_yen_is_high => 1,
c_depth => 384,
c_has_default_data => 0,
c_limit_data_pitch => 18,
c_has_sinit => 0,
c_mem_init_file => "q_rom.mif",
c_default_data => "0",
c_ymake_bmm => 0,
c_addr_width => 9);
end for;
for all : huff_rom use entity XilinxCoreLib.blkmemsp_v5_0(behavioral)
generic map(
c_sinit_value => "0",
c_reg_inputs => 0,
c_yclk_is_rising => 1,
c_has_en => 0,
c_ysinit_is_high => 1,
c_ywe_is_high => 1,
c_ytop_addr => "1024",
c_yprimitive_type => "16kx1",
c_yhierarchy => "hierarchy1",
c_has_rdy => 0,
c_has_limit_data_pitch => 0,
c_write_mode => 0,
c_width => 20,
c_yuse_single_primitive => 0,
c_has_nd => 0,
c_enable_rlocs => 0,
c_has_we => 0,
c_has_rfd => 0,
c_has_din => 0,
c_ybottom_addr => "0",
c_pipe_stages => 0,
c_yen_is_high => 1,
c_depth => 352,
c_has_default_data => 0,
c_limit_data_pitch => 18,
c_has_sinit => 0,
c_mem_init_file => "huff_rom.mif",
c_default_data => "0",
c_ymake_bmm => 0,
c_addr_width => 9);
end for;
 
for all : tabla_q use entity XilinxCoreLib.blkmemsp_v5_0(behavioral)
generic map(
c_sinit_value => "0",
c_reg_inputs => 0,
c_yclk_is_rising => 1,
c_has_en => 0,
c_ysinit_is_high => 1,
c_ywe_is_high => 1,
c_ytop_addr => "1024",
c_yprimitive_type => "16kx1",
c_yhierarchy => "hierarchy1",
c_has_rdy => 0,
c_has_limit_data_pitch => 0,
c_write_mode => 0,
c_width => 8,
c_yuse_single_primitive => 0,
c_has_nd => 0,
c_enable_rlocs => 0,
c_has_we => 0,
c_has_rfd => 0,
c_has_din => 0,
c_ybottom_addr => "0",
c_pipe_stages => 0,
c_yen_is_high => 1,
c_depth => 384,
c_has_default_data => 0,
c_limit_data_pitch => 18,
c_has_sinit => 0,
c_mem_init_file => "tabla_q.mif",
c_default_data => "0",
c_ymake_bmm => 0,
c_addr_width => 9);
end for;
--pragma translate_on
 
end for;
end configuracionJPG;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.