libpgf/ 40777 0 0 0 12323042325 5334 5libpgf/autogen.sh100777 0 0 200 12232452342 7405 0#! /bin/sh touch NEWS && touch AUTHORS libtoolize --copy --force && aclocal && automake --gnu --add-missing --copy && autoconf libpgf/config.h.in100777 0 0 3015 12232452335 7463 0/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR /* Name of package */ #undef PACKAGE /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Version number of package */ #undef VERSION libpgf/configure.ac100777 0 0 2142 12313041777 7732 0AC_INIT(src/PGFimage.cpp) dnl The library interface version dnl see documentation for versioning in the libtool manual dnl NOTE: these should only be updated before public releases dnl The current version of the interface. If interfaces has been dnl added removed changed bump this INTERFACE_CURRENT=6 dnl If the source has been changed bump this INTERFACE_REVISION=11 dnl If any interfaces has been added since last release, bump this dnl If any interfaces has been removed, set this to 0 dnl The age is always less than CURRENT INTERFACE_AGE=0 INTERFACE_VERSION=$INTERFACE_CURRENT:$INTERFACE_REVISION:$INTERFACE_AGE AC_SUBST(INTERFACE_VERSION) PACKAGE_RELEASE=2 AC_SUBST(PACKAGE_RELEASE) AM_INIT_AUTOMAKE(libpgf,6.14.12) AC_PROG_LIBTOOL AC_CONFIG_HEADERS( config.h ) AC_PROG_CXX dnl Check for doxygen support AC_PATH_PROG([DOXYGEN], [doxygen]) AC_PATH_PROG([DOT], [dot]) AM_CONDITIONAL(HAS_DOXYGEN, test $DOXYGEN && $DOT) # Generate output AC_OUTPUT(Makefile src/Makefile include/Makefile doc/Makefile doc/Doxyfile libpgf.spec libpgf.pc ) libpgf/COPYING100777 0 0 57475 12232452342 6534 0 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONSlibpgf/doc/ 40777 0 0 0 12323042641 6102 5libpgf/doc/Doxyfile.in100777 0 0 225407 12313041610 10361 0# Doxyfile 1.7.4 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project # # All text after a hash (#) is considered a comment and will be ignored # The format is: # TAG = value [value, ...] # For lists items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (" ") #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # http://www.gnu.org/software/libiconv for the list of possible encodings. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. PROJECT_NAME = libpgf # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = 6.14.12 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer # a quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = "PGF - Progressive Graphics File" # With the PROJECT_LOGO tag one can specify an logo or icon that is # included in the documentation. The maximum height of the logo should not # exceed 55 pixels and the maximum width should not exceed 200 pixels. # Doxygen will copy the logo to the output directory. PROJECT_LOGO = "./PGF.PNG" # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = . # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output # format and will distribute the generated files over these directories. # Enabling this option can be useful when feeding doxygen a huge amount of # source files, where putting all generated files in the same directory would # otherwise cause performance problems for the file system. CREATE_SUBDIRS = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend # the brief description of a member or function before the detailed description. # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator # that is used to form the text in various listings. Each string # in this list, if found as the leading text of the brief description, will be # stripped from the text and the result after processing the whole list, is # used as the annotated text. Otherwise, the brief description is used as-is. # If left blank, the following values are used ("$name" is automatically # replaced with the name of the entity): "The $name class" "The $name widget" # "The $name file" "is" "provides" "specifies" "contains" # "represents" "a" "an" "the" ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = YES # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. INLINE_INHERITED_MEMB = YES # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = NO # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag # can be used to strip a user-defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the # path to strip. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells # the reader which header file to include in order to use a class. # If left blank only the name of the header file containing the class # definition is used. Otherwise one should specify the include paths that # are normally passed to the compiler using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful if your file system # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) JAVADOC_AUTOBRIEF = NO # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style # comment as the brief description. If set to NO, the comments # will behave just like regular Qt-style comments (thus requiring # an explicit \brief command for a brief description.) QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// # comments) as a brief description. This used to be the default behaviour. # The new default is to treat a multi-line C++ comment block as a detailed # description. Set this tag to YES if you prefer the old behaviour instead. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented # member inherits the documentation from any documented member that it # re-implements. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce # a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 8 # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". # For example adding "sideeffect=\par Side Effects:\n" will allow you to # put the command \sideeffect (or @sideeffect) in the documentation, which # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. # For instance, some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = NO # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java # sources only. Doxygen will then generate output that is more tailored for # Java. For instance, namespaces will be presented as packages, qualified # scopes will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources only. Doxygen will then generate output that is more tailored for # Fortran. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for # VHDL. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given extension. # Doxygen has a built-in mapping, but you can override or extend it using this # tag. The format is ext=language, where ext is a file extension, and language # is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, # C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make # doxygen treat .inc files as Fortran files (default is PHP), and .f files as C # (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions # you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. EXTENSION_MAPPING = # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. # func(std::string) {}). This also makes the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = NO # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. # Doxygen will parse them like normal C++ but will assume all classes use public # instead of private inheritance when no explicit protection keyword is present. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate getter # and setter methods for a property. Setting this option to YES (the default) # will make doxygen replace the get and set methods by a property in the # documentation. This will only work if the methods are indeed getting or # setting a simple type. If this is not the case, or you want to show the # methods anyway, you should set this option to NO. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO # Set the SUBGROUPING tag to YES (the default) to allow class member groups of # the same type (for instance a group of public functions) to be put as a # subgroup of that type (e.g. under the Public Functions section). Set it to # NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. SUBGROUPING = YES # When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and # unions are shown inside the group in which they are included (e.g. using # @ingroup) instead of on a separate page (for HTML and Man pages) or # section (for LaTeX and RTF). INLINE_GROUPED_CLASSES = NO # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum # is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically # be useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. TYPEDEF_HIDES_STRUCT = NO # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to # determine which symbols to keep in memory and which to flush to disk. # When the cache is full, less often used symbols will be written to disk. # For small to medium size projects (<1000 input files) the default value is # probably good enough. For larger projects a too small cache size can cause # doxygen to be busy swapping symbols to and from disk most of the time # causing a significant performance penalty. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on # a logarithmic scale so increasing the size by one will roughly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols SYMBOL_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = YES # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in # the interface are included in the documentation. # If set to NO (the default) only methods in the interface are included. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base # name of the file that contains the anonymous namespace. By default # anonymous namespaces are hidden. EXTRACT_ANON_NSPACES = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the # various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = YES # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. # If set to NO (the default) these classes will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = YES # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all # friend (class|struct|union) declarations. # If set to NO (the default) these declarations will be included in the # documentation. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any # documentation blocks found inside the body of a function. # If set to NO (the default) these blocks will be appended to the # function's detailed documentation block. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation # that is typed after a \internal command is included. If the tag is set # to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate # file names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen # will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES # If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen # will list include files with double quotes in the documentation # rather than with sharp brackets. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen # will sort the (detailed) documentation of file and class members # alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the # brief documentation of file, namespace and class members alphabetically # by member name. If set to NO (the default) the members will appear in # declaration order. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen # will sort the (brief and detailed) documentation of class members so that # constructors and destructors are listed first. If set to NO (the default) # the constructors will appear in the respective orders defined by # SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. # This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO # and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the # hierarchy of group names into alphabetical order. If set to NO (the default) # the group names will appear in their defined order. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to # NO (the default), the class list will be sorted only by class name, # not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the # alphabetical list. SORT_BY_SCOPE_NAME = NO # If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to # do proper type resolution of all parameters of a function it will reject a # match between the prototype and the implementation of a member function even # if there is only one candidate or it is obvious which candidate to choose # by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen # will still accept a match between prototype and implementation in such cases. STRICT_PROTO_MATCHING = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or # disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or # disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or # disable (NO) the deprecated list. This list is created by putting # \deprecated commands in the documentation. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or macro consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and macros in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES # If the sources in your project are distributed over multiple directories # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy # in the documentation. The default is NO. SHOW_DIRECTORIES = NO # Set the SHOW_FILES tag to NO to disable the generation of the Files page. # This will remove the Files entry from the Quick Index and from the # Folder Tree View (if specified). The default is YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the # Namespaces page. This will remove the Namespaces entry from the Quick Index # and from the Folder Tree View (if specified). The default is YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file # provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. The create the layout file # that represents doxygen's defaults, run doxygen with the -l option. # You can optionally specify a file name after the option, if omitted # DoxygenLayout.xml will be used as the name of the layout file. LAYOUT_FILE = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some # parameters in a documented function, or documenting parameters that # don't exist or using markup commands wrongly. WARN_IF_DOC_ERROR = YES # The WARN_NO_PARAMDOC option can be enabled to get warnings for # functions that are documented, but have no documentation for their parameters # or return value. If set to NO (the default) doxygen will only warn about # wrong or incomplete parameter documentation, but not about the absence of # documentation. WARN_NO_PARAMDOC = NO # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the # warning originated and the warning text. Optionally the format may contain # $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written # to stderr. WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag can be used to specify the files and/or directories that contain # documented source files. You may enter file names like "myfile.cpp" or # directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = .. # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is # also the default input encoding. Doxygen uses libiconv (or the iconv built # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for # the list of possible encodings. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh # *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py # *.f90 *.f *.for *.vhd *.vhdl FILE_PATTERNS = *.c \ *.cc \ *.cxx \ *.cpp \ *.c++ \ *.d \ *.java \ *.ii \ *.ixx \ *.ipp \ *.i++ \ *.inl \ *.h \ *.hh \ *.hxx \ *.hpp \ *.h++ \ *.idl \ *.odl \ *.cs \ *.php \ *.php3 \ *.inc \ *.m \ *.mm \ *.dox \ *.py \ *.C \ *.CC \ *.C++ \ *.II \ *.I++ \ *.H \ *.HH \ *.H++ \ *.CS \ *.PHP \ *.PHP3 \ *.M \ *.MM \ *.PY # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. Note that the wildcards are matched # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. EXAMPLE_PATTERNS = * # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude # commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes # to standard output. If FILTER_PATTERNS is specified, this tag will be # ignored. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the # filter if there is a match. The filters are a list of the form: # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further # info on how filters are used. If FILTER_PATTERNS is empty or if # non of the patterns match the file name, INPUT_FILTER is applied. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source # files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) # and it is also possible to disable source filtering for a specific pattern # using *.ext= (so without naming a filter). This option only has effect when # FILTER_SOURCE_FILES is enabled. FILTER_SOURCE_PATTERNS = #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also # VERBATIM_HEADERS is set to NO. SOURCE_BROWSER = YES # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = YES # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code # fragments. Normal C and C++ comments will always remain visible. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES # then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES # then for each documented function all documented entities # called/used by that function will be listed. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will # link to the source code. Otherwise they will link to the documentation. REFERENCES_LINK_SOURCE = YES # If the USE_HTAGS tag is set to YES then the references to source code # will point to the HTML generated by the htags(1) tool instead of doxygen # built-in source browser. The htags tool is part of GNU's global source # tagging system (see http://www.gnu.org/software/global/global.html). You # will need version 4.8.6 or higher. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = NO #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = NO # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for # each generated HTML page (for example: .htm,.php,.asp). If it is left blank # doxygen will generate files with .html extension. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a # standard header. Note that when using a custom header you are responsible # for the proper inclusion of any scripts and style sheets that doxygen # needs, which is dependent on the configuration options used. # It is adviced to generate a default header using "doxygen -w html # header.html footer.html stylesheet.css YourConfigFile" and then modify # that header. Note that the header is subject to change so you typically # have to redo this when upgrading to a newer version of doxygen or when # changing the value of configuration settings such as GENERATE_TREEVIEW! HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a # standard footer. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If the tag is left blank doxygen # will generate a default style sheet. Note that doxygen will try to copy # the style sheet file to the HTML output directory, so don't put your own # stylesheet in the HTML output directory as well, or it will be erased! HTML_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the # $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these # files. In the HTML_STYLESHEET file, use the file name only. Also note that # the files will be copied as-is; there are no commands or markers available. HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. # Doxygen will adjust the colors in the stylesheet and background images # according to this color. Hue is specified as an angle on a colorwheel, # see http://en.wikipedia.org/wiki/Hue for more information. # For instance the value 0 represents red, 60 is yellow, 120 is green, # 180 is cyan, 240 is blue, 300 purple, and 360 is red again. # The allowed range is 0 to 359. HTML_COLORSTYLE_HUE = 220 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of # the colors in the HTML output. For a value of 0 the output will use # grayscales only. A value of 255 will produce the most vivid colors. HTML_COLORSTYLE_SAT = 100 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to # the luminance component of the colors in the HTML output. Values below # 100 gradually make the output lighter, whereas values above 100 make # the output darker. The value divided by 100 is the actual gamma applied, # so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, # and 100 does not change the gamma. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting # this to NO can help when comparing the output of multiple runs. HTML_TIMESTAMP = YES # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, # files or namespaces will be aligned in HTML using tables. If set to # NO a bullet list will be used. HTML_ALIGN_MEMBERS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. For this to work a browser that supports # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). HTML_DYNAMIC_SECTIONS = NO # If the GENERATE_DOCSET tag is set to YES, additional index files # will be generated that can be used as input for Apple's Xcode 3 # integrated development environment, introduced with OSX 10.5 (Leopard). # To create a documentation set, doxygen will generate a Makefile in the # HTML output directory. Running make will produce the docset in that # directory and running "make install" will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find # it at startup. # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html # for more information. GENERATE_DOCSET = NO # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the # feed. A documentation feed provides an umbrella under which multiple # documentation sets from a single provider (such as a company or product suite) # can be grouped. DOCSET_FEEDNAME = "Doxygen generated docs" # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that # should uniquely identify the documentation set bundle. This should be a # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen # will append .docset to the name. DOCSET_BUNDLE_ID = org.doxygen.Project # When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. DOCSET_PUBLISHER_ID = org.doxygen.Publisher # The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can # be used to specify the file name of the resulting .chm file. You # can add a path in front of the file if the result should not be # written to the html output directory. CHM_FILE = # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can # be used to specify the location (absolute path including file name) of # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run # the HTML help compiler on the generated index.hhp. HHC_LOCATION = # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING # is used to encode HtmlHelp index (hhk), content (hhc) and project file # content. CHM_INDEX_ENCODING = # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated # that can be used as input for Qt's qhelpgenerator to generate a # Qt Compressed Help (.qch) of the generated HTML documentation. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can # be used to specify the file name of the resulting .qch file. # The path specified is relative to the HTML output folder. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#namespace QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#virtual-folders QHP_VIRTUAL_FOLDER = doc # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to # add. For more information please see # http://doc.trolltech.com/qthelpproject.html#custom-filters QHP_CUST_FILTER_NAME = # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see # # Qt Help Project / Custom Filters. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's # filter section matches. # # Qt Help Project / Filter Attributes. QHP_SECT_FILTER_ATTRS = # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can # be used to specify the location of Qt's qhelpgenerator. # If non-empty doxygen will try to run qhelpgenerator on the generated # .qhp file. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files # will be generated, which together with the HTML files, form an Eclipse help # plugin. To install this plugin and make it available under the help contents # menu in Eclipse, the contents of the directory containing the HTML and XML # files needs to be copied into the plugins directory of eclipse. The name of # the directory within the plugins directory should be the same as # the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before # the help appears. GENERATE_ECLIPSEHELP = NO # A unique identifier for the eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have # this name. ECLIPSE_DOC_ID = org.doxygen.Project # The DISABLE_INDEX tag can be used to turn on/off the condensed index at # top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. DISABLE_INDEX = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values # (range [0,1..20]) that doxygen will group on one line in the generated HTML # documentation. Note that a value of 0 will completely suppress the enum # values from appearing in the overview section. ENUM_VALUES_PER_LINE = 4 # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. # If the tag value is set to YES, a side panel will be generated # containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). # Windows users are probably better off using the HTML help feature. GENERATE_TREEVIEW = YES # By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, # and Class Hierarchy pages using a tree view instead of an ordered list. USE_INLINE_TREES = NO # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 # When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open # links to external symbols imported via tag files in a separate window. EXT_LINKS_IN_WINDOW = NO # Use this tag to change the font size of Latex formulas included # as images in the HTML documentation. The default is 10. Note that # when you change the font size after a successful doxygen run you need # to manually remove any form_*.png images from the HTML output directory # to force them to be regenerated. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are # not supported properly for IE 6.0, but are supported on all modern browsers. # Note that when changing this option you need to delete any form_*.png files # in the HTML output before the changes have effect. FORMULA_TRANSPARENT = YES # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax # (see http://www.mathjax.org) which uses client side Javascript for the # rendering instead of using prerendered bitmaps. Use this if you do not # have LaTeX installed or if you want to formulas look prettier in the HTML # output. When enabled you also need to install MathJax separately and # configure the path to it using the MATHJAX_RELPATH option. USE_MATHJAX = NO # When MathJax is enabled you need to specify the location relative to the # HTML output directory using the MATHJAX_RELPATH option. The destination # directory should contain the MathJax.js script. For instance, if the mathjax # directory is located at the same level as the HTML output directory, then # MATHJAX_RELPATH should be ../mathjax. The default value points to the # mathjax.org site, so you can quickly see the result without installing # MathJax, but it is strongly recommended to install a local copy of MathJax # before deployment. MATHJAX_RELPATH = http://www.mathjax.org/mathjax # When the SEARCHENGINE tag is enabled doxygen will generate a search box # for the HTML output. The underlying search engine uses javascript # and DHTML and should work on any modern browser. Note that when using # HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets # (GENERATE_DOCSET) there is already a search function so this one should # typically be disabled. For large projects the javascript based search engine # can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a PHP enabled web server instead of at the web client # using Javascript. Doxygen will generate the search PHP script and index # file to put on the web server. The advantage of the server # based approach is that it scales better to large projects and allows # full text search. The disadvantages are that it is more difficult to setup # and does not have live searching capabilities. SERVER_BASED_SEARCH = NO #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = YES # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. If left blank `latex' will be used as the default command name. # Note that when enabling USE_PDFLATEX this option is only used for # generating bitmaps for formulas in the HTML output, but not in the # Makefile that is written to the output directory. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to # generate index for LaTeX. If left blank `makeindex' will be used as the # default command name. MAKEINDEX_CMD_NAME = makeindex # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used # by the printer. Possible values are: a4, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4wide # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for # the generated latex document. The header should contain everything until # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for # the generated latex document. The footer should contain everything after # the last chapter. If it is left blank doxygen will generate a # standard footer. Notice: only use this tag if you know what you are doing! LATEX_FOOTER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will # contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of # plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. # command to the generated LaTeX files. This will instruct LaTeX to keep # running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not # include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO # If LATEX_SOURCE_CODE is set to YES then doxygen will include # source code with syntax highlighting in the LaTeX output. # Note that which sources are shown also depends on other settings # such as SOURCE_BROWSER. LATEX_SOURCE_CODE = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output # The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = YES # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES Doxygen generates more compact # RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated # will contain hyperlink fields. The RTF file will # contain links (just like the HTML output) instead of page references. # This makes the output suitable for online browsing using WORD or other # programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = YES # The MAN_OUTPUT tag is used to specify where the man pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = .3 # If the MAN_LINKS tag is set to YES and Doxygen generates man output, # then it will generate one additional man file for each entity # documented in the real man page(s). These additional files # only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES Doxygen will # generate an XML file that captures the structure of # the code including all documentation. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `xml' will be used as the default path. XML_OUTPUT = xml # The XML_SCHEMA tag can be used to specify an XML schema, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_SCHEMA = # The XML_DTD tag can be used to specify an XML DTD, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_DTD = # If the XML_PROGRAMLISTING tag is set to YES Doxygen will # dump the program listings (including syntax highlighting # and cross-referencing information) to the XML output. Note that # enabling this will significantly increase the size of the XML output. XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will # generate an AutoGen Definitions (see autogen.sf.net) file # that captures the structure of the code including all # documentation. Note that this feature is still experimental # and incomplete at the moment. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES Doxygen will # generate a Perl module file that captures the structure of # the code including all documentation. Note that this # feature is still experimental and incomplete at the # moment. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES Doxygen will generate # the necessary Makefile rules, Perl scripts and LaTeX code to be able # to generate PDF and DVI output from the Perl module output. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be # nicely formatted so it can be parsed by a human reader. This is useful # if you want to understand what is going on. On the other hand, if this # tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. # This is useful so different doxyrules.make files included by the same # Makefile don't overwrite each other's variables. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # pointed to by INCLUDE_PATH will be searched when a #include is found. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by # the preprocessor. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). The argument of the tag is a list of macros of the form: name # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. To prevent a macro definition from being # undefined via #undef or recursively expanded use the := operator # instead of the = operator. PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition that # overrules the definition found in the source code. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all references to function-like macros # that are alone on a line, have an all uppercase name, and do not end with a # semicolon, because these will confuse the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- # The TAGFILES option can be used to specify one or more tagfiles. # Optionally an initial location of the external documentation # can be added for each tagfile. The format of a tag file without # this location is as follows: # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # TAGFILES = file1=loc1 "file2 = loc2" ... # where "loc1" and "loc2" can be relative or absolute paths or # URLs. If a location is present for each tag, the installdox tool # does not have to be run to correct the links. # Note that each tag file must have a unique name # (where the name does NOT include the path) # If a tag file is not located in the directory in which doxygen # is run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed # in the modules index. If set to NO, only the current project's groups will # be listed. EXTERNAL_GROUPS = YES # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base # or super classes. Setting the tag to NO turns the diagrams off. Note that # this option also works with HAVE_DOT disabled, but it is recommended to # install and use dot, since it yields more powerful graphs. CLASS_DIAGRAMS = YES # You can define message sequence charts within doxygen comments using the \msc # command. Doxygen will then run the mscgen tool (see # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the # documentation. The MSCGEN_PATH tag allows you to specify the directory where # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. MSCGEN_PATH = # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = NO # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is # allowed to run in parallel. When set to 0 (the default) doxygen will # base this on the number of processors available in the system. You can set it # explicitly to a value larger than 0 to get control over the balance # between CPU load and processing speed. DOT_NUM_THREADS = 0 # By default doxygen will write a font called Helvetica to the output # directory and reference it in all dot files that doxygen generates. # When you want a differently looking font you can specify the font name # using DOT_FONTNAME. You need to make sure dot is able to find the font, # which can be done by putting it in a standard location or by setting the # DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory # containing the font. DOT_FONTNAME = FreeSans # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. # The default size is 10pt. DOT_FONTSIZE = 10 # By default doxygen will tell dot to use the output directory to look for the # FreeSans.ttf font (which doxygen will put there itself). If you specify a # different font using DOT_FONTNAME you can set the path where dot # can find it using this tag. DOT_FONTPATH = # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the # the CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen # will generate a graph for groups, showing the direct groups dependencies GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. UML_LOOK = YES # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented # file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and # HAVE_DOT tags are set to YES then doxygen will generate a graph for each # documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH and HAVE_DOT options are set to YES then # doxygen will generate a call dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable call graphs # for selected functions only using the \callgraph command. CALL_GRAPH = YES # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then # doxygen will generate a caller dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable caller # graphs for selected functions only using the \callergraph command. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will generate a graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. Possible values are svg, png, jpg, or gif. # If left blank png will be used. DOT_IMAGE_FORMAT = png # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the # \dotfile command). DOTFILE_DIRS = # The MSCFILE_DIRS tag can be used to specify one or more directories that # contain msc files that are included in the documentation (see the # \mscfile command). MSCFILE_DIRS = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is # visualized by representing a node as a red box. Note that doxygen if the # number of direct children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the # graphs generated by dot. A depth value of 3 means that only nodes reachable # from the root by following a path via at most 3 edges will be shown. Nodes # that lay further from the root node will be omitted. Note that setting this # option to 1 or 2 may greatly reduce the computation time needed for large # code bases. Also note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. MAX_DOT_GRAPH_DEPTH = 1000 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not # seem to support this out of the box. Warning: Depending on the platform used, # enabling this option may lead to badly anti-aliased labels on the edges of # a graph (i.e. they become hard to read). DOT_TRANSPARENT = YES # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) # support this, this feature is disabled by default. DOT_MULTI_TARGETS = NO # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will # remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES libpgf/doc/Makefile.am100777 0 0 772 12232452341 10225 0DOC_MODULE=$(PACKAGE)-$(VERSION) DOC_DIR=$(DESTDIR)$(datadir)/doc/$(DOC_MODULE) doc: html/index.html clean-local: rm -rf html man latex *~ html/index.html: Doxyfile doxygen Doxyfile.in install-data-local: html/index.html $(mkinstalldirs) $(DOC_DIR)/html $(mkinstalldirs) $(DESTDIR)$(datadir)/man/man3 -(cd html && for f in *.html *.png; do $(INSTALL) -m 644 "$$f" "$(DOC_DIR)/html/$$f"; done) -(cd man/man3; for f in *.3; do $(INSTALL) -m 644 "$$f" "$(DESTDIR)$(datadir)/man/man3/$$f"; done) libpgf/doc/PGF.PNG100777 0 0 3033 12232452341 7164 0‰PNG  IHDR…4+.l»sRGB®ÎégAMA± üa pHYsÃÃÇo¨d°IDATx^휋±ƒ E)Æf,À2l&e¤›I1¾ á'., 3/'c ÑÈaÿˆØ¯‘z@Œôg~ÿe—<>Ÿ÷§WÅ·ØÐ !ö•‘Mˆû6O#޾‚i(¶°벿–ý“P‰°RÕú ,ѹùñ°m;´´¶Fgúj¾S…‚ô·ŸsòÑ–‡wU€ñ¨ÔÉC îŒá*™Axê¾RaÂX0Tfã_­4{Þ–DÈ&ˆŽVk/)¾|dü«ûäÃ%%¦Ü*Ý)Ðéù;†Vùd‚eªiÝøƒòáóÀ¸ûÞÀ3<Àf•!Ëa?²<@«¦KÓ“ÇaÃáXB¼ŒËȇ7VJ»¸¨}OÝõ•Õ]ð­ÏãÁç`È?:–ê«Vò‡·¡·ºøV™ôd|þš²2­èû&Ýxxw^d?Ôèö^8ÝØE@£h=·¦¥Hå°óxÀ?úö "õ×Sù+&Ý%pè~ð*l—‡ò¦*ûn´pºA¸>¹Î™êH>qvž¾òüWú½ë–&.¶ö¼Ö¿JÞØá3‘ãüy â:³_!wB0<0¼øƒÇ÷^~·‰| P‡É$Gn"¡T"!Õâ¯bì)!×ß-‰Ï3ò!Õ!õTno– 4[‘XäÕ?öœ'­üÝx”Z °qò‰¬üÇúªH>Œ=ŸLÄNÔU&ºÁH¶üñH(1kÏ‹bHÆ0òæ¯jó%}Ewy•ª{6퉞 _8sïHÞ0ìÇ*} -kPÿ¨Ï'fxD·wjÞUb±‚GµOÄ:î(¿p_|~Á£±¿‹ †¤ ßt͆n–QV5á=Ïß-ÒœVú 9ÌM‘ïf«Èb9ù«ÿÊ#È'ºó}ŠâAr„‘QV``ó%Cñ¸¯>x›¾âñ95•§S_õãÑ©Ï/é)¼ünKûáÛsj’ƒžI·Ü¤?rUö<ã_ÕØóžZæëç—¸õs[HÇŽŽK2ƒóJ_Ìã›Ý#[ö¸ IìzÖ£‚|{õü«|¾ýªOíüD×2“ƲsfÁ%Èžù»<ùhŸsy$æ'–ª, !ÉWAêxå¯Zòhœ¿º ûýÙ|ꌊ˜[ÕÏÓžÄcû1R÷Q{}Æšg Ïòâž|„ù«ê)±ÕÀx¾è–z^„pJF“ž<ž©Ÿ_uNf~û·Ltu’fßÄÃó¯JâóFö|ˆù¢#Ù>úêòù¨ _«^\zòõÕ <`ŠŸCÒ3|f¾ÏÕX½”í¡YixuåÔ÷=å£U}i?ìó8„ç9N0 Ï8öü–ù%„> >¯fc¼{¥'@_U×™òA{~0ˆ¹Ãyéð¤&é+Ç(þn¾ŠÔÒ Eõ«€ l’^®á8Λ×6>žO±IòÌiÔåÙøœ9³ ?·Kf蚇½*:ÝVATï‡Ù”Ìü]nAš^¯ žÇù­ï#ùUÌ£÷x¾¥;_4µþòqÇÓ]fG~ÄrUÎû‚Ù!àêˆzW+eÉ}{ decoded image). /// It might throw an IOException. /// @param level The image level of the resulting image in the internal image buffer. void Reconstruct(int level = 0) THROW_; ////////////////////////////////////////////////////////////////////// /// Get image data in interleaved format: (ordering of RGB data is BGR[A]) /// Upsampling, YUV to RGB transform and interleaving are done here to reduce the number /// of passes over the data. /// The absolute value of pitch is the number of bytes of an image row of the given image buffer. /// If pitch is negative, then the image buffer must point to the last row of a bottom-up image (first byte on last row). /// if pitch is positive, then the image buffer must point to the first row of a top-down image (first byte). /// The sequence of output channels in the output image buffer does not need to be the same as provided by PGF. In case of different sequences you have to /// provide a channelMap of size of expected channels (depending on image mode). For example, PGF provides a channel sequence BGR in RGB color mode. /// If your provided image buffer expects a channel sequence ARGB, then the channelMap looks like { 3, 2, 1, 0 }. /// It might throw an IOException. /// @param pitch The number of bytes of a row of the image buffer. /// @param buff An image buffer. /// @param bpp The number of bits per pixel used in image buffer. /// @param channelMap A integer array containing the mapping of PGF channel ordering to expected channel ordering. /// @param cb A pointer to a callback procedure. The procedure is called after each copied buffer row. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void GetBitmap(int pitch, UINT8* buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) const THROW_; // throws IOException ////////////////////////////////////////////////////////////////////// /// Get YUV image data in interleaved format: (ordering is YUV[A]) /// The absolute value of pitch is the number of bytes of an image row of the given image buffer. /// If pitch is negative, then the image buffer must point to the last row of a bottom-up image (first byte on last row). /// if pitch is positive, then the image buffer must point to the first row of a top-down image (first byte). /// The sequence of output channels in the output image buffer does not need to be the same as provided by PGF. In case of different sequences you have to /// provide a channelMap of size of expected channels (depending on image mode). For example, PGF provides a channel sequence BGR in RGB color mode. /// If your provided image buffer expects a channel sequence VUY, then the channelMap looks like { 2, 1, 0 }. /// It might throw an IOException. /// @param pitch The number of bytes of a row of the image buffer. /// @param buff An image buffer. /// @param bpp The number of bits per pixel used in image buffer. /// @param channelMap A integer array containing the mapping of PGF channel ordering to expected channel ordering. /// @param cb A pointer to a callback procedure. The procedure is called after each copied buffer row. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void GetYUV(int pitch, DataT* buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) const THROW_; // throws IOException ////////////////////////////////////////////////////////////////////// /// Import an image from a specified image buffer. /// This method is usually called before Write(...) and after SetHeader(...). /// The absolute value of pitch is the number of bytes of an image row. /// If pitch is negative, then buff points to the last row of a bottom-up image (first byte on last row). /// If pitch is positive, then buff points to the first row of a top-down image (first byte). /// The sequence of input channels in the input image buffer does not need to be the same as expected from PGF. In case of different sequences you have to /// provide a channelMap of size of expected channels (depending on image mode). For example, PGF expects in RGB color mode a channel sequence BGR. /// If your provided image buffer contains a channel sequence ARGB, then the channelMap looks like { 3, 2, 1, 0 }. /// It might throw an IOException. /// @param pitch The number of bytes of a row of the image buffer. /// @param buff An image buffer. /// @param bpp The number of bits per pixel used in image buffer. /// @param channelMap A integer array containing the mapping of input channel ordering to expected channel ordering. /// @param cb A pointer to a callback procedure. The procedure is called after each imported buffer row. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_; ////////////////////////////////////////////////////////////////////// /// Import a YUV image from a specified image buffer. /// The absolute value of pitch is the number of bytes of an image row. /// If pitch is negative, then buff points to the last row of a bottom-up image (first byte on last row). /// If pitch is positive, then buff points to the first row of a top-down image (first byte). /// The sequence of input channels in the input image buffer does not need to be the same as expected from PGF. In case of different sequences you have to /// provide a channelMap of size of expected channels (depending on image mode). For example, PGF expects in RGB color mode a channel sequence BGR. /// If your provided image buffer contains a channel sequence VUY, then the channelMap looks like { 2, 1, 0 }. /// It might throw an IOException. /// @param pitch The number of bytes of a row of the image buffer. /// @param buff An image buffer. /// @param bpp The number of bits per pixel used in image buffer. /// @param channelMap A integer array containing the mapping of input channel ordering to expected channel ordering. /// @param cb A pointer to a callback procedure. The procedure is called after each imported buffer row. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_; ////////////////////////////////////////////////////////////////////// /// Encode and write a entire PGF image (header and image) at current stream position. /// A PGF image is structered in levels, numbered between 0 and Levels() - 1. /// Each level can be seen as a single image, containing the same content /// as all other levels, but in a different size (width, height). /// The image size at level i is double the size (width, height) of the image at level i+1. /// The image at level 0 contains the original size. /// Precondition: the PGF image contains a valid header (see also SetHeader(...)). /// It might throw an IOException. /// @param stream A PGF stream /// @param nWrittenBytes [in-out] The number of bytes written into stream are added to the input value. /// @param cb A pointer to a callback procedure. The procedure is called after writing a single level. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void Write(CPGFStream* stream, UINT32* nWrittenBytes = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_; ////////////////////////////////////////////////////////////////// /// Create wavelet transform channels and encoder. Write header at current stream position. /// Call this method before your first call of Write(int level) or WriteImage(), but after SetHeader(). /// This method is called inside of Write(stream, ...). /// It might throw an IOException. /// @param stream A PGF stream /// @return The number of bytes written into stream. UINT32 WriteHeader(CPGFStream* stream) THROW_; ////////////////////////////////////////////////////////////////////// /// Encode and write the one and only image at current stream position. /// Call this method after WriteHeader(). In case you want to write uncached metadata, /// then do that after WriteHeader() and before WriteImage(). /// This method is called inside of Write(stream, ...). /// It might throw an IOException. /// @param stream A PGF stream /// @param cb A pointer to a callback procedure. The procedure is called after writing a single level. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. /// @return The number of bytes written into stream. UINT32 WriteImage(CPGFStream* stream, CallbackPtr cb = NULL, void *data = NULL) THROW_; #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////// /// Encode and write down to given level at current stream position. /// A PGF image is structered in levels, numbered between 0 and Levels() - 1. /// Each level can be seen as a single image, containing the same content /// as all other levels, but in a different size (width, height). /// The image size at level i is double the size (width, height) of the image at level i+1. /// The image at level 0 contains the original size. /// Preconditions: the PGF image contains a valid header (see also SetHeader(...)) and /// WriteHeader() has been called before. Levels() > 0. /// The ROI encoding scheme must be used (see also SetHeader(...)). /// It might throw an IOException. /// @param level [0, nLevels) The image level of the resulting image in the internal image buffer. /// @param cb A pointer to a callback procedure. The procedure is called after writing a single level. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. /// @return The number of bytes written into stream. UINT32 Write(int level, CallbackPtr cb = NULL, void *data = NULL) THROW_; #endif ///////////////////////////////////////////////////////////////////// /// Configures the encoder. /// @param useOMP Use parallel threading with Open MP during encoding. Default value: true. Influences the encoding only if the codec has been compiled with OpenMP support. /// @param favorSpeedOverSize Favors encoding speed over compression ratio. Default value: false void ConfigureEncoder(bool useOMP = true, bool favorSpeedOverSize = false) { m_useOMPinEncoder = useOMP; m_favorSpeedOverSize = favorSpeedOverSize; } ///////////////////////////////////////////////////////////////////// /// Configures the decoder. /// @param useOMP Use parallel threading with Open MP during decoding. Default value: true. Influences the decoding only if the codec has been compiled with OpenMP support. /// @param skipUserData The file might contain user data (metadata). User data ist usually read during Open and stored in memory. Set this flag to false when storing in memory is not needed. void ConfigureDecoder(bool useOMP = true, bool skipUserData = false) { m_useOMPinDecoder = useOMP; m_skipUserData = skipUserData; } //////////////////////////////////////////////////////////////////// /// Reset stream position to start of PGF pre-header void ResetStreamPos() THROW_; ////////////////////////////////////////////////////////////////////// /// Set internal PGF image buffer channel. /// @param channel A YUV data channel /// @param c A channel index void SetChannel(DataT* channel, int c = 0) { ASSERT(c >= 0 && c < MaxChannels); m_channel[c] = channel; } ////////////////////////////////////////////////////////////////////// /// Set PGF header and user data. /// Precondition: The PGF image has been closed with Close(...) or never opened with Open(...). /// It might throw an IOException. /// @param header A valid and already filled in PGF header structure /// @param flags A combination of additional version flags. In case you use level-wise encoding then set flag = PGFROI. /// @param userData A user-defined memory block containing any kind of cached metadata. /// @param userDataLength The size of user-defined memory block in bytes void SetHeader(const PGFHeader& header, BYTE flags = 0, UINT8* userData = 0, UINT32 userDataLength = 0) THROW_; // throws IOException ////////////////////////////////////////////////////////////////////// /// Set maximum intensity value for image modes with more than eight bits per channel. /// Call this method after SetHeader, but before ImportBitmap. /// @param maxValue The maximum intensity value. void SetMaxValue(UINT32 maxValue); ////////////////////////////////////////////////////////////////////// /// Set progress mode used in Read and Write. /// Default mode is PM_Relative. /// This method must be called before Open() or SetHeader(). /// PM_Relative: 100% = level difference between current level and target level of Read/Write /// PM_Absolute: 100% = number of levels void SetProgressMode(ProgressMode pm) { m_progressMode = pm; } ////////////////////////////////////////////////////////////////////// /// Set refresh callback procedure and its parameter. /// The refresh callback is called during Read(...) after each level read. /// @param callback A refresh callback procedure /// @param arg A parameter of the refresh callback procedure void SetRefreshCallback(RefreshCB callback, void* arg) { m_cb = callback; m_cbArg = arg; } ////////////////////////////////////////////////////////////////////// /// Sets the red, green, blue (RGB) color values for a range of entries in the palette (clut). /// It might throw an IOException. /// @param iFirstColor The color table index of the first entry to set. /// @param nColors The number of color table entries to set. /// @param prgbColors A pointer to the array of RGBQUAD structures to set the color table entries. void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD* prgbColors) THROW_; ////////////////////////////////////////////////////////////////////// /// Return an internal YUV image channel. /// @param c A channel index /// @return An internal YUV image channel DataT* GetChannel(int c = 0) { ASSERT(c >= 0 && c < MaxChannels); return m_channel[c]; } ////////////////////////////////////////////////////////////////////// /// Retrieves red, green, blue (RGB) color values from a range of entries in the palette of the DIB section. /// It might throw an IOException. /// @param iFirstColor The color table index of the first entry to retrieve. /// @param nColors The number of color table entries to retrieve. /// @param prgbColors A pointer to the array of RGBQUAD structures to retrieve the color table entries. void GetColorTable(UINT32 iFirstColor, UINT32 nColors, RGBQUAD* prgbColors) const THROW_; ////////////////////////////////////////////////////////////////////// // Returns address of internal color table /// @return Address of color table const RGBQUAD* GetColorTable() const { return m_postHeader.clut; } ////////////////////////////////////////////////////////////////////// /// Return the PGF header structure. /// @return A PGF header structure const PGFHeader* GetHeader() const { return &m_header; } ////////////////////////////////////////////////////////////////////// /// Get maximum intensity value for image modes with more than eight bits per channel. /// Don't call this method before the PGF header has been read. /// @return The maximum intensity value. UINT32 GetMaxValue() const { return (1 << m_header.usedBitsPerChannel) - 1; } ////////////////////////////////////////////////////////////////////// /// Return the stream position of the user data or 0. /// Precondition: The PGF image has been opened with a call of Open(...). UINT64 GetUserDataPos() const { return m_userDataPos; } ////////////////////////////////////////////////////////////////////// /// Return user data and size of user data. /// Precondition: The PGF image has been opened with a call of Open(...). /// @param size [out] Size of user data in bytes. /// @return A pointer to user data or NULL if there is no user data. const UINT8* GetUserData(UINT32& size) const; ////////////////////////////////////////////////////////////////////// /// Return the length of all encoded headers in bytes. /// Precondition: The PGF image has been opened with a call of Open(...). /// @return The length of all encoded headers in bytes UINT32 GetEncodedHeaderLength() const; ////////////////////////////////////////////////////////////////////// /// Return the length of an encoded PGF level in bytes. /// Precondition: The PGF image has been opened with a call of Open(...). /// @param level The image level /// @return The length of a PGF level in bytes UINT32 GetEncodedLevelLength(int level) const { ASSERT(level >= 0 && level < m_header.nLevels); return m_levelLength[m_header.nLevels - level - 1]; } ////////////////////////////////////////////////////////////////////// /// Reads the encoded PGF headers and copies it to a target buffer. /// Precondition: The PGF image has been opened with a call of Open(...). /// It might throw an IOException. /// @param target The target buffer /// @param targetLen The length of the target buffer in bytes /// @return The number of bytes copied to the target buffer UINT32 ReadEncodedHeader(UINT8* target, UINT32 targetLen) const THROW_; ////////////////////////////////////////////////////////////////////// /// Reads the data of an encoded PGF level and copies it to a target buffer /// without decoding. /// Precondition: The PGF image has been opened with a call of Open(...). /// It might throw an IOException. /// @param level The image level /// @param target The target buffer /// @param targetLen The length of the target buffer in bytes /// @return The number of bytes copied to the target buffer UINT32 ReadEncodedData(int level, UINT8* target, UINT32 targetLen) const THROW_; ////////////////////////////////////////////////////////////////////// /// Return current image width of given channel in pixels. /// The returned width depends on the levels read so far and on ROI. /// @param c A channel index /// @return Channel width in pixels UINT32 ChannelWidth(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_width[c]; } ////////////////////////////////////////////////////////////////////// /// Return current image height of given channel in pixels. /// The returned height depends on the levels read so far and on ROI. /// @param c A channel index /// @return Channel height in pixels UINT32 ChannelHeight(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_height[c]; } ////////////////////////////////////////////////////////////////////// /// Return bits per channel of the image's encoder. /// @return Bits per channel BYTE ChannelDepth() const { return CurrentChannelDepth(m_preHeader.version); } ////////////////////////////////////////////////////////////////////// /// Return image width of channel 0 at given level in pixels. /// The returned width is independent of any Read-operations and ROI. /// @param level A level /// @return Image level width in pixels UINT32 Width(int level = 0) const { ASSERT(level >= 0); return LevelWidth(m_header.width, level); } ////////////////////////////////////////////////////////////////////// /// Return image height of channel 0 at given level in pixels. /// The returned height is independent of any Read-operations and ROI. /// @param level A level /// @return Image level height in pixels UINT32 Height(int level = 0) const { ASSERT(level >= 0); return LevelHeight(m_header.height, level); } ////////////////////////////////////////////////////////////////////// /// Return current image level. /// Since Read(...) can be used to read each image level separately, it is /// helpful to know the current level. The current level immediately after Open(...) is Levels(). /// @return Current image level BYTE Level() const { return (BYTE)m_currentLevel; } ////////////////////////////////////////////////////////////////////// /// Return the number of image levels. /// @return Number of image levels BYTE Levels() const { return m_header.nLevels; } ////////////////////////////////////////////////////////////////////// /// Return the PGF quality. The quality is inbetween 0 and MaxQuality. /// PGF quality 0 means lossless quality. /// @return PGF quality BYTE Quality() const { return m_header.quality; } ////////////////////////////////////////////////////////////////////// /// Return the number of image channels. /// An image of type RGB contains 3 image channels (B, G, R). /// @return Number of image channels BYTE Channels() const { return m_header.channels; } ////////////////////////////////////////////////////////////////////// /// Return the image mode. /// An image mode is a predefined constant value (see also PGFtypes.h) compatible with Adobe Photoshop. /// It represents an image type and format. /// @return Image mode BYTE Mode() const { return m_header.mode; } ////////////////////////////////////////////////////////////////////// /// Return the number of bits per pixel. /// Valid values can be 1, 8, 12, 16, 24, 32, 48, 64. /// @return Number of bits per pixel. BYTE BPP() const { return m_header.bpp; } ////////////////////////////////////////////////////////////////////// /// Return true if the pgf image supports Region Of Interest (ROI). /// @return true if the pgf image supports ROI. bool ROIisSupported() const { return (m_preHeader.version & PGFROI) == PGFROI; } ////////////////////////////////////////////////////////////////////// /// Returns number of used bits per input/output image channel. /// Precondition: header must be initialized. /// @return number of used bits per input/output image channel. BYTE UsedBitsPerChannel() const; ////////////////////////////////////////////////////////////////////// /// Returns images' PGF version /// @return PGF codec version of the image BYTE Version() const { return CurrentVersion(m_preHeader.version); } //class methods ////////////////////////////////////////////////////////////////////// /// Check for valid import image mode. /// @param mode Image mode /// @return True if an image of given mode can be imported with ImportBitmap(...) static bool ImportIsSupported(BYTE mode); ////////////////////////////////////////////////////////////////////// /// Compute and return image width at given level. /// @param width Original image width (at level 0) /// @param level An image level /// @return Image level width in pixels static UINT32 LevelWidth(UINT32 width, int level) { ASSERT(level >= 0); UINT32 w = (width >> level); return ((w << level) == width) ? w : w + 1; } ////////////////////////////////////////////////////////////////////// /// Compute and return image height at given level. /// @param height Original image height (at level 0) /// @param level An image level /// @return Image level height in pixels static UINT32 LevelHeight(UINT32 height, int level) { ASSERT(level >= 0); UINT32 h = (height >> level); return ((h << level) == height) ? h : h + 1; } ////////////////////////////////////////////////////////////////////// /// Compute and return codec version. /// @return current PGF codec version static BYTE CurrentVersion(BYTE version = PGFVersion); ////////////////////////////////////////////////////////////////////// /// Compute and return codec version. /// @return current PGF codec version static BYTE CurrentChannelDepth(BYTE version = PGFVersion) { return (version & PGF32) ? 32 : 16; } protected: CWaveletTransform* m_wtChannel[MaxChannels]; ///< wavelet transformed color channels DataT* m_channel[MaxChannels]; ///< untransformed channels in YUV format CDecoder* m_decoder; ///< PGF decoder CEncoder* m_encoder; ///< PGF encoder UINT32* m_levelLength; ///< length of each level in bytes; first level starts immediately after this array UINT32 m_width[MaxChannels]; ///< width of each channel at current level UINT32 m_height[MaxChannels]; ///< height of each channel at current level PGFPreHeader m_preHeader; ///< PGF pre-header PGFHeader m_header; ///< PGF file header PGFPostHeader m_postHeader; ///< PGF post-header UINT64 m_userDataPos; ///< stream position of user data int m_currentLevel; ///< transform level of current image BYTE m_quant; ///< quantization parameter bool m_downsample; ///< chrominance channels are downsampled bool m_favorSpeedOverSize; ///< favor encoding speed over compression ratio bool m_useOMPinEncoder; ///< use Open MP in encoder bool m_useOMPinDecoder; ///< use Open MP in decoder bool m_skipUserData; ///< skip user data (metadata) during open #ifdef __PGFROISUPPORT__ bool m_streamReinitialized; ///< stream has been reinitialized PGFRect m_roi; ///< region of interest #endif private: RefreshCB m_cb; ///< pointer to refresh callback procedure void *m_cbArg; ///< refresh callback argument double m_percent; ///< progress [0..1] ProgressMode m_progressMode; ///< progress mode used in Read and Write; PM_Relative is default mode void ComputeLevels(); void CompleteHeader(); void RgbToYuv(int pitch, UINT8* rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data) THROW_; void Downsample(int nChannel); UINT32 UpdatePostHeaderSize() THROW_; void WriteLevel() THROW_; #ifdef __PGFROISUPPORT__ void SetROI(PGFRect rect); #endif UINT8 Clamp4(DataT v) const { if (v & 0xFFFFFFF0) return (v < 0) ? (UINT8)0: (UINT8)15; else return (UINT8)v; } UINT16 Clamp6(DataT v) const { if (v & 0xFFFFFFC0) return (v < 0) ? (UINT16)0: (UINT16)63; else return (UINT16)v; } UINT8 Clamp8(DataT v) const { // needs only one test in the normal case if (v & 0xFFFFFF00) return (v < 0) ? (UINT8)0 : (UINT8)255; else return (UINT8)v; } UINT16 Clamp16(DataT v) const { if (v & 0xFFFF0000) return (v < 0) ? (UINT16)0: (UINT16)65535; else return (UINT16)v; } UINT32 Clamp31(DataT v) const { return (v < 0) ? 0 : (UINT32)v; } }; #endif //PGF_PGFIMAGE_H libpgf/include/PGFplatform.h100777 0 0 52066 12313025745 11450 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2007-06-12 19:27:47 +0200 (Di, 12 Jun 2007) $ * $Revision: 307 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file PGFplatform.h /// @brief PGF platform specific definitions /// @author C. Stamm #ifndef PGF_PGFPLATFORM_H #define PGF_PGFPLATFORM_H #include #include #include //------------------------------------------------------------------------------- // Endianess detection taken from lcms2 header. // This list can be endless, so only some checks are performed over here. //------------------------------------------------------------------------------- #if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(WORDS_BIGENDIAN) #define PGF_USE_BIG_ENDIAN 1 #endif #if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(__sparc) || defined(__sparc__) #define PGF_USE_BIG_ENDIAN 1 #endif #if defined(__ppc__) || defined(__s390__) || defined(__s390x__) #define PGF_USE_BIG_ENDIAN 1 #endif #ifdef TARGET_CPU_PPC #define PGF_USE_BIG_ENDIAN 1 #endif //------------------------------------------------------------------------------- // ROI support //------------------------------------------------------------------------------- #ifndef NPGFROI #define __PGFROISUPPORT__ // without ROI support the program code gets simpler and smaller #endif //------------------------------------------------------------------------------- // 32 bit per channel support //------------------------------------------------------------------------------- #ifndef NPGF32 #define __PGF32SUPPORT__ // without 32 bit the memory consumption during encoding and decoding is much lesser #endif //------------------------------------------------------------------------------- // 32 Bit platform constants //------------------------------------------------------------------------------- #define WordWidth 32 ///< WordBytes*8 #define WordWidthLog 5 ///< ld of WordWidth #define WordMask 0xFFFFFFE0 ///< least WordWidthLog bits are zero #define WordBytes 4 ///< sizeof(UINT32) #define WordBytesMask 0xFFFFFFFC ///< least WordBytesLog bits are zero #define WordBytesLog 2 ///< ld of WordBytes //------------------------------------------------------------------------------- // Alignment macros (used in PGF based libraries) //------------------------------------------------------------------------------- #define DWWIDTHBITS(bits) (((bits) + WordWidth - 1) & WordMask) ///< aligns scanline width in bits to DWORD value #define DWWIDTH(bytes) (((bytes) + WordBytes - 1) & WordBytesMask) ///< aligns scanline width in bytes to DWORD value #define DWWIDTHREST(bytes) ((WordBytes - (bytes)%WordBytes)%WordBytes) ///< DWWIDTH(bytes) - bytes //------------------------------------------------------------------------------- // Min-Max macros //------------------------------------------------------------------------------- #ifndef __min #define __min(x, y) ((x) <= (y) ? (x) : (y)) #define __max(x, y) ((x) >= (y) ? (x) : (y)) #endif // __min //------------------------------------------------------------------------------- // Defines -- Adobe image modes. //------------------------------------------------------------------------------- #define ImageModeBitmap 0 #define ImageModeGrayScale 1 #define ImageModeIndexedColor 2 #define ImageModeRGBColor 3 #define ImageModeCMYKColor 4 #define ImageModeHSLColor 5 #define ImageModeHSBColor 6 #define ImageModeMultichannel 7 #define ImageModeDuotone 8 #define ImageModeLabColor 9 #define ImageModeGray16 10 // 565 #define ImageModeRGB48 11 #define ImageModeLab48 12 #define ImageModeCMYK64 13 #define ImageModeDeepMultichannel 14 #define ImageModeDuotone16 15 // pgf extension #define ImageModeRGBA 17 #define ImageModeGray32 18 // MSB is 0 (can be interpreted as signed 15.16 fixed point format) #define ImageModeRGB12 19 #define ImageModeRGB16 20 #define ImageModeUnknown 255 //------------------------------------------------------------------------------- // WINDOWS //------------------------------------------------------------------------------- #if defined(WIN32) || defined(WINCE) || defined(WIN64) #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers //------------------------------------------------------------------------------- // MFC //------------------------------------------------------------------------------- #ifdef _MFC_VER #include // MFC core and standard components #include // MFC extensions #include // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT #include #else #include #include #endif // _MFC_VER //------------------------------------------------------------------------------- #define DllExport __declspec( dllexport ) //------------------------------------------------------------------------------- // unsigned number type definitions //------------------------------------------------------------------------------- typedef unsigned char UINT8; typedef unsigned char BYTE; typedef unsigned short UINT16; typedef unsigned short WORD; typedef unsigned int UINT32; typedef unsigned long DWORD; typedef unsigned long ULONG; typedef unsigned __int64 UINT64; typedef unsigned __int64 ULONGLONG; //------------------------------------------------------------------------------- // signed number type definitions //------------------------------------------------------------------------------- typedef signed char INT8; typedef signed short INT16; typedef signed int INT32; typedef signed int BOOL; typedef signed long LONG; typedef signed __int64 INT64; typedef signed __int64 LONGLONG; //------------------------------------------------------------------------------- // other types //------------------------------------------------------------------------------- typedef int OSError; typedef bool (__cdecl *CallbackPtr)(double percent, bool escapeAllowed, void *data); //------------------------------------------------------------------------------- // struct type definitions //------------------------------------------------------------------------------- //------------------------------------------------------------------------------- // DEBUG macros //------------------------------------------------------------------------------- #ifndef ASSERT #ifdef _DEBUG #define ASSERT(x) assert(x) #else #if defined(__GNUC__) #define ASSERT(ignore)((void) 0) #elif _MSC_VER >= 1300 #define ASSERT __noop #else #define ASSERT ((void)0) #endif #endif //_DEBUG #endif //ASSERT //------------------------------------------------------------------------------- // Exception handling macros //------------------------------------------------------------------------------- #ifdef NEXCEPTIONS extern OSError _PGF_Error_; extern OSError GetLastPGFError(); #define ReturnWithError(err) { _PGF_Error_ = err; return; } #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; } #else #define ReturnWithError(err) throw IOException(err) #define ReturnWithError2(err, ret) throw IOException(err) #endif //NEXCEPTIONS #if _MSC_VER >= 1300 //#define THROW_ throw(...) #pragma warning( disable : 4290 ) #define THROW_ throw(IOException) #else #define THROW_ #endif //------------------------------------------------------------------------------- // constants //------------------------------------------------------------------------------- #define FSFromStart FILE_BEGIN // 0 #define FSFromCurrent FILE_CURRENT // 1 #define FSFromEnd FILE_END // 2 #define INVALID_SET_FILE_POINTER ((DWORD)-1) //------------------------------------------------------------------------------- // IO Error constants //------------------------------------------------------------------------------- #define NoError ERROR_SUCCESS ///< no error #define AppError 0x20000000 ///< all application error messages must be larger than this value #define InsufficientMemory 0x20000001 ///< memory allocation wasn't successfull #define InvalidStreamPos 0x20000002 ///< invalid memory stream position #define EscapePressed 0x20000003 ///< user break by ESC #define WrongVersion 0x20000004 ///< wrong pgf version #define FormatCannotRead 0x20000005 ///< wrong data file format #define ImageTooSmall 0x20000006 ///< image is too small #define ZlibError 0x20000007 ///< error in zlib functions #define ColorTableError 0x20000008 ///< errors related to color table size #define PNGError 0x20000009 ///< errors in png functions #define MissingData 0x2000000A ///< expected data cannot be read //------------------------------------------------------------------------------- // methods //------------------------------------------------------------------------------- inline OSError FileRead(HANDLE hFile, int *count, void *buffPtr) { if (ReadFile(hFile, buffPtr, *count, (ULONG *)count, NULL)) { return NoError; } else { return GetLastError(); } } inline OSError FileWrite(HANDLE hFile, int *count, void *buffPtr) { if (WriteFile(hFile, buffPtr, *count, (ULONG *)count, NULL)) { return NoError; } else { return GetLastError(); } } inline OSError GetFPos(HANDLE hFile, UINT64 *pos) { #ifdef WINCE LARGE_INTEGER li; li.QuadPart = 0; li.LowPart = SetFilePointer (hFile, li.LowPart, &li.HighPart, FILE_CURRENT); if (li.LowPart == INVALID_SET_FILE_POINTER) { OSError err = GetLastError(); if (err != NoError) { return err; } } *pos = li.QuadPart; return NoError; #else LARGE_INTEGER li; li.QuadPart = 0; if (SetFilePointerEx(hFile, li, (PLARGE_INTEGER)pos, FILE_CURRENT)) { return NoError; } else { return GetLastError(); } #endif } inline OSError SetFPos(HANDLE hFile, int posMode, INT64 posOff) { #ifdef WINCE LARGE_INTEGER li; li.QuadPart = posOff; if (SetFilePointer (hFile, li.LowPart, &li.HighPart, posMode) == INVALID_SET_FILE_POINTER) { OSError err = GetLastError(); if (err != NoError) { return err; } } return NoError; #else LARGE_INTEGER li; li.QuadPart = posOff; if (SetFilePointerEx(hFile, li, NULL, posMode)) { return NoError; } else { return GetLastError(); } #endif } #endif //WIN32 //------------------------------------------------------------------------------- // Apple OSX //------------------------------------------------------------------------------- #ifdef __APPLE__ #define __POSIX__ #endif // __APPLE__ //------------------------------------------------------------------------------- // LINUX //------------------------------------------------------------------------------- #if defined(__linux__) || defined(__GLIBC__) #define __POSIX__ #endif // __linux__ or __GLIBC__ //------------------------------------------------------------------------------- // SOLARIS //------------------------------------------------------------------------------- #ifdef __sun #define __POSIX__ #endif // __sun //------------------------------------------------------------------------------- // *BSD //------------------------------------------------------------------------------- #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) #ifndef __POSIX__ #define __POSIX__ #endif #ifndef off64_t #define off64_t off_t #endif #ifndef lseek64 #define lseek64 lseek #endif #endif // __NetBSD__ or __OpenBSD__ or __FreeBSD__ //------------------------------------------------------------------------------- // POSIX *NIXes //------------------------------------------------------------------------------- #ifdef __POSIX__ #include #include #include // for int64_t and uint64_t #include // memcpy() //------------------------------------------------------------------------------- // unsigned number type definitions //------------------------------------------------------------------------------- typedef unsigned char UINT8; typedef unsigned char BYTE; typedef unsigned short UINT16; typedef unsigned short WORD; typedef unsigned int UINT32; typedef unsigned int DWORD; typedef unsigned long ULONG; typedef unsigned long long __Uint64; typedef __Uint64 UINT64; typedef __Uint64 ULONGLONG; //------------------------------------------------------------------------------- // signed number type definitions //------------------------------------------------------------------------------- typedef signed char INT8; typedef signed short INT16; typedef signed int INT32; typedef signed int BOOL; typedef signed long LONG; typedef int64_t INT64; typedef int64_t LONGLONG; //------------------------------------------------------------------------------- // other types //------------------------------------------------------------------------------- typedef int OSError; typedef int HANDLE; typedef unsigned long ULONG_PTR; typedef void* PVOID; typedef char* LPTSTR; typedef bool (*CallbackPtr)(double percent, bool escapeAllowed, void *data); //------------------------------------------------------------------------------- // struct type definitions //------------------------------------------------------------------------------- typedef struct tagRGBTRIPLE { BYTE rgbtBlue; BYTE rgbtGreen; BYTE rgbtRed; } RGBTRIPLE; typedef struct tagRGBQUAD { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD; typedef union _LARGE_INTEGER { struct { DWORD LowPart; LONG HighPart; } u; LONGLONG QuadPart; } LARGE_INTEGER, *PLARGE_INTEGER; #endif // __POSIX__ #if defined(__POSIX__) || defined(WINCE) // CMYK macros #define GetKValue(cmyk) ((BYTE)(cmyk)) #define GetYValue(cmyk) ((BYTE)((cmyk)>> 8)) #define GetMValue(cmyk) ((BYTE)((cmyk)>>16)) #define GetCValue(cmyk) ((BYTE)((cmyk)>>24)) #define CMYK(c,m,y,k) ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24))) //------------------------------------------------------------------------------- // methods //------------------------------------------------------------------------------- /* The MulDiv function multiplies two 32-bit values and then divides the 64-bit * result by a third 32-bit value. The return value is rounded up or down to * the nearest integer. * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/muldiv.asp * */ __inline int MulDiv(int nNumber, int nNumerator, int nDenominator) { INT64 multRes = nNumber*nNumerator; INT32 divRes = INT32(multRes/nDenominator); return divRes; } #endif // __POSIX__ or WINCE #ifdef __POSIX__ //------------------------------------------------------------------------------- // DEBUG macros //------------------------------------------------------------------------------- #ifndef ASSERT #ifdef _DEBUG #define ASSERT(x) assert(x) #else #define ASSERT(x) #endif //_DEBUG #endif //ASSERT //------------------------------------------------------------------------------- // Exception handling macros //------------------------------------------------------------------------------- #ifdef NEXCEPTIONS extern OSError _PGF_Error_; extern OSError GetLastPGFError(); #define ReturnWithError(err) { _PGF_Error_ = err; return; } #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; } #else #define ReturnWithError(err) throw IOException(err) #define ReturnWithError2(err, ret) throw IOException(err) #endif //NEXCEPTIONS #define THROW_ throw(IOException) #define CONST const //------------------------------------------------------------------------------- // constants //------------------------------------------------------------------------------- #define FSFromStart SEEK_SET #define FSFromCurrent SEEK_CUR #define FSFromEnd SEEK_END //------------------------------------------------------------------------------- // IO Error constants //------------------------------------------------------------------------------- #define NoError 0x0000 ///< no error #define AppError 0x2000 ///< all application error messages must be larger than this value #define InsufficientMemory 0x2001 ///< memory allocation wasn't successfull #define InvalidStreamPos 0x2002 ///< invalid memory stream position #define EscapePressed 0x2003 ///< user break by ESC #define WrongVersion 0x2004 ///< wrong pgf version #define FormatCannotRead 0x2005 ///< wrong data file format #define ImageTooSmall 0x2006 ///< image is too small #define ZlibError 0x2007 ///< error in zlib functions #define ColorTableError 0x2008 ///< errors related to color table size #define PNGError 0x2009 ///< errors in png functions #define MissingData 0x200A ///< expected data cannot be read //------------------------------------------------------------------------------- // methods //------------------------------------------------------------------------------- __inline OSError FileRead(HANDLE hFile, int *count, void *buffPtr) { *count = (int)read(hFile, buffPtr, *count); if (*count != -1) { return NoError; } else { return errno; } } __inline OSError FileWrite(HANDLE hFile, int *count, void *buffPtr) { *count = (int)write(hFile, buffPtr, (size_t)*count); if (*count != -1) { return NoError; } else { return errno; } } __inline OSError GetFPos(HANDLE hFile, UINT64 *pos) { #ifdef __APPLE__ off_t ret; if ((ret = lseek(hFile, 0, SEEK_CUR)) == -1) { return errno; } else { *pos = (UINT64)ret; return NoError; } #else off64_t ret; if ((ret = lseek64(hFile, 0, SEEK_CUR)) == -1) { return errno; } else { *pos = (UINT64)ret; return NoError; } #endif } __inline OSError SetFPos(HANDLE hFile, int posMode, INT64 posOff) { #ifdef __APPLE__ if ((lseek(hFile, (off_t)posOff, posMode)) == -1) { return errno; } else { return NoError; } #else if ((lseek64(hFile, (off64_t)posOff, posMode)) == -1) { return errno; } else { return NoError; } #endif } #endif /* __POSIX__ */ //------------------------------------------------------------------------------- //------------------------------------------------------------------------------- // Big Endian //------------------------------------------------------------------------------- #ifdef PGF_USE_BIG_ENDIAN #ifndef _lrotl #define _lrotl(x,n) (((x) << ((UINT32)(n))) | ((x) >> (32 - (UINT32)(n)))) #endif __inline UINT16 ByteSwap(UINT16 wX) { return ((wX & 0xFF00) >> 8) | ((wX & 0x00FF) << 8); } __inline UINT32 ByteSwap(UINT32 dwX) { #ifdef _X86_ _asm mov eax, dwX _asm bswap eax _asm mov dwX, eax return dwX; #else return _lrotl(((dwX & 0xFF00FF00) >> 8) | ((dwX & 0x00FF00FF) << 8), 16); #endif } #if defined(WIN32) || defined(WIN64) __inline UINT64 ByteSwap(UINT64 ui64) { return _byteswap_uint64(ui64); } #endif #define __VAL(x) ByteSwap(x) #else //PGF_USE_BIG_ENDIAN #define __VAL(x) (x) #endif //PGF_USE_BIG_ENDIAN // OpenMP rules (inspired from libraw project) // NOTE: Use LIBPGF_DISABLE_OPENMP to disable OpenMP support in whole libpgf #ifndef LIBPGF_DISABLE_OPENMP # if defined (_OPENMP) # if defined (WIN32) || defined(WIN64) # if defined (_MSC_VER) && (_MSC_VER >= 1500) // VS2008 SP1 and VS2010+ : OpenMP works OK # define LIBPGF_USE_OPENMP # elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910) // untested on 9.x and 10.x, Intel documentation claims OpenMP 2.5 support in 9.1 # define LIBPGF_USE_OPENMP # else # undef LIBPGF_USE_OPENMP # endif // Not Win32 # elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT) # undef LIBPGF_USE_OPENMP # else # define LIBPGF_USE_OPENMP # endif # endif // defined (_OPENMP) #endif // ifndef LIBPGF_DISABLE_OPENMP #ifdef LIBPGF_USE_OPENMP #include #endif #endif //PGF_PGFPLATFORM_H libpgf/include/PGFstream.h100777 0 0 17061 12232452335 11112 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2007-06-11 10:56:17 +0200 (Mo, 11 Jun 2007) $ * $Revision: 299 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file PGFstream.h /// @brief PGF stream class /// @author C. Stamm #ifndef PGF_STREAM_H #define PGF_STREAM_H #include "PGFtypes.h" #include ///////////////////////////////////////////////////////////////////// /// Abstract stream base class. /// @author C. Stamm /// @brief Abstract stream base class class CPGFStream { public: ////////////////////////////////////////////////////////////////////// /// Standard constructor. CPGFStream() {} ////////////////////////////////////////////////////////////////////// /// Standard destructor. virtual ~CPGFStream() {} ////////////////////////////////////////////////////////////////////// /// Write some bytes out of a buffer into this stream. /// @param count A pointer to a value containing the number of bytes should be written. After this call it contains the number of written bytes. /// @param buffer A memory buffer virtual void Write(int *count, void *buffer)=0; ////////////////////////////////////////////////////////////////////// /// Read some bytes from this stream and stores them into a buffer. /// @param count A pointer to a value containing the number of bytes should be read. After this call it contains the number of read bytes. /// @param buffer A memory buffer virtual void Read(int *count, void *buffer)=0; ////////////////////////////////////////////////////////////////////// /// Set stream position either absolute or relative. /// @param posMode A position mode (FSFromStart, FSFromCurrent, FSFromEnd) /// @param posOff A new stream position (absolute positioning) or a position offset (relative positioning) virtual void SetPos(short posMode, INT64 posOff)=0; ////////////////////////////////////////////////////////////////////// /// Get current stream position. /// @return Current stream position virtual UINT64 GetPos() const=0; ////////////////////////////////////////////////////////////////////// /// Check stream validity. /// @return True if stream and current position is valid virtual bool IsValid() const=0; }; ///////////////////////////////////////////////////////////////////// /// A PGF stream subclass for external storage files. /// @author C. Stamm /// @brief File stream class class CPGFFileStream : public CPGFStream { protected: HANDLE m_hFile; ///< file handle public: CPGFFileStream() : m_hFile(0) {} /// Constructor /// @param hFile File handle CPGFFileStream(HANDLE hFile) : m_hFile(hFile) {} /// @return File handle HANDLE GetHandle() { return m_hFile; } virtual ~CPGFFileStream() { m_hFile = 0; } virtual void Write(int *count, void *buffer) THROW_; // throws IOException virtual void Read(int *count, void *buffer) THROW_; // throws IOException virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException virtual UINT64 GetPos() const THROW_; // throws IOException virtual bool IsValid() const { return m_hFile != 0; } }; ///////////////////////////////////////////////////////////////////// /// A PGF stream subclass for internal memory. /// @author C. Stamm /// @brief Memory stream class class CPGFMemoryStream : public CPGFStream { protected: UINT8 *m_buffer, *m_pos;///< buffer start address and current buffer address UINT8 *m_eos; ///< end of stream (first address beyond written area) size_t m_size; ///< buffer size bool m_allocated; ///< indicates a new allocated buffer public: /// Constructor /// @param size Size of new allocated memory buffer CPGFMemoryStream(size_t size) THROW_; /// Constructor. Use already allocated memory of given size /// @param pBuffer Memory location /// @param size Memory size CPGFMemoryStream(UINT8 *pBuffer, size_t size) THROW_; /// Use already allocated memory of given size /// @param pBuffer Memory location /// @param size Memory size void Reinitialize(UINT8 *pBuffer, size_t size) THROW_; virtual ~CPGFMemoryStream() { m_pos = 0; if (m_allocated) { // the memory buffer has been allocated inside of CPMFmemoryStream constructor delete[] m_buffer; m_buffer = 0; } } virtual void Write(int *count, void *buffer) THROW_; // throws IOException virtual void Read(int *count, void *buffer); virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException virtual UINT64 GetPos() const { ASSERT(IsValid()); return m_pos - m_buffer; } virtual bool IsValid() const { return m_buffer != 0; } /// @return Memory size size_t GetSize() const { return m_size; } /// @return Memory buffer const UINT8* GetBuffer() const { return m_buffer; } /// @return Memory buffer UINT8* GetBuffer() { return m_buffer; } /// @return relative position of end of stream (= stream length) UINT64 GetEOS() const { ASSERT(IsValid()); return m_eos - m_buffer; } /// @param length Stream length (= relative position of end of stream) void SetEOS(UINT64 length) { ASSERT(IsValid()); m_eos = m_buffer + length; } }; ///////////////////////////////////////////////////////////////////// /// A PGF stream subclass for internal memory files. Usable only with MFC. /// @author C. Stamm /// @brief Cached memory file stream class #ifdef _MFC_VER class CPGFMemFileStream : public CPGFStream { protected: CMemFile *m_memFile; ///< MFC memory file public: CPGFMemFileStream(CMemFile *memFile) : m_memFile(memFile) {} virtual bool IsValid() const { return m_memFile != NULL; } virtual ~CPGFMemFileStream() {} virtual void Write(int *count, void *buffer) THROW_; // throws IOException virtual void Read(int *count, void *buffer) THROW_; // throws IOException virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException virtual UINT64 GetPos() const THROW_; // throws IOException }; #endif ///////////////////////////////////////////////////////////////////// /// A PGF stream subclass for IStream. Usable only with COM. /// @author C. Stamm /// @brief COM IStream class #if defined(WIN32) || defined(WINCE) class CPGFIStream : public CPGFStream { protected: IStream *m_stream; ///< COM+ IStream public: CPGFIStream(IStream *stream) : m_stream(stream) {} virtual bool IsValid() const { return m_stream != 0; } virtual ~CPGFIStream() {} virtual void Write(int *count, void *buffer) THROW_; // throws IOException virtual void Read(int *count, void *buffer) THROW_; // throws IOException virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException virtual UINT64 GetPos() const THROW_; // throws IOException IStream* GetIStream() const { return m_stream; } }; #endif #endif // PGF_STREAM_H libpgf/include/PGFtypes.h100777 0 0 23353 12313042301 10750 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2007-06-11 10:56:17 +0200 (Mo, 11 Jun 2007) $ * $Revision: 299 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file PGFtypes.h /// @brief PGF definitions /// @author C. Stamm #ifndef PGF_PGFTYPES_H #define PGF_PGFTYPES_H #include "PGFplatform.h" //------------------------------------------------------------------------------- // Constraints //------------------------------------------------------------------------------- // BufferSize <= UINT16_MAX //------------------------------------------------------------------------------- // Codec versions // // Version 2: modified data structure PGFHeader (backward compatibility assured) // Version 4: DataT: INT32 instead of INT16, allows 31 bit per pixel and channel (backward compatibility assured) // Version 5: ROI, new block-reordering scheme (backward compatibility assured) // Version 6: modified data structure PGFPreHeader: hSize (header size) is now a UINT32 instead of a UINT16 (backward compatibility assured) // //------------------------------------------------------------------------------- #define PGFCodecVersion "6.14.12" ///< Major number ///< Minor number: Year (2) Week (2) #define PGFCodecVersionID 0x061412 ///< Codec version ID to use for API check in client implementation //------------------------------------------------------------------------------- // Image constants //------------------------------------------------------------------------------- #define PGFMagic "PGF" ///< PGF identification #define MaxLevel 30 ///< maximum number of transform levels #define NSubbands 4 ///< number of subbands per level #define MaxChannels 8 ///< maximum number of (color) channels #define DownsampleThreshold 3 ///< if quality is larger than this threshold than downsampling is used #define ColorTableLen 256 ///< size of color lookup table (clut) // version flags #define Version2 2 ///< data structure PGFHeader of major version 2 #define PGF32 4 ///< 32 bit values are used -> allows at maximum 31 bits, otherwise 16 bit values are used -> allows at maximum 15 bits #define PGFROI 8 ///< supports Regions Of Interest #define Version5 16 ///< new coding scheme since major version 5 #define Version6 32 ///< new HeaderSize: 32 bits instead of 16 bits // version numbers #ifdef __PGF32SUPPORT__ #define PGFVersion (Version2 | PGF32 | Version5 | Version6) ///< current standard version #else #define PGFVersion (Version2 | Version5 | Version6) ///< current standard version #endif //------------------------------------------------------------------------------- // Coder constants //------------------------------------------------------------------------------- #define BufferSize 16384 ///< must be a multiple of WordWidth #define RLblockSizeLen 15 ///< block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize) #define LinBlockSize 8 ///< side length of a coefficient block in a HH or LL subband #define InterBlockSize 4 ///< side length of a coefficient block in a HL or LH subband #ifdef __PGF32SUPPORT__ #define MaxBitPlanes 31 ///< maximum number of bit planes of m_value: 32 minus sign bit #else #define MaxBitPlanes 15 ///< maximum number of bit planes of m_value: 16 minus sign bit #endif #define MaxBitPlanesLog 5 ///< number of bits to code the maximum number of bit planes (in 32 or 16 bit mode) #define MaxQuality MaxBitPlanes ///< maximum quality //------------------------------------------------------------------------------- // Types //------------------------------------------------------------------------------- enum Orientation { LL=0, HL=1, LH=2, HH=3 }; /// general PGF file structure /// PGFPreHeaderV6 PGFHeader PGFPostHeader LevelLengths Level_n-1 Level_n-2 ... Level_0 /// PGFPostHeader ::= [ColorTable] [UserData] /// LevelLengths ::= UINT32[nLevels] #pragma pack(1) ///////////////////////////////////////////////////////////////////// /// PGF magic and version (part of PGF pre-header) /// @author C. Stamm /// @brief PGF identification and version struct PGFMagicVersion { char magic[3]; ///< PGF identification = "PGF" UINT8 version; ///< PGF version // total: 4 Bytes }; ///////////////////////////////////////////////////////////////////// /// PGF pre-header defined header length and PGF identification and version /// @author C. Stamm /// @brief PGF pre-header struct PGFPreHeader : PGFMagicVersion { UINT32 hSize; ///< total size of PGFHeader, [ColorTable], and [UserData] in bytes // total: 8 Bytes }; ///////////////////////////////////////////////////////////////////// /// PGF header contains image information /// @author C. Stamm /// @brief PGF header struct PGFHeader { PGFHeader() : width(0), height(0), nLevels(0), quality(0), bpp(0), channels(0), mode(ImageModeUnknown), usedBitsPerChannel(0), reserved1(0), reserved2(0) {} UINT32 width; ///< image width in pixels UINT32 height; ///< image height in pixels UINT8 nLevels; ///< number of DWT levels UINT8 quality; ///< quantization parameter: 0=lossless, 4=standard, 6=poor quality UINT8 bpp; ///< bits per pixel UINT8 channels; ///< number of channels UINT8 mode; ///< image mode according to Adobe's image modes UINT8 usedBitsPerChannel; ///< number of used bits per channel in 16- and 32-bit per channel modes UINT8 reserved1, reserved2; ///< not used // total: 16 Bytes }; ///////////////////////////////////////////////////////////////////// /// PGF post-header is optional. It contains color table and user data /// @author C. Stamm /// @brief Optional PGF post-header struct PGFPostHeader { RGBQUAD clut[ColorTableLen];///< color table for indexed color images UINT8 *userData; ///< user data of size userDataLen UINT32 userDataLen; ///< user data size in bytes }; ///////////////////////////////////////////////////////////////////// /// ROI block header is used with ROI coding scheme. It contains block size and tile end flag /// @author C. Stamm /// @brief Block header used with ROI coding scheme union ROIBlockHeader { /// Constructor /// @param v Buffer size ROIBlockHeader(UINT16 v) { val = v; } /// Constructor /// @param size Buffer size /// @param end 0/1 Flag; 1: last part of a tile ROIBlockHeader(UINT32 size, bool end) { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; } UINT16 val; ///< unstructured union value /// @brief Named ROI block header (part of the union) struct RBH { #ifdef PGF_USE_BIG_ENDIAN UINT16 tileEnd : 1; ///< 1: last part of a tile UINT16 bufferSize: RLblockSizeLen; ///< number of uncoded UINT32 values in a block #else UINT16 bufferSize: RLblockSizeLen; ///< number of uncoded UINT32 values in a block UINT16 tileEnd : 1; ///< 1: last part of a tile #endif // PGF_USE_BIG_ENDIAN } rbh; ///< ROI block header // total: 2 Bytes }; #pragma pack() ///////////////////////////////////////////////////////////////////// /// PGF I/O exception /// @author C. Stamm /// @brief PGF exception struct IOException { /// Standard constructor IOException() : error(NoError) {} /// Constructor /// @param err Run-time error IOException(OSError err) : error(err) {} OSError error; ///< operating system error code }; ///////////////////////////////////////////////////////////////////// /// Rectangle /// @author C. Stamm /// @brief Rectangle struct PGFRect { /// Standard constructor PGFRect() : left(0), top(0), right(0), bottom(0) {} /// Constructor /// @param x Left offset /// @param y Top offset /// @param width Rectangle width /// @param height Rectangle height PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {} /// @return Rectangle width UINT32 Width() const { return right - left; } /// @return Rectangle height UINT32 Height() const { return bottom - top; } /// Test if point (x,y) is inside this rectangle /// @param x Point coordinate x /// @param y Point coordinate y /// @return True if point (x,y) is inside this rectangle bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); } UINT32 left, top, right, bottom; }; #ifdef __PGF32SUPPORT__ typedef INT32 DataT; #else typedef INT16 DataT; #endif typedef void (*RefreshCB)(void *p); //------------------------------------------------------------------------------- // Image constants //------------------------------------------------------------------------------- #define MagicVersionSize sizeof(PGFMagicVersion) #define PreHeaderSize sizeof(PGFPreHeader) #define HeaderSize sizeof(PGFHeader) #define ColorTableSize ColorTableLen*sizeof(RGBQUAD) #define DataTSize sizeof(DataT) #endif //PGF_PGFTYPES_H libpgf/INSTALL100777 0 0 2756 12313025746 6506 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-05-09 18:09:51 +0000 (Di, 09 Mai 2006) $ * $Revision: 186 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ Remark: The make process uses libtool. To compile and install the library, do the following: 1. './configure' 1.2 './configure --help' : gives you more information 2 'make' : will compile a shared and a static library 3. Install the library: make install Note: As this build process uses libtool there is a library interface created by libtool. This interface is libpgf.la, the static library itself is in libpgf.a and the shared library iteslf is in libpgf.so.x.y. All these files are needed. For more information see: http://www.gnu.org/software/libtoollibpgf/libpgf.pc.in100777 0 0 362 12232452342 7614 0prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@prefix@/include/@PACKAGE@ Name: @PACKAGE@ Description: libpgf - Progressive Graphics File (PGF) library Version: @VERSION@ Libs: -L${libdir} -lpgf Cflags: -I${includedir} libpgf/libpgf.spec.in100777 0 0 3670 12232452335 10173 0%define name @PACKAGE@ %define ver @VERSION@ %define prefix /usr %define datadir %{prefix}/share %define pkgname %{name}-%{ver} Summary: PGF (Progressive Graphics File) library Name: %{name} Version: %{ver} Vendor: TODO (www.libpgf.org) Release: %{rpm_release} License: LGPL Group: System Environment/Libraries URL: http://www.libpgf.org Source: ftp://www.libpgf.org/pub/%name/%{pkgname}.tar.gz BuildRoot: /var/tmp/%{pkgname}-%{user}/ Docdir: %{datadir}/doc/ %description libpgf is a library for working with PGF (Progresive Graphics File) images. # This is the summary for the devel rpm %package devel Summary: Include files, libraries and documentation for development Requires: %{name} = %{ver} Group: Development/Libraries # This is the description for the devel package %description devel libpgf is a library for working with PGF (Progresive Graphics File) images. %prep %setup CFLAGS=$RPM_OPT_FLAGS ./configure %{extra_configure_options} --prefix=%{prefix} %build make %install if test "/" != %{buildroot}; then rm -rf %{buildroot}; else echo "buildroot set to /, not deleting!"; fi; %makeinstall %clean if test "/" != %{buildroot}; then rm -rf %{buildroot}; else echo "buildroot set to /, not deleting!"; fi; # Since this is a library, we should run ldconfig # after installation and un-installation %post -p /sbin/ldconfig %postun -p /sbin/ldconfig # These are all files which make up the rpm # Shell globbing may be used %files %defattr(-, root, root) %{prefix}/lib/libpgf.so.* # The files which go in the devel package %files devel %defattr(-, root, root) %{prefix}/include/libpgf/* %{prefix}/lib/libpgf.a %{prefix}/lib/libpgf.so %{prefix}/lib/libpgf.la %{prefix}/lib/pkgconfig/@PACKAGE@.pc %{datadir}/doc/%{name}-%{ver}/html/* %{datadir}/man/man3/* # This is a changelog for the RPM ONLY! %changelog * Mon May 29 2005 Thomas Sondergaard initial spec file created from template libpgf/Makefile.am100777 0 0 2543 12232452342 7477 0 SUBDIRS = src include if HAS_DOXYGEN SUBDIRS += doc endif PACKAGE = @PACKAGE@ VERSION = @VERSION@ EXTRA_DIST = autogen.sh FAQ PGFCodec.sln PGFCodec.vcproj \ libpgf.spec #EXTRA_DIST = TODO BUGS README ChangeLog ReleaseNotes $(PACKAGE).spec \ # $(PACKAGE).spec.in $(PACKAGE).pc $(PACKAGE).pc.in ARCH = i386 RPM_DIR = $(HOME)/redhat DISTCLEANFILES = $(PACKAGE)-$(VERSION).tar.gz *~ RPMEXTRACONFOPT="--disable-dependency-tracking" RPMRELEASE=$(PACKAGE_RELEASE) install-data-local:: $(PACKAGE).pc $(mkinstalldirs) $(DESTDIR)$(libdir)/pkgconfig $(INSTALL) -m 644 $(PACKAGE).pc $(DESTDIR)$(libdir)/pkgconfig/$(PACKAGE).pc .PHONY: ChangeLog ChangeLog: echo "ChangeLog generation disabled" # svn2cl.sh rpm: $(RPM_DIR) dist rpmbuild --clean --quiet \ --define='extra_configure_options $(RPMEXTRACONFOPT)' \ --define='user $(USER)' \ --define='_topdir $(RPM_DIR)' \ --define='rpm_release $(RPMRELEASE)' \ --define='rpm_testbuild 0' \ $(RPMEXTRADEFINES) \ $(RPMEXTRAARGS) \ -ta $(PACKAGE)-$(VERSION).tar.gz $(RPM_DIR): -mkdir $(RPM_DIR) -mkdir $(RPM_DIR)/BUILD -mkdir $(RPM_DIR)/SPECS -mkdir $(RPM_DIR)/SOURCES -mkdir $(RPM_DIR)/SRPMS -mkdir $(RPM_DIR)/RPMS -mkdir $(RPM_DIR)/RPMS/i386 -mkdir $(RPM_DIR)/RPMS/i486 -mkdir $(RPM_DIR)/RPMS/i686 -mkdir $(RPM_DIR)/RPMS/ia64 -mkdir $(RPM_DIR)/RPMS/noarch libpgf/PGFCodec.sln100777 0 0 11476 12313025745 7563 0 Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PGFCodec", "PGFCodec.vcxproj", "{5B490780-D7B3-4997-95E3-E9617E474649}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Debug16|Win32 = Debug16|Win32 Debug16|x64 = Debug16|x64 Debug16OMP|Win32 = Debug16OMP|Win32 Debug16OMP|x64 = Debug16OMP|x64 DebugMFC|Win32 = DebugMFC|Win32 DebugMFC|x64 = DebugMFC|x64 DebugOMP|Win32 = DebugOMP|Win32 DebugOMP|x64 = DebugOMP|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 Release16|Win32 = Release16|Win32 Release16|x64 = Release16|x64 Release16OMP|Win32 = Release16OMP|Win32 Release16OMP|x64 = Release16OMP|x64 ReleaseMFC|Win32 = ReleaseMFC|Win32 ReleaseMFC|x64 = ReleaseMFC|x64 ReleaseOMP BE|Win32 = ReleaseOMP BE|Win32 ReleaseOMP BE|x64 = ReleaseOMP BE|x64 ReleaseOMP|Win32 = ReleaseOMP|Win32 ReleaseOMP|x64 = ReleaseOMP|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {5B490780-D7B3-4997-95E3-E9617E474649}.Debug|Win32.ActiveCfg = Debug|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug|Win32.Build.0 = Debug|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug|x64.ActiveCfg = Debug|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug|x64.Build.0 = Debug|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16|Win32.ActiveCfg = Debug16|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16|Win32.Build.0 = Debug16|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16|x64.ActiveCfg = Debug16|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16|x64.Build.0 = Debug16|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16OMP|Win32.ActiveCfg = Debug16OMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16OMP|Win32.Build.0 = Debug16OMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16OMP|x64.ActiveCfg = Debug16OMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Debug16OMP|x64.Build.0 = Debug16OMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugMFC|Win32.ActiveCfg = DebugMFC|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugMFC|Win32.Build.0 = DebugMFC|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugMFC|x64.ActiveCfg = DebugMFC|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugMFC|x64.Build.0 = DebugMFC|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugOMP|Win32.ActiveCfg = DebugOMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugOMP|Win32.Build.0 = DebugOMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugOMP|x64.ActiveCfg = DebugOMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.DebugOMP|x64.Build.0 = DebugOMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Release|Win32.ActiveCfg = Release|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Release|Win32.Build.0 = Release|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Release|x64.ActiveCfg = Release|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Release|x64.Build.0 = Release|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16|Win32.ActiveCfg = Release16|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16|Win32.Build.0 = Release16|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16|x64.ActiveCfg = Release16|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16|x64.Build.0 = Release16|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16OMP|Win32.ActiveCfg = Release16OMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16OMP|Win32.Build.0 = Release16OMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16OMP|x64.ActiveCfg = Release16OMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.Release16OMP|x64.Build.0 = Release16OMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseMFC|Win32.ActiveCfg = ReleaseMFC|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseMFC|Win32.Build.0 = ReleaseMFC|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseMFC|x64.ActiveCfg = ReleaseMFC|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseMFC|x64.Build.0 = ReleaseMFC|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP BE|Win32.ActiveCfg = ReleaseOMP BE|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP BE|Win32.Build.0 = ReleaseOMP BE|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP BE|x64.ActiveCfg = ReleaseOMP BE|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP BE|x64.Build.0 = ReleaseOMP BE|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP|Win32.ActiveCfg = ReleaseOMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP|Win32.Build.0 = ReleaseOMP|Win32 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP|x64.ActiveCfg = ReleaseOMP|x64 {5B490780-D7B3-4997-95E3-E9617E474649}.ReleaseOMP|x64.Build.0 = ReleaseOMP|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal libpgf/PGFCodec.vcxproj100777 0 0 147273 12313025745 10507 0 Debug16OMP Win32 Debug16OMP x64 Debug16 Win32 Debug16 x64 DebugMFC Win32 DebugMFC x64 DebugOMP Win32 DebugOMP x64 Debug Win32 Debug x64 Release16OMP Win32 Release16OMP x64 Release16 Win32 Release16 x64 ReleaseMFC Win32 ReleaseMFC x64 ReleaseOMP BE Win32 ReleaseOMP BE x64 ReleaseOMP Win32 ReleaseOMP x64 Release Win32 Release x64 {5B490780-D7B3-4997-95E3-E9617E474649} PGFCodec SAK SAK SAK SAK StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 Dynamic MultiByte StaticLibrary v110 Dynamic MultiByte StaticLibrary v110 Dynamic MultiByte StaticLibrary v110 Dynamic MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte StaticLibrary v110 false MultiByte <_ProjectFileVersion>11.0.50727.1 lib\$(Platform)\ $(Platform)\$(Configuration)\ false $(ProjectName)d $(Platform)\$(Configuration)\ false lib\$(Platform)\ $(ProjectName)d lib\$(Platform)\ $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ lib\$(Platform)\ lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)MFCd $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)MFCd lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)MFC $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)MFC lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)16d $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)16d lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)16 $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)16 lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)OMP $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)OMP lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)16OMP $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)16OMP lib\$(Platform)\ $(Platform)\$(Configuration)\ false $(ProjectName)OMPd $(Platform)\$(Configuration)\ false lib\$(Platform)\ $(ProjectName)OMPd lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)16OMPd $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)16OMPd lib\$(Platform)\ $(Platform)\$(Configuration)\ $(ProjectName)OMPBE $(Platform)\$(Configuration)\ lib\$(Platform)\ $(ProjectName)OMPBE Disabled include;%(AdditionalIncludeDirectories) TRACE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN64;TRACE;_DEBUG;_LIB;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) _MFC_VER;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL false Level4 true EditAndContinue _DEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN64;_MFC_VER;_DEBUG;_LIB;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL false Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable Speed include;%(AdditionalIncludeDirectories) WIN32;_MFC_VER;NDEBUG;_LIB;%(PreprocessorDefinitions) true MultiThreadedDLL false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable Speed include;%(AdditionalIncludeDirectories) WIN64;_MFC_VER;NDEBUG;_LIB;%(PreprocessorDefinitions) true MultiThreadedDLL false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_LIB;NPGF32;TRACE;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL false Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN64;_DEBUG;_LIB;NPGF32;TRACE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL false Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;NPGF32;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN64;NDEBUG;_LIB;NPGF32;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;NPGF32;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN64;NDEBUG;_LIB;NPGF32;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) TRACE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL true Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN64;TRACE;_DEBUG;_LIB;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL true Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_LIB;NPGF32;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL false true Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true Disabled include;%(AdditionalIncludeDirectories) WIN64;_DEBUG;_LIB;NPGF32;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL false true Level4 true ProgramDatabase _DEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;__BIG_ENDIAN__;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true MaxSpeed AnySuitable true Speed true true include;%(AdditionalIncludeDirectories) WIN64;NDEBUG;_LIB;__BIG_ENDIAN__;%(PreprocessorDefinitions) true MultiThreadedDLL NotSet false true Level4 true NDEBUG;%(PreprocessorDefinitions) 0x0409 true true libpgf/README100777 0 0 3331 12321453321 6314 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-05-18 16:03:32 +0200 (Thu, 18 May 2006) $ * $Revision: 194 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ The Progressive Graphics File ============================= For more information see http://www.libpgf.org. There you can find some documents concerning this progressive graphic file codec. This project is hosted on the Sourceforge.net platform. For support and questions, please use the installed mailing list and forums there. The Sourceforge URL of our project is: http://sourceforge.net/projects/libpgf ============================= Version 6.14.12, (Wed, 9 April 2014) Release Notes ------------- 1. The new version is a minor update of version 6.12.24. 2. It mainly contains some fixes of memory leaks in the OpenMP part and some improvements suggested by cppcheck and Coverity. 3. The Visual Studio project files are in the VS 11 format. libpgf/src/ 40777 0 0 0 12323042270 6122 5libpgf/src/BitStream.h100777 0 0 24074 12232452341 10317 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ * $Revision: 229 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Bitstream.h /// @brief PGF bit-stream operations /// @author C. Stamm #ifndef PGF_BITSTREAM_H #define PGF_BITSTREAM_H #include "PGFtypes.h" // constants //static const WordWidth = 32; //static const WordWidthLog = 5; static const UINT32 Filled = 0xFFFFFFFF; /// @brief Make 64 bit unsigned integer from two 32 bit unsigned integers #define MAKEU64(a, b) ((UINT64) (((UINT32) (a)) | ((UINT64) ((UINT32) (b))) << 32)) // these procedures have to be inlined because of performance reasons ////////////////////////////////////////////////////////////////////// /// Set one bit of a bit stream to 1 /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream inline void SetBit(UINT32* stream, UINT32 pos) { stream[pos >> WordWidthLog] |= (1 << (pos%WordWidth)); } ////////////////////////////////////////////////////////////////////// /// Set one bit of a bit stream to 0 /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream inline void ClearBit(UINT32* stream, UINT32 pos) { stream[pos >> WordWidthLog] &= ~(1 << (pos%WordWidth)); } ////////////////////////////////////////////////////////////////////// /// Return one bit of a bit stream /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @return bit at position pos of bit stream stream inline bool GetBit(UINT32* stream, UINT32 pos) { return (stream[pos >> WordWidthLog] & (1 << (pos%WordWidth))) > 0; } ////////////////////////////////////////////////////////////////////// /// Compare k-bit binary representation of stream at position pos with val /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param k Number of bits to compare /// @param val Value to compare with /// @return true if equal inline bool CompareBitBlock(UINT32* stream, UINT32 pos, UINT32 k, UINT32 val) { const UINT32 iLoInt = pos >> WordWidthLog; const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog; ASSERT(iLoInt <= iHiInt); const UINT32 mask = (Filled >> (WordWidth - k)); if (iLoInt == iHiInt) { // fits into one integer val &= mask; val <<= (pos%WordWidth); return (stream[iLoInt] & val) == val; } else { // must be splitted over integer boundary UINT64 v1 = MAKEU64(stream[iLoInt], stream[iHiInt]); UINT64 v2 = UINT64(val & mask) << (pos%WordWidth); return (v1 & v2) == v2; } } ////////////////////////////////////////////////////////////////////// /// Store k-bit binary representation of val in stream at position pos /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param val Value to store in stream at position pos /// @param k Number of bits of integer representation of val inline void SetValueBlock(UINT32* stream, UINT32 pos, UINT32 val, UINT32 k) { const UINT32 offset = pos%WordWidth; const UINT32 iLoInt = pos >> WordWidthLog; const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog; ASSERT(iLoInt <= iHiInt); const UINT32 loMask = Filled << offset; const UINT32 hiMask = Filled >> (WordWidth - 1 - ((pos + k - 1)%WordWidth)); if (iLoInt == iHiInt) { // fits into one integer stream[iLoInt] &= ~(loMask & hiMask); // clear bits stream[iLoInt] |= val << offset; // write value } else { // must be splitted over integer boundary stream[iLoInt] &= ~loMask; // clear bits stream[iLoInt] |= val << offset; // write lower part of value stream[iHiInt] &= ~hiMask; // clear bits stream[iHiInt] |= val >> (WordWidth - offset); // write higher part of value } } ////////////////////////////////////////////////////////////////////// /// Read k-bit number from stream at position pos /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param k Number of bits to read: 1 <= k <= 32 inline UINT32 GetValueBlock(UINT32* stream, UINT32 pos, UINT32 k) { UINT32 count, hiCount; const UINT32 iLoInt = pos >> WordWidthLog; // integer of first bit const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog; // integer of last bit const UINT32 loMask = Filled << (pos%WordWidth); const UINT32 hiMask = Filled >> (WordWidth - 1 - ((pos + k - 1)%WordWidth)); if (iLoInt == iHiInt) { // inside integer boundary count = stream[iLoInt] & (loMask & hiMask); count >>= pos%WordWidth; } else { // overlapping integer boundary count = stream[iLoInt] & loMask; count >>= pos%WordWidth; hiCount = stream[iHiInt] & hiMask; hiCount <<= WordWidth - (pos%WordWidth); count |= hiCount; } return count; } ////////////////////////////////////////////////////////////////////// /// Clear block of size at least len at position pos in stream /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param len Number of bits set to 0 inline void ClearBitBlock(UINT32* stream, UINT32 pos, UINT32 len) { ASSERT(len > 0); const UINT32 iFirstInt = pos >> WordWidthLog; const UINT32 iLastInt = (pos + len - 1) >> WordWidthLog; const UINT32 startMask = Filled << (pos%WordWidth); // const UINT32 endMask=Filled>>(WordWidth-1-((pos+len-1)%WordWidth)); if (iFirstInt == iLastInt) { stream[iFirstInt] &= ~(startMask /*& endMask*/); } else { stream[iFirstInt] &= ~startMask; for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) { // changed <= stream[i] = 0; } //stream[iLastInt] &= ~endMask; } } ////////////////////////////////////////////////////////////////////// /// Set block of size at least len at position pos in stream /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param len Number of bits set to 1 inline void SetBitBlock(UINT32* stream, UINT32 pos, UINT32 len) { ASSERT(len > 0); const UINT32 iFirstInt = pos >> WordWidthLog; const UINT32 iLastInt = (pos + len - 1) >> WordWidthLog; const UINT32 startMask = Filled << (pos%WordWidth); // const UINT32 endMask=Filled>>(WordWidth-1-((pos+len-1)%WordWidth)); if (iFirstInt == iLastInt) { stream[iFirstInt] |= (startMask /*& endMask*/); } else { stream[iFirstInt] |= startMask; for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) { // changed <= stream[i] = Filled; } //stream[iLastInt] &= ~endMask; } } ////////////////////////////////////////////////////////////////////// /// Returns the distance to the next 1 in stream at position pos. /// If no 1 is found within len bits, then len is returned. /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param len size of search area (in bits) /// return The distance to the next 1 in stream at position pos inline UINT32 SeekBitRange(UINT32* stream, UINT32 pos, UINT32 len) { UINT32 count = 0; UINT32 testMask = 1 << (pos%WordWidth); UINT32* word = stream + (pos >> WordWidthLog); while (((*word & testMask) == 0) && (count < len)) { count++; testMask <<= 1; if (!testMask) { word++; testMask = 1; // fast steps if all bits in a word are zero while ((count + WordWidth <= len) && (*word == 0)) { word++; count += WordWidth; } } } return count; } ////////////////////////////////////////////////////////////////////// /// Returns the distance to the next 0 in stream at position pos. /// If no 0 is found within len bits, then len is returned. /// @param stream A bit stream stored in array of unsigned integers /// @param pos A valid zero-based position in the bit stream /// @param len size of search area (in bits) /// return The distance to the next 0 in stream at position pos inline UINT32 SeekBit1Range(UINT32* stream, UINT32 pos, UINT32 len) { UINT32 count = 0; UINT32 testMask = 1 << (pos%WordWidth); UINT32* word = stream + (pos >> WordWidthLog); while (((*word & testMask) != 0) && (count < len)) { count++; testMask <<= 1; if (!testMask) { word++; testMask = 1; // fast steps if all bits in a word are one while ((count + WordWidth <= len) && (*word == Filled)) { word++; count += WordWidth; } } } return count; } ////////////////////////////////////////////////////////////////////// /// Compute bit position of the next 32-bit word /// @param pos current bit stream position /// @return bit position of next 32-bit word inline UINT32 AlignWordPos(UINT32 pos) { // return ((pos + WordWidth - 1) >> WordWidthLog) << WordWidthLog; return DWWIDTHBITS(pos); } ////////////////////////////////////////////////////////////////////// /// Compute number of the 32-bit words /// @param pos Current bit stream position /// @return Number of 32-bit words inline UINT32 NumberOfWords(UINT32 pos) { return (pos + WordWidth - 1) >> WordWidthLog; } #endif //PGF_BITSTREAM_H libpgf/src/Decoder.cpp100777 0 0 74174 12313026516 10334 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ * $Revision: 229 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Decoder.cpp /// @brief PGF decoder class implementation /// @author C. Stamm, R. Spuler #include "Decoder.h" #ifdef TRACE #include #endif ////////////////////////////////////////////////////// // PGF: file structure // // PGFPreHeader PGFHeader PGFPostHeader LevelLengths Level_n-1 Level_n-2 ... Level_0 // PGFPostHeader ::= [ColorTable] [UserData] // LevelLengths ::= UINT32[nLevels] ////////////////////////////////////////////////////// // Decoding scheme // input: binary file // output: wavelet coefficients stored in subbands // // file (for each buffer: packedLength (16 bit), packed bits) // | // m_codeBuffer (for each plane: RLcodeLength (16 bit), RLcoded sigBits + m_sign, refBits) // | | | // m_sign sigBits refBits [BufferLen, BufferLen, BufferLen] // | | | // m_value [BufferSize] // | // subband // // Constants #define CodeBufferBitLen (CodeBufferLen*WordWidth) ///< max number of bits in m_codeBuffer #define MaxCodeLen ((1 << RLblockSizeLen) - 1) ///< max length of RL encoded block ///////////////////////////////////////////////////////////////////// /// Constructor /// Read pre-header, header, and levelLength /// It might throw an IOException. /// @param stream A PGF stream /// @param preHeader [out] A PGF pre-header /// @param header [out] A PGF header /// @param postHeader [out] A PGF post-header /// @param levelLength The location of the levelLength array. The array is allocated in this method. The caller has to delete this array. /// @param userDataPos The stream position of the user data (metadata) /// @param useOMP If true, then the decoder will use multi-threading based on openMP /// @param skipUserData If true, then user data is not read. In case of available user data, the file position is still returned in userDataPos. CDecoder::CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header, PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos, bool useOMP, bool skipUserData) THROW_ : m_stream(stream) , m_startPos(0) , m_streamSizeEstimation(0) , m_encodedHeaderLength(0) , m_currentBlockIndex(0) , m_macroBlocksAvailable(0) #ifdef __PGFROISUPPORT__ , m_roi(false) #endif { ASSERT(m_stream); int count, expected; // set number of threads #ifdef LIBPGF_USE_OPENMP m_macroBlockLen = omp_get_num_procs(); #else m_macroBlockLen = 1; #endif if (useOMP && m_macroBlockLen > 1) { #ifdef LIBPGF_USE_OPENMP omp_set_num_threads(m_macroBlockLen); #endif // create macro block array m_macroBlocks = new(std::nothrow) CMacroBlock*[m_macroBlockLen]; if (!m_macroBlocks) ReturnWithError(InsufficientMemory); for (int i=0; i < m_macroBlockLen; i++) m_macroBlocks[i] = new CMacroBlock(); m_currentBlock = m_macroBlocks[m_currentBlockIndex]; } else { m_macroBlocks = 0; m_macroBlockLen = 1; // there is only one macro block m_currentBlock = new CMacroBlock(); } // store current stream position m_startPos = m_stream->GetPos(); // read magic and version count = expected = MagicVersionSize; m_stream->Read(&count, &preHeader); if (count != expected) ReturnWithError(MissingData); // read header size if (preHeader.version & Version6) { // 32 bit header size since version 6 count = expected = 4; } else { count = expected = 2; } m_stream->Read(&count, ((UINT8*)&preHeader) + MagicVersionSize); if (count != expected) ReturnWithError(MissingData); // make sure the values are correct read preHeader.hSize = __VAL(preHeader.hSize); // check magic number if (memcmp(preHeader.magic, PGFMagic, 3) != 0) { // error condition: wrong Magic number ReturnWithError(FormatCannotRead); } // read file header count = expected = (preHeader.hSize < HeaderSize) ? preHeader.hSize : HeaderSize; m_stream->Read(&count, &header); if (count != expected) ReturnWithError(MissingData); // make sure the values are correct read header.height = __VAL(UINT32(header.height)); header.width = __VAL(UINT32(header.width)); // be ready to read all versions including version 0 if (preHeader.version > 0) { #ifndef __PGFROISUPPORT__ // check ROI usage if (preHeader.version & PGFROI) ReturnWithError(FormatCannotRead); #endif int size = preHeader.hSize - HeaderSize; if (size > 0) { // read post-header if (header.mode == ImageModeIndexedColor) { ASSERT((size_t)size >= ColorTableSize); // read color table count = expected = ColorTableSize; m_stream->Read(&count, postHeader.clut); if (count != expected) ReturnWithError(MissingData); size -= count; } if (size > 0) { userDataPos = m_stream->GetPos(); postHeader.userDataLen = size; if (skipUserData) { Skip(size); } else { // create user data memory block postHeader.userData = new(std::nothrow) UINT8[postHeader.userDataLen]; if (!postHeader.userData) ReturnWithError(InsufficientMemory); // read user data count = expected = postHeader.userDataLen; m_stream->Read(&count, postHeader.userData); if (count != expected) ReturnWithError(MissingData); } } } // create levelLength levelLength = new(std::nothrow) UINT32[header.nLevels]; if (!levelLength) ReturnWithError(InsufficientMemory); // read levelLength count = expected = header.nLevels*WordBytes; m_stream->Read(&count, levelLength); if (count != expected) ReturnWithError(MissingData); #ifdef PGF_USE_BIG_ENDIAN // make sure the values are correct read for (int i=0; i < header.nLevels; i++) { levelLength[i] = __VAL(levelLength[i]); } #endif // compute the total size in bytes; keep attention: level length information is optional for (int i=0; i < header.nLevels; i++) { m_streamSizeEstimation += levelLength[i]; } } // store current stream position m_encodedHeaderLength = UINT32(m_stream->GetPos() - m_startPos); } ///////////////////////////////////////////////////////////////////// // Destructor CDecoder::~CDecoder() { if (m_macroBlocks) { for (int i=0; i < m_macroBlockLen; i++) delete m_macroBlocks[i]; delete[] m_macroBlocks; } else { delete m_currentBlock; } } ////////////////////////////////////////////////////////////////////// /// Copies data from the open stream to a target buffer. /// It might throw an IOException. /// @param target The target buffer /// @param len The number of bytes to read /// @return The number of bytes copied to the target buffer UINT32 CDecoder::ReadEncodedData(UINT8* target, UINT32 len) const THROW_ { ASSERT(m_stream); int count = len; m_stream->Read(&count, target); return count; } ///////////////////////////////////////////////////////////////////// /// Unpartitions a rectangular region of a given subband. /// Partitioning scheme: The plane is partitioned in squares of side length LinBlockSize. /// Read wavelet coefficients from the output buffer of a macro block. /// It might throw an IOException. /// @param band A subband /// @param quantParam Dequantization value /// @param width The width of the rectangle /// @param height The height of the rectangle /// @param startPos The relative subband position of the top left corner of the rectangular region /// @param pitch The number of bytes in row of the subband void CDecoder::Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_ { ASSERT(band); const div_t ww = div(width, LinBlockSize); const div_t hh = div(height, LinBlockSize); const int ws = pitch - LinBlockSize; const int wr = pitch - ww.rem; int pos, base = startPos, base2; // main height for (int i=0; i < hh.quot; i++) { // main width base2 = base; for (int j=0; j < ww.quot; j++) { pos = base2; for (int y=0; y < LinBlockSize; y++) { for (int x=0; x < LinBlockSize; x++) { DequantizeValue(band, pos, quantParam); pos++; } pos += ws; } base2 += LinBlockSize; } // rest of width pos = base2; for (int y=0; y < LinBlockSize; y++) { for (int x=0; x < ww.rem; x++) { DequantizeValue(band, pos, quantParam); pos++; } pos += wr; base += pitch; } } // main width base2 = base; for (int j=0; j < ww.quot; j++) { // rest of height pos = base2; for (int y=0; y < hh.rem; y++) { for (int x=0; x < LinBlockSize; x++) { DequantizeValue(band, pos, quantParam); pos++; } pos += ws; } base2 += LinBlockSize; } // rest of height pos = base2; for (int y=0; y < hh.rem; y++) { // rest of width for (int x=0; x < ww.rem; x++) { DequantizeValue(band, pos, quantParam); pos++; } pos += wr; } } //////////////////////////////////////////////////////////////////// // Decode and dequantize HL, and LH band of one level // LH and HH are interleaved in the codestream and must be split // Deccoding and dequantization of HL and LH Band (interleaved) using partitioning scheme // partitions the plane in squares of side length InterBlockSize // It might throw an IOException. void CDecoder::DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_ { CSubband* hlBand = wtChannel->GetSubband(level, HL); CSubband* lhBand = wtChannel->GetSubband(level, LH); const div_t lhH = div(lhBand->GetHeight(), InterBlockSize); const div_t hlW = div(hlBand->GetWidth(), InterBlockSize); const int hlws = hlBand->GetWidth() - InterBlockSize; const int hlwr = hlBand->GetWidth() - hlW.rem; const int lhws = lhBand->GetWidth() - InterBlockSize; const int lhwr = lhBand->GetWidth() - hlW.rem; int hlPos, lhPos; int hlBase = 0, lhBase = 0, hlBase2, lhBase2; ASSERT(lhBand->GetWidth() >= hlBand->GetWidth()); ASSERT(hlBand->GetHeight() >= lhBand->GetHeight()); if (!hlBand->AllocMemory()) ReturnWithError(InsufficientMemory); if (!lhBand->AllocMemory()) ReturnWithError(InsufficientMemory); // correct quantParam with normalization factor quantParam -= level; if (quantParam < 0) quantParam = 0; // main height for (int i=0; i < lhH.quot; i++) { // main width hlBase2 = hlBase; lhBase2 = lhBase; for (int j=0; j < hlW.quot; j++) { hlPos = hlBase2; lhPos = lhBase2; for (int y=0; y < InterBlockSize; y++) { for (int x=0; x < InterBlockSize; x++) { DequantizeValue(hlBand, hlPos, quantParam); DequantizeValue(lhBand, lhPos, quantParam); hlPos++; lhPos++; } hlPos += hlws; lhPos += lhws; } hlBase2 += InterBlockSize; lhBase2 += InterBlockSize; } // rest of width hlPos = hlBase2; lhPos = lhBase2; for (int y=0; y < InterBlockSize; y++) { for (int x=0; x < hlW.rem; x++) { DequantizeValue(hlBand, hlPos, quantParam); DequantizeValue(lhBand, lhPos, quantParam); hlPos++; lhPos++; } // width difference between HL and LH if (lhBand->GetWidth() > hlBand->GetWidth()) { DequantizeValue(lhBand, lhPos, quantParam); } hlPos += hlwr; lhPos += lhwr; hlBase += hlBand->GetWidth(); lhBase += lhBand->GetWidth(); } } // main width hlBase2 = hlBase; lhBase2 = lhBase; for (int j=0; j < hlW.quot; j++) { // rest of height hlPos = hlBase2; lhPos = lhBase2; for (int y=0; y < lhH.rem; y++) { for (int x=0; x < InterBlockSize; x++) { DequantizeValue(hlBand, hlPos, quantParam); DequantizeValue(lhBand, lhPos, quantParam); hlPos++; lhPos++; } hlPos += hlws; lhPos += lhws; } hlBase2 += InterBlockSize; lhBase2 += InterBlockSize; } // rest of height hlPos = hlBase2; lhPos = lhBase2; for (int y=0; y < lhH.rem; y++) { // rest of width for (int x=0; x < hlW.rem; x++) { DequantizeValue(hlBand, hlPos, quantParam); DequantizeValue(lhBand, lhPos, quantParam); hlPos++; lhPos++; } // width difference between HL and LH if (lhBand->GetWidth() > hlBand->GetWidth()) { DequantizeValue(lhBand, lhPos, quantParam); } hlPos += hlwr; lhPos += lhwr; hlBase += hlBand->GetWidth(); } // height difference between HL and LH if (hlBand->GetHeight() > lhBand->GetHeight()) { // total width hlPos = hlBase; for (int j=0; j < hlBand->GetWidth(); j++) { DequantizeValue(hlBand, hlPos, quantParam); hlPos++; } } } //////////////////////////////////////////////////////////////////// /// Skip a given number of bytes in the open stream. /// It might throw an IOException. void CDecoder::Skip(UINT64 offset) THROW_ { m_stream->SetPos(FSFromCurrent, offset); } ////////////////////////////////////////////////////////////////////// /// Dequantization of a single value at given position in subband. /// If encoded data is available, then stores dequantized band value into /// buffer m_value at position m_valuePos. /// Otherwise reads encoded data block and decodes it. /// It might throw an IOException. /// @param band A subband /// @param bandPos A valid position in subband band /// @param quantParam The quantization parameter void CDecoder::DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_ { ASSERT(m_currentBlock); if (m_currentBlock->IsCompletelyRead()) { // all data of current macro block has been read --> prepare next macro block DecodeTileBuffer(); } band->SetData(bandPos, m_currentBlock->m_value[m_currentBlock->m_valuePos] << quantParam); m_currentBlock->m_valuePos++; } ////////////////////////////////////////////////////////////////////// // Read next group of blocks from stream and decodes them into macro blocks // It might throw an IOException. void CDecoder::DecodeTileBuffer() THROW_ { // current block has been read --> prepare next current block m_macroBlocksAvailable--; if (m_macroBlocksAvailable > 0) { m_currentBlock = m_macroBlocks[++m_currentBlockIndex]; } else { DecodeBuffer(); } ASSERT(m_currentBlock); } ////////////////////////////////////////////////////////////////////// // Read next block from stream and decode into macro block // Decoding scheme: (16 bits) [ ROI ] data // ROI ::= (15 bits) (1 bit) // It might throw an IOException. void CDecoder::DecodeBuffer() THROW_ { ASSERT(m_macroBlocksAvailable <= 0); // macro block management if (m_macroBlockLen == 1) { ASSERT(m_currentBlock); ReadMacroBlock(m_currentBlock); m_currentBlock->BitplaneDecode(); m_macroBlocksAvailable = 1; } else { m_macroBlocksAvailable = 0; for (int i=0; i < m_macroBlockLen; i++) { // read sequentially several blocks try { ReadMacroBlock(m_macroBlocks[i]); m_macroBlocksAvailable++; } catch(IOException& ex) { if (ex.error == MissingData) { break; // no further data available } else { throw; } } } #ifdef LIBPGF_USE_OPENMP // decode in parallel #pragma omp parallel for default(shared) //no declared exceptions in next block #endif for (int i=0; i < m_macroBlocksAvailable; i++) { m_macroBlocks[i]->BitplaneDecode(); } // prepare current macro block m_currentBlockIndex = 0; m_currentBlock = m_macroBlocks[m_currentBlockIndex]; } } ////////////////////////////////////////////////////////////////////// // Read next block from stream and store it in the given block // It might throw an IOException. void CDecoder::ReadMacroBlock(CMacroBlock* block) THROW_ { ASSERT(block); UINT16 wordLen; ROIBlockHeader h(BufferSize); int count, expected; #ifdef TRACE //UINT32 filePos = (UINT32)m_stream->GetPos(); //printf("DecodeBuffer: %d\n", filePos); #endif // read wordLen count = expected = sizeof(UINT16); m_stream->Read(&count, &wordLen); if (count != expected) ReturnWithError(MissingData); wordLen = __VAL(wordLen); if (wordLen > BufferSize) ReturnWithError(FormatCannotRead); #ifdef __PGFROISUPPORT__ // read ROIBlockHeader if (m_roi) { m_stream->Read(&count, &h.val); if (count != expected) ReturnWithError(MissingData); // convert ROIBlockHeader h.val = __VAL(h.val); } #endif // save header block->m_header = h; // read data count = expected = wordLen*WordBytes; m_stream->Read(&count, block->m_codeBuffer); if (count != expected) ReturnWithError(MissingData); #ifdef PGF_USE_BIG_ENDIAN // convert data count /= WordBytes; for (int i=0; i < count; i++) { block->m_codeBuffer[i] = __VAL(block->m_codeBuffer[i]); } #endif #ifdef __PGFROISUPPORT__ ASSERT(m_roi && h.rbh.bufferSize <= BufferSize || h.rbh.bufferSize == BufferSize); #else ASSERT(h.rbh.bufferSize == BufferSize); #endif } ////////////////////////////////////////////////////////////////////// // Read next block from stream but don't decode into macro block // Encoding scheme: (16 bits) [ ROI ] data // ROI ::= (15 bits) (1 bit) // It might throw an IOException. void CDecoder::SkipTileBuffer() THROW_ { // current block is not used m_macroBlocksAvailable--; // check if pre-decoded data is available if (m_macroBlocksAvailable > 0) { m_currentBlock = m_macroBlocks[++m_currentBlockIndex]; return; } UINT16 wordLen; int count, expected; // read wordLen count = expected = sizeof(wordLen); m_stream->Read(&count, &wordLen); if (count != expected) ReturnWithError(MissingData); wordLen = __VAL(wordLen); ASSERT(wordLen <= BufferSize); #ifdef __PGFROISUPPORT__ if (m_roi) { // skip ROIBlockHeader m_stream->SetPos(FSFromCurrent, sizeof(ROIBlockHeader)); } #endif // skip data m_stream->SetPos(FSFromCurrent, wordLen*WordBytes); } ////////////////////////////////////////////////////////////////////// // Decode block into buffer of given size using bit plane coding. // A buffer contains bufferLen UINT32 values, thus, bufferSize bits per bit plane. // Following coding scheme is used: // Buffer ::= (5 bits) foreach(plane i): Plane[i] // Plane[i] ::= [ Sig1 | Sig2 ] [DWORD alignment] refBits // Sig1 ::= 1 (15 bits) codedSigAndSignBits // Sig2 ::= 0 (15 bits) [Sign1 | Sign2 ] [DWORD alignment] sigBits // Sign1 ::= 1 (15 bits) codedSignBits // Sign2 ::= 0 (15 bits) [DWORD alignment] signBits void CDecoder::CMacroBlock::BitplaneDecode() { UINT32 bufferSize = m_header.rbh.bufferSize; ASSERT(bufferSize <= BufferSize); UINT32 nPlanes; UINT32 codePos = 0, codeLen, sigLen, sigPos, signLen, signPos; DataT planeMask; // clear significance vector for (UINT32 k=0; k < bufferSize; k++) { m_sigFlagVector[k] = false; } m_sigFlagVector[bufferSize] = true; // sentinel // clear output buffer for (UINT32 k=0; k < BufferSize; k++) { m_value[k] = 0; } // read number of bit planes // nPlanes = GetValueBlock(m_codeBuffer, 0, MaxBitPlanesLog); codePos += MaxBitPlanesLog; // loop through all bit planes if (nPlanes == 0) nPlanes = MaxBitPlanes + 1; ASSERT(0 < nPlanes && nPlanes <= MaxBitPlanes + 1); planeMask = 1 << (nPlanes - 1); for (int plane = nPlanes - 1; plane >= 0; plane--) { // read RL code if (GetBit(m_codeBuffer, codePos)) { // RL coding of sigBits is used // <1>_ codePos++; // read codeLen codeLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(codeLen <= MaxCodeLen); // position of encoded sigBits and signBits sigPos = codePos + RLblockSizeLen; ASSERT(sigPos < CodeBufferBitLen); // refinement bits codePos = AlignWordPos(sigPos + codeLen); ASSERT(codePos < CodeBufferBitLen); // run-length decode significant bits and signs from m_codeBuffer and // read refinement bits from m_codeBuffer and compose bit plane sigLen = ComposeBitplaneRLD(bufferSize, planeMask, sigPos, &m_codeBuffer[codePos >> WordWidthLog]); } else { // no RL coding is used for sigBits and signBits together // <0> codePos++; // read sigLen sigLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(sigLen <= MaxCodeLen); codePos += RLblockSizeLen; ASSERT(codePos < CodeBufferBitLen); // read RL code for signBits if (GetBit(m_codeBuffer, codePos)) { // RL coding is used just for signBits // <1>__ codePos++; // read codeLen codeLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(codeLen <= MaxCodeLen); // sign bits signPos = codePos + RLblockSizeLen; ASSERT(signPos < CodeBufferBitLen); // significant bits sigPos = AlignWordPos(signPos + codeLen); ASSERT(sigPos < CodeBufferBitLen); // refinement bits codePos = AlignWordPos(sigPos + sigLen); ASSERT(codePos < CodeBufferBitLen); // read significant and refinement bitset from m_codeBuffer sigLen = ComposeBitplaneRLD(bufferSize, planeMask, &m_codeBuffer[sigPos >> WordWidthLog], &m_codeBuffer[codePos >> WordWidthLog], signPos); } else { // RL coding of signBits was not efficient and therefore not used // <0>___ codePos++; // read signLen signLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(signLen <= MaxCodeLen); // sign bits signPos = AlignWordPos(codePos + RLblockSizeLen); ASSERT(signPos < CodeBufferBitLen); // significant bits sigPos = AlignWordPos(signPos + signLen); ASSERT(sigPos < CodeBufferBitLen); // refinement bits codePos = AlignWordPos(sigPos + sigLen); ASSERT(codePos < CodeBufferBitLen); // read significant and refinement bitset from m_codeBuffer sigLen = ComposeBitplane(bufferSize, planeMask, &m_codeBuffer[sigPos >> WordWidthLog], &m_codeBuffer[codePos >> WordWidthLog], &m_codeBuffer[signPos >> WordWidthLog]); } } // start of next chunk codePos = AlignWordPos(codePos + bufferSize - sigLen); ASSERT(codePos < CodeBufferBitLen); // next plane planeMask >>= 1; } m_valuePos = 0; } //////////////////////////////////////////////////////////////////// // Reconstruct bitplane from significant bitset and refinement bitset // returns length [bits] of sigBits // input: sigBits, refBits, signBits // output: m_value UINT32 CDecoder::CMacroBlock::ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits) { ASSERT(sigBits); ASSERT(refBits); ASSERT(signBits); UINT32 valPos = 0, signPos = 0, refPos = 0; UINT32 sigPos = 0, sigEnd; UINT32 zerocnt; while (valPos < bufferSize) { // search next 1 in m_sigFlagVector using searching with sentinel sigEnd = valPos; while(!m_sigFlagVector[sigEnd]) { sigEnd++; } sigEnd -= valPos; sigEnd += sigPos; // search 1's in sigBits[sigPos..sigEnd) // these 1's are significant bits while (sigPos < sigEnd) { // search 0's zerocnt = SeekBitRange(sigBits, sigPos, sigEnd - sigPos); sigPos += zerocnt; valPos += zerocnt; if (sigPos < sigEnd) { // write bit to m_value SetBitAtPos(valPos, planeMask); // copy sign bit SetSign(valPos, GetBit(signBits, signPos++)); // update significance flag vector m_sigFlagVector[valPos++] = true; sigPos++; } } // refinement bit if (valPos < bufferSize) { // write one refinement bit if (GetBit(refBits, refPos)) { SetBitAtPos(valPos, planeMask); } refPos++; valPos++; } } ASSERT(sigPos <= bufferSize); ASSERT(refPos <= bufferSize); ASSERT(signPos <= bufferSize); ASSERT(valPos == bufferSize); return sigPos; } //////////////////////////////////////////////////////////////////// // Reconstruct bitplane from significant bitset and refinement bitset // returns length [bits] of decoded significant bits // input: RL encoded sigBits and signBits in m_codeBuffer, refBits // output: m_value // RLE: // - Decode run of 2^k zeros by a single 0. // - Decode run of count 0's followed by a 1 with codeword: 1x // - x is 0: if a positive sign has been stored, otherwise 1 // - Read each bit from m_codeBuffer[codePos] and increment codePos. UINT32 CDecoder::CMacroBlock::ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 codePos, UINT32* refBits) { ASSERT(refBits); UINT32 valPos = 0, refPos = 0; UINT32 sigPos = 0, sigEnd; UINT32 k = 3; UINT32 runlen = 1 << k; // = 2^k UINT32 count = 0, rest = 0; bool set1 = false; while (valPos < bufferSize) { // search next 1 in m_sigFlagVector using searching with sentinel sigEnd = valPos; while(!m_sigFlagVector[sigEnd]) { sigEnd++; } sigEnd -= valPos; sigEnd += sigPos; while (sigPos < sigEnd) { if (rest || set1) { // rest of last run sigPos += rest; valPos += rest; rest = 0; } else { // decode significant bits if (GetBit(m_codeBuffer, codePos++)) { // extract counter and generate zero run of length count if (k > 0) { // extract counter count = GetValueBlock(m_codeBuffer, codePos, k); codePos += k; if (count > 0) { sigPos += count; valPos += count; } // adapt k (half run-length interval) k--; runlen >>= 1; } set1 = true; } else { // generate zero run of length 2^k sigPos += runlen; valPos += runlen; // adapt k (double run-length interval) if (k < WordWidth) { k++; runlen <<= 1; } } } if (sigPos < sigEnd) { if (set1) { set1 = false; // write 1 bit SetBitAtPos(valPos, planeMask); // set sign bit SetSign(valPos, GetBit(m_codeBuffer, codePos++)); // update significance flag vector m_sigFlagVector[valPos++] = true; sigPos++; } } else { rest = sigPos - sigEnd; sigPos = sigEnd; valPos -= rest; } } // refinement bit if (valPos < bufferSize) { // write one refinement bit if (GetBit(refBits, refPos)) { SetBitAtPos(valPos, planeMask); } refPos++; valPos++; } } ASSERT(sigPos <= bufferSize); ASSERT(refPos <= bufferSize); ASSERT(valPos == bufferSize); return sigPos; } //////////////////////////////////////////////////////////////////// // Reconstruct bitplane from significant bitset, refinement bitset, and RL encoded sign bits // returns length [bits] of sigBits // input: sigBits, refBits, RL encoded signBits // output: m_value // RLE: // decode run of 2^k 1's by a single 1 // decode run of count 1's followed by a 0 with codeword: 0 UINT32 CDecoder::CMacroBlock::ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos) { ASSERT(sigBits); ASSERT(refBits); UINT32 valPos = 0, refPos = 0; UINT32 sigPos = 0, sigEnd; UINT32 zerocnt, count = 0; UINT32 k = 0; UINT32 runlen = 1 << k; // = 2^k bool signBit = false; bool zeroAfterRun = false; while (valPos < bufferSize) { // search next 1 in m_sigFlagVector using searching with sentinel sigEnd = valPos; while(!m_sigFlagVector[sigEnd]) { sigEnd++; } sigEnd -= valPos; sigEnd += sigPos; // search 1's in sigBits[sigPos..sigEnd) // these 1's are significant bits while (sigPos < sigEnd) { // search 0's zerocnt = SeekBitRange(sigBits, sigPos, sigEnd - sigPos); sigPos += zerocnt; valPos += zerocnt; if (sigPos < sigEnd) { // write bit to m_value SetBitAtPos(valPos, planeMask); // check sign bit if (count == 0) { // all 1's have been set if (zeroAfterRun) { // finish the run with a 0 signBit = false; zeroAfterRun = false; } else { // decode next sign bit if (GetBit(m_codeBuffer, signPos++)) { // generate 1's run of length 2^k count = runlen - 1; signBit = true; // adapt k (double run-length interval) if (k < WordWidth) { k++; runlen <<= 1; } } else { // extract counter and generate 1's run of length count if (k > 0) { // extract counter count = GetValueBlock(m_codeBuffer, signPos, k); signPos += k; // adapt k (half run-length interval) k--; runlen >>= 1; } if (count > 0) { count--; signBit = true; zeroAfterRun = true; } else { signBit = false; } } } } else { ASSERT(count > 0); ASSERT(signBit); count--; } // copy sign bit SetSign(valPos, signBit); // update significance flag vector m_sigFlagVector[valPos++] = true; sigPos++; } } // refinement bit if (valPos < bufferSize) { // write one refinement bit if (GetBit(refBits, refPos)) { SetBitAtPos(valPos, planeMask); } refPos++; valPos++; } } ASSERT(sigPos <= bufferSize); ASSERT(refPos <= bufferSize); ASSERT(valPos == bufferSize); return sigPos; } //////////////////////////////////////////////////////////////////// #ifdef TRACE void CDecoder::DumpBuffer() { //printf("\nDump\n"); //for (int i=0; i < BufferSize; i++) { // printf("%d", m_value[i]); //} } #endif //TRACE libpgf/src/Decoder.h100777 0 0 23712 12313026516 7771 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ * $Revision: 229 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Decoder.h /// @brief PGF decoder class /// @author C. Stamm, R. Spuler #ifndef PGF_DECODER_H #define PGF_DECODER_H #include "PGFstream.h" #include "BitStream.h" #include "Subband.h" #include "WaveletTransform.h" ///////////////////////////////////////////////////////////////////// // Constants #define BufferLen (BufferSize/WordWidth) ///< number of words per buffer #define CodeBufferLen BufferSize ///< number of words in code buffer (CodeBufferLen > BufferLen) ///////////////////////////////////////////////////////////////////// /// PGF decoder class. /// @author C. Stamm, R. Spuler /// @brief PGF decoder class CDecoder { ////////////////////////////////////////////////////////////////////// /// PGF decoder macro block class. /// @author C. Stamm, I. Bauersachs /// @brief A macro block is a decoding unit of fixed size (uncoded) class CMacroBlock { public: ////////////////////////////////////////////////////////////////////// /// Constructor: Initializes new macro block. /// @param decoder Pointer to outer class. CMacroBlock() : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block #pragma warning( suppress : 4351 ) , m_value() , m_codeBuffer() , m_valuePos(0) , m_sigFlagVector() { } ////////////////////////////////////////////////////////////////////// /// Returns true if this macro block has been completely read. /// @return true if current value position is at block end bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; } ////////////////////////////////////////////////////////////////////// /// Decodes already read input data into this macro block. /// Several macro blocks can be decoded in parallel. /// Call CDecoder::ReadMacroBlock before this method. void BitplaneDecode(); ROIBlockHeader m_header; ///< block header DataT m_value[BufferSize]; ///< output buffer of values with index m_valuePos UINT32 m_codeBuffer[CodeBufferLen]; ///< input buffer for encoded bitstream UINT32 m_valuePos; ///< current position in m_value private: UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits); UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits); UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos); void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; } void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); } bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder }; public: ///////////////////////////////////////////////////////////////////// /// Constructor: Read pre-header, header, and levelLength at current stream position. /// It might throw an IOException. /// @param stream A PGF stream /// @param preHeader [out] A PGF pre-header /// @param header [out] A PGF header /// @param postHeader [out] A PGF post-header /// @param levelLength The location of the levelLength array. The array is allocated in this method. The caller has to delete this array. /// @param userDataPos The stream position of the user data (metadata) /// @param useOMP If true, then the decoder will use multi-threading based on openMP /// @param skipUserData If true, then user data is not read. In case of available user data, the file position is still returned in userDataPos. CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header, PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos, bool useOMP, bool skipUserData) THROW_; // throws IOException ///////////////////////////////////////////////////////////////////// /// Destructor ~CDecoder(); ///////////////////////////////////////////////////////////////////// /// Unpartitions a rectangular region of a given subband. /// Partitioning scheme: The plane is partitioned in squares of side length LinBlockSize. /// Read wavelet coefficients from the output buffer of a macro block. /// It might throw an IOException. /// @param band A subband /// @param quantParam Dequantization value /// @param width The width of the rectangle /// @param height The height of the rectangle /// @param startPos The relative subband position of the top left corner of the rectangular region /// @param pitch The number of bytes in row of the subband void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_; ///////////////////////////////////////////////////////////////////// /// Deccoding and dequantization of HL and LH subband (interleaved) using partitioning scheme. /// Partitioning scheme: The plane is partitioned in squares of side length InterBlockSize. /// It might throw an IOException. /// @param wtChannel A wavelet transform channel containing the HL and HL band /// @param level Wavelet transform level /// @param quantParam Dequantization value void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_; ////////////////////////////////////////////////////////////////////// /// Return the length of all encoded headers in bytes. /// @return The length of all encoded headers in bytes UINT32 GetEncodedHeaderLength() const { return m_encodedHeaderLength; } //////////////////////////////////////////////////////////////////// /// Reset stream position to beginning of PGF pre-header void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); } //////////////////////////////////////////////////////////////////// /// Reset stream position to beginning of data block void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); } //////////////////////////////////////////////////////////////////// /// Skip a given number of bytes in the open stream. /// It might throw an IOException. void Skip(UINT64 offset) THROW_; ///////////////////////////////////////////////////////////////////// /// Dequantization of a single value at given position in subband. /// It might throw an IOException. /// @param band A subband /// @param bandPos A valid position in subband band /// @param quantParam The quantization parameter void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_; ////////////////////////////////////////////////////////////////////// /// Copies data from the open stream to a target buffer. /// It might throw an IOException. /// @param target The target buffer /// @param len The number of bytes to read /// @return The number of bytes copied to the target buffer UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_; ///////////////////////////////////////////////////////////////////// /// Reads stream and decodes tile buffer /// It might throw an IOException. void DecodeBuffer() THROW_; ///////////////////////////////////////////////////////////////////// /// @return Stream CPGFStream* GetStream() { return m_stream; } ///////////////////////////////////////////////////////////////////// /// @return True if decoded macro blocks are available for processing bool MacroBlocksAvailable() const { return m_macroBlocksAvailable > 1; } #ifdef __PGFROISUPPORT__ ///////////////////////////////////////////////////////////////////// /// Reads stream and decodes tile buffer /// It might throw an IOException. void DecodeTileBuffer() THROW_; ///////////////////////////////////////////////////////////////////// /// Resets stream position to next tile. /// It might throw an IOException. void SkipTileBuffer() THROW_; ///////////////////////////////////////////////////////////////////// /// Enables region of interest (ROI) status. void SetROI() { m_roi = true; } #endif #ifdef TRACE void DumpBuffer(); #endif private: void ReadMacroBlock(CMacroBlock* block) THROW_; ///< throws IOException CPGFStream *m_stream; ///< input PGF stream UINT64 m_startPos; ///< stream position at the beginning of the PGF pre-header UINT64 m_streamSizeEstimation; ///< estimation of stream size UINT32 m_encodedHeaderLength; ///< stream offset from startPos to the beginning of the data part (highest level) CMacroBlock **m_macroBlocks; ///< array of macroblocks int m_currentBlockIndex; ///< index of current macro block int m_macroBlockLen; ///< array length int m_macroBlocksAvailable; ///< number of decoded macro blocks (including currently used macro block) CMacroBlock *m_currentBlock; ///< current macro block (used by main thread) #ifdef __PGFROISUPPORT__ bool m_roi; ///< true: ensures region of interest (ROI) decoding #endif }; #endif //PGF_DECODER_H libpgf/src/Encoder.cpp100777 0 0 62005 12313025746 10340 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2007-02-03 13:04:21 +0100 (Sa, 03 Feb 2007) $ * $Revision: 280 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Encoder.cpp /// @brief PGF encoder class implementation /// @author C. Stamm, R. Spuler #include "Encoder.h" #ifdef TRACE #include #endif ////////////////////////////////////////////////////// // PGF: file structure // // PGFPreHeader PGFHeader PGFPostHeader LevelLengths Level_n-1 Level_n-2 ... Level_0 // PGFPostHeader ::= [ColorTable] [UserData] // LevelLengths ::= UINT32[nLevels] ////////////////////////////////////////////////////// // Encoding scheme // input: wavelet coefficients stored in subbands // output: binary file // // subband // | // m_value [BufferSize] // | | | // m_sign sigBits refBits [BufferSize, BufferLen, BufferLen] // | | | // m_codeBuffer (for each plane: RLcodeLength (16 bit), RLcoded sigBits + m_sign, refBits) // | // file (for each buffer: packedLength (16 bit), packed bits) // // Constants #define CodeBufferBitLen (CodeBufferLen*WordWidth) ///< max number of bits in m_codeBuffer #define MaxCodeLen ((1 << RLblockSizeLen) - 1) ///< max length of RL encoded block ////////////////////////////////////////////////////// /// Write pre-header, header, postHeader, and levelLength. /// It might throw an IOException. /// @param stream A PGF stream /// @param preHeader A already filled in PGF pre-header /// @param header An already filled in PGF header /// @param postHeader [in] An already filled in PGF post-header (containing color table, user data, ...) /// @param userDataPos [out] File position of user data /// @param useOMP If true, then the encoder will use multi-threading based on openMP CEncoder::CEncoder(CPGFStream* stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader& postHeader, UINT64& userDataPos, bool useOMP) THROW_ : m_stream(stream) , m_bufferStartPos(0) , m_currLevelIndex(0) , m_nLevels(header.nLevels) , m_favorSpeed(false) , m_forceWriting(false) #ifdef __PGFROISUPPORT__ , m_roi(false) #endif { ASSERT(m_stream); int count; m_lastMacroBlock = 0; m_levelLength = NULL; // set number of threads #ifdef LIBPGF_USE_OPENMP m_macroBlockLen = omp_get_num_procs(); #else m_macroBlockLen = 1; #endif if (useOMP && m_macroBlockLen > 1) { #ifdef LIBPGF_USE_OPENMP omp_set_num_threads(m_macroBlockLen); #endif // create macro block array m_macroBlocks = new(std::nothrow) CMacroBlock*[m_macroBlockLen]; if (!m_macroBlocks) ReturnWithError(InsufficientMemory); for (int i=0; i < m_macroBlockLen; i++) m_macroBlocks[i] = new CMacroBlock(this); m_currentBlock = m_macroBlocks[m_lastMacroBlock++]; } else { m_macroBlocks = 0; m_macroBlockLen = 1; m_currentBlock = new CMacroBlock(this); } // save file position m_startPosition = m_stream->GetPos(); // write preHeader preHeader.hSize = __VAL(preHeader.hSize); count = PreHeaderSize; m_stream->Write(&count, &preHeader); // write file header header.height = __VAL(header.height); header.width = __VAL(header.width); count = HeaderSize; m_stream->Write(&count, &header); // write postHeader if (header.mode == ImageModeIndexedColor) { // write color table count = ColorTableSize; m_stream->Write(&count, (void *)postHeader.clut); } // save user data file position userDataPos = m_stream->GetPos(); if (postHeader.userDataLen) { if (postHeader.userData) { // write user data count = postHeader.userDataLen; m_stream->Write(&count, postHeader.userData); } else { m_stream->SetPos(FSFromCurrent, count); } } // save level length file position m_levelLengthPos = m_stream->GetPos(); } ////////////////////////////////////////////////////// // Destructor CEncoder::~CEncoder() { if (m_macroBlocks) { for (int i=0; i < m_macroBlockLen; i++) delete m_macroBlocks[i]; delete[] m_macroBlocks; } else { delete m_currentBlock; } } ///////////////////////////////////////////////////////////////////// /// Increase post-header size and write new size into stream. /// @param preHeader An already filled in PGF pre-header /// It might throw an IOException. void CEncoder::UpdatePostHeaderSize(PGFPreHeader preHeader) THROW_ { UINT64 curPos = m_stream->GetPos(); // end of user data int count = PreHeaderSize; // write preHeader m_stream->SetPos(FSFromStart, m_startPosition); preHeader.hSize = __VAL(preHeader.hSize); m_stream->Write(&count, &preHeader); m_stream->SetPos(FSFromStart, curPos); } ///////////////////////////////////////////////////////////////////// /// Create level length data structure and write a place holder into stream. /// It might throw an IOException. /// @param levelLength A reference to an integer array, large enough to save the relative file positions of all PGF levels /// @return number of bytes written into stream UINT32 CEncoder::WriteLevelLength(UINT32*& levelLength) THROW_ { // renew levelLength delete[] levelLength; levelLength = new(std::nothrow) UINT32[m_nLevels]; if (!levelLength) ReturnWithError(InsufficientMemory); for (UINT8 l = 0; l < m_nLevels; l++) levelLength[l] = 0; m_levelLength = levelLength; // save level length file position m_levelLengthPos = m_stream->GetPos(); // write dummy levelLength int count = m_nLevels*WordBytes; m_stream->Write(&count, m_levelLength); // save current file position SetBufferStartPos(); return count; } ////////////////////////////////////////////////////// /// Write new levelLength into stream. /// It might throw an IOException. /// @return Written image bytes. UINT32 CEncoder::UpdateLevelLength() THROW_ { UINT64 curPos = m_stream->GetPos(); // end of image // set file pos to levelLength m_stream->SetPos(FSFromStart, m_levelLengthPos); if (m_levelLength) { #ifdef PGF_USE_BIG_ENDIAN UINT32 levelLength; int count = WordBytes; for (int i=0; i < m_currLevelIndex; i++) { levelLength = __VAL(UINT32(m_levelLength[i])); m_stream->Write(&count, &levelLength); } #else int count = m_currLevelIndex*WordBytes; m_stream->Write(&count, m_levelLength); #endif //PGF_USE_BIG_ENDIAN } else { int count = m_currLevelIndex*WordBytes; m_stream->SetPos(FSFromCurrent, count); } // begin of image UINT32 retValue = UINT32(curPos - m_stream->GetPos()); // restore file position m_stream->SetPos(FSFromStart, curPos); return retValue; } ///////////////////////////////////////////////////////////////////// /// Partitions a rectangular region of a given subband. /// Partitioning scheme: The plane is partitioned in squares of side length LinBlockSize. /// Write wavelet coefficients from subband into the input buffer of a macro block. /// It might throw an IOException. /// @param band A subband /// @param width The width of the rectangle /// @param height The height of the rectangle /// @param startPos The absolute subband position of the top left corner of the rectangular region /// @param pitch The number of bytes in row of the subband void CEncoder::Partition(CSubband* band, int width, int height, int startPos, int pitch) THROW_ { ASSERT(band); const div_t hh = div(height, LinBlockSize); const div_t ww = div(width, LinBlockSize); const int ws = pitch - LinBlockSize; const int wr = pitch - ww.rem; int pos, base = startPos, base2; // main height for (int i=0; i < hh.quot; i++) { // main width base2 = base; for (int j=0; j < ww.quot; j++) { pos = base2; for (int y=0; y < LinBlockSize; y++) { for (int x=0; x < LinBlockSize; x++) { WriteValue(band, pos); pos++; } pos += ws; } base2 += LinBlockSize; } // rest of width pos = base2; for (int y=0; y < LinBlockSize; y++) { for (int x=0; x < ww.rem; x++) { WriteValue(band, pos); pos++; } pos += wr; base += pitch; } } // main width base2 = base; for (int j=0; j < ww.quot; j++) { // rest of height pos = base2; for (int y=0; y < hh.rem; y++) { for (int x=0; x < LinBlockSize; x++) { WriteValue(band, pos); pos++; } pos += ws; } base2 += LinBlockSize; } // rest of height pos = base2; for (int y=0; y < hh.rem; y++) { // rest of width for (int x=0; x < ww.rem; x++) { WriteValue(band, pos); pos++; } pos += wr; } } ////////////////////////////////////////////////////// /// Pad buffer with zeros and encode buffer. /// It might throw an IOException. void CEncoder::Flush() THROW_ { if (m_currentBlock->m_valuePos > 0) { // pad buffer with zeros memset(&(m_currentBlock->m_value[m_currentBlock->m_valuePos]), 0, (BufferSize - m_currentBlock->m_valuePos)*DataTSize); m_currentBlock->m_valuePos = BufferSize; // encode buffer m_forceWriting = true; // makes sure that the following EncodeBuffer is really written into the stream EncodeBuffer(ROIBlockHeader(m_currentBlock->m_valuePos, true)); } } ///////////////////////////////////////////////////////////////////// // Stores band value from given position bandPos into buffer m_value at position m_valuePos // If buffer is full encode it to file // It might throw an IOException. void CEncoder::WriteValue(CSubband* band, int bandPos) THROW_ { if (m_currentBlock->m_valuePos == BufferSize) { EncodeBuffer(ROIBlockHeader(BufferSize, false)); } DataT val = m_currentBlock->m_value[m_currentBlock->m_valuePos++] = band->GetData(bandPos); UINT32 v = abs(val); if (v > m_currentBlock->m_maxAbsValue) m_currentBlock->m_maxAbsValue = v; } ///////////////////////////////////////////////////////////////////// // Encode buffer and write data into stream. // h contains buffer size and flag indicating end of tile. // Encoding scheme: (16 bits) [ ROI ] data // ROI ::= (15 bits) (1 bit) // It might throw an IOException. void CEncoder::EncodeBuffer(ROIBlockHeader h) THROW_ { ASSERT(m_currentBlock); #ifdef __PGFROISUPPORT__ ASSERT(m_roi && h.rbh.bufferSize <= BufferSize || h.rbh.bufferSize == BufferSize); #else ASSERT(h.rbh.bufferSize == BufferSize); #endif m_currentBlock->m_header = h; // macro block management if (m_macroBlockLen == 1) { m_currentBlock->BitplaneEncode(); WriteMacroBlock(m_currentBlock); } else { // save last level index int lastLevelIndex = m_currentBlock->m_lastLevelIndex; if (m_forceWriting || m_lastMacroBlock == m_macroBlockLen) { // encode macro blocks /* volatile OSError error = NoError; #ifdef LIBPGF_USE_OPENMP #pragma omp parallel for ordered default(shared) #endif for (int i=0; i < m_lastMacroBlock; i++) { if (error == NoError) { m_macroBlocks[i]->BitplaneEncode(); #ifdef LIBPGF_USE_OPENMP #pragma omp ordered #endif { try { WriteMacroBlock(m_macroBlocks[i]); } catch (IOException& e) { error = e.error; } delete m_macroBlocks[i]; m_macroBlocks[i] = 0; } } } if (error != NoError) ReturnWithError(error); */ #ifdef LIBPGF_USE_OPENMP #pragma omp parallel for default(shared) //no declared exceptions in next block #endif for (int i=0; i < m_lastMacroBlock; i++) { m_macroBlocks[i]->BitplaneEncode(); } for (int i=0; i < m_lastMacroBlock; i++) { WriteMacroBlock(m_macroBlocks[i]); } // prepare for next round m_forceWriting = false; m_lastMacroBlock = 0; } // re-initialize macro block m_currentBlock = m_macroBlocks[m_lastMacroBlock++]; m_currentBlock->Init(lastLevelIndex); } } ///////////////////////////////////////////////////////////////////// // Write encoded macro block into stream. // It might throw an IOException. void CEncoder::WriteMacroBlock(CMacroBlock* block) THROW_ { ASSERT(block); #ifdef __PGFROISUPPORT__ ROIBlockHeader h = block->m_header; #endif UINT16 wordLen = UINT16(NumberOfWords(block->m_codePos)); ASSERT(wordLen <= CodeBufferLen); int count = sizeof(UINT16); #ifdef TRACE //UINT32 filePos = (UINT32)m_stream->GetPos(); //printf("EncodeBuffer: %d\n", filePos); #endif #ifdef PGF_USE_BIG_ENDIAN // write wordLen UINT16 wl = __VAL(wordLen); m_stream->Write(&count, &wl); ASSERT(count == sizeof(UINT16)); #ifdef __PGFROISUPPORT__ // write ROIBlockHeader if (m_roi) { h.val = __VAL(h.val); m_stream->Write(&count, &h.val); ASSERT(count == sizeof(UINT16)); } #endif // __PGFROISUPPORT__ // convert data for (int i=0; i < wordLen; i++) { block->m_codeBuffer[i] = __VAL(block->m_codeBuffer[i]); } #else // write wordLen m_stream->Write(&count, &wordLen); ASSERT(count == sizeof(UINT16)); #ifdef __PGFROISUPPORT__ // write ROIBlockHeader if (m_roi) { m_stream->Write(&count, &h.val); ASSERT(count == sizeof(UINT16)); } #endif // __PGFROISUPPORT__ #endif // PGF_USE_BIG_ENDIAN // write encoded data into stream count = wordLen*WordBytes; m_stream->Write(&count, block->m_codeBuffer); // store levelLength if (m_levelLength) { // store level length // EncodeBuffer has been called after m_lastLevelIndex has been updated ASSERT(m_currLevelIndex < m_nLevels); m_levelLength[m_currLevelIndex] += (UINT32)ComputeBufferLength(); m_currLevelIndex = block->m_lastLevelIndex + 1; } // prepare for next buffer SetBufferStartPos(); // reset values block->m_valuePos = 0; block->m_maxAbsValue = 0; } //////////////////////////////////////////////////////// // Encode buffer of given size using bit plane coding. // A buffer contains bufferLen UINT32 values, thus, bufferSize bits per bit plane. // Following coding scheme is used: // Buffer ::= (5 bits) foreach(plane i): Plane[i] // Plane[i] ::= [ Sig1 | Sig2 ] [DWORD alignment] refBits // Sig1 ::= 1 (15 bits) codedSigAndSignBits // Sig2 ::= 0 (15 bits) [Sign1 | Sign2 ] [DWORD alignment] sigBits // Sign1 ::= 1 (15 bits) codedSignBits // Sign2 ::= 0 (15 bits) [DWORD alignment] signBits void CEncoder::CMacroBlock::BitplaneEncode() { UINT8 nPlanes; UINT32 sigLen, codeLen = 0, wordPos, refLen, signLen; UINT32 sigBits[BufferLen] = { 0 }; UINT32 refBits[BufferLen] = { 0 }; UINT32 signBits[BufferLen] = { 0 }; UINT32 planeMask; UINT32 bufferSize = m_header.rbh.bufferSize; ASSERT(bufferSize <= BufferSize); bool useRL; #ifdef TRACE //printf("which thread: %d\n", omp_get_thread_num()); #endif // clear significance vector for (UINT32 k=0; k < bufferSize; k++) { m_sigFlagVector[k] = false; } m_sigFlagVector[bufferSize] = true; // sentinel // clear output buffer for (UINT32 k=0; k < bufferSize; k++) { m_codeBuffer[k] = 0; } m_codePos = 0; // compute number of bit planes and split buffer into separate bit planes nPlanes = NumberOfBitplanes(); // write number of bit planes to m_codeBuffer // SetValueBlock(m_codeBuffer, 0, nPlanes, MaxBitPlanesLog); m_codePos += MaxBitPlanesLog; // loop through all bit planes if (nPlanes == 0) nPlanes = MaxBitPlanes + 1; planeMask = 1 << (nPlanes - 1); for (int plane = nPlanes - 1; plane >= 0; plane--) { // clear significant bitset for (UINT32 k=0; k < BufferLen; k++) { sigBits[k] = 0; } // split bitplane in significant bitset and refinement bitset sigLen = DecomposeBitplane(bufferSize, planeMask, m_codePos + RLblockSizeLen + 1, sigBits, refBits, signBits, signLen, codeLen); if (sigLen > 0 && codeLen <= MaxCodeLen && codeLen < AlignWordPos(sigLen) + AlignWordPos(signLen) + 2*RLblockSizeLen) { // set RL code bit // <1> SetBit(m_codeBuffer, m_codePos++); // write length codeLen to m_codeBuffer SetValueBlock(m_codeBuffer, m_codePos, codeLen, RLblockSizeLen); m_codePos += RLblockSizeLen + codeLen; } else { #ifdef TRACE //printf("new\n"); //for (UINT32 i=0; i < bufferSize; i++) { // printf("%s", (GetBit(sigBits, i)) ? "1" : "_"); // if (i%120 == 119) printf("\n"); //} //printf("\n"); #endif // TRACE // run-length coding wasn't efficient enough // we don't use RL coding for sigBits // <0> ClearBit(m_codeBuffer, m_codePos++); // write length sigLen to m_codeBuffer ASSERT(sigLen <= MaxCodeLen); SetValueBlock(m_codeBuffer, m_codePos, sigLen, RLblockSizeLen); m_codePos += RLblockSizeLen; if (m_encoder->m_favorSpeed || signLen == 0) { useRL = false; } else { // overwrite m_codeBuffer useRL = true; // run-length encode m_sign and append them to the m_codeBuffer codeLen = RLESigns(m_codePos + RLblockSizeLen + 1, signBits, signLen); } if (useRL && codeLen <= MaxCodeLen && codeLen < signLen) { // RL encoding of m_sign was efficient // <1>_ // write RL code bit SetBit(m_codeBuffer, m_codePos++); // write codeLen to m_codeBuffer SetValueBlock(m_codeBuffer, m_codePos, codeLen, RLblockSizeLen); // compute position of sigBits wordPos = NumberOfWords(m_codePos + RLblockSizeLen + codeLen); ASSERT(0 <= wordPos && wordPos < CodeBufferLen); } else { // RL encoding of signBits wasn't efficient // <0>__ // clear RL code bit ClearBit(m_codeBuffer, m_codePos++); // write signLen to m_codeBuffer ASSERT(signLen <= MaxCodeLen); SetValueBlock(m_codeBuffer, m_codePos, signLen, RLblockSizeLen); // write signBits to m_codeBuffer wordPos = NumberOfWords(m_codePos + RLblockSizeLen); ASSERT(0 <= wordPos && wordPos < CodeBufferLen); codeLen = NumberOfWords(signLen); for (UINT32 k=0; k < codeLen; k++) { m_codeBuffer[wordPos++] = signBits[k]; } } // write sigBits // _ ASSERT(0 <= wordPos && wordPos < CodeBufferLen); refLen = NumberOfWords(sigLen); for (UINT32 k=0; k < refLen; k++) { m_codeBuffer[wordPos++] = sigBits[k]; } m_codePos = wordPos << WordWidthLog; } // append refinement bitset (aligned to word boundary) // _ wordPos = NumberOfWords(m_codePos); ASSERT(0 <= wordPos && wordPos < CodeBufferLen); refLen = NumberOfWords(bufferSize - sigLen); for (UINT32 k=0; k < refLen; k++) { m_codeBuffer[wordPos++] = refBits[k]; } m_codePos = wordPos << WordWidthLog; planeMask >>= 1; } ASSERT(0 <= m_codePos && m_codePos <= CodeBufferBitLen); } ////////////////////////////////////////////////////////// // Split bitplane of length bufferSize into significant and refinement bitset // returns length [bits] of significant bits // input: bufferSize, planeMask, codePos // output: sigBits, refBits, signBits, signLen [bits], codeLen [bits] // RLE // - Encode run of 2^k zeros by a single 0. // - Encode run of count 0's followed by a 1 with codeword: 1x // - x is 0: if a positive sign is stored, otherwise 1 // - Store each bit in m_codeBuffer[codePos] and increment codePos. UINT32 CEncoder::CMacroBlock::DecomposeBitplane(UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32* sigBits, UINT32* refBits, UINT32* signBits, UINT32& signLen, UINT32& codeLen) { ASSERT(sigBits); ASSERT(refBits); ASSERT(signBits); ASSERT(codePos < CodeBufferBitLen); UINT32 sigPos = 0; UINT32 valuePos = 0, valueEnd; UINT32 refPos = 0; // set output value signLen = 0; // prepare RLE of Sigs and Signs const UINT32 outStartPos = codePos; UINT32 k = 3; UINT32 runlen = 1 << k; // = 2^k UINT32 count = 0; while (valuePos < bufferSize) { // search next 1 in m_sigFlagVector using searching with sentinel valueEnd = valuePos; while(!m_sigFlagVector[valueEnd]) { valueEnd++; } // search 1's in m_value[plane][valuePos..valueEnd) // these 1's are significant bits while (valuePos < valueEnd) { if (GetBitAtPos(valuePos, planeMask)) { // RLE encoding // encode run of count 0's followed by a 1 // with codeword: 1(signBits[signPos]) SetBit(m_codeBuffer, codePos++); if (k > 0) { SetValueBlock(m_codeBuffer, codePos, count, k); codePos += k; // adapt k (half the zero run-length) k--; runlen >>= 1; } // copy and write sign bit if (m_value[valuePos] < 0) { SetBit(signBits, signLen++); SetBit(m_codeBuffer, codePos++); } else { ClearBit(signBits, signLen++); ClearBit(m_codeBuffer, codePos++); } // write a 1 to sigBits SetBit(sigBits, sigPos++); // update m_sigFlagVector m_sigFlagVector[valuePos] = true; // prepare for next run count = 0; } else { // RLE encoding count++; if (count == runlen) { // encode run of 2^k zeros by a single 0 ClearBit(m_codeBuffer, codePos++); // adapt k (double the zero run-length) if (k < WordWidth) { k++; runlen <<= 1; } // prepare for next run count = 0; } // write 0 to sigBits sigPos++; } valuePos++; } // refinement bit if (valuePos < bufferSize) { // write one refinement bit if (GetBitAtPos(valuePos++, planeMask)) { SetBit(refBits, refPos); } else { ClearBit(refBits, refPos); } refPos++; } } // RLE encoding of the rest of the plane // encode run of count 0's followed by a 1 // with codeword: 1(signBits[signPos]) SetBit(m_codeBuffer, codePos++); if (k > 0) { SetValueBlock(m_codeBuffer, codePos, count, k); codePos += k; } // write dmmy sign bit SetBit(m_codeBuffer, codePos++); // write word filler zeros ASSERT(sigPos <= bufferSize); ASSERT(refPos <= bufferSize); ASSERT(signLen <= bufferSize); ASSERT(valuePos == bufferSize); ASSERT(codePos >= outStartPos && codePos < CodeBufferBitLen); codeLen = codePos - outStartPos; return sigPos; } /////////////////////////////////////////////////////// // Compute number of bit planes needed UINT8 CEncoder::CMacroBlock::NumberOfBitplanes() { UINT8 cnt = 0; // determine number of bitplanes for max value if (m_maxAbsValue > 0) { while (m_maxAbsValue > 0) { m_maxAbsValue >>= 1; cnt++; } if (cnt == MaxBitPlanes + 1) cnt = 0; // end cs ASSERT(cnt <= MaxBitPlanes); ASSERT((cnt >> MaxBitPlanesLog) == 0); return cnt; } else { return 1; } } ////////////////////////////////////////////////////// // Adaptive Run-Length encoder for long sequences of ones. // Returns length of output in bits. // - Encode run of 2^k ones by a single 1. // - Encode run of count 1's followed by a 0 with codeword: 0. // - Store each bit in m_codeBuffer[codePos] and increment codePos. UINT32 CEncoder::CMacroBlock::RLESigns(UINT32 codePos, UINT32* signBits, UINT32 signLen) { ASSERT(signBits); ASSERT(0 <= codePos && codePos < CodeBufferBitLen); ASSERT(0 < signLen && signLen <= BufferSize); const UINT32 outStartPos = codePos; UINT32 k = 0; UINT32 runlen = 1 << k; // = 2^k UINT32 count = 0; UINT32 signPos = 0; while (signPos < signLen) { // search next 0 in signBits starting at position signPos count = SeekBit1Range(signBits, signPos, __min(runlen, signLen - signPos)); // count 1's found if (count == runlen) { // encode run of 2^k ones by a single 1 signPos += count; SetBit(m_codeBuffer, codePos++); // adapt k (double the 1's run-length) if (k < WordWidth) { k++; runlen <<= 1; } } else { // encode run of count 1's followed by a 0 // with codeword: 0(count) signPos += count + 1; ClearBit(m_codeBuffer, codePos++); if (k > 0) { SetValueBlock(m_codeBuffer, codePos, count, k); codePos += k; } // adapt k (half the 1's run-length) if (k > 0) { k--; runlen >>= 1; } } } ASSERT(signPos == signLen || signPos == signLen + 1); ASSERT(codePos >= outStartPos && codePos < CodeBufferBitLen); return codePos - outStartPos; } ////////////////////////////////////////////////////// #ifdef TRACE void CEncoder::DumpBuffer() const { //printf("\nDump\n"); //for (UINT32 i=0; i < BufferSize; i++) { // printf("%d", m_value[i]); //} //printf("\n"); } #endif //TRACE libpgf/src/Encoder.h100777 0 0 24111 12313025746 10001 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ * $Revision: 229 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Encoder.h /// @brief PGF encoder class /// @author C. Stamm, R. Spuler #ifndef PGF_ENCODER_H #define PGF_ENCODER_H #include "PGFstream.h" #include "BitStream.h" #include "Subband.h" #include "WaveletTransform.h" ///////////////////////////////////////////////////////////////////// // Constants #define BufferLen (BufferSize/WordWidth) ///< number of words per buffer #define CodeBufferLen BufferSize ///< number of words in code buffer (CodeBufferLen > BufferLen) ///////////////////////////////////////////////////////////////////// /// PGF encoder class. /// @author C. Stamm /// @brief PGF encoder class CEncoder { ////////////////////////////////////////////////////////////////////// /// PGF encoder macro block class. /// @author C. Stamm, I. Bauersachs /// @brief A macro block is an encoding unit of fixed size (uncoded) class CMacroBlock { public: ////////////////////////////////////////////////////////////////////// /// Constructor: Initializes new macro block. /// @param encoder Pointer to outer class. CMacroBlock(CEncoder *encoder) #pragma warning( suppress : 4351 ) : m_value() , m_codeBuffer() , m_header(0) , m_encoder(encoder) , m_sigFlagVector() { ASSERT(m_encoder); Init(-1); } ////////////////////////////////////////////////////////////////////// /// Reinitialzes this macro block (allows reusage). /// @param lastLevelIndex Level length directory index of last encoded level: [0, nLevels) void Init(int lastLevelIndex) { // initialize for reusage m_valuePos = 0; m_maxAbsValue = 0; m_codePos = 0; m_lastLevelIndex = lastLevelIndex; } ////////////////////////////////////////////////////////////////////// /// Encodes this macro block into internal code buffer. /// Several macro blocks can be encoded in parallel. /// Call CEncoder::WriteMacroBlock after this method. void BitplaneEncode(); DataT m_value[BufferSize]; ///< input buffer of values with index m_valuePos UINT32 m_codeBuffer[CodeBufferLen]; ///< output buffer for encoded bitstream ROIBlockHeader m_header; ///< block header UINT32 m_valuePos; ///< current buffer position UINT32 m_maxAbsValue; ///< maximum absolute coefficient in each buffer UINT32 m_codePos; ///< current position in encoded bitstream int m_lastLevelIndex; ///< index of last encoded level: [0, nLevels); used because a level-end can occur before a buffer is full private: UINT32 RLESigns(UINT32 codePos, UINT32* signBits, UINT32 signLen); UINT32 DecomposeBitplane(UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32* sigBits, UINT32* refBits, UINT32* signBits, UINT32& signLen, UINT32& codeLen); UINT8 NumberOfBitplanes(); bool GetBitAtPos(UINT32 pos, UINT32 planeMask) const { return (abs(m_value[pos]) & planeMask) > 0; } CEncoder *m_encoder; // encoder instance bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder }; public: ///////////////////////////////////////////////////////////////////// /// Write pre-header, header, post-Header, and levelLength. /// It might throw an IOException. /// @param stream A PGF stream /// @param preHeader A already filled in PGF pre-header /// @param header An already filled in PGF header /// @param postHeader [in] An already filled in PGF post-header (containing color table, user data, ...) /// @param userDataPos [out] File position of user data /// @param useOMP If true, then the encoder will use multi-threading based on openMP CEncoder(CPGFStream* stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader& postHeader, UINT64& userDataPos, bool useOMP) THROW_; // throws IOException ///////////////////////////////////////////////////////////////////// /// Destructor ~CEncoder(); ///////////////////////////////////////////////////////////////////// /// Encoder favors speed over compression size void FavorSpeedOverSize() { m_favorSpeed = true; } ///////////////////////////////////////////////////////////////////// /// Pad buffer with zeros and encode buffer. /// It might throw an IOException. void Flush() THROW_; ///////////////////////////////////////////////////////////////////// /// Increase post-header size and write new size into stream. /// @param preHeader An already filled in PGF pre-header /// It might throw an IOException. void UpdatePostHeaderSize(PGFPreHeader preHeader) THROW_; ///////////////////////////////////////////////////////////////////// /// Create level length data structure and write a place holder into stream. /// It might throw an IOException. /// @param levelLength A reference to an integer array, large enough to save the relative file positions of all PGF levels /// @return number of bytes written into stream UINT32 WriteLevelLength(UINT32*& levelLength) THROW_; ///////////////////////////////////////////////////////////////////// /// Write new levelLength into stream. /// It might throw an IOException. /// @return Written image bytes. UINT32 UpdateLevelLength() THROW_; ///////////////////////////////////////////////////////////////////// /// Partitions a rectangular region of a given subband. /// Partitioning scheme: The plane is partitioned in squares of side length LinBlockSize. /// Write wavelet coefficients from subband into the input buffer of a macro block. /// It might throw an IOException. /// @param band A subband /// @param width The width of the rectangle /// @param height The height of the rectangle /// @param startPos The absolute subband position of the top left corner of the rectangular region /// @param pitch The number of bytes in row of the subband void Partition(CSubband* band, int width, int height, int startPos, int pitch) THROW_; ///////////////////////////////////////////////////////////////////// /// Informs the encoder about the encoded level. /// @param currentLevel encoded level [0, nLevels) void SetEncodedLevel(int currentLevel) { ASSERT(currentLevel >= 0); m_currentBlock->m_lastLevelIndex = m_nLevels - currentLevel - 1; m_forceWriting = true; } ///////////////////////////////////////////////////////////////////// /// Write a single value into subband at given position. /// It might throw an IOException. /// @param band A subband /// @param bandPos A valid position in subband band void WriteValue(CSubband* band, int bandPos) THROW_; ///////////////////////////////////////////////////////////////////// /// Compute stream length of header. /// @return header length INT64 ComputeHeaderLength() const { return m_levelLengthPos - m_startPosition; } ///////////////////////////////////////////////////////////////////// /// Compute stream length of encoded buffer. /// @return encoded buffer length INT64 ComputeBufferLength() const { return m_stream->GetPos() - m_bufferStartPos; } ///////////////////////////////////////////////////////////////////// /// Compute file offset between real and expected levelLength position. /// @return file offset INT64 ComputeOffset() const { return m_stream->GetPos() - m_levelLengthPos; } ///////////////////////////////////////////////////////////////////// /// Save current stream position as beginning of current level. void SetBufferStartPos() { m_bufferStartPos = m_stream->GetPos(); } #ifdef __PGFROISUPPORT__ ///////////////////////////////////////////////////////////////////// /// Encodes tile buffer and writes it into stream /// It might throw an IOException. void EncodeTileBuffer() THROW_ { ASSERT(m_currentBlock && m_currentBlock->m_valuePos >= 0 && m_currentBlock->m_valuePos <= BufferSize); EncodeBuffer(ROIBlockHeader(m_currentBlock->m_valuePos, true)); } ///////////////////////////////////////////////////////////////////// /// Enables region of interest (ROI) status. void SetROI() { m_roi = true; } #endif #ifdef TRACE void DumpBuffer() const; #endif private: void EncodeBuffer(ROIBlockHeader h) THROW_; // throws IOException void WriteMacroBlock(CMacroBlock* block) THROW_; // throws IOException CPGFStream *m_stream; ///< output PMF stream UINT64 m_startPosition; ///< stream position of PGF start (PreHeader) UINT64 m_levelLengthPos; ///< stream position of Metadata UINT64 m_bufferStartPos; ///< stream position of encoded buffer CMacroBlock **m_macroBlocks; ///< array of macroblocks int m_macroBlockLen; ///< array length int m_lastMacroBlock; ///< array index of the last created macro block CMacroBlock *m_currentBlock; ///< current macro block (used by main thread) UINT32* m_levelLength; ///< temporary saves the level index int m_currLevelIndex; ///< counts where (=index) to save next value UINT8 m_nLevels; ///< number of levels bool m_favorSpeed; ///< favor speed over size bool m_forceWriting; ///< all macro blocks have to be written into the stream #ifdef __PGFROISUPPORT__ bool m_roi; ///< true: ensures region of interest (ROI) encoding #endif }; #endif //PGF_ENCODER libpgf/src/Makefile.am100777 0 0 411 12232452341 10235 0INCLUDES = -I$(top_srcdir)/include # @PGFCODEC_CFLAGS@ lib_LTLIBRARIES = libpgf.la libpgf_la_LDFLAGS = -version-info @INTERFACE_VERSION@ libpgf_la_SOURCES = \ Decoder.cpp \ Encoder.cpp \ PGFimage.cpp \ PGFstream.cpp \ Subband.cpp \ WaveletTransform.cpp libpgf/src/PGFimage.cpp100777 0 0 252317 12313025746 10427 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2007-02-03 13:04:21 +0100 (Sa, 03 Feb 2007) $ * $Revision: 280 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file PGFimage.cpp /// @brief PGF image class implementation /// @author C. Stamm #include "PGFimage.h" #include "Decoder.h" #include "Encoder.h" #include #include #define YUVoffset4 8 // 2^3 #define YUVoffset6 32 // 2^5 #define YUVoffset8 128 // 2^7 #define YUVoffset16 32768 // 2^15 //#define YUVoffset31 1073741824 // 2^30 ////////////////////////////////////////////////////////////////////// // global methods and variables #ifdef NEXCEPTIONS OSError _PGF_Error_; OSError GetLastPGFError() { OSError tmp = _PGF_Error_; _PGF_Error_ = NoError; return tmp; } #endif ////////////////////////////////////////////////////////////////////// // Standard constructor: It is used to create a PGF instance for opening and reading. CPGFImage::CPGFImage() : m_decoder(0) , m_encoder(0) , m_levelLength(0) , m_currentLevel(0) , m_quant(0) , m_userDataPos(0) , m_downsample(false) , m_favorSpeedOverSize(false) , m_useOMPinEncoder(true) , m_useOMPinDecoder(true) , m_skipUserData(false) #ifdef __PGFROISUPPORT__ , m_streamReinitialized(false) #endif , m_cb(0) , m_cbArg(0) , m_progressMode(PM_Relative) , m_percent(0) { // init preHeader memcpy(m_preHeader.magic, PGFMagic, 3); m_preHeader.version = PGFVersion; m_preHeader.hSize = 0; // init postHeader m_postHeader.userData = 0; m_postHeader.userDataLen = 0; // init channels for (int i=0; i < MaxChannels; i++) { m_channel[i] = 0; m_wtChannel[i] = 0; } // set image width and height m_width[0] = 0; m_height[0] = 0; } ////////////////////////////////////////////////////////////////////// // Destructor: Destroy internal data structures. CPGFImage::~CPGFImage() { Destroy(); } ////////////////////////////////////////////////////////////////////// // Destroy internal data structures. // Destructor calls this method during destruction. void CPGFImage::Destroy() { Close(); for (int i=0; i < m_header.channels; i++) { delete m_wtChannel[i]; m_wtChannel[i]=0; // also deletes m_channel m_channel[i] = 0; } delete[] m_postHeader.userData; m_postHeader.userData = 0; m_postHeader.userDataLen = 0; delete[] m_levelLength; m_levelLength = 0; delete m_encoder; m_encoder = NULL; m_userDataPos = 0; } ////////////////////////////////////////////////////////////////////// // Close PGF image after opening and reading. // Destructor calls this method during destruction. void CPGFImage::Close() { delete m_decoder; m_decoder = 0; } ///////////////////////////////////////////////////////////////////////////// // Open a PGF image at current stream position: read pre-header, header, levelLength, and ckeck image type. // Precondition: The stream has been opened for reading. // It might throw an IOException. // @param stream A PGF stream void CPGFImage::Open(CPGFStream *stream) THROW_ { ASSERT(stream); // create decoder and read PGFPreHeader PGFHeader PGFPostHeader LevelLengths m_decoder = new CDecoder(stream, m_preHeader, m_header, m_postHeader, m_levelLength, m_userDataPos, m_useOMPinDecoder, m_skipUserData); if (m_header.nLevels > MaxLevel) ReturnWithError(FormatCannotRead); // set current level m_currentLevel = m_header.nLevels; // set image width and height m_width[0] = m_header.width; m_height[0] = m_header.height; // complete header CompleteHeader(); // interpret quant parameter if (m_header.quality > DownsampleThreshold && (m_header.mode == ImageModeRGBColor || m_header.mode == ImageModeRGBA || m_header.mode == ImageModeRGB48 || m_header.mode == ImageModeCMYKColor || m_header.mode == ImageModeCMYK64 || m_header.mode == ImageModeLabColor || m_header.mode == ImageModeLab48)) { m_downsample = true; m_quant = m_header.quality - 1; } else { m_downsample = false; m_quant = m_header.quality; } // set channel dimensions (chrominance is subsampled by factor 2) if (m_downsample) { for (int i=1; i < m_header.channels; i++) { m_width[i] = (m_width[0] + 1)/2; m_height[i] = (m_height[0] + 1)/2; } } else { for (int i=1; i < m_header.channels; i++) { m_width[i] = m_width[0]; m_height[i] = m_height[0]; } } if (m_header.nLevels > 0) { // init wavelet subbands for (int i=0; i < m_header.channels; i++) { m_wtChannel[i] = new CWaveletTransform(m_width[i], m_height[i], m_header.nLevels); } // used in Read when PM_Absolute m_percent = pow(0.25, m_header.nLevels); } else { // very small image: we don't use DWT and encoding // read channels for (int c=0; c < m_header.channels; c++) { const UINT32 size = m_width[c]*m_height[c]; m_channel[c] = new(std::nothrow) DataT[size]; if (!m_channel[c]) ReturnWithError(InsufficientMemory); // read channel data from stream for (UINT32 i=0; i < size; i++) { int count = DataTSize; stream->Read(&count, &m_channel[c][i]); if (count != DataTSize) ReturnWithError(MissingData); } } } } //////////////////////////////////////////////////////////// void CPGFImage::CompleteHeader() { if (m_header.mode == ImageModeUnknown) { // undefined mode switch(m_header.bpp) { case 1: m_header.mode = ImageModeBitmap; break; case 8: m_header.mode = ImageModeGrayScale; break; case 12: m_header.mode = ImageModeRGB12; break; case 16: m_header.mode = ImageModeRGB16; break; case 24: m_header.mode = ImageModeRGBColor; break; case 32: m_header.mode = ImageModeRGBA; break; case 48: m_header.mode = ImageModeRGB48; break; default: m_header.mode = ImageModeRGBColor; break; } } if (!m_header.bpp) { // undefined bpp switch(m_header.mode) { case ImageModeBitmap: m_header.bpp = 1; break; case ImageModeIndexedColor: case ImageModeGrayScale: m_header.bpp = 8; break; case ImageModeRGB12: m_header.bpp = 12; break; case ImageModeRGB16: case ImageModeGray16: m_header.bpp = 16; break; case ImageModeRGBColor: case ImageModeLabColor: m_header.bpp = 24; break; case ImageModeRGBA: case ImageModeCMYKColor: case ImageModeGray32: m_header.bpp = 32; break; case ImageModeRGB48: case ImageModeLab48: m_header.bpp = 48; break; case ImageModeCMYK64: m_header.bpp = 64; break; default: ASSERT(false); m_header.bpp = 24; } } if (m_header.mode == ImageModeRGBColor && m_header.bpp == 32) { // change mode m_header.mode = ImageModeRGBA; } ASSERT(m_header.mode != ImageModeBitmap || m_header.bpp == 1); ASSERT(m_header.mode != ImageModeIndexedColor || m_header.bpp == 8); ASSERT(m_header.mode != ImageModeGrayScale || m_header.bpp == 8); ASSERT(m_header.mode != ImageModeGray16 || m_header.bpp == 16); ASSERT(m_header.mode != ImageModeGray32 || m_header.bpp == 32); ASSERT(m_header.mode != ImageModeRGBColor || m_header.bpp == 24); ASSERT(m_header.mode != ImageModeRGBA || m_header.bpp == 32); ASSERT(m_header.mode != ImageModeRGB12 || m_header.bpp == 12); ASSERT(m_header.mode != ImageModeRGB16 || m_header.bpp == 16); ASSERT(m_header.mode != ImageModeRGB48 || m_header.bpp == 48); ASSERT(m_header.mode != ImageModeLabColor || m_header.bpp == 24); ASSERT(m_header.mode != ImageModeLab48 || m_header.bpp == 48); ASSERT(m_header.mode != ImageModeCMYKColor || m_header.bpp == 32); ASSERT(m_header.mode != ImageModeCMYK64 || m_header.bpp == 64); // set number of channels if (!m_header.channels) { switch(m_header.mode) { case ImageModeBitmap: case ImageModeIndexedColor: case ImageModeGrayScale: case ImageModeGray16: case ImageModeGray32: m_header.channels = 1; break; case ImageModeRGBColor: case ImageModeRGB12: case ImageModeRGB16: case ImageModeRGB48: case ImageModeLabColor: case ImageModeLab48: m_header.channels = 3; break; case ImageModeRGBA: case ImageModeCMYKColor: case ImageModeCMYK64: m_header.channels = 4; break; default: ASSERT(false); m_header.channels = 3; } } // store used bits per channel UINT8 bpc = m_header.bpp/m_header.channels; if (bpc > 31) bpc = 31; if (!m_header.usedBitsPerChannel || m_header.usedBitsPerChannel > bpc) { m_header.usedBitsPerChannel = bpc; } } ////////////////////////////////////////////////////////////////////// /// Return user data and size of user data. /// Precondition: The PGF image has been opened with a call of Open(...). /// @param size [out] Size of user data in bytes. /// @return A pointer to user data or NULL if there is no user data. const UINT8* CPGFImage::GetUserData(UINT32& size) const { size = m_postHeader.userDataLen; return m_postHeader.userData; } ////////////////////////////////////////////////////////////////////// /// After you've written a PGF image, you can call this method followed by GetBitmap/GetYUV /// to get a quick reconstruction (coded -> decoded image). /// It might throw an IOException. /// @param level The image level of the resulting image in the internal image buffer. void CPGFImage::Reconstruct(int level /*= 0*/) THROW_ { if (m_header.nLevels == 0) { // image didn't use wavelet transform if (level == 0) { for (int i=0; i < m_header.channels; i++) { ASSERT(m_wtChannel[i]); m_channel[i] = m_wtChannel[i]->GetSubband(0, LL)->GetBuffer(); } } } else { int currentLevel = m_header.nLevels; if (ROIisSupported()) { // enable ROI reading SetROI(PGFRect(0, 0, m_header.width, m_header.height)); } while (currentLevel > level) { for (int i=0; i < m_header.channels; i++) { ASSERT(m_wtChannel[i]); // dequantize subbands if (currentLevel == m_header.nLevels) { // last level also has LL band m_wtChannel[i]->GetSubband(currentLevel, LL)->Dequantize(m_quant); } m_wtChannel[i]->GetSubband(currentLevel, HL)->Dequantize(m_quant); m_wtChannel[i]->GetSubband(currentLevel, LH)->Dequantize(m_quant); m_wtChannel[i]->GetSubband(currentLevel, HH)->Dequantize(m_quant); // inverse transform from m_wtChannel to m_channel OSError err = m_wtChannel[i]->InverseTransform(currentLevel, &m_width[i], &m_height[i], &m_channel[i]); if (err != NoError) ReturnWithError(err); ASSERT(m_channel[i]); } currentLevel--; } } } ////////////////////////////////////////////////////////////////////// // Read and decode some levels of a PGF image at current stream position. // A PGF image is structered in levels, numbered between 0 and Levels() - 1. // Each level can be seen as a single image, containing the same content // as all other levels, but in a different size (width, height). // The image size at level i is double the size (width, height) of the image at level i+1. // The image at level 0 contains the original size. // Precondition: The PGF image has been opened with a call of Open(...). // It might throw an IOException. // @param level The image level of the resulting image in the internal image buffer. // @param cb A pointer to a callback procedure. The procedure is called after reading a single level. If cb returns true, then it stops proceeding. // @param data Data Pointer to C++ class container to host callback procedure. void CPGFImage::Read(int level /*= 0*/, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) THROW_ { ASSERT((level >= 0 && level < m_header.nLevels) || m_header.nLevels == 0); // m_header.nLevels == 0: image didn't use wavelet transform ASSERT(m_decoder); #ifdef __PGFROISUPPORT__ if (ROIisSupported() && m_header.nLevels > 0) { // new encoding scheme supporting ROI PGFRect rect(0, 0, m_header.width, m_header.height); Read(rect, level, cb, data); return; } #endif if (m_header.nLevels == 0) { if (level == 0) { // the data has already been read during open // now update progress if (cb) { if ((*cb)(1.0, true, data)) ReturnWithError(EscapePressed); } } } else { const int levelDiff = m_currentLevel - level; double percent = (m_progressMode == PM_Relative) ? pow(0.25, levelDiff) : m_percent; // encoding scheme without ROI while (m_currentLevel > level) { for (int i=0; i < m_header.channels; i++) { ASSERT(m_wtChannel[i]); // decode file and write stream to m_wtChannel if (m_currentLevel == m_header.nLevels) { // last level also has LL band m_wtChannel[i]->GetSubband(m_currentLevel, LL)->PlaceTile(*m_decoder, m_quant); } if (m_preHeader.version & Version5) { // since version 5 m_wtChannel[i]->GetSubband(m_currentLevel, HL)->PlaceTile(*m_decoder, m_quant); m_wtChannel[i]->GetSubband(m_currentLevel, LH)->PlaceTile(*m_decoder, m_quant); } else { // until version 4 m_decoder->DecodeInterleaved(m_wtChannel[i], m_currentLevel, m_quant); } m_wtChannel[i]->GetSubband(m_currentLevel, HH)->PlaceTile(*m_decoder, m_quant); } volatile OSError error = NoError; // volatile prevents optimizations #ifdef LIBPGF_USE_OPENMP #pragma omp parallel for default(shared) #endif for (int i=0; i < m_header.channels; i++) { // inverse transform from m_wtChannel to m_channel if (error == NoError) { OSError err = m_wtChannel[i]->InverseTransform(m_currentLevel, &m_width[i], &m_height[i], &m_channel[i]); if (err != NoError) error = err; } ASSERT(m_channel[i]); } if (error != NoError) ReturnWithError(error); // set new level: must be done before refresh callback m_currentLevel--; // now we have to refresh the display if (m_cb) m_cb(m_cbArg); // now update progress if (cb) { percent *= 4; if (m_progressMode == PM_Absolute) m_percent = percent; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } // automatically closing if (m_currentLevel == 0) Close(); } #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// Read a rectangular region of interest of a PGF image at current stream position. /// The origin of the coordinate axis is the top-left corner of the image. /// All coordinates are measured in pixels. /// It might throw an IOException. /// @param rect [inout] Rectangular region of interest (ROI). The rect might be cropped. /// @param level The image level of the resulting image in the internal image buffer. /// @param cb A pointer to a callback procedure. The procedure is called after reading a single level. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void CPGFImage::Read(PGFRect& rect, int level /*= 0*/, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) THROW_ { ASSERT((level >= 0 && level < m_header.nLevels) || m_header.nLevels == 0); // m_header.nLevels == 0: image didn't use wavelet transform ASSERT(m_decoder); if (m_header.nLevels == 0 || !ROIisSupported()) { rect.left = rect.top = 0; rect.right = m_header.width; rect.bottom = m_header.height; Read(level, cb, data); } else { ASSERT(ROIisSupported()); // new encoding scheme supporting ROI ASSERT(rect.left < m_header.width && rect.top < m_header.height); const int levelDiff = m_currentLevel - level; double percent = (m_progressMode == PM_Relative) ? pow(0.25, levelDiff) : m_percent; // check level difference if (levelDiff <= 0) { // it is a new read call, probably with a new ROI m_currentLevel = m_header.nLevels; m_decoder->SetStreamPosToData(); } // check rectangle if (rect.right == 0 || rect.right > m_header.width) rect.right = m_header.width; if (rect.bottom == 0 || rect.bottom > m_header.height) rect.bottom = m_header.height; // enable ROI decoding and reading SetROI(rect); while (m_currentLevel > level) { for (int i=0; i < m_header.channels; i++) { ASSERT(m_wtChannel[i]); // get number of tiles and tile indices const UINT32 nTiles = m_wtChannel[i]->GetNofTiles(m_currentLevel); const PGFRect& tileIndices = m_wtChannel[i]->GetTileIndices(m_currentLevel); // decode file and write stream to m_wtChannel if (m_currentLevel == m_header.nLevels) { // last level also has LL band ASSERT(nTiles == 1); m_decoder->DecodeTileBuffer(); m_wtChannel[i]->GetSubband(m_currentLevel, LL)->PlaceTile(*m_decoder, m_quant); } for (UINT32 tileY=0; tileY < nTiles; tileY++) { for (UINT32 tileX=0; tileX < nTiles; tileX++) { // check relevance of tile if (tileIndices.IsInside(tileX, tileY)) { m_decoder->DecodeTileBuffer(); m_wtChannel[i]->GetSubband(m_currentLevel, HL)->PlaceTile(*m_decoder, m_quant, true, tileX, tileY); m_wtChannel[i]->GetSubband(m_currentLevel, LH)->PlaceTile(*m_decoder, m_quant, true, tileX, tileY); m_wtChannel[i]->GetSubband(m_currentLevel, HH)->PlaceTile(*m_decoder, m_quant, true, tileX, tileY); } else { // skip tile m_decoder->SkipTileBuffer(); } } } } volatile OSError error = NoError; // volatile prevents optimizations #ifdef LIBPGF_USE_OPENMP #pragma omp parallel for default(shared) #endif for (int i=0; i < m_header.channels; i++) { // inverse transform from m_wtChannel to m_channel if (error == NoError) { OSError err = m_wtChannel[i]->InverseTransform(m_currentLevel, &m_width[i], &m_height[i], &m_channel[i]); if (err != NoError) error = err; } ASSERT(m_channel[i]); } if (error != NoError) ReturnWithError(error); // set new level: must be done before refresh callback m_currentLevel--; // now we have to refresh the display if (m_cb) m_cb(m_cbArg); // now update progress if (cb) { percent *= 4; if (m_progressMode == PM_Absolute) m_percent = percent; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } // automatically closing if (m_currentLevel == 0) Close(); } ////////////////////////////////////////////////////////////////////// /// Compute ROIs for each channel and each level /// @param rect rectangular region of interest (ROI) void CPGFImage::SetROI(PGFRect rect) { ASSERT(m_decoder); ASSERT(ROIisSupported()); // store ROI for a later call of GetBitmap m_roi = rect; // enable ROI decoding m_decoder->SetROI(); // enlarge ROI because of border artefacts const UINT32 dx = FilterWidth/2*(1 << m_currentLevel); const UINT32 dy = FilterHeight/2*(1 << m_currentLevel); if (rect.left < dx) rect.left = 0; else rect.left -= dx; if (rect.top < dy) rect.top = 0; else rect.top -= dy; rect.right += dx; if (rect.right > m_header.width) rect.right = m_header.width; rect.bottom += dy; if (rect.bottom > m_header.height) rect.bottom = m_header.height; // prepare wavelet channels for using ROI ASSERT(m_wtChannel[0]); m_wtChannel[0]->SetROI(rect); if (m_downsample && m_header.channels > 1) { // all further channels are downsampled, therefore downsample ROI rect.left >>= 1; rect.top >>= 1; rect.right >>= 1; rect.bottom >>= 1; } for (int i=1; i < m_header.channels; i++) { ASSERT(m_wtChannel[i]); m_wtChannel[i]->SetROI(rect); } } #endif // __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// Return the length of all encoded headers in bytes. /// Precondition: The PGF image has been opened with a call of Open(...). /// @return The length of all encoded headers in bytes UINT32 CPGFImage::GetEncodedHeaderLength() const { ASSERT(m_decoder); return m_decoder->GetEncodedHeaderLength(); } ////////////////////////////////////////////////////////////////////// /// Reads the encoded PGF headers and copies it to a target buffer. /// Precondition: The PGF image has been opened with a call of Open(...). /// It might throw an IOException. /// @param target The target buffer /// @param targetLen The length of the target buffer in bytes /// @return The number of bytes copied to the target buffer UINT32 CPGFImage::ReadEncodedHeader(UINT8* target, UINT32 targetLen) const THROW_ { ASSERT(target); ASSERT(targetLen > 0); ASSERT(m_decoder); // reset stream position m_decoder->SetStreamPosToStart(); // compute number of bytes to read UINT32 len = __min(targetLen, GetEncodedHeaderLength()); // read data len = m_decoder->ReadEncodedData(target, len); ASSERT(len >= 0 && len <= targetLen); return len; } //////////////////////////////////////////////////////////////////// /// Reset stream position to start of PGF pre-header void CPGFImage::ResetStreamPos() THROW_ { ASSERT(m_decoder); return m_decoder->SetStreamPosToStart(); } ////////////////////////////////////////////////////////////////////// /// Reads the data of an encoded PGF level and copies it to a target buffer /// without decoding. /// Precondition: The PGF image has been opened with a call of Open(...). /// It might throw an IOException. /// @param level The image level /// @param target The target buffer /// @param targetLen The length of the target buffer in bytes /// @return The number of bytes copied to the target buffer UINT32 CPGFImage::ReadEncodedData(int level, UINT8* target, UINT32 targetLen) const THROW_ { ASSERT(level >= 0 && level < m_header.nLevels); ASSERT(target); ASSERT(targetLen > 0); ASSERT(m_decoder); // reset stream position m_decoder->SetStreamPosToData(); // position stream UINT64 offset = 0; for (int i=m_header.nLevels - 1; i > level; i--) { offset += m_levelLength[m_header.nLevels - 1 - i]; } m_decoder->Skip(offset); // compute number of bytes to read UINT32 len = __min(targetLen, GetEncodedLevelLength(level)); // read data len = m_decoder->ReadEncodedData(target, len); ASSERT(len >= 0 && len <= targetLen); return len; } ////////////////////////////////////////////////////////////////////// /// Set maximum intensity value for image modes with more than eight bits per channel. /// Call this method after SetHeader, but before ImportBitmap. /// @param maxValue The maximum intensity value. void CPGFImage::SetMaxValue(UINT32 maxValue) { const BYTE bpc = m_header.bpp/m_header.channels; BYTE pot = 0; while(maxValue > 0) { pot++; maxValue >>= 1; } // store bits per channel if (pot > bpc) pot = bpc; if (pot > 31) pot = 31; m_header.usedBitsPerChannel = pot; } ////////////////////////////////////////////////////////////////////// /// Returns number of used bits per input/output image channel. /// Precondition: header must be initialized. /// @return number of used bits per input/output image channel. BYTE CPGFImage::UsedBitsPerChannel() const { const BYTE bpc = m_header.bpp/m_header.channels; if (bpc > 8) { return m_header.usedBitsPerChannel; } else { return bpc; } } ////////////////////////////////////////////////////////////////////// /// Return version BYTE CPGFImage::CurrentVersion(BYTE version) { if (version & Version6) return 6; if (version & Version5) return 5; if (version & Version2) return 2; return 1; } ////////////////////////////////////////////////////////////////// // Import an image from a specified image buffer. // This method is usually called before Write(...) and after SetHeader(...). // It might throw an IOException. // The absolute value of pitch is the number of bytes of an image row. // If pitch is negative, then buff points to the last row of a bottom-up image (first byte on last row). // If pitch is positive, then buff points to the first row of a top-down image (first byte). // The sequence of input channels in the input image buffer does not need to be the same as expected from PGF. In case of different sequences you have to // provide a channelMap of size of expected channels (depending on image mode). For example, PGF expects in RGB color mode a channel sequence BGR. // If your provided image buffer contains a channel sequence ARGB, then the channelMap looks like { 3, 2, 1 }. // @param pitch The number of bytes of a row of the image buffer. // @param buff An image buffer. // @param bpp The number of bits per pixel used in image buffer. // @param channelMap A integer array containing the mapping of input channel ordering to expected channel ordering. // @param cb A pointer to a callback procedure. The procedure is called after each imported buffer row. If cb returns true, then it stops proceeding. // @param data Data Pointer to C++ class container to host callback procedure. void CPGFImage::ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[] /*= NULL */, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) THROW_ { ASSERT(buff); ASSERT(m_channel[0]); // color transform RgbToYuv(pitch, buff, bpp, channelMap, cb, data); if (m_downsample) { // Subsampling of the chrominance and alpha channels for (int i=1; i < m_header.channels; i++) { Downsample(i); } } } ///////////////////////////////////////////////////////////////// // Bilinerar Subsampling of channel ch by a factor 2 void CPGFImage::Downsample(int ch) { ASSERT(ch > 0); const int w = m_width[0]; const int w2 = w/2; const int h2 = m_height[0]/2; const int oddW = w%2; // don't use bool -> problems with MaxSpeed optimization const int oddH = m_height[0]%2; // " int loPos = 0; int hiPos = w; int sampledPos = 0; DataT* buff = m_channel[ch]; ASSERT(buff); for (int i=0; i < h2; i++) { for (int j=0; j < w2; j++) { // compute average of pixel block buff[sampledPos] = (buff[loPos] + buff[loPos + 1] + buff[hiPos] + buff[hiPos + 1]) >> 2; loPos += 2; hiPos += 2; sampledPos++; } if (oddW) { buff[sampledPos] = (buff[loPos] + buff[hiPos]) >> 1; loPos++; hiPos++; sampledPos++; } loPos += w; hiPos += w; } if (oddH) { for (int j=0; j < w2; j++) { buff[sampledPos] = (buff[loPos] + buff[loPos+1]) >> 1; loPos += 2; hiPos += 2; sampledPos++; } if (oddW) { buff[sampledPos] = buff[loPos]; } } // downsampled image has half width and half height m_width[ch] = (m_width[ch] + 1)/2; m_height[ch] = (m_height[ch] + 1)/2; } ////////////////////////////////////////////////////////////////////// void CPGFImage::ComputeLevels() { const int maxThumbnailWidth = 20*FilterWidth; const int m = __min(m_header.width, m_header.height); int s = m; if (m_header.nLevels < 1 || m_header.nLevels > MaxLevel) { m_header.nLevels = 1; // compute a good value depending on the size of the image while (s > maxThumbnailWidth) { m_header.nLevels++; s = s/2; } } int levels = m_header.nLevels; // we need a signed value during level reduction // reduce number of levels if the image size is smaller than FilterWidth*2^levels s = FilterWidth*(1 << levels); // must be at least the double filter size because of subsampling while (m < s) { levels--; s = s/2; } if (levels > MaxLevel) m_header.nLevels = MaxLevel; else if (levels < 0) m_header.nLevels = 0; else m_header.nLevels = (UINT8)levels; // used in Write when PM_Absolute m_percent = pow(0.25, m_header.nLevels); ASSERT(0 <= m_header.nLevels && m_header.nLevels <= MaxLevel); } ////////////////////////////////////////////////////////////////////// /// Set PGF header and user data. /// Precondition: The PGF image has been closed with Close(...) or never opened with Open(...). /// It might throw an IOException. /// @param header A valid and already filled in PGF header structure /// @param flags A combination of additional version flags. In case you use level-wise encoding then set flag = PGFROI. /// @param userData A user-defined memory block containing any kind of cached metadata. /// @param userDataLength The size of user-defined memory block in bytes void CPGFImage::SetHeader(const PGFHeader& header, BYTE flags /*=0*/, UINT8* userData /*= 0*/, UINT32 userDataLength /*= 0*/) THROW_ { ASSERT(!m_decoder); // current image must be closed ASSERT(header.quality <= MaxQuality); // init state #ifdef __PGFROISUPPORT__ m_streamReinitialized = false; #endif // init preHeader memcpy(m_preHeader.magic, PGFMagic, 3); m_preHeader.version = PGFVersion | flags; m_preHeader.hSize = HeaderSize; // copy header memcpy(&m_header, &header, HeaderSize); // complete header CompleteHeader(); // check and set number of levels ComputeLevels(); // check for downsample if (m_header.quality > DownsampleThreshold && (m_header.mode == ImageModeRGBColor || m_header.mode == ImageModeRGBA || m_header.mode == ImageModeRGB48 || m_header.mode == ImageModeCMYKColor || m_header.mode == ImageModeCMYK64 || m_header.mode == ImageModeLabColor || m_header.mode == ImageModeLab48)) { m_downsample = true; m_quant = m_header.quality - 1; } else { m_downsample = false; m_quant = m_header.quality; } // update header size and copy user data if (m_header.mode == ImageModeIndexedColor) { // update header size m_preHeader.hSize += ColorTableSize; } if (userDataLength && userData) { m_postHeader.userData = new(std::nothrow) UINT8[userDataLength]; if (!m_postHeader.userData) ReturnWithError(InsufficientMemory); m_postHeader.userDataLen = userDataLength; memcpy(m_postHeader.userData, userData, userDataLength); // update header size m_preHeader.hSize += userDataLength; } // allocate channels for (int i=0; i < m_header.channels; i++) { // set current width and height m_width[i] = m_header.width; m_height[i] = m_header.height; // allocate channels ASSERT(!m_channel[i]); m_channel[i] = new(std::nothrow) DataT[m_header.width*m_header.height]; if (!m_channel[i]) { if (i) i--; while(i) { delete[] m_channel[i]; m_channel[i] = 0; i--; } ReturnWithError(InsufficientMemory); } } } ////////////////////////////////////////////////////////////////// /// Create wavelet transform channels and encoder. Write header at current stream position. /// Call this method before your first call of Write(int level) or WriteImage(), but after SetHeader(). /// This method is called inside of Write(stream, ...). /// It might throw an IOException. /// @param stream A PGF stream /// @return The number of bytes written into stream. UINT32 CPGFImage::WriteHeader(CPGFStream* stream) THROW_ { ASSERT(m_header.nLevels <= MaxLevel); ASSERT(m_header.quality <= MaxQuality); // quality is already initialized if (m_header.nLevels > 0) { volatile OSError error = NoError; // volatile prevents optimizations // create new wt channels #ifdef LIBPGF_USE_OPENMP #pragma omp parallel for default(shared) #endif for (int i=0; i < m_header.channels; i++) { DataT *temp = NULL; if (error == NoError) { if (m_wtChannel[i]) { ASSERT(m_channel[i]); // copy m_channel to temp int size = m_height[i]*m_width[i]; temp = new(std::nothrow) DataT[size]; if (temp) { memcpy(temp, m_channel[i], size*DataTSize); delete m_wtChannel[i]; // also deletes m_channel m_channel[i] = NULL; } else { error = InsufficientMemory; } } if (error == NoError) { if (temp) { ASSERT(!m_channel[i]); m_channel[i] = temp; } m_wtChannel[i] = new CWaveletTransform(m_width[i], m_height[i], m_header.nLevels, m_channel[i]); if (m_wtChannel[i]) { #ifdef __PGFROISUPPORT__ m_wtChannel[i]->SetROI(PGFRect(0, 0, m_width[i], m_height[i])); #endif // wavelet subband decomposition for (int l=0; error == NoError && l < m_header.nLevels; l++) { OSError err = m_wtChannel[i]->ForwardTransform(l, m_quant); if (err != NoError) error = err; } } else { delete[] m_channel[i]; error = InsufficientMemory; } } } } if (error != NoError) { // free already allocated memory for (int i=0; i < m_header.channels; i++) { delete m_wtChannel[i]; } ReturnWithError(error); } m_currentLevel = m_header.nLevels; // create encoder and eventually write headers and levelLength m_encoder = new CEncoder(stream, m_preHeader, m_header, m_postHeader, m_userDataPos, m_useOMPinEncoder); if (m_favorSpeedOverSize) m_encoder->FavorSpeedOverSize(); #ifdef __PGFROISUPPORT__ if (ROIisSupported()) { // new encoding scheme supporting ROI m_encoder->SetROI(); } #endif } else { // very small image: we don't use DWT and encoding // create encoder and eventually write headers and levelLength m_encoder = new CEncoder(stream, m_preHeader, m_header, m_postHeader, m_userDataPos, m_useOMPinEncoder); } INT64 nBytes = m_encoder->ComputeHeaderLength(); return (nBytes > 0) ? (UINT32)nBytes : 0; } ////////////////////////////////////////////////////////////////// // Encode and write next level of a PGF image at current stream position. // A PGF image is structered in levels, numbered between 0 and Levels() - 1. // Each level can be seen as a single image, containing the same content // as all other levels, but in a different size (width, height). // The image size at level i is double the size (width, height) of the image at level i+1. // The image at level 0 contains the original size. // It might throw an IOException. void CPGFImage::WriteLevel() THROW_ { ASSERT(m_encoder); ASSERT(m_currentLevel > 0); ASSERT(m_header.nLevels > 0); #ifdef __PGFROISUPPORT__ if (ROIisSupported()) { const int lastChannel = m_header.channels - 1; for (int i=0; i < m_header.channels; i++) { // get number of tiles and tile indices const UINT32 nTiles = m_wtChannel[i]->GetNofTiles(m_currentLevel); const UINT32 lastTile = nTiles - 1; if (m_currentLevel == m_header.nLevels) { // last level also has LL band ASSERT(nTiles == 1); m_wtChannel[i]->GetSubband(m_currentLevel, LL)->ExtractTile(*m_encoder); m_encoder->EncodeTileBuffer(); } for (UINT32 tileY=0; tileY < nTiles; tileY++) { for (UINT32 tileX=0; tileX < nTiles; tileX++) { m_wtChannel[i]->GetSubband(m_currentLevel, HL)->ExtractTile(*m_encoder, true, tileX, tileY); m_wtChannel[i]->GetSubband(m_currentLevel, LH)->ExtractTile(*m_encoder, true, tileX, tileY); m_wtChannel[i]->GetSubband(m_currentLevel, HH)->ExtractTile(*m_encoder, true, tileX, tileY); if (i == lastChannel && tileY == lastTile && tileX == lastTile) { // all necessary data are buffered. next call of EncodeBuffer will write the last piece of data of the current level. m_encoder->SetEncodedLevel(--m_currentLevel); } m_encoder->EncodeTileBuffer(); } } } } else #endif { for (int i=0; i < m_header.channels; i++) { ASSERT(m_wtChannel[i]); if (m_currentLevel == m_header.nLevels) { // last level also has LL band m_wtChannel[i]->GetSubband(m_currentLevel, LL)->ExtractTile(*m_encoder); } //encoder.EncodeInterleaved(m_wtChannel[i], m_currentLevel, m_quant); // until version 4 m_wtChannel[i]->GetSubband(m_currentLevel, HL)->ExtractTile(*m_encoder); // since version 5 m_wtChannel[i]->GetSubband(m_currentLevel, LH)->ExtractTile(*m_encoder); // since version 5 m_wtChannel[i]->GetSubband(m_currentLevel, HH)->ExtractTile(*m_encoder); } // all necessary data are buffered. next call of EncodeBuffer will write the last piece of data of the current level. m_encoder->SetEncodedLevel(--m_currentLevel); } } ////////////////////////////////////////////////////////////////////// // Return written levelLength bytes UINT32 CPGFImage::UpdatePostHeaderSize() THROW_ { ASSERT(m_encoder); INT64 offset = m_encoder->ComputeOffset(); ASSERT(offset >= 0); if (offset > 0) { // update post-header size and rewrite pre-header m_preHeader.hSize += (UINT32)offset; m_encoder->UpdatePostHeaderSize(m_preHeader); } // write dummy levelLength into stream return m_encoder->WriteLevelLength(m_levelLength); } ////////////////////////////////////////////////////////////////////// /// Encode and write the one and only image at current stream position. /// Call this method after WriteHeader(). In case you want to write uncached metadata, /// then do that after WriteHeader() and before WriteImage(). /// This method is called inside of Write(stream, ...). /// It might throw an IOException. /// @param stream A PGF stream /// @param cb A pointer to a callback procedure. The procedure is called after writing a single level. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. /// @return The number of bytes written into stream. UINT32 CPGFImage::WriteImage(CPGFStream* stream, CallbackPtr cb /*= NULL*/, void *data /*= NULL*/) THROW_ { ASSERT(stream); ASSERT(m_preHeader.hSize); int levels = m_header.nLevels; double percent = pow(0.25, levels); // update post-header size, rewrite pre-header, and write dummy levelLength UINT32 nWrittenBytes = UpdatePostHeaderSize(); if (levels == 0) { // write channels for (int c=0; c < m_header.channels; c++) { const UINT32 size = m_width[c]*m_height[c]; // write channel data into stream for (UINT32 i=0; i < size; i++) { int count = DataTSize; stream->Write(&count, &m_channel[c][i]); } } // now update progress if (cb) { if ((*cb)(1, true, data)) ReturnWithError(EscapePressed); } } else { // encode quantized wavelet coefficients and write to PGF file // encode subbands, higher levels first // color channels are interleaved // encode all levels for (m_currentLevel = levels; m_currentLevel > 0; ) { WriteLevel(); // decrements m_currentLevel // now update progress if (cb) { percent *= 4; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } // flush encoder and write level lengths m_encoder->Flush(); } // update level lengths nWrittenBytes += m_encoder->UpdateLevelLength(); // return written image bytes // delete encoder delete m_encoder; m_encoder = NULL; ASSERT(!m_encoder); return nWrittenBytes; } ////////////////////////////////////////////////////////////////// /// Encode and write a entire PGF image (header and image) at current stream position. /// A PGF image is structered in levels, numbered between 0 and Levels() - 1. /// Each level can be seen as a single image, containing the same content /// as all other levels, but in a different size (width, height). /// The image size at level i is double the size (width, height) of the image at level i+1. /// The image at level 0 contains the original size. /// Precondition: the PGF image contains a valid header (see also SetHeader(...)). /// It might throw an IOException. /// @param stream A PGF stream /// @param nWrittenBytes [in-out] The number of bytes written into stream are added to the input value. /// @param cb A pointer to a callback procedure. The procedure is called after writing a single level. If cb returns true, then it stops proceeding. /// @param data Data Pointer to C++ class container to host callback procedure. void CPGFImage::Write(CPGFStream* stream, UINT32* nWrittenBytes /*= NULL*/, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) THROW_ { ASSERT(stream); ASSERT(m_preHeader.hSize); // create wavelet transform channels and encoder UINT32 nBytes = WriteHeader(stream); // write image nBytes += WriteImage(stream, cb, data); // return written bytes if (nWrittenBytes) *nWrittenBytes += nBytes; } #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////// // Encode and write down to given level at current stream position. // A PGF image is structered in levels, numbered between 0 and Levels() - 1. // Each level can be seen as a single image, containing the same content // as all other levels, but in a different size (width, height). // The image size at level i is double the size (width, height) of the image at level i+1. // The image at level 0 contains the original size. // Precondition: the PGF image contains a valid header (see also SetHeader(...)) and WriteHeader() has been called before Write(). // The ROI encoding scheme is used. // It might throw an IOException. // @param level The image level of the resulting image in the internal image buffer. // @param cb A pointer to a callback procedure. The procedure is called after writing a single level. If cb returns true, then it stops proceeding. // @param data Data Pointer to C++ class container to host callback procedure. // @return The number of bytes written into stream. UINT32 CPGFImage::Write(int level, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) THROW_ { ASSERT(m_header.nLevels > 0); ASSERT(0 <= level && level < m_header.nLevels); ASSERT(m_encoder); ASSERT(ROIisSupported()); const int levelDiff = m_currentLevel - level; double percent = (m_progressMode == PM_Relative) ? pow(0.25, levelDiff) : m_percent; UINT32 nWrittenBytes = 0; if (m_currentLevel == m_header.nLevels) { // update post-header size, rewrite pre-header, and write dummy levelLength nWrittenBytes = UpdatePostHeaderSize(); } else { // prepare for next level: save current file position, because the stream might have been reinitialized if (m_encoder->ComputeBufferLength()) { m_streamReinitialized = true; } } // encoding scheme with ROI while (m_currentLevel > level) { WriteLevel(); // decrements m_currentLevel if (m_levelLength) { nWrittenBytes += m_levelLength[m_header.nLevels - m_currentLevel - 1]; } // now update progress if (cb) { percent *= 4; if (m_progressMode == PM_Absolute) m_percent = percent; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } // automatically closing if (m_currentLevel == 0) { if (!m_streamReinitialized) { // don't write level lengths, if the stream position changed inbetween two Write operations m_encoder->UpdateLevelLength(); } // delete encoder delete m_encoder; m_encoder = NULL; } return nWrittenBytes; } #endif // __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////// // Check for valid import image mode. // @param mode Image mode // @return True if an image of given mode can be imported with ImportBitmap(...) bool CPGFImage::ImportIsSupported(BYTE mode) { size_t size = DataTSize; if (size >= 2) { switch(mode) { case ImageModeBitmap: case ImageModeIndexedColor: case ImageModeGrayScale: case ImageModeRGBColor: case ImageModeCMYKColor: case ImageModeHSLColor: case ImageModeHSBColor: //case ImageModeDuotone: case ImageModeLabColor: case ImageModeRGB12: case ImageModeRGB16: case ImageModeRGBA: return true; } } if (size >= 3) { switch(mode) { case ImageModeGray16: case ImageModeRGB48: case ImageModeLab48: case ImageModeCMYK64: //case ImageModeDuotone16: return true; } } if (size >=4) { switch(mode) { case ImageModeGray32: return true; } } return false; } ////////////////////////////////////////////////////////////////////// /// Retrieves red, green, blue (RGB) color values from a range of entries in the palette of the DIB section. /// It might throw an IOException. /// @param iFirstColor The color table index of the first entry to retrieve. /// @param nColors The number of color table entries to retrieve. /// @param prgbColors A pointer to the array of RGBQUAD structures to retrieve the color table entries. void CPGFImage::GetColorTable(UINT32 iFirstColor, UINT32 nColors, RGBQUAD* prgbColors) const THROW_ { if (iFirstColor + nColors > ColorTableLen) ReturnWithError(ColorTableError); for (UINT32 i=iFirstColor, j=0; j < nColors; i++, j++) { prgbColors[j] = m_postHeader.clut[i]; } } ////////////////////////////////////////////////////////////////////// /// Sets the red, green, blue (RGB) color values for a range of entries in the palette (clut). /// It might throw an IOException. /// @param iFirstColor The color table index of the first entry to set. /// @param nColors The number of color table entries to set. /// @param prgbColors A pointer to the array of RGBQUAD structures to set the color table entries. void CPGFImage::SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD* prgbColors) THROW_ { if (iFirstColor + nColors > ColorTableLen) ReturnWithError(ColorTableError); for (UINT32 i=iFirstColor, j=0; j < nColors; i++, j++) { m_postHeader.clut[i] = prgbColors[j]; } } ////////////////////////////////////////////////////////////////// // Buffer transform from interleaved to channel seperated format // the absolute value of pitch is the number of bytes of an image row // if pitch is negative, then buff points to the last row of a bottom-up image (first byte on last row) // if pitch is positive, then buff points to the first row of a top-down image (first byte) // bpp is the number of bits per pixel used in image buffer buff // // RGB is transformed into YUV format (ordering of buffer data is BGR[A]) // Y = (R + 2*G + B)/4 -128 // U = R - G // V = B - G // // Since PGF Codec version 2.0 images are stored in top-down direction // // The sequence of input channels in the input image buffer does not need to be the same as expected from PGF. In case of different sequences you have to // provide a channelMap of size of expected channels (depending on image mode). For example, PGF expects in RGB color mode a channel sequence BGR. // If your provided image buffer contains a channel sequence ARGB, then the channelMap looks like { 3, 2, 1 }. void CPGFImage::RgbToYuv(int pitch, UINT8* buff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data /*=NULL*/) THROW_ { ASSERT(buff); int yPos = 0, cnt = 0; double percent = 0; const double dP = 1.0/m_header.height; int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(sizeof(defMap)/sizeof(defMap[0]) == MaxChannels); if (channelMap == NULL) channelMap = defMap; switch(m_header.mode) { case ImageModeBitmap: { ASSERT(m_header.channels == 1); ASSERT(m_header.bpp == 1); ASSERT(bpp == 1); const UINT32 w = m_header.width; const UINT32 w2 = (m_header.width + 7)/8; DataT* y = m_channel[0]; ASSERT(y); for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } for (UINT32 j=0; j < w2; j++) { y[yPos++] = buff[j] - YUVoffset8; } for (UINT32 j=w2; j < w; j++) { y[yPos++] = YUVoffset8; } //UINT cnt = w; //for (UINT32 j=0; j < w2; j++) { // for (int k=7; k >= 0; k--) { // if (cnt) { // y[yPos++] = YUVoffset8 + (1 & (buff[j] >> k)); // cnt--; // } // } //} buff += pitch; } } break; case ImageModeIndexedColor: case ImageModeGrayScale: case ImageModeHSLColor: case ImageModeHSBColor: case ImageModeLabColor: { ASSERT(m_header.channels >= 1); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); const int channels = bpp/8; ASSERT(channels >= m_header.channels); for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { for (int c=0; c < m_header.channels; c++) { m_channel[c][yPos] = buff[cnt + channelMap[c]] - YUVoffset8; } cnt += channels; yPos++; } buff += pitch; } } break; case ImageModeGray16: case ImageModeLab48: { ASSERT(m_header.channels >= 1); ASSERT(m_header.bpp == m_header.channels*16); ASSERT(bpp%16 == 0); UINT16 *buff16 = (UINT16 *)buff; const int pitch16 = pitch/2; const int channels = bpp/16; ASSERT(channels >= m_header.channels); const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { for (int c=0; c < m_header.channels; c++) { m_channel[c][yPos] = (buff16[cnt + channelMap[c]] >> shift) - yuvOffset16; } cnt += channels; yPos++; } buff16 += pitch16; } } break; case ImageModeRGBColor: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); const int channels = bpp/8; ASSERT(channels >= m_header.channels); UINT8 b, g, r; for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { b = buff[cnt + channelMap[0]]; g = buff[cnt + channelMap[1]]; r = buff[cnt + channelMap[2]]; // Yuv y[yPos] = ((b + (g << 1) + r) >> 2) - YUVoffset8; u[yPos] = r - g; v[yPos] = b - g; yPos++; cnt += channels; } buff += pitch; } } break; case ImageModeRGB48: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*16); ASSERT(bpp%16 == 0); UINT16 *buff16 = (UINT16 *)buff; const int pitch16 = pitch/2; const int channels = bpp/16; ASSERT(channels >= m_header.channels); const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); UINT16 b, g, r; for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { b = buff16[cnt + channelMap[0]] >> shift; g = buff16[cnt + channelMap[1]] >> shift; r = buff16[cnt + channelMap[2]] >> shift; // Yuv y[yPos] = ((b + (g << 1) + r) >> 2) - yuvOffset16; u[yPos] = r - g; v[yPos] = b - g; yPos++; cnt += channels; } buff16 += pitch16; } } break; case ImageModeRGBA: case ImageModeCMYKColor: { ASSERT(m_header.channels == 4); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); const int channels = bpp/8; ASSERT(channels >= m_header.channels); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); DataT* a = m_channel[3]; ASSERT(a); UINT8 b, g, r; for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { b = buff[cnt + channelMap[0]]; g = buff[cnt + channelMap[1]]; r = buff[cnt + channelMap[2]]; // Yuv y[yPos] = ((b + (g << 1) + r) >> 2) - YUVoffset8; u[yPos] = r - g; v[yPos] = b - g; a[yPos++] = buff[cnt + channelMap[3]] - YUVoffset8; cnt += channels; } buff += pitch; } } break; case ImageModeCMYK64: { ASSERT(m_header.channels == 4); ASSERT(m_header.bpp == m_header.channels*16); ASSERT(bpp%16 == 0); UINT16 *buff16 = (UINT16 *)buff; const int pitch16 = pitch/2; const int channels = bpp/16; ASSERT(channels >= m_header.channels); const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); DataT* a = m_channel[3]; ASSERT(a); UINT16 b, g, r; for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { b = buff16[cnt + channelMap[0]] >> shift; g = buff16[cnt + channelMap[1]] >> shift; r = buff16[cnt + channelMap[2]] >> shift; // Yuv y[yPos] = ((b + (g << 1) + r) >> 2) - yuvOffset16; u[yPos] = r - g; v[yPos] = b - g; a[yPos++] = (buff16[cnt + channelMap[3]] >> shift) - yuvOffset16; cnt += channels; } buff16 += pitch16; } } break; #ifdef __PGF32SUPPORT__ case ImageModeGray32: { ASSERT(m_header.channels == 1); ASSERT(m_header.bpp == 32); ASSERT(bpp == 32); ASSERT(DataTSize == sizeof(UINT32)); DataT* y = m_channel[0]; ASSERT(y); UINT32 *buff32 = (UINT32 *)buff; const int pitch32 = pitch/4; const int shift = 31 - UsedBitsPerChannel(); ASSERT(shift >= 0); const DataT yuvOffset31 = 1 << (UsedBitsPerChannel() - 1); for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } for (UINT32 w=0; w < m_header.width; w++) { y[yPos++] = (buff32[w] >> shift) - yuvOffset31; } buff32 += pitch32; } } break; #endif case ImageModeRGB12: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*4); ASSERT(bpp == m_header.channels*4); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); UINT8 rgb = 0, b, g, r; for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { if (w%2 == 0) { // even pixel position rgb = buff[cnt]; b = rgb & 0x0F; g = (rgb & 0xF0) >> 4; cnt++; rgb = buff[cnt]; r = rgb & 0x0F; } else { // odd pixel position b = (rgb & 0xF0) >> 4; cnt++; rgb = buff[cnt]; g = rgb & 0x0F; r = (rgb & 0xF0) >> 4; cnt++; } // Yuv y[yPos] = ((b + (g << 1) + r) >> 2) - YUVoffset4; u[yPos] = r - g; v[yPos] = b - g; yPos++; } buff += pitch; } } break; case ImageModeRGB16: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == 16); ASSERT(bpp == 16); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); UINT16 *buff16 = (UINT16 *)buff; UINT16 rgb, b, g, r; const int pitch16 = pitch/2; for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } for (UINT32 w=0; w < m_header.width; w++) { rgb = buff16[w]; r = (rgb & 0xF800) >> 10; // highest 5 bits g = (rgb & 0x07E0) >> 5; // middle 6 bits b = (rgb & 0x001F) << 1; // lowest 5 bits // Yuv y[yPos] = ((b + (g << 1) + r) >> 2) - YUVoffset6; u[yPos] = r - g; v[yPos] = b - g; yPos++; } buff16 += pitch16; } } break; default: ASSERT(false); } } ////////////////////////////////////////////////////////////////// // Get image data in interleaved format: (ordering of RGB data is BGR[A]) // Upsampling, YUV to RGB transform and interleaving are done here to reduce the number // of passes over the data. // The absolute value of pitch is the number of bytes of an image row of the given image buffer. // If pitch is negative, then the image buffer must point to the last row of a bottom-up image (first byte on last row). // if pitch is positive, then the image buffer must point to the first row of a top-down image (first byte). // The sequence of output channels in the output image buffer does not need to be the same as provided by PGF. In case of different sequences you have to // provide a channelMap of size of expected channels (depending on image mode). For example, PGF provides a channel sequence BGR in RGB color mode. // If your provided image buffer expects a channel sequence ARGB, then the channelMap looks like { 3, 2, 1 }. // It might throw an IOException. // @param pitch The number of bytes of a row of the image buffer. // @param buff An image buffer. // @param bpp The number of bits per pixel used in image buffer. // @param channelMap A integer array containing the mapping of PGF channel ordering to expected channel ordering. // @param cb A pointer to a callback procedure. The procedure is called after each copied buffer row. If cb returns true, then it stops proceeding. // @param data Data Pointer to C++ class container to host callback procedure. void CPGFImage::GetBitmap(int pitch, UINT8* buff, BYTE bpp, int channelMap[] /*= NULL */, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) const THROW_ { ASSERT(buff); UINT32 w = m_width[0]; UINT32 h = m_height[0]; UINT8* targetBuff = 0; // used if ROI is used UINT8* buffStart = 0; // used if ROI is used int targetPitch = 0; // used if ROI is used #ifdef __PGFROISUPPORT__ const PGFRect& roi = (ROIisSupported()) ? m_wtChannel[0]->GetROI(m_currentLevel) : PGFRect(0, 0, w, h); // roi is usually larger than m_roi const PGFRect levelRoi(LevelWidth(m_roi.left, m_currentLevel), LevelHeight(m_roi.top, m_currentLevel), LevelWidth(m_roi.Width(), m_currentLevel), LevelHeight(m_roi.Height(), m_currentLevel)); ASSERT(w <= roi.Width() && h <= roi.Height()); ASSERT(roi.left <= levelRoi.left && levelRoi.right <= roi.right); ASSERT(roi.top <= levelRoi.top && levelRoi.bottom <= roi.bottom); if (ROIisSupported() && (levelRoi.Width() < w || levelRoi.Height() < h)) { // ROI is used -> create a temporary image buffer for roi // compute pitch targetPitch = pitch; pitch = AlignWordPos(w*bpp)/8; // create temporary output buffer targetBuff = buff; buff = buffStart = new(std::nothrow) UINT8[pitch*h]; if (!buff) ReturnWithError(InsufficientMemory); } #endif const bool wOdd = (1 == w%2); const double dP = 1.0/h; int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(sizeof(defMap)/sizeof(defMap[0]) == MaxChannels); if (channelMap == NULL) channelMap = defMap; int sampledPos = 0, yPos = 0; DataT uAvg, vAvg; double percent = 0; UINT32 i, j; switch(m_header.mode) { case ImageModeBitmap: { ASSERT(m_header.channels == 1); ASSERT(m_header.bpp == 1); ASSERT(bpp == 1); const UINT32 w2 = (w + 7)/8; DataT* y = m_channel[0]; ASSERT(y); for (i=0; i < h; i++) { for (j=0; j < w2; j++) { buff[j] = Clamp8(y[yPos++] + YUVoffset8); } yPos += w - w2; //UINT32 cnt = w; //for (j=0; j < w2; j++) { // buff[j] = 0; // for (int k=0; k < 8; k++) { // if (cnt) { // buff[j] <<= 1; // buff[j] |= (1 & (y[yPos++] - YUVoffset8)); // cnt--; // } // } //} buff += pitch; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } break; } case ImageModeIndexedColor: case ImageModeGrayScale: case ImageModeHSLColor: case ImageModeHSBColor: { ASSERT(m_header.channels >= 1); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); int cnt, channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { cnt = 0; for (j=0; j < w; j++) { for (int c=0; c < m_header.channels; c++) { buff[cnt + channelMap[c]] = Clamp8(m_channel[c][yPos] + YUVoffset8); } cnt += channels; yPos++; } buff += pitch; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } break; } case ImageModeGray16: { ASSERT(m_header.channels >= 1); ASSERT(m_header.bpp == m_header.channels*16); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); int cnt, channels; if (bpp%16 == 0) { const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); UINT16 *buff16 = (UINT16 *)buff; int pitch16 = pitch/2; channels = bpp/16; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { cnt = 0; for (j=0; j < w; j++) { for (int c=0; c < m_header.channels; c++) { buff16[cnt + channelMap[c]] = Clamp16((m_channel[c][yPos] + yuvOffset16) << shift); } cnt += channels; yPos++; } buff16 += pitch16; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else { ASSERT(bpp%8 == 0); const int shift = __max(0, UsedBitsPerChannel() - 8); channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { cnt = 0; for (j=0; j < w; j++) { for (int c=0; c < m_header.channels; c++) { buff[cnt + channelMap[c]] = Clamp8((m_channel[c][yPos] + yuvOffset16) >> shift); } cnt += channels; yPos++; } buff += pitch; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } break; } case ImageModeRGBColor: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); ASSERT(bpp >= m_header.bpp); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); UINT8 *buffg = &buff[channelMap[1]], *buffr = &buff[channelMap[2]], *buffb = &buff[channelMap[0]]; UINT8 g; int cnt, channels = bpp/8; if(m_downsample){ for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; // Yuv buffg[cnt] = g = Clamp8(y[yPos] + YUVoffset8 - ((uAvg + vAvg ) >> 2)); // must be logical shift operator buffr[cnt] = Clamp8(uAvg + g); buffb[cnt] = Clamp8(vAvg + g); yPos++; cnt += channels; if (j%2) sampledPos++; } buffb += pitch; buffg += pitch; buffr += pitch; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } }else{ for (i=0; i < h; i++) { cnt = 0; for (j = 0; j < w; j++) { uAvg = u[yPos]; vAvg = v[yPos]; // Yuv buffg[cnt] = g = Clamp8(y[yPos] + YUVoffset8 - ((uAvg + vAvg ) >> 2)); // must be logical shift operator buffr[cnt] = Clamp8(uAvg + g); buffb[cnt] = Clamp8(vAvg + g); yPos++; cnt += channels; } buffb += pitch; buffg += pitch; buffr += pitch; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } break; } case ImageModeRGB48: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == 48); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); int cnt, channels; DataT g; if (bpp >= 48 && bpp%16 == 0) { const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); UINT16 *buff16 = (UINT16 *)buff; int pitch16 = pitch/2; channels = bpp/16; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; } else { uAvg = u[yPos]; vAvg = v[yPos]; } // Yuv g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2); // must be logical shift operator buff16[cnt + channelMap[1]] = Clamp16(g << shift); buff16[cnt + channelMap[2]] = Clamp16((uAvg + g) << shift); buff16[cnt + channelMap[0]] = Clamp16((vAvg + g) << shift); yPos++; cnt += channels; if (j%2) sampledPos++; } buff16 += pitch16; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else { ASSERT(bpp%8 == 0); const int shift = __max(0, UsedBitsPerChannel() - 8); channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; } else { uAvg = u[yPos]; vAvg = v[yPos]; } // Yuv g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2); // must be logical shift operator buff[cnt + channelMap[1]] = Clamp8(g >> shift); buff[cnt + channelMap[2]] = Clamp8((uAvg + g) >> shift); buff[cnt + channelMap[0]] = Clamp8((vAvg + g) >> shift); yPos++; cnt += channels; if (j%2) sampledPos++; } buff += pitch; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } break; } case ImageModeLabColor: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); DataT* l = m_channel[0]; ASSERT(l); DataT* a = m_channel[1]; ASSERT(a); DataT* b = m_channel[2]; ASSERT(b); int cnt, channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = a[sampledPos]; vAvg = b[sampledPos]; } else { uAvg = a[yPos]; vAvg = b[yPos]; } buff[cnt + channelMap[0]] = Clamp8(l[yPos] + YUVoffset8); buff[cnt + channelMap[1]] = Clamp8(uAvg + YUVoffset8); buff[cnt + channelMap[2]] = Clamp8(vAvg + YUVoffset8); cnt += channels; yPos++; if (j%2) sampledPos++; } buff += pitch; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } break; } case ImageModeLab48: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*16); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); DataT* l = m_channel[0]; ASSERT(l); DataT* a = m_channel[1]; ASSERT(a); DataT* b = m_channel[2]; ASSERT(b); int cnt, channels; if (bpp%16 == 0) { const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); UINT16 *buff16 = (UINT16 *)buff; int pitch16 = pitch/2; channels = bpp/16; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = a[sampledPos]; vAvg = b[sampledPos]; } else { uAvg = a[yPos]; vAvg = b[yPos]; } buff16[cnt + channelMap[0]] = Clamp16((l[yPos] + yuvOffset16) << shift); buff16[cnt + channelMap[1]] = Clamp16((uAvg + yuvOffset16) << shift); buff16[cnt + channelMap[2]] = Clamp16((vAvg + yuvOffset16) << shift); cnt += channels; yPos++; if (j%2) sampledPos++; } buff16 += pitch16; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else { ASSERT(bpp%8 == 0); const int shift = __max(0, UsedBitsPerChannel() - 8); channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = a[sampledPos]; vAvg = b[sampledPos]; } else { uAvg = a[yPos]; vAvg = b[yPos]; } buff[cnt + channelMap[0]] = Clamp8((l[yPos] + yuvOffset16) >> shift); buff[cnt + channelMap[1]] = Clamp8((uAvg + yuvOffset16) >> shift); buff[cnt + channelMap[2]] = Clamp8((vAvg + yuvOffset16) >> shift); cnt += channels; yPos++; if (j%2) sampledPos++; } buff += pitch; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } break; } case ImageModeRGBA: case ImageModeCMYKColor: { ASSERT(m_header.channels == 4); ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%8 == 0); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); DataT* a = m_channel[3]; ASSERT(a); UINT8 g, aAvg; int cnt, channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; aAvg = Clamp8(a[sampledPos] + YUVoffset8); } else { uAvg = u[yPos]; vAvg = v[yPos]; aAvg = Clamp8(a[yPos] + YUVoffset8); } // Yuv buff[cnt + channelMap[1]] = g = Clamp8(y[yPos] + YUVoffset8 - ((uAvg + vAvg ) >> 2)); // must be logical shift operator buff[cnt + channelMap[2]] = Clamp8(uAvg + g); buff[cnt + channelMap[0]] = Clamp8(vAvg + g); buff[cnt + channelMap[3]] = aAvg; yPos++; cnt += channels; if (j%2) sampledPos++; } buff += pitch; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } break; } case ImageModeCMYK64: { ASSERT(m_header.channels == 4); ASSERT(m_header.bpp == 64); const DataT yuvOffset16 = 1 << (UsedBitsPerChannel() - 1); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); DataT* a = m_channel[3]; ASSERT(a); DataT g, aAvg; int cnt, channels; if (bpp%16 == 0) { const int shift = 16 - UsedBitsPerChannel(); ASSERT(shift >= 0); UINT16 *buff16 = (UINT16 *)buff; int pitch16 = pitch/2; channels = bpp/16; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; aAvg = a[sampledPos] + yuvOffset16; } else { uAvg = u[yPos]; vAvg = v[yPos]; aAvg = a[yPos] + yuvOffset16; } // Yuv g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2); // must be logical shift operator buff16[cnt + channelMap[1]] = Clamp16(g << shift); buff16[cnt + channelMap[2]] = Clamp16((uAvg + g) << shift); buff16[cnt + channelMap[0]] = Clamp16((vAvg + g) << shift); buff16[cnt + channelMap[3]] = Clamp16(aAvg << shift); yPos++; cnt += channels; if (j%2) sampledPos++; } buff16 += pitch16; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else { ASSERT(bpp%8 == 0); const int shift = __max(0, UsedBitsPerChannel() - 8); channels = bpp/8; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; aAvg = a[sampledPos] + yuvOffset16; } else { uAvg = u[yPos]; vAvg = v[yPos]; aAvg = a[yPos] + yuvOffset16; } // Yuv g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2); // must be logical shift operator buff[cnt + channelMap[1]] = Clamp8(g >> shift); buff[cnt + channelMap[2]] = Clamp8((uAvg + g) >> shift); buff[cnt + channelMap[0]] = Clamp8((vAvg + g) >> shift); buff[cnt + channelMap[3]] = Clamp8(aAvg >> shift); yPos++; cnt += channels; if (j%2) sampledPos++; } buff += pitch; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } break; } #ifdef __PGF32SUPPORT__ case ImageModeGray32: { ASSERT(m_header.channels == 1); ASSERT(m_header.bpp == 32); const int yuvOffset31 = 1 << (UsedBitsPerChannel() - 1); DataT* y = m_channel[0]; ASSERT(y); if (bpp == 32) { const int shift = 31 - UsedBitsPerChannel(); ASSERT(shift >= 0); UINT32 *buff32 = (UINT32 *)buff; int pitch32 = pitch/4; for (i=0; i < h; i++) { for (j=0; j < w; j++) { buff32[j] = Clamp31((y[yPos++] + yuvOffset31) << shift); } buff32 += pitch32; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else if (bpp == 16) { const int usedBits = UsedBitsPerChannel(); UINT16 *buff16 = (UINT16 *)buff; int pitch16 = pitch/2; if (usedBits < 16) { const int shift = 16 - usedBits; for (i=0; i < h; i++) { for (j=0; j < w; j++) { buff16[j] = Clamp16((y[yPos++] + yuvOffset31) << shift); } buff16 += pitch16; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else { const int shift = __max(0, usedBits - 16); for (i=0; i < h; i++) { for (j=0; j < w; j++) { buff16[j] = Clamp16((y[yPos++] + yuvOffset31) >> shift); } buff16 += pitch16; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } } else { ASSERT(bpp == 8); const int shift = __max(0, UsedBitsPerChannel() - 8); for (i=0; i < h; i++) { for (j=0; j < w; j++) { buff[j] = Clamp8((y[yPos++] + yuvOffset31) >> shift); } buff += pitch; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } break; } #endif case ImageModeRGB12: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == m_header.channels*4); ASSERT(bpp == m_header.channels*4); ASSERT(!m_downsample); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); UINT16 yval; int cnt; for (i=0; i < h; i++) { cnt = 0; for (j=0; j < w; j++) { // Yuv uAvg = u[yPos]; vAvg = v[yPos]; yval = Clamp4(y[yPos++] + YUVoffset4 - ((uAvg + vAvg ) >> 2)); // must be logical shift operator if (j%2 == 0) { buff[cnt] = UINT8(Clamp4(vAvg + yval) | (yval << 4)); cnt++; buff[cnt] = Clamp4(uAvg + yval); } else { buff[cnt] |= Clamp4(vAvg + yval) << 4; cnt++; buff[cnt] = UINT8(yval | (Clamp4(uAvg + yval) << 4)); cnt++; } } buff += pitch; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } break; } case ImageModeRGB16: { ASSERT(m_header.channels == 3); ASSERT(m_header.bpp == 16); ASSERT(bpp == 16); ASSERT(!m_downsample); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); UINT16 yval; UINT16 *buff16 = (UINT16 *)buff; int pitch16 = pitch/2; for (i=0; i < h; i++) { for (j=0; j < w; j++) { // Yuv uAvg = u[yPos]; vAvg = v[yPos]; yval = Clamp6(y[yPos++] + YUVoffset6 - ((uAvg + vAvg ) >> 2)); // must be logical shift operator buff16[j] = (yval << 5) | ((Clamp6(uAvg + yval) >> 1) << 11) | (Clamp6(vAvg + yval) >> 1); } buff16 += pitch16; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } break; } default: ASSERT(false); } #ifdef __PGFROISUPPORT__ if (targetBuff) { // copy valid ROI (m_roi) from temporary buffer (roi) to target buffer if (bpp%8 == 0) { BYTE bypp = bpp/8; buff = buffStart + (levelRoi.top - roi.top)*pitch + (levelRoi.left - roi.left)*bypp; w = levelRoi.Width()*bypp; h = levelRoi.Height(); for (i=0; i < h; i++) { for (j=0; j < w; j++) { targetBuff[j] = buff[j]; } targetBuff += targetPitch; buff += pitch; } } else { // to do } delete[] buffStart; buffStart = 0; } #endif } ////////////////////////////////////////////////////////////////////// /// Get YUV image data in interleaved format: (ordering is YUV[A]) /// The absolute value of pitch is the number of bytes of an image row of the given image buffer. /// If pitch is negative, then the image buffer must point to the last row of a bottom-up image (first byte on last row). /// if pitch is positive, then the image buffer must point to the first row of a top-down image (first byte). /// The sequence of output channels in the output image buffer does not need to be the same as provided by PGF. In case of different sequences you have to /// provide a channelMap of size of expected channels (depending on image mode). For example, PGF provides a channel sequence BGR in RGB color mode. /// If your provided image buffer expects a channel sequence VUY, then the channelMap looks like { 2, 1, 0 }. /// It might throw an IOException. /// @param pitch The number of bytes of a row of the image buffer. /// @param buff An image buffer. /// @param bpp The number of bits per pixel used in image buffer. /// @param channelMap A integer array containing the mapping of PGF channel ordering to expected channel ordering. /// @param cb A pointer to a callback procedure. The procedure is called after each copied buffer row. If cb returns true, then it stops proceeding. void CPGFImage::GetYUV(int pitch, DataT* buff, BYTE bpp, int channelMap[] /*= NULL*/, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) const THROW_ { ASSERT(buff); const UINT32 w = m_width[0]; const UINT32 h = m_height[0]; const bool wOdd = (1 == w%2); const int dataBits = DataTSize*8; ASSERT(dataBits == 16 || dataBits == 32); const int pitch2 = pitch/DataTSize; const int yuvOffset = (dataBits == 16) ? YUVoffset8 : YUVoffset16; const double dP = 1.0/h; int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(sizeof(defMap)/sizeof(defMap[0]) == MaxChannels); if (channelMap == NULL) channelMap = defMap; int sampledPos = 0, yPos = 0; DataT uAvg, vAvg; double percent = 0; UINT32 i, j; if (m_header.channels == 3) { ASSERT(bpp%dataBits == 0); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); int cnt, channels = bpp/dataBits; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; } else { uAvg = u[yPos]; vAvg = v[yPos]; } buff[cnt + channelMap[0]] = y[yPos]; buff[cnt + channelMap[1]] = uAvg; buff[cnt + channelMap[2]] = vAvg; yPos++; cnt += channels; if (j%2) sampledPos++; } buff += pitch2; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } else if (m_header.channels == 4) { ASSERT(m_header.bpp == m_header.channels*8); ASSERT(bpp%dataBits == 0); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); DataT* a = m_channel[3]; ASSERT(a); UINT8 aAvg; int cnt, channels = bpp/dataBits; ASSERT(channels >= m_header.channels); for (i=0; i < h; i++) { if (i%2) sampledPos -= (w + 1)/2; cnt = 0; for (j=0; j < w; j++) { if (m_downsample) { // image was downsampled uAvg = u[sampledPos]; vAvg = v[sampledPos]; aAvg = Clamp8(a[sampledPos] + yuvOffset); } else { uAvg = u[yPos]; vAvg = v[yPos]; aAvg = Clamp8(a[yPos] + yuvOffset); } // Yuv buff[cnt + channelMap[0]] = y[yPos]; buff[cnt + channelMap[1]] = uAvg; buff[cnt + channelMap[2]] = vAvg; buff[cnt + channelMap[3]] = aAvg; yPos++; cnt += channels; if (j%2) sampledPos++; } buff += pitch2; if (wOdd) sampledPos++; if (cb) { percent += dP; if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); } } } } ////////////////////////////////////////////////////////////////////// /// Import a YUV image from a specified image buffer. /// The absolute value of pitch is the number of bytes of an image row. /// If pitch is negative, then buff points to the last row of a bottom-up image (first byte on last row). /// If pitch is positive, then buff points to the first row of a top-down image (first byte). /// The sequence of input channels in the input image buffer does not need to be the same as expected from PGF. In case of different sequences you have to /// provide a channelMap of size of expected channels (depending on image mode). For example, PGF expects in RGB color mode a channel sequence BGR. /// If your provided image buffer contains a channel sequence VUY, then the channelMap looks like { 2, 1, 0 }. /// It might throw an IOException. /// @param pitch The number of bytes of a row of the image buffer. /// @param buff An image buffer. /// @param bpp The number of bits per pixel used in image buffer. /// @param channelMap A integer array containing the mapping of input channel ordering to expected channel ordering. /// @param cb A pointer to a callback procedure. The procedure is called after each imported buffer row. If cb returns true, then it stops proceeding. void CPGFImage::ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[] /*= NULL*/, CallbackPtr cb /*= NULL*/, void *data /*=NULL*/) THROW_ { ASSERT(buff); const double dP = 1.0/m_header.height; const int dataBits = DataTSize*8; ASSERT(dataBits == 16 || dataBits == 32); const int pitch2 = pitch/DataTSize; const int yuvOffset = (dataBits == 16) ? YUVoffset8 : YUVoffset16; int yPos = 0, cnt = 0; double percent = 0; int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(sizeof(defMap)/sizeof(defMap[0]) == MaxChannels); if (channelMap == NULL) channelMap = defMap; if (m_header.channels == 3) { ASSERT(bpp%dataBits == 0); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); const int channels = bpp/dataBits; ASSERT(channels >= m_header.channels); for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { y[yPos] = buff[cnt + channelMap[0]]; u[yPos] = buff[cnt + channelMap[1]]; v[yPos] = buff[cnt + channelMap[2]]; yPos++; cnt += channels; } buff += pitch2; } } else if (m_header.channels == 4) { ASSERT(bpp%dataBits == 0); DataT* y = m_channel[0]; ASSERT(y); DataT* u = m_channel[1]; ASSERT(u); DataT* v = m_channel[2]; ASSERT(v); DataT* a = m_channel[3]; ASSERT(a); const int channels = bpp/dataBits; ASSERT(channels >= m_header.channels); for (UINT32 h=0; h < m_header.height; h++) { if (cb) { if ((*cb)(percent, true, data)) ReturnWithError(EscapePressed); percent += dP; } cnt = 0; for (UINT32 w=0; w < m_header.width; w++) { y[yPos] = buff[cnt + channelMap[0]]; u[yPos] = buff[cnt + channelMap[1]]; v[yPos] = buff[cnt + channelMap[2]]; a[yPos] = buff[cnt + channelMap[3]] - yuvOffset; yPos++; cnt += channels; } buff += pitch2; } } if (m_downsample) { // Subsampling of the chrominance and alpha channels for (int i=1; i < m_header.channels; i++) { Downsample(i); } } } libpgf/src/PGFstream.cpp100777 0 0 17552 12232452341 10613 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2007-01-19 11:51:24 +0100 (Fr, 19 Jan 2007) $ * $Revision: 268 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file PGFstream.cpp /// @brief PGF stream class implementation /// @author C. Stamm #include "PGFstream.h" #ifdef WIN32 #include #endif ////////////////////////////////////////////////////////////////////// // CPGFFileStream ////////////////////////////////////////////////////////////////////// void CPGFFileStream::Write(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); OSError err; if ((err = FileWrite(m_hFile, count, buffPtr)) != NoError) ReturnWithError(err); } ////////////////////////////////////////////////////////////////////// void CPGFFileStream::Read(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); OSError err; if ((err = FileRead(m_hFile, count, buffPtr)) != NoError) ReturnWithError(err); } ////////////////////////////////////////////////////////////////////// void CPGFFileStream::SetPos(short posMode, INT64 posOff) THROW_ { ASSERT(IsValid()); OSError err; if ((err = SetFPos(m_hFile, posMode, posOff)) != NoError) ReturnWithError(err); } ////////////////////////////////////////////////////////////////////// UINT64 CPGFFileStream::GetPos() const THROW_ { ASSERT(IsValid()); OSError err; UINT64 pos = 0; if ((err = GetFPos(m_hFile, &pos)) != NoError) ReturnWithError2(err, pos); return pos; } ////////////////////////////////////////////////////////////////////// // CPGFMemoryStream ////////////////////////////////////////////////////////////////////// /// Allocate memory block of given size /// @param size Memory size CPGFMemoryStream::CPGFMemoryStream(size_t size) THROW_ : m_size(size) , m_allocated(true) { m_buffer = m_pos = m_eos = new(std::nothrow) UINT8[m_size]; if (!m_buffer) ReturnWithError(InsufficientMemory); } ////////////////////////////////////////////////////////////////////// /// Use already allocated memory of given size /// @param pBuffer Memory location /// @param size Memory size CPGFMemoryStream::CPGFMemoryStream(UINT8 *pBuffer, size_t size) THROW_ : m_buffer(pBuffer) , m_pos(pBuffer) , m_eos(pBuffer + size) , m_size(size) , m_allocated(false) { ASSERT(IsValid()); } ////////////////////////////////////////////////////////////////////// /// Use already allocated memory of given size /// @param pBuffer Memory location /// @param size Memory size void CPGFMemoryStream::Reinitialize(UINT8 *pBuffer, size_t size) THROW_ { if (!m_allocated) { m_buffer = m_pos = pBuffer; m_size = size; m_eos = m_buffer + size; } } ////////////////////////////////////////////////////////////////////// void CPGFMemoryStream::Write(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); const size_t deltaSize = 0x4000 + *count; if (m_pos + *count <= m_buffer + m_size) { memcpy(m_pos, buffPtr, *count); m_pos += *count; if (m_pos > m_eos) m_eos = m_pos; } else if (m_allocated) { // memory block is too small -> reallocate a deltaSize larger block size_t offset = m_pos - m_buffer; UINT8 *buf_tmp = (UINT8 *)realloc(m_buffer, m_size + deltaSize); if (!buf_tmp) { delete[] m_buffer; m_buffer = 0; ReturnWithError(InsufficientMemory); } else { m_buffer = buf_tmp; } m_size += deltaSize; // reposition m_pos m_pos = m_buffer + offset; // write block memcpy(m_pos, buffPtr, *count); m_pos += *count; if (m_pos > m_eos) m_eos = m_pos; } else { ReturnWithError(InsufficientMemory); } ASSERT(m_pos <= m_eos); } ////////////////////////////////////////////////////////////////////// void CPGFMemoryStream::Read(int *count, void *buffPtr) { ASSERT(IsValid()); ASSERT(count); ASSERT(buffPtr); ASSERT(m_buffer + m_size >= m_eos); ASSERT(m_pos <= m_eos); if (m_pos + *count <= m_eos) { memcpy(buffPtr, m_pos, *count); m_pos += *count; } else { // end of memory block reached -> read only until end *count = (int)__max(0, m_eos - m_pos); memcpy(buffPtr, m_pos, *count); m_pos += *count; } ASSERT(m_pos <= m_eos); } ////////////////////////////////////////////////////////////////////// void CPGFMemoryStream::SetPos(short posMode, INT64 posOff) THROW_ { ASSERT(IsValid()); switch(posMode) { case FSFromStart: m_pos = m_buffer + posOff; break; case FSFromCurrent: m_pos += posOff; break; case FSFromEnd: m_pos = m_eos + posOff; break; default: ASSERT(false); } if (m_pos > m_eos) ReturnWithError(InvalidStreamPos); } ////////////////////////////////////////////////////////////////////// // CPGFMemFileStream #ifdef _MFC_VER ////////////////////////////////////////////////////////////////////// void CPGFMemFileStream::Write(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); m_memFile->Write(buffPtr, *count); } ////////////////////////////////////////////////////////////////////// void CPGFMemFileStream::Read(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); m_memFile->Read(buffPtr, *count); } ////////////////////////////////////////////////////////////////////// void CPGFMemFileStream::SetPos(short posMode, INT64 posOff) THROW_ { ASSERT(IsValid()); m_memFile->Seek(posOff, posMode); } ////////////////////////////////////////////////////////////////////// UINT64 CPGFMemFileStream::GetPos() const THROW_ { return (UINT64)m_memFile->GetPosition(); } #endif // _MFC_VER ////////////////////////////////////////////////////////////////////// // CPGFIStream #if defined(WIN32) || defined(WINCE) ////////////////////////////////////////////////////////////////////// void CPGFIStream::Write(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); HRESULT hr = m_stream->Write(buffPtr, *count, (ULONG *)count); if (FAILED(hr)) { ReturnWithError(hr); } } ////////////////////////////////////////////////////////////////////// void CPGFIStream::Read(int *count, void *buffPtr) THROW_ { ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); HRESULT hr = m_stream->Read(buffPtr, *count, (ULONG *)count); if (FAILED(hr)) { ReturnWithError(hr); } } ////////////////////////////////////////////////////////////////////// void CPGFIStream::SetPos(short posMode, INT64 posOff) THROW_ { ASSERT(IsValid()); LARGE_INTEGER li; li.QuadPart = posOff; HRESULT hr = m_stream->Seek(li, posMode, NULL); if (FAILED(hr)) { ReturnWithError(hr); } } ////////////////////////////////////////////////////////////////////// UINT64 CPGFIStream::GetPos() const THROW_ { ASSERT(IsValid()); LARGE_INTEGER n; ULARGE_INTEGER pos; n.QuadPart = 0; HRESULT hr = m_stream->Seek(n, FSFromCurrent, &pos); if (SUCCEEDED(hr)) { return pos.QuadPart; } else { ReturnWithError2(hr, pos.QuadPart); } } #endif // WIN32 || WINCE libpgf/src/Subband.cpp100777 0 0 21105 12313025746 10333 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ * $Revision: 229 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Subband.cpp /// @brief PGF wavelet subband class implementation /// @author C. Stamm #include "Subband.h" #include "Encoder.h" #include "Decoder.h" ///////////////////////////////////////////////////////////////////// // Default constructor CSubband::CSubband() : m_width(0) , m_height(0) , m_size(0) , m_level(0) , m_orientation(LL) , m_data(0) , m_dataPos(0) #ifdef __PGFROISUPPORT__ , m_nTiles(0) #endif { } ///////////////////////////////////////////////////////////////////// // Destructor CSubband::~CSubband() { FreeMemory(); } ///////////////////////////////////////////////////////////////////// // Initialize subband parameters void CSubband::Initialize(UINT32 width, UINT32 height, int level, Orientation orient) { m_width = width; m_height = height; m_size = m_width*m_height; m_level = level; m_orientation = orient; m_data = 0; m_dataPos = 0; #ifdef __PGFROISUPPORT__ m_ROI.left = 0; m_ROI.top = 0; m_ROI.right = m_width; m_ROI.bottom = m_height; m_nTiles = 0; #endif } ///////////////////////////////////////////////////////////////////// // Allocate a memory buffer to store all wavelet coefficients of this subband. // @return True if the allocation works without any problems bool CSubband::AllocMemory() { UINT32 oldSize = m_size; #ifdef __PGFROISUPPORT__ m_size = BufferWidth()*m_ROI.Height(); #endif ASSERT(m_size > 0); if (m_data) { if (oldSize >= m_size) { return true; } else { delete[] m_data; m_data = new(std::nothrow) DataT[m_size]; return (m_data != 0); } } else { m_data = new(std::nothrow) DataT[m_size]; return (m_data != 0); } } ///////////////////////////////////////////////////////////////////// // Delete the memory buffer of this subband. void CSubband::FreeMemory() { if (m_data) { delete[] m_data; m_data = 0; } } ///////////////////////////////////////////////////////////////////// // Perform subband quantization with given quantization parameter. // A scalar quantization (with dead-zone) is used. A large quantization value // results in strong quantization and therefore in big quality loss. // @param quantParam A quantization parameter (larger or equal to 0) void CSubband::Quantize(int quantParam) { if (m_orientation == LL) { quantParam -= (m_level + 1); // uniform rounding quantization if (quantParam > 0) { quantParam--; for (UINT32 i=0; i < m_size; i++) { if (m_data[i] < 0) { m_data[i] = -(((-m_data[i] >> quantParam) + 1) >> 1); } else { m_data[i] = ((m_data[i] >> quantParam) + 1) >> 1; } } } } else { if (m_orientation == HH) { quantParam -= (m_level - 1); } else { quantParam -= m_level; } // uniform deadzone quantization if (quantParam > 0) { int threshold = ((1 << quantParam) * 7)/5; // good value quantParam--; for (UINT32 i=0; i < m_size; i++) { if (m_data[i] < -threshold) { m_data[i] = -(((-m_data[i] >> quantParam) + 1) >> 1); } else if (m_data[i] > threshold) { m_data[i] = ((m_data[i] >> quantParam) + 1) >> 1; } else { m_data[i] = 0; } } } } } ////////////////////////////////////////////////////////////////////// /// Perform subband dequantization with given quantization parameter. /// A scalar quantization (with dead-zone) is used. A large quantization value /// results in strong quantization and therefore in big quality loss. /// @param quantParam A quantization parameter (larger or equal to 0) void CSubband::Dequantize(int quantParam) { if (m_orientation == LL) { quantParam -= m_level + 1; } else if (m_orientation == HH) { quantParam -= m_level - 1; } else { quantParam -= m_level; } if (quantParam > 0) { for (UINT32 i=0; i < m_size; i++) { m_data[i] <<= quantParam; } } } ///////////////////////////////////////////////////////////////////// /// Extracts a rectangular subregion of this subband. /// Write wavelet coefficients into buffer. /// It might throw an IOException. /// @param encoder An encoder instance /// @param tile True if just a rectangular region is extracted, false if the entire subband is extracted. /// @param tileX Tile index in x-direction /// @param tileY Tile index in y-direction void CSubband::ExtractTile(CEncoder& encoder, bool tile /*= false*/, UINT32 tileX /*= 0*/, UINT32 tileY /*= 0*/) THROW_ { #ifdef __PGFROISUPPORT__ if (tile) { // compute tile position and size UINT32 xPos, yPos, w, h; TilePosition(tileX, tileY, xPos, yPos, w, h); // write values into buffer using partitiong scheme encoder.Partition(this, w, h, xPos + yPos*m_width, m_width); } else #endif { // write values into buffer using partitiong scheme encoder.Partition(this, m_width, m_height, 0, m_width); } } ///////////////////////////////////////////////////////////////////// /// Decoding and dequantization of this subband. /// It might throw an IOException. /// @param decoder A decoder instance /// @param quantParam Dequantization value /// @param tile True if just a rectangular region is placed, false if the entire subband is placed. /// @param tileX Tile index in x-direction /// @param tileY Tile index in y-direction void CSubband::PlaceTile(CDecoder& decoder, int quantParam, bool tile /*= false*/, UINT32 tileX /*= 0*/, UINT32 tileY /*= 0*/) THROW_ { // allocate memory if (!AllocMemory()) ReturnWithError(InsufficientMemory); // correct quantParam with normalization factor if (m_orientation == LL) { quantParam -= m_level + 1; } else if (m_orientation == HH) { quantParam -= m_level - 1; } else { quantParam -= m_level; } if (quantParam < 0) quantParam = 0; #ifdef __PGFROISUPPORT__ if (tile) { UINT32 xPos, yPos, w, h; // compute tile position and size TilePosition(tileX, tileY, xPos, yPos, w, h); ASSERT(xPos >= m_ROI.left && yPos >= m_ROI.top); decoder.Partition(this, quantParam, w, h, (xPos - m_ROI.left) + (yPos - m_ROI.top)*BufferWidth(), BufferWidth()); } else #endif { // read values into buffer using partitiong scheme decoder.Partition(this, quantParam, m_width, m_height, 0, m_width); } } #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// Compute tile position and size. /// @param tileX Tile index in x-direction /// @param tileY Tile index in y-direction /// @param xPos [out] Offset to left /// @param yPos [out] Offset to top /// @param w [out] Tile width /// @param h [out] Tile height void CSubband::TilePosition(UINT32 tileX, UINT32 tileY, UINT32& xPos, UINT32& yPos, UINT32& w, UINT32& h) const { // example // band = HH, w = 30, ldTiles = 2 -> 4 tiles in a row/column // --> tile widths // 8 7 8 7 // // tile partitioning scheme // 0 1 2 3 // 4 5 6 7 // 8 9 A B // C D E F UINT32 nTiles = m_nTiles; ASSERT(tileX < nTiles); ASSERT(tileY < nTiles); UINT32 m; UINT32 left = 0, right = nTiles; UINT32 top = 0, bottom = nTiles; xPos = 0; yPos = 0; w = m_width; h = m_height; while (nTiles > 1) { // compute xPos and w with binary search m = left + ((right - left) >> 1); if (tileX >= m) { xPos += (w + 1) >> 1; w >>= 1; left = m; } else { w = (w + 1) >> 1; right = m; } // compute yPos and h with binary search m = top + ((bottom - top) >> 1); if (tileY >= m) { yPos += (h + 1) >> 1; h >>= 1; top = m; } else { h = (h + 1) >> 1; bottom = m; } nTiles >>= 1; } ASSERT(xPos < m_width && (xPos + w <= m_width)); ASSERT(yPos < m_height && (yPos + h <= m_height)); } #endif libpgf/src/Subband.h100777 0 0 16540 12232452341 10002 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ * $Revision: 229 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file Subband.h /// @brief PGF wavelet subband class /// @author C. Stamm #ifndef PGF_SUBBAND_H #define PGF_SUBBAND_H #include "PGFtypes.h" class CEncoder; class CDecoder; class CRoiIndices; ////////////////////////////////////////////////////////////////////// /// PGF wavelet channel subband class. /// @author C. Stamm, R. Spuler /// @brief Wavelet channel class class CSubband { friend class CWaveletTransform; public: ////////////////////////////////////////////////////////////////////// /// Standard constructor. CSubband(); ////////////////////////////////////////////////////////////////////// /// Destructor. ~CSubband(); ////////////////////////////////////////////////////////////////////// /// Allocate a memory buffer to store all wavelet coefficients of this subband. /// @return True if the allocation did work without any problems bool AllocMemory(); ////////////////////////////////////////////////////////////////////// /// Delete the memory buffer of this subband. void FreeMemory(); ///////////////////////////////////////////////////////////////////// /// Extracts a rectangular subregion of this subband. /// Write wavelet coefficients into buffer. /// It might throw an IOException. /// @param encoder An encoder instance /// @param tile True if just a rectangular region is extracted, false if the entire subband is extracted. /// @param tileX Tile index in x-direction /// @param tileY Tile index in y-direction void ExtractTile(CEncoder& encoder, bool tile = false, UINT32 tileX = 0, UINT32 tileY = 0) THROW_; ///////////////////////////////////////////////////////////////////// /// Decoding and dequantization of this subband. /// It might throw an IOException. /// @param decoder A decoder instance /// @param quantParam Dequantization value /// @param tile True if just a rectangular region is placed, false if the entire subband is placed. /// @param tileX Tile index in x-direction /// @param tileY Tile index in y-direction void PlaceTile(CDecoder& decoder, int quantParam, bool tile = false, UINT32 tileX = 0, UINT32 tileY = 0) THROW_; ////////////////////////////////////////////////////////////////////// /// Perform subband quantization with given quantization parameter. /// A scalar quantization (with dead-zone) is used. A large quantization value /// results in strong quantization and therefore in big quality loss. /// @param quantParam A quantization parameter (larger or equal to 0) void Quantize(int quantParam); ////////////////////////////////////////////////////////////////////// /// Perform subband dequantization with given quantization parameter. /// A scalar quantization (with dead-zone) is used. A large quantization value /// results in strong quantization and therefore in big quality loss. /// @param quantParam A quantization parameter (larger or equal to 0) void Dequantize(int quantParam); ////////////////////////////////////////////////////////////////////// /// Store wavelet coefficient in subband at given position. /// @param pos A subband position (>= 0) /// @param v A wavelet coefficient void SetData(UINT32 pos, DataT v) { ASSERT(pos < m_size); m_data[pos] = v; } ////////////////////////////////////////////////////////////////////// /// Get a pointer to an array of all wavelet coefficients of this subband. /// @return Pointer to array of wavelet coefficients DataT* GetBuffer() { return m_data; } ////////////////////////////////////////////////////////////////////// /// Return wavelet coefficient at given position. /// @param pos A subband position (>= 0) /// @return Wavelet coefficient DataT GetData(UINT32 pos) const { ASSERT(pos < m_size); return m_data[pos]; } ////////////////////////////////////////////////////////////////////// /// Return level of this subband. /// @return Level of this subband int GetLevel() const { return m_level; } ////////////////////////////////////////////////////////////////////// /// Return height of this subband. /// @return Height of this subband (in pixels) int GetHeight() const { return m_height; } ////////////////////////////////////////////////////////////////////// /// Return width of this subband. /// @return Width of this subband (in pixels) int GetWidth() const { return m_width; } ////////////////////////////////////////////////////////////////////// /// Return orientation of this subband. /// LL LH /// HL HH /// @return Orientation of this subband (LL, HL, LH, HH) Orientation GetOrientation() const { return m_orientation; } #ifdef __PGFROISUPPORT__ ///////////////////////////////////////////////////////////////////// /// Set data buffer position to given position + one row. /// @param pos Given position void IncBuffRow(UINT32 pos) { m_dataPos = pos + BufferWidth(); } #endif private: void Initialize(UINT32 width, UINT32 height, int level, Orientation orient); void WriteBuffer(DataT val) { ASSERT(m_dataPos < m_size); m_data[m_dataPos++] = val; } void SetBuffer(DataT* b) { ASSERT(b); m_data = b; } DataT ReadBuffer() { ASSERT(m_dataPos < m_size); return m_data[m_dataPos++]; } UINT32 GetBuffPos() const { return m_dataPos; } #ifdef __PGFROISUPPORT__ UINT32 BufferWidth() const { return m_ROI.Width(); } void TilePosition(UINT32 tileX, UINT32 tileY, UINT32& left, UINT32& top, UINT32& w, UINT32& h) const; const PGFRect& GetROI() const { return m_ROI; } void SetNTiles(UINT32 nTiles) { m_nTiles = nTiles; } void SetROI(const PGFRect& roi) { ASSERT(roi.right <= m_width); ASSERT(roi.bottom <= m_height); m_ROI = roi; } void InitBuffPos(UINT32 left = 0, UINT32 top = 0) { m_dataPos = top*BufferWidth() + left; ASSERT(m_dataPos < m_size); } #else void InitBuffPos() { m_dataPos = 0; } #endif private: UINT32 m_width; ///< width in pixels UINT32 m_height; ///< height in pixels UINT32 m_size; ///< size of data buffer m_data int m_level; ///< recursion level Orientation m_orientation; ///< 0=LL, 1=HL, 2=LH, 3=HH L=lowpass filtered, H=highpass filterd UINT32 m_dataPos; ///< current position in m_data DataT* m_data; ///< buffer #ifdef __PGFROISUPPORT__ PGFRect m_ROI; ///< region of interest UINT32 m_nTiles; ///< number of tiles in one dimension in this subband #endif }; #endif //PGF_SUBBAND_H libpgf/src/WaveletTransform.cpp100777 0 0 46505 12313025746 12273 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-05-18 16:03:32 +0200 (Do, 18 Mai 2006) $ * $Revision: 194 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file WaveletTransform.cpp /// @brief PGF wavelet transform class implementation /// @author C. Stamm #include "WaveletTransform.h" #define c1 1 // best value 1 #define c2 2 // best value 2 ////////////////////////////////////////////////////////////////////////// // Constructor: Constructs a wavelet transform pyramid of given size and levels. // @param width The width of the original image (at level 0) in pixels // @param height The height of the original image (at level 0) in pixels // @param levels The number of levels (>= 0) // @param data Input data of subband LL at level 0 CWaveletTransform::CWaveletTransform(UINT32 width, UINT32 height, int levels, DataT* data) : m_nLevels(levels + 1) , m_subband(0) { ASSERT(m_nLevels > 0 && m_nLevels <= MaxLevel + 1); InitSubbands(width, height, data); #ifdef __PGFROISUPPORT__ m_ROIindices.SetLevels(levels + 1); #endif } ///////////////////////////////////////////////////////////////////// // Initialize size subbands on all levels void CWaveletTransform::InitSubbands(UINT32 width, UINT32 height, DataT* data) { if (m_subband) Destroy(); // create subbands m_subband = new CSubband[m_nLevels][NSubbands]; // init subbands UINT32 loWidth = width; UINT32 hiWidth = width; UINT32 loHeight = height; UINT32 hiHeight = height; for (int level = 0; level < m_nLevels; level++) { m_subband[level][LL].Initialize(loWidth, loHeight, level, LL); // LL m_subband[level][HL].Initialize(hiWidth, loHeight, level, HL); // HL m_subband[level][LH].Initialize(loWidth, hiHeight, level, LH); // LH m_subband[level][HH].Initialize(hiWidth, hiHeight, level, HH); // HH hiWidth = loWidth >> 1; hiHeight = loHeight >> 1; loWidth = (loWidth + 1) >> 1; loHeight = (loHeight + 1) >> 1; } if (data) { m_subband[0][LL].SetBuffer(data); } } ////////////////////////////////////////////////////////////////////////// // Compute fast forward wavelet transform of LL subband at given level and // stores result on all 4 subbands of level + 1. // Wavelet transform used in writing a PGF file // Forward Transform of srcBand and split and store it into subbands on destLevel // high pass filter at even positions: 1/4(-2, 4, -2) // low pass filter at odd positions: 1/8(-1, 2, 6, 2, -1) // @param level A wavelet transform pyramid level (>= 0 && < Levels()) // @param quant A quantization value (linear scalar quantization) // @return error in case of a memory allocation problem OSError CWaveletTransform::ForwardTransform(int level, int quant) { ASSERT(level >= 0 && level < m_nLevels - 1); const int destLevel = level + 1; ASSERT(m_subband[destLevel]); CSubband* srcBand = &m_subband[level][LL]; ASSERT(srcBand); const UINT32 width = srcBand->GetWidth(); const UINT32 height = srcBand->GetHeight(); DataT* src = srcBand->GetBuffer(); ASSERT(src); DataT *row0, *row1, *row2, *row3; // Allocate memory for next transform level for (int i=0; i < NSubbands; i++) { if (!m_subband[destLevel][i].AllocMemory()) return InsufficientMemory; } if (height >= FilterHeight) { // transform LL subband // top border handling row0 = src; row1 = row0 + width; row2 = row1 + width; ForwardRow(row0, width); ForwardRow(row1, width); ForwardRow(row2, width); for (UINT32 k=0; k < width; k++) { row1[k] -= ((row0[k] + row2[k] + c1) >> 1); row0[k] += ((row1[k] + c1) >> 1); } LinearToMallat(destLevel, row0, row1, width); row0 = row1; row1 = row2; row2 += width; row3 = row2 + width; // middle part for (UINT32 i=3; i < height-1; i += 2) { ForwardRow(row2, width); ForwardRow(row3, width); for (UINT32 k=0; k < width; k++) { row2[k] -= ((row1[k] + row3[k] + c1) >> 1); row1[k] += ((row0[k] + row2[k] + c2) >> 2); } LinearToMallat(destLevel, row1, row2, width); row0 = row2; row1 = row3; row2 = row3 + width; row3 = row2 + width; } // bottom border handling if (height & 1) { for (UINT32 k=0; k < width; k++) { row1[k] += ((row0[k] + c1) >> 1); } LinearToMallat(destLevel, row1, NULL, width); row0 = row1; row1 += width; } else { ForwardRow(row2, width); for (UINT32 k=0; k < width; k++) { row2[k] -= row1[k]; row1[k] += ((row0[k] + row2[k] + c2) >> 2); } LinearToMallat(destLevel, row1, row2, width); row0 = row1; row1 = row2; row2 += width; } } else { // if height is too small row0 = src; row1 = row0 + width; // first part for (UINT32 k=0; k < height; k += 2) { ForwardRow(row0, width); ForwardRow(row1, width); LinearToMallat(destLevel, row0, row1, width); row0 += width << 1; row1 += width << 1; } // bottom if (height & 1) { LinearToMallat(destLevel, row0, NULL, width); } } if (quant > 0) { // subband quantization (without LL) for (int i=1; i < NSubbands; i++) { m_subband[destLevel][i].Quantize(quant); } // LL subband quantization if (destLevel == m_nLevels - 1) { m_subband[destLevel][LL].Quantize(quant); } } // free source band srcBand->FreeMemory(); return NoError; } ////////////////////////////////////////////////////////////// // Forward transform one row // high pass filter at even positions: 1/4(-2, 4, -2) // low pass filter at odd positions: 1/8(-1, 2, 6, 2, -1) void CWaveletTransform::ForwardRow(DataT* src, UINT32 width) { if (width >= FilterWidth) { UINT32 i = 3; // left border handling src[1] -= ((src[0] + src[2] + c1) >> 1); src[0] += ((src[1] + c1) >> 1); // middle part for (; i < width-1; i += 2) { src[i] -= ((src[i-1] + src[i+1] + c1) >> 1); src[i-1] += ((src[i-2] + src[i] + c2) >> 2); } // right border handling if (width & 1) { src[i-1] += ((src[i-2] + c1) >> 1); } else { src[i] -= src[i-1]; src[i-1] += ((src[i-2] + src[i] + c2) >> 2); } } } ///////////////////////////////////////////////////////////////// // Copy transformed rows loRow and hiRow to subbands LL,HL,LH,HH void CWaveletTransform::LinearToMallat(int destLevel, DataT* loRow, DataT* hiRow, UINT32 width) { const UINT32 wquot = width >> 1; const bool wrem = width & 1; CSubband &ll = m_subband[destLevel][LL], &hl = m_subband[destLevel][HL]; CSubband &lh = m_subband[destLevel][LH], &hh = m_subband[destLevel][HH]; if (hiRow) { for (UINT32 i=0; i < wquot; i++) { ll.WriteBuffer(*loRow++); // first access, than increment hl.WriteBuffer(*loRow++); lh.WriteBuffer(*hiRow++); // first access, than increment hh.WriteBuffer(*hiRow++); } if (wrem) { ll.WriteBuffer(*loRow); lh.WriteBuffer(*hiRow); } } else { for (UINT32 i=0; i < wquot; i++) { ll.WriteBuffer(*loRow++); // first access, than increment hl.WriteBuffer(*loRow++); } if (wrem) ll.WriteBuffer(*loRow); } } ////////////////////////////////////////////////////////////////////////// // Compute fast inverse wavelet transform of all 4 subbands of given level and // stores result in LL subband of level - 1. // Inverse wavelet transform used in reading a PGF file // Inverse Transform srcLevel and combine to destBand // inverse high pass filter for even positions: 1/4(-1, 4, -1) // inverse low pass filter for odd positions: 1/8(-1, 4, 6, 4, -1) // @param srcLevel A wavelet transform pyramid level (> 0 && <= Levels()) // @param w [out] A pointer to the returned width of subband LL (in pixels) // @param h [out] A pointer to the returned height of subband LL (in pixels) // @param data [out] A pointer to the returned array of image data // @return error in case of a memory allocation problem OSError CWaveletTransform::InverseTransform(int srcLevel, UINT32* w, UINT32* h, DataT** data) { ASSERT(srcLevel > 0 && srcLevel < m_nLevels); const int destLevel = srcLevel - 1; ASSERT(m_subband[destLevel]); CSubband* destBand = &m_subband[destLevel][LL]; UINT32 width, height; // allocate memory for the results of the inverse transform if (!destBand->AllocMemory()) return InsufficientMemory; DataT *dest = destBand->GetBuffer(), *origin = dest, *row0, *row1, *row2, *row3; #ifdef __PGFROISUPPORT__ PGFRect destROI = destBand->GetROI(); // is valid only after AllocMemory width = destROI.Width(); height = destROI.Height(); const UINT32 destWidth = width; // destination buffer width const UINT32 destHeight = height; // destination buffer height // update destination ROI if (destROI.top & 1) { destROI.top++; origin += destWidth; height--; } if (destROI.left & 1) { destROI.left++; origin++; width--; } // init source buffer position const UINT32 leftD = destROI.left >> 1; const UINT32 left0 = m_subband[srcLevel][LL].GetROI().left; const UINT32 left1 = m_subband[srcLevel][HL].GetROI().left; const UINT32 topD = destROI.top >> 1; const UINT32 top0 = m_subband[srcLevel][LL].GetROI().top; const UINT32 top1 = m_subband[srcLevel][LH].GetROI().top; ASSERT(m_subband[srcLevel][LH].GetROI().left == left0); ASSERT(m_subband[srcLevel][HH].GetROI().left == left1); ASSERT(m_subband[srcLevel][HL].GetROI().top == top0); ASSERT(m_subband[srcLevel][HH].GetROI().top == top1); UINT32 srcOffsetX[2] = { 0, 0 }; UINT32 srcOffsetY[2] = { 0, 0 }; if (leftD >= __max(left0, left1)) { srcOffsetX[0] = leftD - left0; srcOffsetX[1] = leftD - left1; } else { if (left0 <= left1) { const UINT32 dx = (left1 - leftD) << 1; destROI.left += dx; origin += dx; width -= dx; srcOffsetX[0] = left1 - left0; } else { const UINT32 dx = (left0 - leftD) << 1; destROI.left += dx; origin += dx; width -= dx; srcOffsetX[1] = left0 - left1; } } if (topD >= __max(top0, top1)) { srcOffsetY[0] = topD - top0; srcOffsetY[1] = topD - top1; } else { if (top0 <= top1) { const UINT32 dy = (top1 - topD) << 1; destROI.top += dy; origin += dy*destWidth; height -= dy; srcOffsetY[0] = top1 - top0; } else { const UINT32 dy = (top0 - topD) << 1; destROI.top += dy; origin += dy*destWidth; height -= dy; srcOffsetY[1] = top0 - top1; } } m_subband[srcLevel][LL].InitBuffPos(srcOffsetX[0], srcOffsetY[0]); m_subband[srcLevel][HL].InitBuffPos(srcOffsetX[1], srcOffsetY[0]); m_subband[srcLevel][LH].InitBuffPos(srcOffsetX[0], srcOffsetY[1]); m_subband[srcLevel][HH].InitBuffPos(srcOffsetX[1], srcOffsetY[1]); #else width = destBand->GetWidth(); height = destBand->GetHeight(); PGFRect destROI(0, 0, width, height); const UINT32 destWidth = width; // destination buffer width const UINT32 destHeight = height; // destination buffer height // init source buffer position for (int i=0; i < NSubbands; i++) { m_subband[srcLevel][i].InitBuffPos(); } #endif if (destHeight >= FilterHeight) { // top border handling row0 = origin; row1 = row0 + destWidth; MallatToLinear(srcLevel, row0, row1, width); for (UINT32 k=0; k < width; k++) { row0[k] -= ((row1[k] + c1) >> 1); } // middle part row2 = row1 + destWidth; row3 = row2 + destWidth; for (UINT32 i=destROI.top + 2; i < destROI.bottom - 1; i += 2) { MallatToLinear(srcLevel, row2, row3, width); for (UINT32 k=0; k < width; k++) { row2[k] -= ((row1[k] + row3[k] + c2) >> 2); row1[k] += ((row0[k] + row2[k] + c1) >> 1); } InverseRow(row0, width); InverseRow(row1, width); row0 = row2; row1 = row3; row2 = row1 + destWidth; row3 = row2 + destWidth; } // bottom border handling if (height & 1) { MallatToLinear(srcLevel, row2, NULL, width); for (UINT32 k=0; k < width; k++) { row2[k] -= ((row1[k] + c1) >> 1); row1[k] += ((row0[k] + row2[k] + c1) >> 1); } InverseRow(row0, width); InverseRow(row1, width); InverseRow(row2, width); row0 = row1; row1 = row2; row2 += destWidth; } else { for (UINT32 k=0; k < width; k++) { row1[k] += row0[k]; } InverseRow(row0, width); InverseRow(row1, width); row0 = row1; row1 += destWidth; } } else { // height is too small row0 = origin; row1 = row0 + destWidth; // first part for (UINT32 k=0; k < height; k += 2) { MallatToLinear(srcLevel, row0, row1, width); InverseRow(row0, width); InverseRow(row1, width); row0 += destWidth << 1; row1 += destWidth << 1; } // bottom if (height & 1) { MallatToLinear(srcLevel, row0, NULL, width); InverseRow(row0, width); } } // free memory of the current srcLevel for (int i=0; i < NSubbands; i++) { m_subband[srcLevel][i].FreeMemory(); } // return info *w = destWidth; *h = height; *data = dest; return NoError; } ////////////////////////////////////////////////////////////////////// // Inverse Wavelet Transform of one row // inverse high pass filter for even positions: 1/4(-1, 4, -1) // inverse low pass filter for odd positions: 1/8(-1, 4, 6, 4, -1) void CWaveletTransform::InverseRow(DataT* dest, UINT32 width) { if (width >= FilterWidth) { UINT32 i = 2; // left border handling dest[0] -= ((dest[1] + c1) >> 1); // middle part for (; i < width - 1; i += 2) { dest[i] -= ((dest[i-1] + dest[i+1] + c2) >> 2); dest[i-1] += ((dest[i-2] + dest[i] + c1) >> 1); } // right border handling if (width & 1) { dest[i] -= ((dest[i-1] + c1) >> 1); dest[i-1] += ((dest[i-2] + dest[i] + c1) >> 1); } else { dest[i-1] += dest[i-2]; } } } /////////////////////////////////////////////////////////////////// // Copy transformed coefficients from subbands LL,HL,LH,HH to interleaved format void CWaveletTransform::MallatToLinear(int srcLevel, DataT* loRow, DataT* hiRow, UINT32 width) { const UINT32 wquot = width >> 1; const bool wrem = width & 1; CSubband &ll = m_subband[srcLevel][LL], &hl = m_subband[srcLevel][HL]; CSubband &lh = m_subband[srcLevel][LH], &hh = m_subband[srcLevel][HH]; if (hiRow) { #ifdef __PGFROISUPPORT__ const bool storePos = wquot < ll.BufferWidth(); UINT32 llPos = 0, hlPos = 0, lhPos = 0, hhPos = 0; if (storePos) { // save current src buffer positions llPos = ll.GetBuffPos(); hlPos = hl.GetBuffPos(); lhPos = lh.GetBuffPos(); hhPos = hh.GetBuffPos(); } #endif for (UINT32 i=0; i < wquot; i++) { *loRow++ = ll.ReadBuffer();// first access, than increment *loRow++ = hl.ReadBuffer();// first access, than increment *hiRow++ = lh.ReadBuffer();// first access, than increment *hiRow++ = hh.ReadBuffer();// first access, than increment } if (wrem) { *loRow++ = ll.ReadBuffer();// first access, than increment *hiRow++ = lh.ReadBuffer();// first access, than increment } #ifdef __PGFROISUPPORT__ if (storePos) { // increment src buffer positions ll.IncBuffRow(llPos); hl.IncBuffRow(hlPos); lh.IncBuffRow(lhPos); hh.IncBuffRow(hhPos); } #endif } else { #ifdef __PGFROISUPPORT__ const bool storePos = wquot < ll.BufferWidth(); UINT32 llPos = 0, hlPos = 0; if (storePos) { // save current src buffer positions llPos = ll.GetBuffPos(); hlPos = hl.GetBuffPos(); } #endif for (UINT32 i=0; i < wquot; i++) { *loRow++ = ll.ReadBuffer();// first access, than increment *loRow++ = hl.ReadBuffer();// first access, than increment } if (wrem) *loRow++ = ll.ReadBuffer(); #ifdef __PGFROISUPPORT__ if (storePos) { // increment src buffer positions ll.IncBuffRow(llPos); hl.IncBuffRow(hlPos); } #endif } } #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// Compute and store ROIs for each level /// @param rect rectangular region of interest (ROI) void CWaveletTransform::SetROI(const PGFRect& rect) { // create tile indices m_ROIindices.CreateIndices(); // compute tile indices m_ROIindices.ComputeIndices(m_subband[0][LL].GetWidth(), m_subband[0][LL].GetHeight(), rect); // compute ROIs UINT32 w, h; PGFRect r; for (int i=0; i < m_nLevels; i++) { const PGFRect& indices = m_ROIindices.GetIndices(i); for (int o=0; o < NSubbands; o++) { CSubband& subband = m_subband[i][o]; subband.SetNTiles(m_ROIindices.GetNofTiles(i)); // must be called before TilePosition() subband.TilePosition(indices.left, indices.top, r.left, r.top, w, h); subband.TilePosition(indices.right - 1, indices.bottom - 1, r.right, r.bottom, w, h); r.right += w; r.bottom += h; subband.SetROI(r); } } } ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// void CRoiIndices::CreateIndices() { if (!m_indices) { // create tile indices m_indices = new PGFRect[m_nLevels]; } } ////////////////////////////////////////////////////////////////////// /// Computes a tile index either in x- or y-direction for a given image position. /// @param width PGF image width /// @param height PGF image height /// @param pos A valid image position: (0 <= pos < width) or (0 <= pos < height) /// @param horizontal If true, then pos must be a x-value, otherwise a y-value /// @param isMin If true, then pos is left/top, else pos right/bottom void CRoiIndices::ComputeTileIndex(UINT32 width, UINT32 height, UINT32 pos, bool horizontal, bool isMin) { ASSERT(m_indices); UINT32 m; UINT32 tileIndex = 0; UINT32 tileMin = 0, tileMax = (horizontal) ? width : height; ASSERT(pos <= tileMax); // compute tile index with binary search for (int i=m_nLevels - 1; i >= 0; i--) { // store values if (horizontal) { if (isMin) { m_indices[i].left = tileIndex; } else { m_indices[i].right = tileIndex + 1; } } else { if (isMin) { m_indices[i].top = tileIndex; } else { m_indices[i].bottom = tileIndex + 1; } } // compute values tileIndex <<= 1; m = tileMin + (tileMax - tileMin)/2; if (pos >= m) { tileMin = m; tileIndex++; } else { tileMax = m; } } } ///////////////////////////////////////////////////////////////////// /// Compute tile indices for given rectangle (ROI) /// @param width PGF image width /// @param height PGF image height /// @param rect ROI void CRoiIndices::ComputeIndices(UINT32 width, UINT32 height, const PGFRect& rect) { ComputeTileIndex(width, height, rect.left, true, true); ComputeTileIndex(width, height, rect.top, false, true); ComputeTileIndex(width, height, rect.right, true, false); ComputeTileIndex(width, height, rect.bottom, false, false); } #endif // __PGFROISUPPORT__ libpgf/src/WaveletTransform.h100777 0 0 16131 12232452341 11723 0/* * The Progressive Graphics File; http://www.libpgf.org * * $Date: 2006-05-18 16:03:32 +0200 (Do, 18 Mai 2006) $ * $Revision: 194 $ * * This file Copyright (C) 2006 xeraina GmbH, Switzerland * * This program 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 program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////// /// @file WaveletTransform.h /// @brief PGF wavelet transform class /// @author C. Stamm #ifndef PGF_WAVELETTRANSFORM_H #define PGF_WAVELETTRANSFORM_H #include "PGFtypes.h" #include "Subband.h" ////////////////////////////////////////////////////////////////////// // Constants #define FilterWidth 5 ///< number of coefficients of the row wavelet filter #define FilterHeight 3 ///< number of coefficients of the column wavelet filter #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// PGF ROI and tile support. This is a helper class for CWaveletTransform. /// @author C. Stamm /// @brief ROI indices class CRoiIndices { friend class CWaveletTransform; ////////////////////////////////////////////////////////////////////// /// Constructor: Creates a ROI helper object CRoiIndices() : m_nLevels(0) , m_indices(0) {} ////////////////////////////////////////////////////////////////////// /// Destructor ~CRoiIndices() { Destroy(); } void Destroy() { delete[] m_indices; m_indices = 0; } void CreateIndices(); void ComputeIndices(UINT32 width, UINT32 height, const PGFRect& rect); const PGFRect& GetIndices(int level) const { ASSERT(m_indices); ASSERT(level >= 0 && level < m_nLevels); return m_indices[level]; } void SetLevels(int levels) { ASSERT(levels > 0); m_nLevels = levels; } void ComputeTileIndex(UINT32 width, UINT32 height, UINT32 pos, bool horizontal, bool isMin); public: ////////////////////////////////////////////////////////////////////// /// Returns the number of tiles in one dimension at given level. /// @param level A wavelet transform pyramid level (>= 0 && < Levels()) UINT32 GetNofTiles(int level) const { ASSERT(level >= 0 && level < m_nLevels); return 1 << (m_nLevels - level - 1); } private: int m_nLevels; ///< number of levels of the image PGFRect *m_indices; ///< array of tile indices (index is level) }; #endif //__PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// PGF wavelet transform class. /// @author C. Stamm, R. Spuler /// @brief PGF wavelet transform class CWaveletTransform { friend class CSubband; public: ////////////////////////////////////////////////////////////////////// /// Constructor: Constructs a wavelet transform pyramid of given size and levels. /// @param width The width of the original image (at level 0) in pixels /// @param height The height of the original image (at level 0) in pixels /// @param levels The number of levels (>= 0) /// @param data Input data of subband LL at level 0 CWaveletTransform(UINT32 width, UINT32 height, int levels, DataT* data = NULL); ////////////////////////////////////////////////////////////////////// /// Destructor ~CWaveletTransform() { Destroy(); } ////////////////////////////////////////////////////////////////////// /// Compute fast forward wavelet transform of LL subband at given level and /// stores result on all 4 subbands of level + 1. /// @param level A wavelet transform pyramid level (>= 0 && < Levels()) /// @param quant A quantization value (linear scalar quantization) /// @return error in case of a memory allocation problem OSError ForwardTransform(int level, int quant); ////////////////////////////////////////////////////////////////////// /// Compute fast inverse wavelet transform of all 4 subbands of given level and /// stores result in LL subband of level - 1. /// @param level A wavelet transform pyramid level (> 0 && <= Levels()) /// @param width A pointer to the returned width of subband LL (in pixels) /// @param height A pointer to the returned height of subband LL (in pixels) /// @param data A pointer to the returned array of image data /// @return error in case of a memory allocation problem OSError InverseTransform(int level, UINT32* width, UINT32* height, DataT** data); ////////////////////////////////////////////////////////////////////// /// Get pointer to one of the 4 subband at a given level. /// @param level A wavelet transform pyramid level (>= 0 && <= Levels()) /// @param orientation A quarter of the subband (LL, LH, HL, HH) CSubband* GetSubband(int level, Orientation orientation) { ASSERT(level >= 0 && level < m_nLevels); return &m_subband[level][orientation]; } #ifdef __PGFROISUPPORT__ ////////////////////////////////////////////////////////////////////// /// Compute and store ROIs for each level /// @param rect rectangular region of interest (ROI) void SetROI(const PGFRect& rect); ////////////////////////////////////////////////////////////////////// /// Get tile indices of a ROI at given level. /// @param level A valid subband level. const PGFRect& GetTileIndices(int level) const { return m_ROIindices.GetIndices(level); } ////////////////////////////////////////////////////////////////////// /// Get number of tiles in x- or y-direction at given level. /// @param level A valid subband level. UINT32 GetNofTiles(int level) const { return m_ROIindices.GetNofTiles(level); } ////////////////////////////////////////////////////////////////////// /// Return ROI at given level. /// @param level A valid subband level. const PGFRect& GetROI(int level) const { return m_subband[level][LL].GetROI(); } #endif // __PGFROISUPPORT__ private: void Destroy() { delete[] m_subband; m_subband = 0; #ifdef __PGFROISUPPORT__ m_ROIindices.Destroy(); #endif } void InitSubbands(UINT32 width, UINT32 height, DataT* data); void ForwardRow(DataT* buff, UINT32 width); void InverseRow(DataT* buff, UINT32 width); void LinearToMallat(int destLevel,DataT* loRow, DataT* hiRow, UINT32 width); void MallatToLinear(int srcLevel, DataT* loRow, DataT* hiRow, UINT32 width); #ifdef __PGFROISUPPORT__ CRoiIndices m_ROIindices; ///< ROI indices #endif //__PGFROISUPPORT__ int m_nLevels; ///< number of transform levels: one more than the number of level in PGFimage CSubband (*m_subband)[NSubbands]; ///< quadtree of subbands: LL HL LH HH }; #endif //PGF_WAVELETTRANSFORM_H