From 769cf91297c76f800eeb884a429dfc44bfbd1d7e Mon Sep 17 00:00:00 2001 From: jpr Date: Tue, 21 Oct 2003 12:08:53 +0000 Subject: [PATCH] add the files for 'xmedcon' Jpeg Lossless library --- src/jpeg/ljpg/CMakeLists.txt | 37 ++ src/jpeg/ljpg/COPYING.LIB | 510 ++++++++++++++++++++++++++ src/jpeg/ljpg/ChangeLog | 118 ++++++ src/jpeg/ljpg/Makefile | 403 ++++++++++++++++++++ src/jpeg/ljpg/Makefile.am | 23 ++ src/jpeg/ljpg/Makefile.in | 403 ++++++++++++++++++++ src/jpeg/ljpg/README | 118 ++++++ src/jpeg/ljpg/decomp.c | 98 +++++ src/jpeg/ljpg/huffd.c | 691 +++++++++++++++++++++++++++++++++++ src/jpeg/ljpg/io.h | 27 ++ src/jpeg/ljpg/jpeg.h | 183 ++++++++++ src/jpeg/ljpg/jpegless.h | 57 +++ src/jpeg/ljpg/jpegutil.c | 252 +++++++++++++ src/jpeg/ljpg/libljpg.la | 35 ++ src/jpeg/ljpg/mcu.c | 122 +++++++ src/jpeg/ljpg/mcu.h | 41 +++ src/jpeg/ljpg/predict.c | 184 ++++++++++ src/jpeg/ljpg/predict.h | 168 +++++++++ src/jpeg/ljpg/proto.h | 47 +++ src/jpeg/ljpg/read.c | 673 ++++++++++++++++++++++++++++++++++ 20 files changed, 4190 insertions(+) create mode 100644 src/jpeg/ljpg/CMakeLists.txt create mode 100644 src/jpeg/ljpg/COPYING.LIB create mode 100644 src/jpeg/ljpg/ChangeLog create mode 100644 src/jpeg/ljpg/Makefile create mode 100644 src/jpeg/ljpg/Makefile.am create mode 100644 src/jpeg/ljpg/Makefile.in create mode 100644 src/jpeg/ljpg/README create mode 100644 src/jpeg/ljpg/decomp.c create mode 100644 src/jpeg/ljpg/huffd.c create mode 100644 src/jpeg/ljpg/io.h create mode 100644 src/jpeg/ljpg/jpeg.h create mode 100644 src/jpeg/ljpg/jpegless.h create mode 100644 src/jpeg/ljpg/jpegutil.c create mode 100644 src/jpeg/ljpg/libljpg.la create mode 100644 src/jpeg/ljpg/mcu.c create mode 100644 src/jpeg/ljpg/mcu.h create mode 100644 src/jpeg/ljpg/predict.c create mode 100644 src/jpeg/ljpg/predict.h create mode 100644 src/jpeg/ljpg/proto.h create mode 100644 src/jpeg/ljpg/read.c diff --git a/src/jpeg/ljpg/CMakeLists.txt b/src/jpeg/ljpg/CMakeLists.txt new file mode 100644 index 00000000..b1f6722c --- /dev/null +++ b/src/jpeg/ljpg/CMakeLists.txt @@ -0,0 +1,37 @@ +#LTVERSION = 0:1:0 + +#lib_LTLIBRARIES = libgdcmjpg.la + +##CXXFLAGS = @CXXFLAGS@ + +SET(libgdcmjpg_la_SOURCES + decomp.c \ + huffd.c \ + jpegutil.c \ + mcu.c \ + predict.c \ + read.c +) + +#libgdcmjpgincludedir = $(includedir) +SET(llibgdcmjpginclude_HEADERS + io.h \ + jpeg.h \ + jpegless.h \ + mcu.h \ + predict.h \ + proto.h +) + +#EXTRA_DIST = \ +# jconfig.linux \ +# jconfig.vc + +ADD_LIBRARY(gdcmjpeg ${libgdcmjpeg_la_SOURCES}) + +#INSTALL_FILES(/include "\\.h$") +INSTALL_FILES(/include FILES ${libgdcmjpeginclude_HEADERS}) +#INSTALL_FILES(/include FILES jconfig.linux jconfig.vc) +INSTALL_FILES(/include FILES jconfig.linux) + +INSTALL_TARGETS(/lib/ gdcmjpeg) \ No newline at end of file diff --git a/src/jpeg/ljpg/COPYING.LIB b/src/jpeg/ljpg/COPYING.LIB new file mode 100644 index 00000000..cf9b6b99 --- /dev/null +++ b/src/jpeg/ljpg/COPYING.LIB @@ -0,0 +1,510 @@ + + 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. +^L + 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. +^L + 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. +^L + 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. +^L + 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. +^L + 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. +^L + 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. +^L + 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 +^L + 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! + + diff --git a/src/jpeg/ljpg/ChangeLog b/src/jpeg/ljpg/ChangeLog new file mode 100644 index 00000000..1613f07a --- /dev/null +++ b/src/jpeg/ljpg/ChangeLog @@ -0,0 +1,118 @@ +2003-06-11 Wednesday 01:20 enlf + + * Makefile.in: + - Replace user DO_CYGWIN conditional by auto-generated + PLATFORM_WIN32. + +2003-06-10 Tuesday 00:06 enlf + + * Makefile.in: + - Generate DLL file on Win32 platform with cygwin/gcc combo. + +2003-06-09 Monday 23:13 enlf + + * Makefile.in: + - Renamed unused.h header in more appropriate m-autocof.h header. + +2003-06-09 Monday 00:30 enlf + + * Makefile.in: + - After configure changes, update Makefile.in templates. + +2003-04-25 Friday 00:38 enlf + + * Makefile.in: + - Touched by latest autotools: autoconf-2.57, automake-1.7.4 & + libtool-1.5 + +2002-12-13 Friday 00:54 enlf + + * Makefile.in: + - Commit autogenerated changes. + +2002-12-12 Thursday 23:04 enlf + + * README: + - Cornell license update for "any" purpose instead of "research". + +2002-11-29 Friday 00:12 enlf + + * Makefile.am, Makefile.in: + - Do not install headers. Prevent unnecessary conflicts with system + headers. + +2002-11-05 Tuesday 01:46 enlf + + * huffd.c: + - Changed C++ comment into C comment. + +2002-10-28 Monday 23:09 enlf + + * Makefile.am, Makefile.in: + - Be a little more open: remove GNU specific compiler flags. + +2002-10-26 Saturday 17:36 enlf + + * Makefile.in: + - Fixed PNG library check and added --with-png-prefix config + possibility. + +2002-10-26 Saturday 00:35 enlf + + * Makefile.am, Makefile.in: + - Upgrade of our autoconf, automake & libtool utils. + +2002-10-25 Friday 16:23 enlf + + * mcu.c: + - Fix MacOSX 10.1 link error with Undefined symbols _mcuROW1 & + _mcuROW2: (probably left out of not being used in mcu.c source file + itself) + +2002-10-24 Thursday 02:00 enlf + + * Makefile.am, Makefile.in: + - Being friendly to others, removed a GNU C specific option. + +2002-10-21 Monday 22:46 enlf + + * mcu.c, read.c: + - Fix prototype warnings for Sun ONE compiler. + +2002-10-16 Wednesday 22:03 enlf + + * huffd.c: + - Fix for 24bit RGB lossless jpeg pixeldata. + +2002-10-15 Tuesday 09:50 enlf + + * Makefile.in: + - Extra files in distro. + +2002-10-15 Tuesday 09:48 enlf + + * COPYING.LIB, README: + - Contribution released under LGPL license. + +2002-10-15 Tuesday 02:14 enlf + + * huffd.c, jpegutil.c, read.c: + - Add newline to error messages. + +2002-10-15 Tuesday 02:04 enlf + + * decomp.c, huffd.c, jpeg.h, jpegutil.c, read.c: + - Catch unwanted exits. + +2002-10-15 Tuesday 00:27 enlf + + * Makefile.in: + - Changes due to moving of dicom & ljpg subdirs. + +2002-10-14 Monday 23:56 enlf + + * ChangeLog, Makefile.am, Makefile.in, README, decomp.c, huffd.c, + io.h, jpeg.h, jpegless.h, jpegutil.c, mcu.c, mcu.h, predict.c, + predict.h, proto.h, read.c: + - Placed ljpg dir in libs subdir. + diff --git a/src/jpeg/ljpg/Makefile b/src/jpeg/ljpg/Makefile new file mode 100644 index 00000000..4e68926d --- /dev/null +++ b/src/jpeg/ljpg/Makefile @@ -0,0 +1,403 @@ +# Generated automatically from Makefile.in by configure. +# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = /bin/sh + +srcdir = . +top_srcdir = ../../.. +prefix = /usr/local +exec_prefix = ${prefix} + +bindir = ${exec_prefix}/bin +sbindir = ${exec_prefix}/sbin +libexecdir = ${exec_prefix}/libexec +datadir = ${prefix}/share +sysconfdir = ${prefix}/etc +sharedstatedir = ${prefix}/com +localstatedir = ${prefix}/var +libdir = ${exec_prefix}/lib +infodir = ${prefix}/info +mandir = ${prefix}/man +includedir = ${prefix}/include +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/gdcm +pkglibdir = $(libdir)/gdcm +pkgincludedir = $(includedir)/gdcm + +top_builddir = ../../.. + +ACLOCAL = aclocal +AUTOCONF = autoconf +AUTOMAKE = automake +AUTOHEADER = autoheader + +INSTALL = /usr/bin/install -c +INSTALL_PROGRAM = ${INSTALL} $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_SCRIPT = ${INSTALL_PROGRAM} +transform = s,x,x, + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = i686-pc-linux-gnu +host_triplet = i686-pc-linux-gnu +AS = @AS@ +CC = gcc +CPP = cc -E +CXX = c++ +DLLTOOL = @DLLTOOL@ +DOXYGEN = true +ECHO = echo +EXEEXT = +HAVE_DOXYGEN = +LIBTOOL = $(SHELL) $(top_builddir)/libtool +LN_S = ln -s +MAINT = +MAKEINFO = makeinfo +OBJDUMP = @OBJDUMP@ +OBJEXT = o +PACKAGE = gdcm +PYTHON = /usr/bin/python2 +PYTHON_EXEC_PREFIX = ${exec_prefix} +PYTHON_INCLUDES = -I/usr/include/python2.2 +PYTHON_PLATFORM = linux2 +PYTHON_PREFIX = ${prefix} +PYTHON_VERSION = 2.2 +RANLIB = ranlib +STRIP = strip +SWIG = swig13 +VERSION = 0.3.0 +pkgpyexecdir = ${pyexecdir}/gdcm +pkgpythondir = ${pythondir}/gdcm +pyexecdir = ${exec_prefix}/lib/python2.2/site-packages +pythondir = ${prefix}/lib/python2.2/site-packages + +LTVERSION = 0:1:0 + +lib_LTLIBRARIES = libgdcmjpg.la + +libgdcmjpg_la_SOURCES = \ + decomp.c \ + huffd.c \ + jpegutil.c \ + mcu.c \ + predict.c \ + read.c + + +libgdcmjpgincludedir = $(includedir) +libgdcmjpginclude_HEADERS = \ + io.h \ + jpeg.h \ + jpegless.h \ + mcu.h \ + predict.h \ + proto.h + +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../../src/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) + + +DEFS = -DHAVE_CONFIG_H -I. -I$(srcdir) -I../../../src +CPPFLAGS = +LDFLAGS = +LIBS = +libgdcmjpg_la_LDFLAGS = +libgdcmjpg_la_LIBADD = +libgdcmjpg_la_OBJECTS = decomp.lo huffd.lo jpegutil.lo mcu.lo \ +predict.lo read.lo +CFLAGS = -g -O2 +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +HEADERS = $(libgdcmjpginclude_HEADERS) + +DIST_COMMON = README COPYING.LIB ChangeLog Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +DEP_FILES = .deps/decomp.P .deps/huffd.P .deps/jpegutil.P .deps/mcu.P \ +.deps/predict.P .deps/read.P +SOURCES = $(libgdcmjpg_la_SOURCES) +OBJECTS = $(libgdcmjpg_la_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .obj .s +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu src/jpeg/ljpg/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-libLTLIBRARIES: + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + +distclean-libLTLIBRARIES: + +maintainer-clean-libLTLIBRARIES: + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libdir) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \ + done + +# FIXME: We should only use cygpath when building on Windows, +# and only if it is available. +.c.obj: + $(COMPILE) -c `cygpath -w $<` + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + -rm -f *.$(OBJEXT) + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libgdcmjpg.la: $(libgdcmjpg_la_OBJECTS) $(libgdcmjpg_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libgdcmjpg_la_LDFLAGS) $(libgdcmjpg_la_OBJECTS) $(libgdcmjpg_la_LIBADD) $(LIBS) + +install-libgdcmjpgincludeHEADERS: $(libgdcmjpginclude_HEADERS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libgdcmjpgincludedir) + @list='$(libgdcmjpginclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \ + echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libgdcmjpgincludedir)/$$p"; \ + $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libgdcmjpgincludedir)/$$p; \ + done + +uninstall-libgdcmjpgincludeHEADERS: + @$(NORMAL_UNINSTALL) + list='$(libgdcmjpginclude_HEADERS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(libgdcmjpgincludedir)/$$p; \ + done + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = src/jpeg/ljpg + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/jpeg/ljpg/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: install-libLTLIBRARIES +install-exec: install-exec-am + +install-data-am: install-libgdcmjpgincludeHEADERS +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-libLTLIBRARIES \ + uninstall-libgdcmjpgincludeHEADERS +uninstall: uninstall-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(libgdcmjpgincludedir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \ + clean-depend clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-libLTLIBRARIES distclean-compile \ + distclean-libtool distclean-tags distclean-depend \ + distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-libLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \ +clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \ +uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \ +distclean-compile clean-compile maintainer-clean-compile \ +mostlyclean-libtool distclean-libtool clean-libtool \ +maintainer-clean-libtool uninstall-libgdcmjpgincludeHEADERS \ +install-libgdcmjpgincludeHEADERS tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir mostlyclean-depend \ +distclean-depend clean-depend maintainer-clean-depend info-am info \ +dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ +install-exec install-data-am install-data install-am install \ +uninstall-am uninstall all-redirect all-am all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/jpeg/ljpg/Makefile.am b/src/jpeg/ljpg/Makefile.am new file mode 100644 index 00000000..cb51f570 --- /dev/null +++ b/src/jpeg/ljpg/Makefile.am @@ -0,0 +1,23 @@ +LTVERSION = 0:1:0 + +lib_LTLIBRARIES = libgdcmjpg.la + +##CXXFLAGS = @CXXFLAGS@ + +libgdcmjpg_la_SOURCES = \ + decomp.c \ + huffd.c \ + jpegutil.c \ + mcu.c \ + predict.c \ + read.c + +libgdcmjpgincludedir = $(includedir) +libgdcmjpginclude_HEADERS = \ + io.h \ + jpeg.h \ + jpegless.h \ + mcu.h \ + predict.h \ + proto.h + diff --git a/src/jpeg/ljpg/Makefile.in b/src/jpeg/ljpg/Makefile.in new file mode 100644 index 00000000..6924ca2d --- /dev/null +++ b/src/jpeg/ljpg/Makefile.in @@ -0,0 +1,403 @@ +# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AS = @AS@ +CC = @CC@ +CPP = @CPP@ +CXX = @CXX@ +DLLTOOL = @DLLTOOL@ +DOXYGEN = @DOXYGEN@ +ECHO = @ECHO@ +EXEEXT = @EXEEXT@ +HAVE_DOXYGEN = @HAVE_DOXYGEN@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_INCLUDES = @PYTHON_INCLUDES@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +SWIG = @SWIG@ +VERSION = @VERSION@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ + +LTVERSION = 0:1:0 + +lib_LTLIBRARIES = libgdcmjpg.la + +libgdcmjpg_la_SOURCES = \ + decomp.c \ + huffd.c \ + jpegutil.c \ + mcu.c \ + predict.c \ + read.c + + +libgdcmjpgincludedir = $(includedir) +libgdcmjpginclude_HEADERS = \ + io.h \ + jpeg.h \ + jpegless.h \ + mcu.h \ + predict.h \ + proto.h + +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../../src/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I../../../src +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +libgdcmjpg_la_LDFLAGS = +libgdcmjpg_la_LIBADD = +libgdcmjpg_la_OBJECTS = decomp.lo huffd.lo jpegutil.lo mcu.lo \ +predict.lo read.lo +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +HEADERS = $(libgdcmjpginclude_HEADERS) + +DIST_COMMON = README COPYING.LIB ChangeLog Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +DEP_FILES = .deps/decomp.P .deps/huffd.P .deps/jpegutil.P .deps/mcu.P \ +.deps/predict.P .deps/read.P +SOURCES = $(libgdcmjpg_la_SOURCES) +OBJECTS = $(libgdcmjpg_la_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .obj .s +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu src/jpeg/ljpg/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-libLTLIBRARIES: + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + +distclean-libLTLIBRARIES: + +maintainer-clean-libLTLIBRARIES: + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libdir) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \ + done + +# FIXME: We should only use cygpath when building on Windows, +# and only if it is available. +.c.obj: + $(COMPILE) -c `cygpath -w $<` + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + -rm -f *.$(OBJEXT) + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libgdcmjpg.la: $(libgdcmjpg_la_OBJECTS) $(libgdcmjpg_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libgdcmjpg_la_LDFLAGS) $(libgdcmjpg_la_OBJECTS) $(libgdcmjpg_la_LIBADD) $(LIBS) + +install-libgdcmjpgincludeHEADERS: $(libgdcmjpginclude_HEADERS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libgdcmjpgincludedir) + @list='$(libgdcmjpginclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \ + echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libgdcmjpgincludedir)/$$p"; \ + $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libgdcmjpgincludedir)/$$p; \ + done + +uninstall-libgdcmjpgincludeHEADERS: + @$(NORMAL_UNINSTALL) + list='$(libgdcmjpginclude_HEADERS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(libgdcmjpgincludedir)/$$p; \ + done + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = src/jpeg/ljpg + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/jpeg/ljpg/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: install-libLTLIBRARIES +install-exec: install-exec-am + +install-data-am: install-libgdcmjpgincludeHEADERS +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-libLTLIBRARIES \ + uninstall-libgdcmjpgincludeHEADERS +uninstall: uninstall-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(libgdcmjpgincludedir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \ + clean-depend clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-libLTLIBRARIES distclean-compile \ + distclean-libtool distclean-tags distclean-depend \ + distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-libLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \ +clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \ +uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \ +distclean-compile clean-compile maintainer-clean-compile \ +mostlyclean-libtool distclean-libtool clean-libtool \ +maintainer-clean-libtool uninstall-libgdcmjpgincludeHEADERS \ +install-libgdcmjpgincludeHEADERS tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir mostlyclean-depend \ +distclean-depend clean-depend maintainer-clean-depend info-am info \ +dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ +install-exec install-data-am install-data install-am install \ +uninstall-am uninstall all-redirect all-am all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/jpeg/ljpg/README b/src/jpeg/ljpg/README new file mode 100644 index 00000000..2425ef73 --- /dev/null +++ b/src/jpeg/ljpg/README @@ -0,0 +1,118 @@ +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# filename: README # +# # +# UTILITY text: Medical Image Conversion Utility # +# # +# purpose : the ljpg 'you-should-read' file # +# # +# project : (X)MedCon by Erik Nolf # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# $Id: README,v 1.1 2003/10/21 12:08:53 jpr Exp $ + +(X)MedCon's LossLess JPEG Decompression Library (DICOM) +----------------------------------------------- + +This library code was originally contributed by 'Jaslet Bertrand'. + +The software is based in part on the work of: + +a) the Cornell University LossLess JPEG library + + see ftp://ftp.cs.cornell.edu/pub/multimed + +b) the Independent JPEG Group's JPEG software + + see http://www.ijg.org + +License & Copyright notices: +--------------------------- + +1) (X)MedCon's LJPG (C) 2002, Jaslet Bertrand. + + Read the file ./COPYING.LIB + +2) Cornell University + +Copyright (c) 1993 Cornell University, Kongji Huang +All rights reserved. + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without written +agreement is hereby granted, provided that the above copyright notice +and the following two paragraphs appear in all copies of this +software. + +IN NO EVENT SHALL THE CORNELL UNIVERSITY BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF CORNELL +UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +THE CORNELL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND CORNELL UNIVERSITY HAS +NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, +OR MODIFICATIONS. + +--------------------------------------------------------------------------- + +Copyright (c) 1993 The Regents of the University of California, Brian +C. Smith All rights reserved. + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without written +agreement is hereby granted, provided that the above copyright notice +and the following two paragraphs appear in all copies of this +software. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY +FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, +ENHANCEMENTS, OR MODIFICATIONS. + +--------------------------------------------------------------------------- + +3) Independent JPEG Group (IJG) + +The authors make NO WARRANTY or representation, either express or +implied, with respect to this software, its quality, accuracy, +merchantability, or fitness for a particular purpose. This software is +provided "AS IS", and you, its user, assume the entire risk as to its +quality and accuracy. + +This software is copyright (C) 1991, 1992, Thomas G. Lane. All Rights +Reserved except as specified below. + +Permission is hereby granted to use, copy, modify, and distribute this +software (or portions thereof) for any purpose, without fee, subject to +these conditions: (1) If any part of the source code for this software +is distributed, then this README file must be included, with this +copyright and no-warranty notice unaltered; and any additions, +deletions, or changes to the original files must be clearly indicated +in accompanying documentation. (2) If only executable code is +distributed, then the accompanying documentation must state that "this +software is based in part on the work of the Independent JPEG Group". +(3) Permission for use of this software is granted only if the user +accepts full responsibility for any undesirable consequences; the +authors accept NO LIABILITY for damages of any kind. + +Permission is NOT granted for the use of any IJG author's name or +company name in advertising or publicity relating to this software or +products derived from it. This software may be referred to only as +"the Independent JPEG Group's software". + +We specifically permit and encourage the use of this software as the +basis of commercial products, provided that all warranty or liability +claims are assumed by the product vendor. + +--------------------------------------------------------------------------- + diff --git a/src/jpeg/ljpg/decomp.c b/src/jpeg/ljpg/decomp.c new file mode 100644 index 00000000..d5cf9f48 --- /dev/null +++ b/src/jpeg/ljpg/decomp.c @@ -0,0 +1,98 @@ +/* + * decomp.c -- + * + * This is the routine that is called to decompress a frame + * image data. It is based on the program originally named ljpgtopnm.c. + * Major portions taken from the Independent JPEG Group' software, and + * from the Cornell lossless JPEG code + */ +/* + * $Id: decomp.c,v 1.1 2003/10/21 12:08:53 jpr Exp $ + */ +#include +#include +#include +#include "io.h" +#include "jpeg.h" +#include "mcu.h" +#include "proto.h" + +DecompressInfo dcInfo; +StreamIN JpegInFile; + +/* + *-------------------------------------------------------------- + * + * ReadJpegData -- + * + * This is an interface routine to the JPEG library. The + * JPEG library calls this routine to "get more data" + * + * Results: + * Number of bytes actually returned. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +static void efree(void **ptr) +{ + if((*ptr) != 0) + free((*ptr)); + *ptr = 0; +} + + +int ReadJpegData (Uchar *buffer, int numBytes) +{ + unsigned long size = sizeof(unsigned char); + + fread(buffer,size,numBytes, JpegInFile); + + return numBytes; +} + + +short JPEGLosslessDecodeImage (StreamIN inFile, unsigned short *image16, int depth, int length) +{ + /* Initialization */ + JpegInFile = inFile; + MEMSET (&dcInfo, 0, sizeof (dcInfo)); + inputBufferOffset = 0; + + /* Allocate input buffer */ + inputBuffer = (unsigned char*)malloc((size_t)length+5); + if (inputBuffer == NULL) + return -1; + + /* Read input buffer */ + ReadJpegData (inputBuffer, length); + inputBuffer [length] = EOF; + + /* Read JPEG File header */ + ReadFileHeader (&dcInfo); + if (dcInfo.error) { efree ((void **)&inputBuffer); return -1; } + + /* Read the scan header */ + if (!ReadScanHeader (&dcInfo)) { efree ((void **)&inputBuffer); return -1; } + + /* + * Decode the image bits stream. Clean up everything when + * finished decoding. + */ + DecoderStructInit (&dcInfo); + + if (dcInfo.error) { efree ((void **)&inputBuffer); return -1; } + + HuffDecoderInit (&dcInfo); + + if (dcInfo.error) { efree ((void **)&inputBuffer); return -1; } + + DecodeImage (&dcInfo, (unsigned short **) &image16, depth); + + /* Free input buffer */ + efree ((void **)&inputBuffer); + + return 0; +} diff --git a/src/jpeg/ljpg/huffd.c b/src/jpeg/ljpg/huffd.c new file mode 100644 index 00000000..e23fffb5 --- /dev/null +++ b/src/jpeg/ljpg/huffd.c @@ -0,0 +1,691 @@ +/* + * huffd.c -- + * + * Code for JPEG lossless decoding. Large parts are grabbed from the IJG + * software + */ +/* + * $Id: huffd.c,v 1.1 2003/10/21 12:08:53 jpr Exp $ + */ +#include +#include +#include +#include "jpeg.h" +#include "mcu.h" +#include "io.h" +#include "proto.h" +#include "predict.h" + + +#define RST0 0xD0 /* RST0 marker code */ + +static long getBuffer; /* current bit-extraction buffer */ +static int bitsLeft; /* # of unused bits in it */ + +/* + * The following variables keep track of the input buffer + * for the JPEG data, which is read by ReadJpegData. + */ +Uchar *inputBuffer; /* Input buffer for JPEG data */ +int inputBufferOffset = 0; /* Offset of current byte */ + +/* + * Code for extracting the next N bits from the input stream. + * (N never exceeds 15 for JPEG data.) + * This needs to go as fast as possible! + * + * We read source bytes into getBuffer and dole out bits as needed. + * If getBuffer already contains enough bits, they are fetched in-line + * by the macros get_bits() and get_bit(). When there aren't enough bits, + * FillBitBuffer is called; it will attempt to fill getBuffer to the + * "high water mark", then extract the desired number of bits. The idea, + * of course, is to minimize the function-call overhead cost of entering + * FillBitBuffer. + * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width + * of getBuffer to be used. (On machines with wider words, an even larger + * buffer could be used.) + */ + +#define BITS_PER_LONG (8*sizeof(long)) +#define MIN_GET_BITS (BITS_PER_LONG-7) /* max value for long getBuffer */ + +/* + * bmask[n] is mask for n rightmost bits + */ +static int bmask[] = {0x0000, + 0x0001, 0x0003, 0x0007, 0x000F, + 0x001F, 0x003F, 0x007F, 0x00FF, + 0x01FF, 0x03FF, 0x07FF, 0x0FFF, + 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF}; + +/* + *-------------------------------------------------------------- + * + * FillBitBuffer -- + * + * Load up the bit buffer with at least nbits + * Process any stuffed bytes at this time. + * + * Results: + * None + * + * Side effects: + * The bitwise global variables are updated. + * + *-------------------------------------------------------------- + */ +#define FillBitBuffer(nbits) { \ + int c, c2; \ + while (bitsLeft < MIN_GET_BITS) { \ + c = GetJpegChar (); \ + /* If it's 0xFF, check and discard stuffed zero byte */ \ + if (c == 0xFF) { \ + c2 = GetJpegChar (); \ + if (c2 != 0) { \ + UnGetJpegChar (c2); \ + UnGetJpegChar (c); \ + c = 0; \ + } \ + }/*endif 0xFF*/ \ + /* OK, load c into getBuffer */ \ + getBuffer = (getBuffer << 8) | c; \ + bitsLeft += 8; \ + }/*endwhile*/ \ +}/*endof FillBitBuffer*/ + +/* Macros to make things go at some speed! */ +/* NB: parameter to get_bits should be simple variable, not expression */ + +#define show_bits(nbits,rv) { \ + if (bitsLeft < nbits) FillBitBuffer(nbits); \ + rv = (getBuffer >> (bitsLeft-(nbits))) & bmask[nbits]; \ +} + +#define show_bits8(rv) { \ + if (bitsLeft < 8) FillBitBuffer(8); \ + rv = (getBuffer >> (bitsLeft-8)) & 0xff; \ +} + +#define flush_bits(nbits) { \ + bitsLeft -= (nbits); \ +} + +#define get_bits(nbits,rv) { \ + if (bitsLeft < nbits) FillBitBuffer(nbits); \ + rv = ((getBuffer >> (bitsLeft -= (nbits)))) & bmask[nbits]; \ +} + +#define get_bit(rv) { \ + if (!bitsLeft) FillBitBuffer(1); \ + rv = (getBuffer >> (--bitsLeft)) & 1; \ +} + +/* + *-------------------------------------------------------------- + * + * PmPutRow -- + * + * Output one row of pixels stored in RowBuf. + * + * Results: + * None + * + * Side effects: + * One row of pixels are write to file pointed by outFile. + * + *-------------------------------------------------------------- + */ + + +void PmPutRow24(MCU *RowBuf, int numCol, unsigned char **image) +{ + register int col; + + for (col = 0; col < numCol; col++) + { + /* take each RGB column */ + **image = (unsigned char) RowBuf[col][0]; + *(*image+1) = (unsigned char) RowBuf[col][1]; + *(*image+2) = (unsigned char) RowBuf[col][2]; + (*image)+=3; + } +} + + +void PmPutRow16(MCU *RowBuf, int numCol, unsigned short **image) +{ + register int col; + + for (col = 0; col < numCol; col++) + { + **image = (unsigned short) RowBuf[col][0]; + (*image)++; + } +} + + +void PmPutRow8(MCU *RowBuf, int numCol, unsigned char **image) +{ + register int col; + + for (col = 0; col < numCol; col++) + { + **image = (unsigned char) RowBuf[col][0]; + (*image)++; + } +} + + + + +/* + *-------------------------------------------------------------- + * + * HuffDecode -- + * + * Taken from Figure F.16: extract next coded symbol from + * input stream. This should becode a macro. + * + * Results: + * Next coded symbol + * + * Side effects: + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +#define HuffDecode(htbl,rv) \ +{ \ + int l, code, temp; \ + \ + /* \ + * If the huffman code is less than 8 bits, we can use the fast \ + * table lookup to get its value. It's more than 8 bits about \ + * 3-4% of the time. \ + */ \ + show_bits8(code); \ + if (htbl->numbits[code]) { \ + flush_bits(htbl->numbits[code]); \ + rv=htbl->value[code]; \ + } \ + else { \ + flush_bits(8); \ + l = 8; \ + while (code > htbl->maxcode[l]) { \ + get_bit(temp); \ + code = (code << 1) | temp; \ + l++; \ + } \ + \ + /* \ + * With garbage input we may reach the sentinel value l = 17. \ + */ \ + \ + if (l > 16) { \ + fprintf (stderr, "Corrupt JPEG data: bad Huffman code\n"); \ + rv = 0; /* fake a zero as the safest result */ \ + } else { \ + rv = htbl->huffval[htbl->valptr[l] + \ + ((int)(code - htbl->mincode[l]))]; \ + } \ + }/*endelse*/ \ +}/*HuffDecode*/ + +/* + *-------------------------------------------------------------- + * + * HuffExtend -- + * + * Code and table for Figure F.12: extend sign bit + * + * Results: + * The extended value. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +static int extendTest[16] = /* entry n is 2**(n-1) */ +{0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000}; + +static int extendOffset[16] = /* entry n is (-1 << n) + 1 */ +{0, ((-1) << 1) + 1, ((-1) << 2) + 1, ((-1) << 3) + 1, ((-1) << 4) + 1, + ((-1) << 5) + 1, ((-1) << 6) + 1, ((-1) << 7) + 1, ((-1) << 8) + 1, + ((-1) << 9) + 1, ((-1) << 10) + 1, ((-1) << 11) + 1, ((-1) << 12) + 1, + ((-1) << 13) + 1, ((-1) << 14) + 1, ((-1) << 15) + 1}; + +#define HuffExtend(x,s) { \ + if ((x) < extendTest[s]) { \ + (x) += extendOffset[s]; \ + } \ +} + +/* + *-------------------------------------------------------------- + * + * HuffDecoderInit -- + * + * Initialize for a Huffman-compressed scan. + * This is invoked after reading the SOS marker. + * + * Results: + * None + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +void HuffDecoderInit (DecompressInfo *dcPtr) +{ + short ci; + JpegComponentInfo *compptr; + /* + * Initialize siv-lyon1.fr + tatic variables + */ + bitsLeft = 0; + + for (ci = 0; ci < dcPtr->compsInScan; ci++) { + compptr = dcPtr->curCompInfo[ci]; + /* + * Make sure requested tables are present + */ + if (dcPtr->dcHuffTblPtrs[compptr->dcTblNo] == NULL) { + fprintf (stderr, "Error: Use of undefined Huffman table\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + /* + * Compute derived values for Huffman tables. + * We may do this more than once for same table, but it's not a + * big deal + */ + FixHuffTbl (dcPtr->dcHuffTblPtrs[compptr->dcTblNo]); + } + + /* + * Initialize restart stuff + */ + dcPtr->restartInRows = (dcPtr->restartInterval)/(dcPtr->imageWidth); + dcPtr->restartRowsToGo = dcPtr->restartInRows; + dcPtr->nextRestartNum = 0; +} + +/* + *-------------------------------------------------------------- + * + * ProcessRestart -- + * + * Check for a restart marker & resynchronize decoder. + * + * Results: + * None. + * + * Side effects: + * BitStream is parsed, bit buffer is reset, etc. + * + *-------------------------------------------------------------- + */ +static void ProcessRestart(DecompressInfo *dcPtr) +{ + int c, nbytes; + /*short ci;*/ + + /* + * Throw away any unused bits remaining in bit buffer + */ + nbytes = bitsLeft / 8; + bitsLeft = 0; + + /* + * Scan for next JPEG marker + */ + do + { + do + { /* skip any non-FF bytes */ + nbytes++; + c = GetJpegChar(); + } + while (c != 0xFF); + + do + { /* skip any duplicate FFs */ + /* + * we don't increment nbytes here since extra FFs are legal + */ + c = GetJpegChar (); + } + while (c == 0xFF); + } + while (c == 0); /* repeat if it was a stuffed FF/00 */ + + if (c != (RST0 + dcPtr->nextRestartNum)) { + + /* + * Uh-oh, the restart markers have been messed up too. + * Just bail out. + */ + fprintf (stderr, "Error: Corrupt JPEG data. Exiting...\n"); + /* exit(-1); */ + dcPtr->error = -1; return; + } + + /* + * Update restart state + */ + dcPtr->restartRowsToGo = dcPtr->restartInRows; + dcPtr->nextRestartNum = (dcPtr->nextRestartNum + 1) & 7; +} + +/* + *-------------------------------------------------------------- + * + * DecodeFirstRow -- + * + * Decode the first raster line of samples at the start of + * the scan and at the beginning of each restart interval. + * This includes modifying the component value so the real + * value, not the difference is returned. + * + * Results: + * None. + * + * Side effects: + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +void DecodeFirstRow (DecompressInfo *dcPtr, MCU *curRowBuf) +{ + register short curComp,ci; + register int s,col,compsInScan,numCOL; + register JpegComponentInfo *compptr; + int Pr,Pt,d; + HuffmanTable *dctbl; + Pr=dcPtr->dataPrecision; + Pt=dcPtr->Pt; + compsInScan=dcPtr->compsInScan; + numCOL=dcPtr->imageWidth; + + /* + * the start of the scan or at the beginning of restart interval. + */ + for (curComp = 0; curComp < compsInScan; curComp++) { + ci = dcPtr->MCUmembership[curComp]; + compptr = dcPtr->curCompInfo[ci]; + dctbl = dcPtr->dcHuffTblPtrs[compptr->dcTblNo]; + + /* + * Section F.2.2.1: decode the difference + */ + HuffDecode (dctbl,s); + if (s) { + get_bits(s,d); + HuffExtend(d,s); + } else { + d = 0; + } + + /* + * Add the predictor to the difference. + */ + curRowBuf[0][curComp]=d+(1<<(Pr-Pt-1)); + } + + /* + * the rest of the first row + */ + for (col=1; colMCUmembership[curComp]; + compptr = dcPtr->curCompInfo[ci]; + dctbl = dcPtr->dcHuffTblPtrs[compptr->dcTblNo]; + + /* + * Section F.2.2.1: decode the difference + */ + HuffDecode (dctbl,s); + if (s) { + get_bits(s,d); + HuffExtend(d,s); + } else { + d = 0; + } + + /* + * Add the predictor to the difference. + */ + curRowBuf[col][curComp]=d+curRowBuf[col-1][curComp]; + } + } + + if (dcPtr->restartInRows) { + (dcPtr->restartRowsToGo)--; + } +}/*endof DecodeFirstRow*/ + +/* + *-------------------------------------------------------------- + * + * DecodeImage -- + * + * Decode the input stream. This includes modifying + * the component value so the real value, not the + * difference is returned. + * + * Results: + * None. + * + * Side effects: + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +void DecodeImage (DecompressInfo *dcPtr, unsigned short **image, int depth) +{ + register int s, d, col, row; + register short curComp, ci; + HuffmanTable *dctbl; + JpegComponentInfo *compptr; + int predictor; + int numCOL, numROW, compsInScan; + MCU *prevRowBuf, *curRowBuf; + int imagewidth, Pt, psv; + unsigned short *image16tmp; + unsigned char *image8tmp, *image24tmp; + + numCOL = imagewidth=dcPtr->imageWidth; + numROW = dcPtr->imageHeight; + compsInScan = dcPtr->compsInScan; + Pt = dcPtr->Pt; + psv = dcPtr->Ss; + prevRowBuf = mcuROW2; + curRowBuf = mcuROW1; + + if (depth == 8) + image8tmp = (unsigned char *) *image; + else if (depth == 16) + image16tmp = (unsigned short *) *image; + else if (depth == 24) + image24tmp = (unsigned char *) *image; + else { + fprintf(stderr,"Unsupported image depth %d\n",depth); + dcPtr->error = -1; return; + } + + /* + * Decode the first row of image. Output the row and + * turn this row into a previous row for later predictor + * calculation. + */ + row = 0; + DecodeFirstRow (dcPtr, curRowBuf); + + if (depth == 8) + PmPutRow8 (curRowBuf, numCOL, &image8tmp); + else if (depth == 16) + PmPutRow16 (curRowBuf, numCOL, &image16tmp); + else if (depth == 24) + PmPutRow24 (curRowBuf, numCOL, &image24tmp); + + swap(MCU *, prevRowBuf, curRowBuf); + + /* optimal case : 8 bit image, one color component, no restartInRows */ + if ((depth == 8) && (compsInScan == 1) && (dcPtr->restartInRows == 0)) + { + + unsigned char *curPixelPtr; + int left,upper,diag; + + /* initializations */ + + curComp = 0; + ci = dcPtr->MCUmembership[curComp]; + compptr = dcPtr->curCompInfo[ci]; + dctbl = dcPtr->dcHuffTblPtrs[compptr->dcTblNo]; + curPixelPtr = image8tmp; + + for (row=1; row>1); break; + case 6: upper = *(curPixelPtr - numCOL); + left = *(curPixelPtr - 1); + diag = *(curPixelPtr - numCOL - 1); + predictor = upper+((left-diag)>>1); break; + case 7: upper = *(curPixelPtr - numCOL); + left = *(curPixelPtr - 1); + predictor = (left+upper)>>1; break; + default : predictor = 0; + }/*endsandwich*/ + + *curPixelPtr = (unsigned char) (d + predictor); + curPixelPtr++; + }/*endfor col*/ + }/*endelse*/ + + }/*endfor row*/ + }/*endif fast case*/ + + else { /*normal case with 16 bits or color or ...*/ + for (row=1; rowrestartInRows) + { + if (dcPtr->restartRowsToGo == 0) + { + ProcessRestart (dcPtr); if (dcPtr->error) return; + /* + * Reset predictors at restart. + */ + DecodeFirstRow(dcPtr,curRowBuf); + if (depth == 8) + PmPutRow8 (curRowBuf, numCOL, &image8tmp); + else if (depth == 16) + PmPutRow16 (curRowBuf, numCOL, &image16tmp); + else if (depth == 24) + PmPutRow24 (curRowBuf, numCOL, &image24tmp); + + swap(MCU *,prevRowBuf,curRowBuf); + continue; + } + dcPtr->restartRowsToGo--; + }/*endif*/ + + /* + * For the rest of the column on this row, predictor + * calculations are base on PSV. + */ + + /* several color components to decode (RGB colors)*/ + + /* The upper neighbors are predictors for the first column. */ + for (curComp = 0; curComp < compsInScan; curComp++) + { + ci = dcPtr->MCUmembership[curComp]; + compptr = dcPtr->curCompInfo[ci]; + dctbl = dcPtr->dcHuffTblPtrs[compptr->dcTblNo]; + + /* Section F.2.2.1: decode the difference */ + HuffDecode (dctbl,s); + if (s) { get_bits(s,d); HuffExtend(d,s); } + else d = 0; + curRowBuf[0][curComp]=d+prevRowBuf[0][curComp]; + }/*endfor curComp*/ + + for (col=1; col < numCOL; col++) + { + for (curComp = 0; curComp < compsInScan; curComp++) + { + ci = dcPtr->MCUmembership[curComp]; + compptr = dcPtr->curCompInfo[ci]; + dctbl = dcPtr->dcHuffTblPtrs[compptr->dcTblNo]; + + /* Section F.2.2.1: decode the difference */ + HuffDecode (dctbl, s); + if (s) { get_bits (s, d); HuffExtend (d, s); } + else d = 0; + + QuickPredict (col,curComp,curRowBuf,prevRowBuf,psv,&predictor); + + curRowBuf[col][curComp]=d+predictor; + }/*endfor curComp*/ + }/*endfor col*/ + + if (depth == 8) + PmPutRow8 (curRowBuf, numCOL, &image8tmp); + else if (depth == 16) + PmPutRow16 (curRowBuf, numCOL, &image16tmp); + else if (depth == 24) + PmPutRow24 (curRowBuf, numCOL, &image24tmp); + + swap(MCU *, prevRowBuf, curRowBuf); + + }/*endfor row*/ + }/*endelse*/ +}/*endofmethod DecodeImage*/ diff --git a/src/jpeg/ljpg/io.h b/src/jpeg/ljpg/io.h new file mode 100644 index 00000000..934dbfd9 --- /dev/null +++ b/src/jpeg/ljpg/io.h @@ -0,0 +1,27 @@ +/* + * io.h -- + * + */ +/* + * $Id: io.h,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#ifndef _IO +#define _IO + +#include "jpeg.h" + +/* + * Size of the input and output buffer + */ +#define JPEG_BUF_SIZE 4096 + +/* + * The following variables keep track of the input and output + * buffer for the JPEG data. + */ +extern char outputBuffer[JPEG_BUF_SIZE]; /* output buffer */ +extern int numOutputBytes; /* bytes in the output buffer */ +extern Uchar *inputBuffer; /* Input buffer for JPEG data */ +extern int inputBufferOffset; /* Offset of current byte */ + +#endif /* _IO */ diff --git a/src/jpeg/ljpg/jpeg.h b/src/jpeg/ljpg/jpeg.h new file mode 100644 index 00000000..f2ff7db3 --- /dev/null +++ b/src/jpeg/ljpg/jpeg.h @@ -0,0 +1,183 @@ +/* + * jpeg.h + * + * Basic jpeg data structure definitions. + */ +/* + * $Id: jpeg.h,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#ifndef _JPEG +#define _JPEG + +typedef unsigned char Uchar; +typedef unsigned short Ushort; +typedef unsigned int Uint; +typedef FILE * StreamIN ; + + +/* + * The following structure stores basic information about one component. + */ +typedef struct JpegComponentInfo +{ + /* + * These values are fixed over the whole image. + * They are read from the SOF marker. + */ + short componentId; /* identifier for this component (0..255) */ + short componentIndex; /* its index in SOF or cPtr->compInfo[] */ + + /* + * Downsampling is not normally used in lossless JPEG, although + * it is permitted by the JPEG standard (DIS). We set all sampling + * factors to 1 in this program. + */ + short hSampFactor; /* horizontal sampling factor */ + short vSampFactor; /* vertical sampling factor */ + + /* + * Huffman table selector (0..3). The value may vary + * between scans. It is read from the SOS marker. + */ + short dcTblNo; +} JpegComponentInfo; + + +/* + * One of the following structures is created for each huffman coding + * table. We use the same structure for encoding and decoding, so there + * may be some extra fields for encoding that aren't used in the decoding + * and vice-versa. + */ +typedef struct HuffmanTable +{ + /* + * These two fields directly represent the contents of a JPEG DHT + * marker + */ + Uchar bits[17]; + Uchar huffval[256]; + + /* + * This field is used only during compression. It's initialized + * FALSE when the table is created, and set TRUE when it's been + * output to the file. + */ + int sentTable; + + /* + * The remaining fields are computed from the above to allow more + * efficient coding and decoding. These fields should be considered + * private to the Huffman compression & decompression modules. + */ + Ushort ehufco[256]; + char ehufsi[256]; + + Ushort mincode[17]; + int maxcode[18]; + short valptr[17]; + int numbits[256]; + int value[256]; +} HuffmanTable; + +/* + * One of the following structures is used to pass around the + * compression information. + */ + + + +/* + * One of the following structures is used to pass around the + * decompression information. + */ +typedef struct DecompressInfo +{ + /* + * Image width, height, and image data precision (bits/sample) + * These fields are set by ReadFileHeader or ReadScanHeader + */ + int imageWidth; + int imageHeight; + int dataPrecision; + + /* + * compInfo[i] describes component that appears i'th in SOF + * numComponents is the # of color components in JPEG image. + */ + JpegComponentInfo compInfo[4]; + short numComponents; + + /* + * *curCompInfo[i] describes component that appears i'th in SOS. + * compsInScan is the # of color components in current scan. + */ + JpegComponentInfo *curCompInfo[4]; + short compsInScan; + + /* + * MCUmembership[i] indexes the i'th component of MCU into the + * curCompInfo array. + */ + short MCUmembership[10]; + + /* + * ptrs to Huffman coding tables, or NULL if not defined + */ + HuffmanTable *dcHuffTblPtrs[4]; + + /* + * prediction seletion value (PSV) and point transform parameter (Pt) + */ + int Ss; + int Pt; + + /* + * In lossless JPEG, restart interval shall be an integer + * multiple of the number of MCU in a MCU row. + */ + int restartInterval;/* MCUs per restart interval, 0 = no restart */ + int restartInRows; /*if > 0, MCU rows per restart interval; 0 = no restart*/ + + /* + * these fields are private data for the entropy decoder + */ + int restartRowsToGo; /* MCUs rows left in this restart interval */ + short nextRestartNum; /* # of next RSTn marker (0..7) */ + + int error; /* an ERROR flag */ + +} DecompressInfo; + + +/* + *-------------------------------------------------------------- + * + * swap -- + * + * Swap the contents stored in a and b. + * "type" is the variable type of a and b. + * + * Results: + * The values in a and b are swapped. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +#define swap(type,a,b) {type c; c=(a); (a)=(b); (b)=c;} + +#define MEMSET(s,c,n) memset((void *)(s),(int)(c),(int)(n)) +#define MEMCPY(s1,s2,n) memcpy((void *)(s1),(void *)(s2),(int)(n)) + +/* + * Lossless JPEG specifies data precision to be from 2 to 16 bits/sample. + */ +#define MinPrecisionBits 2 +#define MaxPrecisionBits 16 +#define MinPrecisionValue 2 +#define MaxPrecisionValue 65535 + +#endif /* _JPEG */ + diff --git a/src/jpeg/ljpg/jpegless.h b/src/jpeg/ljpg/jpegless.h new file mode 100644 index 00000000..6a198c5e --- /dev/null +++ b/src/jpeg/ljpg/jpegless.h @@ -0,0 +1,57 @@ +/* + * JPEGLess.h + * + * --------------------------------------------------------------- + * + * Lossless JPEG compression and decompression algorithms. + * + * --------------------------------------------------------------- + * + * It is based on the program originally named ljpgtopnm and pnmtoljpg. + * Major portions taken from the Independetn JPEG Group' software, and + * from the Cornell lossless JPEG code (the original copyright notices + * for those packages appears below). + * + * --------------------------------------------------------------- + * + * This is the main routine for the lossless JPEG decoder. Large + * parts are stolen from the IJG code + */ +/* + * $Id: jpegless.h,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#include "jpeg.h" + +#ifndef _JPEGLOSSLESS_ +#define _JPEGLOSSLESS_ + +#if defined(__cplusplus) +extern "C" +{ +#endif + + + +/* Global variables for lossless encoding process */ + +int psvSet[7]; /* the PSV (prediction selection value) set */ +int numSelValue; /* number of PSVs in psvSet */ +long inputFileBytes; /* the input file size in bytes */ +long outputFileBytes; /* the output file size in bytes */ +long totalHuffSym[7]; /* total bits of category symbols for each PSV */ +long totalAddBits[7]; /* total bits of additional bits for each PSV */ +int verbose; /* the verbose flag */ + + +/* + * read a JPEG lossless (8 or 16 bit) image in a file and decode it + */ +short JPEGLosslessDecodeImage (StreamIN inFile, unsigned short * image16, int depth, int length); + + +#if defined(__cplusplus) +} +#endif + +#endif /* _JPEGLOSSLESS_ */ + diff --git a/src/jpeg/ljpg/jpegutil.c b/src/jpeg/ljpg/jpegutil.c new file mode 100644 index 00000000..022332b9 --- /dev/null +++ b/src/jpeg/ljpg/jpegutil.c @@ -0,0 +1,252 @@ +/* + * jpegutil.c -- + * + * Various utility routines used in the jpeg encoder/decoder. Large parts + * are stolen from the IJG code + */ +/* + * $Id: jpegutil.c,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#include +#include +#include +#include "jpeg.h" +#include "mcu.h" +#include "proto.h" + +/* + * To fix memory leaks, memory is allocated once for the mcu buffers. + * Enough memory is reserved to accomodate up to 1024-wide images + * with up to 4 components. + */ +char mcuROW1Memory[1024 * sizeof(MCU)]; +char mcuROW2Memory[1024 * sizeof(MCU)]; +char buf1Memory[1024 * 4 * sizeof(ComponentType)]; +char buf2Memory[1024 * 4 * sizeof(ComponentType)]; + + +unsigned int bitMask[] = { 0xffffffff, 0x7fffffff, 0x3fffffff, 0x1fffffff, + 0x0fffffff, 0x07ffffff, 0x03ffffff, 0x01ffffff, + 0x00ffffff, 0x007fffff, 0x003fffff, 0x001fffff, + 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, + 0x0000ffff, 0x00007fff, 0x00003fff, 0x00001fff, + 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff, + 0x000000ff, 0x0000007f, 0x0000003f, 0x0000001f, + 0x0000000f, 0x00000007, 0x00000003, 0x00000001}; +/* + *-------------------------------------------------------------- + * + * JroundUp -- + * + * Compute a rounded up to next multiple of b; a >= 0, b > 0 + * + * Results: + * Rounded up value. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +int JroundUp (int a, int b) +{ + a += b - 1; + return a - (a % b); +} + +/* + *-------------------------------------------------------------- + * + * DecoderStructInit -- + * + * Initalize the rest of the fields in the decompression + * structure. + * + * Results: + * None. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ + +void DecoderStructInit (DecompressInfo *dcPtr) +{ + char *buf1,*buf2; + short ci,i; + JpegComponentInfo *compPtr; + int mcuSize; + + /* + * Check sampling factor validity. + */ + for (ci = 0; ci < dcPtr->numComponents; ci++) { + compPtr = &dcPtr->compInfo[ci]; + if ((compPtr->hSampFactor != 1) || (compPtr->vSampFactor != 1)) { + fprintf (stderr, "Error: Downsampling is not supported.\n"); + /* exit(-1); */ + dcPtr->error = -1; return; + } + } + + /* + * Prepare array describing MCU composition + */ + if (dcPtr->compsInScan == 1) { + dcPtr->MCUmembership[0] = 0; + } else { + short ci; + + if (dcPtr->compsInScan > 4) { + fprintf (stderr, "Too many components for interleaved scan\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + for (ci = 0; ci < dcPtr->compsInScan; ci++) { + dcPtr->MCUmembership[ci] = ci; + } + } + + /* + * Initialize mucROW1 and mcuROW2 which buffer two rows of + * pixels for predictor calculation. + */ + + mcuROW1 = (MCU *) mcuROW1Memory; + mcuROW2 = (MCU *) mcuROW2Memory; + + mcuSize=dcPtr->compsInScan * sizeof(ComponentType); + + buf1 = buf1Memory; + buf2 = buf2Memory; + + for (i=0;iimageWidth;i++) { + mcuROW1[i]=(MCU)(buf1+i*mcuSize); + mcuROW2[i]=(MCU)(buf2+i*mcuSize); + } + + dcPtr->error = 0; + +}/*endof DecoderStructInit*/ + + +/* + *-------------------------------------------------------------- + * + * FixHuffTbl -- + * + * Compute derived values for a Huffman table one the DHT marker + * has been processed. This generates both the encoding and + * decoding tables. + * + * Results: + * None. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +void FixHuffTbl (HuffmanTable *htbl) +{ + int p, i, l, lastp, si; + char huffsize[257]; + Ushort huffcode[257]; + Ushort code; + int size; + int value, ll, ul; + + /* + * Figure C.1: make table of Huffman code length for each symbol + * Note that this is in code-length order. + */ + p = 0; + for (l = 1; l <= 16; l++) { + for (i = 1; i <= (int)htbl->bits[l]; i++) + huffsize[p++] = (char)l; + } + huffsize[p] = 0; + lastp = p; + + + /* + * Figure C.2: generate the codes themselves + * Note that this is in code-length order. + */ + code = 0; + si = huffsize[0]; + p = 0; + while (huffsize[p]) { + while (((int)huffsize[p]) == si) { + huffcode[p++] = code; + code++; + } + code <<= 1; + si++; + } + + /* + * Figure C.3: generate encoding tables + * These are code and size indexed by symbol value + * Set any codeless symbols to have code length 0; this allows + * EmitBits to detect any attempt to emit such symbols. + */ + MEMSET(htbl->ehufsi, 0, sizeof(htbl->ehufsi)); + + for (p = 0; p < lastp; p++) { + htbl->ehufco[htbl->huffval[p]] = huffcode[p]; + htbl->ehufsi[htbl->huffval[p]] = huffsize[p]; + } + + /* + * Figure F.15: generate decoding tables + */ + p = 0; + for (l = 1; l <= 16; l++) { + if (htbl->bits[l]) { + htbl->valptr[l] = p; + htbl->mincode[l] = huffcode[p]; + p += htbl->bits[l]; + htbl->maxcode[l] = huffcode[p - 1]; + } else { + htbl->maxcode[l] = -1; + } + } + + /* + * We put in this value to ensure HuffDecode terminates. + */ + htbl->maxcode[17] = 0xFFFFFL; + + /* + * Build the numbits, value lookup tables. + * These table allow us to gather 8 bits from the bits stream, + * and immediately lookup the size and value of the huffman codes. + * If size is zero, it means that more than 8 bits are in the huffman + * code (this happens about 3-4% of the time). + */ + /*bzero (htbl->numbits, sizeof(htbl->numbits));*/ + memset(htbl->numbits, 0, sizeof(htbl->numbits)); + + for (p=0; phuffval[p]; + code = huffcode[p]; + ll = code << (8-size); + if (size < 8) { + ul = ll | bitMask[24+size]; + } else { + ul = ll; + } + for (i=ll; i<=ul; i++) { + htbl->numbits[i] = size; + htbl->value[i] = value; + } + } + } +} + + diff --git a/src/jpeg/ljpg/libljpg.la b/src/jpeg/ljpg/libljpg.la new file mode 100644 index 00000000..9409a14f --- /dev/null +++ b/src/jpeg/ljpg/libljpg.la @@ -0,0 +1,35 @@ +# libljpg.la - a libtool library file +# Generated by ltmain.sh - GNU libtool 1.5 (1.1220 2003/04/05 19:32:58) +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='' + +# Names of this library. +library_names='' + +# The name of the static archive. +old_library='libljpg.a' + +# Libraries that this one depends upon. +dependency_libs='' + +# Version information for libljpg. +current= +age= +revision= + +# Is this an already installed library? +installed=no + +# Should we warn about portability when linking against -modules? +shouldnotlink=no + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='' diff --git a/src/jpeg/ljpg/mcu.c b/src/jpeg/ljpg/mcu.c new file mode 100644 index 00000000..85c4b5e9 --- /dev/null +++ b/src/jpeg/ljpg/mcu.c @@ -0,0 +1,122 @@ +/* + * mcu.c -- + * + * Support for MCU allocation, deallocation, and printing. + * + */ +/* + * $Id: mcu.c,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#include +#include +#include +#include "jpeg.h" +#include "mcu.h" +#include "proto.h" + +MCU *mcuTable; /* the global mcu table that buffers the source image */ + +MCU *mcuROW1=NULL; /* point to two rows of MCU in encoding & decoding */ +MCU *mcuROW2=NULL; + +int numMCU; /* number of MCUs in mcuTable */ + +/* + *-------------------------------------------------------------- + * + * MakeMCU, InitMcuTable -- + * + * InitMcuTable does a big malloc to get the amount of memory + * we'll need for storing MCU's, once we know the size of our + * input and output images. + * MakeMCU returns an MCU for input parsing. + * + * Results: + * A new MCU + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +void InitMcuTable (int numMCU,int compsInScan) +{ + int i, mcuSize; + char *buffer; + + /* + * Compute size of on MCU (in bytes). Round up so it's on a + * boundary for any alignment. In this code, we assume this + * is a whole multiple of sizeof(double). + */ + mcuSize = compsInScan * sizeof(ComponentType); + mcuSize = JroundUp(mcuSize,sizeof(double)); + + /* + * Allocate the MCU table, and a buffer which will contain all + * the data. Then carve up the buffer by hand. Note that + * mcuTable[0] points to the buffer, in case we want to free + * it up later. + */ + mcuTable = (MCU *)malloc(numMCU * sizeof(MCU)); + if (mcuTable==NULL) + fprintf(stderr,"Not enough memory for mcuTable\n"); + buffer = (char *)malloc(numMCU * mcuSize); + if (buffer==NULL) + fprintf(stderr,"Not enough memory for buffer\n"); + for (i=0; i +#include "mcu.h" + +#ifdef DEBUG +/* + *-------------------------------------------------------------- + * + * Predict -- + * + * Calculate the predictor for pixel[row][col][curComp], + * i.e. curRowBuf[col][curComp]. It handles the all special + * cases at image edges, such as first row and first column + * of a scan. + * + * Results: + * predictor is passed out. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +void +Predict(int row,int col, /* position of the pixel to be predicted */ + int curComp, /* the pixel's component that is predicting */ + MCU *curRowBuf,MCU *prevRowBuf, /* current and previous row of image */ + int Pr, /* data precision */ + int Pt, /* point transformation */ + int psv, /* predictor selection value */ + int *predictor) /* preditor value (output) */ +{ + register int left,upper,diag,leftcol; + + leftcol=col-1; + if (row==0) { + + /* + * The predictor of first pixel is (1<<(Pr-Pt-1), and the + * predictors for rest of first row are left neighbors. + */ + if (col==0) { + *predictor = (1<<(Pr-Pt-1)); + } + else { + *predictor = curRowBuf[leftcol][curComp]; + } + } + else { + + /* + * The predictors of first column are upper neighbors. + * All other preditors are calculated according to psv. + */ + upper=prevRowBuf[col][curComp]; + if (col==0) + *predictor = upper; + else { + left=curRowBuf[leftcol][curComp]; + diag=prevRowBuf[leftcol][curComp]; + switch (psv) { + case 0: + *predictor = 0; + break; + case 1: + *predictor = left; + break; + case 2: + *predictor = upper; + break; + case 3: + *predictor = diag; + break; + case 4: + *predictor = left+upper-diag; + break; + case 5: + *predictor = left+((upper-diag)>>1); + break; + case 6: + *predictor = upper+((left-diag)>>1); + break; + case 7: + *predictor = (left+upper)>>1; + break; + default: + fprintf(stderr,"Warning: Undefined PSV\n"); + *predictor = 0; + } + } + } +} + +/* + *-------------------------------------------------------------- + * + * QuickPredict -- + * + * Calculate the predictor for sample curRowBuf[col][curComp]. + * It does not handle the special cases at image edges, such + * as first row and first column of a scan. We put the special + * case checkings outside so that the computations in main + * loop can be simpler. This has enhenced the performance + * significantly. + * + * Results: + * predictor is passed out. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +void +QuickPredict(int col /* column # of the pixel to be predicted */, + int curComp /* the pixel's component that is predicting */, + MCU *curRowBuf,MCU *prevRowBuf,/* current and previous row of image */ + int psv /* predictor selection value */, + int predictor /* preditor value (output) */) +{ + register int left,upper,diag,leftcol; + + /* + * All predictor are calculated according to psv. + */ + switch (psv) { + case 0: + *predictor = 0; + break; + case 1: + leftcol = col-1; + left = curRowBuf[leftcol][curComp]; + *predictor = left; + break; + case 2: + upper = prevRowBuf[col][curComp]; + *predictor = upper; + break; + case 3: + leftcol = col-1; + diag = prevRowBuf[leftcol][curComp]; + *predictor = diag; + break; + case 4: + leftcol = col-1; + upper = prevRowBuf[col][curComp]; + left = curRowBuf[leftcol][curComp]; + diag = prevRowBuf[leftcol][curComp]; + *predictor = left + upper - diag; + break; + case 5: + leftcol = col-1; + upper = prevRowBuf[col][curComp]; + left = curRowBuf[leftcol][curComp]; + diag = prevRowBuf[leftcol][curComp]; + *predictor = left+((upper-diag)>>1); + break; + case 6: + leftcol = col-1; + upper = prevRowBuf[col][curComp]; + left = curRowBuf[leftcol][curComp]; + diag = prevRowBuf[leftcol][curComp]; + *predictor = upper+((left-diag)>>1); + break; + case 7: + leftcol = col-1; + upper = prevRowBuf[col][curComp]; + left = curRowBuf[leftcol][curComp]; + *predictor = (left+upper)>>1; + break; + default: + fprintf(stderr,"Warning: Undefined PSV\n"); + *predictor = 0; + } +} +#endif /*DEBUG*/ diff --git a/src/jpeg/ljpg/predict.h b/src/jpeg/ljpg/predict.h new file mode 100644 index 00000000..107ad7c4 --- /dev/null +++ b/src/jpeg/ljpg/predict.h @@ -0,0 +1,168 @@ +/* + * predict.h -- + * + * Code for predictor calculation. Its function version, predictor.c, + * is used in debugging compilation. + */ +/* + * $Id: predict.h,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#ifndef _PREDICTOR +#define _PREDICTOR + +#ifndef DEBUG + +/* + *-------------------------------------------------------------- + * + * Predict -- + * + * Calculate the predictor for pixel[row][col][curComp], + * i.e. curRowBuf[col][curComp]. It handles the all special + * cases at image edges, such as first row and first column + * of a scan. + * + * Results: + * predictor is passed out. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +#define Predict(row,col,curComp,curRowBuf,prevRowBuf,Pr,Pt,psv,predictor) \ +{ register int left,upper,diag,leftcol; \ + \ + leftcol=col-1; \ + if (row==0) { \ + \ + /* \ + * The predictor of first pixel is (1<<(Pr-Pt-1), and the \ + * predictors for rest of first row are left neighbors. \ + */ \ + if (col==0) { \ + *predictor = (1<<(Pr-Pt-1)); \ + } \ + else { \ + *predictor = curRowBuf[leftcol][curComp]; \ + } \ + } \ + else { \ + \ + /* \ + * The predictors of first column are upper neighbors. \ + * All other preditors are calculated according to psv. \ + */ \ + upper=prevRowBuf[col][curComp]; \ + if (col==0) \ + *predictor = upper; \ + else { \ + left=curRowBuf[leftcol][curComp]; \ + diag=prevRowBuf[leftcol][curComp]; \ + switch (psv) { \ + case 0: \ + *predictor = 0; \ + break; \ + case 1: \ + *predictor = left; \ + break; \ + case 2: \ + *predictor = upper; \ + break; \ + case 3: \ + *predictor = diag; \ + break; \ + case 4: \ + *predictor = left+upper-diag; \ + break; \ + case 5: \ + *predictor = left+((upper-diag)>>1); \ + break; \ + case 6: \ + *predictor = upper+((left-diag)>>1); \ + break; \ + case 7: \ + *predictor = (left+upper)>>1; \ + break; \ + default: \ + fprintf(stderr,"Warning: Undefined PSV\n"); \ + *predictor = 0; \ + } \ + } \ + } \ +} + +/* + *-------------------------------------------------------------- + * + * QuickPredict -- + * + * Calculate the predictor for sample curRowBuf[col][curComp]. + * It does not handle the special cases at image edges, such + * as first row and first column of a scan. We put the special + * case checkings outside so that the computations in main + * loop can be simpler. This has enhenced the performance + * significantly. + * + * Results: + * predictor is passed out. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +#define QuickPredict(col,curComp,curRowBuf,prevRowBuf,psv,predictor){ \ + register int left,upper,diag,leftcol; \ + \ + /* \ + * All predictor are calculated according to psv. \ + */ \ + switch (psv) { \ + case 0: \ + *predictor = 0; \ + break; \ + case 1: \ + *predictor = curRowBuf [col-1] [curComp]; \ + break; \ + case 2: \ + *predictor = prevRowBuf[col][curComp]; \ + break; \ + case 3: \ + *predictor = prevRowBuf [col-1] [curComp]; \ + break; \ + case 4: \ + leftcol = col-1; \ + upper = prevRowBuf[col][curComp]; \ + left = curRowBuf[leftcol][curComp]; \ + diag = prevRowBuf[leftcol][curComp]; \ + *predictor = left + upper - diag; \ + break; \ + case 5: \ + leftcol = col-1; \ + upper = prevRowBuf[col][curComp]; \ + left = curRowBuf[leftcol][curComp]; \ + diag = prevRowBuf[leftcol][curComp]; \ + *predictor = left+((upper-diag)>>1); \ + break; \ + case 6: \ + leftcol = col-1; \ + upper = prevRowBuf[col][curComp]; \ + left = curRowBuf[leftcol][curComp]; \ + diag = prevRowBuf[leftcol][curComp]; \ + *predictor = upper+((left-diag)>>1); \ + break; \ + case 7: \ + leftcol = col-1; \ + upper = prevRowBuf[col][curComp]; \ + left = curRowBuf[leftcol][curComp]; \ + *predictor = (left+upper)>>1; \ + break; \ + default: \ + fprintf(stderr,"Warning: Undefined PSV\n"); \ + *predictor = 0; \ + } \ +} + +#endif /* DEBUG */ +#endif /* _PREDICTOR */ diff --git a/src/jpeg/ljpg/proto.h b/src/jpeg/ljpg/proto.h new file mode 100644 index 00000000..5b3a55de --- /dev/null +++ b/src/jpeg/ljpg/proto.h @@ -0,0 +1,47 @@ +/* + * proto.h -- + * + * Part of the Independent JPEG Group's software. + * See the file Copyright for more details. + */ +/* + * $Id: proto.h,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#ifndef _PROTO +#define _PROTO + +#ifdef __STDC__ + # define P(s) s +#else + # define P(s) () +#endif + +#include "mcu.h" + + +/* huffd.c */ +void HuffDecoderInit P((DecompressInfo *dcPtr )); +void DecodeImage P((DecompressInfo *dcPtr, unsigned short **image, int depth)); +void FixHuffTbl (HuffmanTable *htbl); + +/* decomp.c */ +int ReadJpegData P((Uchar *buffer , int numBytes)); + +/* read.c */ +void ReadFileHeader P((DecompressInfo *dcPtr )); +int ReadScanHeader P((DecompressInfo *dcPtr )); +int GetJpegChar(); +void UnGetJpegChar(int ch); + +/* util.c */ +int JroundUp P((int a , int b )); +void DecoderStructInit P((DecompressInfo *dcPtr )); + + /* mcu.c */ +void InitMcuTable P((int numMCU , int blocksInMCU )); +void PrintMCU P((int blocksInMCU , MCU mcu )); + + +#undef P +#endif /* _PROTO */ + diff --git a/src/jpeg/ljpg/read.c b/src/jpeg/ljpg/read.c new file mode 100644 index 00000000..3753d63a --- /dev/null +++ b/src/jpeg/ljpg/read.c @@ -0,0 +1,673 @@ +/* + * read.c -- + * + * Code for reading and processing JPEG markers. Large parts are grabbed + * from the IJG software + */ +/* + * $Id: read.c,v 1.1 2003/10/21 12:08:54 jpr Exp $ + */ +#include +#include +#include +#include "jpeg.h" +#include "mcu.h" +#include "io.h" +#include "proto.h" + +/* + * To fix a memory leak (memory malloc'd then never freed) in the original + * version of lossless JPEG decompression, memory is allocated for 4 + * Huffman tables once here, then pointers set later as needed + */ + +HuffmanTable HuffmanTableMemory[4]; + +/* + * Enumerate all the JPEG marker codes + */ +typedef enum { + M_SOF0 = 0xc0, + M_SOF1 = 0xc1, + M_SOF2 = 0xc2, + M_SOF3 = 0xc3, + + M_SOF5 = 0xc5, + M_SOF6 = 0xc6, + M_SOF7 = 0xc7, + + M_JPG = 0xc8, + M_SOF9 = 0xc9, + M_SOF10 = 0xca, + M_SOF11 = 0xcb, + + M_SOF13 = 0xcd, + M_SOF14 = 0xce, + M_SOF15 = 0xcf, + + M_DHT = 0xc4, + + M_DAC = 0xcc, + + M_RST0 = 0xd0, + M_RST1 = 0xd1, + M_RST2 = 0xd2, + M_RST3 = 0xd3, + M_RST4 = 0xd4, + M_RST5 = 0xd5, + M_RST6 = 0xd6, + M_RST7 = 0xd7, + + M_SOI = 0xd8, + M_EOI = 0xd9, + M_SOS = 0xda, + M_DQT = 0xdb, + M_DNL = 0xdc, + M_DRI = 0xdd, + M_DHP = 0xde, + M_EXP = 0xdf, + + M_APP0 = 0xe0, + M_APP15 = 0xef, + + M_JPG0 = 0xf0, + M_JPG13 = 0xfd, + M_COM = 0xfe, + + M_TEM = 0x01, + + M_ERROR = 0x100 +} JpegMarker; + + +/* + *-------------------------------------------------------------- + * + * Get2bytes -- + * + * Get a 2-byte unsigned integer (e.g., a marker parameter length + * field) + * + * Results: + * Next two byte of input as an integer. + * + * Side effects: + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +static Uint Get2bytes (void) +{ + int a; + a = GetJpegChar(); + return (a << 8) + GetJpegChar(); +} + +/* + *-------------------------------------------------------------- + * + * SkipVariable -- + * + * Skip over an unknown or uninteresting variable-length marker + * + * Results: + * None. + * + * Side effects: + * Bitstream is parsed over marker. + * + * + *-------------------------------------------------------------- + */ +static void SkipVariable (DecompressInfo *dcPtr) +{ + int length; + + length = Get2bytes () - 2; + + while (length--) { + GetJpegChar(); + } +} + +/* + *-------------------------------------------------------------- + * + * GetDht -- + * + * Process a DHT marker + * + * Results: + * None + * + * Side effects: + * A huffman table is read. + * Exits on error. + * + *-------------------------------------------------------------- + */ +static void GetDht (DecompressInfo *dcPtr) +{ + int length; + Uchar bits[17]; + Uchar huffval[256]; + int i, index, count; + HuffmanTable **htblptr=NULL; + + length = Get2bytes () - 2; + + while (length) { + index = GetJpegChar(); + + bits[0] = 0; + count = 0; + for (i = 1; i <= 16; i++) { + bits[i] = GetJpegChar(); + count += bits[i]; + } + + if (count > 256) { + fprintf (stderr, "Bogus DHT counts\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + for (i = 0; i < count; i++) + huffval[i] = GetJpegChar(); + + length -= 1 + 16 + count; + + if (index & 0x10) { /* AC table definition */ + fprintf(stderr,"Huffman table for lossless JPEG is not defined.\n"); + } + else { /* DC table definition */ + htblptr = &dcPtr->dcHuffTblPtrs[index]; + } + + if (index < 0 || index >= 4) + { + fprintf (stderr, "Bogus DHT index %d\n", index); + /* exit (1); */ + dcPtr->error = -1; return; + } + + if (*htblptr == NULL) + { + *htblptr = &HuffmanTableMemory[index]; + if (*htblptr==NULL) + { + fprintf(stderr,"Can't malloc HuffmanTable\n"); + /* exit(-1); */ + dcPtr->error = -1; return; + } + } + + MEMCPY((*htblptr)->bits, bits, sizeof ((*htblptr)->bits)); + MEMCPY((*htblptr)->huffval, huffval, sizeof ((*htblptr)->huffval)); + } +} + +/* + *-------------------------------------------------------------- + * + * GetDri -- + * + * Process a DRI marker + * + * Results: + * None + * + * Side effects: + * Exits on error. + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +static void GetDri (DecompressInfo *dcPtr) +{ + if (Get2bytes () != 4) + { + fprintf (stderr, "Bogus length in DRI\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + dcPtr->restartInterval = (Ushort) Get2bytes (); +} + +/* + *-------------------------------------------------------------- + * + * GetApp0 -- + * + * Process an APP0 marker. + * + * Results: + * None + * + * Side effects: + * Bitstream is parsed + * + *-------------------------------------------------------------- + */ +static void GetApp0 (DecompressInfo *dcPtr) +{ + int length; + + length = Get2bytes () - 2; + while (length-- > 0) /* skip any remaining data */ + (void)GetJpegChar(); +} + +/* + *-------------------------------------------------------------- + * + * GetSof -- + * + * Process a SOFn marker + * + * Results: + * None. + * + * Side effects: + * Bitstream is parsed + * Exits on error + * dcPtr structure is filled in + * + *-------------------------------------------------------------- + */ +static void GetSof (DecompressInfo *dcPtr, int code) +{ + int length; + short ci; + int c; + JpegComponentInfo *compptr; + + code = code; + + length = Get2bytes (); + + dcPtr->dataPrecision = GetJpegChar(); + dcPtr->imageHeight = Get2bytes (); + dcPtr->imageWidth = Get2bytes (); + dcPtr->numComponents = GetJpegChar(); + + /* + * We don't support files in which the image height is initially + * specified as 0 and is later redefined by DNL. As long as we + * have to check that, might as well have a general sanity check. + */ + if ((dcPtr->imageHeight <= 0 ) || + (dcPtr->imageWidth <= 0) || + (dcPtr->numComponents <= 0)) { + fprintf (stderr, "Empty JPEG image (DNL not supported)\n"); + /* exit(1); */ + dcPtr->error = -1; return; + } + + if ((dcPtr->dataPrecisiondataPrecision>MaxPrecisionBits)) { + fprintf (stderr, "Unsupported JPEG data precision\n"); + /* exit(1); */ + dcPtr->error = -1; return; + } + + if (length != (dcPtr->numComponents * 3 + 8)) { + fprintf (stderr, "Bogus SOF length\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + for (ci = 0; ci < dcPtr->numComponents; ci++) { + compptr = &dcPtr->compInfo[ci]; + compptr->componentIndex = ci; + compptr->componentId = GetJpegChar(); + c = GetJpegChar(); + compptr->hSampFactor = (c >> 4) & 15; + compptr->vSampFactor = (c) & 15; + (void) GetJpegChar(); /* skip Tq */ + } +}/*endof GetSof */ + + +/* + *-------------------------------------------------------------- + * + * GetSos -- + * + * Process a SOS marker + * + * Results: + * None. + * + * Side effects: + * Bitstream is parsed. + * Exits on error. + * + *-------------------------------------------------------------- + */ +static void GetSos (DecompressInfo *dcPtr) +{ + int length; + int i, ci, n, c, cc; + JpegComponentInfo *compptr; + + length = Get2bytes (); + + /* + * Get the number of image components. + */ + n = GetJpegChar(); + dcPtr->compsInScan = n; + length -= 3; + + if (length != (n * 2 + 3) || n < 1 || n > 4) { + fprintf (stderr, "Bogus SOS length\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + + for (i = 0; i < n; i++) { + cc = GetJpegChar(); + c = GetJpegChar(); + length -= 2; + + for (ci = 0; ci < dcPtr->numComponents; ci++) + if (cc == dcPtr->compInfo[ci].componentId) { + break; + } + + if (ci >= dcPtr->numComponents) { + fprintf (stderr, "Invalid component number in SOS\n"); + /* exit (1); */ + dcPtr->error = -1; return; + } + + compptr = &dcPtr->compInfo[ci]; + dcPtr->curCompInfo[i] = compptr; + compptr->dcTblNo = (c >> 4) & 15; + } + + /* + * Get the PSV, skip Se, and get the point transform parameter. + */ + dcPtr->Ss = GetJpegChar(); + (void)GetJpegChar(); + c = GetJpegChar(); + dcPtr->Pt = c & 0x0F; +}/*endof GetSos */ + + +/* + *-------------------------------------------------------------- + * + * GetSoi -- + * + * Process an SOI marker + * + * Results: + * None. + * + * Side effects: + * Bitstream is parsed. + * Exits on error. + * + *-------------------------------------------------------------- + */ +static void GetSoi (DecompressInfo *dcPtr) +{ + + /* + * Reset all parameters that are defined to be reset by SOI + */ + dcPtr->restartInterval = 0; +} + +/* + *-------------------------------------------------------------- + * + * NextMarker -- + * + * Find the next JPEG marker Note that the output might not + * be a valid marker code but it will never be 0 or FF + * + * Results: + * The marker found. + * + * Side effects: + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +static int NextMarker (void) +{ + int c, nbytes; + + nbytes = 0; + do { + /* + * skip any non-FF bytes + */ + do { + nbytes++; + c = GetJpegChar(); + } while (c != 0xFF); + /* + * skip any duplicate FFs without incrementing nbytes, since + * extra FFs are legal + */ + do { + c = GetJpegChar(); + } while (c == 0xFF); + } while (c == 0); /* repeat if it was a stuffed FF/00 */ + + return c; +} + +/* + *-------------------------------------------------------------- + * + * ProcessTables -- + * + * Scan and process JPEG markers that can appear in any order + * Return when an SOI, EOI, SOFn, or SOS is found + * + * Results: + * The marker found. + * + * Side effects: + * Bitstream is parsed. + * + *-------------------------------------------------------------- + */ +static JpegMarker ProcessTables (dcPtr) + DecompressInfo *dcPtr; +{ + int c; + + while (1) { + c = NextMarker (); + + switch (c) { + case M_SOF0: + case M_SOF1: + case M_SOF2: + case M_SOF3: + case M_SOF5: + case M_SOF6: + case M_SOF7: + case M_JPG: + case M_SOF9: + case M_SOF10: + case M_SOF11: + case M_SOF13: + case M_SOF14: + case M_SOF15: + case M_SOI: + case M_EOI: + case M_SOS: + return ((JpegMarker)c); + + case M_DHT: + GetDht (dcPtr); if (dcPtr->error) return 0; + break; + + case M_DQT: + fprintf(stderr,"Not a lossless JPEG file.\n"); + break; + + case M_DRI: + GetDri (dcPtr); if (dcPtr->error) return 0; + break; + + case M_APP0: + GetApp0 (dcPtr); + break; + + case M_RST0: /* these are all parameterless */ + case M_RST1: + case M_RST2: + case M_RST3: + case M_RST4: + case M_RST5: + case M_RST6: + case M_RST7: + case M_TEM: + fprintf (stderr, "Warning: unexpected marker 0x%02x\n", c); + break; + + default: /* must be DNL, DHP, EXP, APPn, JPGn, COM, + * or RESn */ + SkipVariable (dcPtr); + break; + } + } +}/*endof ProcessTables */ + + +/* + *-------------------------------------------------------------- + * + * ReadFileHeader -- + * + * Initialize and read the file header (everything through + * the SOF marker). + * + * Results: + * None + * + * Side effects: + * Exit on error. + * + *-------------------------------------------------------------- + */ +void ReadFileHeader (DecompressInfo *dcPtr) +{ + int c, c2; + + /* + * Demand an SOI marker at the start of the file --- otherwise it's + * probably not a JPEG file at all. + */ + c = GetJpegChar(); + c2 = GetJpegChar(); + if ((c != 0xFF) || (c2 != M_SOI)) { + if( c == EOF ) { + fprintf(stderr, "Reached end of input file. All done!\n"); + /* fclose(outFile); */ + /* exit(1); */ + dcPtr->error = -1; return; + } else { + fprintf (stderr, "Not a JPEG file. Found %02X %02X\n", c, c2); + /* exit (1); */ + dcPtr->error = -1; return; + } + }/*endif*/ + + GetSoi (dcPtr); if (dcPtr->error) return; /* OK, process SOI */ + + /* + * Process markers until SOF + */ + c = ProcessTables (dcPtr); if (dcPtr->error) return; + + switch (c) { + case M_SOF0: + case M_SOF1: + case M_SOF3: + GetSof (dcPtr, c); + break; + + default: + fprintf (stderr, "Unsupported SOF marker type 0x%02x\n", c); + break; + } +}/*endof ReadFileHeader*/ + + +/* + *-------------------------------------------------------------- + * + * ReadScanHeader -- + * + * Read the start of a scan (everything through the SOS marker). + * + * Results: + * 1 if find SOS, 0 if find EOI + * + * Side effects: + * Bitstream is parsed, may exit on errors. + * + *-------------------------------------------------------------- + */ +int ReadScanHeader (DecompressInfo *dcPtr) +{ + int c; + + /* + * Process markers until SOS or EOI + */ + c = ProcessTables (dcPtr); if (dcPtr->error) return 0; + + switch (c) { + case M_SOS: + GetSos (dcPtr); + return 1; + + case M_EOI: + return 0; + + default: + fprintf (stderr, "Unexpected marker 0x%02x\n", c); + break; + } + return 0; +}/*endof ReadScanHeader*/ + + +/* + *-------------------------------------------------------------- + * + * GetJpegChar, UnGetJpegChar -- + * + * + * Results: + * GetJpegChar returns the next character in the stream, or EOF + * UnGetJpegChar returns nothing. + * + * Side effects: + * A byte is consumed or put back into the inputBuffer. + * + *-------------------------------------------------------------- + */ +int GetJpegChar(void) +{ + return (int)inputBuffer[inputBufferOffset++]; +} + +void UnGetJpegChar(int ch) +{ + inputBuffer[--inputBufferOffset] = ch; +} + -- 2.45.1